Bug 1441136: Add a fast way to enumerate ShadowRoots in a document. r=smaug

MozReview-Commit-ID: 7QffP56jsyk
This commit is contained in:
Emilio Cobos Álvarez
2018-03-29 18:49:10 +02:00
parent 12e993f341
commit c94e7011c1
5 changed files with 64 additions and 25 deletions

View File

@@ -168,26 +168,6 @@ ServoStyleSet::Init(nsPresContext* aPresContext)
SetStylistXBLStyleSheetsDirty();
}
template<typename Functor>
void
EnumerateShadowRootsInSubtree(const nsINode& aRoot, const Functor& aCb)
{
for (const nsINode* cur = &aRoot; cur; cur = cur->GetNextNode()) {
if (!cur->IsElement()) {
continue;
}
auto* shadowRoot = cur->AsElement()->GetShadowRoot();
if (!shadowRoot) {
continue;
}
aCb(*shadowRoot);
EnumerateShadowRootsInSubtree(*shadowRoot, aCb);
}
}
// FIXME(emilio): We may want a faster way to do this.
template<typename Functor>
void
EnumerateShadowRoots(const nsIDocument& aDoc, const Functor& aCb)
@@ -196,7 +176,13 @@ EnumerateShadowRoots(const nsIDocument& aDoc, const Functor& aCb)
return;
}
EnumerateShadowRootsInSubtree(aDoc, aCb);
const nsIDocument::ShadowRootSet& shadowRoots = aDoc.ComposedShadowRoots();
for (auto iter = shadowRoots.ConstIter(); !iter.Done(); iter.Next()) {
ShadowRoot* root = iter.Get()->GetKey();
MOZ_ASSERT(root);
MOZ_DIAGNOSTIC_ASSERT(root->IsComposedDocParticipant());
aCb(*root);
}
}
void