mirror of
https://github.com/servo/servo.git
synced 2025-06-17 12:54:28 +00:00
commit
8317122068
10 changed files with 71 additions and 64 deletions
|
@ -795,7 +795,7 @@ impl<'ln> NodeUtils for ThreadSafeLayoutNode<'ln> {
|
||||||
match self.type_id() {
|
match self.type_id() {
|
||||||
TextNodeTypeId => {
|
TextNodeTypeId => {
|
||||||
unsafe {
|
unsafe {
|
||||||
let text: JS<Text> = TextCast::to(self.get_jsmanaged());
|
let text: JS<Text> = TextCast::to(self.get_jsmanaged()).unwrap();
|
||||||
if !is_whitespace(text.get().characterdata.data) {
|
if !is_whitespace(text.get().characterdata.data) {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
|
@ -5793,9 +5793,16 @@ class GlobalGenRoots():
|
||||||
unsafe { derived.clone().transmute() }
|
unsafe { derived.clone().transmute() }
|
||||||
}
|
}
|
||||||
|
|
||||||
fn to<T: ${toBound}>(base: &JS<T>) -> JS<Self> {
|
fn to<T: ${toBound}>(base: &JS<T>) -> Option<JS<Self>> {
|
||||||
|
match base.get().${checkFn}() {
|
||||||
|
true => unsafe { Some(base.clone().transmute()) },
|
||||||
|
false => None
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
unsafe fn to_unchecked<T: ${toBound}>(base: &JS<T>) -> JS<Self> {
|
||||||
assert!(base.get().${checkFn}());
|
assert!(base.get().${checkFn}());
|
||||||
unsafe { base.clone().transmute() }
|
base.clone().transmute()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
''').substitute({'checkFn': 'is_' + name.lower(),
|
''').substitute({'checkFn': 'is_' + name.lower(),
|
||||||
|
|
|
@ -213,7 +213,7 @@ impl Document {
|
||||||
// http://dom.spec.whatwg.org/#dom-document-doctype
|
// http://dom.spec.whatwg.org/#dom-document-doctype
|
||||||
pub fn GetDoctype(&self) -> Option<JS<DocumentType>> {
|
pub fn GetDoctype(&self) -> Option<JS<DocumentType>> {
|
||||||
self.node.children().find(|child| child.is_doctype())
|
self.node.children().find(|child| child.is_doctype())
|
||||||
.map(|node| DocumentTypeCast::to(&node))
|
.map(|node| DocumentTypeCast::to(&node).unwrap())
|
||||||
}
|
}
|
||||||
|
|
||||||
// http://dom.spec.whatwg.org/#dom-document-documentelement
|
// http://dom.spec.whatwg.org/#dom-document-documentelement
|
||||||
|
@ -314,7 +314,7 @@ impl Document {
|
||||||
.map(|title_elem| {
|
.map(|title_elem| {
|
||||||
for child in title_elem.children() {
|
for child in title_elem.children() {
|
||||||
if child.is_text() {
|
if child.is_text() {
|
||||||
let text: JS<Text> = TextCast::to(&child);
|
let text: JS<Text> = TextCast::to(&child).unwrap();
|
||||||
title.push_str(text.get().characterdata.data.as_slice());
|
title.push_str(text.get().characterdata.data.as_slice());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -362,7 +362,7 @@ impl Document {
|
||||||
fn get_html_element(&self) -> Option<JS<HTMLHtmlElement>> {
|
fn get_html_element(&self) -> Option<JS<HTMLHtmlElement>> {
|
||||||
self.GetDocumentElement().filtered(|root| {
|
self.GetDocumentElement().filtered(|root| {
|
||||||
root.get().node.type_id == ElementNodeTypeId(HTMLHtmlElementTypeId)
|
root.get().node.type_id == ElementNodeTypeId(HTMLHtmlElementTypeId)
|
||||||
}).map(|elem| HTMLHtmlElementCast::to(&elem))
|
}).map(|elem| HTMLHtmlElementCast::to(&elem).unwrap())
|
||||||
}
|
}
|
||||||
|
|
||||||
// http://www.whatwg.org/specs/web-apps/current-work/#dom-document-head
|
// http://www.whatwg.org/specs/web-apps/current-work/#dom-document-head
|
||||||
|
@ -371,7 +371,7 @@ impl Document {
|
||||||
let node: JS<Node> = NodeCast::from(&root);
|
let node: JS<Node> = NodeCast::from(&root);
|
||||||
node.children().find(|child| {
|
node.children().find(|child| {
|
||||||
child.type_id() == ElementNodeTypeId(HTMLHeadElementTypeId)
|
child.type_id() == ElementNodeTypeId(HTMLHeadElementTypeId)
|
||||||
}).map(|node| HTMLHeadElementCast::to(&node))
|
}).map(|node| HTMLHeadElementCast::to(&node).unwrap())
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -385,7 +385,7 @@ impl Document {
|
||||||
ElementNodeTypeId(HTMLFrameSetElementTypeId) => true,
|
ElementNodeTypeId(HTMLFrameSetElementTypeId) => true,
|
||||||
_ => false
|
_ => false
|
||||||
}
|
}
|
||||||
}).map(|node| HTMLElementCast::to(&node))
|
}).map(|node| HTMLElementCast::to(&node).unwrap())
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -434,7 +434,7 @@ impl Document {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
let element: JS<Element> = ElementCast::to(node);
|
let element: JS<Element> = ElementCast::to(node).unwrap();
|
||||||
element.get().get_attribute(Null, "name").map_or(false, |attr| {
|
element.get().get_attribute(Null, "name").map_or(false, |attr| {
|
||||||
attr.get().value_ref() == name
|
attr.get().value_ref() == name
|
||||||
})
|
})
|
||||||
|
|
|
@ -272,15 +272,15 @@ impl Element {
|
||||||
// This hardcoding is awful.
|
// This hardcoding is awful.
|
||||||
match abstract_self.get().node.type_id {
|
match abstract_self.get().node.type_id {
|
||||||
ElementNodeTypeId(HTMLImageElementTypeId) => {
|
ElementNodeTypeId(HTMLImageElementTypeId) => {
|
||||||
let mut elem: JS<HTMLImageElement> = HTMLImageElementCast::to(abstract_self);
|
let mut elem: JS<HTMLImageElement> = HTMLImageElementCast::to(abstract_self).unwrap();
|
||||||
elem.get_mut().AfterSetAttr(local_name.clone(), value.clone());
|
elem.get_mut().AfterSetAttr(local_name.clone(), value.clone());
|
||||||
}
|
}
|
||||||
ElementNodeTypeId(HTMLIFrameElementTypeId) => {
|
ElementNodeTypeId(HTMLIFrameElementTypeId) => {
|
||||||
let mut elem: JS<HTMLIFrameElement> = HTMLIFrameElementCast::to(abstract_self);
|
let mut elem: JS<HTMLIFrameElement> = HTMLIFrameElementCast::to(abstract_self).unwrap();
|
||||||
elem.get_mut().AfterSetAttr(local_name.clone(), value.clone());
|
elem.get_mut().AfterSetAttr(local_name.clone(), value.clone());
|
||||||
}
|
}
|
||||||
ElementNodeTypeId(HTMLObjectElementTypeId) => {
|
ElementNodeTypeId(HTMLObjectElementTypeId) => {
|
||||||
let mut elem: JS<HTMLObjectElement> = HTMLObjectElementCast::to(abstract_self);
|
let mut elem: JS<HTMLObjectElement> = HTMLObjectElementCast::to(abstract_self).unwrap();
|
||||||
elem.get_mut().AfterSetAttr(local_name.clone(), value.clone());
|
elem.get_mut().AfterSetAttr(local_name.clone(), value.clone());
|
||||||
}
|
}
|
||||||
_ => ()
|
_ => ()
|
||||||
|
@ -341,11 +341,11 @@ impl Element {
|
||||||
// This hardcoding is awful.
|
// This hardcoding is awful.
|
||||||
match abstract_self.get().node.type_id {
|
match abstract_self.get().node.type_id {
|
||||||
ElementNodeTypeId(HTMLImageElementTypeId) => {
|
ElementNodeTypeId(HTMLImageElementTypeId) => {
|
||||||
let mut elem: JS<HTMLImageElement> = HTMLImageElementCast::to(abstract_self);
|
let mut elem: JS<HTMLImageElement> = HTMLImageElementCast::to(abstract_self).unwrap();
|
||||||
elem.get_mut().BeforeRemoveAttr(local_name.clone());
|
elem.get_mut().BeforeRemoveAttr(local_name.clone());
|
||||||
}
|
}
|
||||||
ElementNodeTypeId(HTMLIFrameElementTypeId) => {
|
ElementNodeTypeId(HTMLIFrameElementTypeId) => {
|
||||||
let mut elem: JS<HTMLIFrameElement> = HTMLIFrameElementCast::to(abstract_self);
|
let mut elem: JS<HTMLIFrameElement> = HTMLIFrameElementCast::to(abstract_self).unwrap();
|
||||||
elem.get_mut().BeforeRemoveAttr(local_name.clone());
|
elem.get_mut().BeforeRemoveAttr(local_name.clone());
|
||||||
}
|
}
|
||||||
_ => ()
|
_ => ()
|
||||||
|
|
|
@ -28,7 +28,7 @@ pub fn dispatch_event(target: &JS<EventTarget>,
|
||||||
|
|
||||||
//TODO: no chain if not participating in a tree
|
//TODO: no chain if not participating in a tree
|
||||||
if target.get().is_node() {
|
if target.get().is_node() {
|
||||||
let target_node: JS<Node> = NodeCast::to(target);
|
let target_node: JS<Node> = NodeCast::to(target).unwrap();
|
||||||
for ancestor in target_node.ancestors() {
|
for ancestor in target_node.ancestors() {
|
||||||
let ancestor_target: JS<EventTarget> = EventTargetCast::from(&ancestor);
|
let ancestor_target: JS<EventTarget> = EventTargetCast::from(&ancestor);
|
||||||
chain.push(ancestor_target);
|
chain.push(ancestor_target);
|
||||||
|
|
|
@ -39,7 +39,7 @@ impl HTMLCollection {
|
||||||
let mut elements = ~[];
|
let mut elements = ~[];
|
||||||
for child in root.traverse_preorder() {
|
for child in root.traverse_preorder() {
|
||||||
if child.is_element() {
|
if child.is_element() {
|
||||||
let elem: JS<Element> = ElementCast::to(&child);
|
let elem: JS<Element> = ElementCast::to(&child).unwrap();
|
||||||
if predicate(&elem) {
|
if predicate(&elem) {
|
||||||
elements.push(elem);
|
elements.push(elem);
|
||||||
}
|
}
|
||||||
|
|
|
@ -30,23 +30,23 @@ pub fn serialize(iterator: &mut NodeIterator) -> ~str {
|
||||||
html.push_str(
|
html.push_str(
|
||||||
match node.type_id() {
|
match node.type_id() {
|
||||||
ElementNodeTypeId(..) => {
|
ElementNodeTypeId(..) => {
|
||||||
let elem: JS<Element> = ElementCast::to(&node);
|
let elem: JS<Element> = ElementCast::to(&node).unwrap();
|
||||||
serialize_elem(&elem, &mut open_elements)
|
serialize_elem(&elem, &mut open_elements)
|
||||||
}
|
}
|
||||||
CommentNodeTypeId => {
|
CommentNodeTypeId => {
|
||||||
let comment: JS<Comment> = CommentCast::to(&node);
|
let comment: JS<Comment> = CommentCast::to(&node).unwrap();
|
||||||
serialize_comment(&comment)
|
serialize_comment(&comment)
|
||||||
}
|
}
|
||||||
TextNodeTypeId => {
|
TextNodeTypeId => {
|
||||||
let text: JS<Text> = TextCast::to(&node);
|
let text: JS<Text> = TextCast::to(&node).unwrap();
|
||||||
serialize_text(&text)
|
serialize_text(&text)
|
||||||
}
|
}
|
||||||
DoctypeNodeTypeId => {
|
DoctypeNodeTypeId => {
|
||||||
let doctype: JS<DocumentType> = DocumentTypeCast::to(&node);
|
let doctype: JS<DocumentType> = DocumentTypeCast::to(&node).unwrap();
|
||||||
serialize_doctype(&doctype)
|
serialize_doctype(&doctype)
|
||||||
}
|
}
|
||||||
ProcessingInstructionNodeTypeId => {
|
ProcessingInstructionNodeTypeId => {
|
||||||
let processing_instruction: JS<ProcessingInstruction> = ProcessingInstructionCast::to(&node);
|
let processing_instruction: JS<ProcessingInstruction> = ProcessingInstructionCast::to(&node).unwrap();
|
||||||
serialize_processing_instruction(&processing_instruction)
|
serialize_processing_instruction(&processing_instruction)
|
||||||
}
|
}
|
||||||
DocumentFragmentNodeTypeId => {
|
DocumentFragmentNodeTypeId => {
|
||||||
|
@ -71,7 +71,7 @@ fn serialize_comment(comment: &JS<Comment>) -> ~str {
|
||||||
fn serialize_text(text: &JS<Text>) -> ~str {
|
fn serialize_text(text: &JS<Text>) -> ~str {
|
||||||
match text.get().characterdata.node.parent_node {
|
match text.get().characterdata.node.parent_node {
|
||||||
Some(ref parent) if parent.is_element() => {
|
Some(ref parent) if parent.is_element() => {
|
||||||
let elem: JS<Element> = ElementCast::to(parent);
|
let elem: JS<Element> = ElementCast::to(parent).unwrap();
|
||||||
match elem.get().tag_name.as_slice() {
|
match elem.get().tag_name.as_slice() {
|
||||||
"style" | "script" | "xmp" | "iframe" |
|
"style" | "script" | "xmp" | "iframe" |
|
||||||
"noembed" | "noframes" | "plaintext" |
|
"noembed" | "noframes" | "plaintext" |
|
||||||
|
@ -103,7 +103,7 @@ fn serialize_elem(elem: &JS<Element>, open_elements: &mut ~[~str]) -> ~str {
|
||||||
"pre" | "listing" | "textarea" if elem.get().namespace == namespace::HTML => {
|
"pre" | "listing" | "textarea" if elem.get().namespace == namespace::HTML => {
|
||||||
match elem.get().node.first_child {
|
match elem.get().node.first_child {
|
||||||
Some(ref child) if child.is_text() => {
|
Some(ref child) if child.is_text() => {
|
||||||
let text: JS<CharacterData> = CharacterDataCast::to(child);
|
let text: JS<CharacterData> = CharacterDataCast::to(child).unwrap();
|
||||||
if text.get().data.len() > 0 && text.get().data[0] == 0x0A as u8 {
|
if text.get().data.len() > 0 && text.get().data[0] == 0x0A as u8 {
|
||||||
rv.push_str("\x0A");
|
rv.push_str("\x0A");
|
||||||
}
|
}
|
||||||
|
|
|
@ -407,7 +407,7 @@ impl NodeHelpers for JS<Node> {
|
||||||
if self.is_in_doc() {
|
if self.is_in_doc() {
|
||||||
for node in self.traverse_preorder() {
|
for node in self.traverse_preorder() {
|
||||||
if node.is_element() {
|
if node.is_element() {
|
||||||
let element: JS<Element> = ElementCast::to(&node);
|
let element: JS<Element> = ElementCast::to(&node).unwrap();
|
||||||
element.bind_to_tree_impl();
|
element.bind_to_tree_impl();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -423,7 +423,7 @@ impl NodeHelpers for JS<Node> {
|
||||||
|
|
||||||
for node in self.traverse_preorder() {
|
for node in self.traverse_preorder() {
|
||||||
if node.is_element() {
|
if node.is_element() {
|
||||||
let element: JS<Element> = ElementCast::to(&node);
|
let element: JS<Element> = ElementCast::to(&node).unwrap();
|
||||||
element.unbind_from_tree_impl();
|
element.unbind_from_tree_impl();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -660,7 +660,7 @@ impl NodeIterator {
|
||||||
|
|
||||||
fn next_child(&self, node: &JS<Node>) -> Option<JS<Node>> {
|
fn next_child(&self, node: &JS<Node>) -> Option<JS<Node>> {
|
||||||
if !self.include_descendants_of_void && node.is_element() {
|
if !self.include_descendants_of_void && node.is_element() {
|
||||||
let elem: JS<Element> = ElementCast::to(node);
|
let elem: JS<Element> = ElementCast::to(node).unwrap();
|
||||||
if elem.get().is_void() {
|
if elem.get().is_void() {
|
||||||
None
|
None
|
||||||
} else {
|
} else {
|
||||||
|
@ -761,7 +761,7 @@ impl Node {
|
||||||
self.children()
|
self.children()
|
||||||
.filter(|node| node.is_element())
|
.filter(|node| node.is_element())
|
||||||
.map(|node| {
|
.map(|node| {
|
||||||
let elem: JS<Element> = ElementCast::to(&node);
|
let elem: JS<Element> = ElementCast::to(&node).unwrap();
|
||||||
elem
|
elem
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
@ -837,18 +837,18 @@ impl Node {
|
||||||
pub fn NodeName(&self, abstract_self: &JS<Node>) -> DOMString {
|
pub fn NodeName(&self, abstract_self: &JS<Node>) -> DOMString {
|
||||||
match self.type_id {
|
match self.type_id {
|
||||||
ElementNodeTypeId(..) => {
|
ElementNodeTypeId(..) => {
|
||||||
let elem: JS<Element> = ElementCast::to(abstract_self);
|
let elem: JS<Element> = ElementCast::to(abstract_self).unwrap();
|
||||||
elem.get().TagName()
|
elem.get().TagName()
|
||||||
}
|
}
|
||||||
TextNodeTypeId => ~"#text",
|
TextNodeTypeId => ~"#text",
|
||||||
ProcessingInstructionNodeTypeId => {
|
ProcessingInstructionNodeTypeId => {
|
||||||
let processing_instruction: JS<ProcessingInstruction> =
|
let processing_instruction: JS<ProcessingInstruction> =
|
||||||
ProcessingInstructionCast::to(abstract_self);
|
ProcessingInstructionCast::to(abstract_self).unwrap();
|
||||||
processing_instruction.get().Target()
|
processing_instruction.get().Target()
|
||||||
}
|
}
|
||||||
CommentNodeTypeId => ~"#comment",
|
CommentNodeTypeId => ~"#comment",
|
||||||
DoctypeNodeTypeId => {
|
DoctypeNodeTypeId => {
|
||||||
let doctype: JS<DocumentType> = DocumentTypeCast::to(abstract_self);
|
let doctype: JS<DocumentType> = DocumentTypeCast::to(abstract_self).unwrap();
|
||||||
doctype.get().name.clone()
|
doctype.get().name.clone()
|
||||||
},
|
},
|
||||||
DocumentFragmentNodeTypeId => ~"#document-fragment",
|
DocumentFragmentNodeTypeId => ~"#document-fragment",
|
||||||
|
@ -884,7 +884,7 @@ impl Node {
|
||||||
pub fn GetParentElement(&self) -> Option<JS<Element>> {
|
pub fn GetParentElement(&self) -> Option<JS<Element>> {
|
||||||
self.parent_node.clone()
|
self.parent_node.clone()
|
||||||
.filtered(|parent| parent.is_element())
|
.filtered(|parent| parent.is_element())
|
||||||
.map(|node| ElementCast::to(&node))
|
.map(|node| ElementCast::to(&node).unwrap())
|
||||||
}
|
}
|
||||||
|
|
||||||
// http://dom.spec.whatwg.org/#dom-node-haschildnodes
|
// http://dom.spec.whatwg.org/#dom-node-haschildnodes
|
||||||
|
@ -932,7 +932,7 @@ impl Node {
|
||||||
CommentNodeTypeId |
|
CommentNodeTypeId |
|
||||||
TextNodeTypeId |
|
TextNodeTypeId |
|
||||||
ProcessingInstructionNodeTypeId => {
|
ProcessingInstructionNodeTypeId => {
|
||||||
let chardata: JS<CharacterData> = CharacterDataCast::to(abstract_self);
|
let chardata: JS<CharacterData> = CharacterDataCast::to(abstract_self).unwrap();
|
||||||
Some(chardata.get().Data())
|
Some(chardata.get().Data())
|
||||||
}
|
}
|
||||||
_ => {
|
_ => {
|
||||||
|
@ -962,7 +962,7 @@ impl Node {
|
||||||
let mut content = ~"";
|
let mut content = ~"";
|
||||||
for node in abstract_self.traverse_preorder() {
|
for node in abstract_self.traverse_preorder() {
|
||||||
if node.is_text() {
|
if node.is_text() {
|
||||||
let text: JS<Text> = TextCast::to(&node);
|
let text: JS<Text> = TextCast::to(&node).unwrap();
|
||||||
content.push_str(text.get().characterdata.data.as_slice());
|
content.push_str(text.get().characterdata.data.as_slice());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -971,7 +971,7 @@ impl Node {
|
||||||
CommentNodeTypeId |
|
CommentNodeTypeId |
|
||||||
TextNodeTypeId |
|
TextNodeTypeId |
|
||||||
ProcessingInstructionNodeTypeId => {
|
ProcessingInstructionNodeTypeId => {
|
||||||
let characterdata: JS<CharacterData> = CharacterDataCast::to(abstract_self);
|
let characterdata: JS<CharacterData> = CharacterDataCast::to(abstract_self).unwrap();
|
||||||
Some(characterdata.get().Data())
|
Some(characterdata.get().Data())
|
||||||
}
|
}
|
||||||
DoctypeNodeTypeId |
|
DoctypeNodeTypeId |
|
||||||
|
@ -1003,7 +1003,7 @@ impl Node {
|
||||||
ProcessingInstructionNodeTypeId => {
|
ProcessingInstructionNodeTypeId => {
|
||||||
self.wait_until_safe_to_modify_dom();
|
self.wait_until_safe_to_modify_dom();
|
||||||
|
|
||||||
let mut characterdata: JS<CharacterData> = CharacterDataCast::to(abstract_self);
|
let mut characterdata: JS<CharacterData> = CharacterDataCast::to(abstract_self).unwrap();
|
||||||
characterdata.get_mut().data = value.clone();
|
characterdata.get_mut().data = value.clone();
|
||||||
|
|
||||||
// Notify the document that the content of this node is different
|
// Notify the document that the content of this node is different
|
||||||
|
@ -1310,7 +1310,7 @@ impl Node {
|
||||||
// XXXabinader: clone() for each node as trait?
|
// XXXabinader: clone() for each node as trait?
|
||||||
let mut copy: JS<Node> = match node.type_id() {
|
let mut copy: JS<Node> = match node.type_id() {
|
||||||
DoctypeNodeTypeId => {
|
DoctypeNodeTypeId => {
|
||||||
let doctype: JS<DocumentType> = DocumentTypeCast::to(node);
|
let doctype: JS<DocumentType> = DocumentTypeCast::to(node).unwrap();
|
||||||
let doctype = doctype.get();
|
let doctype = doctype.get();
|
||||||
let doctype = DocumentType::new(doctype.name.clone(),
|
let doctype = DocumentType::new(doctype.name.clone(),
|
||||||
Some(doctype.public_id.clone()),
|
Some(doctype.public_id.clone()),
|
||||||
|
@ -1322,13 +1322,13 @@ impl Node {
|
||||||
NodeCast::from(&doc_fragment)
|
NodeCast::from(&doc_fragment)
|
||||||
},
|
},
|
||||||
CommentNodeTypeId => {
|
CommentNodeTypeId => {
|
||||||
let comment: JS<Comment> = CommentCast::to(node);
|
let comment: JS<Comment> = CommentCast::to(node).unwrap();
|
||||||
let comment = comment.get();
|
let comment = comment.get();
|
||||||
let comment = Comment::new(comment.characterdata.data.clone(), &document);
|
let comment = Comment::new(comment.characterdata.data.clone(), &document);
|
||||||
NodeCast::from(&comment)
|
NodeCast::from(&comment)
|
||||||
},
|
},
|
||||||
DocumentNodeTypeId => {
|
DocumentNodeTypeId => {
|
||||||
let document: JS<Document> = DocumentCast::to(node);
|
let document: JS<Document> = DocumentCast::to(node).unwrap();
|
||||||
let document = document.get();
|
let document = document.get();
|
||||||
let is_html_doc = match document.is_html_document {
|
let is_html_doc = match document.is_html_document {
|
||||||
true => HTMLDocument,
|
true => HTMLDocument,
|
||||||
|
@ -1339,19 +1339,19 @@ impl Node {
|
||||||
NodeCast::from(&document)
|
NodeCast::from(&document)
|
||||||
},
|
},
|
||||||
ElementNodeTypeId(..) => {
|
ElementNodeTypeId(..) => {
|
||||||
let element: JS<Element> = ElementCast::to(node);
|
let element: JS<Element> = ElementCast::to(node).unwrap();
|
||||||
let element = element.get();
|
let element = element.get();
|
||||||
let element = build_element_from_tag(element.tag_name.clone(), &document);
|
let element = build_element_from_tag(element.tag_name.clone(), &document);
|
||||||
NodeCast::from(&element)
|
NodeCast::from(&element)
|
||||||
},
|
},
|
||||||
TextNodeTypeId => {
|
TextNodeTypeId => {
|
||||||
let text: JS<Text> = TextCast::to(node);
|
let text: JS<Text> = TextCast::to(node).unwrap();
|
||||||
let text = text.get();
|
let text = text.get();
|
||||||
let text = Text::new(text.characterdata.data.clone(), &document);
|
let text = Text::new(text.characterdata.data.clone(), &document);
|
||||||
NodeCast::from(&text)
|
NodeCast::from(&text)
|
||||||
},
|
},
|
||||||
ProcessingInstructionNodeTypeId => {
|
ProcessingInstructionNodeTypeId => {
|
||||||
let pi: JS<ProcessingInstruction> = ProcessingInstructionCast::to(node);
|
let pi: JS<ProcessingInstruction> = ProcessingInstructionCast::to(node).unwrap();
|
||||||
let pi = pi.get();
|
let pi = pi.get();
|
||||||
let pi = ProcessingInstruction::new(pi.target.clone(),
|
let pi = ProcessingInstruction::new(pi.target.clone(),
|
||||||
pi.characterdata.data.clone(), &document);
|
pi.characterdata.data.clone(), &document);
|
||||||
|
@ -1361,24 +1361,24 @@ impl Node {
|
||||||
|
|
||||||
// Step 3.
|
// Step 3.
|
||||||
if copy.is_document() {
|
if copy.is_document() {
|
||||||
document = DocumentCast::to(©);
|
document = DocumentCast::to(©).unwrap();
|
||||||
}
|
}
|
||||||
assert_eq!(copy.get().owner_doc(), &document);
|
assert_eq!(copy.get().owner_doc(), &document);
|
||||||
|
|
||||||
// Step 4 (some data already copied in step 2).
|
// Step 4 (some data already copied in step 2).
|
||||||
match node.type_id() {
|
match node.type_id() {
|
||||||
DocumentNodeTypeId => {
|
DocumentNodeTypeId => {
|
||||||
let node_doc: JS<Document> = DocumentCast::to(node);
|
let node_doc: JS<Document> = DocumentCast::to(node).unwrap();
|
||||||
let node_doc = node_doc.get();
|
let node_doc = node_doc.get();
|
||||||
let mut copy_doc: JS<Document> = DocumentCast::to(©);
|
let mut copy_doc: JS<Document> = DocumentCast::to(©).unwrap();
|
||||||
let copy_doc = copy_doc.get_mut();
|
let copy_doc = copy_doc.get_mut();
|
||||||
copy_doc.set_encoding_name(node_doc.encoding_name.clone());
|
copy_doc.set_encoding_name(node_doc.encoding_name.clone());
|
||||||
copy_doc.set_quirks_mode(node_doc.quirks_mode());
|
copy_doc.set_quirks_mode(node_doc.quirks_mode());
|
||||||
},
|
},
|
||||||
ElementNodeTypeId(..) => {
|
ElementNodeTypeId(..) => {
|
||||||
let node_elem: JS<Element> = ElementCast::to(node);
|
let node_elem: JS<Element> = ElementCast::to(node).unwrap();
|
||||||
let node_elem = node_elem.get();
|
let node_elem = node_elem.get();
|
||||||
let mut copy_elem: JS<Element> = ElementCast::to(©);
|
let mut copy_elem: JS<Element> = ElementCast::to(©).unwrap();
|
||||||
let copy_elem = copy_elem.get_mut();
|
let copy_elem = copy_elem.get_mut();
|
||||||
// FIXME: https://github.com/mozilla/servo/issues/1737
|
// FIXME: https://github.com/mozilla/servo/issues/1737
|
||||||
copy_elem.namespace = node_elem.namespace.clone();
|
copy_elem.namespace = node_elem.namespace.clone();
|
||||||
|
@ -1561,13 +1561,13 @@ impl Node {
|
||||||
let mut prev_text = None;
|
let mut prev_text = None;
|
||||||
for mut child in self.children() {
|
for mut child in self.children() {
|
||||||
if child.is_text() {
|
if child.is_text() {
|
||||||
let characterdata: JS<CharacterData> = CharacterDataCast::to(&child);
|
let characterdata: JS<CharacterData> = CharacterDataCast::to(&child).unwrap();
|
||||||
if characterdata.get().Length() == 0 {
|
if characterdata.get().Length() == 0 {
|
||||||
abstract_self.remove_child(&mut child);
|
abstract_self.remove_child(&mut child);
|
||||||
} else {
|
} else {
|
||||||
match prev_text {
|
match prev_text {
|
||||||
Some(ref text_node) => {
|
Some(ref text_node) => {
|
||||||
let mut prev_characterdata: JS<CharacterData> = CharacterDataCast::to(text_node);
|
let mut prev_characterdata: JS<CharacterData> = CharacterDataCast::to(text_node).unwrap();
|
||||||
let _ = prev_characterdata.get_mut().AppendData(characterdata.get().Data());
|
let _ = prev_characterdata.get_mut().AppendData(characterdata.get().Data());
|
||||||
abstract_self.remove_child(&mut child);
|
abstract_self.remove_child(&mut child);
|
||||||
},
|
},
|
||||||
|
@ -1592,34 +1592,34 @@ impl Node {
|
||||||
// http://dom.spec.whatwg.org/#dom-node-isequalnode
|
// http://dom.spec.whatwg.org/#dom-node-isequalnode
|
||||||
pub fn IsEqualNode(&self, abstract_self: &JS<Node>, maybe_node: Option<JS<Node>>) -> bool {
|
pub fn IsEqualNode(&self, abstract_self: &JS<Node>, maybe_node: Option<JS<Node>>) -> bool {
|
||||||
fn is_equal_doctype(node: &JS<Node>, other: &JS<Node>) -> bool {
|
fn is_equal_doctype(node: &JS<Node>, other: &JS<Node>) -> bool {
|
||||||
let doctype: JS<DocumentType> = DocumentTypeCast::to(node);
|
let doctype: JS<DocumentType> = DocumentTypeCast::to(node).unwrap();
|
||||||
let other_doctype: JS<DocumentType> = DocumentTypeCast::to(other);
|
let other_doctype: JS<DocumentType> = DocumentTypeCast::to(other).unwrap();
|
||||||
(doctype.get().name == other_doctype.get().name) &&
|
(doctype.get().name == other_doctype.get().name) &&
|
||||||
(doctype.get().public_id == other_doctype.get().public_id) &&
|
(doctype.get().public_id == other_doctype.get().public_id) &&
|
||||||
(doctype.get().system_id == other_doctype.get().system_id)
|
(doctype.get().system_id == other_doctype.get().system_id)
|
||||||
}
|
}
|
||||||
fn is_equal_element(node: &JS<Node>, other: &JS<Node>) -> bool {
|
fn is_equal_element(node: &JS<Node>, other: &JS<Node>) -> bool {
|
||||||
let element: JS<Element> = ElementCast::to(node);
|
let element: JS<Element> = ElementCast::to(node).unwrap();
|
||||||
let other_element: JS<Element> = ElementCast::to(other);
|
let other_element: JS<Element> = ElementCast::to(other).unwrap();
|
||||||
// FIXME: namespace prefix
|
// FIXME: namespace prefix
|
||||||
(element.get().namespace == other_element.get().namespace) &&
|
(element.get().namespace == other_element.get().namespace) &&
|
||||||
(element.get().tag_name == other_element.get().tag_name) &&
|
(element.get().tag_name == other_element.get().tag_name) &&
|
||||||
(element.get().attrs.len() == other_element.get().attrs.len())
|
(element.get().attrs.len() == other_element.get().attrs.len())
|
||||||
}
|
}
|
||||||
fn is_equal_processinginstruction(node: &JS<Node>, other: &JS<Node>) -> bool {
|
fn is_equal_processinginstruction(node: &JS<Node>, other: &JS<Node>) -> bool {
|
||||||
let pi: JS<ProcessingInstruction> = ProcessingInstructionCast::to(node);
|
let pi: JS<ProcessingInstruction> = ProcessingInstructionCast::to(node).unwrap();
|
||||||
let other_pi: JS<ProcessingInstruction> = ProcessingInstructionCast::to(other);
|
let other_pi: JS<ProcessingInstruction> = ProcessingInstructionCast::to(other).unwrap();
|
||||||
(pi.get().target == other_pi.get().target) &&
|
(pi.get().target == other_pi.get().target) &&
|
||||||
(pi.get().characterdata.data == other_pi.get().characterdata.data)
|
(pi.get().characterdata.data == other_pi.get().characterdata.data)
|
||||||
}
|
}
|
||||||
fn is_equal_characterdata(node: &JS<Node>, other: &JS<Node>) -> bool {
|
fn is_equal_characterdata(node: &JS<Node>, other: &JS<Node>) -> bool {
|
||||||
let characterdata: JS<CharacterData> = CharacterDataCast::to(node);
|
let characterdata: JS<CharacterData> = CharacterDataCast::to(node).unwrap();
|
||||||
let other_characterdata: JS<CharacterData> = CharacterDataCast::to(other);
|
let other_characterdata: JS<CharacterData> = CharacterDataCast::to(other).unwrap();
|
||||||
characterdata.get().data == other_characterdata.get().data
|
characterdata.get().data == other_characterdata.get().data
|
||||||
}
|
}
|
||||||
fn is_equal_element_attrs(node: &JS<Node>, other: &JS<Node>) -> bool {
|
fn is_equal_element_attrs(node: &JS<Node>, other: &JS<Node>) -> bool {
|
||||||
let element: JS<Element> = ElementCast::to(node);
|
let element: JS<Element> = ElementCast::to(node).unwrap();
|
||||||
let other_element: JS<Element> = ElementCast::to(other);
|
let other_element: JS<Element> = ElementCast::to(other).unwrap();
|
||||||
assert!(element.get().attrs.len() == other_element.get().attrs.len());
|
assert!(element.get().attrs.len() == other_element.get().attrs.len());
|
||||||
element.get().attrs.iter().all(|attr| {
|
element.get().attrs.iter().all(|attr| {
|
||||||
other_element.get().attrs.iter().any(|other_attr| {
|
other_element.get().attrs.iter().any(|other_attr| {
|
||||||
|
|
|
@ -369,7 +369,7 @@ pub fn parse_html(page: &Page,
|
||||||
ElementNodeTypeId(HTMLIFrameElementTypeId) => {
|
ElementNodeTypeId(HTMLIFrameElementTypeId) => {
|
||||||
let iframe_chan = discovery_chan.clone();
|
let iframe_chan = discovery_chan.clone();
|
||||||
let mut iframe_element: JS<HTMLIFrameElement> =
|
let mut iframe_element: JS<HTMLIFrameElement> =
|
||||||
HTMLIFrameElementCast::to(&element);
|
HTMLIFrameElementCast::to(&element).unwrap();
|
||||||
let sandboxed = iframe_element.get().is_sandboxed();
|
let sandboxed = iframe_element.get().is_sandboxed();
|
||||||
let elem: JS<Element> = ElementCast::from(&iframe_element);
|
let elem: JS<Element> = ElementCast::from(&iframe_element);
|
||||||
let src_opt = elem.get().get_attribute(Null, "src").map(|x| x.get().Value());
|
let src_opt = elem.get().get_attribute(Null, "src").map(|x| x.get().Value());
|
||||||
|
@ -475,7 +475,7 @@ pub fn parse_html(page: &Page,
|
||||||
debug!("iterating over children {:?}", scriptnode.first_child());
|
debug!("iterating over children {:?}", scriptnode.first_child());
|
||||||
for child in scriptnode.children() {
|
for child in scriptnode.children() {
|
||||||
debug!("child = {:?}", child);
|
debug!("child = {:?}", child);
|
||||||
let text: JS<Text> = TextCast::to(&child);
|
let text: JS<Text> = TextCast::to(&child).unwrap();
|
||||||
data.push(text.get().characterdata.data.to_str()); // FIXME: Bad copy.
|
data.push(text.get().characterdata.data.to_str()); // FIXME: Bad copy.
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -494,7 +494,7 @@ pub fn parse_html(page: &Page,
|
||||||
debug!("iterating over children {:?}", style.first_child());
|
debug!("iterating over children {:?}", style.first_child());
|
||||||
for child in style.children() {
|
for child in style.children() {
|
||||||
debug!("child = {:?}", child);
|
debug!("child = {:?}", child);
|
||||||
let text: JS<Text> = TextCast::to(&child);
|
let text: JS<Text> = TextCast::to(&child).unwrap();
|
||||||
data.push(text.get().characterdata.data.to_str()); // FIXME: Bad copy.
|
data.push(text.get().characterdata.data.to_str()); // FIXME: Bad copy.
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -915,11 +915,11 @@ impl ScriptTask {
|
||||||
let doc_node: JS<Node> = NodeCast::from(&document);
|
let doc_node: JS<Node> = NodeCast::from(&document);
|
||||||
let mut anchors = doc_node.traverse_preorder().filter(|node| node.is_anchor_element());
|
let mut anchors = doc_node.traverse_preorder().filter(|node| node.is_anchor_element());
|
||||||
anchors.find(|node| {
|
anchors.find(|node| {
|
||||||
let elem: JS<Element> = ElementCast::to(node);
|
let elem: JS<Element> = ElementCast::to(node).unwrap();
|
||||||
elem.get().get_attribute(Null, "name").map_or(false, |attr| {
|
elem.get().get_attribute(Null, "name").map_or(false, |attr| {
|
||||||
attr.get().value_ref() == fragid
|
attr.get().value_ref() == fragid
|
||||||
})
|
})
|
||||||
}).map(|node| ElementCast::to(&node))
|
}).map(|node| ElementCast::to(&node).unwrap())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1027,7 +1027,7 @@ impl ScriptTask {
|
||||||
}
|
}
|
||||||
|
|
||||||
if node.is_element() {
|
if node.is_element() {
|
||||||
let element: JS<Element> = ElementCast::to(&node);
|
let element: JS<Element> = ElementCast::to(&node).unwrap();
|
||||||
if "a" == element.get().tag_name {
|
if "a" == element.get().tag_name {
|
||||||
self.load_url_from_element(page, element.get())
|
self.load_url_from_element(page, element.get())
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue