diff --git a/dom/base/Document.h b/dom/base/Document.h index 78a12cf46f76..ba73133087ff 100644 --- a/dom/base/Document.h +++ b/dom/base/Document.h @@ -2889,6 +2889,10 @@ class Document : public nsINode, */ Document* GetTemplateContentsOwner(); + Document* GetTemplateContentsOwnerIfExists() const { + return mTemplateContentsOwner.get(); + } + /** * Returns true if this document is a static clone of a normal document. * diff --git a/dom/base/DocumentOrShadowRoot.cpp b/dom/base/DocumentOrShadowRoot.cpp index 647c0614e328..744d053cab8b 100644 --- a/dom/base/DocumentOrShadowRoot.cpp +++ b/dom/base/DocumentOrShadowRoot.cpp @@ -620,11 +620,6 @@ int32_t DocumentOrShadowRoot::StyleOrderIndexOfSheet( return mStyleSheets.IndexOf(&aSheet); } -void DocumentOrShadowRoot::GetAdoptedStyleSheets( - nsTArray>& aAdoptedStyleSheets) const { - aAdoptedStyleSheets = mAdoptedStyleSheets.Clone(); -} - void DocumentOrShadowRoot::TraverseSheetRefInStylesIfApplicable( StyleSheet& aSheet, nsCycleCollectionTraversalCallback& cb) { if (!aSheet.IsApplicable()) { diff --git a/dom/base/DocumentOrShadowRoot.h b/dom/base/DocumentOrShadowRoot.h index ad8f4ca8abe2..08422d317f9e 100644 --- a/dom/base/DocumentOrShadowRoot.h +++ b/dom/base/DocumentOrShadowRoot.h @@ -89,8 +89,6 @@ class DocumentOrShadowRoot : public RadioGroupManager { StyleSheetList* StyleSheets(); - void GetAdoptedStyleSheets(nsTArray>&) const; - void RemoveStyleSheet(StyleSheet&); Element* GetElementById(const nsAString& aElementId); diff --git a/dom/base/ShadowRoot.cpp b/dom/base/ShadowRoot.cpp index dea45b90e761..67fc00dbacbe 100644 --- a/dom/base/ShadowRoot.cpp +++ b/dom/base/ShadowRoot.cpp @@ -101,6 +101,17 @@ JSObject* ShadowRoot::WrapNode(JSContext* aCx, return mozilla::dom::ShadowRoot_Binding::Wrap(aCx, this, aGivenProto); } +void ShadowRoot::NodeInfoChanged(Document* aOldDoc) { + DocumentFragment::NodeInfoChanged(aOldDoc); + Document* newDoc = OwnerDoc(); + const bool fromOrToTemplate = + aOldDoc->GetTemplateContentsOwnerIfExists() == newDoc || + newDoc->GetTemplateContentsOwnerIfExists() == aOldDoc; + if (!fromOrToTemplate) { + ClearAdoptedStyleSheets(); + } +} + void ShadowRoot::CloneInternalDataFrom(ShadowRoot* aOther) { if (aOther->IsUAWidget()) { SetIsUAWidget(); diff --git a/dom/base/ShadowRoot.h b/dom/base/ShadowRoot.h index 1fe0576c96a0..c96b1005d9f8 100644 --- a/dom/base/ShadowRoot.h +++ b/dom/base/ShadowRoot.h @@ -185,10 +185,7 @@ class ShadowRoot final : public DocumentFragment, JSObject* WrapNode(JSContext*, JS::Handle aGivenProto) final; - void NodeInfoChanged(Document* aOldDoc) override { - DocumentFragment::NodeInfoChanged(aOldDoc); - ClearAdoptedStyleSheets(); - } + void NodeInfoChanged(Document* aOldDoc) override; void AddToIdTable(Element* aElement, nsAtom* aId); void RemoveFromIdTable(Element* aElement, nsAtom* aId); diff --git a/testing/web-platform/meta/css/cssom/CSSStyleSheet-template-adoption.html.ini b/testing/web-platform/meta/css/cssom/CSSStyleSheet-template-adoption.html.ini deleted file mode 100644 index 61d8c152115e..000000000000 --- a/testing/web-platform/meta/css/cssom/CSSStyleSheet-template-adoption.html.ini +++ /dev/null @@ -1,4 +0,0 @@ -[CSSStyleSheet-template-adoption.html] - [adoptedStyleSheets won'te be cleared when adopting into/from