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.)

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

mercurial