Bug 1425759: Make Shadow DOM not use XBL anymore. r=smaug,xidorn

More improvements to come. In particular, this still iterates through Shadow DOM
in each_xbl_cascade_data, but that should be changed later. That allows to
cleanup a bunch of stuff and finally fix Shadow DOM cascade order.

We still rely on the binding parent to be setup properly in the shadow tree, but
that requirement can go away later (we can walk the containing shadow chain
instead).

This mostly focuses on removing the XBL binding from the Shadow host.

It'd be nice to do EnumerateShadowRoots faster. I think that should also be a
followup, if needed.

MozReview-Commit-ID: Jf2iGvLC5de
This commit is contained in:
Emilio Cobos Álvarez
2018-02-25 18:01:42 +01:00
parent 99e5b9f573
commit 23e91e805a
10 changed files with 175 additions and 102 deletions

View File

@@ -1218,17 +1218,17 @@ Element::AttachShadow(const ShadowRootInit& aInit, ErrorResult& aError)
return nullptr;
}
return AttachShadowInternal(aInit.mMode == ShadowRootMode::Closed, aError);
return AttachShadowInternal(aInit.mMode, aError);
}
already_AddRefed<ShadowRoot>
Element::CreateShadowRoot(ErrorResult& aError)
{
return AttachShadowInternal(false, aError);
return AttachShadowInternal(ShadowRootMode::Open, aError);
}
already_AddRefed<ShadowRoot>
Element::AttachShadowInternal(bool aClosed, ErrorResult& aError)
Element::AttachShadowInternal(ShadowRootMode aMode, ErrorResult& aError)
{
/**
* 3. If context object is a shadow host, then throw
@@ -1241,20 +1241,10 @@ Element::AttachShadowInternal(bool aClosed, ErrorResult& aError)
nsAutoScriptBlocker scriptBlocker;
RefPtr<mozilla::dom::NodeInfo> nodeInfo;
nodeInfo = mNodeInfo->NodeInfoManager()->GetNodeInfo(
nsGkAtoms::documentFragmentNodeName, nullptr, kNameSpaceID_None,
DOCUMENT_FRAGMENT_NODE);
RefPtr<nsXBLDocumentInfo> docInfo = new nsXBLDocumentInfo(OwnerDoc());
nsXBLPrototypeBinding* protoBinding = new nsXBLPrototypeBinding();
aError = protoBinding->Init(NS_LITERAL_CSTRING("shadowroot"),
docInfo, nullptr, true);
if (aError.Failed()) {
delete protoBinding;
return nullptr;
}
RefPtr<mozilla::dom::NodeInfo> nodeInfo =
mNodeInfo->NodeInfoManager()->GetNodeInfo(
nsGkAtoms::documentFragmentNodeName, nullptr, kNameSpaceID_None,
DOCUMENT_FRAGMENT_NODE);
if (nsIDocument* doc = GetComposedDoc()) {
if (nsIPresShell* shell = doc->GetShell()) {
@@ -1264,19 +1254,13 @@ Element::AttachShadowInternal(bool aClosed, ErrorResult& aError)
}
MOZ_ASSERT(!GetPrimaryFrame());
// Unlike for XBL, false is the default for inheriting style.
protoBinding->SetInheritsStyle(false);
// Calling SetPrototypeBinding takes ownership of protoBinding.
docInfo->SetPrototypeBinding(NS_LITERAL_CSTRING("shadowroot"), protoBinding);
/**
* 4. Let shadow be a new shadow root whose node document is
* context objects node document, host is context object,
* and mode is inits mode.
*/
RefPtr<ShadowRoot> shadowRoot =
new ShadowRoot(this, aClosed, nodeInfo.forget(), protoBinding);
new ShadowRoot(this, aMode, nodeInfo.forget());
shadowRoot->SetIsComposedDocParticipant(IsInComposedDoc());
@@ -1285,13 +1269,6 @@ Element::AttachShadowInternal(bool aClosed, ErrorResult& aError)
*/
SetShadowRoot(shadowRoot);
// xblBinding takes ownership of docInfo.
RefPtr<nsXBLBinding> xblBinding = new nsXBLBinding(shadowRoot, protoBinding);
shadowRoot->SetAssociatedBinding(xblBinding);
xblBinding->SetBoundElement(this);
SetXBLBinding(xblBinding);
/**
* 6. Return shadow.
*/