Bug 1318542 - Label NODE_IS_NATIVE_ANONYMOUS on the elements from ::cue up to nsVideoFrame. r=heycam, bz
Since the ::cue div created by JS, it doesn't have the NODE_IS_NATIVE_ANONYMOUS flag.
We set the NODE_IS_NATIVE_ANONYMOUS when binding to domtree from the ::cue up to the RootOfAnonymousSubtree
so that GetClosestNonNativeAnonymousAncestor will return video element as style parent.
MozReview-Commit-ID: 3EiYOqnbY15
--- a/dom/base/Element.cpp
+++ b/dom/base/Element.cpp
@@ -1695,16 +1695,38 @@ Element::BindToTree(nsIDocument* aDocume
child = child->GetNextSibling()) {
rv = child->BindToTree(nullptr, shadowRoot,
shadowRoot->GetBindingParent(),
aCompileEventHandlers);
NS_ENSURE_SUCCESS(rv, rv);
}
}
+ // Pseudo-elements implemented by JS must have the NODE_IS_NATIVE_ANONYMOUS
+ // flag set on them. For C++-created pseudo-elements, this is done in
+ // nsCSSFrameConstructor::GetAnonymousContent, but any JS that creates
+ // pseudo-elements would run after that. So we set that flag here,
+ // when the element implementing the pseudo is inserted into the document.
+ // We maintain the invariant that any NAC-implemented pseudo-element's
+ // anonymous ancestors are also flagged as NAC, which the style system relies on.
+ if (aDocument) {
+ CSSPseudoElementType pseudoType = GetPseudoElementType();
+ if (pseudoType != CSSPseudoElementType::NotPseudo &&
+ nsCSSPseudoElements::PseudoElementIsJSCreatedNAC(pseudoType)) {
+ SetFlags(NODE_IS_NATIVE_ANONYMOUS);
+ nsIContent* parent = aParent;
+ while (parent && !parent->IsRootOfNativeAnonymousSubtree()) {
+ MOZ_ASSERT(parent->IsInNativeAnonymousSubtree());
+ parent->SetFlags(NODE_IS_NATIVE_ANONYMOUS);
+ parent = parent->GetParent();
+ }
+ MOZ_ASSERT(parent);
+ }
+ }
+
// XXXbz script execution during binding can trigger some of these
// postcondition asserts.... But we do want that, since things will
// generally be quite broken when that happens.
NS_POSTCONDITION(aDocument == GetUncomposedDoc(), "Bound to wrong document");
NS_POSTCONDITION(aParent == GetParent(), "Bound to wrong parent");
NS_POSTCONDITION(aBindingParent == GetBindingParent(),
"Bound to wrong binding parent");