tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

HTMLButtonElement.h (5870B)


      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/. */
      6 
      7 #ifndef mozilla_dom_HTMLButtonElement_h
      8 #define mozilla_dom_HTMLButtonElement_h
      9 
     10 #include "mozilla/Attributes.h"
     11 #include "mozilla/dom/ConstraintValidation.h"
     12 #include "nsGenericHTMLElement.h"
     13 
     14 namespace mozilla {
     15 class EventChainPostVisitor;
     16 class EventChainPreVisitor;
     17 namespace dom {
     18 class FormData;
     19 
     20 class HTMLButtonElement final : public nsGenericHTMLFormControlElementWithState,
     21                                public ConstraintValidation {
     22 public:
     23  using ConstraintValidation::GetValidationMessage;
     24 
     25  explicit HTMLButtonElement(
     26      already_AddRefed<mozilla::dom::NodeInfo>&& aNodeInfo,
     27      FromParser aFromParser = NOT_FROM_PARSER);
     28 
     29  NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(
     30      HTMLButtonElement, nsGenericHTMLFormControlElementWithState)
     31 
     32  // nsISupports
     33  NS_DECL_ISUPPORTS_INHERITED
     34 
     35  int32_t TabIndexDefault() override;
     36 
     37  NS_IMPL_FROMNODE_HTML_WITH_TAG(HTMLButtonElement, button)
     38 
     39  // Element
     40  bool IsInteractiveHTMLContent() const override { return true; }
     41 
     42  // nsGenericHTMLFormElement
     43  void SaveState() override;
     44  bool RestoreState(PresState* aState) override;
     45 
     46  // overriden nsIFormControl methods
     47  NS_IMETHOD Reset() override;
     48  NS_IMETHOD SubmitNamesValues(FormData* aFormData) override;
     49 
     50  void FieldSetDisabledChanged(bool aNotify) override;
     51 
     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;
     61 
     62  // nsINode
     63  nsresult Clone(dom::NodeInfo*, nsINode** aResult) const override;
     64  JSObject* WrapNode(JSContext*, JS::Handle<JSObject*> aGivenProto) override;
     65 
     66  // nsIContent
     67  nsresult BindToTree(BindContext&, nsINode& aParent) override;
     68  void UnbindFromTree(UnbindContext&) override;
     69  void DoneCreatingElement() override;
     70 
     71  void UpdateBarredFromConstraintValidation();
     72  void UpdateValidityElementStates(bool aNotify);
     73  /**
     74   * Called when an attribute is about to be changed
     75   */
     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
     80   */
     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;
     88 
     89  // nsGenericHTMLElement
     90  bool IsHTMLFocusable(IsFocusableFlags, bool* aIsFocusable,
     91                       int32_t* aTabIndex) override;
     92  bool IsDisabledForEvents(WidgetEvent* aEvent) override;
     93 
     94  // WebIDL
     95  bool Disabled() const { return GetBoolAttr(nsGkAtoms::disabled); }
     96  void SetDisabled(bool aDisabled, ErrorResult& aError) {
     97    SetHTMLBoolAttr(nsGkAtoms::disabled, aDisabled, aError);
     98  }
     99  // GetFormAction implemented in superclass
    100  void SetFormAction(const nsAString& aFormAction, ErrorResult& aRv) {
    101    SetHTMLAttr(nsGkAtoms::formaction, aFormAction, aRv);
    102  }
    103  void GetFormEnctype(nsAString& aFormEncType);
    104  void SetFormEnctype(const nsAString& aFormEnctype, ErrorResult& aRv) {
    105    SetHTMLAttr(nsGkAtoms::formenctype, aFormEnctype, aRv);
    106  }
    107  void GetFormMethod(nsAString& aFormMethod);
    108  void SetFormMethod(const nsAString& aFormMethod, ErrorResult& aRv) {
    109    SetHTMLAttr(nsGkAtoms::formmethod, aFormMethod, aRv);
    110  }
    111  bool FormNoValidate() const { return GetBoolAttr(nsGkAtoms::formnovalidate); }
    112  void SetFormNoValidate(bool aFormNoValidate, ErrorResult& aError) {
    113    SetHTMLBoolAttr(nsGkAtoms::formnovalidate, aFormNoValidate, aError);
    114  }
    115  void GetFormTarget(DOMString& aFormTarget) {
    116    GetHTMLAttr(nsGkAtoms::formtarget, aFormTarget);
    117  }
    118  void SetFormTarget(const nsAString& aFormTarget, ErrorResult& aRv) {
    119    SetHTMLAttr(nsGkAtoms::formtarget, aFormTarget, aRv);
    120  }
    121  void GetName(DOMString& aName) { GetHTMLAttr(nsGkAtoms::name, aName); }
    122  void SetName(const nsAString& aName, ErrorResult& aRv) {
    123    SetHTMLAttr(nsGkAtoms::name, aName, aRv);
    124  }
    125  void GetType(nsAString& aType);
    126  void SetType(const nsAString& aType, ErrorResult& aRv) {
    127    SetHTMLAttr(nsGkAtoms::type, aType, aRv);
    128  }
    129  void GetValue(nsAString& aValue) { GetHTMLAttr(nsGkAtoms::value, aValue); }
    130  void SetValue(const nsAString& aValue, ErrorResult& aRv) {
    131    SetHTMLAttr(nsGkAtoms::value, aValue, aRv);
    132  }
    133 
    134  // Override SetCustomValidity so we update our state properly when it's called
    135  // via bindings.
    136  void SetCustomValidity(const nsAString& aError);
    137 
    138  // Command & CommandFor
    139  Element* GetCommandForElement() const;
    140  void SetCommandForElement(Element*);
    141  void GetCommand(nsAString& aCommand) const;
    142  Element::Command GetCommand() const;
    143  void SetCommand(const nsAString& aValue) {
    144    SetHTMLAttr(nsGkAtoms::command, aValue);
    145  }
    146 
    147 protected:
    148  virtual ~HTMLButtonElement();
    149 
    150  bool InAutoState() const;
    151  const nsAttrValue::EnumTableEntry* ResolveAutoState() const;
    152 
    153  bool mDisabledChanged : 1;
    154  bool mInInternalActivate : 1;
    155  bool mInhibitStateRestoration : 1;
    156 };
    157 
    158 }  // namespace dom
    159 }  // namespace mozilla
    160 
    161 #endif  // mozilla_dom_HTMLButtonElement_h