diff options
Diffstat (limited to 'components/script/dom/range.rs')
-rw-r--r-- | components/script/dom/range.rs | 18 |
1 files changed, 5 insertions, 13 deletions
diff --git a/components/script/dom/range.rs b/components/script/dom/range.rs index 8e8b9888b87..b2507aeab3b 100644 --- a/components/script/dom/range.rs +++ b/components/script/dom/range.rs @@ -22,11 +22,10 @@ use dom::characterdata::CharacterData; use dom::document::Document; use dom::documentfragment::DocumentFragment; use dom::element::Element; -use dom::globalscope::GlobalScope; -use dom::htmlbodyelement::HTMLBodyElement; use dom::htmlscriptelement::HTMLScriptElement; use dom::node::{Node, UnbindContext}; use dom::text::Text; +use dom::window::Window; use heapsize::HeapSizeOf; use js::jsapi::JSTracer; use std::cell::{Cell, UnsafeCell}; @@ -70,8 +69,8 @@ impl Range { } // https://dom.spec.whatwg.org/#dom-range - pub fn Constructor(global: &GlobalScope) -> Fallible<Root<Range>> { - let document = global.as_window().Document(); + pub fn Constructor(window: &Window) -> Fallible<Root<Range>> { + let document = window.Document(); Ok(Range::new_with_doc(&document)) } @@ -901,6 +900,7 @@ impl RangeMethods for Range { fn CreateContextualFragment(&self, fragment: DOMString) -> Fallible<Root<DocumentFragment>> { // Step 1. let node = self.StartContainer(); + let owner_doc = node.owner_doc(); let element = match node.type_id() { NodeTypeId::Document(_) | NodeTypeId::DocumentFragment => None, NodeTypeId::Element(_) => Some(Root::downcast::<Element>(node).unwrap()), @@ -911,15 +911,7 @@ impl RangeMethods for Range { }; // Step 2. - let should_create_body = element.as_ref().map_or(true, |elem| { - let elem = elem.downcast::<Element>().unwrap(); - elem.local_name() == &local_name!("html") && elem.html_element_in_html_document() - }); - let element: Root<Node> = if should_create_body { - Root::upcast(HTMLBodyElement::new(local_name!("body"), None, &self.StartContainer().owner_doc())) - } else { - Root::upcast(element.unwrap()) - }; + let element = Element::fragment_parsing_context(&owner_doc, element.r()); // Step 3. let fragment_node = try!(element.parse_fragment(fragment)); |