Skip to content

Commit 0f7252d

Browse files
Update declarative shadow dom
Signed-off-by: batu_hoang <[email protected]>
1 parent 518a3ac commit 0f7252d

File tree

3 files changed

+28
-6
lines changed

3 files changed

+28
-6
lines changed

html5ever/src/tree_builder/mod.rs

+21-2
Original file line numberDiff line numberDiff line change
@@ -1376,6 +1376,25 @@ where
13761376
fn insert_phantom(&self, name: LocalName) -> Handle {
13771377
self.insert_element(Push, ns!(html), name, vec![])
13781378
}
1379+
1380+
fn insert_foreign_element(
1381+
&self,
1382+
tag: Tag,
1383+
ns: Namespace,
1384+
only_add_to_element_stack: bool,
1385+
) -> Handle {
1386+
let adjusted_insertion_location = self.appropriate_place_for_insertion(None);
1387+
let qname = QualName::new(None, ns, tag.name);
1388+
let elem = create_element(&self.sink, qname.clone(), tag.attrs.clone());
1389+
1390+
if !only_add_to_element_stack {
1391+
self.insert_at(adjusted_insertion_location, AppendNode(elem.clone()));
1392+
}
1393+
1394+
self.push(&elem);
1395+
1396+
elem
1397+
}
13791398
//§ END
13801399

13811400
fn should_attach_declarative_shadow(&self, tag: &Tag) -> bool {
@@ -1416,9 +1435,9 @@ where
14161435
is_shadow_root_mode && allow_declarative_shadow_roots && adjusted_current_node_not_topmost
14171436
}
14181437

1419-
fn attach_declarative_shadow(&self, tag: &Tag) -> Result<(), String> {
1438+
fn attach_declarative_shadow(&self, tag: &Tag, shadow_host: &Handle, template: &Handle) -> Result<(), String> {
14201439
self.sink
1421-
.attach_declarative_shadow(self.open_elems.borrow().last().unwrap(), tag.attrs.clone())
1440+
.attach_declarative_shadow(shadow_host, template, tag.attrs.clone())
14221441
}
14231442

14241443
fn create_formatting_element_for(&self, tag: Tag) -> Handle {

html5ever/src/tree_builder/rules.rs

+6-4
Original file line numberDiff line numberDiff line change
@@ -160,10 +160,12 @@ where
160160
self.template_modes.borrow_mut().push(InTemplate);
161161

162162
if (self.should_attach_declarative_shadow(&tag)) {
163-
if self.attach_declarative_shadow(&tag).is_err() {
164-
// TODO:
165-
// insert at the adjusted insertion location
166-
// with the result of insert a foreign element for template tag
163+
let shadow_host = self.open_elems.borrow().last().unwrap().clone();
164+
let template = self.insert_foreign_element(tag.clone(), ns!(html), true);
165+
166+
if self.attach_declarative_shadow(&tag, &shadow_host, &template).is_err() {
167+
let adjusted_insertion_location = self.appropriate_place_for_insertion(None);
168+
self.insert_at(adjusted_insertion_location, AppendNode(template.clone()));
167169
}
168170
} else {
169171
self.insert_element_for(tag);

markup5ever/interface/tree_builder.rs

+1
Original file line numberDiff line numberDiff line change
@@ -269,6 +269,7 @@ pub trait TreeSink {
269269
fn attach_declarative_shadow(
270270
&self,
271271
_location: &Self::Handle,
272+
_template: &Self::Handle,
272273
_attrs: Vec<Attribute>,
273274
) -> Result<(), String> {
274275
Err(String::from(

0 commit comments

Comments
 (0)