LCOV - code coverage report
Current view: top level - dom/html - nsGenericHTMLElement.h (source / functions) Hit Total Coverage
Test: output.info Lines: 30 342 8.8 %
Date: 2017-07-14 16:53:18 Functions: 14 125 11.2 %
Legend: Lines: hit not hit

          Line data    Source code
       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             : #ifndef nsGenericHTMLElement_h___
       7             : #define nsGenericHTMLElement_h___
       8             : 
       9             : #include "mozilla/Attributes.h"
      10             : #include "mozilla/EventForwards.h"
      11             : #include "nsMappedAttributeElement.h"
      12             : #include "nsIDOMHTMLElement.h"
      13             : #include "nsNameSpaceManager.h"  // for kNameSpaceID_None
      14             : #include "nsIFormControl.h"
      15             : #include "nsGkAtoms.h"
      16             : #include "nsContentCreatorFunctions.h"
      17             : #include "mozilla/ErrorResult.h"
      18             : #include "nsIDOMHTMLMenuElement.h"
      19             : #include "mozilla/dom/BindingDeclarations.h"
      20             : #include "mozilla/dom/DOMRect.h"
      21             : #include "mozilla/dom/ValidityState.h"
      22             : #include "mozilla/dom/Element.h"
      23             : 
      24             : class nsDOMTokenList;
      25             : class nsIDOMHTMLMenuElement;
      26             : class nsIEditor;
      27             : class nsIFormControlFrame;
      28             : class nsIFrame;
      29             : class nsILayoutHistoryState;
      30             : class nsIURI;
      31             : class nsPresState;
      32             : struct nsSize;
      33             : 
      34             : namespace mozilla {
      35             : class EventChainPostVisitor;
      36             : class EventChainPreVisitor;
      37             : class EventChainVisitor;
      38             : class EventListenerManager;
      39             : class EventStates;
      40             : class TextEditor;
      41             : namespace dom {
      42             : class HTMLFormElement;
      43             : class HTMLMenuElement;
      44             : } // namespace dom
      45             : } // namespace mozilla
      46             : 
      47             : typedef nsMappedAttributeElement nsGenericHTMLElementBase;
      48             : 
      49             : /**
      50             :  * A common superclass for HTML elements
      51             :  */
      52             : class nsGenericHTMLElement : public nsGenericHTMLElementBase,
      53             :                              public nsIDOMHTMLElement
      54             : {
      55             : public:
      56             :   using Element::SetTabIndex;
      57             :   using Element::Focus;
      58          97 :   explicit nsGenericHTMLElement(already_AddRefed<mozilla::dom::NodeInfo>& aNodeInfo)
      59          97 :     : nsGenericHTMLElementBase(aNodeInfo)
      60             :   {
      61          97 :     NS_ASSERTION(mNodeInfo->NamespaceID() == kNameSpaceID_XHTML,
      62             :                  "Unexpected namespace");
      63          97 :     AddStatesSilently(NS_EVENT_STATE_LTR);
      64          97 :     SetFlags(NODE_HAS_DIRECTION_LTR);
      65          97 :   }
      66             : 
      67             :   NS_DECL_ISUPPORTS_INHERITED
      68             : 
      69        3656 :   NS_IMPL_FROMCONTENT(nsGenericHTMLElement, kNameSpaceID_XHTML)
      70             : 
      71             :   // From Element
      72             :   nsresult CopyInnerTo(mozilla::dom::Element* aDest, bool aPreallocateChildren);
      73             : 
      74           0 :   void GetTitle(mozilla::dom::DOMString& aTitle)
      75             :   {
      76           0 :     GetHTMLAttr(nsGkAtoms::title, aTitle);
      77           0 :   }
      78           0 :   NS_IMETHOD SetTitle(const nsAString& aTitle) override
      79             :   {
      80           0 :     SetHTMLAttr(nsGkAtoms::title, aTitle);
      81           0 :     return NS_OK;
      82             :   }
      83           0 :   void GetLang(mozilla::dom::DOMString& aLang)
      84             :   {
      85           0 :     GetHTMLAttr(nsGkAtoms::lang, aLang);
      86           0 :   }
      87           0 :   NS_IMETHOD SetLang(const nsAString& aLang) override
      88             :   {
      89           0 :     SetHTMLAttr(nsGkAtoms::lang, aLang);
      90           0 :     return NS_OK;
      91             :   }
      92           0 :   void GetDir(mozilla::dom::DOMString& aDir)
      93             :   {
      94           0 :     GetHTMLEnumAttr(nsGkAtoms::dir, aDir);
      95           0 :   }
      96           0 :   void SetDir(const nsAString& aDir, mozilla::ErrorResult& aError)
      97             :   {
      98           0 :     SetHTMLAttr(nsGkAtoms::dir, aDir, aError);
      99           0 :   }
     100           0 :   bool Hidden() const
     101             :   {
     102           0 :     return GetBoolAttr(nsGkAtoms::hidden);
     103             :   }
     104           0 :   void SetHidden(bool aHidden, mozilla::ErrorResult& aError)
     105             :   {
     106           0 :     SetHTMLBoolAttr(nsGkAtoms::hidden, aHidden, aError);
     107           0 :   }
     108             :   void Click(mozilla::dom::CallerType aCallerType);
     109           0 :   void GetAccessKey(nsString& aAccessKey)
     110             :   {
     111           0 :     GetHTMLAttr(nsGkAtoms::accesskey, aAccessKey);
     112           0 :   }
     113           0 :   void SetAccessKey(const nsAString& aAccessKey, mozilla::ErrorResult& aError)
     114             :   {
     115           0 :     SetHTMLAttr(nsGkAtoms::accesskey, aAccessKey, aError);
     116           0 :   }
     117             :   void GetAccessKeyLabel(nsString& aAccessKeyLabel);
     118           0 :   virtual bool Draggable() const
     119             :   {
     120           0 :     return AttrValueIs(kNameSpaceID_None, nsGkAtoms::draggable,
     121           0 :                        nsGkAtoms::_true, eIgnoreCase);
     122             :   }
     123           0 :   void SetDraggable(bool aDraggable, mozilla::ErrorResult& aError)
     124             :   {
     125           0 :     SetHTMLAttr(nsGkAtoms::draggable,
     126           0 :                 aDraggable ? NS_LITERAL_STRING("true")
     127           0 :                            : NS_LITERAL_STRING("false"),
     128           0 :                 aError);
     129           0 :   }
     130           0 :   void GetContentEditable(nsString& aContentEditable)
     131             :   {
     132           0 :     ContentEditableTristate value = GetContentEditableValue();
     133           0 :     if (value == eTrue) {
     134           0 :       aContentEditable.AssignLiteral("true");
     135           0 :     } else if (value == eFalse) {
     136           0 :       aContentEditable.AssignLiteral("false");
     137             :     } else {
     138           0 :       aContentEditable.AssignLiteral("inherit");
     139             :     }
     140           0 :   }
     141           0 :   void SetContentEditable(const nsAString& aContentEditable,
     142             :                           mozilla::ErrorResult& aError)
     143             :   {
     144           0 :     if (aContentEditable.LowerCaseEqualsLiteral("inherit")) {
     145           0 :       UnsetHTMLAttr(nsGkAtoms::contenteditable, aError);
     146           0 :     } else if (aContentEditable.LowerCaseEqualsLiteral("true")) {
     147           0 :       SetHTMLAttr(nsGkAtoms::contenteditable, NS_LITERAL_STRING("true"), aError);
     148           0 :     } else if (aContentEditable.LowerCaseEqualsLiteral("false")) {
     149           0 :       SetHTMLAttr(nsGkAtoms::contenteditable, NS_LITERAL_STRING("false"), aError);
     150             :     } else {
     151           0 :       aError.Throw(NS_ERROR_DOM_SYNTAX_ERR);
     152             :     }
     153           0 :   }
     154           0 :   bool IsContentEditable()
     155             :   {
     156           0 :     for (nsIContent* node = this; node; node = node->GetParent()) {
     157           0 :       nsGenericHTMLElement* element = FromContent(node);
     158           0 :       if (element) {
     159           0 :         ContentEditableTristate value = element->GetContentEditableValue();
     160           0 :         if (value != eInherit) {
     161           0 :           return value == eTrue;
     162             :         }
     163             :       }
     164             :     }
     165           0 :     return false;
     166             :   }
     167             : 
     168             :   /**
     169             :    * Returns the count of descendants (inclusive of this node) in
     170             :    * the uncomposed document that are explicitly set as editable.
     171             :    */
     172             :   uint32_t EditableInclusiveDescendantCount();
     173             : 
     174             :   mozilla::dom::HTMLMenuElement* GetContextMenu() const;
     175             :   bool Spellcheck();
     176           0 :   void SetSpellcheck(bool aSpellcheck, mozilla::ErrorResult& aError)
     177             :   {
     178           0 :     SetHTMLAttr(nsGkAtoms::spellcheck,
     179           0 :                 aSpellcheck ? NS_LITERAL_STRING("true")
     180           0 :                             : NS_LITERAL_STRING("false"),
     181           0 :                 aError);
     182           0 :   }
     183             : 
     184             :   void GetInnerText(mozilla::dom::DOMString& aValue, mozilla::ErrorResult& aError);
     185             :   void SetInnerText(const nsAString& aValue);
     186             : 
     187             :   /**
     188             :    * Determine whether an attribute is an event (onclick, etc.)
     189             :    * @param aName the attribute
     190             :    * @return whether the name is an event handler name
     191             :    */
     192             :   virtual bool IsEventAttributeNameInternal(nsIAtom* aName) override;
     193             : 
     194             : #define EVENT(name_, id_, type_, struct_) /* nothing; handled by nsINode */
     195             : // The using nsINode::Get/SetOn* are to avoid warnings about shadowing the XPCOM
     196             : // getter and setter on nsINode.
     197             : #define FORWARDED_EVENT(name_, id_, type_, struct_)                           \
     198             :   using nsINode::GetOn##name_;                                                \
     199             :   using nsINode::SetOn##name_;                                                \
     200             :   mozilla::dom::EventHandlerNonNull* GetOn##name_();                          \
     201             :   void SetOn##name_(mozilla::dom::EventHandlerNonNull* handler);
     202             : #define ERROR_EVENT(name_, id_, type_, struct_)                               \
     203             :   using nsINode::GetOn##name_;                                                \
     204             :   using nsINode::SetOn##name_;                                                \
     205             :   already_AddRefed<mozilla::dom::EventHandlerNonNull> GetOn##name_();         \
     206             :   void SetOn##name_(mozilla::dom::EventHandlerNonNull* handler);
     207             : #include "mozilla/EventNameList.h" // IWYU pragma: keep
     208             : #undef ERROR_EVENT
     209             : #undef FORWARDED_EVENT
     210             : #undef EVENT
     211           0 :   mozilla::dom::Element* GetOffsetParent()
     212             :   {
     213           0 :     mozilla::CSSIntRect rcFrame;
     214           0 :     return GetOffsetRect(rcFrame);
     215             :   }
     216           0 :   int32_t OffsetTop()
     217             :   {
     218           0 :     mozilla::CSSIntRect rcFrame;
     219           0 :     GetOffsetRect(rcFrame);
     220             : 
     221           0 :     return rcFrame.y;
     222             :   }
     223           0 :   int32_t OffsetLeft()
     224             :   {
     225           0 :     mozilla::CSSIntRect rcFrame;
     226           0 :     GetOffsetRect(rcFrame);
     227             : 
     228           0 :     return rcFrame.x;
     229             :   }
     230           0 :   int32_t OffsetWidth()
     231             :   {
     232           0 :     mozilla::CSSIntRect rcFrame;
     233           0 :     GetOffsetRect(rcFrame);
     234             : 
     235           0 :     return rcFrame.width;
     236             :   }
     237           0 :   int32_t OffsetHeight()
     238             :   {
     239           0 :     mozilla::CSSIntRect rcFrame;
     240           0 :     GetOffsetRect(rcFrame);
     241             : 
     242           0 :     return rcFrame.height;
     243             :   }
     244             : 
     245             :   // These methods are already implemented in nsIContent but we want something
     246             :   // faster for HTMLElements ignoring the namespace checking.
     247             :   // This is safe because we already know that we are in the HTML namespace.
     248           0 :   inline bool IsHTMLElement() const
     249             :   {
     250           0 :     return true;
     251             :   }
     252             : 
     253           0 :   inline bool IsHTMLElement(nsIAtom* aTag) const
     254             :   {
     255           0 :     return mNodeInfo->Equals(aTag);
     256             :   }
     257             : 
     258             :   template<typename First, typename... Args>
     259           0 :   inline bool IsAnyOfHTMLElements(First aFirst, Args... aArgs) const
     260             :   {
     261           0 :     return IsNodeInternal(aFirst, aArgs...);
     262             :   }
     263             : 
     264             : protected:
     265           0 :   virtual ~nsGenericHTMLElement() {}
     266             : 
     267             : public:
     268             :   /**
     269             :    * Get width and height, using given image request if attributes are unset.
     270             :    * Pass a reference to the image request, since the method may change the
     271             :    * value and we want to use the updated value.
     272             :    */
     273             :   nsSize GetWidthHeightForImage(RefPtr<imgRequestProxy>& aImageRequest);
     274             : 
     275             :   // XPIDL methods
     276           6 :   NS_FORWARD_NSIDOMNODE_TO_NSINODE
     277             : 
     278           0 :   NS_FORWARD_NSIDOMELEMENT_TO_GENERIC
     279             : 
     280           0 :   NS_IMETHOD GetTitle(nsAString& aTitle) final override {
     281           0 :     mozilla::dom::DOMString title;
     282           0 :     GetTitle(title);
     283           0 :     title.ToString(aTitle);
     284           0 :     return NS_OK;
     285             :   }
     286           0 :   NS_IMETHOD GetLang(nsAString& aLang) final override {
     287           0 :     mozilla::dom::DOMString lang;
     288           0 :     GetLang(lang);
     289           0 :     lang.ToString(aLang);
     290           0 :     return NS_OK;
     291             :   }
     292           0 :   NS_IMETHOD GetDir(nsAString& aDir) final override {
     293           0 :     mozilla::dom::DOMString dir;
     294           0 :     GetDir(dir);
     295           0 :     dir.ToString(aDir);
     296           0 :     return NS_OK;
     297             :   }
     298           0 :   NS_IMETHOD SetDir(const nsAString& aDir) final override {
     299           0 :     mozilla::ErrorResult rv;
     300           0 :     SetDir(aDir, rv);
     301           0 :     return rv.StealNSResult();
     302             :   }
     303           0 :   NS_IMETHOD GetDOMClassName(nsAString& aClassName) final {
     304           0 :     GetHTMLAttr(nsGkAtoms::_class, aClassName);
     305           0 :     return NS_OK;
     306             :   }
     307           0 :   NS_IMETHOD SetDOMClassName(const nsAString& aClassName) final {
     308           0 :     SetClassName(aClassName);
     309           0 :     return NS_OK;
     310             :   }
     311             :   NS_IMETHOD GetDataset(nsISupports** aDataset) final override;
     312           0 :   NS_IMETHOD GetHidden(bool* aHidden) final override {
     313           0 :     *aHidden = Hidden();
     314           0 :     return NS_OK;
     315             :   }
     316           0 :   NS_IMETHOD SetHidden(bool aHidden) final override {
     317           0 :     mozilla::ErrorResult rv;
     318           0 :     SetHidden(aHidden, rv);
     319           0 :     return rv.StealNSResult();
     320             :   }
     321           0 :   NS_IMETHOD DOMBlur() final override {
     322           0 :     mozilla::ErrorResult rv;
     323           0 :     Blur(rv);
     324           0 :     return rv.StealNSResult();
     325             :   }
     326           0 :   NS_IMETHOD GetAccessKey(nsAString& aAccessKey) final override {
     327           0 :     nsString accessKey;
     328           0 :     GetAccessKey(accessKey);
     329           0 :     aAccessKey.Assign(accessKey);
     330           0 :     return NS_OK;
     331             :   }
     332           0 :   NS_IMETHOD SetAccessKey(const nsAString& aAccessKey) final override {
     333           0 :     mozilla::ErrorResult rv;
     334           0 :     SetAccessKey(aAccessKey, rv);
     335           0 :     return rv.StealNSResult();
     336             :   }
     337           0 :   NS_IMETHOD GetAccessKeyLabel(nsAString& aAccessKeyLabel)
     338             :     final override {
     339           0 :     nsString accessKeyLabel;
     340           0 :     GetAccessKeyLabel(accessKeyLabel);
     341           0 :     aAccessKeyLabel.Assign(accessKeyLabel);
     342           0 :     return NS_OK;
     343             :   }
     344           0 :   NS_IMETHOD SetDraggable(bool aDraggable) final override {
     345           0 :     mozilla::ErrorResult rv;
     346           0 :     SetDraggable(aDraggable, rv);
     347           0 :     return rv.StealNSResult();
     348             :   }
     349           0 :   NS_IMETHOD GetContentEditable(nsAString& aContentEditable)
     350             :     final override {
     351           0 :     nsString contentEditable;
     352           0 :     GetContentEditable(contentEditable);
     353           0 :     aContentEditable.Assign(contentEditable);
     354           0 :     return NS_OK;
     355             :   }
     356           0 :   NS_IMETHOD SetContentEditable(const nsAString& aContentEditable)
     357             :     final override {
     358           0 :     mozilla::ErrorResult rv;
     359           0 :     SetContentEditable(aContentEditable, rv);
     360           0 :     return rv.StealNSResult();
     361             :   }
     362           0 :   NS_IMETHOD GetIsContentEditable(bool* aIsContentEditable)
     363             :     final override {
     364           0 :     *aIsContentEditable = IsContentEditable();
     365           0 :     return NS_OK;
     366             :   }
     367             :   NS_IMETHOD GetContextMenu(nsIDOMHTMLMenuElement** aContextMenu)
     368             :     final override;
     369           4 :   NS_IMETHOD GetSpellcheck(bool* aSpellcheck) final override {
     370           4 :     *aSpellcheck = Spellcheck();
     371           4 :     return NS_OK;
     372             :   }
     373           0 :   NS_IMETHOD SetSpellcheck(bool aSpellcheck) final override {
     374           0 :     mozilla::ErrorResult rv;
     375           0 :     SetSpellcheck(aSpellcheck, rv);
     376           0 :     return rv.StealNSResult();
     377             :   }
     378           0 :   NS_IMETHOD GetOuterHTML(nsAString& aOuterHTML) final override {
     379           0 :     mozilla::dom::Element::GetOuterHTML(aOuterHTML);
     380           0 :     return NS_OK;
     381             :   }
     382           0 :   NS_IMETHOD SetOuterHTML(const nsAString& aOuterHTML) final override {
     383           0 :     mozilla::ErrorResult rv;
     384           0 :     mozilla::dom::Element::SetOuterHTML(aOuterHTML, rv);
     385           0 :     return rv.StealNSResult();
     386             :   }
     387             :   NS_IMETHOD InsertAdjacentHTML(const nsAString& position,
     388             :                                 const nsAString& text) final override;
     389           0 :   NS_IMETHOD ScrollIntoView(bool top, uint8_t _argc) final override {
     390           0 :     if (!_argc) {
     391           0 :       top = true;
     392             :     }
     393           0 :     mozilla::dom::Element::ScrollIntoView(top);
     394           0 :     return NS_OK;
     395             :   }
     396           0 :   NS_IMETHOD GetOffsetParent(nsIDOMElement** aOffsetParent)
     397             :     final override {
     398           0 :     mozilla::dom::Element* offsetParent = GetOffsetParent();
     399           0 :     if (!offsetParent) {
     400           0 :       *aOffsetParent = nullptr;
     401           0 :       return NS_OK;
     402             :     }
     403           0 :     return CallQueryInterface(offsetParent, aOffsetParent);
     404             :   }
     405           0 :   NS_IMETHOD GetOffsetTop(int32_t* aOffsetTop) final override {
     406           0 :     *aOffsetTop = OffsetTop();
     407           0 :     return NS_OK;
     408             :   }
     409           0 :   NS_IMETHOD GetOffsetLeft(int32_t* aOffsetLeft) final override {
     410           0 :     *aOffsetLeft = OffsetLeft();
     411           0 :     return NS_OK;
     412             :   }
     413           0 :   NS_IMETHOD GetOffsetWidth(int32_t* aOffsetWidth) final override {
     414           0 :     *aOffsetWidth = OffsetWidth();
     415           0 :     return NS_OK;
     416             :   }
     417           0 :   NS_IMETHOD GetOffsetHeight(int32_t* aOffsetHeight) final override {
     418           0 :     *aOffsetHeight = OffsetHeight();
     419           0 :     return NS_OK;
     420             :   }
     421           0 :   NS_IMETHOD GetTabIndex(int32_t* aTabIndex) final override {
     422           0 :     *aTabIndex = TabIndex();
     423           0 :     return NS_OK;
     424             :   }
     425           0 :   NS_IMETHOD SetTabIndex(int32_t aTabIndex) final override {
     426           0 :     mozilla::ErrorResult rv;
     427           0 :     SetTabIndex(aTabIndex, rv);
     428           0 :     return rv.StealNSResult();
     429             :   }
     430           0 :   NS_IMETHOD Focus() final override {
     431           0 :     mozilla::ErrorResult rv;
     432           0 :     Focus(rv);
     433           0 :     return rv.StealNSResult();
     434             :   }
     435           0 :   NS_IMETHOD GetDraggable(bool* aDraggable) final override {
     436           0 :     *aDraggable = Draggable();
     437           0 :     return NS_OK;
     438             :   }
     439           0 :   NS_IMETHOD GetInnerHTML(nsAString& aInnerHTML) override {
     440           0 :     return mozilla::dom::Element::GetInnerHTML(aInnerHTML);
     441             :   }
     442             :   using mozilla::dom::Element::SetInnerHTML;
     443           0 :   NS_IMETHOD SetInnerHTML(const nsAString& aInnerHTML) final override {
     444           0 :     mozilla::ErrorResult rv;
     445           0 :     SetInnerHTML(aInnerHTML, rv);
     446           0 :     return rv.StealNSResult();
     447             :   }
     448             : 
     449             :   using nsGenericHTMLElementBase::GetOwnerDocument;
     450             : 
     451           4 :   virtual nsIDOMNode* AsDOMNode() override { return this; }
     452             : 
     453             : public:
     454             :   // Implementation for nsIContent
     455             :   virtual nsresult BindToTree(nsIDocument* aDocument, nsIContent* aParent,
     456             :                               nsIContent* aBindingParent,
     457             :                               bool aCompileEventHandlers) override;
     458             :   virtual void UnbindFromTree(bool aDeep = true,
     459             :                               bool aNullParent = true) override;
     460             : 
     461           0 :   virtual bool IsFocusableInternal(int32_t *aTabIndex, bool aWithMouse) override
     462             :   {
     463           0 :     bool isFocusable = false;
     464           0 :     IsHTMLFocusable(aWithMouse, &isFocusable, aTabIndex);
     465           0 :     return isFocusable;
     466             :   }
     467             :   /**
     468             :    * Returns true if a subclass is not allowed to override the value returned
     469             :    * in aIsFocusable.
     470             :    */
     471             :   virtual bool IsHTMLFocusable(bool aWithMouse,
     472             :                                bool *aIsFocusable,
     473             :                                int32_t *aTabIndex);
     474             :   virtual bool PerformAccesskey(bool aKeyCausesActivation,
     475             :                                 bool aIsTrustedEvent) override;
     476             : 
     477             :   /**
     478             :    * Check if an event for an anchor can be handled
     479             :    * @return true if the event can be handled, false otherwise
     480             :    */
     481             :   bool CheckHandleEventForAnchorsPreconditions(
     482             :          mozilla::EventChainVisitor& aVisitor);
     483             :   nsresult GetEventTargetParentForAnchors(
     484             :              mozilla::EventChainPreVisitor& aVisitor);
     485             :   nsresult PostHandleEventForAnchors(mozilla::EventChainPostVisitor& aVisitor);
     486             :   bool IsHTMLLink(nsIURI** aURI) const;
     487             : 
     488             :   // HTML element methods
     489           1 :   void Compact() { mAttrsAndChildren.Compact(); }
     490             : 
     491             :   virtual void UpdateEditableState(bool aNotify) override;
     492             : 
     493             :   virtual mozilla::EventStates IntrinsicState() const override;
     494             : 
     495             :   // Helper for setting our editable flag and notifying
     496           0 :   void DoSetEditableFlag(bool aEditable, bool aNotify) {
     497           0 :     SetEditableFlag(aEditable);
     498           0 :     UpdateState(aNotify);
     499           0 :   }
     500             : 
     501             :   virtual bool ParseAttribute(int32_t aNamespaceID,
     502             :                               nsIAtom* aAttribute,
     503             :                               const nsAString& aValue,
     504             :                               nsAttrValue& aResult) override;
     505             : 
     506             :   bool ParseBackgroundAttribute(int32_t aNamespaceID,
     507             :                                 nsIAtom* aAttribute,
     508             :                                 const nsAString& aValue,
     509             :                                 nsAttrValue& aResult);
     510             : 
     511             :   NS_IMETHOD_(bool) IsAttributeMapped(const nsIAtom* aAttribute) const override;
     512             :   virtual nsMapRuleToAttributesFunc GetAttributeMappingFunction() const override;
     513             : 
     514             :   /**
     515             :    * Get the base target for any links within this piece
     516             :    * of content. Generally, this is the document's base target,
     517             :    * but certain content carries a local base for backward
     518             :    * compatibility.
     519             :    *
     520             :    * @param aBaseTarget the base target [OUT]
     521             :    */
     522             :   void GetBaseTarget(nsAString& aBaseTarget) const;
     523             : 
     524             :   /**
     525             :    * Get the primary form control frame for this element.  Same as
     526             :    * GetPrimaryFrame(), except it QI's to nsIFormControlFrame.
     527             :    *
     528             :    * @param aFlush whether to flush out frames so that they're up to date.
     529             :    * @return the primary frame as nsIFormControlFrame
     530             :    */
     531             :   nsIFormControlFrame* GetFormControlFrame(bool aFlushFrames);
     532             : 
     533             :   //----------------------------------------
     534             : 
     535             :   /**
     536             :    * Parse an alignment attribute (top/middle/bottom/baseline)
     537             :    *
     538             :    * @param aString the string to parse
     539             :    * @param aResult the resulting HTMLValue
     540             :    * @return whether the value was parsed
     541             :    */
     542             :   static bool ParseAlignValue(const nsAString& aString,
     543             :                                 nsAttrValue& aResult);
     544             : 
     545             :   /**
     546             :    * Parse a div align string to value (left/right/center/middle/justify)
     547             :    *
     548             :    * @param aString the string to parse
     549             :    * @param aResult the resulting HTMLValue
     550             :    * @return whether the value was parsed
     551             :    */
     552             :   static bool ParseDivAlignValue(const nsAString& aString,
     553             :                                    nsAttrValue& aResult);
     554             : 
     555             :   /**
     556             :    * Convert a table halign string to value (left/right/center/char/justify)
     557             :    *
     558             :    * @param aString the string to parse
     559             :    * @param aResult the resulting HTMLValue
     560             :    * @return whether the value was parsed
     561             :    */
     562             :   static bool ParseTableHAlignValue(const nsAString& aString,
     563             :                                       nsAttrValue& aResult);
     564             : 
     565             :   /**
     566             :    * Convert a table cell halign string to value
     567             :    *
     568             :    * @param aString the string to parse
     569             :    * @param aResult the resulting HTMLValue
     570             :    * @return whether the value was parsed
     571             :    */
     572             :   static bool ParseTableCellHAlignValue(const nsAString& aString,
     573             :                                           nsAttrValue& aResult);
     574             : 
     575             :   /**
     576             :    * Convert a table valign string to value (left/right/center/char/justify/
     577             :    * abscenter/absmiddle/middle)
     578             :    *
     579             :    * @param aString the string to parse
     580             :    * @param aResult the resulting HTMLValue
     581             :    * @return whether the value was parsed
     582             :    */
     583             :   static bool ParseTableVAlignValue(const nsAString& aString,
     584             :                                       nsAttrValue& aResult);
     585             : 
     586             :   /**
     587             :    * Convert an image attribute to value (width, height, hspace, vspace, border)
     588             :    *
     589             :    * @param aAttribute the attribute to parse
     590             :    * @param aString the string to parse
     591             :    * @param aResult the resulting HTMLValue
     592             :    * @return whether the value was parsed
     593             :    */
     594             :   static bool ParseImageAttribute(nsIAtom* aAttribute,
     595             :                                     const nsAString& aString,
     596             :                                     nsAttrValue& aResult);
     597             : 
     598             :   static bool ParseReferrerAttribute(const nsAString& aString,
     599             :                                      nsAttrValue& aResult);
     600             : 
     601             :   /**
     602             :    * Convert a frameborder string to value (yes/no/1/0)
     603             :    *
     604             :    * @param aString the string to parse
     605             :    * @param aResult the resulting HTMLValue
     606             :    * @return whether the value was parsed
     607             :    */
     608             :   static bool ParseFrameborderValue(const nsAString& aString,
     609             :                                       nsAttrValue& aResult);
     610             : 
     611             :   /**
     612             :    * Convert a scrolling string to value (yes/no/on/off/scroll/noscroll/auto)
     613             :    *
     614             :    * @param aString the string to parse
     615             :    * @param aResult the resulting HTMLValue
     616             :    * @return whether the value was parsed
     617             :    */
     618             :   static bool ParseScrollingValue(const nsAString& aString,
     619             :                                     nsAttrValue& aResult);
     620             : 
     621             :   /*
     622             :    * Attribute Mapping Helpers
     623             :    */
     624             : 
     625             :   /**
     626             :    * A style attribute mapping function for the most common attributes, to be
     627             :    * called by subclasses' attribute mapping functions.  Currently handles
     628             :    * dir, lang and hidden, could handle others.
     629             :    *
     630             :    * @param aAttributes the list of attributes to map
     631             :    * @param aData the returned rule data [INOUT]
     632             :    * @see GetAttributeMappingFunction
     633             :    */
     634             :   static void MapCommonAttributesInto(const nsMappedAttributes* aAttributes,
     635             :                                       mozilla::GenericSpecifiedValues* aGenericData);
     636             :   /**
     637             :    * Same as MapCommonAttributesInto except that it does not handle hidden.
     638             :    *
     639             :    * @param aAttributes the list of attributes to map
     640             :    * @param aData the returned rule data [INOUT]
     641             :    * @see GetAttributeMappingFunction
     642             :    */
     643             :   static void MapCommonAttributesIntoExceptHidden(const nsMappedAttributes* aAttributes,
     644             :                                                   mozilla::GenericSpecifiedValues* aGenericData);
     645             : 
     646             :   static const MappedAttributeEntry sCommonAttributeMap[];
     647             :   static const MappedAttributeEntry sImageMarginSizeAttributeMap[];
     648             :   static const MappedAttributeEntry sImageBorderAttributeMap[];
     649             :   static const MappedAttributeEntry sImageAlignAttributeMap[];
     650             :   static const MappedAttributeEntry sDivAlignAttributeMap[];
     651             :   static const MappedAttributeEntry sBackgroundAttributeMap[];
     652             :   static const MappedAttributeEntry sBackgroundColorAttributeMap[];
     653             : 
     654             :   /**
     655             :    * Helper to map the align attribute into a style struct.
     656             :    *
     657             :    * @param aAttributes the list of attributes to map
     658             :    * @param aData the returned rule data [INOUT]
     659             :    * @see GetAttributeMappingFunction
     660             :    */
     661             :   static void MapImageAlignAttributeInto(const nsMappedAttributes* aAttributes,
     662             :                                          mozilla::GenericSpecifiedValues* aGenericData);
     663             : 
     664             :   /**
     665             :    * Helper to map the align attribute into a style struct for things
     666             :    * like <div>, <h1>, etc.
     667             :    *
     668             :    * @param aAttributes the list of attributes to map
     669             :    * @param aData the returned rule data [INOUT]
     670             :    * @see GetAttributeMappingFunction
     671             :    */
     672             :   static void MapDivAlignAttributeInto(const nsMappedAttributes* aAttributes,
     673             :                                        mozilla::GenericSpecifiedValues* aGenericData);
     674             : 
     675             :   /**
     676             :    * Helper to map the valign attribute into a style struct for things
     677             :    * like <col>, <tr>, <section>, etc.
     678             :    *
     679             :    * @param aAttributes the list of attributes to map
     680             :    * @param aData the returned rule data [INOUT]
     681             :    * @see GetAttributeMappingFunction
     682             :    */
     683             :   static void MapVAlignAttributeInto(const nsMappedAttributes* aAttributes,
     684             :                                      mozilla::GenericSpecifiedValues* aGenericData);
     685             : 
     686             :   /**
     687             :    * Helper to map the image border attribute into a style struct.
     688             :    *
     689             :    * @param aAttributes the list of attributes to map
     690             :    * @param aData the returned rule data [INOUT]
     691             :    * @see GetAttributeMappingFunction
     692             :    */
     693             :   static void MapImageBorderAttributeInto(const nsMappedAttributes* aAttributes,
     694             :                                           mozilla::GenericSpecifiedValues* aGenericData);
     695             :   /**
     696             :    * Helper to map the image margin attribute into a style struct.
     697             :    *
     698             :    * @param aAttributes the list of attributes to map
     699             :    * @param aData the returned rule data [INOUT]
     700             :    * @see GetAttributeMappingFunction
     701             :    */
     702             :   static void MapImageMarginAttributeInto(const nsMappedAttributes* aAttributes,
     703             :                                           mozilla::GenericSpecifiedValues* aGenericData);
     704             :   /**
     705             :    * Helper to map the image position attribute into a style struct.
     706             :    *
     707             :    * @param aAttributes the list of attributes to map
     708             :    * @param aData the returned rule data [INOUT]
     709             :    * @see GetAttributeMappingFunction
     710             :    */
     711             :   static void MapImageSizeAttributesInto(const nsMappedAttributes* aAttributes,
     712             :                                          mozilla::GenericSpecifiedValues* aGenericData);
     713             : 
     714             :   /**
     715             :    * Helper to map `width` attribute into a style struct.
     716             :    *
     717             :    * @param aAttributes the list of attributes to map
     718             :    * @param aData the returned rule data [INOUT]
     719             :    * @see GetAttributeMappingFunction
     720             :    */
     721             :   static void MapWidthAttributeInto(const nsMappedAttributes* aAttributes,
     722             :                                     mozilla::GenericSpecifiedValues* aGenericData);
     723             :   /**
     724             :    * Helper to map `height` attribute into a style struct.
     725             :    *
     726             :    * @param aAttributes the list of attributes to map
     727             :    * @param aData the returned rule data [INOUT]
     728             :    * @see GetAttributeMappingFunction
     729             :    */
     730             :   static void MapHeightAttributeInto(const nsMappedAttributes* aAttributes,
     731             :                                      mozilla::GenericSpecifiedValues* aGenericData);
     732             :   /**
     733             :    * Helper to map the background attribute
     734             :    * into a style struct.
     735             :    *
     736             :    * @param aAttributes the list of attributes to map
     737             :    * @param aData the returned rule data [INOUT]
     738             :    * @see GetAttributeMappingFunction
     739             :    */
     740             :   static void MapBackgroundInto(const nsMappedAttributes* aAttributes,
     741             :                                 mozilla::GenericSpecifiedValues* aGenericData);
     742             :   /**
     743             :    * Helper to map the bgcolor attribute
     744             :    * into a style struct.
     745             :    *
     746             :    * @param aAttributes the list of attributes to map
     747             :    * @param aData the returned rule data [INOUT]
     748             :    * @see GetAttributeMappingFunction
     749             :    */
     750             :   static void MapBGColorInto(const nsMappedAttributes* aAttributes,
     751             :                              mozilla::GenericSpecifiedValues* aGenericData);
     752             :   /**
     753             :    * Helper to map the background attributes (currently background and bgcolor)
     754             :    * into a style struct.
     755             :    *
     756             :    * @param aAttributes the list of attributes to map
     757             :    * @param aData the returned rule data [INOUT]
     758             :    * @see GetAttributeMappingFunction
     759             :    */
     760             :   static void MapBackgroundAttributesInto(const nsMappedAttributes* aAttributes,
     761             :                                           mozilla::GenericSpecifiedValues* aGenericData);
     762             :   /**
     763             :    * Helper to map the scrolling attribute on FRAME and IFRAME
     764             :    * into a style struct.
     765             :    *
     766             :    * @param aAttributes the list of attributes to map
     767             :    * @param aData the returned rule data [INOUT]
     768             :    * @see GetAttributeMappingFunction
     769             :    */
     770             :   static void MapScrollingAttributeInto(const nsMappedAttributes* aAttributes,
     771             :                                         mozilla::GenericSpecifiedValues* aGenericData);
     772             :   /**
     773             :    * Get the presentation context for this content node.
     774             :    * @return the presentation context
     775             :    */
     776             :   enum PresContextFor
     777             :   {
     778             :     eForComposedDoc,
     779             :     eForUncomposedDoc
     780             :   };
     781             :   nsPresContext* GetPresContext(PresContextFor aFor);
     782             : 
     783             :   // Form Helper Routines
     784             :   /**
     785             :    * Find an ancestor of this content node which is a form (could be null)
     786             :    * @param aCurrentForm the current form for this node.  If this is
     787             :    *        non-null, and no ancestor form is found, and the current form is in
     788             :    *        a connected subtree with the node, the current form will be
     789             :    *        returned.  This is needed to handle cases when HTML elements have a
     790             :    *        current form that they're not descendants of.
     791             :    * @note This method should not be called if the element has a form attribute.
     792             :    */
     793             :   mozilla::dom::HTMLFormElement*
     794             :   FindAncestorForm(mozilla::dom::HTMLFormElement* aCurrentForm = nullptr);
     795             : 
     796             :   virtual void RecompileScriptEventListeners() override;
     797             : 
     798             :   /**
     799             :    * See if the document being tested has nav-quirks mode enabled.
     800             :    * @param doc the document
     801             :    */
     802             :   static bool InNavQuirksMode(nsIDocument* aDoc);
     803             : 
     804             :   /**
     805             :    * Helper method for NS_IMPL_URI_ATTR macro.
     806             :    * Gets the absolute URI value of an attribute, by resolving any relative
     807             :    * URIs in the attribute against the baseuri of the element. If the attribute
     808             :    * isn't a relative URI the value of the attribute is returned as is. Only
     809             :    * works for attributes in null namespace.
     810             :    *
     811             :    * @param aAttr      name of attribute.
     812             :    * @param aBaseAttr  name of base attribute.
     813             :    * @param aResult    result value [out]
     814             :    */
     815             :   void GetURIAttr(nsIAtom* aAttr, nsIAtom* aBaseAttr, nsAString& aResult) const;
     816             : 
     817             :   /**
     818             :    * Gets the absolute URI values of an attribute, by resolving any relative
     819             :    * URIs in the attribute against the baseuri of the element. If a substring
     820             :    * isn't a relative URI, the substring is returned as is. Only works for
     821             :    * attributes in null namespace.
     822             :    */
     823             :   bool GetURIAttr(nsIAtom* aAttr, nsIAtom* aBaseAttr, nsIURI** aURI) const;
     824             : 
     825             :   /**
     826             :    * Returns the current disabled state of the element.
     827             :    */
     828           0 :   virtual bool IsDisabled() const {
     829           0 :     return false;
     830             :   }
     831             : 
     832           0 :   bool IsHidden() const
     833             :   {
     834           0 :     return HasAttr(kNameSpaceID_None, nsGkAtoms::hidden);
     835             :   }
     836             : 
     837             :   virtual bool IsLabelable() const override;
     838             : 
     839             :   static bool MatchLabelsElement(Element* aElement, int32_t aNamespaceID,
     840             :                                  nsIAtom* aAtom, void* aData);
     841             : 
     842             :   already_AddRefed<nsINodeList> Labels();
     843             : 
     844             :   virtual bool IsInteractiveHTMLContent(bool aIgnoreTabindex) const override;
     845             : 
     846             :   static bool TouchEventsEnabled(JSContext* /* unused */, JSObject* /* unused */);
     847             : 
     848             :   static inline bool
     849           0 :   CanHaveName(nsIAtom* aTag)
     850             :   {
     851           0 :     return aTag == nsGkAtoms::img ||
     852           0 :            aTag == nsGkAtoms::form ||
     853           0 :            aTag == nsGkAtoms::applet ||
     854           0 :            aTag == nsGkAtoms::embed ||
     855           0 :            aTag == nsGkAtoms::object;
     856             :   }
     857             :   static inline bool
     858           0 :   ShouldExposeNameAsHTMLDocumentProperty(Element* aElement)
     859             :   {
     860           0 :     return aElement->IsHTMLElement() &&
     861           0 :            CanHaveName(aElement->NodeInfo()->NameAtom());
     862             :   }
     863             :   static inline bool
     864        2158 :   ShouldExposeIdAsHTMLDocumentProperty(Element* aElement)
     865             :   {
     866        2158 :     if (aElement->IsAnyOfHTMLElements(nsGkAtoms::applet,
     867             :                                       nsGkAtoms::embed,
     868             :                                       nsGkAtoms::object)) {
     869           0 :       return true;
     870             :     }
     871             : 
     872             :     // Per spec, <img> is exposed by id only if it also has a nonempty
     873             :     // name (which doesn't have to match the id or anything).
     874             :     // HasName() is true precisely when name is nonempty.
     875        2158 :     return aElement->IsHTMLElement(nsGkAtoms::img) && aElement->HasName();
     876             :   }
     877             : 
     878             : protected:
     879             :   /**
     880             :    * Add/remove this element to the documents name cache
     881             :    */
     882           0 :   void AddToNameTable(nsIAtom* aName) {
     883           0 :     NS_ASSERTION(HasName(), "Node doesn't have name?");
     884           0 :     nsIDocument* doc = GetUncomposedDoc();
     885           0 :     if (doc && !IsInAnonymousSubtree()) {
     886           0 :       doc->AddToNameTable(this, aName);
     887             :     }
     888           0 :   }
     889          10 :   void RemoveFromNameTable() {
     890          10 :     if (HasName()) {
     891           0 :       nsIDocument* doc = GetUncomposedDoc();
     892           0 :       if (doc) {
     893           0 :         doc->RemoveFromNameTable(this, GetParsedAttr(nsGkAtoms::name)->
     894           0 :                                          GetAtomValue());
     895             :       }
     896             :     }
     897          10 :   }
     898             : 
     899             :   /**
     900             :    * Register or unregister an access key to this element based on the
     901             :    * accesskey attribute.
     902             :    */
     903          97 :   void RegAccessKey()
     904             :   {
     905          97 :     if (HasFlag(NODE_HAS_ACCESSKEY)) {
     906           0 :       RegUnRegAccessKey(true);
     907             :     }
     908          97 :   }
     909             : 
     910           6 :   void UnregAccessKey()
     911             :   {
     912           6 :     if (HasFlag(NODE_HAS_ACCESSKEY)) {
     913           0 :       RegUnRegAccessKey(false);
     914             :     }
     915           6 :   }
     916             : 
     917             : private:
     918             :   void RegUnRegAccessKey(bool aDoReg);
     919             : 
     920             : protected:
     921             :   virtual nsresult BeforeSetAttr(int32_t aNamespaceID, nsIAtom* aName,
     922             :                                  const nsAttrValueOrString* aValue,
     923             :                                  bool aNotify) override;
     924             :   virtual nsresult AfterSetAttr(int32_t aNamespaceID, nsIAtom* aName,
     925             :                                 const nsAttrValue* aValue,
     926             :                                 const nsAttrValue* aOldValue,
     927             :                                 bool aNotify) override;
     928             : 
     929             :   virtual mozilla::EventListenerManager*
     930             :     GetEventListenerManagerForAttr(nsIAtom* aAttrName,
     931             :                                    bool* aDefer) override;
     932             : 
     933             :   /**
     934             :    * Dispatch a simulated mouse click by keyboard to the given element.
     935             :    */
     936             :   nsresult DispatchSimulatedClick(nsGenericHTMLElement* aElement,
     937             :                                   bool aIsTrusted,
     938             :                                   nsPresContext* aPresContext);
     939             : 
     940             :   /**
     941             :    * Create a URI for the given aURISpec string.
     942             :    * Returns INVALID_STATE_ERR and nulls *aURI if aURISpec is empty
     943             :    * and the document's URI matches the element's base URI.
     944             :    */
     945             :   nsresult NewURIFromString(const nsAString& aURISpec, nsIURI** aURI);
     946             : 
     947           0 :   void GetHTMLAttr(nsIAtom* aName, nsAString& aResult) const
     948             :   {
     949           0 :     GetAttr(kNameSpaceID_None, aName, aResult);
     950           0 :   }
     951           0 :   void GetHTMLAttr(nsIAtom* aName, mozilla::dom::DOMString& aResult) const
     952             :   {
     953           0 :     GetAttr(kNameSpaceID_None, aName, aResult);
     954           0 :   }
     955           0 :   void GetHTMLEnumAttr(nsIAtom* aName, nsAString& aResult) const
     956             :   {
     957           0 :     GetEnumAttr(aName, nullptr, aResult);
     958           0 :   }
     959           0 :   void GetHTMLURIAttr(nsIAtom* aName, nsAString& aResult) const
     960             :   {
     961           0 :     GetURIAttr(aName, nullptr, aResult);
     962           0 :   }
     963             : 
     964           0 :   void SetHTMLAttr(nsIAtom* aName, const nsAString& aValue)
     965             :   {
     966           0 :     SetAttr(kNameSpaceID_None, aName, aValue, true);
     967           0 :   }
     968           0 :   void SetHTMLAttr(nsIAtom* aName, const nsAString& aValue, mozilla::ErrorResult& aError)
     969             :   {
     970           0 :     mozilla::dom::Element::SetAttr(aName, aValue, aError);
     971           0 :   }
     972           0 :   void UnsetHTMLAttr(nsIAtom* aName, mozilla::ErrorResult& aError)
     973             :   {
     974           0 :     mozilla::dom::Element::UnsetAttr(aName, aError);
     975           0 :   }
     976           0 :   void SetHTMLBoolAttr(nsIAtom* aName, bool aValue, mozilla::ErrorResult& aError)
     977             :   {
     978           0 :     if (aValue) {
     979           0 :       SetHTMLAttr(aName, EmptyString(), aError);
     980             :     } else {
     981           0 :       UnsetHTMLAttr(aName, aError);
     982             :     }
     983           0 :   }
     984             :   template<typename T>
     985           0 :   void SetHTMLIntAttr(nsIAtom* aName, T aValue, mozilla::ErrorResult& aError)
     986             :   {
     987           0 :     nsAutoString value;
     988           0 :     value.AppendInt(aValue);
     989             : 
     990           0 :     SetHTMLAttr(aName, value, aError);
     991           0 :   }
     992             : 
     993             :   /**
     994             :    * Helper method for NS_IMPL_STRING_ATTR macro.
     995             :    * Sets the value of an attribute, returns specified default value if the
     996             :    * attribute isn't set. Only works for attributes in null namespace.
     997             :    *
     998             :    * @param aAttr    name of attribute.
     999             :    * @param aDefault default-value to return if attribute isn't set.
    1000             :    * @param aResult  result value [out]
    1001             :    */
    1002             :   nsresult SetAttrHelper(nsIAtom* aAttr, const nsAString& aValue);
    1003             : 
    1004             :   /**
    1005             :    * Helper method for NS_IMPL_INT_ATTR macro.
    1006             :    * Gets the integer-value of an attribute, returns specified default value
    1007             :    * if the attribute isn't set or isn't set to an integer. Only works for
    1008             :    * attributes in null namespace.
    1009             :    *
    1010             :    * @param aAttr    name of attribute.
    1011             :    * @param aDefault default-value to return if attribute isn't set.
    1012             :    */
    1013             :   int32_t GetIntAttr(nsIAtom* aAttr, int32_t aDefault) const;
    1014             : 
    1015             :   /**
    1016             :    * Helper method for NS_IMPL_INT_ATTR macro.
    1017             :    * Sets value of attribute to specified integer. Only works for attributes
    1018             :    * in null namespace.
    1019             :    *
    1020             :    * @param aAttr    name of attribute.
    1021             :    * @param aValue   Integer value of attribute.
    1022             :    */
    1023             :   nsresult SetIntAttr(nsIAtom* aAttr, int32_t aValue);
    1024             : 
    1025             :   /**
    1026             :    * Helper method for NS_IMPL_UINT_ATTR macro.
    1027             :    * Gets the unsigned integer-value of an attribute, returns specified default
    1028             :    * value if the attribute isn't set or isn't set to an integer. Only works for
    1029             :    * attributes in null namespace.
    1030             :    *
    1031             :    * @param aAttr    name of attribute.
    1032             :    * @param aDefault default-value to return if attribute isn't set.
    1033             :    */
    1034             :   uint32_t GetUnsignedIntAttr(nsIAtom* aAttr, uint32_t aDefault) const;
    1035             : 
    1036             :   /**
    1037             :    * Helper method for NS_IMPL_UINT_ATTR macro.
    1038             :    * Sets value of attribute to specified unsigned integer. Only works for
    1039             :    * attributes in null namespace.
    1040             :    *
    1041             :    * @param aAttr    name of attribute.
    1042             :    * @param aValue   Integer value of attribute.
    1043             :    * @param aDefault Default value (in case value is out of range).  If the spec
    1044             :    *                 doesn't provide one, should be 1 if the value is limited to
    1045             :    *                 nonzero values, and 0 otherwise.
    1046             :    */
    1047           0 :   void SetUnsignedIntAttr(nsIAtom* aName, uint32_t aValue, uint32_t aDefault,
    1048             :                           mozilla::ErrorResult& aError)
    1049             :   {
    1050           0 :     nsAutoString value;
    1051           0 :     if (aValue > INT32_MAX) {
    1052           0 :       value.AppendInt(aDefault);
    1053             :     } else {
    1054           0 :       value.AppendInt(aValue);
    1055             :     }
    1056             : 
    1057           0 :     SetHTMLAttr(aName, value, aError);
    1058           0 :   }
    1059             : 
    1060             :   /**
    1061             :    * Sets value of attribute to specified double. Only works for attributes
    1062             :    * in null namespace.
    1063             :    *
    1064             :    * @param aAttr    name of attribute.
    1065             :    * @param aValue   Double value of attribute.
    1066             :    */
    1067           0 :   void SetDoubleAttr(nsIAtom* aAttr, double aValue, mozilla::ErrorResult& aRv)
    1068             :   {
    1069           0 :     nsAutoString value;
    1070           0 :     value.AppendFloat(aValue);
    1071             : 
    1072           0 :     SetHTMLAttr(aAttr, value, aRv);
    1073           0 :   }
    1074             : 
    1075             :   /**
    1076             :    * Locates the nsIEditor associated with this node.  In general this is
    1077             :    * equivalent to GetEditorInternal(), but for designmode or contenteditable,
    1078             :    * this may need to get an editor that's not actually on this element's
    1079             :    * associated TextControlFrame.  This is used by the spellchecking routines
    1080             :    * to get the editor affected by changing the spellcheck attribute on this
    1081             :    * node.
    1082             :    */
    1083             :   virtual already_AddRefed<nsIEditor> GetAssociatedEditor();
    1084             : 
    1085             :   /**
    1086             :    * Get the frame's offset information for offsetTop/Left/Width/Height.
    1087             :    * Returns the parent the offset is relative to.
    1088             :    * @note This method flushes pending notifications (FlushType::Layout).
    1089             :    * @param aRect the offset information [OUT]
    1090             :    */
    1091             :   mozilla::dom::Element* GetOffsetRect(mozilla::CSSIntRect& aRect);
    1092             : 
    1093             :   /**
    1094             :    * Returns true if this is the current document's body element
    1095             :    */
    1096             :   bool IsCurrentBodyElement();
    1097             : 
    1098             :   /**
    1099             :    * Ensures all editors associated with a subtree are synced, for purposes of
    1100             :    * spellchecking.
    1101             :    */
    1102             :   static void SyncEditorsOnSubtree(nsIContent* content);
    1103             : 
    1104             :   enum ContentEditableTristate {
    1105             :     eInherit = -1,
    1106             :     eFalse = 0,
    1107             :     eTrue = 1
    1108             :   };
    1109             : 
    1110             :   /**
    1111             :    * Returns eTrue if the element has a contentEditable attribute and its value
    1112             :    * is "true" or an empty string. Returns eFalse if the element has a
    1113             :    * contentEditable attribute and its value is "false". Otherwise returns
    1114             :    * eInherit.
    1115             :    */
    1116         147 :   ContentEditableTristate GetContentEditableValue() const
    1117             :   {
    1118             :     static const nsIContent::AttrValuesArray values[] =
    1119             :       { &nsGkAtoms::_false, &nsGkAtoms::_true, &nsGkAtoms::_empty, nullptr };
    1120             : 
    1121         147 :     if (!MayHaveContentEditableAttr())
    1122         147 :       return eInherit;
    1123             : 
    1124           0 :     int32_t value = FindAttrValueIn(kNameSpaceID_None,
    1125             :                                     nsGkAtoms::contenteditable, values,
    1126           0 :                                     eIgnoreCase);
    1127             : 
    1128           0 :     return value > 0 ? eTrue : (value == 0 ? eFalse : eInherit);
    1129             :   }
    1130             : 
    1131             :   // Used by A, AREA, LINK, and STYLE.
    1132             :   already_AddRefed<nsIURI> GetHrefURIForAnchors() const;
    1133             : 
    1134             :   /**
    1135             :    * Returns whether this element is an editable root. There are two types of
    1136             :    * editable roots:
    1137             :    *   1) the documentElement if the whole document is editable (for example for
    1138             :    *      desginMode=on)
    1139             :    *   2) an element that is marked editable with contentEditable=true and that
    1140             :    *      doesn't have a parent or whose parent is not editable.
    1141             :    * Note that this doesn't return input and textarea elements that haven't been
    1142             :    * made editable through contentEditable or designMode.
    1143             :    */
    1144             :   bool IsEditableRoot() const;
    1145             : 
    1146             : private:
    1147             :   void ChangeEditableState(int32_t aChange);
    1148             : };
    1149             : 
    1150             : namespace mozilla {
    1151             : namespace dom {
    1152             : class HTMLFieldSetElement;
    1153             : } // namespace dom
    1154             : } // namespace mozilla
    1155             : 
    1156             : #define FORM_ELEMENT_FLAG_BIT(n_) NODE_FLAG_BIT(ELEMENT_TYPE_SPECIFIC_BITS_OFFSET + (n_))
    1157             : 
    1158             : // Form element specific bits
    1159             : enum {
    1160             :   // If this flag is set on an nsGenericHTMLFormElement or an HTMLImageElement,
    1161             :   // that means that we have added ourselves to our mForm.  It's possible to
    1162             :   // have a non-null mForm, but not have this flag set.  That happens when the
    1163             :   // form is set via the content sink.
    1164             :   ADDED_TO_FORM =                         FORM_ELEMENT_FLAG_BIT(0),
    1165             : 
    1166             :   // If this flag is set on an nsGenericHTMLFormElement or an HTMLImageElement,
    1167             :   // that means that its form is in the process of being unbound from the tree,
    1168             :   // and this form element hasn't re-found its form in
    1169             :   // nsGenericHTMLFormElement::UnbindFromTree yet.
    1170             :   MAYBE_ORPHAN_FORM_ELEMENT =             FORM_ELEMENT_FLAG_BIT(1),
    1171             : 
    1172             :   // If this flag is set on an nsGenericHTMLElement or an HTMLImageElement, then
    1173             :   // the element might be in the past names map of its form.
    1174             :   MAY_BE_IN_PAST_NAMES_MAP =              FORM_ELEMENT_FLAG_BIT(2)
    1175             : };
    1176             : 
    1177             : // NOTE: I don't think it's possible to have both ADDED_TO_FORM and
    1178             : // MAYBE_ORPHAN_FORM_ELEMENT set at the same time, so if it becomes an issue we
    1179             : // can probably merge them into the same bit.  --bz
    1180             : 
    1181             : ASSERT_NODE_FLAGS_SPACE(ELEMENT_TYPE_SPECIFIC_BITS_OFFSET + 3);
    1182             : 
    1183             : #undef FORM_ELEMENT_FLAG_BIT
    1184             : 
    1185             : /**
    1186             :  * A helper class for form elements that can contain children
    1187             :  */
    1188             : class nsGenericHTMLFormElement : public nsGenericHTMLElement,
    1189             :                                  public nsIFormControl
    1190             : {
    1191             : public:
    1192             :   nsGenericHTMLFormElement(already_AddRefed<mozilla::dom::NodeInfo>& aNodeInfo,
    1193             :                            uint8_t aType);
    1194             : 
    1195             :   NS_DECL_ISUPPORTS_INHERITED
    1196             : 
    1197             :   nsINode* GetScopeChainParent() const override;
    1198             : 
    1199             :   virtual bool IsNodeOfType(uint32_t aFlags) const override;
    1200             :   virtual void SaveSubtreeState() override;
    1201             : 
    1202             :   // nsIFormControl
    1203             :   virtual mozilla::dom::HTMLFieldSetElement* GetFieldSet() override;
    1204             :   virtual mozilla::dom::Element* GetFormElement() override;
    1205           0 :   mozilla::dom::HTMLFormElement* GetForm() const
    1206             :   {
    1207           0 :     return mForm;
    1208             :   }
    1209             :   virtual void SetForm(nsIDOMHTMLFormElement* aForm) override;
    1210             :   virtual void ClearForm(bool aRemoveFromForm, bool aUnbindOrDelete) override;
    1211             : 
    1212             :   nsresult GetForm(nsIDOMHTMLFormElement** aForm);
    1213             : 
    1214           0 :   NS_IMETHOD SaveState() override
    1215             :   {
    1216           0 :     return NS_OK;
    1217             :   }
    1218             : 
    1219           0 :   virtual bool RestoreState(nsPresState* aState) override
    1220             :   {
    1221           0 :     return false;
    1222             :   }
    1223           0 :   virtual bool AllowDrop() override
    1224             :   {
    1225           0 :     return true;
    1226             :   }
    1227             : 
    1228             :   // nsIContent
    1229             :   virtual nsresult BindToTree(nsIDocument* aDocument, nsIContent* aParent,
    1230             :                               nsIContent* aBindingParent,
    1231             :                               bool aCompileEventHandlers) override;
    1232             :   virtual void UnbindFromTree(bool aDeep = true,
    1233             :                               bool aNullParent = true) override;
    1234             :   virtual IMEState GetDesiredIMEState() override;
    1235             :   virtual mozilla::EventStates IntrinsicState() const override;
    1236             : 
    1237             :   virtual nsresult GetEventTargetParent(
    1238             :                      mozilla::EventChainPreVisitor& aVisitor) override;
    1239             :   virtual nsresult PreHandleEvent(
    1240             :                      mozilla::EventChainVisitor& aVisitor) override;
    1241             :   virtual bool IsDisabled() const override;
    1242             : 
    1243             :   /**
    1244             :    * This callback is called by a fieldest on all its elements whenever its
    1245             :    * disabled attribute is changed so the element knows its disabled state
    1246             :    * might have changed.
    1247             :    *
    1248             :    * @note Classes redefining this method should not do any content
    1249             :    * state updates themselves but should just make sure to call into
    1250             :    * nsGenericHTMLFormElement::FieldSetDisabledChanged.
    1251             :    */
    1252             :   virtual void FieldSetDisabledChanged(bool aNotify);
    1253             : 
    1254           0 :   void FieldSetFirstLegendChanged(bool aNotify) {
    1255           0 :     UpdateFieldSet(aNotify);
    1256           0 :   }
    1257             : 
    1258             :   /**
    1259             :    * This callback is called by a fieldset on all it's elements when it's being
    1260             :    * destroyed. When called, the elements should check that aFieldset is there
    1261             :    * first parent fieldset and null mFieldset in that case only.
    1262             :    *
    1263             :    * @param aFieldSet The fieldset being removed.
    1264             :    */
    1265             :   void ForgetFieldSet(nsIContent* aFieldset);
    1266             : 
    1267             :   /**
    1268             :    * Returns if the control can be disabled.
    1269             :    */
    1270             :   bool CanBeDisabled() const;
    1271             : 
    1272             :   virtual bool IsHTMLFocusable(bool aWithMouse, bool* aIsFocusable,
    1273             :                                  int32_t* aTabIndex) override;
    1274             : 
    1275             :   virtual bool IsLabelable() const override;
    1276             : 
    1277             : protected:
    1278             :   virtual ~nsGenericHTMLFormElement();
    1279             : 
    1280             :   virtual nsresult BeforeSetAttr(int32_t aNameSpaceID, nsIAtom* aName,
    1281             :                                  const nsAttrValueOrString* aValue,
    1282             :                                  bool aNotify) override;
    1283             : 
    1284             :   virtual nsresult AfterSetAttr(int32_t aNameSpaceID, nsIAtom* aName,
    1285             :                                 const nsAttrValue* aValue,
    1286             :                                 const nsAttrValue* aOldValue,
    1287             :                                 bool aNotify) override;
    1288             : 
    1289           0 :   virtual void BeforeSetForm(bool aBindToTree) {}
    1290             : 
    1291           0 :   virtual void AfterClearForm(bool aUnbindOrDelete) {}
    1292             : 
    1293             :   void SetForm(mozilla::dom::HTMLFormElement* aForm, bool aBindToTree);
    1294             : 
    1295             :   /**
    1296             :    * This method will update the form owner, using @form or looking to a parent.
    1297             :    *
    1298             :    * @param aBindToTree Whether the element is being attached to the tree.
    1299             :    * @param aFormIdElement The element associated with the id in @form. If
    1300             :    * aBindToTree is false, aFormIdElement *must* contain the element associated
    1301             :    * with the id in @form. Otherwise, it *must* be null.
    1302             :    *
    1303             :    * @note Callers of UpdateFormOwner have to be sure the element is in a
    1304             :    * document (GetUncomposedDoc() != nullptr).
    1305             :    */
    1306             :   void UpdateFormOwner(bool aBindToTree, Element* aFormIdElement);
    1307             : 
    1308             :   /**
    1309             :    * This method will update mFieldset and set it to the first fieldset parent.
    1310             :    */
    1311             :   void UpdateFieldSet(bool aNotify);
    1312             : 
    1313             :   /**
    1314             :    * Add a form id observer which will observe when the element with the id in
    1315             :    * @form will change.
    1316             :    *
    1317             :    * @return The element associated with the current id in @form (may be null).
    1318             :    */
    1319             :   Element* AddFormIdObserver();
    1320             : 
    1321             :   /**
    1322             :    * Remove the form id observer.
    1323             :    */
    1324             :   void RemoveFormIdObserver();
    1325             : 
    1326             :   /**
    1327             :    * This method is a a callback for IDTargetObserver (from nsIDocument).
    1328             :    * It will be called each time the element associated with the id in @form
    1329             :    * changes.
    1330             :    */
    1331             :   static bool FormIdUpdated(Element* aOldElement, Element* aNewElement,
    1332             :                               void* aData);
    1333             : 
    1334             :   // Returns true if the event should not be handled from GetEventTargetParent
    1335             :   bool IsElementDisabledForEvents(mozilla::EventMessage aMessage,
    1336             :                                   nsIFrame* aFrame);
    1337             : 
    1338             :   // The focusability state of this form control.  eUnfocusable means that it
    1339             :   // shouldn't be focused at all, eInactiveWindow means it's in an inactive
    1340             :   // window, eActiveWindow means it's in an active window.
    1341             :   enum FocusTristate {
    1342             :     eUnfocusable,
    1343             :     eInactiveWindow,
    1344             :     eActiveWindow
    1345             :   };
    1346             : 
    1347             :   // Get our focus state.  If this returns eInactiveWindow, it will set this
    1348             :   // element as the focused element for that window.
    1349             :   FocusTristate FocusState();
    1350             : 
    1351             :   /** The form that contains this control */
    1352             :   mozilla::dom::HTMLFormElement* mForm;
    1353             : 
    1354             :   /* This is a pointer to our closest fieldset parent if any */
    1355             :   mozilla::dom::HTMLFieldSetElement* mFieldSet;
    1356             : };
    1357             : 
    1358           0 : class nsGenericHTMLFormElementWithState : public nsGenericHTMLFormElement
    1359             : {
    1360             : public:
    1361             :   nsGenericHTMLFormElementWithState(already_AddRefed<mozilla::dom::NodeInfo>& aNodeInfo,
    1362             :                                     uint8_t aType);
    1363             : 
    1364             :   /**
    1365             :    * Get the presentation state for a piece of content, or create it if it does
    1366             :    * not exist.  Generally used by SaveState().
    1367             :    */
    1368             :   nsPresState* GetPrimaryPresState();
    1369             : 
    1370             :   /**
    1371             :    * Get the layout history object for a particular piece of content.
    1372             :    *
    1373             :    * @param aRead if true, won't return a layout history state if the
    1374             :    *              layout history state is empty.
    1375             :    * @return the history state object
    1376             :    */
    1377             :   already_AddRefed<nsILayoutHistoryState>
    1378             :     GetLayoutHistory(bool aRead);
    1379             : 
    1380             :   /**
    1381             :    * Restore the state for a form control.  Ends up calling
    1382             :    * nsIFormControl::RestoreState().
    1383             :    *
    1384             :    * @return false if RestoreState() was not called, the return
    1385             :    *         value of RestoreState() otherwise.
    1386             :    */
    1387             :   bool RestoreFormControlState();
    1388             : 
    1389             :   /**
    1390             :    * Called when we have been cloned and adopted, and the information of the
    1391             :    * node has been changed.
    1392             :    */
    1393             :   virtual void NodeInfoChanged(nsIDocument* aOldDoc) override;
    1394             : 
    1395             : protected:
    1396             :   /* Generates the state key for saving the form state in the session if not
    1397             :      computed already. The result is stored in mStateKey on success */
    1398             :   nsresult GenerateStateKey();
    1399             : 
    1400             :   /* Used to store the key to that element in the session. Is void until
    1401             :      GenerateStateKey has been used */
    1402             :   nsCString mStateKey;
    1403             : };
    1404             : 
    1405             : //----------------------------------------------------------------------
    1406             : 
    1407             : /**
    1408             :  * This macro is similar to NS_IMPL_STRING_ATTR except that the getter method
    1409             :  * falls back to an alternative method if the content attribute isn't set.
    1410             :  */
    1411             : #define NS_IMPL_STRING_ATTR_WITH_FALLBACK(_class, _method, _atom, _fallback) \
    1412             :   NS_IMETHODIMP                                                              \
    1413             :   _class::Get##_method(nsAString& aValue)                                    \
    1414             :   {                                                                          \
    1415             :     if (!GetAttr(kNameSpaceID_None, nsGkAtoms::_atom, aValue)) {             \
    1416             :       _fallback(aValue);                                                     \
    1417             :     }                                                                        \
    1418             :     return NS_OK;                                                            \
    1419             :   }                                                                          \
    1420             :   NS_IMETHODIMP                                                              \
    1421             :   _class::Set##_method(const nsAString& aValue)                              \
    1422             :   {                                                                          \
    1423             :     return SetAttrHelper(nsGkAtoms::_atom, aValue);                          \
    1424             :   }
    1425             : 
    1426             : /**
    1427             :  * A macro to implement the getter and setter for a given integer
    1428             :  * valued content property. The method uses the generic GetAttr and
    1429             :  * SetAttr methods.
    1430             :  */
    1431             : #define NS_IMPL_INT_ATTR(_class, _method, _atom)                    \
    1432             :   NS_IMPL_INT_ATTR_DEFAULT_VALUE(_class, _method, _atom, 0)
    1433             : 
    1434             : #define NS_IMPL_INT_ATTR_DEFAULT_VALUE(_class, _method, _atom, _default)  \
    1435             :   NS_IMETHODIMP                                                           \
    1436             :   _class::Get##_method(int32_t* aValue)                                   \
    1437             :   {                                                                       \
    1438             :     *aValue = GetIntAttr(nsGkAtoms::_atom, _default);                     \
    1439             :     return NS_OK;                                                         \
    1440             :   }                                                                       \
    1441             :   NS_IMETHODIMP                                                           \
    1442             :   _class::Set##_method(int32_t aValue)                                    \
    1443             :   {                                                                       \
    1444             :     return SetIntAttr(nsGkAtoms::_atom, aValue);                          \
    1445             :   }
    1446             : 
    1447             : /**
    1448             :  * A macro to implement the getter and setter for a given unsigned integer
    1449             :  * valued content property. The method uses GetUnsignedIntAttr and
    1450             :  * SetUnsignedIntAttr methods.
    1451             :  */
    1452             : #define NS_IMPL_UINT_ATTR(_class, _method, _atom)                         \
    1453             :   NS_IMPL_UINT_ATTR_DEFAULT_VALUE(_class, _method, _atom, 0)
    1454             : 
    1455             : #define NS_IMPL_UINT_ATTR_DEFAULT_VALUE(_class, _method, _atom, _default) \
    1456             :   NS_IMETHODIMP                                                           \
    1457             :   _class::Get##_method(uint32_t* aValue)                                  \
    1458             :   {                                                                       \
    1459             :     *aValue = GetUnsignedIntAttr(nsGkAtoms::_atom, _default);             \
    1460             :     return NS_OK;                                                         \
    1461             :   }                                                                       \
    1462             :   NS_IMETHODIMP                                                           \
    1463             :   _class::Set##_method(uint32_t aValue)                                   \
    1464             :   {                                                                       \
    1465             :     mozilla::ErrorResult rv;                                              \
    1466             :     SetUnsignedIntAttr(nsGkAtoms::_atom, aValue, _default, rv);           \
    1467             :     return rv.StealNSResult();                                            \
    1468             :   }
    1469             : 
    1470             : /**
    1471             :  * A macro to implement the getter and setter for a given unsigned integer
    1472             :  * valued content property. The method uses GetUnsignedIntAttr and
    1473             :  * SetUnsignedIntAttr methods. This macro is similar to NS_IMPL_UINT_ATTR except
    1474             :  * that it throws an exception if the set value is null.
    1475             :  */
    1476             : #define NS_IMPL_UINT_ATTR_NON_ZERO(_class, _method, _atom)                \
    1477             :   NS_IMPL_UINT_ATTR_NON_ZERO_DEFAULT_VALUE(_class, _method, _atom, 1)
    1478             : 
    1479             : #define NS_IMPL_UINT_ATTR_NON_ZERO_DEFAULT_VALUE(_class, _method, _atom, _default) \
    1480             :   NS_IMETHODIMP                                                           \
    1481             :   _class::Get##_method(uint32_t* aValue)                                  \
    1482             :   {                                                                       \
    1483             :     *aValue = GetUnsignedIntAttr(nsGkAtoms::_atom, _default);             \
    1484             :     return NS_OK;                                                         \
    1485             :   }                                                                       \
    1486             :   NS_IMETHODIMP                                                           \
    1487             :   _class::Set##_method(uint32_t aValue)                                   \
    1488             :   {                                                                       \
    1489             :     if (aValue == 0) {                                                    \
    1490             :       return NS_ERROR_DOM_INDEX_SIZE_ERR;                                 \
    1491             :     }                                                                     \
    1492             :     mozilla::ErrorResult rv;                                              \
    1493             :     SetUnsignedIntAttr(nsGkAtoms::_atom, aValue, _default, rv);           \
    1494             :     return rv.StealNSResult();                                            \
    1495             :   }
    1496             : 
    1497             : /**
    1498             :  * A macro to implement the getter and setter for a given content
    1499             :  * property that needs to return a URI in string form.  The method
    1500             :  * uses the generic GetAttr and SetAttr methods.  This macro is much
    1501             :  * like the NS_IMPL_STRING_ATTR macro, except we make sure the URI is
    1502             :  * absolute.
    1503             :  */
    1504             : #define NS_IMPL_URI_ATTR(_class, _method, _atom)                    \
    1505             :   NS_IMETHODIMP                                                     \
    1506             :   _class::Get##_method(nsAString& aValue)                           \
    1507             :   {                                                                 \
    1508             :     GetURIAttr(nsGkAtoms::_atom, nullptr, aValue);                  \
    1509             :     return NS_OK;                                                   \
    1510             :   }                                                                 \
    1511             :   NS_IMETHODIMP                                                     \
    1512             :   _class::Set##_method(const nsAString& aValue)                     \
    1513             :   {                                                                 \
    1514             :     return SetAttrHelper(nsGkAtoms::_atom, aValue);               \
    1515             :   }
    1516             : 
    1517             : #define NS_IMPL_URI_ATTR_WITH_BASE(_class, _method, _atom, _base_atom)       \
    1518             :   NS_IMETHODIMP                                                              \
    1519             :   _class::Get##_method(nsAString& aValue)                                    \
    1520             :   {                                                                          \
    1521             :     GetURIAttr(nsGkAtoms::_atom, nsGkAtoms::_base_atom, aValue);             \
    1522             :     return NS_OK;                                                            \
    1523             :   }                                                                          \
    1524             :   NS_IMETHODIMP                                                              \
    1525             :   _class::Set##_method(const nsAString& aValue)                              \
    1526             :   {                                                                          \
    1527             :     return SetAttrHelper(nsGkAtoms::_atom, aValue);                        \
    1528             :   }
    1529             : 
    1530             : /**
    1531             :  * A macro to implement getter and setter for action and form action content
    1532             :  * attributes. It's very similar to NS_IMPL_URI_ATTR excepted that if the
    1533             :  * content attribute is the empty string, the empty string is returned.
    1534             :  */
    1535             : #define NS_IMPL_ACTION_ATTR(_class, _method, _atom)                 \
    1536             :   NS_IMETHODIMP                                                     \
    1537             :   _class::Get##_method(nsAString& aValue)                           \
    1538             :   {                                                                 \
    1539             :     GetAttr(kNameSpaceID_None, nsGkAtoms::_atom, aValue);           \
    1540             :     if (!aValue.IsEmpty()) {                                        \
    1541             :       GetURIAttr(nsGkAtoms::_atom, nullptr, aValue);                 \
    1542             :     }                                                               \
    1543             :     return NS_OK;                                                   \
    1544             :   }                                                                 \
    1545             :   NS_IMETHODIMP                                                     \
    1546             :   _class::Set##_method(const nsAString& aValue)                     \
    1547             :   {                                                                 \
    1548             :     return SetAttrHelper(nsGkAtoms::_atom, aValue);                 \
    1549             :   }
    1550             : 
    1551             : /**
    1552             :  * A macro to implement the getter and setter for a given content
    1553             :  * property that needs to set a non-negative integer. The method
    1554             :  * uses the generic GetAttr and SetAttr methods. This macro is much
    1555             :  * like the NS_IMPL_INT_ATTR macro except we throw an exception if
    1556             :  * the set value is negative.
    1557             :  */
    1558             : #define NS_IMPL_NON_NEGATIVE_INT_ATTR(_class, _method, _atom)             \
    1559             :   NS_IMPL_NON_NEGATIVE_INT_ATTR_DEFAULT_VALUE(_class, _method, _atom, -1)
    1560             : 
    1561             : #define NS_IMPL_NON_NEGATIVE_INT_ATTR_DEFAULT_VALUE(_class, _method, _atom, _default)  \
    1562             :   NS_IMETHODIMP                                                           \
    1563             :   _class::Get##_method(int32_t* aValue)                                   \
    1564             :   {                                                                       \
    1565             :     *aValue = GetIntAttr(nsGkAtoms::_atom, _default);                     \
    1566             :     return NS_OK;                                                         \
    1567             :   }                                                                       \
    1568             :   NS_IMETHODIMP                                                           \
    1569             :   _class::Set##_method(int32_t aValue)                                    \
    1570             :   {                                                                       \
    1571             :     if (aValue < 0) {                                                     \
    1572             :       return NS_ERROR_DOM_INDEX_SIZE_ERR;                                 \
    1573             :     }                                                                     \
    1574             :     return SetIntAttr(nsGkAtoms::_atom, aValue);                          \
    1575             :   }
    1576             : 
    1577             : /**
    1578             :  * A macro to implement the getter and setter for a given content
    1579             :  * property that needs to set an enumerated string. The method
    1580             :  * uses a specific GetEnumAttr and the generic SetAttrHelper methods.
    1581             :  */
    1582             : #define NS_IMPL_ENUM_ATTR_DEFAULT_VALUE(_class, _method, _atom, _default) \
    1583             :   NS_IMETHODIMP                                                           \
    1584             :   _class::Get##_method(nsAString& aValue)                                 \
    1585             :   {                                                                       \
    1586             :     GetEnumAttr(nsGkAtoms::_atom, _default, aValue);                      \
    1587             :     return NS_OK;                                                         \
    1588             :   }                                                                       \
    1589             :   NS_IMETHODIMP                                                           \
    1590             :   _class::Set##_method(const nsAString& aValue)                           \
    1591             :   {                                                                       \
    1592             :     return SetAttrHelper(nsGkAtoms::_atom, aValue);                       \
    1593             :   }
    1594             : 
    1595             : /**
    1596             :  * A macro to implement the getter and setter for a given content
    1597             :  * property that needs to set an enumerated string that has different
    1598             :  * default values for missing and invalid values. The method uses a
    1599             :  * specific GetEnumAttr and the generic SetAttrHelper methods.
    1600             :  */
    1601             : #define NS_IMPL_ENUM_ATTR_DEFAULT_MISSING_INVALID_VALUES(_class, _method, _atom, _defaultMissing, _defaultInvalid) \
    1602             :   NS_IMETHODIMP                                                                                   \
    1603             :   _class::Get##_method(nsAString& aValue)                                                         \
    1604             :   {                                                                                               \
    1605             :     GetEnumAttr(nsGkAtoms::_atom, _defaultMissing, _defaultInvalid, aValue);                      \
    1606             :     return NS_OK;                                                                                 \
    1607             :   }                                                                                               \
    1608             :   NS_IMETHODIMP                                                                                   \
    1609             :   _class::Set##_method(const nsAString& aValue)                                                   \
    1610             :   {                                                                                               \
    1611             :     return SetAttrHelper(nsGkAtoms::_atom, aValue);                                               \
    1612             :   }
    1613             : 
    1614             : #define NS_INTERFACE_MAP_ENTRY_IF_TAG(_interface, _tag)                       \
    1615             :   NS_INTERFACE_MAP_ENTRY_CONDITIONAL(_interface,                              \
    1616             :                                      mNodeInfo->Equals(nsGkAtoms::_tag))
    1617             : 
    1618             : 
    1619             : /**
    1620             :  * A macro to declare the NS_NewHTMLXXXElement() functions.
    1621             :  */
    1622             : #define NS_DECLARE_NS_NEW_HTML_ELEMENT(_elementName)                       \
    1623             : namespace mozilla {                                                        \
    1624             : namespace dom {                                                            \
    1625             : class HTML##_elementName##Element;                                         \
    1626             : }                                                                          \
    1627             : }                                                                          \
    1628             : nsGenericHTMLElement*                                                      \
    1629             : NS_NewHTML##_elementName##Element(already_AddRefed<mozilla::dom::NodeInfo>&& aNodeInfo, \
    1630             :                                   mozilla::dom::FromParser aFromParser = mozilla::dom::NOT_FROM_PARSER);
    1631             : 
    1632             : #define NS_DECLARE_NS_NEW_HTML_ELEMENT_AS_SHARED(_elementName)             \
    1633             : inline nsGenericHTMLElement*                                               \
    1634             : NS_NewHTML##_elementName##Element(already_AddRefed<mozilla::dom::NodeInfo>&& aNodeInfo, \
    1635             :                                   mozilla::dom::FromParser aFromParser = mozilla::dom::NOT_FROM_PARSER) \
    1636             : {                                                                          \
    1637             :   return NS_NewHTMLSharedElement(mozilla::Move(aNodeInfo), aFromParser);   \
    1638             : }
    1639             : 
    1640             : /**
    1641             :  * A macro to implement the NS_NewHTMLXXXElement() functions.
    1642             :  */
    1643             : #define NS_IMPL_NS_NEW_HTML_ELEMENT(_elementName)                            \
    1644             : nsGenericHTMLElement*                                                        \
    1645             : NS_NewHTML##_elementName##Element(already_AddRefed<mozilla::dom::NodeInfo>&& aNodeInfo, \
    1646             :                                   mozilla::dom::FromParser aFromParser)      \
    1647             : {                                                                            \
    1648             :   return new mozilla::dom::HTML##_elementName##Element(aNodeInfo);           \
    1649             : }
    1650             : 
    1651             : #define NS_IMPL_NS_NEW_HTML_ELEMENT_CHECK_PARSER(_elementName)               \
    1652             : nsGenericHTMLElement*                                                        \
    1653             : NS_NewHTML##_elementName##Element(already_AddRefed<mozilla::dom::NodeInfo>&& aNodeInfo, \
    1654             :                                   mozilla::dom::FromParser aFromParser)      \
    1655             : {                                                                            \
    1656             :   return new mozilla::dom::HTML##_elementName##Element(aNodeInfo,            \
    1657             :                                                        aFromParser);         \
    1658             : }
    1659             : 
    1660             : // Here, we expand 'NS_DECLARE_NS_NEW_HTML_ELEMENT()' by hand.
    1661             : // (Calling the macro directly (with no args) produces compiler warnings.)
    1662             : nsGenericHTMLElement*
    1663             : NS_NewHTMLElement(already_AddRefed<mozilla::dom::NodeInfo>&& aNodeInfo,
    1664             :                   mozilla::dom::FromParser aFromParser = mozilla::dom::NOT_FROM_PARSER);
    1665             : 
    1666             : NS_DECLARE_NS_NEW_HTML_ELEMENT(Shared)
    1667             : NS_DECLARE_NS_NEW_HTML_ELEMENT(SharedList)
    1668             : NS_DECLARE_NS_NEW_HTML_ELEMENT(SharedObject)
    1669             : 
    1670             : NS_DECLARE_NS_NEW_HTML_ELEMENT(Anchor)
    1671             : NS_DECLARE_NS_NEW_HTML_ELEMENT(Area)
    1672             : NS_DECLARE_NS_NEW_HTML_ELEMENT(Audio)
    1673             : NS_DECLARE_NS_NEW_HTML_ELEMENT(BR)
    1674             : NS_DECLARE_NS_NEW_HTML_ELEMENT(Body)
    1675             : NS_DECLARE_NS_NEW_HTML_ELEMENT(Button)
    1676             : NS_DECLARE_NS_NEW_HTML_ELEMENT(Canvas)
    1677             : NS_DECLARE_NS_NEW_HTML_ELEMENT(Content)
    1678             : NS_DECLARE_NS_NEW_HTML_ELEMENT(Mod)
    1679             : NS_DECLARE_NS_NEW_HTML_ELEMENT(Data)
    1680             : NS_DECLARE_NS_NEW_HTML_ELEMENT(DataList)
    1681             : NS_DECLARE_NS_NEW_HTML_ELEMENT(Details)
    1682             : NS_DECLARE_NS_NEW_HTML_ELEMENT(Dialog)
    1683             : NS_DECLARE_NS_NEW_HTML_ELEMENT(Div)
    1684             : NS_DECLARE_NS_NEW_HTML_ELEMENT(FieldSet)
    1685             : NS_DECLARE_NS_NEW_HTML_ELEMENT(Font)
    1686             : NS_DECLARE_NS_NEW_HTML_ELEMENT(Form)
    1687             : NS_DECLARE_NS_NEW_HTML_ELEMENT(Frame)
    1688             : NS_DECLARE_NS_NEW_HTML_ELEMENT(FrameSet)
    1689             : NS_DECLARE_NS_NEW_HTML_ELEMENT(HR)
    1690           5 : NS_DECLARE_NS_NEW_HTML_ELEMENT_AS_SHARED(Head)
    1691             : NS_DECLARE_NS_NEW_HTML_ELEMENT(Heading)
    1692           5 : NS_DECLARE_NS_NEW_HTML_ELEMENT_AS_SHARED(Html)
    1693             : NS_DECLARE_NS_NEW_HTML_ELEMENT(IFrame)
    1694             : NS_DECLARE_NS_NEW_HTML_ELEMENT(Image)
    1695             : NS_DECLARE_NS_NEW_HTML_ELEMENT(Input)
    1696             : NS_DECLARE_NS_NEW_HTML_ELEMENT(LI)
    1697             : NS_DECLARE_NS_NEW_HTML_ELEMENT(Label)
    1698             : NS_DECLARE_NS_NEW_HTML_ELEMENT(Legend)
    1699             : NS_DECLARE_NS_NEW_HTML_ELEMENT(Link)
    1700             : NS_DECLARE_NS_NEW_HTML_ELEMENT(Map)
    1701             : NS_DECLARE_NS_NEW_HTML_ELEMENT(Menu)
    1702             : NS_DECLARE_NS_NEW_HTML_ELEMENT(MenuItem)
    1703             : NS_DECLARE_NS_NEW_HTML_ELEMENT(Meta)
    1704             : NS_DECLARE_NS_NEW_HTML_ELEMENT(Meter)
    1705             : NS_DECLARE_NS_NEW_HTML_ELEMENT(Object)
    1706             : NS_DECLARE_NS_NEW_HTML_ELEMENT(OptGroup)
    1707             : NS_DECLARE_NS_NEW_HTML_ELEMENT(Option)
    1708             : NS_DECLARE_NS_NEW_HTML_ELEMENT(Output)
    1709             : NS_DECLARE_NS_NEW_HTML_ELEMENT(Paragraph)
    1710             : NS_DECLARE_NS_NEW_HTML_ELEMENT(Picture)
    1711             : NS_DECLARE_NS_NEW_HTML_ELEMENT(Pre)
    1712             : NS_DECLARE_NS_NEW_HTML_ELEMENT(Progress)
    1713             : NS_DECLARE_NS_NEW_HTML_ELEMENT(Script)
    1714             : NS_DECLARE_NS_NEW_HTML_ELEMENT(Select)
    1715             : NS_DECLARE_NS_NEW_HTML_ELEMENT(Shadow)
    1716             : NS_DECLARE_NS_NEW_HTML_ELEMENT(Source)
    1717             : NS_DECLARE_NS_NEW_HTML_ELEMENT(Span)
    1718             : NS_DECLARE_NS_NEW_HTML_ELEMENT(Style)
    1719             : NS_DECLARE_NS_NEW_HTML_ELEMENT(Summary)
    1720             : NS_DECLARE_NS_NEW_HTML_ELEMENT(TableCaption)
    1721             : NS_DECLARE_NS_NEW_HTML_ELEMENT(TableCell)
    1722             : NS_DECLARE_NS_NEW_HTML_ELEMENT(TableCol)
    1723             : NS_DECLARE_NS_NEW_HTML_ELEMENT(Table)
    1724             : NS_DECLARE_NS_NEW_HTML_ELEMENT(TableRow)
    1725             : NS_DECLARE_NS_NEW_HTML_ELEMENT(TableSection)
    1726             : NS_DECLARE_NS_NEW_HTML_ELEMENT(Tbody)
    1727             : NS_DECLARE_NS_NEW_HTML_ELEMENT(Template)
    1728             : NS_DECLARE_NS_NEW_HTML_ELEMENT(TextArea)
    1729             : NS_DECLARE_NS_NEW_HTML_ELEMENT(Tfoot)
    1730             : NS_DECLARE_NS_NEW_HTML_ELEMENT(Thead)
    1731             : NS_DECLARE_NS_NEW_HTML_ELEMENT(Time)
    1732             : NS_DECLARE_NS_NEW_HTML_ELEMENT(Title)
    1733             : NS_DECLARE_NS_NEW_HTML_ELEMENT(Track)
    1734             : NS_DECLARE_NS_NEW_HTML_ELEMENT(Unknown)
    1735             : NS_DECLARE_NS_NEW_HTML_ELEMENT(Video)
    1736             : 
    1737             : inline nsISupports*
    1738           0 : ToSupports(nsGenericHTMLElement* aHTMLElement)
    1739             : {
    1740           0 :   return static_cast<nsIContent*>(aHTMLElement);
    1741             : }
    1742             : 
    1743             : inline nsISupports*
    1744             : ToCanonicalSupports(nsGenericHTMLElement* aHTMLElement)
    1745             : {
    1746             :   return static_cast<nsIContent*>(aHTMLElement);
    1747             : }
    1748             : 
    1749             : #endif /* nsGenericHTMLElement_h___ */

Generated by: LCOV version 1.13