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 int32_t TabIndexDefault() override
;
37 NS_IMPL_FROMNODE_HTML_WITH_TAG(HTMLButtonElement
, button
)
40 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 void FieldSetDisabledChanged(bool aNotify
) override
;
53 void GetEventTargetParent(EventChainPreVisitor
& aVisitor
) override
;
54 MOZ_CAN_RUN_SCRIPT_BOUNDARY
55 nsresult
PostHandleEvent(EventChainPostVisitor
& aVisitor
) override
;
58 nsresult
Clone(dom::NodeInfo
*, nsINode
** aResult
) const override
;
59 JSObject
* WrapNode(JSContext
*, JS::Handle
<JSObject
*> aGivenProto
) override
;
62 nsresult
BindToTree(BindContext
&, nsINode
& aParent
) override
;
63 void UnbindFromTree(bool aNullParent
= true) override
;
64 void DoneCreatingElement() override
;
66 void UpdateBarredFromConstraintValidation();
67 void UpdateValidityElementStates(bool aNotify
) final
;
69 * Called when an attribute is about to be changed
71 void BeforeSetAttr(int32_t aNameSpaceID
, nsAtom
* aName
,
72 const nsAttrValue
* aValue
, bool aNotify
) override
;
74 * Called when an attribute has just been changed
76 void AfterSetAttr(int32_t aNamespaceID
, nsAtom
* aName
,
77 const nsAttrValue
* aValue
, const nsAttrValue
* aOldValue
,
78 nsIPrincipal
* aSubjectPrincipal
, bool aNotify
) override
;
79 bool ParseAttribute(int32_t aNamespaceID
, nsAtom
* aAttribute
,
80 const nsAString
& aValue
,
81 nsIPrincipal
* aMaybeScriptedPrincipal
,
82 nsAttrValue
& aResult
) override
;
84 // nsGenericHTMLElement
85 bool IsHTMLFocusable(bool aWithMouse
, bool* aIsFocusable
,
86 int32_t* aTabIndex
) override
;
87 bool IsDisabledForEvents(WidgetEvent
* aEvent
) override
;
90 bool Disabled() const { return GetBoolAttr(nsGkAtoms::disabled
); }
91 void SetDisabled(bool aDisabled
, ErrorResult
& aError
) {
92 SetHTMLBoolAttr(nsGkAtoms::disabled
, aDisabled
, aError
);
94 // GetFormAction implemented in superclass
95 void SetFormAction(const nsAString
& aFormAction
, ErrorResult
& aRv
) {
96 SetHTMLAttr(nsGkAtoms::formaction
, aFormAction
, aRv
);
98 void GetFormEnctype(nsAString
& aFormEncType
);
99 void SetFormEnctype(const nsAString
& aFormEnctype
, ErrorResult
& aRv
) {
100 SetHTMLAttr(nsGkAtoms::formenctype
, aFormEnctype
, aRv
);
102 void GetFormMethod(nsAString
& aFormMethod
);
103 void SetFormMethod(const nsAString
& aFormMethod
, ErrorResult
& aRv
) {
104 SetHTMLAttr(nsGkAtoms::formmethod
, aFormMethod
, aRv
);
106 bool FormNoValidate() const { return GetBoolAttr(nsGkAtoms::formnovalidate
); }
107 void SetFormNoValidate(bool aFormNoValidate
, ErrorResult
& aError
) {
108 SetHTMLBoolAttr(nsGkAtoms::formnovalidate
, aFormNoValidate
, aError
);
110 void GetFormTarget(DOMString
& aFormTarget
) {
111 GetHTMLAttr(nsGkAtoms::formtarget
, aFormTarget
);
113 void SetFormTarget(const nsAString
& aFormTarget
, ErrorResult
& aRv
) {
114 SetHTMLAttr(nsGkAtoms::formtarget
, aFormTarget
, aRv
);
116 void GetName(DOMString
& aName
) { GetHTMLAttr(nsGkAtoms::name
, aName
); }
117 void SetName(const nsAString
& aName
, ErrorResult
& aRv
) {
118 SetHTMLAttr(nsGkAtoms::name
, aName
, aRv
);
120 void GetType(nsAString
& aType
);
121 void SetType(const nsAString
& aType
, ErrorResult
& aRv
) {
122 SetHTMLAttr(nsGkAtoms::type
, aType
, aRv
);
124 void GetValue(DOMString
& aValue
) { GetHTMLAttr(nsGkAtoms::value
, aValue
); }
125 void SetValue(const nsAString
& aValue
, ErrorResult
& aRv
) {
126 SetHTMLAttr(nsGkAtoms::value
, aValue
, aRv
);
129 // Override SetCustomValidity so we update our state properly when it's called
131 void SetCustomValidity(const nsAString
& aError
);
134 virtual ~HTMLButtonElement();
136 bool mDisabledChanged
: 1;
137 bool mInInternalActivate
: 1;
138 bool mInhibitStateRestoration
: 1;
142 } // namespace mozilla
144 #endif // mozilla_dom_HTMLButtonElement_h