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

@ -7,7 +7,7 @@ use dom::bindings::codegen::Bindings::DOMImplementationBinding;
use dom::bindings::codegen::Bindings::DOMImplementationBinding::DOMImplementationMethods;
use dom::bindings::codegen::Bindings::DocumentBinding::DocumentMethods;
use dom::bindings::codegen::Bindings::NodeBinding::NodeMethods;
use dom::bindings::codegen::InheritTypes::NodeCast;
use dom::bindings::conversions::Castable;
use dom::bindings::error::Fallible;
use dom::bindings::global::GlobalRef;
use dom::bindings::js::{JS, Root};
@ -20,6 +20,7 @@ use dom::htmlbodyelement::HTMLBodyElement;
use dom::htmlheadelement::HTMLHeadElement;
use dom::htmlhtmlelement::HTMLHtmlElement;
use dom::htmltitleelement::HTMLTitleElement;
use dom::node::Node;
use dom::text::Text;
use std::borrow::ToOwned;
use util::str::DOMString;
@ -76,13 +77,13 @@ impl DOMImplementationMethods for DOMImplementation {
};
{
let doc_node = NodeCast::from_ref(doc.r());
let doc_node = doc.upcast::<Node>();
// Step 4.
match maybe_doctype {
None => (),
Some(ref doctype) => {
let doc_type = NodeCast::from_ref(*doctype);
let doc_type = doctype.upcast::<Node>();
assert!(doc_node.AppendChild(doc_type).is_ok())
}
}
@ -91,7 +92,7 @@ impl DOMImplementationMethods for DOMImplementation {
match maybe_elem {
None => (),
Some(ref elem) => {
assert!(doc_node.AppendChild(NodeCast::from_ref(elem.r())).is_ok())
assert!(doc_node.AppendChild(elem.upcast::<Node>()).is_ok())
}
}
}
@ -114,21 +115,21 @@ impl DOMImplementationMethods for DOMImplementation {
{
// Step 3.
let doc_node = NodeCast::from_ref(doc.r());
let doc_node = doc.upcast::<Node>();
let doc_type = DocumentType::new("html".to_owned(), None, None, doc.r());
assert!(doc_node.AppendChild(NodeCast::from_ref(doc_type.r())).is_ok());
assert!(doc_node.AppendChild(doc_type.upcast::<Node>()).is_ok());
}
{
// Step 4.
let doc_node = NodeCast::from_ref(doc.r());
let doc_html = NodeCast::from_root(
let doc_node = doc.upcast::<Node>();
let doc_html = Root::upcast::<Node>(
HTMLHtmlElement::new("html".to_owned(), None, doc.r()));
assert!(doc_node.AppendChild(doc_html.r()).is_ok());
{
// Step 5.
let doc_head = NodeCast::from_root(
let doc_head = Root::upcast::<Node>(
HTMLHeadElement::new("head".to_owned(), None, doc.r()));
assert!(doc_html.r().AppendChild(doc_head.r()).is_ok());
@ -137,20 +138,20 @@ impl DOMImplementationMethods for DOMImplementation {
None => (),
Some(title_str) => {
// Step 6.1.
let doc_title = NodeCast::from_root(
let doc_title = Root::upcast::<Node>(
HTMLTitleElement::new("title".to_owned(), None, doc.r()));
assert!(doc_head.r().AppendChild(doc_title.r()).is_ok());
// Step 6.2.
let title_text = Text::new(title_str, doc.r());
assert!(doc_title.r().AppendChild(NodeCast::from_ref(title_text.r())).is_ok());
assert!(doc_title.r().AppendChild(title_text.upcast::<Node>()).is_ok());
}
}
}
// Step 7.
let doc_body = HTMLBodyElement::new("body".to_owned(), None, doc.r());
assert!(doc_html.r().AppendChild(NodeCast::from_ref(doc_body.r())).is_ok());
assert!(doc_html.r().AppendChild(doc_body.upcast::<Node>()).is_ok());
}
// Step 8.