mirror of
https://github.com/servo/servo.git
synced 2025-08-05 13:40:08 +01:00
Auto merge of #11496 - GuillaumeGomez:range, r=nox
Implement Range::createContextualFragment <!-- Reviewable:start --> This change is [<img src="https://reviewable.io/review_button.svg" height="35" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/servo/11496) <!-- Reviewable:end -->
This commit is contained in:
commit
51d41c5161
8 changed files with 49 additions and 38 deletions
|
@ -130,7 +130,6 @@ impl Element {
|
||||||
create_element(name, prefix, document, creator)
|
create_element(name, prefix, document, creator)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
pub fn new_inherited(local_name: Atom,
|
pub fn new_inherited(local_name: Atom,
|
||||||
namespace: Namespace, prefix: Option<DOMString>,
|
namespace: Namespace, prefix: Option<DOMString>,
|
||||||
document: &Document) -> Element {
|
document: &Document) -> Element {
|
||||||
|
|
|
@ -532,8 +532,8 @@ impl HTMLScriptElement {
|
||||||
is_js
|
is_js
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn mark_already_started(&self) {
|
pub fn set_already_started(&self, already_started: bool) {
|
||||||
self.already_started.set(true);
|
self.already_started.set(already_started);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn dispatch_event(&self,
|
fn dispatch_event(&self,
|
||||||
|
@ -593,7 +593,7 @@ impl VirtualMethods for HTMLScriptElement {
|
||||||
|
|
||||||
// https://html.spec.whatwg.org/multipage/#already-started
|
// https://html.spec.whatwg.org/multipage/#already-started
|
||||||
if self.already_started.get() {
|
if self.already_started.get() {
|
||||||
copy.downcast::<HTMLScriptElement>().unwrap().mark_already_started();
|
copy.downcast::<HTMLScriptElement>().unwrap().set_already_started(true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -22,6 +22,9 @@ use dom::bindings::weakref::{WeakRef, WeakRefVec};
|
||||||
use dom::characterdata::CharacterData;
|
use dom::characterdata::CharacterData;
|
||||||
use dom::document::Document;
|
use dom::document::Document;
|
||||||
use dom::documentfragment::DocumentFragment;
|
use dom::documentfragment::DocumentFragment;
|
||||||
|
use dom::element::Element;
|
||||||
|
use dom::htmlbodyelement::HTMLBodyElement;
|
||||||
|
use dom::htmlscriptelement::HTMLScriptElement;
|
||||||
use dom::node::{Node, UnbindContext};
|
use dom::node::{Node, UnbindContext};
|
||||||
use dom::text::Text;
|
use dom::text::Text;
|
||||||
use heapsize::HeapSizeOf;
|
use heapsize::HeapSizeOf;
|
||||||
|
@ -893,6 +896,44 @@ impl RangeMethods for Range {
|
||||||
// Step 6.
|
// Step 6.
|
||||||
s
|
s
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// https://dvcs.w3.org/hg/innerhtml/raw-file/tip/index.html#extensions-to-the-range-interface
|
||||||
|
fn CreateContextualFragment(&self, fragment: DOMString) -> Fallible<Root<DocumentFragment>> {
|
||||||
|
// Step 1.
|
||||||
|
let node = self.StartContainer();
|
||||||
|
let element = match node.type_id() {
|
||||||
|
NodeTypeId::Document(_) | NodeTypeId::DocumentFragment => None,
|
||||||
|
NodeTypeId::Element(_) => Some(node),
|
||||||
|
NodeTypeId::CharacterData(CharacterDataTypeId::Comment) |
|
||||||
|
NodeTypeId::CharacterData(CharacterDataTypeId::Text) => node.GetParentNode(),
|
||||||
|
NodeTypeId::CharacterData(CharacterDataTypeId::ProcessingInstruction) |
|
||||||
|
NodeTypeId::DocumentType => unreachable!(),
|
||||||
|
};
|
||||||
|
|
||||||
|
// Step 2.
|
||||||
|
let should_create_body = element.as_ref().map_or(true, |elem| {
|
||||||
|
let elem = elem.downcast::<Element>().unwrap();
|
||||||
|
elem.local_name() == &atom!("html") && elem.html_element_in_html_document()
|
||||||
|
});
|
||||||
|
let element: Root<Node> = if should_create_body {
|
||||||
|
Root::upcast(HTMLBodyElement::new(atom!("body"), None, &self.StartContainer().owner_doc()))
|
||||||
|
} else {
|
||||||
|
Root::upcast(element.unwrap())
|
||||||
|
};
|
||||||
|
|
||||||
|
// Step 3.
|
||||||
|
let fragment_node = try!(element.parse_fragment(fragment));
|
||||||
|
|
||||||
|
// Step 4.
|
||||||
|
for node in fragment_node.upcast::<Node>().traverse_preorder() {
|
||||||
|
if let Some(script) = node.downcast::<HTMLScriptElement>() {
|
||||||
|
script.set_already_started(false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Step 5.
|
||||||
|
Ok(fragment_node)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(JSTraceable)]
|
#[derive(JSTraceable)]
|
||||||
|
|
|
@ -76,9 +76,9 @@ interface Range {
|
||||||
|
|
||||||
// https://dvcs.w3.org/hg/innerhtml/raw-file/tip/index.html#extensions-to-the-range-interface
|
// https://dvcs.w3.org/hg/innerhtml/raw-file/tip/index.html#extensions-to-the-range-interface
|
||||||
partial interface Range {
|
partial interface Range {
|
||||||
// [NewObject, Throws]
|
[NewObject, Throws]
|
||||||
// DocumentFragment createContextualFragment(DOMString fragment);
|
DocumentFragment createContextualFragment(DOMString fragment);
|
||||||
};//
|
};
|
||||||
|
|
||||||
// http://dev.w3.org/csswg/cssom-view/#extensions-to-the-range-interface
|
// http://dev.w3.org/csswg/cssom-view/#extensions-to-the-range-interface
|
||||||
partial interface Range {
|
partial interface Range {
|
||||||
|
|
|
@ -150,7 +150,7 @@ impl<'a> TreeSink for servohtmlparser::Sink {
|
||||||
|
|
||||||
fn mark_script_already_started(&mut self, node: JS<Node>) {
|
fn mark_script_already_started(&mut self, node: JS<Node>) {
|
||||||
let script = node.downcast::<HTMLScriptElement>();
|
let script = node.downcast::<HTMLScriptElement>();
|
||||||
script.map(|script| script.mark_already_started());
|
script.map(|script| script.set_already_started(true));
|
||||||
}
|
}
|
||||||
|
|
||||||
fn complete_script(&mut self, node: JS<Node>) -> NextParserState {
|
fn complete_script(&mut self, node: JS<Node>) -> NextParserState {
|
||||||
|
|
|
@ -107,7 +107,7 @@ impl<'a> TreeSink for servoxmlparser::Sink {
|
||||||
fn mark_script_already_started(&mut self, node: Self::Handle) {
|
fn mark_script_already_started(&mut self, node: Self::Handle) {
|
||||||
let script = node.downcast::<HTMLScriptElement>();
|
let script = node.downcast::<HTMLScriptElement>();
|
||||||
if let Some(script) = script {
|
if let Some(script) = script {
|
||||||
script.mark_already_started();
|
script.set_already_started(true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,35 +1,11 @@
|
||||||
[createContextualFragment.html]
|
[createContextualFragment.html]
|
||||||
type: testharness
|
type: testharness
|
||||||
[Must not throw INVALID_STATE_ERR for a detached node.]
|
|
||||||
expected: FAIL
|
|
||||||
|
|
||||||
[Simple test with paragraphs]
|
|
||||||
expected: FAIL
|
|
||||||
|
|
||||||
[Don't auto-create <body> when applied to <html>]
|
|
||||||
expected: FAIL
|
|
||||||
|
|
||||||
[<script>s should be run when appended to the document (but not before)]
|
[<script>s should be run when appended to the document (but not before)]
|
||||||
expected: FAIL
|
expected: FAIL
|
||||||
|
|
||||||
[<html> and <body> must work the same, 1]
|
|
||||||
expected: FAIL
|
|
||||||
|
|
||||||
[<html> and <body> must work the same, 2]
|
|
||||||
expected: FAIL
|
|
||||||
|
|
||||||
[Implicit <body> creation]
|
|
||||||
expected: FAIL
|
|
||||||
|
|
||||||
[Namespace generally shouldn't matter]
|
[Namespace generally shouldn't matter]
|
||||||
expected: FAIL
|
expected: FAIL
|
||||||
|
|
||||||
[<html> in a different namespace shouldn't be special]
|
[<html> in a different namespace shouldn't be special]
|
||||||
expected: FAIL
|
expected: FAIL
|
||||||
|
|
||||||
[null should be stringified]
|
|
||||||
expected: FAIL
|
|
||||||
|
|
||||||
[undefined should be stringified]
|
|
||||||
expected: FAIL
|
|
||||||
|
|
||||||
|
|
|
@ -1,5 +0,0 @@
|
||||||
[119.html]
|
|
||||||
type: testharness
|
|
||||||
[scheduler: external defer script created with createContextualFragment]
|
|
||||||
expected: FAIL
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue