diff options
-rw-r--r-- | components/script/dom/element.rs | 43 | ||||
-rw-r--r-- | components/script/dom/webidls/Element.webidl | 2 | ||||
-rw-r--r-- | tests/wpt/metadata/dom/nodes/Document-getElementById.html.ini | 8 |
3 files changed, 44 insertions, 9 deletions
diff --git a/components/script/dom/element.rs b/components/script/dom/element.rs index 66ca145d623..b67014f5676 100644 --- a/components/script/dom/element.rs +++ b/components/script/dom/element.rs @@ -15,6 +15,7 @@ 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::NamedNodeMapBinding::NamedNodeMapMethods; +use dom::bindings::codegen::Bindings::NodeBinding::NodeMethods; use dom::bindings::codegen::InheritTypes::{ElementCast, ElementDerived, EventTargetCast}; use dom::bindings::codegen::InheritTypes::{HTMLBodyElementDerived, HTMLInputElementCast}; use dom::bindings::codegen::InheritTypes::{HTMLInputElementDerived, HTMLTableElementCast}; @@ -25,6 +26,7 @@ use dom::bindings::codegen::InheritTypes::HTMLAnchorElementCast; use dom::bindings::error::{ErrorResult, Fallible}; use dom::bindings::error::Error; use dom::bindings::error::Error::{InvalidCharacter, Syntax}; +use dom::bindings::error::Error::NoModificationAllowed; use dom::bindings::js::{MutNullableJS, JS, JSRef, LayoutJS, Temporary, TemporaryPushable}; use dom::bindings::js::OptionalRootable; use dom::bindings::trace::RootedVec; @@ -1184,6 +1186,47 @@ impl<'a> ElementMethods for JSRef<'a, Element> { self.serialize(IncludeNode) } + fn SetOuterHTML(self, value: DOMString) -> Fallible<()> { + let context_document = document_from_node(self).root(); + let context_node: JSRef<Node> = NodeCast::from_ref(self); + // 1. Let parent be the context object's parent. + let context_parent = match context_node.parent_node() { + // 2. If parent is null, terminate these steps. + None => return Ok(()), + Some(parent) => parent.root() + }; + + let parent: Root<Node> = match context_parent.r().type_id() { + // 3. If parent is a Document, throw a DOMException + // with name "NoModificationAllowedError" exception. + NodeTypeId::Document => return Err(NoModificationAllowed), + + // 4. If parent is a DocumentFragment, let parent be a new Element with + // body as its local name, + // The HTML namespace as its namespace, and + // The context object's node document as its node document. + NodeTypeId::DocumentFragment => { + let body_elem = Element::create(QualName::new(ns!(HTML), atom!(body)), + None, context_document.r(), + ElementCreator::ScriptCreated); + let body_node: Temporary<Node> = NodeCast::from_temporary(body_elem); + body_node.root() + }, + _ => context_node.parent_node().unwrap().root() + }; + + // 5. Let fragment be the result of invoking the fragment parsing algorithm with + // the new value as markup, and parent as the context element. + // 6. Replace the context object with fragment within the context object's parent. + parent.r().parse_fragment(HTMLInput::InputString(value)) + .and_then(|frag| { + let frag = frag.root(); + let frag_node: JSRef<Node> = NodeCast::from_ref(frag.r()); + try!(context_parent.r().ReplaceChild(frag_node, context_node)); + Ok(()) + }) + } + // http://dom.spec.whatwg.org/#dom-parentnode-children fn Children(self) -> Temporary<HTMLCollection> { let window = window_from_node(self).root(); diff --git a/components/script/dom/webidls/Element.webidl b/components/script/dom/webidls/Element.webidl index 245df78e812..8d08717cd31 100644 --- a/components/script/dom/webidls/Element.webidl +++ b/components/script/dom/webidls/Element.webidl @@ -66,7 +66,7 @@ partial interface Element { [Throws,TreatNullAs=EmptyString] attribute DOMString innerHTML; [Throws,TreatNullAs=EmptyString] - readonly attribute DOMString outerHTML; + attribute DOMString outerHTML; }; Element implements ChildNode; diff --git a/tests/wpt/metadata/dom/nodes/Document-getElementById.html.ini b/tests/wpt/metadata/dom/nodes/Document-getElementById.html.ini deleted file mode 100644 index 5f10bd87f50..00000000000 --- a/tests/wpt/metadata/dom/nodes/Document-getElementById.html.ini +++ /dev/null @@ -1,8 +0,0 @@ -[Document-getElementById.html] - type: testharness - [add id attribute via outerHTML] - expected: FAIL - - [remove id attribute via outerHTML] - expected: FAIL - |