Introduce trait Castable

This trait is used to hold onto the downcast and upcast functions of all
castable IDL interfaces. A castable IDL interface is one which either derives
from or is derived by other interfaces.

The deriving relation is represented by implementations of marker trait
DerivedFrom<T: Castable> generated in InheritTypes.

/^[ ]*use dom::bindings::codegen::InheritTypes::.*(Base|Cast|Derived)/ {
    /::[a-zA-Z]+(Base|Cast|Derived);/d
    s/([{ ])[a-zA-Z]+(Base|Cast|Derived), /\1/g
    s/([{ ])[a-zA-Z]+(Base|Cast|Derived), /\1/g
    s/, [a-zA-Z]+(Base|Cast|Derived)([},])/\2/g
    s/, [a-zA-Z]+(Base|Cast|Derived)([},])/\2/g
    /\{([a-zA-Z]+(Base|Cast|Derived))?\};$/d
    s/\{([a-zA-Z_]+)\};$/\1;/
}

s/([a-zA-Z]+)Cast::from_ref\(\&?\**([a-zA-Z_]+)(\.r\(\))?\)/\2.upcast::<\1>()/g
s/([a-zA-Z]+)Cast::from_ref\(\&?\**([a-zA-Z_]+)(\.[a-zA-Z_]+\(\))?\)/\2\3.upcast::<\1>()/g
s/\(([a-zA-Z]+)Cast::from_ref\)/\(Castable::upcast::<\1>\)/g

s/([a-zA-Z]+)Cast::from_root/Root::upcast::<\1>/g

s/([a-zA-Z]+)Cast::from_layout_js\(\&([a-zA-Z_.]+)\)/\2.upcast::<\1>()/g

s/([a-zA-Z]+)Cast::to_ref\(\&?\**([a-zA-Z_]+)(\.r\(\))?\)/\2.downcast::<\1>()/g
s/([a-zA-Z]+)Cast::to_ref\(\&?\**([a-zA-Z_]+)(\.[a-zA-Z_]+\(\))?\)/\2\3.downcast::<\1>()/g
s/\(([a-zA-Z]+)Cast::to_ref\)/\(Castable::downcast::<\1>\)/g

s/([a-zA-Z]+)Cast::to_root/Root::downcast::<\1>/g

s/([a-zA-Z]+)Cast::to_layout_js\(&?([a-zA-Z_.]+(\(\))?)\)/\2.downcast::<\1>()/g

s/\.is_document\(\)/.is::<Document>()/g
s/\.is_htmlanchorelement\(\)/.is::<HTMLAnchorElement>()/g
s/\.is_htmlappletelement\(\)/.is::<HTMLAppletElement>()/g
s/\.is_htmlareaelement\(\)/.is::<HTMLAreaElement>()/g
s/\.is_htmlbodyelement\(\)/.is::<HTMLBodyElement>()/g
s/\.is_htmlembedelement\(\)/.is::<HTMLEmbedElement>()/g
s/\.is_htmlfieldsetelement\(\)/.is::<HTMLFieldSetElement>()/g
s/\.is_htmlformelement\(\)/.is::<HTMLFormElement>()/g
s/\.is_htmlframesetelement\(\)/.is::<HTMLFrameSetElement>()/g
s/\.is_htmlhtmlelement\(\)/.is::<HTMLHtmlElement>()/g
s/\.is_htmlimageelement\(\)/.is::<HTMLImageElement>()/g
s/\.is_htmllegendelement\(\)/.is::<HTMLLegendElement>()/g
s/\.is_htmloptgroupelement\(\)/.is::<HTMLOptGroupElement>()/g
s/\.is_htmloptionelement\(\)/.is::<HTMLOptionElement>()/g
s/\.is_htmlscriptelement\(\)/.is::<HTMLScriptElement>()/g
s/\.is_htmltabledatacellelement\(\)/.is::<HTMLTableDataCellElement>()/g
s/\.is_htmltableheadercellelement\(\)/.is::<HTMLTableHeaderCellElement>()/g
s/\.is_htmltablerowelement\(\)/.is::<HTMLTableRowElement>()/g
s/\.is_htmltablesectionelement\(\)/.is::<HTMLTableSectionElement>()/g
s/\.is_htmltitleelement\(\)/.is::<HTMLTitleElement>()/g
This commit is contained in:
Anthony Ramine 2015-10-06 17:21:44 +02:00
parent bd363b009d
commit 13ea3ac413
82 changed files with 1124 additions and 1148 deletions

