@@ -434,6 +434,8 @@ public abstract class TreeBuilder<T> implements TokenHandler,
434434
435435 private boolean forceNoQuirks = false ;
436436
437+ private boolean allowDeclarativeShadowRoots = false ;
438+
437439 // [NOCPP[
438440
439441 private boolean reportingDoctype = true ;
@@ -2958,6 +2960,20 @@ private boolean isSpecialParentInForeign(StackNode<T> stackNode) {
29582960 || (("http://www.w3.org/1998/Math/MathML" == ns ) && (stackNode .getGroup () == MI_MO_MN_MS_MTEXT ));
29592961 }
29602962
2963+ private T getDeclarativeShadowRoot (T currentNode , T templateNode , HtmlAttributes attributes ) {
2964+ if (!isAllowDeclarativeShadowRoots ()) {
2965+ return null ;
2966+ }
2967+
2968+ String shadowRootMode = attributes .getValue (AttributeName .SHADOWROOTMODE );
2969+ if (shadowRootMode == null ) {
2970+ return null ;
2971+ }
2972+
2973+ boolean shadowRootDelegatesFocus = attributes .contains (AttributeName .SHADOWROOTDELEGATESFOCUS );
2974+ return getShadowRootFromHost (currentNode , templateNode , shadowRootMode , shadowRootDelegatesFocus );
2975+ }
2976+
29612977 /**
29622978 *
29632979 * <p>
@@ -5302,9 +5318,17 @@ private void appendToCurrentNodeAndPushElement(ElementName elementName,
53025318 T elt = createElement ("http://www.w3.org/1999/xhtml" , elementName .getName (), attributes , currentNode
53035319 // CPPONLY: , htmlCreator(elementName.getHtmlCreator())
53045320 );
5305- appendElement (elt , currentNode );
53065321 if (ElementName .TEMPLATE == elementName ) {
5307- elt = getDocumentFragmentForTemplate (elt );
5322+ T root = getDeclarativeShadowRoot (currentNode , elt , attributes );
5323+ if (root != null ) {
5324+ setDocumentFragmentForTemplate (elt , root );
5325+ elt = root ;
5326+ } else {
5327+ appendElement (elt , currentNode );
5328+ elt = getDocumentFragmentForTemplate (elt );
5329+ }
5330+ } else {
5331+ appendElement (elt , currentNode );
53085332 }
53095333 StackNode <T > node = createStackNode (elementName , elt
53105334 // [NOCPP[
@@ -5391,6 +5415,13 @@ T getDocumentFragmentForTemplate(T template) {
53915415 return template ;
53925416 }
53935417
5418+ void setDocumentFragmentForTemplate (T template , T fragment ) {
5419+ }
5420+
5421+ T getShadowRootFromHost (T host , T template , String shadowRootMode , boolean shadowRootDelegatesFocus ) {
5422+ return null ;
5423+ }
5424+
53945425 T getFormPointerForContext (T context ) {
53955426 return null ;
53965427 }
@@ -5509,6 +5540,7 @@ private void appendVoidElementToCurrentMayFoster(
55095540 } else {
55105541 T currentNode = nodeFromStackWithBlinkCompat (currentPtr );
55115542 elt = createElement ("http://www.w3.org/1999/xhtml" , name ,
5543+
55125544 attributes , formOwner , currentNode
55135545 // CPPONLY: , htmlCreator(elementName.getHtmlCreator())
55145546 );
@@ -5893,6 +5925,14 @@ public void setIsSrcdocDocument(boolean isSrcdocDocument) {
58935925 this .setForceNoQuirks (isSrcdocDocument );
58945926 }
58955927
5928+ public boolean isAllowDeclarativeShadowRoots () {
5929+ return allowDeclarativeShadowRoots ;
5930+ }
5931+
5932+ public void setAllowDeclarativeShadowRoots (boolean allow ) {
5933+ allowDeclarativeShadowRoots = allow ;
5934+ }
5935+
58965936 // [NOCPP[
58975937
58985938 public void setNamePolicy (XmlViolationPolicy namePolicy ) {
0 commit comments