1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* vim: set ts=8 sts=2 et sw=2 tw=80: */
3 /* This Source Code Form is subject to the terms of the Mozilla Public
4 * License, v. 2.0. If a copy of the MPL was not distributed with this
5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
7 #ifndef mozilla_dom_HTMLButtonElement_h
8 #define mozilla_dom_HTMLButtonElement_h
10 #include "mozilla/Attributes.h"
11 #include "mozilla/dom/ConstraintValidation.h"
12 #include "nsGenericHTMLElement.h"
15 class EventChainPostVisitor
;
16 class EventChainPreVisitor
;
20 class HTMLButtonElement final
: public nsGenericHTMLFormControlElementWithState
,
21 public ConstraintValidation
{
23 using ConstraintValidation::GetValidationMessage
;
25 explicit HTMLButtonElement(
26 already_AddRefed
<mozilla::dom::NodeInfo
>&& aNodeInfo
,
27 FromParser aFromParser
= NOT_FROM_PARSER
);
29 NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(
30 HTMLButtonElement
, nsGenericHTMLFormControlElementWithState
)
33 NS_DECL_ISUPPORTS_INHERITED
35 virtual int32_t TabIndexDefault() override
;
37 NS_IMPL_FROMNODE_HTML_WITH_TAG(HTMLButtonElement
, button
)
40 virtual bool IsInteractiveHTMLContent() const override
{ return true; }
42 // nsGenericHTMLFormElement
43 void SaveState() override
;
44 bool RestoreState(PresState
* aState
) override
;
46 // overriden nsIFormControl methods
47 NS_IMETHOD
Reset() override
;
48 NS_IMETHOD
SubmitNamesValues(FormData
* aFormData
) override
;
50 virtual void FieldSetDisabledChanged(bool aNotify
) override
;
53 void GetEventTargetParent(EventChainPreVisitor
& aVisitor
) override
;
54 MOZ_CAN_RUN_SCRIPT_BOUNDARY
55 virtual nsresult
PostHandleEvent(EventChainPostVisitor
& aVisitor
) override
;
58 virtual nsresult
Clone(dom::NodeInfo
*, nsINode
** aResult
) const override
;
59 virtual JSObject
* WrapNode(JSContext
* aCx
,
60 JS::Handle
<JSObject
*> aGivenProto
) override
;
63 virtual nsresult
BindToTree(BindContext
&, nsINode
& aParent
) override
;
64 virtual void UnbindFromTree(bool aNullParent
= true) override
;
65 virtual void DoneCreatingElement() override
;
67 void UpdateBarredFromConstraintValidation();
69 ElementState
IntrinsicState() const override
;
71 * Called when an attribute is about to be changed
73 virtual nsresult
BeforeSetAttr(int32_t aNameSpaceID
, nsAtom
* aName
,
74 const nsAttrValueOrString
* aValue
,
75 bool aNotify
) override
;
77 * Called when an attribute has just been changed
79 virtual nsresult
AfterSetAttr(int32_t aNamespaceID
, nsAtom
* aName
,
80 const nsAttrValue
* aValue
,
81 const nsAttrValue
* aOldValue
,
82 nsIPrincipal
* aSubjectPrincipal
,
83 bool aNotify
) override
;
84 virtual bool ParseAttribute(int32_t aNamespaceID
, nsAtom
* aAttribute
,
85 const nsAString
& aValue
,
86 nsIPrincipal
* aMaybeScriptedPrincipal
,
87 nsAttrValue
& aResult
) override
;
89 // nsGenericHTMLElement
90 virtual bool IsHTMLFocusable(bool aWithMouse
, bool* aIsFocusable
,
91 int32_t* aTabIndex
) override
;
92 virtual bool IsDisabledForEvents(WidgetEvent
* aEvent
) override
;
95 bool Autofocus() const { return GetBoolAttr(nsGkAtoms::autofocus
); }
96 void SetAutofocus(bool aAutofocus
, ErrorResult
& aError
) {
97 SetHTMLBoolAttr(nsGkAtoms::autofocus
, aAutofocus
, aError
);
99 bool Disabled() const { return GetBoolAttr(nsGkAtoms::disabled
); }
100 void SetDisabled(bool aDisabled
, ErrorResult
& aError
) {
101 SetHTMLBoolAttr(nsGkAtoms::disabled
, aDisabled
, aError
);
103 // GetFormAction implemented in superclass
104 void SetFormAction(const nsAString
& aFormAction
, ErrorResult
& aRv
) {
105 SetHTMLAttr(nsGkAtoms::formaction
, aFormAction
, aRv
);
107 void GetFormEnctype(nsAString
& aFormEncType
);
108 void SetFormEnctype(const nsAString
& aFormEnctype
, ErrorResult
& aRv
) {
109 SetHTMLAttr(nsGkAtoms::formenctype
, aFormEnctype
, aRv
);
111 void GetFormMethod(nsAString
& aFormMethod
);
112 void SetFormMethod(const nsAString
& aFormMethod
, ErrorResult
& aRv
) {
113 SetHTMLAttr(nsGkAtoms::formmethod
, aFormMethod
, aRv
);
115 bool FormNoValidate() const { return GetBoolAttr(nsGkAtoms::formnovalidate
); }
116 void SetFormNoValidate(bool aFormNoValidate
, ErrorResult
& aError
) {
117 SetHTMLBoolAttr(nsGkAtoms::formnovalidate
, aFormNoValidate
, aError
);
119 void GetFormTarget(DOMString
& aFormTarget
) {
120 GetHTMLAttr(nsGkAtoms::formtarget
, aFormTarget
);
122 void SetFormTarget(const nsAString
& aFormTarget
, ErrorResult
& aRv
) {
123 SetHTMLAttr(nsGkAtoms::formtarget
, aFormTarget
, aRv
);
125 void GetName(DOMString
& aName
) { GetHTMLAttr(nsGkAtoms::name
, aName
); }
126 void SetName(const nsAString
& aName
, ErrorResult
& aRv
) {
127 SetHTMLAttr(nsGkAtoms::name
, aName
, aRv
);
129 void GetType(nsAString
& aType
);
130 void SetType(const nsAString
& aType
, ErrorResult
& aRv
) {
131 SetHTMLAttr(nsGkAtoms::type
, aType
, aRv
);
133 void GetValue(DOMString
& aValue
) { GetHTMLAttr(nsGkAtoms::value
, aValue
); }
134 void SetValue(const nsAString
& aValue
, ErrorResult
& aRv
) {
135 SetHTMLAttr(nsGkAtoms::value
, aValue
, aRv
);
138 // Override SetCustomValidity so we update our state properly when it's called
140 void SetCustomValidity(const nsAString
& aError
);
143 virtual ~HTMLButtonElement();
145 bool mDisabledChanged
: 1;
146 bool mInInternalActivate
: 1;
147 bool mInhibitStateRestoration
: 1;
151 } // namespace mozilla
153 #endif // mozilla_dom_HTMLButtonElement_h