View file

@ -19,17 +19,10 @@ use dom::bindings::codegen::Bindings::NamedNodeMapBinding::NamedNodeMapMethods;
use dom::bindings::codegen::Bindings::NodeBinding::{NodeConstants, NodeMethods};
use dom::bindings::codegen::Bindings::NodeListBinding::NodeListMethods;
use dom::bindings::codegen::Bindings::ProcessingInstructionBinding::ProcessingInstructionMethods;
use dom::bindings::codegen::InheritTypes::HTMLElementBase;
use dom::bindings::codegen::InheritTypes::HTMLElementCast;
use dom::bindings::codegen::InheritTypes::{CharacterDataCast, CharacterDataTypeId};
use dom::bindings::codegen::InheritTypes::{DocumentCast, DocumentDerived, DocumentTypeCast};
use dom::bindings::codegen::InheritTypes::{ElementCast, ElementDerived, ElementTypeId};
use dom::bindings::codegen::InheritTypes::{EventTargetCast, EventTargetTypeId};
use dom::bindings::codegen::InheritTypes::{HTMLElementTypeId};
use dom::bindings::codegen::InheritTypes::{NodeBase, NodeCast, NodeTypeId};
use dom::bindings::codegen::InheritTypes::{ProcessingInstructionCast, TextCast, TextDerived};
use dom::bindings::codegen::InheritTypes::{CharacterDataTypeId, ElementTypeId, EventTargetTypeId};
use dom::bindings::codegen::InheritTypes::{HTMLElementTypeId, NodeTypeId};
use dom::bindings::codegen::UnionTypes::NodeOrString;
use dom::bindings::conversions;
use dom::bindings::conversions::{self, Castable, DerivedFrom};
use dom::bindings::error::{Error, ErrorResult, Fallible};
use dom::bindings::global::GlobalRef;
use dom::bindings::js::Root;
@ -362,9 +355,9 @@ impl<'a> Iterator for QuerySelectorIterator {
// TODO(cgaebel): Is it worth it to build a bloom filter here
// (instead of passing `None`)? Probably.
self.iterator.by_ref().filter_map(|node| {
if let Some(element) = ElementCast::to_root(node) {
if let Some(element) = Root::downcast::<Element>(node) {
if matches(selectors, &element, None) {
return Some(NodeCast::from_root(element))
return Some(Root::upcast::<Node>(element))
}
}
None
@ -424,7 +417,7 @@ impl Node {
match self.type_id() {
NodeTypeId::DocumentType => 0,
NodeTypeId::CharacterData(_) => {
CharacterDataCast::to_ref(self).unwrap().Length()
self.downcast::<CharacterData>().unwrap().Length()
},
_ => self.children_count(),
}
@ -725,7 +718,7 @@ impl Node {
Err(()) => Err(Error::Syntax),
// Step 3.
Ok(ref selectors) => {
Ok(self.traverse_preorder().filter_map(ElementCast::to_root).find(|element| {
Ok(self.traverse_preorder().filter_map(Root::downcast::<Element>).find(|element| {
matches(selectors, element, None)
}))
}
@ -795,7 +788,7 @@ impl Node {
pub fn child_elements(&self) -> ChildElementIterator {
fn to_temporary(node: Root<Node>) -> Option<Root<Element>> {
ElementCast::to_root(node)
Root::downcast::<Element>(node)
}
self.children()
.filter_map(to_temporary as fn(_) -> _)
@ -832,7 +825,7 @@ impl Node {
systemId: "".to_owned(),
attrs: {
let e: Option<&Element> = ElementCast::to_ref(self);
let e: Option<&Element> = self.downcast::<Element>();
match e {
Some(element) => element.summarize(),
None => vec!(),
@ -843,7 +836,7 @@ impl Node {
self.owner_doc()
.r()
.GetDocumentElement()
.map(|elem| NodeCast::from_ref(elem.r()) == self)
.map(|elem| elem.upcast::<Node>() == self)
.unwrap_or(false),
shortValue: self.GetNodeValue().unwrap_or("".to_owned()), //FIXME: truncate
@ -853,11 +846,11 @@ impl Node {
// https://dvcs.w3.org/hg/innerhtml/raw-file/tip/index.html#dfn-concept-parse-fragment
pub fn parse_fragment(&self, markup: DOMString) -> Fallible<Root<DocumentFragment>> {
let context_node: &Node = NodeCast::from_ref(self);
let context_node: &Node = self.upcast::<Node>();
let context_document = document_from_node(self);
let fragment = DocumentFragment::new(context_document.r());
if context_document.r().is_html_document() {
let fragment_node = NodeCast::from_ref(fragment.r());
let fragment_node = fragment.upcast::<Node>();
parse_html_fragment(context_node, markup, fragment_node);
} else {
// FIXME: XML case
@ -870,7 +863,7 @@ impl Node {
pub fn insert_cell_or_row<F, G, I>(&self, index: i32, get_items: F, new_child: G) -> Fallible<Root<HTMLElement>>
where F: Fn() -> Root<HTMLCollection>,
G: Fn() -> Root<I>,
I: NodeBase + HTMLElementBase + Reflectable,
I: DerivedFrom<Node> + DerivedFrom<HTMLElement> + Reflectable,
{
if index < -1 {
return Err(Error::IndexSize);
@ -882,7 +875,7 @@ impl Node {
None
} else {
match get_items().elements_iter()
.map(NodeCast::from_root)
.map(Root::upcast::<Node>)
.map(Some)
.chain(iter::once(None))
.nth(index as usize) {
@ -892,11 +885,11 @@ impl Node {
};
{
let tr_node = NodeCast::from_ref(tr.r());
let tr_node = tr.upcast::<Node>();
try!(self.InsertBefore(tr_node, after_node.r()));
}
Ok(HTMLElementCast::from_root(tr))
Ok(Root::upcast::<HTMLElement>(tr))
}
/// Used by `HTMLTableSectionElement::DeleteRow` and `HTMLTableRowElement::DeleteCell`
@ -907,9 +900,9 @@ impl Node {
let element = match index {
index if index < -1 => return Err(Error::IndexSize),
-1 => {
let last_child = NodeCast::from_ref(self).GetLastChild();
let last_child = self.upcast::<Node>().GetLastChild();
match last_child.and_then(|node| node.inclusively_preceding_siblings()
.filter_map(ElementCast::to_root)
.filter_map(Root::downcast::<Element>)
.filter(|elem| is_delete_type(elem))
.next()) {
Some(element) => element,
@ -922,7 +915,7 @@ impl Node {
},
};
NodeCast::from_ref(element.r()).remove_self();
element.upcast::<Node>().remove_self();
Ok(())
}
}
@ -994,7 +987,7 @@ impl LayoutNodeHelpers for LayoutJS<Node> {
#[inline]
#[allow(unsafe_code)]
unsafe fn is_element_for_layout(&self) -> bool {
(*self.unsafe_get()).is_element()
(*self.unsafe_get()).is::<Element>()
}
#[inline]
@ -1300,7 +1293,7 @@ pub enum CloneChildrenFlag {
fn as_uintptr<T>(t: &T) -> uintptr_t { t as *const T as uintptr_t }
impl Node {
pub fn reflect_node<N: Reflectable + NodeBase>
pub fn reflect_node<N: DerivedFrom<Node> + Reflectable>
(node: Box<N>,
document: &Document,
wrap_fn: extern "Rust" fn(*mut JSContext, GlobalRef, Box<N>) -> Root<N>)
@ -1384,12 +1377,12 @@ impl Node {
// Step 4-5.
match node.type_id() {
NodeTypeId::CharacterData(CharacterDataTypeId::Text) => {
if parent.is_document() {
if parent.is::<Document>() {
return Err(Error::HierarchyRequest);
}
},
NodeTypeId::DocumentType => {
if !parent.is_document() {
if !parent.is::<Document>() {
return Err(Error::HierarchyRequest);
}
},
@ -1407,7 +1400,7 @@ impl Node {
NodeTypeId::DocumentFragment => {
// Step 6.1.1(b)
if node.children()
.any(|c| c.r().is_text())
.any(|c| c.r().is::<Text>())
{
return Err(Error::HierarchyRequest);
}
@ -1452,7 +1445,7 @@ impl Node {
Some(child) => {
if parent.children()
.take_while(|c| c.r() != child)
.any(|c| c.r().is_element())
.any(|c| c.r().is::<Element>())
{
return Err(Error::HierarchyRequest);
}
@ -1626,23 +1619,23 @@ impl Node {
// XXXabinader: clone() for each node as trait?
let copy: Root<Node> = match node.type_id() {
NodeTypeId::DocumentType => {
let doctype: &DocumentType = DocumentTypeCast::to_ref(node).unwrap();
let doctype: &DocumentType = node.downcast::<DocumentType>().unwrap();
let doctype = DocumentType::new(doctype.name().clone(),
Some(doctype.public_id().clone()),
Some(doctype.system_id().clone()), document.r());
NodeCast::from_root(doctype)
Root::upcast::<Node>(doctype)
},
NodeTypeId::DocumentFragment => {
let doc_fragment = DocumentFragment::new(document.r());
NodeCast::from_root(doc_fragment)
Root::upcast::<Node>(doc_fragment)
},
NodeTypeId::CharacterData(CharacterDataTypeId::Comment) => {
let cdata = CharacterDataCast::to_ref(node).unwrap();
let cdata = node.downcast::<CharacterData>().unwrap();
let comment = Comment::new(cdata.Data(), document.r());
NodeCast::from_root(comment)
Root::upcast::<Node>(comment)
},
NodeTypeId::Document => {
let document = DocumentCast::to_ref(node).unwrap();
let document = node.downcast::<Document>().unwrap();
let is_html_doc = match document.is_html_document() {
true => IsHTMLDocument::HTMLDocument,
false => IsHTMLDocument::NonHTMLDocument,
@ -1652,10 +1645,10 @@ impl Node {
let document = Document::new(window, Some((*document.url()).clone()),
is_html_doc, None,
None, DocumentSource::NotFromParser, loader);
NodeCast::from_root(document)
Root::upcast::<Node>(document)
},
NodeTypeId::Element(..) => {
let element = ElementCast::to_ref(node).unwrap();
let element = node.downcast::<Element>().unwrap();
let name = QualName {
ns: element.namespace().clone(),
local: element.local_name().clone()
@ -1663,23 +1656,23 @@ impl Node {
let element = Element::create(name,
element.prefix().as_ref().map(|p| Atom::from_slice(&p)),
document.r(), ElementCreator::ScriptCreated);
NodeCast::from_root(element)
Root::upcast::<Node>(element)
},
NodeTypeId::CharacterData(CharacterDataTypeId::Text) => {
let cdata = CharacterDataCast::to_ref(node).unwrap();
let cdata = node.downcast::<CharacterData>().unwrap();
let text = Text::new(cdata.Data(), document.r());
NodeCast::from_root(text)
Root::upcast::<Node>(text)
},
NodeTypeId::CharacterData(CharacterDataTypeId::ProcessingInstruction) => {
let pi = ProcessingInstructionCast::to_ref(node).unwrap();
let pi = node.downcast::<ProcessingInstruction>().unwrap();
let pi = ProcessingInstruction::new(pi.Target(),
CharacterDataCast::from_ref(pi).Data(), document.r());
NodeCast::from_root(pi)
pi.upcast::<CharacterData>().Data(), document.r());
Root::upcast::<Node>(pi)
},
};
// Step 3.
let document = match DocumentCast::to_ref(copy.r()) {
let document = match copy.downcast::<Document>() {
Some(doc) => Root::from_ref(doc),
None => Root::from_ref(document.r()),
};
@ -1688,14 +1681,14 @@ impl Node {
// Step 4 (some data already copied in step 2).
match node.type_id() {
NodeTypeId::Document => {
let node_doc = DocumentCast::to_ref(node).unwrap();
let copy_doc = DocumentCast::to_ref(copy.r()).unwrap();
let node_doc = node.downcast::<Document>().unwrap();
let copy_doc = copy.downcast::<Document>().unwrap();
copy_doc.set_encoding_name(node_doc.encoding_name().clone());
copy_doc.set_quirks_mode(node_doc.quirks_mode());
},
NodeTypeId::Element(..) => {
let node_elem = ElementCast::to_ref(node).unwrap();
let copy_elem = ElementCast::to_ref(copy.r()).unwrap();
let node_elem = node.downcast::<Element>().unwrap();
let copy_elem = copy.downcast::<Element>().unwrap();
for attr in node_elem.attrs().iter().map(JS::root) {
copy_elem.push_new_attribute(attr.local_name().clone(),
@ -1727,9 +1720,9 @@ impl Node {
pub fn collect_text_contents<T: Iterator<Item=Root<Node>>>(iterator: T) -> String {
let mut content = String::new();
for node in iterator {
let text = TextCast::to_ref(node.r());
let text = node.downcast::<Text>();
match text {
Some(text) => content.push_str(&CharacterDataCast::from_ref(text).Data()),
Some(text) => content.push_str(&text.upcast::<CharacterData>().Data()),
None => (),
}
}
@ -1759,7 +1752,7 @@ impl Node {
match node.type_id() {
NodeTypeId::Element(_) => {
let element = ElementCast::to_ref(node).unwrap();
let element = node.downcast::<Element>().unwrap();
// Step 1.
if *element.namespace() != ns!("") && *element.prefix() == prefix {
return element.namespace().clone()
@ -1785,16 +1778,16 @@ impl Node {
// Step 3.
None => ns!(""),
// Step 4.
Some(parent) => Node::locate_namespace(NodeCast::from_ref(parent.r()), prefix)
Some(parent) => Node::locate_namespace(parent.upcast::<Node>(), prefix)
}
},
NodeTypeId::Document => {
match DocumentCast::to_ref(node).unwrap().GetDocumentElement().r() {
match node.downcast::<Document>().unwrap().GetDocumentElement().r() {
// Step 1.
None => ns!(""),
// Step 2.
Some(document_element) => {
Node::locate_namespace(NodeCast::from_ref(document_element), prefix)
Node::locate_namespace(document_element.upcast::<Node>(), prefix)
}
}
},
@ -1804,7 +1797,7 @@ impl Node {
// Step 1.
None => ns!(""),
// Step 2.
Some(parent) => Node::locate_namespace(NodeCast::from_ref(parent.r()), prefix)
Some(parent) => Node::locate_namespace(parent.upcast::<Node>(), prefix)
}
}
}
@ -1835,18 +1828,18 @@ impl NodeMethods for Node {
fn NodeName(&self) -> DOMString {
match self.type_id() {
NodeTypeId::Element(..) => {
let elem: &Element = ElementCast::to_ref(self).unwrap();
let elem: &Element = self.downcast::<Element>().unwrap();
elem.TagName()
}
NodeTypeId::CharacterData(CharacterDataTypeId::Text) => "#text".to_owned(),
NodeTypeId::CharacterData(CharacterDataTypeId::ProcessingInstruction) => {
let processing_instruction: &ProcessingInstruction =
ProcessingInstructionCast::to_ref(self).unwrap();
self.downcast::<ProcessingInstruction>().unwrap();
processing_instruction.Target()
}
NodeTypeId::CharacterData(CharacterDataTypeId::Comment) => "#comment".to_owned(),
NodeTypeId::DocumentType => {
let doctype: &DocumentType = DocumentTypeCast::to_ref(self).unwrap();
let doctype: &DocumentType = self.downcast::<DocumentType>().unwrap();
doctype.name().clone()
},
NodeTypeId::DocumentFragment => "#document-fragment".to_owned(),
@ -1877,7 +1870,7 @@ impl NodeMethods for Node {
// https://dom.spec.whatwg.org/#dom-node-parentelement
fn GetParentElement(&self) -> Option<Root<Element>> {
self.GetParentNode().and_then(ElementCast::to_root)
self.GetParentNode().and_then(Root::downcast::<Element>)
}
// https://dom.spec.whatwg.org/#dom-node-haschildnodes
@ -1918,7 +1911,7 @@ impl NodeMethods for Node {
fn GetNodeValue(&self) -> Option<DOMString> {
match self.type_id() {
NodeTypeId::CharacterData(..) => {
let chardata: &CharacterData = CharacterDataCast::to_ref(self).unwrap();
let chardata: &CharacterData = self.downcast::<CharacterData>().unwrap();
Some(chardata.Data())
}
_ => {
@ -1946,7 +1939,7 @@ impl NodeMethods for Node {
Some(content)
}
NodeTypeId::CharacterData(..) => {
let characterdata: &CharacterData = CharacterDataCast::to_ref(self).unwrap();
let characterdata: &CharacterData = self.downcast::<CharacterData>().unwrap();
Some(characterdata.Data())
}
NodeTypeId::DocumentType |
@ -1967,14 +1960,14 @@ impl NodeMethods for Node {
None
} else {
let document = self.owner_doc();
Some(NodeCast::from_root(document.r().CreateTextNode(value)))
Some(Root::upcast::<Node>(document.r().CreateTextNode(value)))
};
// Step 3.
Node::replace_all(node.r(), self);
}
NodeTypeId::CharacterData(..) => {
let characterdata: &CharacterData = CharacterDataCast::to_ref(self).unwrap();
let characterdata: &CharacterData = self.downcast::<CharacterData>().unwrap();
characterdata.SetData(value);
// Notify the document that the content of this node is different
@ -2019,21 +2012,21 @@ impl NodeMethods for Node {
// Step 4-5.
match node.type_id() {
NodeTypeId::CharacterData(CharacterDataTypeId::Text) if self.is_document() =>
NodeTypeId::CharacterData(CharacterDataTypeId::Text) if self.is::<Document>() =>
return Err(Error::HierarchyRequest),
NodeTypeId::DocumentType if !self.is_document() => return Err(Error::HierarchyRequest),
NodeTypeId::DocumentType if !self.is::<Document>() => return Err(Error::HierarchyRequest),
NodeTypeId::Document => return Err(Error::HierarchyRequest),
_ => ()
}
// Step 6.
if self.is_document() {
if self.is::<Document>() {
match node.type_id() {
// Step 6.1
NodeTypeId::DocumentFragment => {
// Step 6.1.1(b)
if node.children()
.any(|c| c.is_text())
.any(|c| c.is::<Text>())
{
return Err(Error::HierarchyRequest);
}
@ -2042,7 +2035,7 @@ impl NodeMethods for Node {
// Step 6.1.2
1 => {
if self.child_elements()
.any(|c| NodeCast::from_ref(c.r()) != child) {
.any(|c| c.upcast::<Node>() != child) {
return Err(Error::HierarchyRequest);
}
if child.following_siblings()
@ -2057,7 +2050,7 @@ impl NodeMethods for Node {
// Step 6.2
NodeTypeId::Element(..) => {
if self.child_elements()
.any(|c| NodeCast::from_ref(c.r()) != child) {
.any(|c| c.upcast::<Node>() != child) {
return Err(Error::HierarchyRequest);
}
if child.following_siblings()
@ -2076,7 +2069,7 @@ impl NodeMethods for Node {
}
if self.children()
.take_while(|c| c.r() != child)
.any(|c| c.is_element())
.any(|c| c.is::<Element>())
{
return Err(Error::HierarchyRequest);
}
@ -2142,16 +2135,16 @@ impl NodeMethods for Node {
fn Normalize(&self) {
let mut prev_text: Option<Root<Text>> = None;
for child in self.children() {
match TextCast::to_ref(child.r()) {
match child.downcast::<Text>() {
Some(text) => {
let characterdata: &CharacterData = CharacterDataCast::from_ref(text);
let characterdata: &CharacterData = text.upcast::<CharacterData>();
if characterdata.Length() == 0 {
Node::remove(&*child, self, SuppressObserver::Unsuppressed);
} else {
match prev_text {
Some(ref text_node) => {
let prev_characterdata =
CharacterDataCast::from_ref(text_node.r());
text_node.upcast::<CharacterData>();
prev_characterdata.append_data(&**characterdata.data());
Node::remove(&*child, self, SuppressObserver::Unsuppressed);
},
@ -2179,34 +2172,34 @@ impl NodeMethods for Node {
// https://dom.spec.whatwg.org/#dom-node-isequalnode
fn IsEqualNode(&self, maybe_node: Option<&Node>) -> bool {
fn is_equal_doctype(node: &Node, other: &Node) -> bool {
let doctype: &DocumentType = DocumentTypeCast::to_ref(node).unwrap();
let other_doctype: &DocumentType = DocumentTypeCast::to_ref(other).unwrap();
let doctype: &DocumentType = node.downcast::<DocumentType>().unwrap();
let other_doctype: &DocumentType = other.downcast::<DocumentType>().unwrap();
(*doctype.name() == *other_doctype.name()) &&
(*doctype.public_id() == *other_doctype.public_id()) &&
(*doctype.system_id() == *other_doctype.system_id())
}
fn is_equal_element(node: &Node, other: &Node) -> bool {
let element: &Element = ElementCast::to_ref(node).unwrap();
let other_element: &Element = ElementCast::to_ref(other).unwrap();
let element: &Element = node.downcast::<Element>().unwrap();
let other_element: &Element = other.downcast::<Element>().unwrap();
(*element.namespace() == *other_element.namespace()) &&
(*element.prefix() == *other_element.prefix()) &&
(*element.local_name() == *other_element.local_name()) &&
(element.attrs().len() == other_element.attrs().len())
}
fn is_equal_processinginstruction(node: &Node, other: &Node) -> bool {
let pi: &ProcessingInstruction = ProcessingInstructionCast::to_ref(node).unwrap();
let other_pi: &ProcessingInstruction = ProcessingInstructionCast::to_ref(other).unwrap();
let pi: &ProcessingInstruction = node.downcast::<ProcessingInstruction>().unwrap();
let other_pi: &ProcessingInstruction = other.downcast::<ProcessingInstruction>().unwrap();
(*pi.target() == *other_pi.target()) &&
(*CharacterDataCast::from_ref(pi).data() == *CharacterDataCast::from_ref(other_pi).data())
(*pi.upcast::<CharacterData>().data() == *other_pi.upcast::<CharacterData>().data())
}
fn is_equal_characterdata(node: &Node, other: &Node) -> bool {
let characterdata: &CharacterData = CharacterDataCast::to_ref(node).unwrap();
let other_characterdata: &CharacterData = CharacterDataCast::to_ref(other).unwrap();
let characterdata: &CharacterData = node.downcast::<CharacterData>().unwrap();
let other_characterdata: &CharacterData = other.downcast::<CharacterData>().unwrap();
*characterdata.data() == *other_characterdata.data()
}
fn is_equal_element_attrs(node: &Node, other: &Node) -> bool {
let element: &Element = ElementCast::to_ref(node).unwrap();
let other_element: &Element = ElementCast::to_ref(other).unwrap();
let element: &Element = node.downcast::<Element>().unwrap();
let other_element: &Element = other.downcast::<Element>().unwrap();
assert!(element.attrs().len() == other_element.attrs().len());
// FIXME(https://github.com/rust-lang/rust/issues/23338)
let attrs = element.attrs();
@ -2334,9 +2327,9 @@ impl NodeMethods for Node {
// Step 2.
match self.type_id() {
NodeTypeId::Element(..) => ElementCast::to_ref(self).unwrap().lookup_prefix(namespace),
NodeTypeId::Element(..) => self.downcast::<Element>().unwrap().lookup_prefix(namespace),
NodeTypeId::Document => {
DocumentCast::to_ref(self).unwrap().GetDocumentElement().and_then(|element| {
self.downcast::<Document>().unwrap().GetDocumentElement().and_then(|element| {
element.r().lookup_prefix(namespace)
})
},
@ -2382,19 +2375,19 @@ pub struct TrustedNodeAddress(pub *const c_void);
#[allow(unsafe_code)]
unsafe impl Send for TrustedNodeAddress {}
pub fn document_from_node<T: NodeBase + Reflectable>(derived: &T) -> Root<Document> {
let node: &Node = NodeCast::from_ref(derived);
pub fn document_from_node<T: DerivedFrom<Node> + Reflectable>(derived: &T) -> Root<Document> {
let node: &Node = derived.upcast::<Node>();
node.owner_doc()
}
pub fn window_from_node<T: NodeBase + Reflectable>(derived: &T) -> Root<Window> {
pub fn window_from_node<T: DerivedFrom<Node> + Reflectable>(derived: &T) -> Root<Window> {
let document = document_from_node(derived);
Root::from_ref(document.r().window())
}
impl VirtualMethods for Node {
fn super_type(&self) -> Option<&VirtualMethods> {
let eventtarget: &EventTarget = EventTargetCast::from_ref(self);
let eventtarget: &EventTarget = self.upcast::<EventTarget>();
Some(eventtarget as &VirtualMethods)
}