@@ -1378,6 +1378,47 @@ where
1378
1378
}
1379
1379
//§ END
1380
1380
1381
+ fn should_attach_declarative_shadow ( & self , tag : & Tag ) -> bool {
1382
+ let adjusted_insertion_location = self . appropriate_place_for_insertion ( None ) ;
1383
+
1384
+ let ( intended_parent, _node2) = match adjusted_insertion_location {
1385
+ LastChild ( ref p) | BeforeSibling ( ref p) => ( p. clone ( ) , None ) ,
1386
+ TableFosterParenting {
1387
+ ref element,
1388
+ ref prev_element,
1389
+ } => ( element. clone ( ) , Some ( prev_element. clone ( ) ) ) ,
1390
+ } ;
1391
+
1392
+ // template start tag's shadowrootmode is not in the none state
1393
+ let is_shadow_root_mode = tag. attrs . iter ( ) . any ( |attr| {
1394
+ attr. name . local == local_name ! ( "shadowrootmode" )
1395
+ && ( attr. value . to_string ( ) == String :: from ( "open" ) || attr. value . to_string ( ) == String :: from ( "close" ) )
1396
+ } ) ;
1397
+
1398
+ // Check if intended_parent's document allows declarative shadow roots
1399
+ let allow_declarative_shadow_roots = self . sink . allow_declarative_shadow_roots ( & intended_parent) ;
1400
+
1401
+ // the adjusted current node is not the topmost element in the stack of open elements
1402
+ let adjusted_current_node_not_topmost = match self . open_elems . borrow ( ) . first ( ) {
1403
+ // The stack grows downwards; the topmost node on the stack is the first one added to the stack
1404
+ // The current node is the bottommost node in this stack of open elements.
1405
+ //
1406
+ // (1) The adjusted current node is the context element if the parser was created as part of the HTML fragment parsing algorithm
1407
+ // and the stack of open elements has only one element in it (fragment case);
1408
+ // (2) otherwise, the adjusted current node is the current node (the bottomost node)
1409
+ //
1410
+ // => adjusted current node != topmost element in the stack when the stack size > 1
1411
+ Some ( _) => self . open_elems . borrow ( ) . len ( ) > 1 ,
1412
+ None => true ,
1413
+ } ;
1414
+
1415
+ return is_shadow_root_mode && allow_declarative_shadow_roots && adjusted_current_node_not_topmost;
1416
+ }
1417
+
1418
+ fn attach_declarative_shadow ( & self , tag : & Tag ) -> Result < ( ) , String > {
1419
+ self . sink . attach_declarative_shadow ( self . open_elems . borrow ( ) . last ( ) . unwrap ( ) , tag. attrs . clone ( ) )
1420
+ }
1421
+
1381
1422
fn create_formatting_element_for ( & self , tag : Tag ) -> Handle {
1382
1423
// FIXME: This really wants unit tests.
1383
1424
let mut first_match = None ;
0 commit comments