content/base/public/nsIContent.h

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/content/base/public/nsIContent.h	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,1020 @@
     1.4 +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
     1.5 +/* This Source Code Form is subject to the terms of the Mozilla Public
     1.6 + * License, v. 2.0. If a copy of the MPL was not distributed with this
     1.7 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
     1.8 +#ifndef nsIContent_h___
     1.9 +#define nsIContent_h___
    1.10 +
    1.11 +#include "mozilla/Attributes.h"
    1.12 +#include "nsCaseTreatment.h" // for enum, cannot be forward-declared
    1.13 +#include "nsINode.h"
    1.14 +
    1.15 +// Forward declarations
    1.16 +class nsAString;
    1.17 +class nsIAtom;
    1.18 +class nsIURI;
    1.19 +class nsRuleWalker;
    1.20 +class nsAttrValue;
    1.21 +class nsAttrName;
    1.22 +class nsTextFragment;
    1.23 +class nsIFrame;
    1.24 +class nsXBLBinding;
    1.25 +
    1.26 +namespace mozilla {
    1.27 +class EventChainPreVisitor;
    1.28 +namespace dom {
    1.29 +class ShadowRoot;
    1.30 +struct CustomElementData;
    1.31 +} // namespace dom
    1.32 +namespace widget {
    1.33 +struct IMEState;
    1.34 +} // namespace widget
    1.35 +} // namespace mozilla
    1.36 +
    1.37 +enum nsLinkState {
    1.38 +  eLinkState_Unvisited  = 1,
    1.39 +  eLinkState_Visited    = 2,
    1.40 +  eLinkState_NotLink    = 3 
    1.41 +};
    1.42 +
    1.43 +// IID for the nsIContent interface
    1.44 +#define NS_ICONTENT_IID \
    1.45 +{ 0x1329e5b7, 0x4bcd, 0x450c, \
    1.46 +  { 0xa2, 0x3a, 0x98, 0xc5, 0x85, 0xcd, 0x73, 0xf9 } }
    1.47 +
    1.48 +/**
    1.49 + * A node of content in a document's content model. This interface
    1.50 + * is supported by all content objects.
    1.51 + */
    1.52 +class nsIContent : public nsINode {
    1.53 +public:
    1.54 +  typedef mozilla::widget::IMEState IMEState;
    1.55 +
    1.56 +#ifdef MOZILLA_INTERNAL_API
    1.57 +  // If you're using the external API, the only thing you can know about
    1.58 +  // nsIContent is that it exists with an IID
    1.59 +
    1.60 +  nsIContent(already_AddRefed<nsINodeInfo>& aNodeInfo)
    1.61 +    : nsINode(aNodeInfo)
    1.62 +  {
    1.63 +    MOZ_ASSERT(mNodeInfo);
    1.64 +    SetNodeIsContent();
    1.65 +  }
    1.66 +#endif // MOZILLA_INTERNAL_API
    1.67 +
    1.68 +  NS_DECLARE_STATIC_IID_ACCESSOR(NS_ICONTENT_IID)
    1.69 +
    1.70 +  /**
    1.71 +   * Bind this content node to a tree.  If this method throws, the caller must
    1.72 +   * call UnbindFromTree() on the node.  In the typical case of a node being
    1.73 +   * appended to a parent, this will be called after the node has been added to
    1.74 +   * the parent's child list and before nsIDocumentObserver notifications for
    1.75 +   * the addition are dispatched.
    1.76 +   * @param aDocument The new document for the content node.  Must match the
    1.77 +   *                  current document of aParent, if aParent is not null.
    1.78 +   *                  May not be null if aParent is null.
    1.79 +   * @param aParent The new parent for the content node.  May be null if the
    1.80 +   *                node is being bound as a direct child of the document.
    1.81 +   * @param aBindingParent The new binding parent for the content node.
    1.82 +   *                       This is must either be non-null if a particular
    1.83 +   *                       binding parent is desired or match aParent's binding
    1.84 +   *                       parent.
    1.85 +   * @param aCompileEventHandlers whether to initialize the event handlers in
    1.86 +   *        the document (used by nsXULElement)
    1.87 +   * @note either aDocument or aParent must be non-null.  If both are null,
    1.88 +   *       this method _will_ crash.
    1.89 +   * @note This method must not be called by consumers of nsIContent on a node
    1.90 +   *       that is already bound to a tree.  Call UnbindFromTree first.
    1.91 +   * @note This method will handle rebinding descendants appropriately (eg
    1.92 +   *       changing their binding parent as needed).
    1.93 +   * @note This method does not add the content node to aParent's child list
    1.94 +   * @throws NS_ERROR_OUT_OF_MEMORY if that happens
    1.95 +   */
    1.96 +  virtual nsresult BindToTree(nsIDocument* aDocument, nsIContent* aParent,
    1.97 +                              nsIContent* aBindingParent,
    1.98 +                              bool aCompileEventHandlers) = 0;
    1.99 +
   1.100 +  /**
   1.101 +   * Unbind this content node from a tree.  This will set its current document
   1.102 +   * and binding parent to null.  In the typical case of a node being removed
   1.103 +   * from a parent, this will be called after it has been removed from the
   1.104 +   * parent's child list and after the nsIDocumentObserver notifications for
   1.105 +   * the removal have been dispatched.   
   1.106 +   * @param aDeep Whether to recursively unbind the entire subtree rooted at
   1.107 +   *        this node.  The only time false should be passed is when the
   1.108 +   *        parent node of the content is being destroyed.
   1.109 +   * @param aNullParent Whether to null out the parent pointer as well.  This
   1.110 +   *        is usually desirable.  This argument should only be false while
   1.111 +   *        recursively calling UnbindFromTree when a subtree is detached.
   1.112 +   * @note This method is safe to call on nodes that are not bound to a tree.
   1.113 +   */
   1.114 +  virtual void UnbindFromTree(bool aDeep = true,
   1.115 +                              bool aNullParent = true) = 0;
   1.116 +  
   1.117 +  /**
   1.118 +   * DEPRECATED - Use GetCurrentDoc or GetOwnerDoc.
   1.119 +   * Get the document for this content.
   1.120 +   * @return the document
   1.121 +   */
   1.122 +  nsIDocument *GetDocument() const
   1.123 +  {
   1.124 +    return GetCurrentDoc();
   1.125 +  }
   1.126 +
   1.127 +  enum {
   1.128 +    /**
   1.129 +     * All XBL flattened tree children of the node, as well as :before and
   1.130 +     * :after anonymous content and native anonymous children.
   1.131 +     *
   1.132 +     * @note the result children order is
   1.133 +     *   1. :before generated node
   1.134 +     *   2. XBL flattened tree children of this node
   1.135 +     *   3. native anonymous nodes
   1.136 +     *   4. :after generated node
   1.137 +     */
   1.138 +    eAllChildren = 0,
   1.139 +
   1.140 +    /**
   1.141 +     * All XBL explicit children of the node (see
   1.142 +     * http://www.w3.org/TR/xbl/#explicit3 ), as well as :before and :after
   1.143 +     * anonymous content and native anonymous children.
   1.144 +     *
   1.145 +     * @note the result children order is
   1.146 +     *   1. :before generated node
   1.147 +     *   2. XBL explicit children of the node
   1.148 +     *   3. native anonymous nodes
   1.149 +     *   4. :after generated node
   1.150 +     */
   1.151 +    eAllButXBL = 1,
   1.152 +
   1.153 +    /**
   1.154 +     * Skip native anonymous content created for placeholder of HTML input,
   1.155 +     * used in conjunction with eAllChildren or eAllButXBL.
   1.156 +     */
   1.157 +    eSkipPlaceholderContent = 2
   1.158 +  };
   1.159 +
   1.160 +  /**
   1.161 +   * Return either the XBL explicit children of the node or the XBL flattened
   1.162 +   * tree children of the node, depending on the filter, as well as
   1.163 +   * native anonymous children.
   1.164 +   *
   1.165 +   * @note calling this method with eAllButXBL will return children that are
   1.166 +   *  also in the eAllButXBL and eAllChildren child lists of other descendants
   1.167 +   *  of this node in the tree, but those other nodes cannot be reached from the
   1.168 +   *  eAllButXBL child list.
   1.169 +   */
   1.170 +  virtual already_AddRefed<nsINodeList> GetChildren(uint32_t aFilter) = 0;
   1.171 +
   1.172 +  /**
   1.173 +   * Get whether this content is C++-generated anonymous content
   1.174 +   * @see nsIAnonymousContentCreator
   1.175 +   * @return whether this content is anonymous
   1.176 +   */
   1.177 +  bool IsRootOfNativeAnonymousSubtree() const
   1.178 +  {
   1.179 +    NS_ASSERTION(!HasFlag(NODE_IS_NATIVE_ANONYMOUS_ROOT) ||
   1.180 +                 (HasFlag(NODE_IS_ANONYMOUS_ROOT) &&
   1.181 +                  HasFlag(NODE_IS_IN_NATIVE_ANONYMOUS_SUBTREE)),
   1.182 +                 "Some flags seem to be missing!");
   1.183 +    return HasFlag(NODE_IS_NATIVE_ANONYMOUS_ROOT);
   1.184 +  }
   1.185 +
   1.186 +  bool IsRootOfChromeAccessOnlySubtree() const
   1.187 +  {
   1.188 +    return HasFlag(NODE_IS_NATIVE_ANONYMOUS_ROOT |
   1.189 +                   NODE_IS_ROOT_OF_CHROME_ONLY_ACCESS);
   1.190 +  }
   1.191 +
   1.192 +  /**
   1.193 +   * Makes this content anonymous
   1.194 +   * @see nsIAnonymousContentCreator
   1.195 +   */
   1.196 +  void SetIsNativeAnonymousRoot()
   1.197 +  {
   1.198 +    SetFlags(NODE_IS_ANONYMOUS_ROOT | NODE_IS_IN_NATIVE_ANONYMOUS_SUBTREE |
   1.199 +             NODE_IS_NATIVE_ANONYMOUS_ROOT);
   1.200 +  }
   1.201 +
   1.202 +  /**
   1.203 +   * Returns |this| if it is not chrome-only/native anonymous, otherwise
   1.204 +   * first non chrome-only/native anonymous ancestor.
   1.205 +   */
   1.206 +  virtual nsIContent* FindFirstNonChromeOnlyAccessContent() const;
   1.207 +
   1.208 +  /**
   1.209 +   * Returns true if and only if this node has a parent, but is not in
   1.210 +   * its parent's child list.
   1.211 +   */
   1.212 +  bool IsRootOfAnonymousSubtree() const
   1.213 +  {
   1.214 +    NS_ASSERTION(!IsRootOfNativeAnonymousSubtree() ||
   1.215 +                 (GetParent() && GetBindingParent() == GetParent()),
   1.216 +                 "root of native anonymous subtree must have parent equal "
   1.217 +                 "to binding parent");
   1.218 +    NS_ASSERTION(!GetParent() ||
   1.219 +                 ((GetBindingParent() == GetParent()) ==
   1.220 +                  HasFlag(NODE_IS_ANONYMOUS_ROOT)) ||
   1.221 +                 // Unfortunately default content for XBL insertion points is
   1.222 +                 // anonymous content that is bound with the parent of the
   1.223 +                 // insertion point as the parent but the bound element for the
   1.224 +                 // binding as the binding parent.  So we have to complicate
   1.225 +                 // the assert a bit here.
   1.226 +                 (GetBindingParent() &&
   1.227 +                  (GetBindingParent() == GetParent()->GetBindingParent()) ==
   1.228 +                  HasFlag(NODE_IS_ANONYMOUS_ROOT)),
   1.229 +                 "For nodes with parent, flag and GetBindingParent() check "
   1.230 +                 "should match");
   1.231 +    return HasFlag(NODE_IS_ANONYMOUS_ROOT);
   1.232 +  }
   1.233 +
   1.234 +  /**
   1.235 +   * Returns true if there is NOT a path through child lists
   1.236 +   * from the top of this node's parent chain back to this node or
   1.237 +   * if the node is in native anonymous subtree without a parent.
   1.238 +   */
   1.239 +  bool IsInAnonymousSubtree() const
   1.240 +  {
   1.241 +    NS_ASSERTION(!IsInNativeAnonymousSubtree() || GetBindingParent() ||
   1.242 +                 (!IsInDoc() &&
   1.243 +                  static_cast<nsIContent*>(SubtreeRoot())->IsInNativeAnonymousSubtree()),
   1.244 +                 "Must have binding parent when in native anonymous subtree which is in document.\n"
   1.245 +                 "Native anonymous subtree which is not in document must have native anonymous root.");
   1.246 +    return IsInNativeAnonymousSubtree() || (!HasFlag(NODE_IS_IN_SHADOW_TREE) && GetBindingParent() != nullptr);
   1.247 +  }
   1.248 +
   1.249 +  /**
   1.250 +   * Return true iff this node is in an HTML document (in the HTML5 sense of
   1.251 +   * the term, i.e. not in an XHTML/XML document).
   1.252 +   */
   1.253 +  inline bool IsInHTMLDocument() const;
   1.254 +
   1.255 +  /**
   1.256 +   * Get the namespace that this element's tag is defined in
   1.257 +   * @return the namespace
   1.258 +   */
   1.259 +  inline int32_t GetNameSpaceID() const
   1.260 +  {
   1.261 +    return mNodeInfo->NamespaceID();
   1.262 +  }
   1.263 +
   1.264 +  /**
   1.265 +   * Get the NodeInfo for this element
   1.266 +   * @return the nodes node info
   1.267 +   */
   1.268 +  inline nsINodeInfo* NodeInfo() const
   1.269 +  {
   1.270 +    return mNodeInfo;
   1.271 +  }
   1.272 +
   1.273 +  inline bool IsInNamespace(int32_t aNamespace) const
   1.274 +  {
   1.275 +    return mNodeInfo->NamespaceID() == aNamespace;
   1.276 +  }
   1.277 +
   1.278 +  inline bool IsHTML() const
   1.279 +  {
   1.280 +    return IsInNamespace(kNameSpaceID_XHTML);
   1.281 +  }
   1.282 +
   1.283 +  inline bool IsHTML(nsIAtom* aTag) const
   1.284 +  {
   1.285 +    return mNodeInfo->Equals(aTag, kNameSpaceID_XHTML);
   1.286 +  }
   1.287 +
   1.288 +  inline bool IsSVG() const
   1.289 +  {
   1.290 +    return IsInNamespace(kNameSpaceID_SVG);
   1.291 +  }
   1.292 +
   1.293 +  inline bool IsSVG(nsIAtom* aTag) const
   1.294 +  {
   1.295 +    return mNodeInfo->Equals(aTag, kNameSpaceID_SVG);
   1.296 +  }
   1.297 +
   1.298 +  inline bool IsXUL() const
   1.299 +  {
   1.300 +    return IsInNamespace(kNameSpaceID_XUL);
   1.301 +  }
   1.302 +
   1.303 +  inline bool IsXUL(nsIAtom* aTag) const
   1.304 +  {
   1.305 +    return mNodeInfo->Equals(aTag, kNameSpaceID_XUL);
   1.306 +  }
   1.307 +
   1.308 +  inline bool IsMathML() const
   1.309 +  {
   1.310 +    return IsInNamespace(kNameSpaceID_MathML);
   1.311 +  }
   1.312 +
   1.313 +  inline bool IsMathML(nsIAtom* aTag) const
   1.314 +  {
   1.315 +    return mNodeInfo->Equals(aTag, kNameSpaceID_MathML);
   1.316 +  }
   1.317 +
   1.318 +  inline bool IsActiveChildrenElement() const
   1.319 +  {
   1.320 +    return mNodeInfo->Equals(nsGkAtoms::children, kNameSpaceID_XBL) &&
   1.321 +           GetBindingParent();
   1.322 +  }
   1.323 +
   1.324 +  /**
   1.325 +   * Returns an atom holding the name of the attribute of type ID on
   1.326 +   * this content node (if applicable).  Returns null for non-element
   1.327 +   * content nodes.
   1.328 +   */
   1.329 +  virtual nsIAtom *GetIDAttributeName() const = 0;
   1.330 +
   1.331 +  /**
   1.332 +   * Set attribute values. All attribute values are assumed to have a
   1.333 +   * canonical string representation that can be used for these
   1.334 +   * methods. The SetAttr method is assumed to perform a translation
   1.335 +   * of the canonical form into the underlying content specific
   1.336 +   * form.
   1.337 +   *
   1.338 +   * @param aNameSpaceID the namespace of the attribute
   1.339 +   * @param aName the name of the attribute
   1.340 +   * @param aValue the value to set
   1.341 +   * @param aNotify specifies how whether or not the document should be
   1.342 +   *        notified of the attribute change.
   1.343 +   */
   1.344 +  nsresult SetAttr(int32_t aNameSpaceID, nsIAtom* aName,
   1.345 +                   const nsAString& aValue, bool aNotify)
   1.346 +  {
   1.347 +    return SetAttr(aNameSpaceID, aName, nullptr, aValue, aNotify);
   1.348 +  }
   1.349 +
   1.350 +  /**
   1.351 +   * Set attribute values. All attribute values are assumed to have a
   1.352 +   * canonical String representation that can be used for these
   1.353 +   * methods. The SetAttr method is assumed to perform a translation
   1.354 +   * of the canonical form into the underlying content specific
   1.355 +   * form.
   1.356 +   *
   1.357 +   * @param aNameSpaceID the namespace of the attribute
   1.358 +   * @param aName the name of the attribute
   1.359 +   * @param aPrefix the prefix of the attribute
   1.360 +   * @param aValue the value to set
   1.361 +   * @param aNotify specifies how whether or not the document should be
   1.362 +   *        notified of the attribute change.
   1.363 +   */
   1.364 +  virtual nsresult SetAttr(int32_t aNameSpaceID, nsIAtom* aName,
   1.365 +                           nsIAtom* aPrefix, const nsAString& aValue,
   1.366 +                           bool aNotify) = 0;
   1.367 +
   1.368 +  /**
   1.369 +   * Get the current value of the attribute. This returns a form that is
   1.370 +   * suitable for passing back into SetAttr.
   1.371 +   *
   1.372 +   * @param aNameSpaceID the namespace of the attr
   1.373 +   * @param aName the name of the attr
   1.374 +   * @param aResult the value (may legitimately be the empty string) [OUT]
   1.375 +   * @returns true if the attribute was set (even when set to empty string)
   1.376 +   *          false when not set.
   1.377 +   */
   1.378 +  bool GetAttr(int32_t aNameSpaceID, nsIAtom* aName,
   1.379 +               nsAString& aResult) const;
   1.380 +
   1.381 +  /**
   1.382 +   * Determine if an attribute has been set (empty string or otherwise).
   1.383 +   *
   1.384 +   * @param aNameSpaceId the namespace id of the attribute
   1.385 +   * @param aAttr the attribute name
   1.386 +   * @return whether an attribute exists
   1.387 +   */
   1.388 +  bool HasAttr(int32_t aNameSpaceID, nsIAtom* aName) const;
   1.389 +
   1.390 +  /**
   1.391 +   * Test whether this content node's given attribute has the given value.  If
   1.392 +   * the attribute is not set at all, this will return false.
   1.393 +   *
   1.394 +   * @param aNameSpaceID The namespace ID of the attribute.  Must not
   1.395 +   *                     be kNameSpaceID_Unknown.
   1.396 +   * @param aName The name atom of the attribute.  Must not be null.
   1.397 +   * @param aValue The value to compare to.
   1.398 +   * @param aCaseSensitive Whether to do a case-sensitive compare on the value.
   1.399 +   */
   1.400 +  bool AttrValueIs(int32_t aNameSpaceID,
   1.401 +                   nsIAtom* aName,
   1.402 +                   const nsAString& aValue,
   1.403 +                   nsCaseTreatment aCaseSensitive) const;
   1.404 +  
   1.405 +  /**
   1.406 +   * Test whether this content node's given attribute has the given value.  If
   1.407 +   * the attribute is not set at all, this will return false.
   1.408 +   *
   1.409 +   * @param aNameSpaceID The namespace ID of the attribute.  Must not
   1.410 +   *                     be kNameSpaceID_Unknown.
   1.411 +   * @param aName The name atom of the attribute.  Must not be null.
   1.412 +   * @param aValue The value to compare to.  Must not be null.
   1.413 +   * @param aCaseSensitive Whether to do a case-sensitive compare on the value.
   1.414 +   */
   1.415 +  bool AttrValueIs(int32_t aNameSpaceID,
   1.416 +                   nsIAtom* aName,
   1.417 +                   nsIAtom* aValue,
   1.418 +                   nsCaseTreatment aCaseSensitive) const;
   1.419 +  
   1.420 +  enum {
   1.421 +    ATTR_MISSING = -1,
   1.422 +    ATTR_VALUE_NO_MATCH = -2
   1.423 +  };
   1.424 +  /**
   1.425 +   * Check whether this content node's given attribute has one of a given
   1.426 +   * list of values. If there is a match, we return the index in the list
   1.427 +   * of the first matching value. If there was no attribute at all, then
   1.428 +   * we return ATTR_MISSING. If there was an attribute but it didn't
   1.429 +   * match, we return ATTR_VALUE_NO_MATCH. A non-negative result always
   1.430 +   * indicates a match.
   1.431 +   * 
   1.432 +   * @param aNameSpaceID The namespace ID of the attribute.  Must not
   1.433 +   *                     be kNameSpaceID_Unknown.
   1.434 +   * @param aName The name atom of the attribute.  Must not be null.
   1.435 +   * @param aValues a nullptr-terminated array of pointers to atom values to test
   1.436 +   *                against.
   1.437 +   * @param aCaseSensitive Whether to do a case-sensitive compare on the values.
   1.438 +   * @return ATTR_MISSING, ATTR_VALUE_NO_MATCH or the non-negative index
   1.439 +   * indicating the first value of aValues that matched
   1.440 +   */
   1.441 +  typedef nsIAtom* const* const AttrValuesArray;
   1.442 +  virtual int32_t FindAttrValueIn(int32_t aNameSpaceID,
   1.443 +                                  nsIAtom* aName,
   1.444 +                                  AttrValuesArray* aValues,
   1.445 +                                  nsCaseTreatment aCaseSensitive) const
   1.446 +  {
   1.447 +    return ATTR_MISSING;
   1.448 +  }
   1.449 +
   1.450 +  /**
   1.451 +   * Remove an attribute so that it is no longer explicitly specified.
   1.452 +   *
   1.453 +   * @param aNameSpaceID the namespace id of the attribute
   1.454 +   * @param aAttr the name of the attribute to unset
   1.455 +   * @param aNotify specifies whether or not the document should be
   1.456 +   * notified of the attribute change
   1.457 +   */
   1.458 +  virtual nsresult UnsetAttr(int32_t aNameSpaceID, nsIAtom* aAttr, 
   1.459 +                             bool aNotify) = 0;
   1.460 +
   1.461 +
   1.462 +  /**
   1.463 +   * Get the namespace / name / prefix of a given attribute.
   1.464 +   * 
   1.465 +   * @param   aIndex the index of the attribute name
   1.466 +   * @returns The name at the given index, or null if the index is
   1.467 +   *          out-of-bounds.
   1.468 +   * @note    The document returned by NodeInfo()->GetDocument() (if one is
   1.469 +   *          present) is *not* necessarily the owner document of the element.
   1.470 +   * @note    The pointer returned by this function is only valid until the
   1.471 +   *          next call of either GetAttrNameAt or SetAttr on the element.
   1.472 +   */
   1.473 +  virtual const nsAttrName* GetAttrNameAt(uint32_t aIndex) const = 0;
   1.474 +
   1.475 +  /**
   1.476 +   * Get the number of all specified attributes.
   1.477 +   *
   1.478 +   * @return the number of attributes
   1.479 +   */
   1.480 +  virtual uint32_t GetAttrCount() const = 0;
   1.481 +
   1.482 +  /**
   1.483 +   * Get direct access (but read only) to the text in the text content.
   1.484 +   * NOTE: For elements this is *not* the concatenation of all text children,
   1.485 +   * it is simply null;
   1.486 +   */
   1.487 +  virtual const nsTextFragment *GetText() = 0;
   1.488 +
   1.489 +  /**
   1.490 +   * Get the length of the text content.
   1.491 +   * NOTE: This should not be called on elements.
   1.492 +   */
   1.493 +  virtual uint32_t TextLength() const = 0;
   1.494 +
   1.495 +   /**
   1.496 +    * Determines if an event attribute name (such as onclick) is valid for
   1.497 +    * a given element type.
   1.498 +    * @note calls nsContentUtils::IsEventAttributeName with right flag
   1.499 +    * @note overridden by subclasses as needed
   1.500 +    * @param aName the event name to look up
   1.501 +    */
   1.502 +  virtual bool IsEventAttributeName(nsIAtom* aName)
   1.503 +  {
   1.504 +    return false;
   1.505 +  }
   1.506 +
   1.507 +  /**
   1.508 +   * Set the text to the given value. If aNotify is true then
   1.509 +   * the document is notified of the content change.
   1.510 +   * NOTE: For elements this always ASSERTS and returns NS_ERROR_FAILURE
   1.511 +   */
   1.512 +  virtual nsresult SetText(const char16_t* aBuffer, uint32_t aLength,
   1.513 +                           bool aNotify) = 0;
   1.514 +
   1.515 +  /**
   1.516 +   * Append the given value to the current text. If aNotify is true then
   1.517 +   * the document is notified of the content change.
   1.518 +   * NOTE: For elements this always ASSERTS and returns NS_ERROR_FAILURE
   1.519 +   */
   1.520 +  virtual nsresult AppendText(const char16_t* aBuffer, uint32_t aLength,
   1.521 +                              bool aNotify) = 0;
   1.522 +
   1.523 +  /**
   1.524 +   * Set the text to the given value. If aNotify is true then
   1.525 +   * the document is notified of the content change.
   1.526 +   * NOTE: For elements this always asserts and returns NS_ERROR_FAILURE
   1.527 +   */
   1.528 +  nsresult SetText(const nsAString& aStr, bool aNotify)
   1.529 +  {
   1.530 +    return SetText(aStr.BeginReading(), aStr.Length(), aNotify);
   1.531 +  }
   1.532 +
   1.533 +  /**
   1.534 +   * Query method to see if the frame is nothing but whitespace
   1.535 +   * NOTE: Always returns false for elements
   1.536 +   */
   1.537 +  virtual bool TextIsOnlyWhitespace() = 0;
   1.538 +
   1.539 +  /**
   1.540 +   * Method to see if the text node contains data that is useful
   1.541 +   * for a translation: i.e., it consists of more than just whitespace,
   1.542 +   * digits and punctuation.
   1.543 +   * NOTE: Always returns false for elements.
   1.544 +   */
   1.545 +  virtual bool HasTextForTranslation() = 0;
   1.546 +
   1.547 +  /**
   1.548 +   * Append the text content to aResult.
   1.549 +   * NOTE: This asserts and returns for elements
   1.550 +   */
   1.551 +  virtual void AppendTextTo(nsAString& aResult) = 0;
   1.552 +
   1.553 +  /**
   1.554 +   * Append the text content to aResult.
   1.555 +   * NOTE: This asserts and returns for elements
   1.556 +   */
   1.557 +  virtual bool AppendTextTo(nsAString& aResult,
   1.558 +                            const mozilla::fallible_t&) NS_WARN_UNUSED_RESULT = 0;
   1.559 +
   1.560 +  /**
   1.561 +   * Check if this content is focusable and in the current tab order.
   1.562 +   * Note: most callers should use nsIFrame::IsFocusable() instead as it 
   1.563 +   *       checks visibility and other layout factors as well.
   1.564 +   * Tabbable is indicated by a nonnegative tabindex & is a subset of focusable.
   1.565 +   * For example, only the selected radio button in a group is in the 
   1.566 +   * tab order, unless the radio group has no selection in which case
   1.567 +   * all of the visible, non-disabled radio buttons in the group are 
   1.568 +   * in the tab order. On the other hand, all of the visible, non-disabled 
   1.569 +   * radio buttons are always focusable via clicking or script.
   1.570 +   * Also, depending on either the accessibility.tabfocus pref or
   1.571 +   * a system setting (nowadays: Full keyboard access, mac only)
   1.572 +   * some widgets may be focusable but removed from the tab order.
   1.573 +   * @param  [inout, optional] aTabIndex the computed tab index
   1.574 +   *         In: default tabindex for element (-1 nonfocusable, == 0 focusable)
   1.575 +   *         Out: computed tabindex
   1.576 +   * @param  [optional] aTabIndex the computed tab index
   1.577 +   *         < 0 if not tabbable
   1.578 +   *         == 0 if in normal tab order
   1.579 +   *         > 0 can be tabbed to in the order specified by this value
   1.580 +   * @return whether the content is focusable via mouse, kbd or script.
   1.581 +   */
   1.582 +  bool IsFocusable(int32_t* aTabIndex = nullptr, bool aWithMouse = false);
   1.583 +  virtual bool IsFocusableInternal(int32_t* aTabIndex, bool aWithMouse);
   1.584 +
   1.585 +  /**
   1.586 +   * The method focuses (or activates) element that accesskey is bound to. It is
   1.587 +   * called when accesskey is activated.
   1.588 +   *
   1.589 +   * @param aKeyCausesActivation - if true then element should be activated
   1.590 +   * @param aIsTrustedEvent - if true then event that is cause of accesskey
   1.591 +   *                          execution is trusted.
   1.592 +   */
   1.593 +  virtual void PerformAccesskey(bool aKeyCausesActivation,
   1.594 +                                bool aIsTrustedEvent)
   1.595 +  {
   1.596 +  }
   1.597 +
   1.598 +  /*
   1.599 +   * Get desired IME state for the content.
   1.600 +   *
   1.601 +   * @return The desired IME status for the content.
   1.602 +   *         This is a combination of an IME enabled value and
   1.603 +   *         an IME open value of widget::IMEState.
   1.604 +   *         If you return DISABLED, you should not set the OPEN and CLOSE
   1.605 +   *         value.
   1.606 +   *         PASSWORD should be returned only from password editor, this value
   1.607 +   *         has a special meaning. It is used as alternative of DISABLED.
   1.608 +   *         PLUGIN should be returned only when plug-in has focus.  When a
   1.609 +   *         plug-in is focused content, we should send native events directly.
   1.610 +   *         Because we don't process some native events, but they may be needed
   1.611 +   *         by the plug-in.
   1.612 +   */
   1.613 +  virtual IMEState GetDesiredIMEState();
   1.614 +
   1.615 +  /**
   1.616 +   * Gets content node with the binding (or native code, possibly on the
   1.617 +   * frame) responsible for our construction (and existence).  Used by
   1.618 +   * anonymous content (both XBL-generated and native-anonymous).
   1.619 +   *
   1.620 +   * null for all explicit content (i.e., content reachable from the top
   1.621 +   * of its GetParent() chain via child lists).
   1.622 +   *
   1.623 +   * @return the binding parent
   1.624 +   */
   1.625 +  virtual nsIContent *GetBindingParent() const = 0;
   1.626 +
   1.627 +  /**
   1.628 +   * Gets the current XBL binding that is bound to this element.
   1.629 +   *
   1.630 +   * @return the current binding.
   1.631 +   */
   1.632 +  virtual nsXBLBinding *GetXBLBinding() const = 0;
   1.633 +
   1.634 +  /**
   1.635 +   * Sets or unsets an XBL binding for this element. Setting a
   1.636 +   * binding on an element that already has a binding will remove the
   1.637 +   * old binding.
   1.638 +   *
   1.639 +   * @param aBinding The binding to bind to this content. If nullptr is
   1.640 +   *        provided as the argument, then existing binding will be
   1.641 +   *        removed.
   1.642 +   *
   1.643 +   * @param aOldBindingManager The old binding manager that contains
   1.644 +   *                           this content if this content was adopted
   1.645 +   *                           to another document.
   1.646 +   */
   1.647 +  virtual void SetXBLBinding(nsXBLBinding* aBinding,
   1.648 +                             nsBindingManager* aOldBindingManager = nullptr) = 0;
   1.649 +
   1.650 +  /**
   1.651 +   * Sets the ShadowRoot binding for this element. The contents of the
   1.652 +   * binding is rendered in place of this node's children.
   1.653 +   *
   1.654 +   * @param aShadowRoot The ShadowRoot to be bound to this element.
   1.655 +   */
   1.656 +  virtual void SetShadowRoot(mozilla::dom::ShadowRoot* aShadowRoot) = 0;
   1.657 +
   1.658 +  /**
   1.659 +   * Gets the ShadowRoot binding for this element.
   1.660 +   *
   1.661 +   * @return The ShadowRoot currently bound to this element.
   1.662 +   */
   1.663 +  virtual mozilla::dom::ShadowRoot *GetShadowRoot() const = 0;
   1.664 +
   1.665 +  /**
   1.666 +   * Gets the root of the node tree for this content if it is in a shadow tree.
   1.667 +   * This method is called |GetContainingShadow| instead of |GetRootShadowRoot|
   1.668 +   * to avoid confusion with |GetShadowRoot|.
   1.669 +   *
   1.670 +   * @return The ShadowRoot that is the root of the node tree.
   1.671 +   */
   1.672 +  virtual mozilla::dom::ShadowRoot *GetContainingShadow() const = 0;
   1.673 +
   1.674 +  /**
   1.675 +   * Gets the insertion parent element of the XBL binding.
   1.676 +   * The insertion parent is our one true parent in the transformed DOM.
   1.677 +   *
   1.678 +   * @return the insertion parent element.
   1.679 +   */
   1.680 +  virtual nsIContent *GetXBLInsertionParent() const = 0;
   1.681 +
   1.682 +  /**
   1.683 +   * Sets the insertion parent element of the XBL binding.
   1.684 +   *
   1.685 +   * @param aContent The insertion parent element.
   1.686 +   */
   1.687 +  virtual void SetXBLInsertionParent(nsIContent* aContent) = 0;
   1.688 +
   1.689 +  /**
   1.690 +   * Returns the content node that is the parent of this node in the flattened
   1.691 +   * tree. For nodes that are not filtered into an insertion point, this
   1.692 +   * simply returns their DOM parent in the original DOM tree.
   1.693 +   *
   1.694 +   * @return the flattened tree parent
   1.695 +   */
   1.696 +  nsIContent *GetFlattenedTreeParent() const;
   1.697 +
   1.698 +  /**
   1.699 +   * Gets the custom element data used by web components custom element.
   1.700 +   * Custom element data is created at the first attempt to enqueue a callback.
   1.701 +   *
   1.702 +   * @return The custom element data or null if none.
   1.703 +   */
   1.704 +  virtual mozilla::dom::CustomElementData *GetCustomElementData() const = 0;
   1.705 +
   1.706 +  /**
   1.707 +   * Sets the custom element data, ownership of the
   1.708 +   * callback data is taken by this content.
   1.709 +   *
   1.710 +   * @param aCallbackData The custom element data.
   1.711 +   */
   1.712 +  virtual void SetCustomElementData(mozilla::dom::CustomElementData* aData) = 0;
   1.713 +
   1.714 +  /**
   1.715 +   * API to check if this is a link that's traversed in response to user input
   1.716 +   * (e.g. a click event). Specializations for HTML/SVG/generic XML allow for
   1.717 +   * different types of link in different types of content.
   1.718 +   *
   1.719 +   * @param aURI Required out param. If this content is a link, a new nsIURI
   1.720 +   *             set to this link's URI will be passed out.
   1.721 +   *
   1.722 +   * @note The out param, aURI, is guaranteed to be set to a non-null pointer
   1.723 +   *   when the return value is true.
   1.724 +   *
   1.725 +   * XXXjwatt: IMO IsInteractiveLink would be a better name.
   1.726 +   */
   1.727 +  virtual bool IsLink(nsIURI** aURI) const = 0;
   1.728 +
   1.729 +  /**
   1.730 +    * Get a pointer to the full href URI (fully resolved and canonicalized,
   1.731 +    * since it's an nsIURI object) for link elements.
   1.732 +    *
   1.733 +    * @return A pointer to the URI or null if the element is not a link or it
   1.734 +    *         has no HREF attribute.
   1.735 +    */
   1.736 +  virtual already_AddRefed<nsIURI> GetHrefURI() const
   1.737 +  {
   1.738 +    return nullptr;
   1.739 +  }
   1.740 +
   1.741 +  /**
   1.742 +   * This method is called when the parser finishes creating the element.  This
   1.743 +   * particularly means that it has done everything you would expect it to have
   1.744 +   * done after it encounters the > at the end of the tag (for HTML or XML).
   1.745 +   * This includes setting the attributes, setting the document / form, and
   1.746 +   * placing the element into the tree at its proper place.
   1.747 +   *
   1.748 +   * For container elements, this is called *before* any of the children are
   1.749 +   * created or added into the tree.
   1.750 +   *
   1.751 +   * NOTE: this is currently only called for input and button, in the HTML
   1.752 +   * content sink.  If you want to call it on your element, modify the content
   1.753 +   * sink of your choice to do so.  This is an efficiency measure.
   1.754 +   *
   1.755 +   * If you also need to determine whether the parser is the one creating your
   1.756 +   * element (through createElement() or cloneNode() generally) then add a
   1.757 +   * uint32_t aFromParser to the NS_NewXXX() constructor for your element and
   1.758 +   * have the parser pass the appropriate flags. See HTMLInputElement.cpp and
   1.759 +   * nsHTMLContentSink::MakeContentObject().
   1.760 +   *
   1.761 +   * DO NOT USE THIS METHOD to get around the fact that it's hard to deal with
   1.762 +   * attributes dynamically.  If you make attributes affect your element from
   1.763 +   * this method, it will only happen on initialization and JavaScript will not
   1.764 +   * be able to create elements (which requires them to first create the
   1.765 +   * element and then call setAttribute() directly, at which point
   1.766 +   * DoneCreatingElement() has already been called and is out of the picture).
   1.767 +   */
   1.768 +  virtual void DoneCreatingElement()
   1.769 +  {
   1.770 +  }
   1.771 +
   1.772 +  /**
   1.773 +   * This method is called when the parser begins creating the element's 
   1.774 +   * children, if any are present.
   1.775 +   *
   1.776 +   * This is only called for XTF elements currently.
   1.777 +   */
   1.778 +  virtual void BeginAddingChildren()
   1.779 +  {
   1.780 +  }
   1.781 +
   1.782 +  /**
   1.783 +   * This method is called when the parser finishes creating the element's children,
   1.784 +   * if any are present.
   1.785 +   *
   1.786 +   * NOTE: this is currently only called for textarea, select, applet, and
   1.787 +   * object elements in the HTML content sink.  If you want
   1.788 +   * to call it on your element, modify the content sink of your
   1.789 +   * choice to do so.  This is an efficiency measure.
   1.790 +   *
   1.791 +   * If you also need to determine whether the parser is the one creating your
   1.792 +   * element (through createElement() or cloneNode() generally) then add a
   1.793 +   * boolean aFromParser to the NS_NewXXX() constructor for your element and
   1.794 +   * have the parser pass true.  See HTMLInputElement.cpp and
   1.795 +   * nsHTMLContentSink::MakeContentObject().
   1.796 +   *
   1.797 +   * @param aHaveNotified Whether there has been a
   1.798 +   *        ContentInserted/ContentAppended notification for this content node
   1.799 +   *        yet.
   1.800 +   */
   1.801 +  virtual void DoneAddingChildren(bool aHaveNotified)
   1.802 +  {
   1.803 +  }
   1.804 +
   1.805 +  /**
   1.806 +   * For HTML textarea, select, applet, and object elements, returns
   1.807 +   * true if all children have been added OR if the element was not
   1.808 +   * created by the parser. Returns true for all other elements.
   1.809 +   * @returns false if the element was created by the parser and
   1.810 +   *                   it is an HTML textarea, select, applet, or object
   1.811 +   *                   element and not all children have been added.
   1.812 +   * @returns true otherwise.
   1.813 +   */
   1.814 +  virtual bool IsDoneAddingChildren()
   1.815 +  {
   1.816 +    return true;
   1.817 +  }
   1.818 +
   1.819 +  /**
   1.820 +   * Get the ID of this content node (the atom corresponding to the
   1.821 +   * value of the null-namespace attribute whose name is given by
   1.822 +   * GetIDAttributeName().  This may be null if there is no ID.
   1.823 +   */
   1.824 +  nsIAtom* GetID() const {
   1.825 +    if (HasID()) {
   1.826 +      return DoGetID();
   1.827 +    }
   1.828 +    return nullptr;
   1.829 +  }
   1.830 +
   1.831 +  /**
   1.832 +   * Get the class list of this content node (this corresponds to the
   1.833 +   * value of the null-namespace attribute whose name is given by
   1.834 +   * GetClassAttributeName()).  This may be null if there are no
   1.835 +   * classes, but that's not guaranteed.
   1.836 +   */
   1.837 +  const nsAttrValue* GetClasses() const {
   1.838 +    if (HasFlag(NODE_MAY_HAVE_CLASS)) {
   1.839 +      return DoGetClasses();
   1.840 +    }
   1.841 +    return nullptr;
   1.842 +  }
   1.843 +
   1.844 +  /**
   1.845 +   * Walk aRuleWalker over the content style rules (presentational
   1.846 +   * hint rules) for this content node.
   1.847 +   */
   1.848 +  NS_IMETHOD WalkContentStyleRules(nsRuleWalker* aRuleWalker) = 0;
   1.849 +
   1.850 +  /**
   1.851 +   * Should be called when the node can become editable or when it can stop
   1.852 +   * being editable (for example when its contentEditable attribute changes,
   1.853 +   * when it is moved into an editable parent, ...).  If aNotify is true and
   1.854 +   * the node is an element, this will notify the state change.
   1.855 +   */
   1.856 +  virtual void UpdateEditableState(bool aNotify);
   1.857 +
   1.858 +  /**
   1.859 +   * Destroy this node and its children. Ideally this shouldn't be needed
   1.860 +   * but for now we need to do it to break cycles.
   1.861 +   */
   1.862 +  virtual void DestroyContent() = 0;
   1.863 +
   1.864 +  /**
   1.865 +   * Saves the form state of this node and its children.
   1.866 +   */
   1.867 +  virtual void SaveSubtreeState() = 0;
   1.868 +
   1.869 +  /**
   1.870 +   * Getter and setter for our primary frame pointer.  This is the frame that
   1.871 +   * is most closely associated with the content. A frame is more closely
   1.872 +   * associated with the content than another frame if the one frame contains
   1.873 +   * directly or indirectly the other frame (e.g., when a frame is scrolled
   1.874 +   * there is a scroll frame that contains the frame being scrolled). This
   1.875 +   * frame is always the first continuation.
   1.876 +   *
   1.877 +   * In the case of absolutely positioned elements and floated elements, this
   1.878 +   * frame is the out of flow frame, not the placeholder.
   1.879 +   */
   1.880 +  nsIFrame* GetPrimaryFrame() const
   1.881 +  {
   1.882 +    return IsInDoc() ? mPrimaryFrame : nullptr;
   1.883 +  }
   1.884 +  void SetPrimaryFrame(nsIFrame* aFrame) {
   1.885 +    NS_ASSERTION(IsInDoc(), "This will end badly!");
   1.886 +    NS_PRECONDITION(!aFrame || !mPrimaryFrame || aFrame == mPrimaryFrame,
   1.887 +                    "Losing track of existing primary frame");
   1.888 +    mPrimaryFrame = aFrame;
   1.889 +  }
   1.890 +
   1.891 +  nsresult LookupNamespaceURIInternal(const nsAString& aNamespacePrefix,
   1.892 +                                      nsAString& aNamespaceURI) const;
   1.893 +
   1.894 +  /**
   1.895 +   * If this content has independent selection, e.g., if this is input field
   1.896 +   * or textarea, this return TRUE.  Otherwise, false.
   1.897 +   */
   1.898 +  bool HasIndependentSelection();
   1.899 +
   1.900 +  /**
   1.901 +   * If the content is a part of HTML editor, this returns editing
   1.902 +   * host content.  When the content is in designMode, this returns its body
   1.903 +   * element.  Also, when the content isn't editable, this returns null.
   1.904 +   */
   1.905 +  mozilla::dom::Element* GetEditingHost();
   1.906 +
   1.907 +  /**
   1.908 +   * Determing language. Look at the nearest ancestor element that has a lang
   1.909 +   * attribute in the XML namespace or is an HTML/SVG element and has a lang in
   1.910 +   * no namespace attribute.
   1.911 +   */
   1.912 +  void GetLang(nsAString& aResult) const {
   1.913 +    for (const nsIContent* content = this; content; content = content->GetParent()) {
   1.914 +      if (content->GetAttrCount() > 0) {
   1.915 +        // xml:lang has precedence over lang on HTML elements (see
   1.916 +        // XHTML1 section C.7).
   1.917 +        bool hasAttr = content->GetAttr(kNameSpaceID_XML, nsGkAtoms::lang,
   1.918 +                                          aResult);
   1.919 +        if (!hasAttr && (content->IsHTML() || content->IsSVG())) {
   1.920 +          hasAttr = content->GetAttr(kNameSpaceID_None, nsGkAtoms::lang,
   1.921 +                                     aResult);
   1.922 +        }
   1.923 +        NS_ASSERTION(hasAttr || aResult.IsEmpty(),
   1.924 +                     "GetAttr that returns false should not make string non-empty");
   1.925 +        if (hasAttr) {
   1.926 +          return;
   1.927 +        }
   1.928 +      }
   1.929 +    }
   1.930 +  }
   1.931 +
   1.932 +  // Overloaded from nsINode
   1.933 +  virtual already_AddRefed<nsIURI> GetBaseURI(bool aTryUseXHRDocBaseURI = false) const MOZ_OVERRIDE;
   1.934 +
   1.935 +  virtual nsresult PreHandleEvent(
   1.936 +                     mozilla::EventChainPreVisitor& aVisitor) MOZ_OVERRIDE;
   1.937 +
   1.938 +  virtual bool IsPurple() = 0;
   1.939 +  virtual void RemovePurple() = 0;
   1.940 +
   1.941 +  virtual bool OwnedOnlyByTheDOMTree() { return false; }
   1.942 +protected:
   1.943 +  /**
   1.944 +   * Hook for implementing GetID.  This is guaranteed to only be
   1.945 +   * called if HasID() is true.
   1.946 +   */
   1.947 +  virtual nsIAtom* DoGetID() const = 0;
   1.948 +
   1.949 +private:
   1.950 +  /**
   1.951 +   * Hook for implementing GetClasses.  This is guaranteed to only be
   1.952 +   * called if the NODE_MAY_HAVE_CLASS flag is set.
   1.953 +   */
   1.954 +  virtual const nsAttrValue* DoGetClasses() const = 0;
   1.955 +
   1.956 +public:
   1.957 +#ifdef DEBUG
   1.958 +  /**
   1.959 +   * List the content (and anything it contains) out to the given
   1.960 +   * file stream. Use aIndent as the base indent during formatting.
   1.961 +   */
   1.962 +  virtual void List(FILE* out = stdout, int32_t aIndent = 0) const = 0;
   1.963 +
   1.964 +  /**
   1.965 +   * Dump the content (and anything it contains) out to the given
   1.966 +   * file stream. Use aIndent as the base indent during formatting.
   1.967 +   */
   1.968 +  virtual void DumpContent(FILE* out = stdout, int32_t aIndent = 0,
   1.969 +                           bool aDumpAll = true) const = 0;
   1.970 +#endif
   1.971 +
   1.972 +  /**
   1.973 +   * Append to aOutDescription a short (preferably one line) string
   1.974 +   * describing the content.
   1.975 +   * Currently implemented for elements only.
   1.976 +   */
   1.977 +  virtual void Describe(nsAString& aOutDescription) const {
   1.978 +    aOutDescription = NS_LITERAL_STRING("(not an element)");
   1.979 +  }
   1.980 +
   1.981 +  enum ETabFocusType {
   1.982 +  //eTabFocus_textControlsMask = (1<<0),  // unused - textboxes always tabbable
   1.983 +    eTabFocus_formElementsMask = (1<<1),  // non-text form elements
   1.984 +    eTabFocus_linksMask = (1<<2),         // links
   1.985 +    eTabFocus_any = 1 + (1<<1) + (1<<2)   // everything that can be focused
   1.986 +  };
   1.987 +
   1.988 +  // Tab focus model bit field:
   1.989 +  static int32_t sTabFocusModel;
   1.990 +
   1.991 +  // accessibility.tabfocus_applies_to_xul pref - if it is set to true,
   1.992 +  // the tabfocus bit field applies to xul elements.
   1.993 +  static bool sTabFocusModelAppliesToXUL;
   1.994 +};
   1.995 +
   1.996 +NS_DEFINE_STATIC_IID_ACCESSOR(nsIContent, NS_ICONTENT_IID)
   1.997 +
   1.998 +inline nsIContent* nsINode::AsContent()
   1.999 +{
  1.1000 +  MOZ_ASSERT(IsContent());
  1.1001 +  return static_cast<nsIContent*>(this);
  1.1002 +}
  1.1003 +
  1.1004 +#define NS_IMPL_FROMCONTENT_HELPER(_class, _check)                             \
  1.1005 +  static _class* FromContent(nsIContent* aContent)                             \
  1.1006 +  {                                                                            \
  1.1007 +    return aContent->_check ? static_cast<_class*>(aContent) : nullptr;        \
  1.1008 +  }                                                                            \
  1.1009 +  static _class* FromContentOrNull(nsIContent* aContent)                       \
  1.1010 +  {                                                                            \
  1.1011 +    return aContent ? FromContent(aContent) : nullptr;                         \
  1.1012 +  }
  1.1013 +
  1.1014 +#define NS_IMPL_FROMCONTENT(_class, _nsid)                                     \
  1.1015 +  NS_IMPL_FROMCONTENT_HELPER(_class, IsInNamespace(_nsid))
  1.1016 +
  1.1017 +#define NS_IMPL_FROMCONTENT_WITH_TAG(_class, _nsid, _tag)                      \
  1.1018 +  NS_IMPL_FROMCONTENT_HELPER(_class, NodeInfo()->Equals(nsGkAtoms::_tag, _nsid))
  1.1019 +
  1.1020 +#define NS_IMPL_FROMCONTENT_HTML_WITH_TAG(_class, _tag)                        \
  1.1021 +  NS_IMPL_FROMCONTENT_WITH_TAG(_class, kNameSpaceID_XHTML, _tag)
  1.1022 +
  1.1023 +#endif /* nsIContent_h___ */

mercurial