LCOV - code coverage report
Current view: directory - objdir/dist/include - nsIContent.h (source / functions) Found Hit Coverage
Test: app.info Lines: 94 43 45.7 %
Date: 2012-06-02 Functions: 38 19 50.0 %

       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                 : #ifndef nsIContent_h___
      38                 : #define nsIContent_h___
      39                 : 
      40                 : #include "nsCOMPtr.h" // for already_AddRefed
      41                 : #include "nsStringGlue.h"
      42                 : #include "nsCaseTreatment.h"
      43                 : #include "nsChangeHint.h"
      44                 : #include "nsINode.h"
      45                 : #include "nsIDocument.h" // for IsInHTMLDocument
      46                 : 
      47                 : // Forward declarations
      48                 : class nsIAtom;
      49                 : class nsIDOMEvent;
      50                 : class nsIContent;
      51                 : class nsEventListenerManager;
      52                 : class nsIURI;
      53                 : class nsRuleWalker;
      54                 : class nsAttrValue;
      55                 : class nsAttrName;
      56                 : class nsTextFragment;
      57                 : class nsIDocShell;
      58                 : class nsIFrame;
      59                 : class nsISMILAttr;
      60                 : class nsIDOMCSSStyleDeclaration;
      61                 : 
      62                 : namespace mozilla {
      63                 : namespace css {
      64                 : class StyleRule;
      65                 : } // namespace css
      66                 : namespace widget {
      67                 : struct IMEState;
      68                 : } // namespace widget
      69                 : } // namespace mozilla
      70                 : 
      71                 : enum nsLinkState {
      72                 :   eLinkState_Unknown    = 0,
      73                 :   eLinkState_Unvisited  = 1,
      74                 :   eLinkState_Visited    = 2,
      75                 :   eLinkState_NotLink    = 3
      76                 : };
      77                 : 
      78                 : // IID for the nsIContent interface
      79                 : #define NS_ICONTENT_IID \
      80                 : { 0x94671671, 0x9e1b, 0x447a, \
      81                 :   { 0xad, 0xb7, 0xc3, 0x2e, 0x05, 0x6a, 0x96, 0xc9 } }
      82                 : 
      83                 : /**
      84                 :  * A node of content in a document's content model. This interface
      85                 :  * is supported by all content objects.
      86                 :  */
      87          226028 : class nsIContent : public nsINode {
      88                 : public:
      89                 :   typedef mozilla::widget::IMEState IMEState;
      90                 : 
      91                 : #ifdef MOZILLA_INTERNAL_API
      92                 :   // If you're using the external API, the only thing you can know about
      93                 :   // nsIContent is that it exists with an IID
      94                 : 
      95          113018 :   nsIContent(already_AddRefed<nsINodeInfo> aNodeInfo)
      96                 :     : nsINode(aNodeInfo),
      97          113018 :       mPrimaryFrame(nsnull)
      98                 :   {
      99          113018 :     NS_ASSERTION(mNodeInfo,
     100                 :                  "No nsINodeInfo passed to nsIContent, PREPARE TO CRASH!!!");
     101          113018 :   }
     102                 : #endif // MOZILLA_INTERNAL_API
     103                 : 
     104                 :   NS_DECLARE_STATIC_IID_ACCESSOR(NS_ICONTENT_IID)
     105                 : 
     106                 :   /**
     107                 :    * Bind this content node to a tree.  If this method throws, the caller must
     108                 :    * call UnbindFromTree() on the node.  In the typical case of a node being
     109                 :    * appended to a parent, this will be called after the node has been added to
     110                 :    * the parent's child list and before nsIDocumentObserver notifications for
     111                 :    * the addition are dispatched.
     112                 :    * @param aDocument The new document for the content node.  Must match the
     113                 :    *                  current document of aParent, if aParent is not null.
     114                 :    *                  May not be null if aParent is null.
     115                 :    * @param aParent The new parent for the content node.  May be null if the
     116                 :    *                node is being bound as a direct child of the document.
     117                 :    * @param aBindingParent The new binding parent for the content node.
     118                 :    *                       This is allowed to be null.  In that case, the
     119                 :    *                       binding parent of aParent, if any, will be used.
     120                 :    * @param aCompileEventHandlers whether to initialize the event handlers in
     121                 :    *        the document (used by nsXULElement)
     122                 :    * @note either aDocument or aParent must be non-null.  If both are null,
     123                 :    *       this method _will_ crash.
     124                 :    * @note This method must not be called by consumers of nsIContent on a node
     125                 :    *       that is already bound to a tree.  Call UnbindFromTree first.
     126                 :    * @note This method will handle rebinding descendants appropriately (eg
     127                 :    *       changing their binding parent as needed).
     128                 :    * @note This method does not add the content node to aParent's child list
     129                 :    * @throws NS_ERROR_OUT_OF_MEMORY if that happens
     130                 :    */
     131                 :   virtual nsresult BindToTree(nsIDocument* aDocument, nsIContent* aParent,
     132                 :                               nsIContent* aBindingParent,
     133                 :                               bool aCompileEventHandlers) = 0;
     134                 : 
     135                 :   /**
     136                 :    * Unbind this content node from a tree.  This will set its current document
     137                 :    * and binding parent to null.  In the typical case of a node being removed
     138                 :    * from a parent, this will be called after it has been removed from the
     139                 :    * parent's child list and after the nsIDocumentObserver notifications for
     140                 :    * the removal have been dispatched.   
     141                 :    * @param aDeep Whether to recursively unbind the entire subtree rooted at
     142                 :    *        this node.  The only time false should be passed is when the
     143                 :    *        parent node of the content is being destroyed.
     144                 :    * @param aNullParent Whether to null out the parent pointer as well.  This
     145                 :    *        is usually desirable.  This argument should only be false while
     146                 :    *        recursively calling UnbindFromTree when a subtree is detached.
     147                 :    * @note This method is safe to call on nodes that are not bound to a tree.
     148                 :    */
     149                 :   virtual void UnbindFromTree(bool aDeep = true,
     150                 :                               bool aNullParent = true) = 0;
     151                 :   
     152                 :   /**
     153                 :    * DEPRECATED - Use GetCurrentDoc or GetOwnerDoc.
     154                 :    * Get the document for this content.
     155                 :    * @return the document
     156                 :    */
     157             125 :   nsIDocument *GetDocument() const
     158                 :   {
     159             125 :     return GetCurrentDoc();
     160                 :   }
     161                 : 
     162                 :   enum {
     163                 :     /**
     164                 :      * All XBL flattened tree children of the node, as well as :before and
     165                 :      * :after anonymous content and native anonymous children.
     166                 :      *
     167                 :      * @note the result children order is
     168                 :      *   1. :before generated node
     169                 :      *   2. XBL flattened tree children of this node
     170                 :      *   3. native anonymous nodes
     171                 :      *   4. :after generated node
     172                 :      */
     173                 :     eAllChildren = 0,
     174                 : 
     175                 :     /**
     176                 :      * All XBL explicit children of the node (see
     177                 :      * http://www.w3.org/TR/xbl/#explicit3 ), as well as :before and :after
     178                 :      * anonymous content and native anonymous children.
     179                 :      *
     180                 :      * @note the result children order is
     181                 :      *   1. :before generated node
     182                 :      *   2. XBL explicit children of the node
     183                 :      *   3. native anonymous nodes
     184                 :      *   4. :after generated node
     185                 :      */
     186                 :     eAllButXBL = 1,
     187                 : 
     188                 :     /**
     189                 :      * Skip native anonymous content created for placeholder of HTML input,
     190                 :      * used in conjunction with eAllChildren or eAllButXBL.
     191                 :      */
     192                 :     eSkipPlaceholderContent = 2
     193                 :   };
     194                 : 
     195                 :   /**
     196                 :    * Return either the XBL explicit children of the node or the XBL flattened
     197                 :    * tree children of the node, depending on the filter, as well as
     198                 :    * native anonymous children.
     199                 :    *
     200                 :    * @note calling this method with eAllButXBL will return children that are
     201                 :    *  also in the eAllButXBL and eAllChildren child lists of other descendants
     202                 :    *  of this node in the tree, but those other nodes cannot be reached from the
     203                 :    *  eAllButXBL child list.
     204                 :    */
     205                 :   virtual already_AddRefed<nsINodeList> GetChildren(PRUint32 aFilter) = 0;
     206                 : 
     207                 :   /**
     208                 :    * Get whether this content is C++-generated anonymous content
     209                 :    * @see nsIAnonymousContentCreator
     210                 :    * @return whether this content is anonymous
     211                 :    */
     212          112521 :   bool IsRootOfNativeAnonymousSubtree() const
     213                 :   {
     214          112521 :     NS_ASSERTION(!HasFlag(NODE_IS_NATIVE_ANONYMOUS_ROOT) ||
     215                 :                  (HasFlag(NODE_IS_ANONYMOUS) &&
     216                 :                   HasFlag(NODE_IS_IN_ANONYMOUS_SUBTREE)),
     217                 :                  "Some flags seem to be missing!");
     218          112521 :     return HasFlag(NODE_IS_NATIVE_ANONYMOUS_ROOT);
     219                 :   }
     220                 : 
     221                 :   /**
     222                 :    * Makes this content anonymous
     223                 :    * @see nsIAnonymousContentCreator
     224                 :    */
     225               0 :   void SetNativeAnonymous()
     226                 :   {
     227                 :     SetFlags(NODE_IS_ANONYMOUS | NODE_IS_IN_ANONYMOUS_SUBTREE |
     228               0 :              NODE_IS_NATIVE_ANONYMOUS_ROOT);
     229               0 :   }
     230                 : 
     231                 :   /**
     232                 :    * Returns |this| if it is not native anonymous, otherwise
     233                 :    * first non native anonymous ancestor.
     234                 :    */
     235                 :   virtual nsIContent* FindFirstNonNativeAnonymous() const;
     236                 : 
     237                 :   /**
     238                 :    * Returns true if and only if this node has a parent, but is not in
     239                 :    * its parent's child list.
     240                 :    */
     241             417 :   bool IsRootOfAnonymousSubtree() const
     242                 :   {
     243             417 :     NS_ASSERTION(!IsRootOfNativeAnonymousSubtree() ||
     244                 :                  (GetParent() && GetBindingParent() == GetParent()),
     245                 :                  "root of native anonymous subtree must have parent equal "
     246                 :                  "to binding parent");
     247             417 :     NS_ASSERTION(!GetParent() ||
     248                 :                  ((GetBindingParent() == GetParent()) ==
     249                 :                   HasFlag(NODE_IS_ANONYMOUS)) ||
     250                 :                  // Unfortunately default content for XBL insertion points is
     251                 :                  // anonymous content that is bound with the parent of the
     252                 :                  // insertion point as the parent but the bound element for the
     253                 :                  // binding as the binding parent.  So we have to complicate
     254                 :                  // the assert a bit here.
     255                 :                  (GetBindingParent() &&
     256                 :                   (GetBindingParent() == GetParent()->GetBindingParent()) ==
     257                 :                   HasFlag(NODE_IS_ANONYMOUS)),
     258                 :                  "For nodes with parent, flag and GetBindingParent() check "
     259                 :                  "should match");
     260             417 :     return HasFlag(NODE_IS_ANONYMOUS);
     261                 :   }
     262                 : 
     263                 :   /**
     264                 :    * Returns true if there is NOT a path through child lists
     265                 :    * from the top of this node's parent chain back to this node or
     266                 :    * if the node is in native anonymous subtree without a parent.
     267                 :    */
     268              44 :   bool IsInAnonymousSubtree() const
     269                 :   {
     270              44 :     NS_ASSERTION(!IsInNativeAnonymousSubtree() || GetBindingParent() || !GetParent(),
     271                 :                  "must have binding parent when in native anonymous subtree with a parent node");
     272              44 :     return IsInNativeAnonymousSubtree() || GetBindingParent() != nsnull;
     273                 :   }
     274                 : 
     275                 :   /**
     276                 :    * Return true iff this node is in an HTML document (in the HTML5 sense of
     277                 :    * the term, i.e. not in an XHTML/XML document).
     278                 :    */
     279               8 :   inline bool IsInHTMLDocument() const
     280                 :   {
     281               8 :     return OwnerDoc()->IsHTML();
     282                 :   }
     283                 : 
     284                 :   /**
     285                 :    * Get the namespace that this element's tag is defined in
     286                 :    * @return the namespace
     287                 :    */
     288           38600 :   PRInt32 GetNameSpaceID() const
     289                 :   {
     290           38600 :     return mNodeInfo->NamespaceID();
     291                 :   }
     292                 : 
     293                 :   /**
     294                 :    * Get the tag for this element. This will always return a non-null
     295                 :    * atom pointer (as implied by the naming of the method).
     296                 :    */
     297            6666 :   nsIAtom *Tag() const
     298                 :   {
     299            6666 :     return mNodeInfo->NameAtom();
     300                 :   }
     301                 : 
     302                 :   /**
     303                 :    * Get the NodeInfo for this element
     304                 :    * @return the nodes node info
     305                 :    */
     306          110780 :   nsINodeInfo *NodeInfo() const
     307                 :   {
     308          110780 :     return mNodeInfo;
     309                 :   }
     310                 : 
     311          427338 :   inline bool IsInNamespace(PRInt32 aNamespace) const {
     312          427338 :     return mNodeInfo->NamespaceID() == aNamespace;
     313                 :   }
     314                 : 
     315            3706 :   inline bool IsHTML() const {
     316            3706 :     return IsInNamespace(kNameSpaceID_XHTML);
     317                 :   }
     318                 : 
     319            8243 :   inline bool IsHTML(nsIAtom* aTag) const {
     320            8243 :     return mNodeInfo->Equals(aTag, kNameSpaceID_XHTML);
     321                 :   }
     322                 : 
     323            2146 :   inline bool IsSVG() const {
     324            2146 :     return IsInNamespace(kNameSpaceID_SVG);
     325                 :   }
     326                 : 
     327           36743 :   inline bool IsSVG(nsIAtom* aTag) const {
     328           36743 :     return mNodeInfo->Equals(aTag, kNameSpaceID_SVG);
     329                 :   }
     330                 : 
     331          174941 :   inline bool IsXUL() const {
     332          174941 :     return IsInNamespace(kNameSpaceID_XUL);
     333                 :   }
     334                 : 
     335               0 :   inline bool IsMathML() const {
     336               0 :     return IsInNamespace(kNameSpaceID_MathML);
     337                 :   }
     338                 : 
     339               0 :   inline bool IsMathML(nsIAtom* aTag) const {
     340               0 :     return mNodeInfo->Equals(aTag, kNameSpaceID_MathML);
     341                 :   }
     342                 : 
     343                 :   /**
     344                 :    * Returns an atom holding the name of the attribute of type ID on
     345                 :    * this content node (if applicable).  Returns null for non-element
     346                 :    * content nodes.
     347                 :    */
     348                 :   virtual nsIAtom *GetIDAttributeName() const = 0;
     349                 : 
     350                 :   /**
     351                 :    * Normalizes an attribute name and returns it as a nodeinfo if an attribute
     352                 :    * with that name exists. This method is intended for character case
     353                 :    * conversion if the content object is case insensitive (e.g. HTML). Returns
     354                 :    * the nodeinfo of the attribute with the specified name if one exists or
     355                 :    * null otherwise.
     356                 :    *
     357                 :    * @param aStr the unparsed attribute string
     358                 :    * @return the node info. May be nsnull.
     359                 :    */
     360                 :   virtual already_AddRefed<nsINodeInfo> GetExistingAttrNameFromQName(const nsAString& aStr) const = 0;
     361                 : 
     362                 :   /**
     363                 :    * Set attribute values. All attribute values are assumed to have a
     364                 :    * canonical string representation that can be used for these
     365                 :    * methods. The SetAttr method is assumed to perform a translation
     366                 :    * of the canonical form into the underlying content specific
     367                 :    * form.
     368                 :    *
     369                 :    * @param aNameSpaceID the namespace of the attribute
     370                 :    * @param aName the name of the attribute
     371                 :    * @param aValue the value to set
     372                 :    * @param aNotify specifies how whether or not the document should be
     373                 :    *        notified of the attribute change.
     374                 :    */
     375               0 :   nsresult SetAttr(PRInt32 aNameSpaceID, nsIAtom* aName,
     376                 :                    const nsAString& aValue, bool aNotify)
     377                 :   {
     378               0 :     return SetAttr(aNameSpaceID, aName, nsnull, aValue, aNotify);
     379                 :   }
     380                 : 
     381                 :   /**
     382                 :    * Set attribute values. All attribute values are assumed to have a
     383                 :    * canonical String representation that can be used for these
     384                 :    * methods. The SetAttr method is assumed to perform a translation
     385                 :    * of the canonical form into the underlying content specific
     386                 :    * form.
     387                 :    *
     388                 :    * @param aNameSpaceID the namespace of the attribute
     389                 :    * @param aName the name of the attribute
     390                 :    * @param aPrefix the prefix of the attribute
     391                 :    * @param aValue the value to set
     392                 :    * @param aNotify specifies how whether or not the document should be
     393                 :    *        notified of the attribute change.
     394                 :    */
     395                 :   virtual nsresult SetAttr(PRInt32 aNameSpaceID, nsIAtom* aName,
     396                 :                            nsIAtom* aPrefix, const nsAString& aValue,
     397                 :                            bool aNotify) = 0;
     398                 : 
     399                 :   /**
     400                 :    * Get the current value of the attribute. This returns a form that is
     401                 :    * suitable for passing back into SetAttr.
     402                 :    *
     403                 :    * @param aNameSpaceID the namespace of the attr
     404                 :    * @param aName the name of the attr
     405                 :    * @param aResult the value (may legitimately be the empty string) [OUT]
     406                 :    * @returns true if the attribute was set (even when set to empty string)
     407                 :    *          false when not set.
     408                 :    */
     409                 :   virtual bool GetAttr(PRInt32 aNameSpaceID, nsIAtom* aName, 
     410                 :                          nsAString& aResult) const = 0;
     411                 : 
     412                 :   /**
     413                 :    * Determine if an attribute has been set (empty string or otherwise).
     414                 :    *
     415                 :    * @param aNameSpaceId the namespace id of the attribute
     416                 :    * @param aAttr the attribute name
     417                 :    * @return whether an attribute exists
     418                 :    */
     419                 :   virtual bool HasAttr(PRInt32 aNameSpaceID, nsIAtom* aName) const = 0;
     420                 : 
     421                 :   /**
     422                 :    * Test whether this content node's given attribute has the given value.  If
     423                 :    * the attribute is not set at all, this will return false.
     424                 :    *
     425                 :    * @param aNameSpaceID The namespace ID of the attribute.  Must not
     426                 :    *                     be kNameSpaceID_Unknown.
     427                 :    * @param aName The name atom of the attribute.  Must not be null.
     428                 :    * @param aValue The value to compare to.
     429                 :    * @param aCaseSensitive Whether to do a case-sensitive compare on the value.
     430                 :    */
     431               0 :   virtual bool AttrValueIs(PRInt32 aNameSpaceID,
     432                 :                              nsIAtom* aName,
     433                 :                              const nsAString& aValue,
     434                 :                              nsCaseTreatment aCaseSensitive) const
     435                 :   {
     436               0 :     return false;
     437                 :   }
     438                 :   
     439                 :   /**
     440                 :    * Test whether this content node's given attribute has the given value.  If
     441                 :    * the attribute is not set at all, this will return false.
     442                 :    *
     443                 :    * @param aNameSpaceID The namespace ID of the attribute.  Must not
     444                 :    *                     be kNameSpaceID_Unknown.
     445                 :    * @param aName The name atom of the attribute.  Must not be null.
     446                 :    * @param aValue The value to compare to.  Must not be null.
     447                 :    * @param aCaseSensitive Whether to do a case-sensitive compare on the value.
     448                 :    */
     449               0 :   virtual bool AttrValueIs(PRInt32 aNameSpaceID,
     450                 :                              nsIAtom* aName,
     451                 :                              nsIAtom* aValue,
     452                 :                              nsCaseTreatment aCaseSensitive) const
     453                 :   {
     454               0 :     return false;
     455                 :   }
     456                 :   
     457                 :   enum {
     458                 :     ATTR_MISSING = -1,
     459                 :     ATTR_VALUE_NO_MATCH = -2
     460                 :   };
     461                 :   /**
     462                 :    * Check whether this content node's given attribute has one of a given
     463                 :    * list of values. If there is a match, we return the index in the list
     464                 :    * of the first matching value. If there was no attribute at all, then
     465                 :    * we return ATTR_MISSING. If there was an attribute but it didn't
     466                 :    * match, we return ATTR_VALUE_NO_MATCH. A non-negative result always
     467                 :    * indicates a match.
     468                 :    * 
     469                 :    * @param aNameSpaceID The namespace ID of the attribute.  Must not
     470                 :    *                     be kNameSpaceID_Unknown.
     471                 :    * @param aName The name atom of the attribute.  Must not be null.
     472                 :    * @param aValues a NULL-terminated array of pointers to atom values to test
     473                 :    *                against.
     474                 :    * @param aCaseSensitive Whether to do a case-sensitive compare on the values.
     475                 :    * @return ATTR_MISSING, ATTR_VALUE_NO_MATCH or the non-negative index
     476                 :    * indicating the first value of aValues that matched
     477                 :    */
     478                 :   typedef nsIAtom* const* const AttrValuesArray;
     479               0 :   virtual PRInt32 FindAttrValueIn(PRInt32 aNameSpaceID,
     480                 :                                   nsIAtom* aName,
     481                 :                                   AttrValuesArray* aValues,
     482                 :                                   nsCaseTreatment aCaseSensitive) const
     483                 :   {
     484               0 :     return ATTR_MISSING;
     485                 :   }
     486                 : 
     487                 :   /**
     488                 :    * Remove an attribute so that it is no longer explicitly specified.
     489                 :    *
     490                 :    * @param aNameSpaceID the namespace id of the attribute
     491                 :    * @param aAttr the name of the attribute to unset
     492                 :    * @param aNotify specifies whether or not the document should be
     493                 :    * notified of the attribute change
     494                 :    */
     495                 :   virtual nsresult UnsetAttr(PRInt32 aNameSpaceID, nsIAtom* aAttr, 
     496                 :                              bool aNotify) = 0;
     497                 : 
     498                 : 
     499                 :   /**
     500                 :    * Get the namespace / name / prefix of a given attribute.
     501                 :    * 
     502                 :    * @param   aIndex the index of the attribute name
     503                 :    * @returns The name at the given index, or null if the index is
     504                 :    *          out-of-bounds.
     505                 :    * @note    The document returned by NodeInfo()->GetDocument() (if one is
     506                 :    *          present) is *not* necessarily the owner document of the element.
     507                 :    * @note    The pointer returned by this function is only valid until the
     508                 :    *          next call of either GetAttrNameAt or SetAttr on the element.
     509                 :    */
     510                 :   virtual const nsAttrName* GetAttrNameAt(PRUint32 aIndex) const = 0;
     511                 : 
     512                 :   /**
     513                 :    * Get the number of all specified attributes.
     514                 :    *
     515                 :    * @return the number of attributes
     516                 :    */
     517                 :   virtual PRUint32 GetAttrCount() const = 0;
     518                 : 
     519                 :   /**
     520                 :    * Get direct access (but read only) to the text in the text content.
     521                 :    * NOTE: For elements this is *not* the concatenation of all text children,
     522                 :    * it is simply null;
     523                 :    */
     524                 :   virtual const nsTextFragment *GetText() = 0;
     525                 : 
     526                 :   /**
     527                 :    * Get the length of the text content.
     528                 :    * NOTE: This should not be called on elements.
     529                 :    */
     530                 :   virtual PRUint32 TextLength() = 0;
     531                 : 
     532                 :   /**
     533                 :    * Set the text to the given value. If aNotify is true then
     534                 :    * the document is notified of the content change.
     535                 :    * NOTE: For elements this always ASSERTS and returns NS_ERROR_FAILURE
     536                 :    */
     537                 :   virtual nsresult SetText(const PRUnichar* aBuffer, PRUint32 aLength,
     538                 :                            bool aNotify) = 0;
     539                 : 
     540                 :   /**
     541                 :    * Append the given value to the current text. If aNotify is true then
     542                 :    * the document is notified of the content change.
     543                 :    * NOTE: For elements this always ASSERTS and returns NS_ERROR_FAILURE
     544                 :    */
     545                 :   virtual nsresult AppendText(const PRUnichar* aBuffer, PRUint32 aLength,
     546                 :                               bool aNotify) = 0;
     547                 : 
     548                 :   /**
     549                 :    * Set the text to the given value. If aNotify is true then
     550                 :    * the document is notified of the content change.
     551                 :    * NOTE: For elements this always asserts and returns NS_ERROR_FAILURE
     552                 :    */
     553            2661 :   nsresult SetText(const nsAString& aStr, bool aNotify)
     554                 :   {
     555            2661 :     return SetText(aStr.BeginReading(), aStr.Length(), aNotify);
     556                 :   }
     557                 : 
     558                 :   /**
     559                 :    * Query method to see if the frame is nothing but whitespace
     560                 :    * NOTE: Always returns false for elements
     561                 :    */
     562                 :   virtual bool TextIsOnlyWhitespace() = 0;
     563                 : 
     564                 :   /**
     565                 :    * Append the text content to aResult.
     566                 :    * NOTE: This asserts and returns for elements
     567                 :    */
     568                 :   virtual void AppendTextTo(nsAString& aResult) = 0;
     569                 : 
     570                 :   /**
     571                 :    * Check if this content is focusable and in the current tab order.
     572                 :    * Note: most callers should use nsIFrame::IsFocusable() instead as it 
     573                 :    *       checks visibility and other layout factors as well.
     574                 :    * Tabbable is indicated by a nonnegative tabindex & is a subset of focusable.
     575                 :    * For example, only the selected radio button in a group is in the 
     576                 :    * tab order, unless the radio group has no selection in which case
     577                 :    * all of the visible, non-disabled radio buttons in the group are 
     578                 :    * in the tab order. On the other hand, all of the visible, non-disabled 
     579                 :    * radio buttons are always focusable via clicking or script.
     580                 :    * Also, depending on either the accessibility.tabfocus pref or
     581                 :    * a system setting (nowadays: Full keyboard access, mac only)
     582                 :    * some widgets may be focusable but removed from the tab order.
     583                 :    * @param  [inout, optional] aTabIndex the computed tab index
     584                 :    *         In: default tabindex for element (-1 nonfocusable, == 0 focusable)
     585                 :    *         Out: computed tabindex
     586                 :    * @param  [optional] aTabIndex the computed tab index
     587                 :    *         < 0 if not tabbable
     588                 :    *         == 0 if in normal tab order
     589                 :    *         > 0 can be tabbed to in the order specified by this value
     590                 :    * @return whether the content is focusable via mouse, kbd or script.
     591                 :    */
     592               0 :   virtual bool IsFocusable(PRInt32 *aTabIndex = nsnull, bool aWithMouse = false)
     593                 :   {
     594               0 :     if (aTabIndex) 
     595               0 :       *aTabIndex = -1; // Default, not tabbable
     596               0 :     return false;
     597                 :   }
     598                 : 
     599                 :   /**
     600                 :    * The method focuses (or activates) element that accesskey is bound to. It is
     601                 :    * called when accesskey is activated.
     602                 :    *
     603                 :    * @param aKeyCausesActivation - if true then element should be activated
     604                 :    * @param aIsTrustedEvent - if true then event that is cause of accesskey
     605                 :    *                          execution is trusted.
     606                 :    */
     607               0 :   virtual void PerformAccesskey(bool aKeyCausesActivation,
     608                 :                                 bool aIsTrustedEvent)
     609                 :   {
     610               0 :   }
     611                 : 
     612                 :   /*
     613                 :    * Get desired IME state for the content.
     614                 :    *
     615                 :    * @return The desired IME status for the content.
     616                 :    *         This is a combination of an IME enabled value and
     617                 :    *         an IME open value of widget::IMEState.
     618                 :    *         If you return DISABLED, you should not set the OPEN and CLOSE
     619                 :    *         value.
     620                 :    *         PASSWORD should be returned only from password editor, this value
     621                 :    *         has a special meaning. It is used as alternative of DISABLED.
     622                 :    *         PLUGIN should be returned only when plug-in has focus.  When a
     623                 :    *         plug-in is focused content, we should send native events directly.
     624                 :    *         Because we don't process some native events, but they may be needed
     625                 :    *         by the plug-in.
     626                 :    */
     627                 :   virtual IMEState GetDesiredIMEState();
     628                 : 
     629                 :   /**
     630                 :    * Gets content node with the binding (or native code, possibly on the
     631                 :    * frame) responsible for our construction (and existence).  Used by
     632                 :    * anonymous content (both XBL-generated and native-anonymous).
     633                 :    *
     634                 :    * null for all explicit content (i.e., content reachable from the top
     635                 :    * of its GetParent() chain via child lists).
     636                 :    *
     637                 :    * @return the binding parent
     638                 :    */
     639                 :   virtual nsIContent *GetBindingParent() const = 0;
     640                 : 
     641                 :   /**
     642                 :    * Returns the content node that is the parent of this node in the flattened
     643                 :    * tree.
     644                 :    *
     645                 :    * @return the flattened tree parent
     646                 :    */
     647                 :   nsIContent *GetFlattenedTreeParent() const;
     648                 : 
     649                 :   /**
     650                 :    * API to check if this is a link that's traversed in response to user input
     651                 :    * (e.g. a click event). Specializations for HTML/SVG/generic XML allow for
     652                 :    * different types of link in different types of content.
     653                 :    *
     654                 :    * @param aURI Required out param. If this content is a link, a new nsIURI
     655                 :    *             set to this link's URI will be passed out.
     656                 :    *
     657                 :    * @note The out param, aURI, is guaranteed to be set to a non-null pointer
     658                 :    *   when the return value is true.
     659                 :    *
     660                 :    * XXXjwatt: IMO IsInteractiveLink would be a better name.
     661                 :    */
     662                 :   virtual bool IsLink(nsIURI** aURI) const = 0;
     663                 : 
     664                 :   /**
     665                 :    * Get the cached state of the link.  If the state is unknown, 
     666                 :    * return eLinkState_Unknown.
     667                 :    *
     668                 :    * @return The cached link state of the link.
     669                 :    */
     670               0 :   virtual nsLinkState GetLinkState() const
     671                 :   {
     672               0 :     return eLinkState_NotLink;
     673                 :   }
     674                 : 
     675                 :   /**
     676                 :     * Get a pointer to the full href URI (fully resolved and canonicalized,
     677                 :     * since it's an nsIURI object) for link elements.
     678                 :     *
     679                 :     * @return A pointer to the URI or null if the element is not a link or it
     680                 :     *         has no HREF attribute.
     681                 :     */
     682               0 :   virtual already_AddRefed<nsIURI> GetHrefURI() const
     683                 :   {
     684               0 :     return nsnull;
     685                 :   }
     686                 : 
     687                 :   /**
     688                 :    * This method is called when the parser finishes creating the element.  This
     689                 :    * particularly means that it has done everything you would expect it to have
     690                 :    * done after it encounters the > at the end of the tag (for HTML or XML).
     691                 :    * This includes setting the attributes, setting the document / form, and
     692                 :    * placing the element into the tree at its proper place.
     693                 :    *
     694                 :    * For container elements, this is called *before* any of the children are
     695                 :    * created or added into the tree.
     696                 :    *
     697                 :    * NOTE: this is currently only called for input and button, in the HTML
     698                 :    * content sink.  If you want to call it on your element, modify the content
     699                 :    * sink of your choice to do so.  This is an efficiency measure.
     700                 :    *
     701                 :    * If you also need to determine whether the parser is the one creating your
     702                 :    * element (through createElement() or cloneNode() generally) then add a
     703                 :    * PRUint32 aFromParser to the NS_NewXXX() constructor for your element and
     704                 :    * have the parser pass the appropriate flags. See nsHTMLInputElement.cpp and
     705                 :    * nsHTMLContentSink::MakeContentObject().
     706                 :    *
     707                 :    * DO NOT USE THIS METHOD to get around the fact that it's hard to deal with
     708                 :    * attributes dynamically.  If you make attributes affect your element from
     709                 :    * this method, it will only happen on initialization and JavaScript will not
     710                 :    * be able to create elements (which requires them to first create the
     711                 :    * element and then call setAttribute() directly, at which point
     712                 :    * DoneCreatingElement() has already been called and is out of the picture).
     713                 :    */
     714               0 :   virtual void DoneCreatingElement()
     715                 :   {
     716               0 :   }
     717                 : 
     718                 :   /**
     719                 :    * This method is called when the parser begins creating the element's 
     720                 :    * children, if any are present.
     721                 :    *
     722                 :    * This is only called for XTF elements currently.
     723                 :    */
     724           19369 :   virtual void BeginAddingChildren()
     725                 :   {
     726           19369 :   }
     727                 : 
     728                 :   /**
     729                 :    * This method is called when the parser finishes creating the element's children,
     730                 :    * if any are present.
     731                 :    *
     732                 :    * NOTE: this is currently only called for textarea, select, applet, and
     733                 :    * object elements in the HTML content sink.  If you want
     734                 :    * to call it on your element, modify the content sink of your
     735                 :    * choice to do so.  This is an efficiency measure.
     736                 :    *
     737                 :    * If you also need to determine whether the parser is the one creating your
     738                 :    * element (through createElement() or cloneNode() generally) then add a
     739                 :    * boolean aFromParser to the NS_NewXXX() constructor for your element and
     740                 :    * have the parser pass true.  See nsHTMLInputElement.cpp and
     741                 :    * nsHTMLContentSink::MakeContentObject().
     742                 :    *
     743                 :    * @param aHaveNotified Whether there has been a
     744                 :    *        ContentInserted/ContentAppended notification for this content node
     745                 :    *        yet.
     746                 :    */
     747           19419 :   virtual void DoneAddingChildren(bool aHaveNotified)
     748                 :   {
     749           19419 :   }
     750                 : 
     751                 :   /**
     752                 :    * For HTML textarea, select, applet, and object elements, returns
     753                 :    * true if all children have been added OR if the element was not
     754                 :    * created by the parser. Returns true for all other elements.
     755                 :    * @returns false if the element was created by the parser and
     756                 :    *                   it is an HTML textarea, select, applet, or object
     757                 :    *                   element and not all children have been added.
     758                 :    * @returns true otherwise.
     759                 :    */
     760               0 :   virtual bool IsDoneAddingChildren()
     761                 :   {
     762               0 :     return true;
     763                 :   }
     764                 : 
     765                 :   /**
     766                 :    * Get the ID of this content node (the atom corresponding to the
     767                 :    * value of the null-namespace attribute whose name is given by
     768                 :    * GetIDAttributeName().  This may be null if there is no ID.
     769                 :    */
     770               0 :   nsIAtom* GetID() const {
     771               0 :     if (HasID()) {
     772               0 :       return DoGetID();
     773                 :     }
     774               0 :     return nsnull;
     775                 :   }
     776                 : 
     777                 :   /**
     778                 :    * Get the class list of this content node (this corresponds to the
     779                 :    * value of the null-namespace attribute whose name is given by
     780                 :    * GetClassAttributeName()).  This may be null if there are no
     781                 :    * classes, but that's not guaranteed.
     782                 :    */
     783               0 :   const nsAttrValue* GetClasses() const {
     784               0 :     if (HasFlag(NODE_MAY_HAVE_CLASS)) {
     785               0 :       return DoGetClasses();
     786                 :     }
     787               0 :     return nsnull;
     788                 :   }
     789                 : 
     790                 :   /**
     791                 :    * Walk aRuleWalker over the content style rules (presentational
     792                 :    * hint rules) for this content node.
     793                 :    */
     794                 :   NS_IMETHOD WalkContentStyleRules(nsRuleWalker* aRuleWalker) = 0;
     795                 : 
     796                 :   /**
     797                 :    * Get the inline style rule, if any, for this content node
     798                 :    */
     799                 :   virtual mozilla::css::StyleRule* GetInlineStyleRule() = 0;
     800                 : 
     801                 :   /**
     802                 :    * Set the inline style rule for this node.  This will send an
     803                 :    * appropriate AttributeChanged notification if aNotify is true.
     804                 :    */
     805                 :   NS_IMETHOD SetInlineStyleRule(mozilla::css::StyleRule* aStyleRule, bool aNotify) = 0;
     806                 : 
     807                 :   /**
     808                 :    * Is the attribute named stored in the mapped attributes?
     809                 :    *
     810                 :    * // XXXbz we use this method in HasAttributeDependentStyle, so svg
     811                 :    *    returns true here even though it stores nothing in the mapped
     812                 :    *    attributes.
     813                 :    */
     814                 :   NS_IMETHOD_(bool) IsAttributeMapped(const nsIAtom* aAttribute) const = 0;
     815                 : 
     816                 :   /**
     817                 :    * Get a hint that tells the style system what to do when 
     818                 :    * an attribute on this node changes, if something needs to happen
     819                 :    * in response to the change *other* than the result of what is
     820                 :    * mapped into style data via any type of style rule.
     821                 :    */
     822                 :   virtual nsChangeHint GetAttributeChangeHint(const nsIAtom* aAttribute,
     823                 :                                               PRInt32 aModType) const = 0;
     824                 : 
     825                 :   /**
     826                 :    * Returns an atom holding the name of the "class" attribute on this
     827                 :    * content node (if applicable).  Returns null if there is no
     828                 :    * "class" attribute for this type of content node.
     829                 :    */
     830                 :   virtual nsIAtom *GetClassAttributeName() const = 0;
     831                 : 
     832                 :   /**
     833                 :    * Should be called when the node can become editable or when it can stop
     834                 :    * being editable (for example when its contentEditable attribute changes,
     835                 :    * when it is moved into an editable parent, ...).  If aNotify is true and
     836                 :    * the node is an element, this will notify the state change.
     837                 :    */
     838                 :   virtual void UpdateEditableState(bool aNotify);
     839                 : 
     840                 :   /**
     841                 :    * Destroy this node and its children. Ideally this shouldn't be needed
     842                 :    * but for now we need to do it to break cycles.
     843                 :    */
     844                 :   virtual void DestroyContent() = 0;
     845                 : 
     846                 :   /**
     847                 :    * Saves the form state of this node and its children.
     848                 :    */
     849                 :   virtual void SaveSubtreeState() = 0;
     850                 : 
     851                 :   /**
     852                 :    * Getter and setter for our primary frame pointer.  This is the frame that
     853                 :    * is most closely associated with the content. A frame is more closely
     854                 :    * associated with the content than another frame if the one frame contains
     855                 :    * directly or indirectly the other frame (e.g., when a frame is scrolled
     856                 :    * there is a scroll frame that contains the frame being scrolled). This
     857                 :    * frame is always the first continuation.
     858                 :    *
     859                 :    * In the case of absolutely positioned elements and floated elements, this
     860                 :    * frame is the out of flow frame, not the placeholder.
     861                 :    */
     862               0 :   nsIFrame* GetPrimaryFrame() const { return mPrimaryFrame; }
     863               0 :   void SetPrimaryFrame(nsIFrame* aFrame) {
     864               0 :     NS_PRECONDITION(!aFrame || !mPrimaryFrame || aFrame == mPrimaryFrame,
     865                 :                     "Losing track of existing primary frame");
     866               0 :     mPrimaryFrame = aFrame;
     867               0 :   }
     868                 : 
     869                 :   /*
     870                 :    * Returns a new nsISMILAttr that allows the caller to animate the given
     871                 :    * attribute on this element.
     872                 :    *
     873                 :    * The CALLER OWNS the result and is responsible for deleting it.
     874                 :    */
     875                 :   virtual nsISMILAttr* GetAnimatedAttr(PRInt32 aNamespaceID, nsIAtom* aName) = 0;
     876                 : 
     877                 :   /**
     878                 :    * Get the SMIL override style for this content node.  This is a style
     879                 :    * declaration that is applied *after* the inline style, and it can be used
     880                 :    * e.g. to store animated style values.
     881                 :    *
     882                 :    * Note: This method is analogous to the 'GetStyle' method in
     883                 :    * nsGenericHTMLElement and nsStyledElement.
     884                 :    */
     885                 :   virtual nsIDOMCSSStyleDeclaration* GetSMILOverrideStyle() = 0;
     886                 : 
     887                 :   /**
     888                 :    * Get the SMIL override style rule for this content node.  If the rule
     889                 :    * hasn't been created (or if this nsIContent object doesn't support SMIL
     890                 :    * override style), this method simply returns null.
     891                 :    */
     892                 :   virtual mozilla::css::StyleRule* GetSMILOverrideStyleRule() = 0;
     893                 : 
     894                 :   /**
     895                 :    * Set the SMIL override style rule for this node.  If aNotify is true, this
     896                 :    * method will notify the document's pres context, so that the style changes
     897                 :    * will be noticed.
     898                 :    */
     899                 :   virtual nsresult SetSMILOverrideStyleRule(mozilla::css::StyleRule* aStyleRule,
     900                 :                                             bool aNotify) = 0;
     901                 : 
     902                 :   nsresult LookupNamespaceURIInternal(const nsAString& aNamespacePrefix,
     903                 :                                       nsAString& aNamespaceURI) const;
     904                 : 
     905                 :   /**
     906                 :    * If this content has independent selection, e.g., if this is input field
     907                 :    * or textarea, this return TRUE.  Otherwise, false.
     908                 :    */
     909                 :   bool HasIndependentSelection();
     910                 : 
     911                 :   /**
     912                 :    * If the content is a part of HTML editor, this returns editing
     913                 :    * host content.  When the content is in designMode, this returns its body
     914                 :    * element.  Also, when the content isn't editable, this returns null.
     915                 :    */
     916                 :   nsIContent* GetEditingHost();
     917                 : 
     918                 :   /**
     919                 :    * Determing language. Look at the nearest ancestor element that has a lang
     920                 :    * attribute in the XML namespace or is an HTML/SVG element and has a lang in
     921                 :    * no namespace attribute.
     922                 :    */
     923               0 :   void GetLang(nsAString& aResult) const {
     924               0 :     for (const nsIContent* content = this; content; content = content->GetParent()) {
     925               0 :       if (content->GetAttrCount() > 0) {
     926                 :         // xml:lang has precedence over lang on HTML elements (see
     927                 :         // XHTML1 section C.7).
     928                 :         bool hasAttr = content->GetAttr(kNameSpaceID_XML, nsGkAtoms::lang,
     929               0 :                                           aResult);
     930               0 :         if (!hasAttr && (content->IsHTML() || content->IsSVG())) {
     931                 :           hasAttr = content->GetAttr(kNameSpaceID_None, nsGkAtoms::lang,
     932               0 :                                      aResult);
     933                 :         }
     934               0 :         NS_ASSERTION(hasAttr || aResult.IsEmpty(),
     935                 :                      "GetAttr that returns false should not make string non-empty");
     936               0 :         if (hasAttr) {
     937               0 :           return;
     938                 :         }
     939                 :       }
     940                 :     }
     941                 :   }
     942                 : 
     943                 :   // Overloaded from nsINode
     944                 :   virtual already_AddRefed<nsIURI> GetBaseURI() const;
     945                 : 
     946                 :   virtual nsresult PreHandleEvent(nsEventChainPreVisitor& aVisitor);
     947                 : 
     948                 :   virtual bool IsPurple() = 0;
     949                 :   virtual void RemovePurple() = 0;
     950                 : 
     951                 : protected:
     952                 :   /**
     953                 :    * Hook for implementing GetID.  This is guaranteed to only be
     954                 :    * called if HasID() is true.
     955                 :    */
     956                 :   virtual nsIAtom* DoGetID() const = 0;
     957                 : 
     958                 : private:
     959                 :   /**
     960                 :    * Hook for implementing GetClasses.  This is guaranteed to only be
     961                 :    * called if the NODE_MAY_HAVE_CLASS flag is set.
     962                 :    */
     963                 :   virtual const nsAttrValue* DoGetClasses() const = 0;
     964                 : 
     965                 :   /**
     966                 :    * Pointer to our primary frame.  Might be null.
     967                 :    */
     968                 :   nsIFrame* mPrimaryFrame;
     969                 : 
     970                 : public:
     971                 : #ifdef DEBUG
     972                 :   /**
     973                 :    * List the content (and anything it contains) out to the given
     974                 :    * file stream. Use aIndent as the base indent during formatting.
     975                 :    */
     976                 :   virtual void List(FILE* out = stdout, PRInt32 aIndent = 0) const = 0;
     977                 : 
     978                 :   /**
     979                 :    * Dump the content (and anything it contains) out to the given
     980                 :    * file stream. Use aIndent as the base indent during formatting.
     981                 :    */
     982                 :   virtual void DumpContent(FILE* out = stdout, PRInt32 aIndent = 0,
     983                 :                            bool aDumpAll = true) const = 0;
     984                 : #endif
     985                 : 
     986                 :   enum ETabFocusType {
     987                 :   //eTabFocus_textControlsMask = (1<<0),  // unused - textboxes always tabbable
     988                 :     eTabFocus_formElementsMask = (1<<1),  // non-text form elements
     989                 :     eTabFocus_linksMask = (1<<2),         // links
     990                 :     eTabFocus_any = 1 + (1<<1) + (1<<2)   // everything that can be focused
     991                 :   };
     992                 : 
     993                 :   // Tab focus model bit field:
     994                 :   static PRInt32 sTabFocusModel;
     995                 : 
     996                 :   // accessibility.tabfocus_applies_to_xul pref - if it is set to true,
     997                 :   // the tabfocus bit field applies to xul elements.
     998                 :   static bool sTabFocusModelAppliesToXUL;
     999                 : };
    1000                 : 
    1001                 : NS_DEFINE_STATIC_IID_ACCESSOR(nsIContent, NS_ICONTENT_IID)
    1002                 : 
    1003                 : #endif /* nsIContent_h___ */

Generated by: LCOV version 1.7