Bug 1712140 - Part 3: Add support for parsing and building Declarative ShadowDOMs. r=dom-core,webidl,saschanaz,hsivonen

Differential Revision: https://phabricator.services.mozilla.com/D193675
This commit is contained in:
Adam Vandolder
2023-12-06 22:50:49 +00:00
parent 2353e195dc
commit 0956658e5f
21 changed files with 426 additions and 23 deletions

View File

@@ -7,9 +7,12 @@
#include "ErrorList.h"
#include "nsError.h"
#include "nsHtml5AttributeName.h"
#include "nsHtml5HtmlAttributes.h"
#include "nsHtml5String.h"
#include "nsNetUtil.h"
#include "mozilla/dom/FetchPriority.h"
#include "mozilla/dom/ShadowRoot.h"
#include "mozilla/dom/ShadowRootBinding.h"
#include "mozilla/CheckedInt.h"
#include "mozilla/Likely.h"
#include "mozilla/StaticPrefs_dom.h"
@@ -38,6 +41,7 @@ nsHtml5TreeBuilder::nsHtml5TreeBuilder(nsHtml5OplessBuilder* aBuilder)
charBufferLen(0),
quirks(false),
forceNoQuirks(false),
allowDeclarativeShadowRoots(false),
mBuilder(aBuilder),
mViewSource(nullptr),
mOpSink(nullptr),
@@ -1636,6 +1640,53 @@ nsIContentHandle* nsHtml5TreeBuilder::getDocumentFragmentForTemplate(
return fragHandle;
}
void nsHtml5TreeBuilder::setDocumentFragmentForTemplate(
nsIContentHandle* aTemplate, nsIContentHandle* aFragment) {
if (mBuilder) {
nsHtml5TreeOperation::SetDocumentFragmentForTemplate(
static_cast<nsIContent*>(aTemplate),
static_cast<nsIContent*>(aFragment));
return;
}
nsHtml5TreeOperation* treeOp = mOpQueue.AppendElement(mozilla::fallible);
if (MOZ_UNLIKELY(!treeOp)) {
MarkAsBrokenAndRequestSuspensionWithoutBuilder(NS_ERROR_OUT_OF_MEMORY);
return;
}
opSetDocumentFragmentForTemplate operation(aTemplate, aFragment);
treeOp->Init(mozilla::AsVariant(operation));
}
nsIContentHandle* nsHtml5TreeBuilder::getShadowRootFromHost(
nsIContentHandle* aHost, nsIContentHandle* aTemplateNode,
nsHtml5String aShadowRootMode, bool aShadowRootDelegatesFocus) {
mozilla::dom::ShadowRootMode mode;
if (aShadowRootMode.LowerCaseEqualsASCII("open")) {
mode = mozilla::dom::ShadowRootMode::Open;
} else if (aShadowRootMode.LowerCaseEqualsASCII("closed")) {
mode = mozilla::dom::ShadowRootMode::Closed;
} else {
return nullptr;
}
if (mBuilder) {
return nsContentUtils::AttachDeclarativeShadowRoot(
static_cast<nsIContent*>(aHost), mode, aShadowRootDelegatesFocus);
}
nsHtml5TreeOperation* treeOp = mOpQueue.AppendElement(mozilla::fallible);
if (MOZ_UNLIKELY(!treeOp)) {
MarkAsBrokenAndRequestSuspensionWithoutBuilder(NS_ERROR_OUT_OF_MEMORY);
return nullptr;
}
nsIContentHandle* fragHandle = AllocateContentHandle();
opGetShadowRootFromHost operation(aHost, fragHandle, aTemplateNode, mode,
aShadowRootDelegatesFocus);
treeOp->Init(mozilla::AsVariant(operation));
return fragHandle;
}
nsIContentHandle* nsHtml5TreeBuilder::getFormPointerForContext(
nsIContentHandle* aContext) {
MOZ_ASSERT(mBuilder, "Must have builder.");