LCOV - code coverage report
Current view: directory - content/base/src - nsGenericElement.h (source / functions) Found Hit Coverage
Test: app.info Lines: 145 72 49.7 %
Date: 2012-06-02 Functions: 226 41 18.1 %

       1                 : /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
       2                 : /* ***** BEGIN LICENSE BLOCK *****
       3                 :  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
       4                 :  *
       5                 :  * The contents of this file are subject to the Mozilla Public License Version
       6                 :  * 1.1 (the "License"); you may not use this file except in compliance with
       7                 :  * the License. You may obtain a copy of the License at
       8                 :  * http://www.mozilla.org/MPL/
       9                 :  *
      10                 :  * Software distributed under the License is distributed on an "AS IS" basis,
      11                 :  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
      12                 :  * for the specific language governing rights and limitations under the
      13                 :  * License.
      14                 :  *
      15                 :  * The Original Code is Mozilla Communicator client code.
      16                 :  *
      17                 :  * The Initial Developer of the Original Code is
      18                 :  * Netscape Communications Corporation.
      19                 :  * Portions created by the Initial Developer are Copyright (C) 1998
      20                 :  * the Initial Developer. All Rights Reserved.
      21                 :  *
      22                 :  * Contributor(s):
      23                 :  *
      24                 :  * Alternatively, the contents of this file may be used under the terms of
      25                 :  * either of the GNU General Public License Version 2 or later (the "GPL"),
      26                 :  * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
      27                 :  * in which case the provisions of the GPL or the LGPL are applicable instead
      28                 :  * of those above. If you wish to allow use of your version of this file only
      29                 :  * under the terms of either the GPL or the LGPL, and not to allow others to
      30                 :  * use your version of this file under the terms of the MPL, indicate your
      31                 :  * decision by deleting the provisions above and replace them with the notice
      32                 :  * and other provisions required by the GPL or the LGPL. If you do not delete
      33                 :  * the provisions above, a recipient may use your version of this file under
      34                 :  * the terms of any one of the MPL, the GPL or the LGPL.
      35                 :  *
      36                 :  * ***** END LICENSE BLOCK ***** */
      37                 : 
      38                 : /*
      39                 :  * Base class for all element classes; this provides an implementation
      40                 :  * of DOM Core's nsIDOMElement, implements nsIContent, provides
      41                 :  * utility methods for subclasses, and so forth.
      42                 :  */
      43                 : 
      44                 : #ifndef nsGenericElement_h___
      45                 : #define nsGenericElement_h___
      46                 : 
      47                 : #include "nsCOMPtr.h"
      48                 : #include "nsAutoPtr.h"
      49                 : #include "mozilla/dom/Element.h"
      50                 : #include "nsIDOMElement.h"
      51                 : #include "nsIDOMDocumentFragment.h"
      52                 : #include "nsIDOMNSElement.h"
      53                 : #include "nsILinkHandler.h"
      54                 : #include "nsNodeUtils.h"
      55                 : #include "nsAttrAndChildArray.h"
      56                 : #include "mozFlushType.h"
      57                 : #include "nsDOMAttributeMap.h"
      58                 : #include "nsIWeakReference.h"
      59                 : #include "nsCycleCollectionParticipant.h"
      60                 : #include "nsIDocument.h"
      61                 : #include "nsIDOMNodeSelector.h"
      62                 : #include "nsIDOMXPathNSResolver.h"
      63                 : #include "nsPresContext.h"
      64                 : #include "nsIDOMDOMStringMap.h"
      65                 : #include "nsContentList.h"
      66                 : #include "nsDOMClassInfoID.h" // DOMCI_DATA
      67                 : #include "nsIDOMTouchEvent.h"
      68                 : #include "nsIInlineEventHandlers.h"
      69                 : #include "mozilla/CORSMode.h"
      70                 : 
      71                 : #include "nsISMILAttr.h"
      72                 : 
      73                 : class nsIDOMAttr;
      74                 : class nsIDOMEventListener;
      75                 : class nsIFrame;
      76                 : class nsIDOMNamedNodeMap;
      77                 : class nsICSSDeclaration;
      78                 : class nsIDOMCSSStyleDeclaration;
      79                 : class nsIURI;
      80                 : class nsINodeInfo;
      81                 : class nsIControllers;
      82                 : class nsEventListenerManager;
      83                 : class nsIScrollableFrame;
      84                 : class nsAttrValueOrString;
      85                 : class nsContentList;
      86                 : class nsDOMTokenList;
      87                 : class ContentUnbinder;
      88                 : struct nsRect;
      89                 : 
      90                 : typedef PRUptrdiff PtrBits;
      91                 : 
      92                 : /**
      93                 :  * Class that implements the nsIDOMNodeList interface (a list of children of
      94                 :  * the content), by holding a reference to the content and delegating GetLength
      95                 :  * and Item to its existing child list.
      96                 :  * @see nsIDOMNodeList
      97                 :  */
      98                 : class nsChildContentList : public nsINodeList
      99            1527 : {
     100                 : public:
     101            1527 :   nsChildContentList(nsINode* aNode)
     102            1527 :     : mNode(aNode)
     103                 :   {
     104            1527 :     SetIsProxy();
     105            1527 :   }
     106                 : 
     107            1626 :   NS_DECL_CYCLE_COLLECTING_ISUPPORTS
     108           69703 :   NS_DECL_CYCLE_COLLECTION_SKIPPABLE_SCRIPT_HOLDER_CLASS(nsChildContentList)
     109                 : 
     110                 :   // nsWrapperCache
     111                 :   virtual JSObject* WrapObject(JSContext *cx, XPCWrappedNativeScope *scope,
     112                 :                                bool *triedToWrap);
     113                 : 
     114                 :   // nsIDOMNodeList interface
     115                 :   NS_DECL_NSIDOMNODELIST
     116                 : 
     117                 :   // nsINodeList interface
     118                 :   virtual PRInt32 IndexOf(nsIContent* aContent);
     119                 : 
     120            1527 :   void DropReference()
     121                 :   {
     122            1527 :     mNode = nsnull;
     123            1527 :   }
     124                 : 
     125            1527 :   virtual nsINode* GetParentObject()
     126                 :   {
     127            1527 :     return mNode;
     128                 :   }
     129                 : 
     130                 : private:
     131                 :   // The node whose children make up the list (weak reference)
     132                 :   nsINode* mNode;
     133                 : };
     134                 : 
     135                 : /**
     136                 :  * A tearoff class for nsGenericElement to implement additional interfaces
     137                 :  */
     138                 : class nsNode3Tearoff : public nsIDOMXPathNSResolver
     139                 : {
     140                 : public:
     141               0 :   NS_DECL_CYCLE_COLLECTING_ISUPPORTS
     142                 : 
     143            1464 :   NS_DECL_CYCLE_COLLECTION_CLASS(nsNode3Tearoff)
     144                 : 
     145                 :   NS_DECL_NSIDOMXPATHNSRESOLVER
     146                 : 
     147               0 :   nsNode3Tearoff(nsINode *aNode) : mNode(aNode)
     148                 :   {
     149               0 :   }
     150                 : 
     151                 : protected:
     152               0 :   virtual ~nsNode3Tearoff() {}
     153                 : 
     154                 : private:
     155                 :   nsCOMPtr<nsINode> mNode;
     156                 : };
     157                 : 
     158                 : /**
     159                 :  * A class that implements nsIWeakReference
     160                 :  */
     161                 : 
     162                 : class nsNodeWeakReference : public nsIWeakReference
     163                 : {
     164                 : public:
     165              23 :   nsNodeWeakReference(nsINode* aNode)
     166              23 :     : mNode(aNode)
     167                 :   {
     168              23 :   }
     169                 : 
     170                 :   ~nsNodeWeakReference();
     171                 : 
     172                 :   // nsISupports
     173                 :   NS_DECL_ISUPPORTS
     174                 : 
     175                 :   // nsIWeakReference
     176                 :   NS_DECL_NSIWEAKREFERENCE
     177                 : 
     178               0 :   void NoticeNodeDestruction()
     179                 :   {
     180               0 :     mNode = nsnull;
     181               0 :   }
     182                 : 
     183                 : private:
     184                 :   nsINode* mNode;
     185                 : };
     186                 : 
     187                 : /**
     188                 :  * Tearoff to use for nodes to implement nsISupportsWeakReference
     189                 :  */
     190                 : class nsNodeSupportsWeakRefTearoff : public nsISupportsWeakReference
     191              42 : {
     192                 : public:
     193              42 :   nsNodeSupportsWeakRefTearoff(nsINode* aNode)
     194              42 :     : mNode(aNode)
     195                 :   {
     196              42 :   }
     197                 : 
     198                 :   // nsISupports
     199               0 :   NS_DECL_CYCLE_COLLECTING_ISUPPORTS
     200                 : 
     201                 :   // nsISupportsWeakReference
     202                 :   NS_DECL_NSISUPPORTSWEAKREFERENCE
     203                 : 
     204            1548 :   NS_DECL_CYCLE_COLLECTION_CLASS(nsNodeSupportsWeakRefTearoff)
     205                 : 
     206                 : private:
     207                 :   nsCOMPtr<nsINode> mNode;
     208                 : };
     209                 : 
     210                 : /**
     211                 :  * A tearoff class for nsGenericElement to implement NodeSelector
     212                 :  */
     213                 : class nsNodeSelectorTearoff : public nsIDOMNodeSelector
     214                 : {
     215                 : public:
     216               0 :   NS_DECL_CYCLE_COLLECTING_ISUPPORTS
     217                 : 
     218                 :   NS_DECL_NSIDOMNODESELECTOR
     219                 : 
     220            1464 :   NS_DECL_CYCLE_COLLECTION_CLASS(nsNodeSelectorTearoff)
     221                 : 
     222               0 :   nsNodeSelectorTearoff(nsINode *aNode) : mNode(aNode)
     223                 :   {
     224               0 :   }
     225                 : 
     226                 : private:
     227               0 :   ~nsNodeSelectorTearoff() {}
     228                 : 
     229                 : private:
     230                 :   nsCOMPtr<nsINode> mNode;
     231                 : };
     232                 : 
     233                 : // Forward declare to allow being a friend
     234                 : class nsNSElementTearoff;
     235                 : class nsTouchEventReceiverTearoff;
     236                 : class nsInlineEventHandlersTearoff;
     237                 : 
     238                 : /**
     239                 :  * A generic base class for DOM elements, implementing many nsIContent,
     240                 :  * nsIDOMNode and nsIDOMElement methods.
     241                 :  */
     242                 : class nsGenericElement : public mozilla::dom::Element
     243                 : {
     244                 : public:
     245                 :   nsGenericElement(already_AddRefed<nsINodeInfo> aNodeInfo);
     246                 :   virtual ~nsGenericElement();
     247                 : 
     248                 :   friend class nsNSElementTearoff;
     249                 :   friend class nsTouchEventReceiverTearoff;
     250                 :   friend class nsInlineEventHandlersTearoff;
     251                 : 
     252           40516 :   NS_DECL_CYCLE_COLLECTING_ISUPPORTS
     253                 : 
     254                 :   NS_DECL_SIZEOF_EXCLUDING_THIS
     255                 : 
     256                 :   /**
     257                 :    * Called during QueryInterface to give the binding manager a chance to
     258                 :    * get an interface for this element.
     259                 :    */
     260                 :   nsresult PostQueryInterface(REFNSIID aIID, void** aInstancePtr);
     261                 : 
     262                 :   // nsINode interface methods
     263                 :   virtual PRUint32 GetChildCount() const;
     264                 :   virtual nsIContent *GetChildAt(PRUint32 aIndex) const;
     265                 :   virtual nsIContent * const * GetChildArray(PRUint32* aChildCount) const;
     266                 :   virtual PRInt32 IndexOf(nsINode* aPossibleChild) const;
     267                 :   virtual nsresult InsertChildAt(nsIContent* aKid, PRUint32 aIndex,
     268                 :                                  bool aNotify);
     269                 :   virtual nsresult RemoveChildAt(PRUint32 aIndex, bool aNotify);
     270                 :   NS_IMETHOD GetTextContent(nsAString &aTextContent);
     271                 :   NS_IMETHOD SetTextContent(const nsAString& aTextContent);
     272                 : 
     273                 :   // nsIContent interface methods
     274                 :   virtual void UpdateEditableState(bool aNotify);
     275                 : 
     276                 :   virtual nsresult BindToTree(nsIDocument* aDocument, nsIContent* aParent,
     277                 :                               nsIContent* aBindingParent,
     278                 :                               bool aCompileEventHandlers);
     279                 :   virtual void UnbindFromTree(bool aDeep = true,
     280                 :                               bool aNullParent = true);
     281                 :   virtual already_AddRefed<nsINodeList> GetChildren(PRUint32 aFilter);
     282                 :   virtual nsIAtom *GetClassAttributeName() const;
     283                 :   virtual already_AddRefed<nsINodeInfo> GetExistingAttrNameFromQName(const nsAString& aStr) const;
     284            1845 :   nsresult SetAttr(PRInt32 aNameSpaceID, nsIAtom* aName,
     285                 :                    const nsAString& aValue, bool aNotify)
     286                 :   {
     287            1845 :     return SetAttr(aNameSpaceID, aName, nsnull, aValue, aNotify);
     288                 :   }
     289                 :   /**
     290                 :    * Helper for SetAttr/SetParsedAttr. This method will return true if aNotify
     291                 :    * is true or there are mutation listeners that must be triggered, the
     292                 :    * attribute is currently set, and the new value that is about to be set is
     293                 :    * different to the current value. As a perf optimization the new and old
     294                 :    * values will not actually be compared if we aren't notifying and we don't
     295                 :    * have mutation listeners (in which case it's cheap to just return false
     296                 :    * and let the caller go ahead and set the value).
     297                 :    * @param aOldValue Set to the old value of the attribute, but only if there
     298                 :    *   are event listeners. If set, the type of aOldValue will be either
     299                 :    *   nsAttrValue::eString or nsAttrValue::eAtom.
     300                 :    * @param aModType Set to nsIDOMMutationEvent::MODIFICATION or to
     301                 :    *   nsIDOMMutationEvent::ADDITION, but only if this helper returns true
     302                 :    * @param aHasListeners Set to true if there are mutation event listeners
     303                 :    *   listening for NS_EVENT_BITS_MUTATION_ATTRMODIFIED
     304                 :    */
     305                 :   bool MaybeCheckSameAttrVal(PRInt32 aNamespaceID, nsIAtom* aName,
     306                 :                              nsIAtom* aPrefix,
     307                 :                              const nsAttrValueOrString& aValue,
     308                 :                              bool aNotify, nsAttrValue& aOldValue,
     309                 :                              PRUint8* aModType, bool* aHasListeners);
     310                 :   virtual nsresult SetAttr(PRInt32 aNameSpaceID, nsIAtom* aName, nsIAtom* aPrefix,
     311                 :                            const nsAString& aValue, bool aNotify);
     312                 :   virtual nsresult SetParsedAttr(PRInt32 aNameSpaceID, nsIAtom* aName,
     313                 :                                  nsIAtom* aPrefix, nsAttrValue& aParsedValue,
     314                 :                                  bool aNotify);
     315                 :   virtual bool GetAttr(PRInt32 aNameSpaceID, nsIAtom* aName,
     316                 :                          nsAString& aResult) const;
     317                 :   virtual bool HasAttr(PRInt32 aNameSpaceID, nsIAtom* aName) const;
     318                 :   virtual bool AttrValueIs(PRInt32 aNameSpaceID, nsIAtom* aName,
     319                 :                              const nsAString& aValue,
     320                 :                              nsCaseTreatment aCaseSensitive) const;
     321                 :   virtual bool AttrValueIs(PRInt32 aNameSpaceID, nsIAtom* aName,
     322                 :                              nsIAtom* aValue,
     323                 :                              nsCaseTreatment aCaseSensitive) const;
     324                 :   virtual PRInt32 FindAttrValueIn(PRInt32 aNameSpaceID,
     325                 :                                   nsIAtom* aName,
     326                 :                                   AttrValuesArray* aValues,
     327                 :                                   nsCaseTreatment aCaseSensitive) const;
     328                 :   virtual nsresult UnsetAttr(PRInt32 aNameSpaceID, nsIAtom* aAttribute,
     329                 :                              bool aNotify);
     330                 :   virtual const nsAttrName* GetAttrNameAt(PRUint32 aIndex) const;
     331                 :   virtual PRUint32 GetAttrCount() const;
     332                 :   virtual const nsTextFragment *GetText();
     333                 :   virtual PRUint32 TextLength();
     334                 :   virtual nsresult SetText(const PRUnichar* aBuffer, PRUint32 aLength,
     335                 :                            bool aNotify);
     336                 :   // Need to implement this here too to avoid hiding.
     337                 :   nsresult SetText(const nsAString& aStr, bool aNotify)
     338                 :   {
     339                 :     return SetText(aStr.BeginReading(), aStr.Length(), aNotify);
     340                 :   }
     341                 :   virtual nsresult AppendText(const PRUnichar* aBuffer, PRUint32 aLength,
     342                 :                               bool aNotify);
     343                 :   virtual bool TextIsOnlyWhitespace();
     344                 :   virtual void AppendTextTo(nsAString& aResult);
     345                 :   virtual nsIContent *GetBindingParent() const;
     346                 :   virtual bool IsNodeOfType(PRUint32 aFlags) const;
     347                 :   virtual bool IsLink(nsIURI** aURI) const;
     348                 : 
     349                 :   virtual PRUint32 GetScriptTypeID() const;
     350                 :   NS_IMETHOD SetScriptTypeID(PRUint32 aLang);
     351                 : 
     352                 :   virtual void DestroyContent();
     353                 :   virtual void SaveSubtreeState();
     354                 : 
     355               0 :   virtual nsISMILAttr* GetAnimatedAttr(PRInt32 /*aNamespaceID*/, nsIAtom* /*aName*/)
     356                 :   {
     357               0 :     return nsnull;
     358                 :   }
     359                 :   virtual nsIDOMCSSStyleDeclaration* GetSMILOverrideStyle();
     360                 :   virtual mozilla::css::StyleRule* GetSMILOverrideStyleRule();
     361                 :   virtual nsresult SetSMILOverrideStyleRule(mozilla::css::StyleRule* aStyleRule,
     362                 :                                             bool aNotify);
     363                 : 
     364                 : #ifdef DEBUG
     365               0 :   virtual void List(FILE* out, PRInt32 aIndent) const
     366                 :   {
     367               0 :     List(out, aIndent, EmptyCString());
     368               0 :   }
     369                 :   virtual void DumpContent(FILE* out, PRInt32 aIndent, bool aDumpAll) const;
     370                 :   void List(FILE* out, PRInt32 aIndent, const nsCString& aPrefix) const;
     371                 :   void ListAttributes(FILE* out) const;
     372                 : #endif
     373                 : 
     374                 :   virtual const nsAttrValue* DoGetClasses() const;
     375                 :   NS_IMETHOD WalkContentStyleRules(nsRuleWalker* aRuleWalker);
     376                 :   virtual mozilla::css::StyleRule* GetInlineStyleRule();
     377                 :   NS_IMETHOD SetInlineStyleRule(mozilla::css::StyleRule* aStyleRule, bool aNotify);
     378                 :   NS_IMETHOD_(bool)
     379                 :     IsAttributeMapped(const nsIAtom* aAttribute) const;
     380                 :   virtual nsChangeHint GetAttributeChangeHint(const nsIAtom* aAttribute,
     381                 :                                               PRInt32 aModType) const;
     382                 :   /*
     383                 :    * Attribute Mapping Helpers
     384                 :    */
     385                 :   struct MappedAttributeEntry {
     386                 :     nsIAtom** attribute;
     387                 :   };
     388                 : 
     389                 :   /**
     390                 :    * A common method where you can just pass in a list of maps to check
     391                 :    * for attribute dependence. Most implementations of
     392                 :    * IsAttributeMapped should use this function as a default
     393                 :    * handler.
     394                 :    */
     395                 :   template<size_t N>
     396                 :   static bool
     397               0 :   FindAttributeDependence(const nsIAtom* aAttribute,
     398                 :                           const MappedAttributeEntry* const (&aMaps)[N])
     399                 :   {
     400               0 :     return FindAttributeDependence(aAttribute, aMaps, N);
     401                 :   }
     402                 : 
     403                 : private:
     404                 :   static bool
     405                 :   FindAttributeDependence(const nsIAtom* aAttribute,
     406                 :                           const MappedAttributeEntry* const aMaps[],
     407                 :                           PRUint32 aMapCount);
     408                 : 
     409                 : public:
     410                 :   // nsIDOMNode method implementation
     411                 :   NS_IMETHOD GetNodeName(nsAString& aNodeName);
     412                 :   NS_IMETHOD GetLocalName(nsAString& aLocalName);
     413                 :   NS_IMETHOD GetNodeValue(nsAString& aNodeValue);
     414                 :   NS_IMETHOD SetNodeValue(const nsAString& aNodeValue);
     415                 :   NS_IMETHOD GetNodeType(PRUint16* aNodeType);
     416                 :   NS_IMETHOD GetAttributes(nsIDOMNamedNodeMap** aAttributes);
     417                 :   NS_IMETHOD GetNamespaceURI(nsAString& aNamespaceURI);
     418                 :   NS_IMETHOD GetPrefix(nsAString& aPrefix);
     419                 :   NS_IMETHOD IsSupported(const nsAString& aFeature,
     420                 :                          const nsAString& aVersion, bool* aReturn);
     421                 :   NS_IMETHOD HasAttributes(bool* aHasAttributes);
     422                 :   NS_IMETHOD HasChildNodes(bool* aHasChildNodes);
     423              12 :   nsresult InsertBefore(nsIDOMNode* aNewChild, nsIDOMNode* aRefChild,
     424                 :                         nsIDOMNode** aReturn)
     425                 :   {
     426              12 :     return ReplaceOrInsertBefore(false, aNewChild, aRefChild, aReturn);
     427                 :   }
     428               0 :   nsresult ReplaceChild(nsIDOMNode* aNewChild, nsIDOMNode* aOldChild,
     429                 :                         nsIDOMNode** aReturn)
     430                 :   {
     431               0 :     return ReplaceOrInsertBefore(true, aNewChild, aOldChild, aReturn);
     432                 :   }
     433               0 :   nsresult RemoveChild(nsIDOMNode* aOldChild, nsIDOMNode** aReturn)
     434                 :   {
     435               0 :     return nsINode::RemoveChild(aOldChild, aReturn);
     436                 :   }
     437               0 :   nsresult AppendChild(nsIDOMNode* aNewChild, nsIDOMNode** aReturn)
     438                 :   {
     439               0 :     return InsertBefore(aNewChild, nsnull, aReturn);
     440                 :   }
     441                 : 
     442                 :   // nsIDOMElement method implementation
     443                 :   NS_IMETHOD GetTagName(nsAString& aTagName);
     444                 :   NS_IMETHOD GetAttribute(const nsAString& aName,
     445                 :                           nsAString& aReturn);
     446                 :   NS_IMETHOD SetAttribute(const nsAString& aName,
     447                 :                           const nsAString& aValue);
     448                 :   NS_IMETHOD RemoveAttribute(const nsAString& aName);
     449                 :   NS_IMETHOD GetAttributeNode(const nsAString& aName,
     450                 :                               nsIDOMAttr** aReturn);
     451                 :   NS_IMETHOD SetAttributeNode(nsIDOMAttr* aNewAttr, nsIDOMAttr** aReturn);
     452                 :   NS_IMETHOD RemoveAttributeNode(nsIDOMAttr* aOldAttr, nsIDOMAttr** aReturn);
     453                 :   NS_IMETHOD GetElementsByTagName(const nsAString& aTagname,
     454                 :                                   nsIDOMNodeList** aReturn);
     455                 :   NS_IMETHOD GetAttributeNS(const nsAString& aNamespaceURI,
     456                 :                             const nsAString& aLocalName,
     457                 :                             nsAString& aReturn);
     458                 :   NS_IMETHOD SetAttributeNS(const nsAString& aNamespaceURI,
     459                 :                             const nsAString& aQualifiedName,
     460                 :                             const nsAString& aValue);
     461                 :   NS_IMETHOD RemoveAttributeNS(const nsAString& aNamespaceURI,
     462                 :                                const nsAString& aLocalName);
     463                 :   NS_IMETHOD GetAttributeNodeNS(const nsAString& aNamespaceURI,
     464                 :                                 const nsAString& aLocalName,
     465                 :                                 nsIDOMAttr** aReturn);
     466                 :   NS_IMETHOD SetAttributeNodeNS(nsIDOMAttr* aNewAttr, nsIDOMAttr** aReturn);
     467                 :   NS_IMETHOD GetElementsByTagNameNS(const nsAString& aNamespaceURI,
     468                 :                                     const nsAString& aLocalName,
     469                 :                                     nsIDOMNodeList** aReturn);
     470                 :   NS_IMETHOD HasAttribute(const nsAString& aName, bool* aReturn);
     471                 :   NS_IMETHOD HasAttributeNS(const nsAString& aNamespaceURI,
     472                 :                             const nsAString& aLocalName,
     473                 :                             bool* aReturn);
     474                 : 
     475             116 :   nsresult CloneNode(bool aDeep, PRUint8 aOptionalArgc, nsIDOMNode **aResult)
     476                 :   {
     477             116 :     if (!aOptionalArgc) {
     478               0 :       aDeep = true;
     479                 :     }
     480                 :     
     481             116 :     return nsNodeUtils::CloneNodeImpl(this, aDeep, true, aResult);
     482                 :   }
     483                 : 
     484                 :   //----------------------------------------
     485                 : 
     486                 :   /**
     487                 :    * Add a script event listener with the given event handler name
     488                 :    * (like onclick) and with the value as JS
     489                 :    * @param aEventName the event listener name
     490                 :    * @param aValue the JS to attach
     491                 :    * @param aDefer indicates if deferred execution is allowed
     492                 :    */
     493                 :   nsresult AddScriptEventListener(nsIAtom* aEventName,
     494                 :                                   const nsAString& aValue,
     495                 :                                   bool aDefer = true);
     496                 : 
     497                 :   /**
     498                 :    * Do whatever needs to be done when the mouse leaves a link
     499                 :    */
     500                 :   nsresult LeaveLink(nsPresContext* aPresContext);
     501                 : 
     502                 :   /**
     503                 :    * Check whether a spec feature/version is supported.
     504                 :    * @param aObject the object, which should support the feature,
     505                 :    *        for example nsIDOMNode or nsIDOMDOMImplementation
     506                 :    * @param aFeature the feature ("Views", "Core", "HTML", "Range" ...)
     507                 :    * @param aVersion the version ("1.0", "2.0", ...)
     508                 :    * @param aReturn whether the feature is supported or not [OUT]
     509                 :    */
     510                 :   static nsresult InternalIsSupported(nsISupports* aObject,
     511                 :                                       const nsAString& aFeature,
     512                 :                                       const nsAString& aVersion,
     513                 :                                       bool* aReturn);
     514                 : 
     515                 :   static bool ShouldBlur(nsIContent *aContent);
     516                 : 
     517                 :   /**
     518                 :    * If there are listeners for DOMNodeInserted event, fires the event on all
     519                 :    * aNodes
     520                 :    */
     521                 :   static void FireNodeInserted(nsIDocument* aDoc,
     522                 :                                nsINode* aParent,
     523                 :                                nsTArray<nsCOMPtr<nsIContent> >& aNodes);
     524                 : 
     525                 :   /**
     526                 :    * Helper methods for implementing querySelector/querySelectorAll
     527                 :    */
     528                 :   static nsIContent* doQuerySelector(nsINode* aRoot, const nsAString& aSelector,
     529                 :                                      nsresult *aResult NS_OUTPARAM);
     530                 :   static nsresult doQuerySelectorAll(nsINode* aRoot,
     531                 :                                      const nsAString& aSelector,
     532                 :                                      nsIDOMNodeList **aReturn);
     533                 : 
     534                 :   /**
     535                 :    * Method to create and dispatch a left-click event loosely based on
     536                 :    * aSourceEvent. If aFullDispatch is true, the event will be dispatched
     537                 :    * through the full dispatching of the presshell of the aPresContext; if it's
     538                 :    * false the event will be dispatched only as a DOM event.
     539                 :    * If aPresContext is nsnull, this does nothing.
     540                 :    */
     541                 :   static nsresult DispatchClickEvent(nsPresContext* aPresContext,
     542                 :                                      nsInputEvent* aSourceEvent,
     543                 :                                      nsIContent* aTarget,
     544                 :                                      bool aFullDispatch,
     545                 :                                      PRUint32 aFlags,
     546                 :                                      nsEventStatus* aStatus);
     547                 : 
     548                 :   /**
     549                 :    * Method to dispatch aEvent to aTarget. If aFullDispatch is true, the event
     550                 :    * will be dispatched through the full dispatching of the presshell of the
     551                 :    * aPresContext; if it's false the event will be dispatched only as a DOM
     552                 :    * event.
     553                 :    * If aPresContext is nsnull, this does nothing.
     554                 :    */
     555                 :   using nsIContent::DispatchEvent;
     556                 :   static nsresult DispatchEvent(nsPresContext* aPresContext,
     557                 :                                 nsEvent* aEvent,
     558                 :                                 nsIContent* aTarget,
     559                 :                                 bool aFullDispatch,
     560                 :                                 nsEventStatus* aStatus);
     561                 : 
     562                 :   /**
     563                 :    * Get the primary frame for this content with flushing
     564                 :    *
     565                 :    * @param aType the kind of flush to do, typically Flush_Frames or
     566                 :    *              Flush_Layout
     567                 :    * @return the primary frame
     568                 :    */
     569                 :   nsIFrame* GetPrimaryFrame(mozFlushType aType);
     570                 :   // Work around silly C++ name hiding stuff
     571               0 :   nsIFrame* GetPrimaryFrame() const { return nsIContent::GetPrimaryFrame(); }
     572                 : 
     573                 :   /**
     574                 :    * Struct that stores info on an attribute.  The name and value must
     575                 :    * either both be null or both be non-null.
     576                 :    */
     577                 :   struct nsAttrInfo {
     578            3128 :     nsAttrInfo(const nsAttrName* aName, const nsAttrValue* aValue) :
     579            3128 :       mName(aName), mValue(aValue) {}
     580            1253 :     nsAttrInfo(const nsAttrInfo& aOther) :
     581            1253 :       mName(aOther.mName), mValue(aOther.mValue) {}
     582                 : 
     583                 :     const nsAttrName* mName;
     584                 :     const nsAttrValue* mValue;
     585                 :   };
     586                 : 
     587                 :   // Be careful when using this method. This does *NOT* handle
     588                 :   // XUL prototypes. You may want to use GetAttrInfo.
     589               0 :   const nsAttrValue* GetParsedAttr(nsIAtom* aAttr) const
     590                 :   {
     591               0 :     return mAttrsAndChildren.GetAttr(aAttr);
     592                 :   }
     593                 : 
     594                 :   /**
     595                 :    * Returns the attribute map, if there is one.
     596                 :    *
     597                 :    * @return existing attribute map or nsnull.
     598                 :    */
     599               0 :   nsDOMAttributeMap *GetAttributeMap()
     600                 :   {
     601               0 :     nsDOMSlots *slots = GetExistingDOMSlots();
     602                 : 
     603               0 :     return slots ? slots->mAttributeMap.get() : nsnull;
     604                 :   }
     605                 : 
     606               0 :   virtual void RecompileScriptEventListeners()
     607                 :   {
     608               0 :   }
     609                 : 
     610                 :   // nsIDOMNSElement methods
     611                 :   nsresult GetElementsByClassName(const nsAString& aClasses,
     612                 :                                   nsIDOMNodeList** aReturn);
     613                 :   nsresult GetClientRects(nsIDOMClientRectList** aResult);
     614                 :   nsresult GetBoundingClientRect(nsIDOMClientRect** aResult);
     615                 :   PRInt32 GetScrollTop();
     616                 :   void SetScrollTop(PRInt32 aScrollTop);
     617                 :   PRInt32 GetScrollLeft();
     618                 :   void SetScrollLeft(PRInt32 aScrollLeft);
     619                 :   PRInt32 GetScrollHeight();
     620                 :   PRInt32 GetScrollWidth();
     621               0 :   PRInt32 GetClientTop()
     622                 :   {
     623               0 :     return nsPresContext::AppUnitsToIntCSSPixels(GetClientAreaRect().y);
     624                 :   }
     625               0 :   PRInt32 GetClientLeft()
     626                 :   {
     627               0 :     return nsPresContext::AppUnitsToIntCSSPixels(GetClientAreaRect().x);
     628                 :   }
     629               0 :   PRInt32 GetClientHeight()
     630                 :   {
     631               0 :     return nsPresContext::AppUnitsToIntCSSPixels(GetClientAreaRect().height);
     632                 :   }
     633               0 :   PRInt32 GetClientWidth()
     634                 :   {
     635               0 :     return nsPresContext::AppUnitsToIntCSSPixels(GetClientAreaRect().width);
     636                 :   }
     637                 :   nsIContent* GetFirstElementChild();
     638                 :   nsIContent* GetLastElementChild();
     639                 :   nsIContent* GetPreviousElementSibling();
     640                 :   nsIContent* GetNextElementSibling();
     641               0 :   nsresult GetChildElementCount(PRUint32* aResult)
     642                 :   {
     643               0 :     nsContentList* list = GetChildrenList();
     644               0 :     if (!list) {
     645               0 :       *aResult = 0;
     646                 : 
     647               0 :       return NS_ERROR_OUT_OF_MEMORY;
     648                 :     }
     649                 : 
     650               0 :     *aResult = list->Length(true);
     651                 : 
     652               0 :     return NS_OK;
     653                 :   }
     654             167 :   nsresult GetChildren(nsIDOMNodeList** aResult)
     655                 :   {
     656             167 :     nsContentList* list = GetChildrenList();
     657             167 :     if (!list) {
     658               0 :       *aResult = nsnull;
     659                 : 
     660               0 :       return NS_ERROR_OUT_OF_MEMORY;
     661                 :     }
     662                 : 
     663             167 :     NS_ADDREF(*aResult = list);
     664                 : 
     665             167 :     return NS_OK;
     666                 :   }
     667                 :   void SetCapture(bool aRetargetToElement);
     668                 :   void ReleaseCapture();
     669                 :   nsDOMTokenList* GetClassList(nsresult *aResult);
     670                 :   bool MozMatchesSelector(const nsAString& aSelector, nsresult* aResult);
     671                 : 
     672                 :   /**
     673                 :    * Get the attr info for the given namespace ID and attribute name.  The
     674                 :    * namespace ID must not be kNameSpaceID_Unknown and the name must not be
     675                 :    * null.  Note that this can only return info on attributes that actually
     676                 :    * live on this element (and is only virtual to handle XUL prototypes).  That
     677                 :    * is, this should only be called from methods that only care about attrs
     678                 :    * that effectively live in mAttrsAndChildren.
     679                 :    */
     680                 :   virtual nsAttrInfo GetAttrInfo(PRInt32 aNamespaceID, nsIAtom* aName) const;
     681                 : 
     682         2724338 :   NS_DECL_CYCLE_COLLECTION_SKIPPABLE_SCRIPT_HOLDER_CLASS(nsGenericElement)
     683                 : 
     684               0 :   virtual void NodeInfoChanged(nsINodeInfo* aOldNodeInfo)
     685                 :   {
     686               0 :   }
     687                 : 
     688                 :   /**
     689                 :    * Fire a DOMNodeRemoved mutation event for all children of this node
     690                 :    */
     691                 :   void FireNodeRemovedForChildren();
     692                 : 
     693          107870 :   virtual bool IsPurple()
     694                 :   {
     695          107870 :     return mRefCnt.IsPurple();
     696                 :   }
     697                 : 
     698             287 :   virtual void RemovePurple()
     699                 :   {
     700             287 :     mRefCnt.RemovePurple();
     701             287 :   }
     702                 : 
     703                 :   static bool CanSkip(nsINode* aNode, bool aRemovingAllowed);
     704                 :   static bool CanSkipInCC(nsINode* aNode);
     705                 :   static bool CanSkipThis(nsINode* aNode);
     706                 :   static void MarkNodeChildren(nsINode* aNode);
     707                 :   static void InitCCCallbacks();
     708                 :   static void MarkUserData(void* aObject, nsIAtom* aKey, void* aChild,
     709                 :                            void *aData);
     710                 :   static void MarkUserDataHandler(void* aObject, nsIAtom* aKey, void* aChild,
     711                 :                                   void* aData);
     712                 : 
     713                 :   /**
     714                 :    * Parse a string into an nsAttrValue for a CORS attribute.  This
     715                 :    * never fails.  The resulting value is an enumerated value whose
     716                 :    * GetEnumValue() returns one of the above constants.
     717                 :    */
     718                 :   static void ParseCORSValue(const nsAString& aValue, nsAttrValue& aResult);
     719                 : 
     720                 :   /**
     721                 :    * Return the CORS mode for a given string
     722                 :    */
     723                 :   static mozilla::CORSMode StringToCORSMode(const nsAString& aValue);
     724                 :   
     725                 :   /**
     726                 :    * Return the CORS mode for a given nsAttrValue (which may be null,
     727                 :    * but if not should have been parsed via ParseCORSValue).
     728                 :    */
     729                 :   static mozilla::CORSMode AttrValueToCORSMode(const nsAttrValue* aValue);
     730                 : 
     731                 : protected:
     732                 :   /*
     733                 :    * Named-bools for use with SetAttrAndNotify to make call sites easier to
     734                 :    * read.
     735                 :    */
     736                 :   static const bool kFireMutationEvent           = true;
     737                 :   static const bool kDontFireMutationEvent       = false;
     738                 :   static const bool kNotifyDocumentObservers     = true;
     739                 :   static const bool kDontNotifyDocumentObservers = false;
     740                 :   static const bool kCallAfterSetAttr            = true;
     741                 :   static const bool kDontCallAfterSetAttr        = false;
     742                 : 
     743                 :   /**
     744                 :    * Set attribute and (if needed) notify documentobservers and fire off
     745                 :    * mutation events.  This will send the AttributeChanged notification.
     746                 :    * Callers of this method are responsible for calling AttributeWillChange,
     747                 :    * since that needs to happen before the new attr value has been set, and
     748                 :    * in particular before it has been parsed.
     749                 :    *
     750                 :    * For the boolean parameters, consider using the named bools above to aid
     751                 :    * code readability.
     752                 :    *
     753                 :    * @param aNamespaceID  namespace of attribute
     754                 :    * @param aAttribute    local-name of attribute
     755                 :    * @param aPrefix       aPrefix of attribute
     756                 :    * @param aOldValue     previous value of attribute. Only needed if
     757                 :    *                      aFireMutation is true.
     758                 :    * @param aParsedValue  parsed new value of attribute
     759                 :    * @param aModType      nsIDOMMutationEvent::MODIFICATION or ADDITION.  Only
     760                 :    *                      needed if aFireMutation or aNotify is true.
     761                 :    * @param aFireMutation should mutation-events be fired?
     762                 :    * @param aNotify       should we notify document-observers?
     763                 :    * @param aCallAfterSetAttr should we call AfterSetAttr?
     764                 :    */
     765                 :   nsresult SetAttrAndNotify(PRInt32 aNamespaceID,
     766                 :                             nsIAtom* aName,
     767                 :                             nsIAtom* aPrefix,
     768                 :                             const nsAttrValue& aOldValue,
     769                 :                             nsAttrValue& aParsedValue,
     770                 :                             PRUint8 aModType,
     771                 :                             bool aFireMutation,
     772                 :                             bool aNotify,
     773                 :                             bool aCallAfterSetAttr);
     774                 : 
     775                 :   /**
     776                 :    * Convert an attribute string value to attribute type based on the type of
     777                 :    * attribute.  Called by SetAttr().  Note that at the moment we only do this
     778                 :    * for attributes in the null namespace (kNameSpaceID_None).
     779                 :    *
     780                 :    * @param aNamespaceID the namespace of the attribute to convert
     781                 :    * @param aAttribute the attribute to convert
     782                 :    * @param aValue the string value to convert
     783                 :    * @param aResult the nsAttrValue [OUT]
     784                 :    * @return true if the parsing was successful, false otherwise
     785                 :    */
     786                 :   virtual bool ParseAttribute(PRInt32 aNamespaceID,
     787                 :                                 nsIAtom* aAttribute,
     788                 :                                 const nsAString& aValue,
     789                 :                                 nsAttrValue& aResult);
     790                 : 
     791                 :   /**
     792                 :    * Try to set the attribute as a mapped attribute, if applicable.  This will
     793                 :    * only be called for attributes that are in the null namespace and only on
     794                 :    * attributes that returned true when passed to IsAttributeMapped.  The
     795                 :    * caller will not try to set the attr in any other way if this method
     796                 :    * returns true (the value of aRetval does not matter for that purpose).
     797                 :    *
     798                 :    * @param aDocument the current document of this node (an optimization)
     799                 :    * @param aName the name of the attribute
     800                 :    * @param aValue the nsAttrValue to set
     801                 :    * @param [out] aRetval the nsresult status of the operation, if any.
     802                 :    * @return true if the setting was attempted, false otherwise.
     803                 :    */
     804                 :   virtual bool SetMappedAttribute(nsIDocument* aDocument,
     805                 :                                     nsIAtom* aName,
     806                 :                                     nsAttrValue& aValue,
     807                 :                                     nsresult* aRetval);
     808                 : 
     809                 :   /**
     810                 :    * Hook that is called by nsGenericElement::SetAttr to allow subclasses to
     811                 :    * deal with attribute sets.  This will only be called after we verify that
     812                 :    * we're actually doing an attr set and will be called before
     813                 :    * AttributeWillChange and before ParseAttribute and hence before we've set
     814                 :    * the new value.
     815                 :    *
     816                 :    * @param aNamespaceID the namespace of the attr being set
     817                 :    * @param aName the localname of the attribute being set
     818                 :    * @param aValue the value it's being set to represented as either a string or
     819                 :    *        a parsed nsAttrValue. Alternatively, if the attr is being removed it
     820                 :    *        will be null.
     821                 :    * @param aNotify Whether we plan to notify document observers.
     822                 :    */
     823                 :   // Note that this is inlined so that when subclasses call it it gets
     824                 :   // inlined.  Those calls don't go through a vtable.
     825           11454 :   virtual nsresult BeforeSetAttr(PRInt32 aNamespaceID, nsIAtom* aName,
     826                 :                                  const nsAttrValueOrString* aValue,
     827                 :                                  bool aNotify)
     828                 :   {
     829           11454 :     return NS_OK;
     830                 :   }
     831                 : 
     832                 :   /**
     833                 :    * Hook that is called by nsGenericElement::SetAttr to allow subclasses to
     834                 :    * deal with attribute sets.  This will only be called after we have called
     835                 :    * SetAndTakeAttr and AttributeChanged (that is, after we have actually set
     836                 :    * the attr).  It will always be called under a scriptblocker.
     837                 :    *
     838                 :    * @param aNamespaceID the namespace of the attr being set
     839                 :    * @param aName the localname of the attribute being set
     840                 :    * @param aValue the value it's being set to.  If null, the attr is being
     841                 :    *        removed.
     842                 :    * @param aNotify Whether we plan to notify document observers.
     843                 :    */
     844                 :   // Note that this is inlined so that when subclasses call it it gets
     845                 :   // inlined.  Those calls don't go through a vtable.
     846           11454 :   virtual nsresult AfterSetAttr(PRInt32 aNamespaceID, nsIAtom* aName,
     847                 :                                 const nsAttrValue* aValue, bool aNotify)
     848                 :   {
     849           11454 :     return NS_OK;
     850                 :   }
     851                 : 
     852                 :   /**
     853                 :    * Hook to allow subclasses to produce a different nsEventListenerManager if
     854                 :    * needed for attachment of attribute-defined handlers
     855                 :    */
     856                 :   virtual nsEventListenerManager*
     857                 :     GetEventListenerManagerForAttr(nsIAtom* aAttrName, bool* aDefer);
     858                 : 
     859                 :   /**
     860                 :    * Copy attributes and state to another element
     861                 :    * @param aDest the object to copy to
     862                 :    */
     863                 :   nsresult CopyInnerTo(nsGenericElement* aDest) const;
     864                 : 
     865                 :   /**
     866                 :    * Internal hook for converting an attribute name-string to an atomized name
     867                 :    */
     868                 :   virtual const nsAttrName* InternalGetExistingAttrNameFromQName(const nsAString& aStr) const;
     869                 : 
     870                 :   /**
     871                 :    * Retrieve the rectangle for the offsetX properties, which
     872                 :    * are coordinates relative to the returned aOffsetParent.
     873                 :    *
     874                 :    * @param aRect offset rectangle
     875                 :    * @param aOffsetParent offset parent
     876                 :    */
     877                 :   virtual void GetOffsetRect(nsRect& aRect, nsIContent** aOffsetParent);
     878                 : 
     879                 :   nsIFrame* GetStyledFrame();
     880                 : 
     881               0 :   virtual mozilla::dom::Element* GetNameSpaceElement()
     882                 :   {
     883               0 :     return this;
     884                 :   }
     885                 : 
     886                 :   nsresult GetAttributeNodeNSInternal(const nsAString& aNamespaceURI,
     887                 :                                       const nsAString& aLocalName,
     888                 :                                       nsIDOMAttr** aReturn);
     889                 : 
     890                 : public:
     891                 :   // Because of a bug in MS C++ compiler nsDOMSlots must be declared public,
     892                 :   // otherwise nsXULElement::nsXULSlots doesn't compile.
     893                 :   /**
     894                 :    * There are a set of DOM- and scripting-specific instance variables
     895                 :    * that may only be instantiated when a content object is accessed
     896                 :    * through the DOM. Rather than burn actual slots in the content
     897                 :    * objects for each of these instance variables, we put them off
     898                 :    * in a side structure that's only allocated when the content is
     899                 :    * accessed through the DOM.
     900                 :    */
     901                 :   class nsDOMSlots : public nsINode::nsSlots
     902                 :   {
     903                 :   public:
     904                 :     nsDOMSlots();
     905                 :     virtual ~nsDOMSlots();
     906                 : 
     907                 :     void Traverse(nsCycleCollectionTraversalCallback &cb, bool aIsXUL);
     908                 :     void Unlink(bool aIsXUL);
     909                 : 
     910                 :     /**
     911                 :      * The .style attribute (an interface that forwards to the actual
     912                 :      * style rules)
     913                 :      * @see nsGenericHTMLElement::GetStyle
     914                 :      */
     915                 :     nsCOMPtr<nsICSSDeclaration> mStyle;
     916                 : 
     917                 :     /**
     918                 :      * The .dataset attribute.
     919                 :      * @see nsGenericHTMLElement::GetDataset
     920                 :      */
     921                 :     nsIDOMDOMStringMap* mDataset; // [Weak]
     922                 : 
     923                 :     /**
     924                 :      * SMIL Overridde style rules (for SMIL animation of CSS properties)
     925                 :      * @see nsIContent::GetSMILOverrideStyle
     926                 :      */
     927                 :     nsCOMPtr<nsICSSDeclaration> mSMILOverrideStyle;
     928                 : 
     929                 :     /**
     930                 :      * Holds any SMIL override style rules for this element.
     931                 :      */
     932                 :     nsRefPtr<mozilla::css::StyleRule> mSMILOverrideStyleRule;
     933                 : 
     934                 :     /**
     935                 :      * An object implementing nsIDOMNamedNodeMap for this content (attributes)
     936                 :      * @see nsGenericElement::GetAttributes
     937                 :      */
     938                 :     nsRefPtr<nsDOMAttributeMap> mAttributeMap;
     939                 : 
     940                 :     union {
     941                 :       /**
     942                 :       * The nearest enclosing content node with a binding that created us.
     943                 :       * @see nsGenericElement::GetBindingParent
     944                 :       */
     945                 :       nsIContent* mBindingParent;  // [Weak]
     946                 : 
     947                 :       /**
     948                 :       * The controllers of the XUL Element.
     949                 :       */
     950                 :       nsIControllers* mControllers; // [OWNER]
     951                 :     };
     952                 : 
     953                 :     /**
     954                 :      * An object implementing the .children property for this element.
     955                 :      */
     956                 :     nsRefPtr<nsContentList> mChildrenList;
     957                 : 
     958                 :     /**
     959                 :      * An object implementing the .classList property for this element.
     960                 :      */
     961                 :     nsRefPtr<nsDOMTokenList> mClassList;
     962                 :   };
     963                 : 
     964                 : protected:
     965                 :   // Override from nsINode
     966                 :   virtual nsINode::nsSlots* CreateSlots();
     967                 : 
     968            2067 :   nsDOMSlots *DOMSlots()
     969                 :   {
     970            2067 :     return static_cast<nsDOMSlots*>(GetSlots());
     971                 :   }
     972                 : 
     973          437431 :   nsDOMSlots *GetExistingDOMSlots() const
     974                 :   {
     975          437431 :     return static_cast<nsDOMSlots*>(GetExistingSlots());
     976                 :   }
     977                 : 
     978               0 :   void RegisterFreezableElement() {
     979               0 :     OwnerDoc()->RegisterFreezableElement(this);
     980               0 :   }
     981               0 :   void UnregisterFreezableElement() {
     982               0 :     OwnerDoc()->UnregisterFreezableElement(this);
     983               0 :   }
     984                 : 
     985                 :   /**
     986                 :    * Add/remove this element to the documents id cache
     987                 :    */
     988             202 :   void AddToIdTable(nsIAtom* aId) {
     989             202 :     NS_ASSERTION(HasID(), "Node doesn't have an ID?");
     990             202 :     nsIDocument* doc = GetCurrentDoc();
     991             202 :     if (doc && (!IsInAnonymousSubtree() || doc->IsXUL())) {
     992               0 :       doc->AddToIdTable(this, aId);
     993                 :     }
     994             202 :   }
     995          118845 :   void RemoveFromIdTable() {
     996          118845 :     if (HasID()) {
     997             319 :       nsIDocument* doc = GetCurrentDoc();
     998             319 :       if (doc) {
     999             122 :         nsIAtom* id = DoGetID();
    1000                 :         // id can be null during mutation events evilness. Also, XUL elements
    1001                 :         // loose their proto attributes during cc-unlink, so this can happen
    1002                 :         // during cc-unlink too.
    1003             122 :         if (id) {
    1004             122 :           doc->RemoveFromIdTable(this, DoGetID());
    1005                 :         }
    1006                 :       }
    1007                 :     }
    1008          118845 :   }
    1009                 : 
    1010                 :   /**
    1011                 :    * Functions to carry out event default actions for links of all types
    1012                 :    * (HTML links, XLinks, SVG "XLinks", etc.)
    1013                 :    */
    1014                 : 
    1015                 :   /**
    1016                 :    * Check that we meet the conditions to handle a link event
    1017                 :    * and that we are actually on a link.
    1018                 :    *
    1019                 :    * @param aVisitor event visitor
    1020                 :    * @param aURI the uri of the link, set only if the return value is true [OUT]
    1021                 :    * @return true if we can handle the link event, false otherwise
    1022                 :    */
    1023                 :   bool CheckHandleEventForLinksPrecondition(nsEventChainVisitor& aVisitor,
    1024                 :                                               nsIURI** aURI) const;
    1025                 : 
    1026                 :   /**
    1027                 :    * Handle status bar updates before they can be cancelled.
    1028                 :    */
    1029                 :   nsresult PreHandleEventForLinks(nsEventChainPreVisitor& aVisitor);
    1030                 : 
    1031                 :   /**
    1032                 :    * Handle default actions for link event if the event isn't consumed yet.
    1033                 :    */
    1034                 :   nsresult PostHandleEventForLinks(nsEventChainPostVisitor& aVisitor);
    1035                 : 
    1036                 :   /**
    1037                 :    * Get the target of this link element. Consumers should established that
    1038                 :    * this element is a link (probably using IsLink) before calling this
    1039                 :    * function (or else why call it?)
    1040                 :    *
    1041                 :    * Note: for HTML this gets the value of the 'target' attribute; for XLink
    1042                 :    * this gets the value of the xlink:_moz_target attribute, or failing that,
    1043                 :    * the value of xlink:show, converted to a suitably equivalent named target
    1044                 :    * (e.g. _blank).
    1045                 :    */
    1046                 :   virtual void GetLinkTarget(nsAString& aTarget);
    1047                 : 
    1048                 :   friend class ContentUnbinder;
    1049                 :   /**
    1050                 :    * Array containing all attributes and children for this element
    1051                 :    */
    1052                 :   nsAttrAndChildArray mAttrsAndChildren;
    1053                 : 
    1054                 : private:
    1055                 :   /**
    1056                 :    * Get this element's client area rect in app units.
    1057                 :    * @return the frame's client area
    1058                 :    */
    1059                 :   nsRect GetClientAreaRect();
    1060                 : 
    1061                 :   nsIScrollableFrame* GetScrollFrame(nsIFrame **aStyledFrame = nsnull);
    1062                 : 
    1063                 :   nsContentList* GetChildrenList();
    1064                 : };
    1065                 : 
    1066                 : /**
    1067                 :  * Macros to implement Clone(). _elementName is the class for which to implement
    1068                 :  * Clone.
    1069                 :  */
    1070                 : #define NS_IMPL_ELEMENT_CLONE(_elementName)                                 \
    1071                 : nsresult                                                                    \
    1072                 : _elementName::Clone(nsINodeInfo *aNodeInfo, nsINode **aResult) const        \
    1073                 : {                                                                           \
    1074                 :   *aResult = nsnull;                                                        \
    1075                 :   nsCOMPtr<nsINodeInfo> ni = aNodeInfo;                                     \
    1076                 :   _elementName *it = new _elementName(ni.forget());                         \
    1077                 :   if (!it) {                                                                \
    1078                 :     return NS_ERROR_OUT_OF_MEMORY;                                          \
    1079                 :   }                                                                         \
    1080                 :                                                                             \
    1081                 :   nsCOMPtr<nsINode> kungFuDeathGrip = it;                                   \
    1082                 :   nsresult rv = CopyInnerTo(it);                                            \
    1083                 :   if (NS_SUCCEEDED(rv)) {                                                   \
    1084                 :     kungFuDeathGrip.swap(*aResult);                                         \
    1085                 :   }                                                                         \
    1086                 :                                                                             \
    1087                 :   return rv;                                                                \
    1088                 : }
    1089                 : 
    1090                 : #define NS_IMPL_ELEMENT_CLONE_WITH_INIT(_elementName)                       \
    1091                 : nsresult                                                                    \
    1092                 : _elementName::Clone(nsINodeInfo *aNodeInfo, nsINode **aResult) const        \
    1093                 : {                                                                           \
    1094                 :   *aResult = nsnull;                                                        \
    1095                 :   nsCOMPtr<nsINodeInfo> ni = aNodeInfo;                                     \
    1096                 :   _elementName *it = new _elementName(ni.forget());                         \
    1097                 :   if (!it) {                                                                \
    1098                 :     return NS_ERROR_OUT_OF_MEMORY;                                          \
    1099                 :   }                                                                         \
    1100                 :                                                                             \
    1101                 :   nsCOMPtr<nsINode> kungFuDeathGrip = it;                                   \
    1102                 :   nsresult rv = it->Init();                                                 \
    1103                 :   rv |= CopyInnerTo(it);                                                    \
    1104                 :   if (NS_SUCCEEDED(rv)) {                                                   \
    1105                 :     kungFuDeathGrip.swap(*aResult);                                         \
    1106                 :   }                                                                         \
    1107                 :                                                                             \
    1108                 :   return rv;                                                                \
    1109                 : }
    1110                 : 
    1111                 : #define DOMCI_NODE_DATA(_interface, _class)                             \
    1112                 :   DOMCI_DATA(_interface, _class)                                        \
    1113                 :   nsXPCClassInfo* _class::GetClassInfo()                                \
    1114                 :   {                                                                     \
    1115                 :     return static_cast<nsXPCClassInfo*>(                                \
    1116                 :       NS_GetDOMClassInfoInstance(eDOMClassInfo_##_interface##_id));     \
    1117                 :   }
    1118                 : 
    1119                 : /**
    1120                 :  * Yet another tearoff class for nsGenericElement
    1121                 :  * to implement additional interfaces
    1122                 :  */
    1123                 : class nsNSElementTearoff : public nsIDOMNSElement
    1124               2 : {
    1125                 : public:
    1126               0 :   NS_DECL_CYCLE_COLLECTING_ISUPPORTS
    1127                 : 
    1128                 :   NS_DECL_NSIDOMNSELEMENT
    1129                 : 
    1130            1472 :   NS_DECL_CYCLE_COLLECTION_CLASS(nsNSElementTearoff)
    1131                 : 
    1132               2 :   nsNSElementTearoff(nsGenericElement *aContent) : mContent(aContent)
    1133                 :   {
    1134               2 :   }
    1135                 : 
    1136                 : private:
    1137                 :   nsRefPtr<nsGenericElement> mContent;
    1138                 : };
    1139                 : 
    1140                 : /**
    1141                 :  * Tearoff class to implement nsITouchEventReceiver
    1142                 :  */
    1143                 : class nsTouchEventReceiverTearoff : public nsITouchEventReceiver
    1144               0 : {
    1145                 : public:
    1146               0 :   NS_DECL_CYCLE_COLLECTING_ISUPPORTS
    1147                 : 
    1148               0 :   NS_FORWARD_NSITOUCHEVENTRECEIVER(mElement->)
    1149                 : 
    1150            1464 :   NS_DECL_CYCLE_COLLECTION_CLASS(nsTouchEventReceiverTearoff)
    1151                 : 
    1152               0 :   nsTouchEventReceiverTearoff(nsGenericElement *aElement) : mElement(aElement)
    1153                 :   {
    1154               0 :   }
    1155                 : 
    1156                 : private:
    1157                 :   nsRefPtr<nsGenericElement> mElement;
    1158                 : };
    1159                 : 
    1160                 : /**
    1161                 :  * Tearoff class to implement nsIInlineEventHandlers
    1162                 :  */
    1163                 : class nsInlineEventHandlersTearoff : public nsIInlineEventHandlers
    1164               0 : {
    1165                 : public:
    1166               0 :   NS_DECL_CYCLE_COLLECTING_ISUPPORTS
    1167                 : 
    1168               0 :   NS_FORWARD_NSIINLINEEVENTHANDLERS(mElement->)
    1169                 : 
    1170            1464 :   NS_DECL_CYCLE_COLLECTION_CLASS(nsInlineEventHandlersTearoff)
    1171                 : 
    1172               0 :   nsInlineEventHandlersTearoff(nsGenericElement *aElement) : mElement(aElement)
    1173                 :   {
    1174               0 :   }
    1175                 : 
    1176                 : private:
    1177                 :   nsRefPtr<nsGenericElement> mElement;
    1178                 : };
    1179                 : 
    1180                 : #define NS_ELEMENT_INTERFACE_TABLE_TO_MAP_SEGUE                               \
    1181                 :     rv = nsGenericElement::QueryInterface(aIID, aInstancePtr);                \
    1182                 :     if (NS_SUCCEEDED(rv))                                                     \
    1183                 :       return rv;                                                              \
    1184                 :                                                                               \
    1185                 :     NS_OFFSET_AND_INTERFACE_TABLE_TO_MAP_SEGUE
    1186                 : 
    1187                 : #define NS_ELEMENT_INTERFACE_MAP_END                                          \
    1188                 :     {                                                                         \
    1189                 :       return PostQueryInterface(aIID, aInstancePtr);                          \
    1190                 :     }                                                                         \
    1191                 :                                                                               \
    1192                 :     NS_ADDREF(foundInterface);                                                \
    1193                 :                                                                               \
    1194                 :     *aInstancePtr = foundInterface;                                           \
    1195                 :                                                                               \
    1196                 :     return NS_OK;                                                             \
    1197                 :   }
    1198                 : 
    1199                 : #endif /* nsGenericElement_h___ */

Generated by: LCOV version 1.7