content/base/src/ShadowRoot.h

Thu, 15 Jan 2015 21:03:48 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Thu, 15 Jan 2015 21:03:48 +0100
branch
TOR_BUG_9701
changeset 11
deefc01c0e14
permissions
-rw-r--r--

Integrate friendly tips from Tor colleagues to make (or not) 4.5 alpha 3;
This includes removal of overloaded (but unused) methods, and addition of
a overlooked call to DataStruct::SetData(nsISupports, uint32_t, bool.)

     1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
     2 /* This Source Code Form is subject to the terms of the Mozilla Public
     3  * License, v. 2.0. If a copy of the MPL was not distributed with this
     4  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
     6 #ifndef mozilla_dom_shadowroot_h__
     7 #define mozilla_dom_shadowroot_h__
     9 #include "mozilla/dom/DocumentFragment.h"
    10 #include "mozilla/dom/StyleSheetList.h"
    11 #include "nsCOMPtr.h"
    12 #include "nsCycleCollectionParticipant.h"
    13 #include "nsTHashtable.h"
    14 #include "nsDocument.h"
    16 class nsIAtom;
    17 class nsIContent;
    18 class nsIDocument;
    19 class nsINodeInfo;
    20 class nsPIDOMWindow;
    21 class nsXBLPrototypeBinding;
    22 class nsTagNameMapEntry;
    24 namespace mozilla {
    25 namespace dom {
    27 class Element;
    28 class HTMLContentElement;
    29 class HTMLShadowElement;
    30 class ShadowRootStyleSheetList;
    32 class ShadowRoot : public DocumentFragment,
    33                    public nsStubMutationObserver
    34 {
    35   friend class ShadowRootStyleSheetList;
    36 public:
    37   NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(ShadowRoot,
    38                                            DocumentFragment)
    39   NS_DECL_ISUPPORTS_INHERITED
    41   NS_DECL_NSIMUTATIONOBSERVER_ATTRIBUTECHANGED
    42   NS_DECL_NSIMUTATIONOBSERVER_CONTENTAPPENDED
    43   NS_DECL_NSIMUTATIONOBSERVER_CONTENTINSERTED
    44   NS_DECL_NSIMUTATIONOBSERVER_CONTENTREMOVED
    46   ShadowRoot(nsIContent* aContent, already_AddRefed<nsINodeInfo>&& aNodeInfo,
    47              nsXBLPrototypeBinding* aProtoBinding);
    48   virtual ~ShadowRoot();
    50   void AddToIdTable(Element* aElement, nsIAtom* aId);
    51   void RemoveFromIdTable(Element* aElement, nsIAtom* aId);
    52   void InsertSheet(nsCSSStyleSheet* aSheet, nsIContent* aLinkingContent);
    53   void RemoveSheet(nsCSSStyleSheet* aSheet);
    54   bool ApplyAuthorStyles();
    55   void SetApplyAuthorStyles(bool aApplyAuthorStyles);
    56   StyleSheetList* StyleSheets();
    57   HTMLShadowElement* GetShadowElement() { return mShadowElement; }
    59   /**
    60    * Sets the current shadow insertion point where the older
    61    * ShadowRoot will be projected.
    62    */
    63   void SetShadowElement(HTMLShadowElement* aShadowElement);
    65   /**
    66    * Change the node that populates the distribution pool with
    67    * its children. This is distinct from the ShadowRoot host described
    68    * in the specifications. The ShadowRoot host is the element
    69    * which created this ShadowRoot and does not change. The pool host
    70    * is the same as the ShadowRoot host if this is the youngest
    71    * ShadowRoot. If this is an older ShadowRoot, the pool host is
    72    * the <shadow> element in the younger ShadowRoot (if it exists).
    73    */
    74   void ChangePoolHost(nsIContent* aNewHost);
    76   /**
    77    * Distributes a single explicit child of the pool host to the content
    78    * insertion points in this ShadowRoot.
    79    */
    80   void DistributeSingleNode(nsIContent* aContent);
    82   /**
    83    * Removes a single explicit child of the pool host from the content
    84    * insertion points in this ShadowRoot.
    85    */
    86   void RemoveDistributedNode(nsIContent* aContent);
    88   /**
    89    * Distributes all the explicit children of the pool host to the content
    90    * insertion points in this ShadowRoot.
    91    */
    92   void DistributeAllNodes();
    94   void AddInsertionPoint(HTMLContentElement* aInsertionPoint);
    95   void RemoveInsertionPoint(HTMLContentElement* aInsertionPoint);
    97   void SetYoungerShadow(ShadowRoot* aYoungerShadow);
    98   ShadowRoot* GetOlderShadow() { return mOlderShadow; }
    99   ShadowRoot* GetYoungerShadow() { return mYoungerShadow; }
   100   void SetInsertionPointChanged() { mInsertionPointChanged = true; }
   102   void SetAssociatedBinding(nsXBLBinding* aBinding) { mAssociatedBinding = aBinding; }
   104   nsISupports* GetParentObject() const { return mPoolHost; }
   106   nsIContent* GetPoolHost() { return mPoolHost; }
   107   nsTArray<HTMLShadowElement*>& ShadowDescendants() { return mShadowDescendants; }
   109   JSObject* WrapObject(JSContext* aCx) MOZ_OVERRIDE;
   111   static bool IsPooledNode(nsIContent* aChild, nsIContent* aContainer,
   112                            nsIContent* aHost);
   113   static ShadowRoot* FromNode(nsINode* aNode);
   114   static bool IsShadowInsertionPoint(nsIContent* aContent);
   116   // WebIDL methods.
   117   Element* GetElementById(const nsAString& aElementId);
   118   already_AddRefed<nsContentList>
   119     GetElementsByTagName(const nsAString& aNamespaceURI);
   120   already_AddRefed<nsContentList>
   121     GetElementsByTagNameNS(const nsAString& aNamespaceURI,
   122                            const nsAString& aLocalName);
   123   already_AddRefed<nsContentList>
   124     GetElementsByClassName(const nsAString& aClasses);
   125   void GetInnerHTML(nsAString& aInnerHTML);
   126   void SetInnerHTML(const nsAString& aInnerHTML, ErrorResult& aError);
   127 protected:
   128   void Restyle();
   130   // The pool host is the parent of the nodes that will be distributed
   131   // into the insertion points in this ShadowRoot. See |ChangeShadowRoot|.
   132   nsCOMPtr<nsIContent> mPoolHost;
   134   // An array of content insertion points that are a descendant of the ShadowRoot
   135   // sorted in tree order. Insertion points are responsible for notifying
   136   // the ShadowRoot when they are removed or added as a descendant. The insertion
   137   // points are kept alive by the parent node, thus weak references are held
   138   // by the array.
   139   nsTArray<HTMLContentElement*> mInsertionPoints;
   141   // An array of the <shadow> elements that are descendant of the ShadowRoot
   142   // sorted in tree order. Only the first may be a shadow insertion point.
   143   nsTArray<HTMLShadowElement*> mShadowDescendants;
   145   nsTHashtable<nsIdentifierMapEntry> mIdentifierMap;
   146   nsXBLPrototypeBinding* mProtoBinding;
   148   // It is necessary to hold a reference to the associated nsXBLBinding
   149   // because the binding holds a reference on the nsXBLDocumentInfo that
   150   // owns |mProtoBinding|.
   151   nsRefPtr<nsXBLBinding> mAssociatedBinding;
   153   nsRefPtr<ShadowRootStyleSheetList> mStyleSheetList;
   155   // The current shadow insertion point of this ShadowRoot.
   156   HTMLShadowElement* mShadowElement;
   158   // The ShadowRoot that was created by the host element before
   159   // this ShadowRoot was created.
   160   nsRefPtr<ShadowRoot> mOlderShadow;
   162   // The ShadowRoot that was created by the host element after
   163   // this ShadowRoot was created.
   164   nsRefPtr<ShadowRoot> mYoungerShadow;
   166   // A boolean that indicates that an insertion point was added or removed
   167   // from this ShadowRoot and that the nodes need to be redistributed into
   168   // the insertion points. After this flag is set, nodes will be distributed
   169   // on the next mutation event.
   170   bool mInsertionPointChanged;
   171 };
   173 class ShadowRootStyleSheetList : public StyleSheetList
   174 {
   175 public:
   176   ShadowRootStyleSheetList(ShadowRoot* aShadowRoot);
   177   virtual ~ShadowRootStyleSheetList();
   179   NS_DECL_ISUPPORTS_INHERITED
   180   NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(ShadowRootStyleSheetList, StyleSheetList)
   182   virtual nsINode* GetParentObject() const MOZ_OVERRIDE
   183   {
   184     return mShadowRoot;
   185   }
   187   virtual uint32_t Length() MOZ_OVERRIDE;
   188   virtual nsCSSStyleSheet* IndexedGetter(uint32_t aIndex, bool& aFound) MOZ_OVERRIDE;
   190 protected:
   191   nsRefPtr<ShadowRoot> mShadowRoot;
   192 };
   194 } // namespace dom
   195 } // namespace mozilla
   197 #endif // mozilla_dom_shadowroot_h__

mercurial