Bug 1554951 [wpt PR 17043] - wake-lock: Fix invalid types test in wakelock-type.https...
[gecko.git] / dom / html / HTMLButtonElement.h
blob60584c08df7257f850b0d8dcdd400c34aec695ec
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 "nsGenericHTMLElement.h"
12 #include "nsIConstraintValidation.h"
14 namespace mozilla {
15 class EventChainPostVisitor;
16 class EventChainPreVisitor;
17 namespace dom {
19 class HTMLButtonElement final : public nsGenericHTMLFormElementWithState,
20 public nsIConstraintValidation {
21 public:
22 using nsIConstraintValidation::GetValidationMessage;
24 explicit HTMLButtonElement(
25 already_AddRefed<mozilla::dom::NodeInfo>&& aNodeInfo,
26 FromParser aFromParser = NOT_FROM_PARSER);
28 NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(HTMLButtonElement,
29 nsGenericHTMLFormElementWithState)
31 // nsISupports
32 NS_DECL_ISUPPORTS_INHERITED
34 virtual int32_t TabIndexDefault() override;
36 NS_IMPL_FROMNODE_HTML_WITH_TAG(HTMLButtonElement, button)
38 // Element
39 virtual bool IsInteractiveHTMLContent(bool aIgnoreTabindex) const override {
40 return true;
43 // overriden nsIFormControl methods
44 NS_IMETHOD Reset() override;
45 NS_IMETHOD SubmitNamesValues(HTMLFormSubmission* aFormSubmission) override;
46 NS_IMETHOD SaveState() override;
47 bool RestoreState(PresState* aState) override;
48 virtual bool IsDisabledForEvents(WidgetEvent* aEvent) override;
50 virtual void FieldSetDisabledChanged(bool aNotify) override;
52 // EventTarget
53 void GetEventTargetParent(EventChainPreVisitor& aVisitor) override;
54 MOZ_CAN_RUN_SCRIPT_BOUNDARY
55 virtual nsresult PostHandleEvent(EventChainPostVisitor& aVisitor) override;
57 // nsINode
58 virtual nsresult Clone(dom::NodeInfo*, nsINode** aResult) const override;
59 virtual JSObject* WrapNode(JSContext* aCx,
60 JS::Handle<JSObject*> aGivenProto) override;
62 // nsIContent
63 virtual nsresult BindToTree(BindContext&, nsINode& aParent) override;
64 virtual void UnbindFromTree(bool aNullParent = true) override;
65 virtual void DoneCreatingElement() override;
67 void UpdateBarredFromConstraintValidation();
68 // Element
69 EventStates IntrinsicState() const override;
70 /**
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;
76 /**
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;
93 // WebIDL
94 bool Autofocus() const { return GetBoolAttr(nsGkAtoms::autofocus); }
95 void SetAutofocus(bool aAutofocus, ErrorResult& aError) {
96 SetHTMLBoolAttr(nsGkAtoms::autofocus, aAutofocus, aError);
98 bool Disabled() const { return GetBoolAttr(nsGkAtoms::disabled); }
99 void SetDisabled(bool aDisabled, ErrorResult& aError) {
100 SetHTMLBoolAttr(nsGkAtoms::disabled, aDisabled, aError);
102 // nsGenericHTMLFormElement::GetForm is fine.
103 using nsGenericHTMLFormElement::GetForm;
104 // GetFormAction implemented in superclass
105 void SetFormAction(const nsAString& aFormAction, ErrorResult& aRv) {
106 SetHTMLAttr(nsGkAtoms::formaction, aFormAction, aRv);
108 void GetFormEnctype(nsAString& aFormEncType);
109 void SetFormEnctype(const nsAString& aFormEnctype, ErrorResult& aRv) {
110 SetHTMLAttr(nsGkAtoms::formenctype, aFormEnctype, aRv);
112 void GetFormMethod(nsAString& aFormMethod);
113 void SetFormMethod(const nsAString& aFormMethod, ErrorResult& aRv) {
114 SetHTMLAttr(nsGkAtoms::formmethod, aFormMethod, aRv);
116 bool FormNoValidate() const { return GetBoolAttr(nsGkAtoms::formnovalidate); }
117 void SetFormNoValidate(bool aFormNoValidate, ErrorResult& aError) {
118 SetHTMLBoolAttr(nsGkAtoms::formnovalidate, aFormNoValidate, aError);
120 void GetFormTarget(DOMString& aFormTarget) {
121 GetHTMLAttr(nsGkAtoms::formtarget, aFormTarget);
123 void SetFormTarget(const nsAString& aFormTarget, ErrorResult& aRv) {
124 SetHTMLAttr(nsGkAtoms::formtarget, aFormTarget, aRv);
126 void GetName(DOMString& aName) { GetHTMLAttr(nsGkAtoms::name, aName); }
127 void SetName(const nsAString& aName, ErrorResult& aRv) {
128 SetHTMLAttr(nsGkAtoms::name, aName, aRv);
130 void GetType(nsAString& aType);
131 void SetType(const nsAString& aType, ErrorResult& aRv) {
132 SetHTMLAttr(nsGkAtoms::type, aType, aRv);
134 void GetValue(DOMString& aValue) { GetHTMLAttr(nsGkAtoms::value, aValue); }
135 void SetValue(const nsAString& aValue, ErrorResult& aRv) {
136 SetHTMLAttr(nsGkAtoms::value, aValue, aRv);
139 // Override SetCustomValidity so we update our state properly when it's called
140 // via bindings.
141 void SetCustomValidity(const nsAString& aError);
143 protected:
144 virtual ~HTMLButtonElement();
146 bool mDisabledChanged;
147 bool mInInternalActivate;
148 bool mInhibitStateRestoration;
151 } // namespace dom
152 } // namespace mozilla
154 #endif // mozilla_dom_HTMLButtonElement_h