diff --git a/components/script/dom/element.rs b/components/script/dom/element.rs index 83574e7b6fa..df3ba6b4ece 100644 --- a/components/script/dom/element.rs +++ b/components/script/dom/element.rs @@ -13,19 +13,18 @@ use dom::bindings::codegen::Bindings::ElementBinding; use dom::bindings::codegen::Bindings::ElementBinding::ElementMethods; use dom::bindings::codegen::Bindings::EventBinding::EventMethods; use dom::bindings::codegen::Bindings::HTMLInputElementBinding::HTMLInputElementMethods; +use dom::bindings::codegen::Bindings::HTMLTemplateElementBinding::HTMLTemplateElementMethods; use dom::bindings::codegen::Bindings::NamedNodeMapBinding::NamedNodeMapMethods; use dom::bindings::codegen::Bindings::NodeBinding::NodeMethods; -use dom::bindings::codegen::InheritTypes::CharacterDataCast; -use dom::bindings::codegen::InheritTypes::DocumentDerived; -use dom::bindings::codegen::InheritTypes::HTMLAnchorElementCast; -use dom::bindings::codegen::InheritTypes::TextCast; -use dom::bindings::codegen::InheritTypes::{ElementCast, ElementDerived, EventTargetCast}; +use dom::bindings::codegen::InheritTypes::{CharacterDataCast, DocumentDerived, ElementCast}; +use dom::bindings::codegen::InheritTypes::{ElementDerived, EventTargetCast, HTMLAnchorElementCast}; use dom::bindings::codegen::InheritTypes::{HTMLBodyElementDerived, HTMLFontElementDerived}; use dom::bindings::codegen::InheritTypes::{HTMLIFrameElementDerived, HTMLInputElementCast}; use dom::bindings::codegen::InheritTypes::{HTMLInputElementDerived, HTMLTableElementCast}; use dom::bindings::codegen::InheritTypes::{HTMLTableElementDerived, HTMLTableCellElementDerived}; -use dom::bindings::codegen::InheritTypes::{HTMLTableRowElementDerived, HTMLTextAreaElementDerived}; -use dom::bindings::codegen::InheritTypes::{HTMLTableSectionElementDerived, NodeCast}; +use dom::bindings::codegen::InheritTypes::{HTMLTableRowElementDerived, HTMLTableSectionElementDerived}; +use dom::bindings::codegen::InheritTypes::{HTMLTemplateElementCast, HTMLTextAreaElementDerived}; +use dom::bindings::codegen::InheritTypes::{NodeCast, TextCast}; use dom::bindings::codegen::UnionTypes::NodeOrString; use dom::bindings::error::Error::NoModificationAllowed; use dom::bindings::error::Error::{InvalidCharacter, Syntax}; @@ -1280,19 +1279,25 @@ impl ElementMethods for Element { node.get_client_rect().size.height } - // https://dvcs.w3.org/hg/innerhtml/raw-file/tip/index.html#widl-Element-innerHTML + /// https://w3c.github.io/DOM-Parsing/#widl-Element-innerHTML fn GetInnerHTML(&self) -> Fallible { //XXX TODO: XML case self.serialize(ChildrenOnly) } - // https://dvcs.w3.org/hg/innerhtml/raw-file/tip/index.html#widl-Element-innerHTML + /// https://w3c.github.io/DOM-Parsing/#widl-Element-innerHTML fn SetInnerHTML(&self, value: DOMString) -> Fallible<()> { let context_node = NodeCast::from_ref(self); // Step 1. let frag = try!(context_node.parse_fragment(value)); // Step 2. - Node::replace_all(Some(NodeCast::from_ref(frag.r())), context_node); + // https://github.com/w3c/DOM-Parsing/issues/1 + let target = if let Some(template) = HTMLTemplateElementCast::to_ref(self) { + NodeCast::from_root(template.Content()) + } else { + Root::from_ref(context_node) + }; + Node::replace_all(Some(NodeCast::from_ref(&*frag)), &target); Ok(()) } diff --git a/components/script/parse/html.rs b/components/script/parse/html.rs index d7e1535e487..7a0ae327008 100644 --- a/components/script/parse/html.rs +++ b/components/script/parse/html.rs @@ -203,7 +203,14 @@ impl<'a> Serializable for &'a Node { try!(serializer.start_elem(name.clone(), attr_refs)); } - for handle in node.children() { + let children = if let Some(tpl) = HTMLTemplateElementCast::to_ref(node) { + // https://github.com/w3c/DOM-Parsing/issues/1 + NodeCast::from_ref(&*tpl.Content()).children() + } else { + node.children() + }; + + for handle in children { try!(handle.r().serialize(serializer, IncludeNode)); } diff --git a/tests/wpt/metadata/html/semantics/scripting-1/the-template-element/innerhtml-on-templates/innerhtml.html.ini b/tests/wpt/metadata/html/semantics/scripting-1/the-template-element/innerhtml-on-templates/innerhtml.html.ini index 493cbae40ef..450eda06a9e 100644 --- a/tests/wpt/metadata/html/semantics/scripting-1/the-template-element/innerhtml-on-templates/innerhtml.html.ini +++ b/tests/wpt/metadata/html/semantics/scripting-1/the-template-element/innerhtml-on-templates/innerhtml.html.ini @@ -1,11 +1,5 @@ [innerhtml.html] type: testharness - [innerHTML of template element replaces all referenced by the content attribute] - expected: FAIL - - [innerHTML of template element replaces all referenced by the content attribute. Test nested template] - expected: FAIL - [innerHTML of template element replaces all referenced by the content attribute. Test loading of HTML document from a file] expected: FAIL diff --git a/tests/wpt/metadata/html/semantics/scripting-1/the-template-element/serializing-html-templates/outerhtml.html.ini b/tests/wpt/metadata/html/semantics/scripting-1/the-template-element/serializing-html-templates/outerhtml.html.ini deleted file mode 100644 index 6fff7134d8f..00000000000 --- a/tests/wpt/metadata/html/semantics/scripting-1/the-template-element/serializing-html-templates/outerhtml.html.ini +++ /dev/null @@ -1,11 +0,0 @@ -[outerhtml.html] - type: testharness - [Template contents should be serialized instead of template element if serializing template element] - expected: FAIL - - [Template contents should be serialized instead of template element if serializing template element. Test nested template] - expected: FAIL - - [Template contents should be serialized instead of template element if serializing template element. Test serializing whole document] - expected: FAIL -