mirror of
https://github.com/servo/servo.git
synced 2025-06-10 17:43:16 +00:00
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:
parent
bd363b009d
commit
13ea3ac413
82 changed files with 1124 additions and 1148 deletions
|
@ -23,9 +23,7 @@ use devtools_traits::{DevtoolScriptControlMsg, DevtoolsPageInfo};
|
|||
use document_loader::{DocumentLoader, LoadType, NotifierData};
|
||||
use dom::bindings::cell::DOMRefCell;
|
||||
use dom::bindings::codegen::Bindings::DocumentBinding::{DocumentMethods, DocumentReadyState};
|
||||
use dom::bindings::codegen::InheritTypes::{ElementCast, EventCast, EventTargetCast, NodeCast};
|
||||
use dom::bindings::conversions::FromJSValConvertible;
|
||||
use dom::bindings::conversions::StringificationBehavior;
|
||||
use dom::bindings::conversions::{Castable, FromJSValConvertible, StringificationBehavior};
|
||||
use dom::bindings::global::GlobalRef;
|
||||
use dom::bindings::js::{JS, RootCollection, trace_roots};
|
||||
use dom::bindings::js::{Root, RootCollectionPtr, RootedReference};
|
||||
|
@ -35,8 +33,9 @@ use dom::bindings::utils::{DOM_CALLBACKS, WRAP_CALLBACKS};
|
|||
use dom::document::{Document, DocumentProgressHandler, IsHTMLDocument};
|
||||
use dom::document::{DocumentProgressTask, DocumentSource, MouseEventType};
|
||||
use dom::element::Element;
|
||||
use dom::event::{EventBubbles, EventCancelable};
|
||||
use dom::node::{NodeDamage, window_from_node};
|
||||
use dom::event::{Event, EventBubbles, EventCancelable};
|
||||
use dom::eventtarget::EventTarget;
|
||||
use dom::node::{Node, NodeDamage, window_from_node};
|
||||
use dom::servohtmlparser::{ParserContext, ServoHTMLParser};
|
||||
use dom::uievent::UIEvent;
|
||||
use dom::window::{ReflowReason, ScriptHelpers, Window};
|
||||
|
@ -1256,12 +1255,12 @@ impl ScriptTask {
|
|||
let current_url = it_page.document().url().serialize();
|
||||
urls.push(current_url.clone());
|
||||
|
||||
for child in NodeCast::from_ref(&*it_page.document()).traverse_preorder() {
|
||||
let target = EventTargetCast::from_ref(&*child);
|
||||
for child in it_page.document().upcast::<Node>().traverse_preorder() {
|
||||
let target = child.upcast::<EventTarget>();
|
||||
dom_tree_size += heap_size_of_self_and_children(target);
|
||||
}
|
||||
let window = it_page.window();
|
||||
let target = EventTargetCast::from_ref(&*window);
|
||||
let target = window.upcast::<EventTarget>();
|
||||
dom_tree_size += heap_size_of_self_and_children(target);
|
||||
|
||||
reports.push(Report {
|
||||
|
@ -1324,7 +1323,7 @@ impl ScriptTask {
|
|||
let frame_element = doc.find_iframe(subpage_id);
|
||||
|
||||
if let Some(ref frame_element) = frame_element {
|
||||
let element = ElementCast::from_ref(frame_element.r());
|
||||
let element = frame_element.upcast::<Element>();
|
||||
doc.r().begin_focus_transaction();
|
||||
doc.r().request_focus(element);
|
||||
doc.r().commit_focus_transaction(FocusType::Parent);
|
||||
|
@ -1626,7 +1625,7 @@ impl ScriptTask {
|
|||
DocumentSource::FromParser,
|
||||
loader);
|
||||
|
||||
let frame_element = frame_element.r().map(ElementCast::from_ref);
|
||||
let frame_element = frame_element.r().map(Castable::upcast::<Element>);
|
||||
window.r().init_browsing_context(document.r(), frame_element);
|
||||
|
||||
// Create the root frame
|
||||
|
@ -1673,7 +1672,7 @@ impl ScriptTask {
|
|||
}
|
||||
|
||||
fn scroll_fragment_point(&self, pipeline_id: PipelineId, node: &Element) {
|
||||
let node = NodeCast::from_ref(node);
|
||||
let node = node.upcast::<Node>();
|
||||
let rect = node.get_bounding_content_box();
|
||||
let point = Point2D::new(rect.origin.x.to_f32_px(), rect.origin.y.to_f32_px());
|
||||
// FIXME(#2003, pcwalton): This is pretty bogus when multiple layers are involved.
|
||||
|
@ -1732,7 +1731,7 @@ impl ScriptTask {
|
|||
// Notify Constellation about anchors that are no longer mouse over targets.
|
||||
for target in &*prev_mouse_over_targets {
|
||||
if !mouse_over_targets.contains(target) {
|
||||
if NodeCast::from_ref(target.root().r()).is_anchor_element() {
|
||||
if target.upcast::<Node>().is_anchor_element() {
|
||||
let event = ConstellationMsg::NodeStatus(None);
|
||||
let ConstellationChan(ref chan) = self.constellation_chan;
|
||||
chan.send(event).unwrap();
|
||||
|
@ -1744,7 +1743,7 @@ impl ScriptTask {
|
|||
// Notify Constellation about the topmost anchor mouse over target.
|
||||
for target in &*mouse_over_targets {
|
||||
let target = target.root();
|
||||
if NodeCast::from_ref(target.r()).is_anchor_element() {
|
||||
if target.upcast::<Node>().is_anchor_element() {
|
||||
let status = target.r().get_attribute(&ns!(""), &atom!("href"))
|
||||
.and_then(|href| {
|
||||
let value = href.value();
|
||||
|
@ -1845,9 +1844,9 @@ impl ScriptTask {
|
|||
"resize".to_owned(), EventBubbles::DoesNotBubble,
|
||||
EventCancelable::NotCancelable, Some(window.r()),
|
||||
0i32);
|
||||
let event = EventCast::from_ref(uievent.r());
|
||||
let event = uievent.upcast::<Event>();
|
||||
|
||||
let wintarget = EventTargetCast::from_ref(window.r());
|
||||
let wintarget = window.upcast::<EventTarget>();
|
||||
event.fire(wintarget);
|
||||
}
|
||||
|
||||
|
@ -1906,7 +1905,7 @@ impl ScriptTask {
|
|||
// Kick off the initial reflow of the page.
|
||||
debug!("kicking off initial reflow of {:?}", final_url);
|
||||
document.r().disarm_reflow_timeout();
|
||||
document.r().content_changed(NodeCast::from_ref(document.r()),
|
||||
document.r().content_changed(document.upcast::<Node>(),
|
||||
NodeDamage::OtherNodeDamage);
|
||||
let window = window_from_node(document.r());
|
||||
window.r().reflow(ReflowGoal::ForDisplay, ReflowQueryType::NoQuery, ReflowReason::FirstLoad);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue