Bug 1425759: Make ChildIterator handle Shadow DOM explicitly. r?smaug draft
authorEmilio Cobos Álvarez <emilio@crisal.io>
Sun, 25 Feb 2018 17:31:06 +0100
changeset 759772 e0b890813cf6658019733d87c74608ee4ffe9929
parent 759771 19d0d52099d26b91e824a4fe1c6748a112d23b96
child 759773 f87cc99183d50caafa78071901080ef573ae84be
push id100460
push userbmo:emilio@crisal.io
push dateMon, 26 Feb 2018 16:00:57 +0000
reviewerssmaug
bugs1425759, 1422653
milestone60.0a1
Bug 1425759: Make ChildIterator handle Shadow DOM explicitly. r?smaug I'll rename mIsXBLInvolved in a bit, since I plan to do more changes here in bug 1422653. MozReview-Commit-ID: JCeAgk2DoY4
dom/base/ChildIterator.cpp
--- a/dom/base/ChildIterator.cpp
+++ b/dom/base/ChildIterator.cpp
@@ -122,28 +122,40 @@ ExplicitChildIterator::GetNextChild()
 
 void
 FlattenedChildIterator::Init(bool aIgnoreXBL)
 {
   if (aIgnoreXBL) {
     return;
   }
 
+  // TODO(emilio): I think it probably makes sense to only allow constructing
+  // FlattenedChildIterators with Element.
+  if (mParent->IsElement()) {
+    if (ShadowRoot* shadow = mParent->AsElement()->GetShadowRoot()) {
+      mParent = shadow;
+      mXBLInvolved = true;
+      return;
+    }
+  }
+
   nsXBLBinding* binding =
     mParent->OwnerDoc()->BindingManager()->GetBindingWithContent(mParent);
 
   if (binding) {
     MOZ_ASSERT(binding->GetAnonymousContent());
     mParent = binding->GetAnonymousContent();
     mXBLInvolved = true;
   }
 
   // We set mXBLInvolved to true if either:
   // - The node we're iterating has a binding with content attached to it.
   // - The node is generated XBL content and has an <xbl:children> child.
+  //
+  // FIXME(emilio): This is very slow :(
   if (!mXBLInvolved && mParent->GetBindingParent()) {
     for (nsIContent* child = mParent->GetFirstChild();
          child;
          child = child->GetNextSibling()) {
       if (child->NodeInfo()->Equals(nsGkAtoms::children, kNameSpaceID_XBL)) {
         MOZ_ASSERT(child->GetBindingParent());
         mXBLInvolved = true;
         break;