From 9e5e58c0f6e1c65674cc688816f387532661d6f1 Mon Sep 17 00:00:00 2001 From: "Matt A. Tobin" Date: Fri, 17 Apr 2020 07:42:07 -0400 Subject: Bug 1425769 - Base class for ShadowRoot and Document to manage style state Tag #1375 --- dom/base/ShadowRoot.h | 44 +++++++++++++------------------------------- 1 file changed, 13 insertions(+), 31 deletions(-) (limited to 'dom/base/ShadowRoot.h') diff --git a/dom/base/ShadowRoot.h b/dom/base/ShadowRoot.h index c525ba8e8..a24c8138e 100644 --- a/dom/base/ShadowRoot.h +++ b/dom/base/ShadowRoot.h @@ -8,8 +8,7 @@ #define mozilla_dom_shadowroot_h__ #include "mozilla/dom/DocumentFragment.h" -#include "mozilla/dom/StyleSheetList.h" -#include "mozilla/StyleSheet.h" +#include "mozilla/dom/StyleScope.h" #include "nsCOMPtr.h" #include "nsCycleCollectionParticipant.h" #include "nsIContentInlines.h" @@ -27,12 +26,11 @@ class EventChainPreVisitor; namespace dom { class Element; -class ShadowRootStyleSheetList; class ShadowRoot final : public DocumentFragment, + public StyleScope, public nsStubMutationObserver { - friend class ShadowRootStyleSheetList; public: NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(ShadowRoot, DocumentFragment) @@ -49,15 +47,20 @@ public: // Shadow DOM v1 Element* Host(); - ShadowRootMode Mode() + ShadowRootMode Mode() const { return mMode; } - bool IsClosed() + bool IsClosed() const { return mMode == ShadowRootMode::Closed; } + // StyleScope. + nsINode& AsNode() final + { + return *this; + } // [deprecated] Shadow DOM v0 void AddToIdTable(Element* aElement, nsIAtom* aId); @@ -66,7 +69,10 @@ public: void RemoveSheet(StyleSheet* aSheet); bool ApplyAuthorStyles(); void SetApplyAuthorStyles(bool aApplyAuthorStyles); - StyleSheetList* StyleSheets(); + StyleSheetList* StyleSheets() + { + return &StyleScope::EnsureDOMStyleSheets(); + } /** * Distributes all the explicit children of the pool host to the content @@ -155,8 +161,6 @@ protected: // owns |mProtoBinding|. RefPtr mAssociatedBinding; - RefPtr mStyleSheetList; - // A boolean that indicates that an insertion point was added or removed // from this ShadowRoot and that the nodes need to be redistributed into // the insertion points. After this flag is set, nodes will be distributed @@ -172,28 +176,6 @@ protected: nsresult Clone(mozilla::dom::NodeInfo *aNodeInfo, nsINode **aResult) const override; }; -class ShadowRootStyleSheetList : public StyleSheetList -{ -public: - explicit ShadowRootStyleSheetList(ShadowRoot* aShadowRoot); - - NS_DECL_ISUPPORTS_INHERITED - NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(ShadowRootStyleSheetList, StyleSheetList) - - virtual nsINode* GetParentObject() const override - { - return mShadowRoot; - } - - uint32_t Length() override; - StyleSheet* IndexedGetter(uint32_t aIndex, bool& aFound) override; - -protected: - virtual ~ShadowRootStyleSheetList(); - - RefPtr mShadowRoot; -}; - } // namespace dom } // namespace mozilla -- cgit v1.2.3