From 13ea3ac413c511872784ccde416956217746553c Mon Sep 17 00:00:00 2001 From: Anthony Ramine Date: Tue, 6 Oct 2015 17:21:44 +0200 Subject: 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 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::()/g s/\.is_htmlanchorelement\(\)/.is::()/g s/\.is_htmlappletelement\(\)/.is::()/g s/\.is_htmlareaelement\(\)/.is::()/g s/\.is_htmlbodyelement\(\)/.is::()/g s/\.is_htmlembedelement\(\)/.is::()/g s/\.is_htmlfieldsetelement\(\)/.is::()/g s/\.is_htmlformelement\(\)/.is::()/g s/\.is_htmlframesetelement\(\)/.is::()/g s/\.is_htmlhtmlelement\(\)/.is::()/g s/\.is_htmlimageelement\(\)/.is::()/g s/\.is_htmllegendelement\(\)/.is::()/g s/\.is_htmloptgroupelement\(\)/.is::()/g s/\.is_htmloptionelement\(\)/.is::()/g s/\.is_htmlscriptelement\(\)/.is::()/g s/\.is_htmltabledatacellelement\(\)/.is::()/g s/\.is_htmltableheadercellelement\(\)/.is::()/g s/\.is_htmltablerowelement\(\)/.is::()/g s/\.is_htmltablesectionelement\(\)/.is::()/g s/\.is_htmltitleelement\(\)/.is::()/g --- components/script/dom/htmlscriptelement.rs | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) (limited to 'components/script/dom/htmlscriptelement.rs') diff --git a/components/script/dom/htmlscriptelement.rs b/components/script/dom/htmlscriptelement.rs index 994105f50b8..7ae38f951bb 100644 --- a/components/script/dom/htmlscriptelement.rs +++ b/components/script/dom/htmlscriptelement.rs @@ -10,16 +10,16 @@ use dom::bindings::codegen::Bindings::DocumentBinding::DocumentMethods; use dom::bindings::codegen::Bindings::HTMLScriptElementBinding; use dom::bindings::codegen::Bindings::HTMLScriptElementBinding::HTMLScriptElementMethods; use dom::bindings::codegen::Bindings::NodeBinding::NodeMethods; -use dom::bindings::codegen::InheritTypes::{ElementCast, EventTargetCast, HTMLElementCast}; -use dom::bindings::codegen::InheritTypes::{HTMLScriptElementCast, NodeCast}; +use dom::bindings::conversions::Castable; use dom::bindings::global::GlobalRef; use dom::bindings::js::RootedReference; use dom::bindings::js::{JS, Root}; use dom::bindings::refcounted::Trusted; use dom::bindings::trace::JSTraceable; use dom::document::Document; -use dom::element::{AttributeMutation, ElementCreator}; +use dom::element::{AttributeMutation, Element, ElementCreator}; use dom::event::{Event, EventBubbles, EventCancelable}; +use dom::eventtarget::EventTarget; use dom::htmlelement::HTMLElement; use dom::node::{ChildrenMutation, CloneChildrenFlag, Node}; use dom::node::{document_from_node, window_from_node}; @@ -180,7 +180,7 @@ impl HTMLScriptElement { self.parser_inserted.set(false); // Step 3. - let element = ElementCast::from_ref(self); + let element = self.upcast::(); if was_parser_inserted && element.has_attribute(&atom!("async")) { self.non_blocking.set(true); } @@ -190,7 +190,7 @@ impl HTMLScriptElement { return NextParserState::Continue; } // Step 5. - let node = NodeCast::from_ref(self); + let node = self.upcast::(); if !node.is_in_doc() { return NextParserState::Continue; } @@ -454,7 +454,7 @@ impl HTMLScriptElement { } pub fn is_javascript(&self) -> bool { - let element = ElementCast::from_ref(self); + let element = self.upcast::(); let type_attr = element.get_attribute(&ns!(""), &atom!("type")); let is_js = match type_attr.as_ref().map(|s| s.value()) { Some(ref s) if s.is_empty() => { @@ -508,14 +508,14 @@ impl HTMLScriptElement { bubbles, cancelable); let event = event.r(); - let target = EventTargetCast::from_ref(self); + let target = self.upcast::(); event.fire(target) } } impl VirtualMethods for HTMLScriptElement { fn super_type(&self) -> Option<&VirtualMethods> { - let htmlelement: &HTMLElement = HTMLElementCast::from_ref(self); + let htmlelement: &HTMLElement = self.upcast::(); Some(htmlelement as &VirtualMethods) } @@ -524,7 +524,7 @@ impl VirtualMethods for HTMLScriptElement { match attr.local_name() { &atom!("src") => { if let AttributeMutation::Set(_) = mutation { - if !self.parser_inserted.get() && NodeCast::from_ref(self).is_in_doc() { + if !self.parser_inserted.get() && self.upcast::().is_in_doc() { self.prepare(); } } @@ -537,7 +537,7 @@ impl VirtualMethods for HTMLScriptElement { if let Some(ref s) = self.super_type() { s.children_changed(mutation); } - let node = NodeCast::from_ref(self); + let node = self.upcast::(); if !self.parser_inserted.get() && node.is_in_doc() { self.prepare(); } @@ -561,7 +561,7 @@ impl VirtualMethods for HTMLScriptElement { // https://html.spec.whatwg.org/multipage/#already-started if self.already_started.get() { - let copy_elem = HTMLScriptElementCast::to_ref(copy).unwrap(); + let copy_elem = copy.downcast::().unwrap(); copy_elem.mark_already_started(); } } @@ -575,12 +575,12 @@ impl HTMLScriptElementMethods for HTMLScriptElement { // https://html.spec.whatwg.org/multipage/#dom-script-text fn Text(&self) -> DOMString { - Node::collect_text_contents(NodeCast::from_ref(self).children()) + Node::collect_text_contents(self.upcast::().children()) } // https://html.spec.whatwg.org/multipage/#dom-script-text fn SetText(&self, value: DOMString) { - let node = NodeCast::from_ref(self); + let node = self.upcast::(); node.SetTextContent(Some(value)) } } -- cgit v1.2.3