Backed out changeset 2450366cf7ca (bug 1891629) for causing win msix mochitest failures
[gecko.git] / dom / html / HTMLButtonElement.h
blobb1a5c53f6413df22f3c3dc15e25851a8977beeaf
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"
14 namespace mozilla {
15 class EventChainPostVisitor;
16 class EventChainPreVisitor;
17 namespace dom {
18 class FormData;
20 class HTMLButtonElement final : public nsGenericHTMLFormControlElementWithState,
21 public ConstraintValidation {
22 public:
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)
32 // nsISupports
33 NS_DECL_ISUPPORTS_INHERITED
35 int32_t TabIndexDefault() override;
37 NS_IMPL_FROMNODE_HTML_WITH_TAG(HTMLButtonElement, button)
39 // Element
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;
52 // EventTarget
53 void GetEventTargetParent(EventChainPreVisitor& aVisitor) override;
54 MOZ_CAN_RUN_SCRIPT_BOUNDARY
55 nsresult PostHandleEvent(EventChainPostVisitor& aVisitor) override;
56 void LegacyPreActivationBehavior(EventChainVisitor& aVisitor) override;
57 MOZ_CAN_RUN_SCRIPT
58 void ActivationBehavior(EventChainPostVisitor& aVisitor) override;
59 void LegacyCanceledActivationBehavior(
60 EventChainPostVisitor& aVisitor) override;
62 // nsINode
63 nsresult Clone(dom::NodeInfo*, nsINode** aResult) const override;
64 JSObject* WrapNode(JSContext*, JS::Handle<JSObject*> aGivenProto) override;
66 // nsIContent
67 nsresult BindToTree(BindContext&, nsINode& aParent) override;
68 void UnbindFromTree(UnbindContext&) override;
69 void DoneCreatingElement() override;
71 void UpdateBarredFromConstraintValidation();
72 void UpdateValidityElementStates(bool aNotify);
73 /**
74 * Called when an attribute is about to be changed
76 void BeforeSetAttr(int32_t aNameSpaceID, nsAtom* aName,
77 const nsAttrValue* aValue, bool aNotify) override;
78 /**
79 * Called when an attribute has just been changed
81 void AfterSetAttr(int32_t aNamespaceID, nsAtom* aName,
82 const nsAttrValue* aValue, const nsAttrValue* aOldValue,
83 nsIPrincipal* aSubjectPrincipal, bool aNotify) override;
84 bool ParseAttribute(int32_t aNamespaceID, nsAtom* aAttribute,
85 const nsAString& aValue,
86 nsIPrincipal* aMaybeScriptedPrincipal,
87 nsAttrValue& aResult) override;
89 // nsGenericHTMLElement
90 bool IsHTMLFocusable(bool aWithMouse, bool* aIsFocusable,
91 int32_t* aTabIndex) override;
92 bool IsDisabledForEvents(WidgetEvent* aEvent) override;
94 // WebIDL
95 bool Disabled() const { return GetBoolAttr(nsGkAtoms::disabled); }
96 void SetDisabled(bool aDisabled, ErrorResult& aError) {
97 SetHTMLBoolAttr(nsGkAtoms::disabled, aDisabled, aError);
99 // GetFormAction implemented in superclass
100 void SetFormAction(const nsAString& aFormAction, ErrorResult& aRv) {
101 SetHTMLAttr(nsGkAtoms::formaction, aFormAction, aRv);
103 void GetFormEnctype(nsAString& aFormEncType);
104 void SetFormEnctype(const nsAString& aFormEnctype, ErrorResult& aRv) {
105 SetHTMLAttr(nsGkAtoms::formenctype, aFormEnctype, aRv);
107 void GetFormMethod(nsAString& aFormMethod);
108 void SetFormMethod(const nsAString& aFormMethod, ErrorResult& aRv) {
109 SetHTMLAttr(nsGkAtoms::formmethod, aFormMethod, aRv);
111 bool FormNoValidate() const { return GetBoolAttr(nsGkAtoms::formnovalidate); }
112 void SetFormNoValidate(bool aFormNoValidate, ErrorResult& aError) {
113 SetHTMLBoolAttr(nsGkAtoms::formnovalidate, aFormNoValidate, aError);
115 void GetFormTarget(DOMString& aFormTarget) {
116 GetHTMLAttr(nsGkAtoms::formtarget, aFormTarget);
118 void SetFormTarget(const nsAString& aFormTarget, ErrorResult& aRv) {
119 SetHTMLAttr(nsGkAtoms::formtarget, aFormTarget, aRv);
121 void GetName(DOMString& aName) { GetHTMLAttr(nsGkAtoms::name, aName); }
122 void SetName(const nsAString& aName, ErrorResult& aRv) {
123 SetHTMLAttr(nsGkAtoms::name, aName, aRv);
125 void GetType(nsAString& aType);
126 void SetType(const nsAString& aType, ErrorResult& aRv) {
127 SetHTMLAttr(nsGkAtoms::type, aType, aRv);
129 void GetValue(DOMString& aValue) { GetHTMLAttr(nsGkAtoms::value, aValue); }
130 void SetValue(const nsAString& aValue, ErrorResult& aRv) {
131 SetHTMLAttr(nsGkAtoms::value, aValue, aRv);
134 // Override SetCustomValidity so we update our state properly when it's called
135 // via bindings.
136 void SetCustomValidity(const nsAString& aError);
138 protected:
139 virtual ~HTMLButtonElement();
141 bool mDisabledChanged : 1;
142 bool mInInternalActivate : 1;
143 bool mInhibitStateRestoration : 1;
146 } // namespace dom
147 } // namespace mozilla
149 #endif // mozilla_dom_HTMLButtonElement_h