mirror of
https://github.com/servo/servo.git
synced 2025-06-08 16:43:28 +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
|
@ -40,20 +40,18 @@ use ipc_channel::ipc::IpcSender;
|
||||||
use msg::constellation_msg::PipelineId;
|
use msg::constellation_msg::PipelineId;
|
||||||
use opaque_node::OpaqueNodeMethods;
|
use opaque_node::OpaqueNodeMethods;
|
||||||
use script::dom::attr::AttrValue;
|
use script::dom::attr::AttrValue;
|
||||||
use script::dom::bindings::codegen::InheritTypes::{CharacterDataCast, CharacterDataTypeId};
|
use script::dom::bindings::codegen::InheritTypes::{CharacterDataTypeId, ElementTypeId};
|
||||||
use script::dom::bindings::codegen::InheritTypes::{ElementCast, ElementTypeId};
|
use script::dom::bindings::codegen::InheritTypes::{HTMLElementTypeId, NodeTypeId};
|
||||||
use script::dom::bindings::codegen::InheritTypes::{HTMLCanvasElementCast, HTMLElementTypeId};
|
use script::dom::bindings::conversions::Castable;
|
||||||
use script::dom::bindings::codegen::InheritTypes::{HTMLIFrameElementCast, HTMLImageElementCast};
|
|
||||||
use script::dom::bindings::codegen::InheritTypes::{HTMLInputElementCast, HTMLTextAreaElementCast};
|
|
||||||
use script::dom::bindings::codegen::InheritTypes::{NodeCast, NodeTypeId, TextCast};
|
|
||||||
use script::dom::bindings::js::LayoutJS;
|
use script::dom::bindings::js::LayoutJS;
|
||||||
use script::dom::characterdata::LayoutCharacterDataHelpers;
|
use script::dom::characterdata::{CharacterData, LayoutCharacterDataHelpers};
|
||||||
use script::dom::element;
|
use script::dom::element;
|
||||||
use script::dom::element::{Element, LayoutElementHelpers, RawLayoutElementHelpers};
|
use script::dom::element::{Element, LayoutElementHelpers, RawLayoutElementHelpers};
|
||||||
use script::dom::htmlcanvaselement::LayoutHTMLCanvasElementHelpers;
|
use script::dom::htmlcanvaselement::{HTMLCanvasElement, LayoutHTMLCanvasElementHelpers};
|
||||||
use script::dom::htmlimageelement::LayoutHTMLImageElementHelpers;
|
use script::dom::htmliframeelement::HTMLIFrameElement;
|
||||||
use script::dom::htmlinputelement::LayoutHTMLInputElementHelpers;
|
use script::dom::htmlimageelement::{HTMLImageElement, LayoutHTMLImageElementHelpers};
|
||||||
use script::dom::htmltextareaelement::LayoutHTMLTextAreaElementHelpers;
|
use script::dom::htmlinputelement::{HTMLInputElement, LayoutHTMLInputElementHelpers};
|
||||||
|
use script::dom::htmltextareaelement::{HTMLTextAreaElement, LayoutHTMLTextAreaElementHelpers};
|
||||||
use script::dom::node::{HAS_CHANGED, HAS_DIRTY_DESCENDANTS, HAS_DIRTY_SIBLINGS, IS_DIRTY};
|
use script::dom::node::{HAS_CHANGED, HAS_DIRTY_DESCENDANTS, HAS_DIRTY_SIBLINGS, IS_DIRTY};
|
||||||
use script::dom::node::{LayoutNodeHelpers, Node, SharedLayoutData};
|
use script::dom::node::{LayoutNodeHelpers, Node, SharedLayoutData};
|
||||||
use script::dom::text::Text;
|
use script::dom::text::Text;
|
||||||
|
@ -360,14 +358,14 @@ impl<'le> LayoutElement<'le> {
|
||||||
|
|
||||||
pub fn as_node(&self) -> LayoutNode<'le> {
|
pub fn as_node(&self) -> LayoutNode<'le> {
|
||||||
LayoutNode {
|
LayoutNode {
|
||||||
node: NodeCast::from_layout_js(&self.element),
|
node: self.element.upcast::<Node>(),
|
||||||
chain: PhantomData,
|
chain: PhantomData,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn as_element<'le>(node: LayoutJS<Node>) -> Option<LayoutElement<'le>> {
|
fn as_element<'le>(node: LayoutJS<Node>) -> Option<LayoutElement<'le>> {
|
||||||
ElementCast::to_layout_js(&node).map(|element| {
|
node.downcast().map(|element| {
|
||||||
LayoutElement {
|
LayoutElement {
|
||||||
element: element,
|
element: element,
|
||||||
chain: PhantomData,
|
chain: PhantomData,
|
||||||
|
@ -379,7 +377,7 @@ fn as_element<'le>(node: LayoutJS<Node>) -> Option<LayoutElement<'le>> {
|
||||||
impl<'le> ::selectors::Element for LayoutElement<'le> {
|
impl<'le> ::selectors::Element for LayoutElement<'le> {
|
||||||
fn parent_element(&self) -> Option<LayoutElement<'le>> {
|
fn parent_element(&self) -> Option<LayoutElement<'le>> {
|
||||||
unsafe {
|
unsafe {
|
||||||
NodeCast::from_layout_js(&self.element).parent_node_ref().and_then(as_element)
|
self.element.upcast::<Node>().parent_node_ref().and_then(as_element)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -424,7 +422,7 @@ impl<'le> ::selectors::Element for LayoutElement<'le> {
|
||||||
self.as_node().children().all(|node| match node.type_id() {
|
self.as_node().children().all(|node| match node.type_id() {
|
||||||
NodeTypeId::Element(..) => false,
|
NodeTypeId::Element(..) => false,
|
||||||
NodeTypeId::CharacterData(CharacterDataTypeId::Text) => unsafe {
|
NodeTypeId::CharacterData(CharacterDataTypeId::Text) => unsafe {
|
||||||
CharacterDataCast::to_layout_js(&node.node).unwrap().data_for_layout().is_empty()
|
node.node.downcast::<CharacterData>().unwrap().data_for_layout().is_empty()
|
||||||
},
|
},
|
||||||
_ => true
|
_ => true
|
||||||
})
|
})
|
||||||
|
@ -697,7 +695,7 @@ impl<'ln> ThreadSafeLayoutNode<'ln> {
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn as_element(&self) -> ThreadSafeLayoutElement<'ln> {
|
pub fn as_element(&self) -> ThreadSafeLayoutElement<'ln> {
|
||||||
unsafe {
|
unsafe {
|
||||||
let element = match ElementCast::to_layout_js(self.get_jsmanaged()) {
|
let element = match self.get_jsmanaged().downcast::<Element>() {
|
||||||
Some(e) => e.unsafe_get(),
|
Some(e) => e.unsafe_get(),
|
||||||
None => panic!("not an element")
|
None => panic!("not an element")
|
||||||
};
|
};
|
||||||
|
@ -788,12 +786,12 @@ impl<'ln> ThreadSafeLayoutNode<'ln> {
|
||||||
|
|
||||||
pub fn is_ignorable_whitespace(&self) -> bool {
|
pub fn is_ignorable_whitespace(&self) -> bool {
|
||||||
unsafe {
|
unsafe {
|
||||||
let text: LayoutJS<Text> = match TextCast::to_layout_js(self.get_jsmanaged()) {
|
let text: LayoutJS<Text> = match self.get_jsmanaged().downcast::<Text>() {
|
||||||
Some(text) => text,
|
Some(text) => text,
|
||||||
None => return false
|
None => return false
|
||||||
};
|
};
|
||||||
|
|
||||||
if !is_whitespace(CharacterDataCast::from_layout_js(&text).data_for_layout()) {
|
if !is_whitespace(text.upcast::<CharacterData>().data_for_layout()) {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -816,7 +814,7 @@ impl<'ln> ThreadSafeLayoutNode<'ln> {
|
||||||
pub fn get_unsigned_integer_attribute(self, attribute: UnsignedIntegerAttribute)
|
pub fn get_unsigned_integer_attribute(self, attribute: UnsignedIntegerAttribute)
|
||||||
-> Option<u32> {
|
-> Option<u32> {
|
||||||
unsafe {
|
unsafe {
|
||||||
let elem: Option<LayoutJS<Element>> = ElementCast::to_layout_js(self.get_jsmanaged());
|
let elem: Option<LayoutJS<Element>> = self.get_jsmanaged().downcast::<Element>();
|
||||||
match elem {
|
match elem {
|
||||||
Some(element) => {
|
Some(element) => {
|
||||||
element.get_unsigned_integer_attribute_for_layout(attribute)
|
element.get_unsigned_integer_attribute_for_layout(attribute)
|
||||||
|
@ -902,19 +900,19 @@ impl<'ln> ThreadSafeLayoutNode<'ln> {
|
||||||
}
|
}
|
||||||
|
|
||||||
let this = unsafe { self.get_jsmanaged() };
|
let this = unsafe { self.get_jsmanaged() };
|
||||||
let text = TextCast::to_layout_js(this);
|
let text = this.downcast::<Text>();
|
||||||
if let Some(text) = text {
|
if let Some(text) = text {
|
||||||
let data = unsafe {
|
let data = unsafe {
|
||||||
CharacterDataCast::from_layout_js(&text).data_for_layout().to_owned()
|
text.upcast::<CharacterData>().data_for_layout().to_owned()
|
||||||
};
|
};
|
||||||
return TextContent::Text(data);
|
return TextContent::Text(data);
|
||||||
}
|
}
|
||||||
let input = HTMLInputElementCast::to_layout_js(this);
|
let input = this.downcast::<HTMLInputElement>();
|
||||||
if let Some(input) = input {
|
if let Some(input) = input {
|
||||||
let data = unsafe { input.get_value_for_layout() };
|
let data = unsafe { input.get_value_for_layout() };
|
||||||
return TextContent::Text(data);
|
return TextContent::Text(data);
|
||||||
}
|
}
|
||||||
let area = HTMLTextAreaElementCast::to_layout_js(this);
|
let area = this.downcast::<HTMLTextAreaElement>();
|
||||||
if let Some(area) = area {
|
if let Some(area) = area {
|
||||||
let data = unsafe { area.get_value_for_layout() };
|
let data = unsafe { area.get_value_for_layout() };
|
||||||
return TextContent::Text(data);
|
return TextContent::Text(data);
|
||||||
|
@ -928,7 +926,7 @@ impl<'ln> ThreadSafeLayoutNode<'ln> {
|
||||||
let this = unsafe {
|
let this = unsafe {
|
||||||
self.get_jsmanaged()
|
self.get_jsmanaged()
|
||||||
};
|
};
|
||||||
let input = HTMLInputElementCast::to_layout_js(this);
|
let input = this.downcast::<HTMLInputElement>();
|
||||||
if let Some(input) = input {
|
if let Some(input) = input {
|
||||||
let insertion_point = unsafe {
|
let insertion_point = unsafe {
|
||||||
input.get_insertion_point_for_layout()
|
input.get_insertion_point_for_layout()
|
||||||
|
@ -956,7 +954,7 @@ impl<'ln> ThreadSafeLayoutNode<'ln> {
|
||||||
/// FIXME(pcwalton): Don't copy URLs.
|
/// FIXME(pcwalton): Don't copy URLs.
|
||||||
pub fn image_url(&self) -> Option<Url> {
|
pub fn image_url(&self) -> Option<Url> {
|
||||||
unsafe {
|
unsafe {
|
||||||
HTMLImageElementCast::to_layout_js(self.get_jsmanaged())
|
self.get_jsmanaged().downcast::<HTMLImageElement>()
|
||||||
.expect("not an image!")
|
.expect("not an image!")
|
||||||
.image_url()
|
.image_url()
|
||||||
}
|
}
|
||||||
|
@ -964,28 +962,28 @@ impl<'ln> ThreadSafeLayoutNode<'ln> {
|
||||||
|
|
||||||
pub fn canvas_renderer_id(&self) -> Option<usize> {
|
pub fn canvas_renderer_id(&self) -> Option<usize> {
|
||||||
unsafe {
|
unsafe {
|
||||||
let canvas_element = HTMLCanvasElementCast::to_layout_js(self.get_jsmanaged());
|
let canvas_element = self.get_jsmanaged().downcast::<HTMLCanvasElement>();
|
||||||
canvas_element.and_then(|elem| elem.get_renderer_id())
|
canvas_element.and_then(|elem| elem.get_renderer_id())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn canvas_ipc_renderer(&self) -> Option<IpcSender<CanvasMsg>> {
|
pub fn canvas_ipc_renderer(&self) -> Option<IpcSender<CanvasMsg>> {
|
||||||
unsafe {
|
unsafe {
|
||||||
let canvas_element = HTMLCanvasElementCast::to_layout_js(self.get_jsmanaged());
|
let canvas_element = self.get_jsmanaged().downcast::<HTMLCanvasElement>();
|
||||||
canvas_element.and_then(|elem| elem.get_ipc_renderer())
|
canvas_element.and_then(|elem| elem.get_ipc_renderer())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn canvas_width(&self) -> u32 {
|
pub fn canvas_width(&self) -> u32 {
|
||||||
unsafe {
|
unsafe {
|
||||||
let canvas_element = HTMLCanvasElementCast::to_layout_js(self.get_jsmanaged());
|
let canvas_element = self.get_jsmanaged().downcast::<HTMLCanvasElement>();
|
||||||
canvas_element.unwrap().get_canvas_width()
|
canvas_element.unwrap().get_canvas_width()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn canvas_height(&self) -> u32 {
|
pub fn canvas_height(&self) -> u32 {
|
||||||
unsafe {
|
unsafe {
|
||||||
let canvas_element = HTMLCanvasElementCast::to_layout_js(self.get_jsmanaged());
|
let canvas_element = self.get_jsmanaged().downcast::<HTMLCanvasElement>();
|
||||||
canvas_element.unwrap().get_canvas_height()
|
canvas_element.unwrap().get_canvas_height()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -995,7 +993,7 @@ impl<'ln> ThreadSafeLayoutNode<'ln> {
|
||||||
pub fn iframe_pipeline_id(&self) -> PipelineId {
|
pub fn iframe_pipeline_id(&self) -> PipelineId {
|
||||||
use script::dom::htmliframeelement::HTMLIFrameElementLayoutMethods;
|
use script::dom::htmliframeelement::HTMLIFrameElementLayoutMethods;
|
||||||
unsafe {
|
unsafe {
|
||||||
let iframe_element = HTMLIFrameElementCast::to_layout_js(self.get_jsmanaged())
|
let iframe_element = self.get_jsmanaged().downcast::<HTMLIFrameElement>()
|
||||||
.expect("not an iframe element!");
|
.expect("not an iframe element!");
|
||||||
iframe_element.pipeline_id().unwrap()
|
iframe_element.pipeline_id().unwrap()
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,11 +8,10 @@ use devtools_traits::{EvaluateJSReply, Modification, NodeInfo, TimelineMarker, T
|
||||||
use dom::bindings::codegen::Bindings::DOMRectBinding::{DOMRectMethods};
|
use dom::bindings::codegen::Bindings::DOMRectBinding::{DOMRectMethods};
|
||||||
use dom::bindings::codegen::Bindings::DocumentBinding::DocumentMethods;
|
use dom::bindings::codegen::Bindings::DocumentBinding::DocumentMethods;
|
||||||
use dom::bindings::codegen::Bindings::ElementBinding::{ElementMethods};
|
use dom::bindings::codegen::Bindings::ElementBinding::{ElementMethods};
|
||||||
use dom::bindings::codegen::InheritTypes::{ElementCast, NodeCast};
|
use dom::bindings::conversions::{Castable, FromJSValConvertible, jsstring_to_str};
|
||||||
use dom::bindings::conversions::FromJSValConvertible;
|
|
||||||
use dom::bindings::conversions::jsstring_to_str;
|
|
||||||
use dom::bindings::global::GlobalRef;
|
use dom::bindings::global::GlobalRef;
|
||||||
use dom::bindings::js::Root;
|
use dom::bindings::js::Root;
|
||||||
|
use dom::element::Element;
|
||||||
use dom::node::Node;
|
use dom::node::Node;
|
||||||
use ipc_channel::ipc::IpcSender;
|
use ipc_channel::ipc::IpcSender;
|
||||||
use js::jsapi::{ObjectClassName, RootedObject, RootedValue};
|
use js::jsapi::{ObjectClassName, RootedObject, RootedValue};
|
||||||
|
@ -60,7 +59,7 @@ pub fn handle_get_root_node(page: &Rc<Page>, pipeline: PipelineId, reply: IpcSen
|
||||||
let page = get_page(&*page, pipeline);
|
let page = get_page(&*page, pipeline);
|
||||||
let document = page.document();
|
let document = page.document();
|
||||||
|
|
||||||
let node = NodeCast::from_ref(document.r());
|
let node = document.upcast::<Node>();
|
||||||
reply.send(node.summarize()).unwrap();
|
reply.send(node.summarize()).unwrap();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -69,14 +68,14 @@ pub fn handle_get_document_element(page: &Rc<Page>, pipeline: PipelineId, reply:
|
||||||
let document = page.document();
|
let document = page.document();
|
||||||
let document_element = document.r().GetDocumentElement().unwrap();
|
let document_element = document.r().GetDocumentElement().unwrap();
|
||||||
|
|
||||||
let node = NodeCast::from_ref(document_element.r());
|
let node = document_element.upcast::<Node>();
|
||||||
reply.send(node.summarize()).unwrap();
|
reply.send(node.summarize()).unwrap();
|
||||||
}
|
}
|
||||||
|
|
||||||
fn find_node_by_unique_id(page: &Rc<Page>, pipeline: PipelineId, node_id: String) -> Root<Node> {
|
fn find_node_by_unique_id(page: &Rc<Page>, pipeline: PipelineId, node_id: String) -> Root<Node> {
|
||||||
let page = get_page(&*page, pipeline);
|
let page = get_page(&*page, pipeline);
|
||||||
let document = page.document();
|
let document = page.document();
|
||||||
let node = NodeCast::from_ref(document.r());
|
let node = document.upcast::<Node>();
|
||||||
|
|
||||||
for candidate in node.traverse_preorder() {
|
for candidate in node.traverse_preorder() {
|
||||||
if candidate.r().get_unique_id() == node_id {
|
if candidate.r().get_unique_id() == node_id {
|
||||||
|
@ -100,7 +99,7 @@ pub fn handle_get_layout(page: &Rc<Page>,
|
||||||
node_id: String,
|
node_id: String,
|
||||||
reply: IpcSender<ComputedNodeLayout>) {
|
reply: IpcSender<ComputedNodeLayout>) {
|
||||||
let node = find_node_by_unique_id(&*page, pipeline, node_id);
|
let node = find_node_by_unique_id(&*page, pipeline, node_id);
|
||||||
let elem = ElementCast::to_ref(node.r()).expect("should be getting layout of element");
|
let elem = node.downcast::<Element>().expect("should be getting layout of element");
|
||||||
let rect = elem.GetBoundingClientRect();
|
let rect = elem.GetBoundingClientRect();
|
||||||
let width = rect.Width() as f32;
|
let width = rect.Width() as f32;
|
||||||
let height = rect.Height() as f32;
|
let height = rect.Height() as f32;
|
||||||
|
@ -154,7 +153,7 @@ pub fn handle_modify_attribute(page: &Rc<Page>,
|
||||||
node_id: String,
|
node_id: String,
|
||||||
modifications: Vec<Modification>) {
|
modifications: Vec<Modification>) {
|
||||||
let node = find_node_by_unique_id(&*page, pipeline, node_id);
|
let node = find_node_by_unique_id(&*page, pipeline, node_id);
|
||||||
let elem = ElementCast::to_ref(node.r()).expect("should be getting layout of element");
|
let elem = node.downcast::<Element>().expect("should be getting layout of element");
|
||||||
|
|
||||||
for modification in &modifications {
|
for modification in &modifications {
|
||||||
match modification.newValue {
|
match modification.newValue {
|
||||||
|
|
|
@ -3,7 +3,7 @@
|
||||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||||
|
|
||||||
use dom::bindings::codegen::Bindings::EventBinding::EventMethods;
|
use dom::bindings::codegen::Bindings::EventBinding::EventMethods;
|
||||||
use dom::bindings::codegen::InheritTypes::{EventCast, EventTargetCast};
|
use dom::bindings::conversions::Castable;
|
||||||
use dom::element::Element;
|
use dom::element::Element;
|
||||||
use dom::event::{Event, EventBubbles, EventCancelable};
|
use dom::event::{Event, EventBubbles, EventCancelable};
|
||||||
use dom::eventtarget::EventTarget;
|
use dom::eventtarget::EventTarget;
|
||||||
|
@ -45,12 +45,12 @@ pub trait Activatable {
|
||||||
// Step 4
|
// Step 4
|
||||||
// https://html.spec.whatwg.org/multipage/#fire-a-synthetic-mouse-event
|
// https://html.spec.whatwg.org/multipage/#fire-a-synthetic-mouse-event
|
||||||
let win = window_from_node(element);
|
let win = window_from_node(element);
|
||||||
let target = EventTargetCast::from_ref(element);
|
let target = element.upcast::<EventTarget>();
|
||||||
let mouse = MouseEvent::new(win.r(), "click".to_owned(),
|
let mouse = MouseEvent::new(win.r(), "click".to_owned(),
|
||||||
EventBubbles::DoesNotBubble, EventCancelable::NotCancelable, Some(win.r()), 1,
|
EventBubbles::DoesNotBubble, EventCancelable::NotCancelable, Some(win.r()), 1,
|
||||||
0, 0, 0, 0, ctrlKey, shiftKey, altKey, metaKey,
|
0, 0, 0, 0, ctrlKey, shiftKey, altKey, metaKey,
|
||||||
0, None);
|
0, None);
|
||||||
let event = EventCast::from_ref(mouse.r());
|
let event = mouse.upcast::<Event>();
|
||||||
event.fire(target);
|
event.fire(target);
|
||||||
|
|
||||||
// Step 5
|
// Step 5
|
||||||
|
|
|
@ -6,12 +6,13 @@ use cssparser::RGBA;
|
||||||
use devtools_traits::AttrInfo;
|
use devtools_traits::AttrInfo;
|
||||||
use dom::bindings::cell::DOMRefCell;
|
use dom::bindings::cell::DOMRefCell;
|
||||||
use dom::bindings::codegen::Bindings::AttrBinding::{self, AttrMethods};
|
use dom::bindings::codegen::Bindings::AttrBinding::{self, AttrMethods};
|
||||||
use dom::bindings::codegen::InheritTypes::NodeCast;
|
use dom::bindings::conversions::Castable;
|
||||||
use dom::bindings::global::GlobalRef;
|
use dom::bindings::global::GlobalRef;
|
||||||
use dom::bindings::js::{JS, MutNullableHeap};
|
use dom::bindings::js::{JS, MutNullableHeap};
|
||||||
use dom::bindings::js::{LayoutJS, Root, RootedReference};
|
use dom::bindings::js::{LayoutJS, Root, RootedReference};
|
||||||
use dom::bindings::utils::{Reflector, reflect_dom_object};
|
use dom::bindings::utils::{Reflector, reflect_dom_object};
|
||||||
use dom::element::{AttributeMutation, Element};
|
use dom::element::{AttributeMutation, Element};
|
||||||
|
use dom::node::Node;
|
||||||
use dom::values::UNSIGNED_LONG_MAX;
|
use dom::values::UNSIGNED_LONG_MAX;
|
||||||
use dom::virtualmethods::vtable_for;
|
use dom::virtualmethods::vtable_for;
|
||||||
use dom::window::Window;
|
use dom::window::Window;
|
||||||
|
@ -287,7 +288,7 @@ impl Attr {
|
||||||
assert!(Some(owner) == self.owner().r());
|
assert!(Some(owner) == self.owner().r());
|
||||||
mem::swap(&mut *self.value.borrow_mut(), &mut value);
|
mem::swap(&mut *self.value.borrow_mut(), &mut value);
|
||||||
if self.namespace == ns!("") {
|
if self.namespace == ns!("") {
|
||||||
vtable_for(NodeCast::from_ref(owner)).attribute_mutated(
|
vtable_for(owner.upcast::<Node>()).attribute_mutated(
|
||||||
self, AttributeMutation::Set(Some(&value)));
|
self, AttributeMutation::Set(Some(&value)));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -5824,7 +5824,7 @@ class GlobalGenRoots():
|
||||||
|
|
||||||
descriptors = config.getDescriptors(register=True, isCallback=False)
|
descriptors = config.getDescriptors(register=True, isCallback=False)
|
||||||
imports = [CGGeneric("use dom::types::*;\n"),
|
imports = [CGGeneric("use dom::types::*;\n"),
|
||||||
CGGeneric("use dom::bindings::conversions::{IDLInterface, get_dom_class};\n"),
|
CGGeneric("use dom::bindings::conversions::{Castable, DerivedFrom, get_dom_class};\n"),
|
||||||
CGGeneric("use dom::bindings::js::{JS, LayoutJS, Root};\n"),
|
CGGeneric("use dom::bindings::js::{JS, LayoutJS, Root};\n"),
|
||||||
CGGeneric("use dom::bindings::trace::JSTraceable;\n"),
|
CGGeneric("use dom::bindings::trace::JSTraceable;\n"),
|
||||||
CGGeneric("use dom::bindings::utils::Reflectable;\n"),
|
CGGeneric("use dom::bindings::utils::Reflectable;\n"),
|
||||||
|
@ -5839,131 +5839,24 @@ class GlobalGenRoots():
|
||||||
upcast = descriptor.hasDescendants()
|
upcast = descriptor.hasDescendants()
|
||||||
downcast = len(chain) != 1
|
downcast = len(chain) != 1
|
||||||
|
|
||||||
if upcast or downcast:
|
|
||||||
# Define a dummy structure to hold the cast functions.
|
|
||||||
allprotos.append(CGGeneric("pub struct %sCast;\n\n" % name))
|
|
||||||
|
|
||||||
if upcast and not downcast:
|
if upcast and not downcast:
|
||||||
topTypes.append(name)
|
topTypes.append(name)
|
||||||
|
|
||||||
if upcast:
|
if not upcast:
|
||||||
# Define a `FooBase` trait for subclasses to implement, as well as the
|
# No other interface will implement DeriveFrom<Foo> for this Foo, so avoid
|
||||||
# `FooCast::from_*` methods that use it.
|
# implementing it for itself.
|
||||||
allprotos.append(CGGeneric("""\
|
chain = chain[:-1]
|
||||||
/// Types which are derived from `%(name)s` and can be freely converted
|
|
||||||
/// to `%(name)s`
|
|
||||||
pub trait %(baseTrait)s: Sized {}
|
|
||||||
|
|
||||||
impl %(name)sCast {
|
# Implement `DerivedFrom<Bar>` for `Foo`, for all `Bar` that `Foo` inherits from.
|
||||||
#[inline]
|
if chain:
|
||||||
/// Upcast an instance of a derived class of `%(name)s` to `%(name)s`
|
allprotos.append(CGGeneric("impl Castable for %s {}\n" % name))
|
||||||
pub fn from_ref<T: %(baseTrait)s + Reflectable>(derived: &T) -> &%(name)s {
|
|
||||||
unsafe { mem::transmute(derived) }
|
|
||||||
}
|
|
||||||
|
|
||||||
#[inline]
|
|
||||||
#[allow(unrooted_must_root)]
|
|
||||||
pub fn from_layout_js<T: %(baseTrait)s + Reflectable>(derived: &LayoutJS<T>) -> LayoutJS<%(name)s> {
|
|
||||||
unsafe { mem::transmute_copy(derived) }
|
|
||||||
}
|
|
||||||
|
|
||||||
#[inline]
|
|
||||||
pub fn from_root<T: %(baseTrait)s + Reflectable>(derived: Root<T>) -> Root<%(name)s> {
|
|
||||||
unsafe { mem::transmute(derived) }
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
""" % {'baseTrait': name + 'Base', 'name': name}))
|
|
||||||
else:
|
|
||||||
# The `FooBase` trait is not defined, so avoid implementing it by
|
|
||||||
# removing `Foo` itself from the chain.
|
|
||||||
chain = descriptor.prototypeChain[:-1]
|
|
||||||
|
|
||||||
# Implement `BarBase` for `Foo`, for all `Bar` that `Foo` inherits from.
|
|
||||||
for baseName in chain:
|
for baseName in chain:
|
||||||
allprotos.append(CGGeneric("impl %s for %s {}\n" % (baseName + 'Base', name)))
|
allprotos.append(CGGeneric("impl DerivedFrom<%s> for %s {}\n" % (baseName, name)))
|
||||||
if chain:
|
if chain:
|
||||||
allprotos.append(CGGeneric("\n"))
|
allprotos.append(CGGeneric("\n"))
|
||||||
|
|
||||||
if downcast:
|
if downcast:
|
||||||
hierarchy[descriptor.getParentName()].append(name)
|
hierarchy[descriptor.getParentName()].append(name)
|
||||||
# Define a `FooDerived` trait for superclasses to implement,
|
|
||||||
# as well as the `FooCast::to_*` methods that use it.
|
|
||||||
baseName = descriptor.prototypeChain[0]
|
|
||||||
args = {
|
|
||||||
'baseName': baseName,
|
|
||||||
'derivedTrait': name + 'Derived',
|
|
||||||
'methodName': 'is_' + name.lower(),
|
|
||||||
'name': name,
|
|
||||||
}
|
|
||||||
allprotos.append(CGGeneric("""\
|
|
||||||
/// Types which `%(name)s` derives from
|
|
||||||
pub trait %(derivedTrait)s: Sized {
|
|
||||||
fn %(methodName)s(&self) -> bool;
|
|
||||||
}
|
|
||||||
|
|
||||||
impl %(name)sCast {
|
|
||||||
#[inline]
|
|
||||||
/// Downcast an instance of a base class of `%(name)s` to an instance of
|
|
||||||
/// `%(name)s`, if it internally is an instance of `%(name)s`
|
|
||||||
pub fn to_ref<T: %(derivedTrait)s + Reflectable>(base: &T) -> Option<&%(name)s> {
|
|
||||||
match base.%(methodName)s() {
|
|
||||||
true => Some(unsafe { mem::transmute(base) }),
|
|
||||||
false => None
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[inline]
|
|
||||||
#[allow(unrooted_must_root)]
|
|
||||||
pub fn to_layout_js<T: %(derivedTrait)s + Reflectable>(base: &LayoutJS<T>) -> Option<LayoutJS<%(name)s>> {
|
|
||||||
unsafe {
|
|
||||||
match (*base.unsafe_get()).%(methodName)s() {
|
|
||||||
true => Some(mem::transmute_copy(base)),
|
|
||||||
false => None
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[inline]
|
|
||||||
pub fn to_root<T: %(derivedTrait)s + Reflectable>(base: Root<T>) -> Option<Root<%(name)s>> {
|
|
||||||
match base.%(methodName)s() {
|
|
||||||
true => Some(unsafe { mem::transmute(base) }),
|
|
||||||
false => None
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl %(derivedTrait)s for %(baseName)s {
|
|
||||||
fn %(methodName)s(&self) -> bool {
|
|
||||||
let dom_class = unsafe {
|
|
||||||
get_dom_class(self.reflector().get_jsobject().get()).unwrap()
|
|
||||||
};
|
|
||||||
%(name)s::derives(dom_class)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
""" % args))
|
|
||||||
|
|
||||||
# Implement the `FooDerived` trait for non-root superclasses by deferring to
|
|
||||||
# the direct superclass. This leaves the implementation of the `FooDerived`
|
|
||||||
# trait for the root superclass to manual code. `FooDerived` is not
|
|
||||||
# implemented for `Foo` itself.
|
|
||||||
for baseName in descriptor.prototypeChain[1:-1]:
|
|
||||||
args = {
|
|
||||||
'baseName': baseName,
|
|
||||||
'derivedTrait': name + 'Derived',
|
|
||||||
'methodName': 'is_' + name.lower(),
|
|
||||||
'parentName': config.getDescriptor(baseName).getParentName(),
|
|
||||||
}
|
|
||||||
allprotos.append(CGGeneric("""\
|
|
||||||
impl %(derivedTrait)s for %(baseName)s {
|
|
||||||
#[inline]
|
|
||||||
fn %(methodName)s(&self) -> bool {
|
|
||||||
%(parentName)sCast::from_ref(self).%(methodName)s()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
""" % args))
|
|
||||||
|
|
||||||
typeIdCode = []
|
typeIdCode = []
|
||||||
topTypeVariants = [
|
topTypeVariants = [
|
||||||
|
|
|
@ -55,6 +55,7 @@ use libc;
|
||||||
use num::Float;
|
use num::Float;
|
||||||
use num::traits::{Bounded, Zero};
|
use num::traits::{Bounded, Zero};
|
||||||
use std::borrow::ToOwned;
|
use std::borrow::ToOwned;
|
||||||
|
use std::mem;
|
||||||
use std::rc::Rc;
|
use std::rc::Rc;
|
||||||
use std::{char, ptr, slice};
|
use std::{char, ptr, slice};
|
||||||
use util::str::DOMString;
|
use util::str::DOMString;
|
||||||
|
@ -106,6 +107,36 @@ pub trait IDLInterface {
|
||||||
fn derives(&'static DOMClass) -> bool;
|
fn derives(&'static DOMClass) -> bool;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// A trait to hold the cast functions of IDL interfaces that either derive
|
||||||
|
/// or are derived from other interfaces.
|
||||||
|
pub trait Castable: IDLInterface + Reflectable + Sized {
|
||||||
|
/// Check whether a DOM object implements one of its deriving interfaces.
|
||||||
|
fn is<T>(&self) -> bool where T: DerivedFrom<Self> {
|
||||||
|
let class = unsafe {
|
||||||
|
get_dom_class(self.reflector().get_jsobject().get()).unwrap()
|
||||||
|
};
|
||||||
|
T::derives(class)
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Cast a DOM object upwards to one of the interfaces it derives from.
|
||||||
|
fn upcast<T>(&self) -> &T where T: Castable, Self: DerivedFrom<T> {
|
||||||
|
unsafe { mem::transmute(self) }
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Cast a DOM object downwards to one of the interfaces it might implement.
|
||||||
|
fn downcast<T>(&self) -> Option<&T> where T: DerivedFrom<Self> {
|
||||||
|
if self.is::<T>() {
|
||||||
|
Some(unsafe { mem::transmute(self) })
|
||||||
|
} else {
|
||||||
|
None
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// A trait to mark an IDL interface as deriving from another one.
|
||||||
|
#[rustc_on_unimplemented = "The IDL interface `{Self}` is not derived from `{T}`."]
|
||||||
|
pub trait DerivedFrom<T: Castable>: Castable {}
|
||||||
|
|
||||||
/// A trait to convert Rust types to `JSVal`s.
|
/// A trait to convert Rust types to `JSVal`s.
|
||||||
pub trait ToJSValConvertible {
|
pub trait ToJSValConvertible {
|
||||||
/// Convert `self` to a `JSVal`. JSAPI failure causes a task failure.
|
/// Convert `self` to a `JSVal`. JSAPI failure causes a task failure.
|
||||||
|
|
|
@ -24,6 +24,7 @@
|
||||||
//!
|
//!
|
||||||
|
|
||||||
use core::nonzero::NonZero;
|
use core::nonzero::NonZero;
|
||||||
|
use dom::bindings::conversions::{Castable, DerivedFrom};
|
||||||
use dom::bindings::trace::JSTraceable;
|
use dom::bindings::trace::JSTraceable;
|
||||||
use dom::bindings::trace::trace_reflector;
|
use dom::bindings::trace::trace_reflector;
|
||||||
use dom::bindings::utils::{Reflectable, Reflector};
|
use dom::bindings::utils::{Reflectable, Reflector};
|
||||||
|
@ -34,6 +35,7 @@ use layout_interface::TrustedNodeAddress;
|
||||||
use script_task::STACK_ROOTS;
|
use script_task::STACK_ROOTS;
|
||||||
use std::cell::UnsafeCell;
|
use std::cell::UnsafeCell;
|
||||||
use std::default::Default;
|
use std::default::Default;
|
||||||
|
use std::mem;
|
||||||
use std::ops::Deref;
|
use std::ops::Deref;
|
||||||
use std::ptr;
|
use std::ptr;
|
||||||
use util::mem::HeapSizeOf;
|
use util::mem::HeapSizeOf;
|
||||||
|
@ -119,6 +121,24 @@ pub struct LayoutJS<T> {
|
||||||
ptr: NonZero<*const T>
|
ptr: NonZero<*const T>
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl<T: Castable> LayoutJS<T> {
|
||||||
|
/// Cast a DOM object root upwards to one of the interfaces it derives from.
|
||||||
|
pub fn upcast<U>(&self) -> LayoutJS<U> where U: Castable, T: DerivedFrom<U> {
|
||||||
|
unsafe { mem::transmute_copy(self) }
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Cast a DOM object downwards to one of the interfaces it might implement.
|
||||||
|
pub fn downcast<U>(&self) -> Option<LayoutJS<U>> where U: DerivedFrom<T> {
|
||||||
|
unsafe {
|
||||||
|
if (*self.unsafe_get()).is::<U>() {
|
||||||
|
Some(mem::transmute_copy(self))
|
||||||
|
} else {
|
||||||
|
None
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
impl<T: Reflectable> LayoutJS<T> {
|
impl<T: Reflectable> LayoutJS<T> {
|
||||||
/// Get the reflector.
|
/// Get the reflector.
|
||||||
pub unsafe fn get_jsobject(&self) -> *mut JSObject {
|
pub unsafe fn get_jsobject(&self) -> *mut JSObject {
|
||||||
|
@ -447,6 +467,22 @@ pub struct Root<T: Reflectable> {
|
||||||
root_list: *const RootCollection,
|
root_list: *const RootCollection,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl<T: Castable> Root<T> {
|
||||||
|
/// Cast a DOM object root upwards to one of the interfaces it derives from.
|
||||||
|
pub fn upcast<U>(root: Root<T>) -> Root<U> where U: Castable, T: DerivedFrom<U> {
|
||||||
|
unsafe { mem::transmute(root) }
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Cast a DOM object root downwards to one of the interfaces it might implement.
|
||||||
|
pub fn downcast<U>(root: Root<T>) -> Option<Root<U>> where U: DerivedFrom<T> {
|
||||||
|
if root.is::<U>() {
|
||||||
|
Some(unsafe { mem::transmute(root) })
|
||||||
|
} else {
|
||||||
|
None
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
impl<T: Reflectable> Root<T> {
|
impl<T: Reflectable> Root<T> {
|
||||||
/// Create a new stack-bounded root for the provided JS-owned value.
|
/// Create a new stack-bounded root for the provided JS-owned value.
|
||||||
/// It cannot not outlive its associated `RootCollection`, and it gives
|
/// It cannot not outlive its associated `RootCollection`, and it gives
|
||||||
|
|
|
@ -12,9 +12,9 @@ use dom::bindings::codegen::Bindings::CanvasRenderingContext2DBinding;
|
||||||
use dom::bindings::codegen::Bindings::CanvasRenderingContext2DBinding::CanvasRenderingContext2DMethods;
|
use dom::bindings::codegen::Bindings::CanvasRenderingContext2DBinding::CanvasRenderingContext2DMethods;
|
||||||
use dom::bindings::codegen::Bindings::CanvasRenderingContext2DBinding::CanvasWindingRule;
|
use dom::bindings::codegen::Bindings::CanvasRenderingContext2DBinding::CanvasWindingRule;
|
||||||
use dom::bindings::codegen::Bindings::ImageDataBinding::ImageDataMethods;
|
use dom::bindings::codegen::Bindings::ImageDataBinding::ImageDataMethods;
|
||||||
use dom::bindings::codegen::InheritTypes::NodeCast;
|
|
||||||
use dom::bindings::codegen::UnionTypes::HTMLImageElementOrHTMLCanvasElementOrCanvasRenderingContext2D;
|
use dom::bindings::codegen::UnionTypes::HTMLImageElementOrHTMLCanvasElementOrCanvasRenderingContext2D;
|
||||||
use dom::bindings::codegen::UnionTypes::StringOrCanvasGradientOrCanvasPattern;
|
use dom::bindings::codegen::UnionTypes::StringOrCanvasGradientOrCanvasPattern;
|
||||||
|
use dom::bindings::conversions::Castable;
|
||||||
use dom::bindings::error::{Error, Fallible};
|
use dom::bindings::error::{Error, Fallible};
|
||||||
use dom::bindings::global::{GlobalField, GlobalRef};
|
use dom::bindings::global::{GlobalField, GlobalRef};
|
||||||
use dom::bindings::js::{JS, LayoutJS, Root};
|
use dom::bindings::js::{JS, LayoutJS, Root};
|
||||||
|
@ -26,7 +26,7 @@ use dom::htmlcanvaselement::HTMLCanvasElement;
|
||||||
use dom::htmlcanvaselement::utils as canvas_utils;
|
use dom::htmlcanvaselement::utils as canvas_utils;
|
||||||
use dom::htmlimageelement::HTMLImageElement;
|
use dom::htmlimageelement::HTMLImageElement;
|
||||||
use dom::imagedata::ImageData;
|
use dom::imagedata::ImageData;
|
||||||
use dom::node::{NodeDamage, window_from_node};
|
use dom::node::{Node, NodeDamage, window_from_node};
|
||||||
use euclid::matrix2d::Matrix2D;
|
use euclid::matrix2d::Matrix2D;
|
||||||
use euclid::point::Point2D;
|
use euclid::point::Point2D;
|
||||||
use euclid::rect::Rect;
|
use euclid::rect::Rect;
|
||||||
|
@ -148,7 +148,7 @@ impl CanvasRenderingContext2D {
|
||||||
|
|
||||||
fn mark_as_dirty(&self) {
|
fn mark_as_dirty(&self) {
|
||||||
let canvas = self.canvas.root();
|
let canvas = self.canvas.root();
|
||||||
let node = NodeCast::from_ref(canvas.r());
|
let node = canvas.upcast::<Node>();
|
||||||
node.dirty(NodeDamage::OtherNodeDamage);
|
node.dirty(NodeDamage::OtherNodeDamage);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -6,8 +6,8 @@
|
||||||
|
|
||||||
use dom::bindings::cell::DOMRefCell;
|
use dom::bindings::cell::DOMRefCell;
|
||||||
use dom::bindings::codegen::Bindings::CharacterDataBinding::CharacterDataMethods;
|
use dom::bindings::codegen::Bindings::CharacterDataBinding::CharacterDataMethods;
|
||||||
use dom::bindings::codegen::InheritTypes::{ElementCast, NodeCast};
|
|
||||||
use dom::bindings::codegen::UnionTypes::NodeOrString;
|
use dom::bindings::codegen::UnionTypes::NodeOrString;
|
||||||
|
use dom::bindings::conversions::Castable;
|
||||||
use dom::bindings::error::{Error, ErrorResult, Fallible};
|
use dom::bindings::error::{Error, ErrorResult, Fallible};
|
||||||
use dom::bindings::js::{LayoutJS, Root};
|
use dom::bindings::js::{LayoutJS, Root};
|
||||||
use dom::document::Document;
|
use dom::document::Document;
|
||||||
|
@ -113,35 +113,35 @@ impl CharacterDataMethods for CharacterData {
|
||||||
|
|
||||||
// https://dom.spec.whatwg.org/#dom-childnode-before
|
// https://dom.spec.whatwg.org/#dom-childnode-before
|
||||||
fn Before(&self, nodes: Vec<NodeOrString>) -> ErrorResult {
|
fn Before(&self, nodes: Vec<NodeOrString>) -> ErrorResult {
|
||||||
NodeCast::from_ref(self).before(nodes)
|
self.upcast::<Node>().before(nodes)
|
||||||
}
|
}
|
||||||
|
|
||||||
// https://dom.spec.whatwg.org/#dom-childnode-after
|
// https://dom.spec.whatwg.org/#dom-childnode-after
|
||||||
fn After(&self, nodes: Vec<NodeOrString>) -> ErrorResult {
|
fn After(&self, nodes: Vec<NodeOrString>) -> ErrorResult {
|
||||||
NodeCast::from_ref(self).after(nodes)
|
self.upcast::<Node>().after(nodes)
|
||||||
}
|
}
|
||||||
|
|
||||||
// https://dom.spec.whatwg.org/#dom-childnode-replacewith
|
// https://dom.spec.whatwg.org/#dom-childnode-replacewith
|
||||||
fn ReplaceWith(&self, nodes: Vec<NodeOrString>) -> ErrorResult {
|
fn ReplaceWith(&self, nodes: Vec<NodeOrString>) -> ErrorResult {
|
||||||
NodeCast::from_ref(self).replace_with(nodes)
|
self.upcast::<Node>().replace_with(nodes)
|
||||||
}
|
}
|
||||||
|
|
||||||
// https://dom.spec.whatwg.org/#dom-childnode-remove
|
// https://dom.spec.whatwg.org/#dom-childnode-remove
|
||||||
fn Remove(&self) {
|
fn Remove(&self) {
|
||||||
let node = NodeCast::from_ref(self);
|
let node = self.upcast::<Node>();
|
||||||
node.remove_self();
|
node.remove_self();
|
||||||
}
|
}
|
||||||
|
|
||||||
// https://dom.spec.whatwg.org/#dom-nondocumenttypechildnode-previouselementsibling
|
// https://dom.spec.whatwg.org/#dom-nondocumenttypechildnode-previouselementsibling
|
||||||
fn GetPreviousElementSibling(&self) -> Option<Root<Element>> {
|
fn GetPreviousElementSibling(&self) -> Option<Root<Element>> {
|
||||||
NodeCast::from_ref(self).preceding_siblings()
|
self.upcast::<Node>().preceding_siblings()
|
||||||
.filter_map(ElementCast::to_root).next()
|
.filter_map(Root::downcast::<Element>).next()
|
||||||
}
|
}
|
||||||
|
|
||||||
// https://dom.spec.whatwg.org/#dom-nondocumenttypechildnode-nextelementsibling
|
// https://dom.spec.whatwg.org/#dom-nondocumenttypechildnode-nextelementsibling
|
||||||
fn GetNextElementSibling(&self) -> Option<Root<Element>> {
|
fn GetNextElementSibling(&self) -> Option<Root<Element>> {
|
||||||
NodeCast::from_ref(self).following_siblings()
|
self.upcast::<Node>().following_siblings()
|
||||||
.filter_map(ElementCast::to_root).next()
|
.filter_map(Root::downcast::<Element>).next()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -157,7 +157,7 @@ impl CharacterData {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn content_changed(&self) {
|
fn content_changed(&self) {
|
||||||
let node = NodeCast::from_ref(self);
|
let node = self.upcast::<Node>();
|
||||||
let document = node.owner_doc();
|
let document = node.owner_doc();
|
||||||
document.r().content_changed(node, NodeDamage::OtherNodeDamage);
|
document.r().content_changed(node, NodeDamage::OtherNodeDamage);
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,7 +5,7 @@
|
||||||
use dom::bindings::codegen::Bindings::CloseEventBinding;
|
use dom::bindings::codegen::Bindings::CloseEventBinding;
|
||||||
use dom::bindings::codegen::Bindings::CloseEventBinding::CloseEventMethods;
|
use dom::bindings::codegen::Bindings::CloseEventBinding::CloseEventMethods;
|
||||||
use dom::bindings::codegen::Bindings::EventBinding::EventMethods;
|
use dom::bindings::codegen::Bindings::EventBinding::EventMethods;
|
||||||
use dom::bindings::codegen::InheritTypes::EventCast;
|
use dom::bindings::conversions::Castable;
|
||||||
use dom::bindings::error::Fallible;
|
use dom::bindings::error::Fallible;
|
||||||
use dom::bindings::global::GlobalRef;
|
use dom::bindings::global::GlobalRef;
|
||||||
use dom::bindings::js::Root;
|
use dom::bindings::js::Root;
|
||||||
|
@ -43,7 +43,7 @@ impl CloseEvent {
|
||||||
let event = box CloseEvent::new_inherited(wasClean, code, reason);
|
let event = box CloseEvent::new_inherited(wasClean, code, reason);
|
||||||
let ev = reflect_dom_object(event, global, CloseEventBinding::Wrap);
|
let ev = reflect_dom_object(event, global, CloseEventBinding::Wrap);
|
||||||
{
|
{
|
||||||
let event = EventCast::from_ref(ev.r());
|
let event = ev.upcast::<Event>();
|
||||||
event.InitEvent(type_,
|
event.InitEvent(type_,
|
||||||
bubbles == EventBubbles::Bubbles,
|
bubbles == EventBubbles::Bubbles,
|
||||||
cancelable == EventCancelable::Cancelable);
|
cancelable == EventCancelable::Cancelable);
|
||||||
|
|
|
@ -2,7 +2,6 @@
|
||||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||||
|
|
||||||
use dom::bindings::codegen::InheritTypes::ElementCast;
|
|
||||||
use dom::bindings::js::Root;
|
use dom::bindings::js::Root;
|
||||||
use dom::document::Document;
|
use dom::document::Document;
|
||||||
use dom::element::Element;
|
use dom::element::Element;
|
||||||
|
@ -90,11 +89,11 @@ pub fn create_element(name: QualName, prefix: Option<Atom>,
|
||||||
macro_rules! make(
|
macro_rules! make(
|
||||||
($ctor:ident) => ({
|
($ctor:ident) => ({
|
||||||
let obj = $ctor::new((*name.local).to_owned(), prefix, document);
|
let obj = $ctor::new((*name.local).to_owned(), prefix, document);
|
||||||
ElementCast::from_root(obj)
|
Root::upcast::<Element>(obj)
|
||||||
});
|
});
|
||||||
($ctor:ident, $($arg:expr),+) => ({
|
($ctor:ident, $($arg:expr),+) => ({
|
||||||
let obj = $ctor::new((*name.local).to_owned(), prefix, document, $($arg),+);
|
let obj = $ctor::new((*name.local).to_owned(), prefix, document, $($arg),+);
|
||||||
ElementCast::from_root(obj)
|
Root::upcast::<Element>(obj)
|
||||||
})
|
})
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
|
@ -3,13 +3,13 @@
|
||||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||||
|
|
||||||
use dom::bindings::codegen::Bindings::CSSStyleDeclarationBinding::{self, CSSStyleDeclarationMethods};
|
use dom::bindings::codegen::Bindings::CSSStyleDeclarationBinding::{self, CSSStyleDeclarationMethods};
|
||||||
use dom::bindings::codegen::InheritTypes::{ElementCast, NodeCast};
|
use dom::bindings::conversions::Castable;
|
||||||
use dom::bindings::error::{Error, ErrorResult, Fallible};
|
use dom::bindings::error::{Error, ErrorResult, Fallible};
|
||||||
use dom::bindings::global::GlobalRef;
|
use dom::bindings::global::GlobalRef;
|
||||||
use dom::bindings::js::{JS, Root};
|
use dom::bindings::js::{JS, Root};
|
||||||
use dom::bindings::utils::{Reflector, reflect_dom_object};
|
use dom::bindings::utils::{Reflector, reflect_dom_object};
|
||||||
use dom::element::{Element, StylePriority};
|
use dom::element::{Element, StylePriority};
|
||||||
use dom::node::{NodeDamage, document_from_node, window_from_node};
|
use dom::node::{Node, NodeDamage, document_from_node, window_from_node};
|
||||||
use dom::window::Window;
|
use dom::window::Window;
|
||||||
use selectors::parser::PseudoElement;
|
use selectors::parser::PseudoElement;
|
||||||
use std::ascii::AsciiExt;
|
use std::ascii::AsciiExt;
|
||||||
|
@ -75,7 +75,7 @@ impl CSSStyleDeclaration {
|
||||||
|
|
||||||
fn get_computed_style(&self, property: &Atom) -> Option<DOMString> {
|
fn get_computed_style(&self, property: &Atom) -> Option<DOMString> {
|
||||||
let owner = self.owner.root();
|
let owner = self.owner.root();
|
||||||
let node = NodeCast::from_ref(owner.r());
|
let node = owner.upcast::<Node>();
|
||||||
if !node.is_in_doc() {
|
if !node.is_in_doc() {
|
||||||
// TODO: Node should be matched against the style rules of this window.
|
// TODO: Node should be matched against the style rules of this window.
|
||||||
// Firefox is currently the only browser to implement this.
|
// Firefox is currently the only browser to implement this.
|
||||||
|
@ -90,7 +90,7 @@ impl CSSStyleDeclarationMethods for CSSStyleDeclaration {
|
||||||
// https://dev.w3.org/csswg/cssom/#dom-cssstyledeclaration-length
|
// https://dev.w3.org/csswg/cssom/#dom-cssstyledeclaration-length
|
||||||
fn Length(&self) -> u32 {
|
fn Length(&self) -> u32 {
|
||||||
let owner = self.owner.root();
|
let owner = self.owner.root();
|
||||||
let elem = ElementCast::from_ref(owner.r());
|
let elem = owner.upcast::<Element>();
|
||||||
let len = match *elem.style_attribute().borrow() {
|
let len = match *elem.style_attribute().borrow() {
|
||||||
Some(ref declarations) => declarations.normal.len() + declarations.important.len(),
|
Some(ref declarations) => declarations.normal.len() + declarations.important.len(),
|
||||||
None => 0
|
None => 0
|
||||||
|
@ -102,7 +102,7 @@ impl CSSStyleDeclarationMethods for CSSStyleDeclaration {
|
||||||
fn Item(&self, index: u32) -> DOMString {
|
fn Item(&self, index: u32) -> DOMString {
|
||||||
let index = index as usize;
|
let index = index as usize;
|
||||||
let owner = self.owner.root();
|
let owner = self.owner.root();
|
||||||
let elem = ElementCast::from_ref(owner.r());
|
let elem = owner.upcast::<Element>();
|
||||||
let style_attribute = elem.style_attribute().borrow();
|
let style_attribute = elem.style_attribute().borrow();
|
||||||
let result = style_attribute.as_ref().and_then(|declarations| {
|
let result = style_attribute.as_ref().and_then(|declarations| {
|
||||||
if index > declarations.normal.len() {
|
if index > declarations.normal.len() {
|
||||||
|
@ -233,7 +233,7 @@ impl CSSStyleDeclarationMethods for CSSStyleDeclaration {
|
||||||
};
|
};
|
||||||
|
|
||||||
let owner = self.owner.root();
|
let owner = self.owner.root();
|
||||||
let element = ElementCast::from_ref(owner.r());
|
let element = owner.upcast::<Element>();
|
||||||
|
|
||||||
// Step 8
|
// Step 8
|
||||||
for decl in declarations {
|
for decl in declarations {
|
||||||
|
@ -242,7 +242,7 @@ impl CSSStyleDeclarationMethods for CSSStyleDeclaration {
|
||||||
}
|
}
|
||||||
|
|
||||||
let document = document_from_node(element);
|
let document = document_from_node(element);
|
||||||
let node = NodeCast::from_ref(element);
|
let node = element.upcast::<Node>();
|
||||||
document.r().content_changed(node, NodeDamage::NodeStyleDamaged);
|
document.r().content_changed(node, NodeDamage::NodeStyleDamaged);
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
@ -267,7 +267,7 @@ impl CSSStyleDeclarationMethods for CSSStyleDeclaration {
|
||||||
};
|
};
|
||||||
|
|
||||||
let owner = self.owner.root();
|
let owner = self.owner.root();
|
||||||
let element = ElementCast::from_ref(owner.r());
|
let element = owner.upcast::<Element>();
|
||||||
|
|
||||||
// Step 5 & 6
|
// Step 5 & 6
|
||||||
match longhands_from_shorthand(&property) {
|
match longhands_from_shorthand(&property) {
|
||||||
|
@ -276,7 +276,7 @@ impl CSSStyleDeclarationMethods for CSSStyleDeclaration {
|
||||||
}
|
}
|
||||||
|
|
||||||
let document = document_from_node(element);
|
let document = document_from_node(element);
|
||||||
let node = NodeCast::from_ref(element);
|
let node = element.upcast::<Node>();
|
||||||
document.r().content_changed(node, NodeDamage::NodeStyleDamaged);
|
document.r().content_changed(node, NodeDamage::NodeStyleDamaged);
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
@ -300,7 +300,7 @@ impl CSSStyleDeclarationMethods for CSSStyleDeclaration {
|
||||||
let value = self.GetPropertyValue(property.clone());
|
let value = self.GetPropertyValue(property.clone());
|
||||||
|
|
||||||
let owner = self.owner.root();
|
let owner = self.owner.root();
|
||||||
let elem = ElementCast::from_ref(owner.r());
|
let elem = owner.upcast::<Element>();
|
||||||
|
|
||||||
match longhands_from_shorthand(&property) {
|
match longhands_from_shorthand(&property) {
|
||||||
// Step 4
|
// Step 4
|
||||||
|
|
|
@ -5,7 +5,7 @@
|
||||||
use dom::bindings::codegen::Bindings::CustomEventBinding;
|
use dom::bindings::codegen::Bindings::CustomEventBinding;
|
||||||
use dom::bindings::codegen::Bindings::CustomEventBinding::CustomEventMethods;
|
use dom::bindings::codegen::Bindings::CustomEventBinding::CustomEventMethods;
|
||||||
use dom::bindings::codegen::Bindings::EventBinding::EventMethods;
|
use dom::bindings::codegen::Bindings::EventBinding::EventMethods;
|
||||||
use dom::bindings::codegen::InheritTypes::EventCast;
|
use dom::bindings::conversions::Castable;
|
||||||
use dom::bindings::error::Fallible;
|
use dom::bindings::error::Fallible;
|
||||||
use dom::bindings::global::GlobalRef;
|
use dom::bindings::global::GlobalRef;
|
||||||
use dom::bindings::js::{MutHeapJSVal, Root};
|
use dom::bindings::js::{MutHeapJSVal, Root};
|
||||||
|
@ -70,7 +70,7 @@ impl CustomEventMethods for CustomEvent {
|
||||||
can_bubble: bool,
|
can_bubble: bool,
|
||||||
cancelable: bool,
|
cancelable: bool,
|
||||||
detail: HandleValue) {
|
detail: HandleValue) {
|
||||||
let event = EventCast::from_ref(self);
|
let event = self.upcast::<Event>();
|
||||||
if event.dispatching() {
|
if event.dispatching() {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,13 +8,14 @@ use dom::bindings::cell::DOMRefCell;
|
||||||
use dom::bindings::codegen::Bindings::DedicatedWorkerGlobalScopeBinding;
|
use dom::bindings::codegen::Bindings::DedicatedWorkerGlobalScopeBinding;
|
||||||
use dom::bindings::codegen::Bindings::DedicatedWorkerGlobalScopeBinding::DedicatedWorkerGlobalScopeMethods;
|
use dom::bindings::codegen::Bindings::DedicatedWorkerGlobalScopeBinding::DedicatedWorkerGlobalScopeMethods;
|
||||||
use dom::bindings::codegen::Bindings::EventHandlerBinding::EventHandlerNonNull;
|
use dom::bindings::codegen::Bindings::EventHandlerBinding::EventHandlerNonNull;
|
||||||
use dom::bindings::codegen::InheritTypes::{EventTargetCast, WorkerGlobalScopeCast};
|
use dom::bindings::conversions::Castable;
|
||||||
use dom::bindings::error::ErrorResult;
|
use dom::bindings::error::ErrorResult;
|
||||||
use dom::bindings::global::GlobalRef;
|
use dom::bindings::global::GlobalRef;
|
||||||
use dom::bindings::js::{Root, RootCollection};
|
use dom::bindings::js::{Root, RootCollection};
|
||||||
use dom::bindings::refcounted::LiveDOMReferences;
|
use dom::bindings::refcounted::LiveDOMReferences;
|
||||||
use dom::bindings::structuredclone::StructuredCloneData;
|
use dom::bindings::structuredclone::StructuredCloneData;
|
||||||
use dom::bindings::utils::Reflectable;
|
use dom::bindings::utils::Reflectable;
|
||||||
|
use dom::eventtarget::EventTarget;
|
||||||
use dom::messageevent::MessageEvent;
|
use dom::messageevent::MessageEvent;
|
||||||
use dom::worker::{SimpleWorkerErrorHandler, TrustedWorkerAddress, WorkerMessageHandler};
|
use dom::worker::{SimpleWorkerErrorHandler, TrustedWorkerAddress, WorkerMessageHandler};
|
||||||
use dom::workerglobalscope::WorkerGlobalScope;
|
use dom::workerglobalscope::WorkerGlobalScope;
|
||||||
|
@ -219,7 +220,7 @@ impl DedicatedWorkerGlobalScope {
|
||||||
parent_sender.clone(), own_sender, receiver);
|
parent_sender.clone(), own_sender, receiver);
|
||||||
// FIXME(njn): workers currently don't have a unique ID suitable for using in reporter
|
// FIXME(njn): workers currently don't have a unique ID suitable for using in reporter
|
||||||
// registration (#6631), so we instead use a random number and cross our fingers.
|
// registration (#6631), so we instead use a random number and cross our fingers.
|
||||||
let scope = WorkerGlobalScopeCast::from_ref(global.r());
|
let scope = global.upcast::<WorkerGlobalScope>();
|
||||||
|
|
||||||
{
|
{
|
||||||
let _ar = AutoWorkerReset::new(global.r(), worker);
|
let _ar = AutoWorkerReset::new(global.r(), worker);
|
||||||
|
@ -261,7 +262,7 @@ impl DedicatedWorkerGlobalScope {
|
||||||
|
|
||||||
#[allow(unsafe_code)]
|
#[allow(unsafe_code)]
|
||||||
fn receive_event(&self) -> Result<MixedMessage, RecvError> {
|
fn receive_event(&self) -> Result<MixedMessage, RecvError> {
|
||||||
let scope = WorkerGlobalScopeCast::from_ref(self);
|
let scope = self.upcast::<WorkerGlobalScope>();
|
||||||
let worker_port = &self.receiver;
|
let worker_port = &self.receiver;
|
||||||
let devtools_port = scope.from_devtools_receiver();
|
let devtools_port = scope.from_devtools_receiver();
|
||||||
|
|
||||||
|
@ -287,8 +288,8 @@ impl DedicatedWorkerGlobalScope {
|
||||||
fn handle_script_event(&self, msg: WorkerScriptMsg) {
|
fn handle_script_event(&self, msg: WorkerScriptMsg) {
|
||||||
match msg {
|
match msg {
|
||||||
WorkerScriptMsg::DOMMessage(data) => {
|
WorkerScriptMsg::DOMMessage(data) => {
|
||||||
let scope = WorkerGlobalScopeCast::from_ref(self);
|
let scope = self.upcast::<WorkerGlobalScope>();
|
||||||
let target = EventTargetCast::from_ref(self);
|
let target = self.upcast::<EventTarget>();
|
||||||
let _ar = JSAutoRequest::new(scope.get_cx());
|
let _ar = JSAutoRequest::new(scope.get_cx());
|
||||||
let _ac = JSAutoCompartment::new(scope.get_cx(), scope.reflector().get_jsobject().get());
|
let _ac = JSAutoCompartment::new(scope.get_cx(), scope.reflector().get_jsobject().get());
|
||||||
let mut message = RootedValue::new(scope.get_cx(), UndefinedValue());
|
let mut message = RootedValue::new(scope.get_cx(), UndefinedValue());
|
||||||
|
@ -303,11 +304,11 @@ impl DedicatedWorkerGlobalScope {
|
||||||
},
|
},
|
||||||
WorkerScriptMsg::Common(
|
WorkerScriptMsg::Common(
|
||||||
CommonScriptMsg::FireTimer(TimerSource::FromWorker, timer_id)) => {
|
CommonScriptMsg::FireTimer(TimerSource::FromWorker, timer_id)) => {
|
||||||
let scope = WorkerGlobalScopeCast::from_ref(self);
|
let scope = self.upcast::<WorkerGlobalScope>();
|
||||||
scope.handle_fire_timer(timer_id);
|
scope.handle_fire_timer(timer_id);
|
||||||
},
|
},
|
||||||
WorkerScriptMsg::Common(CommonScriptMsg::CollectReports(reports_chan)) => {
|
WorkerScriptMsg::Common(CommonScriptMsg::CollectReports(reports_chan)) => {
|
||||||
let scope = WorkerGlobalScopeCast::from_ref(self);
|
let scope = self.upcast::<WorkerGlobalScope>();
|
||||||
let cx = scope.get_cx();
|
let cx = scope.get_cx();
|
||||||
let path_seg = format!("url({})", scope.get_url());
|
let path_seg = format!("url({})", scope.get_url());
|
||||||
let reports = ScriptTask::get_reports(cx, path_seg);
|
let reports = ScriptTask::get_reports(cx, path_seg);
|
||||||
|
@ -322,7 +323,7 @@ impl DedicatedWorkerGlobalScope {
|
||||||
fn handle_event(&self, event: MixedMessage) {
|
fn handle_event(&self, event: MixedMessage) {
|
||||||
match event {
|
match event {
|
||||||
MixedMessage::FromDevtools(msg) => {
|
MixedMessage::FromDevtools(msg) => {
|
||||||
let global_ref = GlobalRef::Worker(WorkerGlobalScopeCast::from_ref(self));
|
let global_ref = GlobalRef::Worker(self.upcast::<WorkerGlobalScope>());
|
||||||
match msg {
|
match msg {
|
||||||
DevtoolScriptControlMsg::EvaluateJS(_pipe_id, string, sender) =>
|
DevtoolScriptControlMsg::EvaluateJS(_pipe_id, string, sender) =>
|
||||||
devtools::handle_evaluate_js(&global_ref, string, sender),
|
devtools::handle_evaluate_js(&global_ref, string, sender),
|
||||||
|
|
|
@ -14,19 +14,9 @@ use dom::bindings::codegen::Bindings::NodeBinding::NodeMethods;
|
||||||
use dom::bindings::codegen::Bindings::NodeFilterBinding::NodeFilter;
|
use dom::bindings::codegen::Bindings::NodeFilterBinding::NodeFilter;
|
||||||
use dom::bindings::codegen::Bindings::PerformanceBinding::PerformanceMethods;
|
use dom::bindings::codegen::Bindings::PerformanceBinding::PerformanceMethods;
|
||||||
use dom::bindings::codegen::Bindings::WindowBinding::WindowMethods;
|
use dom::bindings::codegen::Bindings::WindowBinding::WindowMethods;
|
||||||
use dom::bindings::codegen::InheritTypes::{DocumentDerived, DocumentTypeCast, ElementCast};
|
use dom::bindings::codegen::InheritTypes::{ElementTypeId, HTMLElementTypeId, NodeTypeId};
|
||||||
use dom::bindings::codegen::InheritTypes::{ElementDerived, ElementTypeId};
|
|
||||||
use dom::bindings::codegen::InheritTypes::{EventCast, EventTargetCast};
|
|
||||||
use dom::bindings::codegen::InheritTypes::{HTMLAnchorElementCast, HTMLAnchorElementDerived};
|
|
||||||
use dom::bindings::codegen::InheritTypes::{HTMLAppletElementDerived, HTMLAreaElementDerived};
|
|
||||||
use dom::bindings::codegen::InheritTypes::{HTMLBaseElementCast, HTMLBodyElementCast};
|
|
||||||
use dom::bindings::codegen::InheritTypes::{HTMLElementCast, HTMLElementTypeId};
|
|
||||||
use dom::bindings::codegen::InheritTypes::{HTMLEmbedElementDerived, HTMLFormElementDerived};
|
|
||||||
use dom::bindings::codegen::InheritTypes::{HTMLHeadElementCast, HTMLHtmlElementCast};
|
|
||||||
use dom::bindings::codegen::InheritTypes::{HTMLIFrameElementCast, HTMLImageElementDerived};
|
|
||||||
use dom::bindings::codegen::InheritTypes::{HTMLScriptElementDerived, HTMLTitleElementDerived};
|
|
||||||
use dom::bindings::codegen::InheritTypes::{NodeCast, NodeTypeId};
|
|
||||||
use dom::bindings::codegen::UnionTypes::NodeOrString;
|
use dom::bindings::codegen::UnionTypes::NodeOrString;
|
||||||
|
use dom::bindings::conversions::Castable;
|
||||||
use dom::bindings::error::{Error, ErrorResult, Fallible};
|
use dom::bindings::error::{Error, ErrorResult, Fallible};
|
||||||
use dom::bindings::global::GlobalRef;
|
use dom::bindings::global::GlobalRef;
|
||||||
use dom::bindings::js::RootedReference;
|
use dom::bindings::js::RootedReference;
|
||||||
|
@ -45,13 +35,20 @@ use dom::element::{Element, ElementCreator};
|
||||||
use dom::event::{Event, EventBubbles, EventCancelable};
|
use dom::event::{Event, EventBubbles, EventCancelable};
|
||||||
use dom::eventtarget::{EventTarget};
|
use dom::eventtarget::{EventTarget};
|
||||||
use dom::htmlanchorelement::HTMLAnchorElement;
|
use dom::htmlanchorelement::HTMLAnchorElement;
|
||||||
|
use dom::htmlappletelement::HTMLAppletElement;
|
||||||
|
use dom::htmlareaelement::HTMLAreaElement;
|
||||||
use dom::htmlbaseelement::HTMLBaseElement;
|
use dom::htmlbaseelement::HTMLBaseElement;
|
||||||
|
use dom::htmlbodyelement::HTMLBodyElement;
|
||||||
use dom::htmlcollection::{CollectionFilter, HTMLCollection};
|
use dom::htmlcollection::{CollectionFilter, HTMLCollection};
|
||||||
use dom::htmlelement::{HTMLElement};
|
use dom::htmlelement::{HTMLElement};
|
||||||
|
use dom::htmlembedelement::HTMLEmbedElement;
|
||||||
|
use dom::htmlformelement::HTMLFormElement;
|
||||||
use dom::htmlheadelement::HTMLHeadElement;
|
use dom::htmlheadelement::HTMLHeadElement;
|
||||||
use dom::htmlhtmlelement::HTMLHtmlElement;
|
use dom::htmlhtmlelement::HTMLHtmlElement;
|
||||||
use dom::htmliframeelement::{self, HTMLIFrameElement};
|
use dom::htmliframeelement::{self, HTMLIFrameElement};
|
||||||
|
use dom::htmlimageelement::HTMLImageElement;
|
||||||
use dom::htmlscriptelement::HTMLScriptElement;
|
use dom::htmlscriptelement::HTMLScriptElement;
|
||||||
|
use dom::htmltitleelement::HTMLTitleElement;
|
||||||
use dom::keyboardevent::KeyboardEvent;
|
use dom::keyboardevent::KeyboardEvent;
|
||||||
use dom::location::Location;
|
use dom::location::Location;
|
||||||
use dom::messageevent::MessageEvent;
|
use dom::messageevent::MessageEvent;
|
||||||
|
@ -167,7 +164,7 @@ impl PartialEq for Document {
|
||||||
struct ImagesFilter;
|
struct ImagesFilter;
|
||||||
impl CollectionFilter for ImagesFilter {
|
impl CollectionFilter for ImagesFilter {
|
||||||
fn filter(&self, elem: &Element, _root: &Node) -> bool {
|
fn filter(&self, elem: &Element, _root: &Node) -> bool {
|
||||||
elem.is_htmlimageelement()
|
elem.is::<HTMLImageElement>()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -175,7 +172,7 @@ impl CollectionFilter for ImagesFilter {
|
||||||
struct EmbedsFilter;
|
struct EmbedsFilter;
|
||||||
impl CollectionFilter for EmbedsFilter {
|
impl CollectionFilter for EmbedsFilter {
|
||||||
fn filter(&self, elem: &Element, _root: &Node) -> bool {
|
fn filter(&self, elem: &Element, _root: &Node) -> bool {
|
||||||
elem.is_htmlembedelement()
|
elem.is::<HTMLEmbedElement>()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -183,7 +180,7 @@ impl CollectionFilter for EmbedsFilter {
|
||||||
struct LinksFilter;
|
struct LinksFilter;
|
||||||
impl CollectionFilter for LinksFilter {
|
impl CollectionFilter for LinksFilter {
|
||||||
fn filter(&self, elem: &Element, _root: &Node) -> bool {
|
fn filter(&self, elem: &Element, _root: &Node) -> bool {
|
||||||
(elem.is_htmlanchorelement() || elem.is_htmlareaelement()) &&
|
(elem.is::<HTMLAnchorElement>() || elem.is::<HTMLAreaElement>()) &&
|
||||||
elem.has_attribute(&atom!("href"))
|
elem.has_attribute(&atom!("href"))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -192,7 +189,7 @@ impl CollectionFilter for LinksFilter {
|
||||||
struct FormsFilter;
|
struct FormsFilter;
|
||||||
impl CollectionFilter for FormsFilter {
|
impl CollectionFilter for FormsFilter {
|
||||||
fn filter(&self, elem: &Element, _root: &Node) -> bool {
|
fn filter(&self, elem: &Element, _root: &Node) -> bool {
|
||||||
elem.is_htmlformelement()
|
elem.is::<HTMLFormElement>()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -200,7 +197,7 @@ impl CollectionFilter for FormsFilter {
|
||||||
struct ScriptsFilter;
|
struct ScriptsFilter;
|
||||||
impl CollectionFilter for ScriptsFilter {
|
impl CollectionFilter for ScriptsFilter {
|
||||||
fn filter(&self, elem: &Element, _root: &Node) -> bool {
|
fn filter(&self, elem: &Element, _root: &Node) -> bool {
|
||||||
elem.is_htmlscriptelement()
|
elem.is::<HTMLScriptElement>()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -208,7 +205,7 @@ impl CollectionFilter for ScriptsFilter {
|
||||||
struct AnchorsFilter;
|
struct AnchorsFilter;
|
||||||
impl CollectionFilter for AnchorsFilter {
|
impl CollectionFilter for AnchorsFilter {
|
||||||
fn filter(&self, elem: &Element, _root: &Node) -> bool {
|
fn filter(&self, elem: &Element, _root: &Node) -> bool {
|
||||||
elem.is_htmlanchorelement() && elem.has_attribute(&atom!("href"))
|
elem.is::<HTMLAnchorElement>() && elem.has_attribute(&atom!("href"))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -216,7 +213,7 @@ impl CollectionFilter for AnchorsFilter {
|
||||||
struct AppletsFilter;
|
struct AppletsFilter;
|
||||||
impl CollectionFilter for AppletsFilter {
|
impl CollectionFilter for AppletsFilter {
|
||||||
fn filter(&self, elem: &Element, _root: &Node) -> bool {
|
fn filter(&self, elem: &Element, _root: &Node) -> bool {
|
||||||
elem.is_htmlappletelement()
|
elem.is::<HTMLAppletElement>()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -290,10 +287,10 @@ impl Document {
|
||||||
/// Refresh the cached first base element in the DOM.
|
/// Refresh the cached first base element in the DOM.
|
||||||
/// https://github.com/w3c/web-platform-tests/issues/2122
|
/// https://github.com/w3c/web-platform-tests/issues/2122
|
||||||
pub fn refresh_base_element(&self) {
|
pub fn refresh_base_element(&self) {
|
||||||
let base = NodeCast::from_ref(self)
|
let base = self.upcast::<Node>()
|
||||||
.traverse_preorder()
|
.traverse_preorder()
|
||||||
.filter_map(HTMLBaseElementCast::to_root)
|
.filter_map(Root::downcast::<HTMLBaseElement>)
|
||||||
.filter(|element| ElementCast::from_ref(&**element).has_attribute(&atom!("href")))
|
.filter(|element| element.upcast::<Element>().has_attribute(&atom!("href")))
|
||||||
.next();
|
.next();
|
||||||
self.base_element.set(base.r());
|
self.base_element.set(base.r());
|
||||||
}
|
}
|
||||||
|
@ -383,7 +380,7 @@ impl Document {
|
||||||
id: Atom) {
|
id: Atom) {
|
||||||
debug!("Adding named element to document {:p}: {:p} id={}", self, element, id);
|
debug!("Adding named element to document {:p}: {:p} id={}", self, element, id);
|
||||||
assert!({
|
assert!({
|
||||||
let node = NodeCast::from_ref(element);
|
let node = element.upcast::<Node>();
|
||||||
node.is_in_doc()
|
node.is_in_doc()
|
||||||
});
|
});
|
||||||
assert!(!id.is_empty());
|
assert!(!id.is_empty());
|
||||||
|
@ -400,11 +397,11 @@ impl Document {
|
||||||
Occupied(entry) => {
|
Occupied(entry) => {
|
||||||
let elements = entry.into_mut();
|
let elements = entry.into_mut();
|
||||||
|
|
||||||
let new_node = NodeCast::from_ref(element);
|
let new_node = element.upcast::<Node>();
|
||||||
let mut head: usize = 0;
|
let mut head: usize = 0;
|
||||||
let root = NodeCast::from_ref(root.r());
|
let root = root.upcast::<Node>();
|
||||||
for node in root.traverse_preorder() {
|
for node in root.traverse_preorder() {
|
||||||
if let Some(elem) = ElementCast::to_ref(node.r()) {
|
if let Some(elem) = node.downcast::<Element>() {
|
||||||
if (*elements)[head].root().r() == elem {
|
if (*elements)[head].root().r() == elem {
|
||||||
head += 1;
|
head += 1;
|
||||||
}
|
}
|
||||||
|
@ -424,16 +421,16 @@ impl Document {
|
||||||
pub fn find_fragment_node(&self, fragid: &str) -> Option<Root<Element>> {
|
pub fn find_fragment_node(&self, fragid: &str) -> Option<Root<Element>> {
|
||||||
self.GetElementById(fragid.to_owned()).or_else(|| {
|
self.GetElementById(fragid.to_owned()).or_else(|| {
|
||||||
let check_anchor = |&node: &&HTMLAnchorElement| {
|
let check_anchor = |&node: &&HTMLAnchorElement| {
|
||||||
let elem = ElementCast::from_ref(node);
|
let elem = node.upcast::<Element>();
|
||||||
elem.get_attribute(&ns!(""), &atom!("name")).map_or(false, |attr| {
|
elem.get_attribute(&ns!(""), &atom!("name")).map_or(false, |attr| {
|
||||||
&**attr.r().value() == fragid
|
&**attr.r().value() == fragid
|
||||||
})
|
})
|
||||||
};
|
};
|
||||||
let doc_node = NodeCast::from_ref(self);
|
let doc_node = self.upcast::<Node>();
|
||||||
doc_node.traverse_preorder()
|
doc_node.traverse_preorder()
|
||||||
.filter_map(HTMLAnchorElementCast::to_root)
|
.filter_map(Root::downcast::<HTMLAnchorElement>)
|
||||||
.find(|node| check_anchor(&node.r()))
|
.find(|node| check_anchor(&node.r()))
|
||||||
.map(ElementCast::from_root)
|
.map(Root::upcast::<Element>)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -443,7 +440,7 @@ impl Document {
|
||||||
Some(root) => root,
|
Some(root) => root,
|
||||||
None => return None,
|
None => return None,
|
||||||
};
|
};
|
||||||
let root = NodeCast::from_ref(root);
|
let root = root.upcast::<Node>();
|
||||||
let address = match self.window.layout().hit_test(root.to_trusted_node_address(), *point) {
|
let address = match self.window.layout().hit_test(root.to_trusted_node_address(), *point) {
|
||||||
Ok(HitTestResponse(node_address)) => Some(node_address),
|
Ok(HitTestResponse(node_address)) => Some(node_address),
|
||||||
Err(()) => {
|
Err(()) => {
|
||||||
|
@ -460,7 +457,7 @@ impl Document {
|
||||||
Some(root) => root,
|
Some(root) => root,
|
||||||
None => return vec!(),
|
None => return vec!(),
|
||||||
};
|
};
|
||||||
let root = NodeCast::from_ref(root);
|
let root = root.upcast::<Node>();
|
||||||
match self.window.layout().mouse_over(root.to_trusted_node_address(), *point) {
|
match self.window.layout().mouse_over(root.to_trusted_node_address(), *point) {
|
||||||
Ok(MouseOverResponse(node_address)) => node_address,
|
Ok(MouseOverResponse(node_address)) => node_address,
|
||||||
Err(()) => vec!(),
|
Err(()) => vec!(),
|
||||||
|
@ -474,7 +471,7 @@ impl Document {
|
||||||
let event = Event::new(GlobalRef::Window(&self.window), "readystatechange".to_owned(),
|
let event = Event::new(GlobalRef::Window(&self.window), "readystatechange".to_owned(),
|
||||||
EventBubbles::DoesNotBubble,
|
EventBubbles::DoesNotBubble,
|
||||||
EventCancelable::NotCancelable);
|
EventCancelable::NotCancelable);
|
||||||
let target = EventTargetCast::from_ref(self);
|
let target = self.upcast::<EventTarget>();
|
||||||
let _ = event.r().fire(target);
|
let _ = event.r().fire(target);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -542,7 +539,7 @@ impl Document {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn dirty_all_nodes(&self) {
|
pub fn dirty_all_nodes(&self) {
|
||||||
let root = NodeCast::from_ref(self);
|
let root = self.upcast::<Node>();
|
||||||
for node in root.traverse_preorder() {
|
for node in root.traverse_preorder() {
|
||||||
node.r().dirty(NodeDamage::OtherNodeDamage)
|
node.r().dirty(NodeDamage::OtherNodeDamage)
|
||||||
}
|
}
|
||||||
|
@ -565,18 +562,18 @@ impl Document {
|
||||||
None => return,
|
None => return,
|
||||||
};
|
};
|
||||||
|
|
||||||
let el = match ElementCast::to_ref(node.r()) {
|
let el = match node.downcast::<Element>() {
|
||||||
Some(el) => Root::from_ref(el),
|
Some(el) => Root::from_ref(el),
|
||||||
None => {
|
None => {
|
||||||
let parent = node.r().GetParentNode();
|
let parent = node.r().GetParentNode();
|
||||||
match parent.and_then(ElementCast::to_root) {
|
match parent.and_then(Root::downcast::<Element>) {
|
||||||
Some(parent) => parent,
|
Some(parent) => parent,
|
||||||
None => return,
|
None => return,
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
let node = NodeCast::from_ref(el.r());
|
let node = el.upcast::<Node>();
|
||||||
debug!("{} on {:?}", mouse_event_type_string, node.debug_str());
|
debug!("{} on {:?}", mouse_event_type_string, node.debug_str());
|
||||||
// Prevent click event if form control element is disabled.
|
// Prevent click event if form control element is disabled.
|
||||||
if let MouseEventType::Click = mouse_event_type {
|
if let MouseEventType::Click = mouse_event_type {
|
||||||
|
@ -601,7 +598,7 @@ impl Document {
|
||||||
false, false, false, false,
|
false, false, false, false,
|
||||||
0i16,
|
0i16,
|
||||||
None);
|
None);
|
||||||
let event = EventCast::from_ref(event.r());
|
let event = event.upcast::<Event>();
|
||||||
|
|
||||||
// https://dvcs.w3.org/hg/dom3events/raw-file/tip/html/DOM3-Events.html#trusted-events
|
// https://dvcs.w3.org/hg/dom3events/raw-file/tip/html/DOM3-Events.html#trusted-events
|
||||||
event.set_trusted(true);
|
event.set_trusted(true);
|
||||||
|
@ -609,7 +606,7 @@ impl Document {
|
||||||
match mouse_event_type {
|
match mouse_event_type {
|
||||||
MouseEventType::Click => el.authentic_click_activation(event),
|
MouseEventType::Click => el.authentic_click_activation(event),
|
||||||
_ => {
|
_ => {
|
||||||
let target = EventTargetCast::from_ref(node);
|
let target = node.upcast::<EventTarget>();
|
||||||
event.fire(target);
|
event.fire(target);
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
@ -639,7 +636,7 @@ impl Document {
|
||||||
false, false, false, false,
|
false, false, false, false,
|
||||||
0i16,
|
0i16,
|
||||||
None);
|
None);
|
||||||
let event = EventCast::from_ref(mouse_event.r());
|
let event = mouse_event.upcast::<Event>();
|
||||||
event.fire(target);
|
event.fire(target);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -653,8 +650,8 @@ impl Document {
|
||||||
for node_address in &mouse_over_addresses {
|
for node_address in &mouse_over_addresses {
|
||||||
let node = node::from_untrusted_node_address(js_runtime, *node_address);
|
let node = node::from_untrusted_node_address(js_runtime, *node_address);
|
||||||
mouse_over_targets.push(node.r().inclusive_ancestors()
|
mouse_over_targets.push(node.r().inclusive_ancestors()
|
||||||
.find(|node| node.r().is_element())
|
.find(|node| node.is::<Element>())
|
||||||
.map(|node| JS::from_ref(ElementCast::to_ref(node.r()).unwrap()))
|
.map(|node| JS::from_ref(node.downcast::<Element>().unwrap()))
|
||||||
.unwrap());
|
.unwrap());
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -667,7 +664,7 @@ impl Document {
|
||||||
if target_ref.get_hover_state() {
|
if target_ref.get_hover_state() {
|
||||||
target_ref.set_hover_state(false);
|
target_ref.set_hover_state(false);
|
||||||
|
|
||||||
let target = EventTargetCast::from_ref(target_ref);
|
let target = target_ref.upcast::<EventTarget>();
|
||||||
|
|
||||||
self.fire_mouse_event(point, &target, "mouseout".to_owned());
|
self.fire_mouse_event(point, &target, "mouseout".to_owned());
|
||||||
}
|
}
|
||||||
|
@ -681,7 +678,7 @@ impl Document {
|
||||||
if !target.get_hover_state() {
|
if !target.get_hover_state() {
|
||||||
target.set_hover_state(true);
|
target.set_hover_state(true);
|
||||||
|
|
||||||
let target = EventTargetCast::from_ref(*target);
|
let target = target.upcast::<EventTarget>();
|
||||||
|
|
||||||
self.fire_mouse_event(point, target, "mouseover".to_owned());
|
self.fire_mouse_event(point, target, "mouseover".to_owned());
|
||||||
|
|
||||||
|
@ -693,7 +690,7 @@ impl Document {
|
||||||
let top_most_node =
|
let top_most_node =
|
||||||
node::from_untrusted_node_address(js_runtime, mouse_over_addresses[0]);
|
node::from_untrusted_node_address(js_runtime, mouse_over_addresses[0]);
|
||||||
|
|
||||||
let target = EventTargetCast::from_ref(top_most_node.r());
|
let target = top_most_node.upcast::<EventTarget>();
|
||||||
self.fire_mouse_event(point, target, "mousemove".to_owned());
|
self.fire_mouse_event(point, target, "mousemove".to_owned());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -716,9 +713,9 @@ impl Document {
|
||||||
let body = self.GetBody();
|
let body = self.GetBody();
|
||||||
|
|
||||||
let target = match (&focused, &body) {
|
let target = match (&focused, &body) {
|
||||||
(&Some(ref focused), _) => EventTargetCast::from_ref(focused.r()),
|
(&Some(ref focused), _) => focused.upcast::<EventTarget>(),
|
||||||
(&None, &Some(ref body)) => EventTargetCast::from_ref(body.r()),
|
(&None, &Some(ref body)) => body.upcast::<EventTarget>(),
|
||||||
(&None, &None) => EventTargetCast::from_ref(&*self.window),
|
(&None, &None) => self.window.upcast::<EventTarget>(),
|
||||||
};
|
};
|
||||||
|
|
||||||
let ctrl = modifiers.contains(CONTROL);
|
let ctrl = modifiers.contains(CONTROL);
|
||||||
|
@ -741,7 +738,7 @@ impl Document {
|
||||||
props.location, is_repeating, is_composing,
|
props.location, is_repeating, is_composing,
|
||||||
ctrl, alt, shift, meta,
|
ctrl, alt, shift, meta,
|
||||||
None, props.key_code);
|
None, props.key_code);
|
||||||
let event = EventCast::from_ref(keyevent.r());
|
let event = keyevent.upcast::<Event>();
|
||||||
event.fire(target);
|
event.fire(target);
|
||||||
let mut prevented = event.DefaultPrevented();
|
let mut prevented = event.DefaultPrevented();
|
||||||
|
|
||||||
|
@ -754,7 +751,7 @@ impl Document {
|
||||||
props.location, is_repeating, is_composing,
|
props.location, is_repeating, is_composing,
|
||||||
ctrl, alt, shift, meta,
|
ctrl, alt, shift, meta,
|
||||||
props.char_code, 0);
|
props.char_code, 0);
|
||||||
let ev = EventCast::from_ref(event.r());
|
let ev = event.upcast::<Event>();
|
||||||
ev.fire(target);
|
ev.fire(target);
|
||||||
prevented = ev.DefaultPrevented();
|
prevented = ev.DefaultPrevented();
|
||||||
// TODO: if keypress event is canceled, prevent firing input events
|
// TODO: if keypress event is canceled, prevent firing input events
|
||||||
|
@ -771,7 +768,7 @@ impl Document {
|
||||||
// https://www.w3.org/Bugs/Public/show_bug.cgi?id=27337
|
// https://www.w3.org/Bugs/Public/show_bug.cgi?id=27337
|
||||||
match key {
|
match key {
|
||||||
Key::Space if !prevented && state == KeyState::Released => {
|
Key::Space if !prevented && state == KeyState::Released => {
|
||||||
let maybe_elem: Option<&Element> = ElementCast::to_ref(target);
|
let maybe_elem: Option<&Element> = target.downcast::<Element>();
|
||||||
if let Some(el) = maybe_elem {
|
if let Some(el) = maybe_elem {
|
||||||
if let Some(a) = el.as_maybe_activatable() {
|
if let Some(a) = el.as_maybe_activatable() {
|
||||||
a.synthetic_click_activation(ctrl, alt, shift, meta);
|
a.synthetic_click_activation(ctrl, alt, shift, meta);
|
||||||
|
@ -779,7 +776,7 @@ impl Document {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Key::Enter if !prevented && state == KeyState::Released => {
|
Key::Enter if !prevented && state == KeyState::Released => {
|
||||||
let maybe_elem: Option<&Element> = ElementCast::to_ref(target);
|
let maybe_elem: Option<&Element> = target.downcast::<Element>();
|
||||||
if let Some(el) = maybe_elem {
|
if let Some(el) = maybe_elem {
|
||||||
if let Some(a) = el.as_maybe_activatable() {
|
if let Some(a) = el.as_maybe_activatable() {
|
||||||
a.implicit_submission(ctrl, alt, shift, meta);
|
a.implicit_submission(ctrl, alt, shift, meta);
|
||||||
|
@ -800,18 +797,18 @@ impl Document {
|
||||||
match nodes.into_iter().next().unwrap() {
|
match nodes.into_iter().next().unwrap() {
|
||||||
NodeOrString::eNode(node) => Ok(node),
|
NodeOrString::eNode(node) => Ok(node),
|
||||||
NodeOrString::eString(string) => {
|
NodeOrString::eString(string) => {
|
||||||
Ok(NodeCast::from_root(self.CreateTextNode(string)))
|
Ok(Root::upcast::<Node>(self.CreateTextNode(string)))
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
let fragment = NodeCast::from_root(self.CreateDocumentFragment());
|
let fragment = Root::upcast::<Node>(self.CreateDocumentFragment());
|
||||||
for node in nodes {
|
for node in nodes {
|
||||||
match node {
|
match node {
|
||||||
NodeOrString::eNode(node) => {
|
NodeOrString::eNode(node) => {
|
||||||
try!(fragment.r().AppendChild(node.r()));
|
try!(fragment.r().AppendChild(node.r()));
|
||||||
},
|
},
|
||||||
NodeOrString::eString(string) => {
|
NodeOrString::eString(string) => {
|
||||||
let node = NodeCast::from_root(self.CreateTextNode(string));
|
let node = Root::upcast::<Node>(self.CreateTextNode(string));
|
||||||
// No try!() here because appending a text node
|
// No try!() here because appending a text node
|
||||||
// should not fail.
|
// should not fail.
|
||||||
fragment.r().AppendChild(node.r()).unwrap();
|
fragment.r().AppendChild(node.r()).unwrap();
|
||||||
|
@ -823,17 +820,17 @@ impl Document {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn get_body_attribute(&self, local_name: &Atom) -> DOMString {
|
pub fn get_body_attribute(&self, local_name: &Atom) -> DOMString {
|
||||||
match self.GetBody().and_then(HTMLBodyElementCast::to_root) {
|
match self.GetBody().and_then(Root::downcast::<HTMLBodyElement>) {
|
||||||
Some(ref body) => {
|
Some(ref body) => {
|
||||||
ElementCast::from_ref(body.r()).get_string_attribute(local_name)
|
body.upcast::<Element>().get_string_attribute(local_name)
|
||||||
},
|
},
|
||||||
None => "".to_owned()
|
None => "".to_owned()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn set_body_attribute(&self, local_name: &Atom, value: DOMString) {
|
pub fn set_body_attribute(&self, local_name: &Atom, value: DOMString) {
|
||||||
if let Some(ref body) = self.GetBody().and_then(HTMLBodyElementCast::to_root) {
|
if let Some(ref body) = self.GetBody().and_then(Root::downcast::<HTMLBodyElement>) {
|
||||||
ElementCast::from_ref(body.r()).set_string_attribute(local_name, value);
|
body.upcast::<Element>().set_string_attribute(local_name, value);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -943,8 +940,8 @@ impl Document {
|
||||||
|
|
||||||
/// Find an iframe element in the document.
|
/// Find an iframe element in the document.
|
||||||
pub fn find_iframe(&self, subpage_id: SubpageId) -> Option<Root<HTMLIFrameElement>> {
|
pub fn find_iframe(&self, subpage_id: SubpageId) -> Option<Root<HTMLIFrameElement>> {
|
||||||
NodeCast::from_ref(self).traverse_preorder()
|
self.upcast::<Node>().traverse_preorder()
|
||||||
.filter_map(HTMLIFrameElementCast::to_root)
|
.filter_map(Root::downcast::<HTMLIFrameElement>)
|
||||||
.find(|node| node.r().subpage_id() == Some(subpage_id))
|
.find(|node| node.r().subpage_id() == Some(subpage_id))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1061,7 +1058,7 @@ impl Document {
|
||||||
GlobalRef::Window(window),
|
GlobalRef::Window(window),
|
||||||
DocumentBinding::Wrap);
|
DocumentBinding::Wrap);
|
||||||
{
|
{
|
||||||
let node = NodeCast::from_ref(document.r());
|
let node = document.upcast::<Node>();
|
||||||
node.set_owner_doc(document.r());
|
node.set_owner_doc(document.r());
|
||||||
}
|
}
|
||||||
document
|
document
|
||||||
|
@ -1069,7 +1066,7 @@ impl Document {
|
||||||
|
|
||||||
fn create_node_list<F: Fn(&Node) -> bool>(&self, callback: F) -> Root<NodeList> {
|
fn create_node_list<F: Fn(&Node) -> bool>(&self, callback: F) -> Root<NodeList> {
|
||||||
let doc = self.GetDocumentElement();
|
let doc = self.GetDocumentElement();
|
||||||
let maybe_node = doc.r().map(NodeCast::from_ref);
|
let maybe_node = doc.r().map(Castable::upcast::<Node>);
|
||||||
let iter = maybe_node.iter().flat_map(|node| node.traverse_preorder())
|
let iter = maybe_node.iter().flat_map(|node| node.traverse_preorder())
|
||||||
.filter(|node| callback(node.r()));
|
.filter(|node| callback(node.r()));
|
||||||
NodeList::new_simple_list(&self.window, iter)
|
NodeList::new_simple_list(&self.window, iter)
|
||||||
|
@ -1078,7 +1075,7 @@ impl Document {
|
||||||
fn get_html_element(&self) -> Option<Root<HTMLHtmlElement>> {
|
fn get_html_element(&self) -> Option<Root<HTMLHtmlElement>> {
|
||||||
self.GetDocumentElement()
|
self.GetDocumentElement()
|
||||||
.r()
|
.r()
|
||||||
.and_then(HTMLHtmlElementCast::to_ref)
|
.and_then(Castable::downcast::<HTMLHtmlElement>)
|
||||||
.map(Root::from_ref)
|
.map(Root::from_ref)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1102,7 +1099,7 @@ impl Document {
|
||||||
|
|
||||||
impl Element {
|
impl Element {
|
||||||
fn click_event_filter_by_disabled_state(&self) -> bool {
|
fn click_event_filter_by_disabled_state(&self) -> bool {
|
||||||
let node = NodeCast::from_ref(self);
|
let node = self.upcast::<Node>();
|
||||||
match node.type_id() {
|
match node.type_id() {
|
||||||
NodeTypeId::Element(ElementTypeId::HTMLElement(HTMLElementTypeId::HTMLButtonElement)) |
|
NodeTypeId::Element(ElementTypeId::HTMLElement(HTMLElementTypeId::HTMLButtonElement)) |
|
||||||
NodeTypeId::Element(ElementTypeId::HTMLElement(HTMLElementTypeId::HTMLInputElement)) |
|
NodeTypeId::Element(ElementTypeId::HTMLElement(HTMLElementTypeId::HTMLInputElement)) |
|
||||||
|
@ -1134,7 +1131,7 @@ impl DocumentMethods for Document {
|
||||||
match self.get_focused_element() {
|
match self.get_focused_element() {
|
||||||
Some(element) => Some(element), // Step 3. and 4.
|
Some(element) => Some(element), // Step 3. and 4.
|
||||||
None => match self.GetBody() { // Step 5.
|
None => match self.GetBody() { // Step 5.
|
||||||
Some(body) => Some(ElementCast::from_root(body)),
|
Some(body) => Some(Root::upcast::<Element>(body)),
|
||||||
None => self.GetDocumentElement(),
|
None => self.GetDocumentElement(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1189,32 +1186,32 @@ impl DocumentMethods for Document {
|
||||||
|
|
||||||
// https://dom.spec.whatwg.org/#dom-document-doctype
|
// https://dom.spec.whatwg.org/#dom-document-doctype
|
||||||
fn GetDoctype(&self) -> Option<Root<DocumentType>> {
|
fn GetDoctype(&self) -> Option<Root<DocumentType>> {
|
||||||
let node = NodeCast::from_ref(self);
|
let node = self.upcast::<Node>();
|
||||||
node.children()
|
node.children()
|
||||||
.filter_map(|c| DocumentTypeCast::to_ref(c.r()).map(Root::from_ref))
|
.filter_map(|c| c.downcast::<DocumentType>().map(Root::from_ref))
|
||||||
.next()
|
.next()
|
||||||
}
|
}
|
||||||
|
|
||||||
// https://dom.spec.whatwg.org/#dom-document-documentelement
|
// https://dom.spec.whatwg.org/#dom-document-documentelement
|
||||||
fn GetDocumentElement(&self) -> Option<Root<Element>> {
|
fn GetDocumentElement(&self) -> Option<Root<Element>> {
|
||||||
let node = NodeCast::from_ref(self);
|
let node = self.upcast::<Node>();
|
||||||
node.child_elements().next()
|
node.child_elements().next()
|
||||||
}
|
}
|
||||||
|
|
||||||
// https://dom.spec.whatwg.org/#dom-document-getelementsbytagname
|
// https://dom.spec.whatwg.org/#dom-document-getelementsbytagname
|
||||||
fn GetElementsByTagName(&self, tag_name: DOMString) -> Root<HTMLCollection> {
|
fn GetElementsByTagName(&self, tag_name: DOMString) -> Root<HTMLCollection> {
|
||||||
HTMLCollection::by_tag_name(&self.window, NodeCast::from_ref(self), tag_name)
|
HTMLCollection::by_tag_name(&self.window, self.upcast::<Node>(), tag_name)
|
||||||
}
|
}
|
||||||
|
|
||||||
// https://dom.spec.whatwg.org/#dom-document-getelementsbytagnamens
|
// https://dom.spec.whatwg.org/#dom-document-getelementsbytagnamens
|
||||||
fn GetElementsByTagNameNS(&self, maybe_ns: Option<DOMString>, tag_name: DOMString)
|
fn GetElementsByTagNameNS(&self, maybe_ns: Option<DOMString>, tag_name: DOMString)
|
||||||
-> Root<HTMLCollection> {
|
-> Root<HTMLCollection> {
|
||||||
HTMLCollection::by_tag_name_ns(&self.window, NodeCast::from_ref(self), tag_name, maybe_ns)
|
HTMLCollection::by_tag_name_ns(&self.window, self.upcast::<Node>(), tag_name, maybe_ns)
|
||||||
}
|
}
|
||||||
|
|
||||||
// https://dom.spec.whatwg.org/#dom-document-getelementsbyclassname
|
// https://dom.spec.whatwg.org/#dom-document-getelementsbyclassname
|
||||||
fn GetElementsByClassName(&self, classes: DOMString) -> Root<HTMLCollection> {
|
fn GetElementsByClassName(&self, classes: DOMString) -> Root<HTMLCollection> {
|
||||||
HTMLCollection::by_class_name(&self.window, NodeCast::from_ref(self), classes)
|
HTMLCollection::by_class_name(&self.window, self.upcast::<Node>(), classes)
|
||||||
}
|
}
|
||||||
|
|
||||||
// https://dom.spec.whatwg.org/#dom-nonelementparentnode-getelementbyid
|
// https://dom.spec.whatwg.org/#dom-nonelementparentnode-getelementbyid
|
||||||
|
@ -1307,7 +1304,7 @@ impl DocumentMethods for Document {
|
||||||
// https://dom.spec.whatwg.org/#dom-document-importnode
|
// https://dom.spec.whatwg.org/#dom-document-importnode
|
||||||
fn ImportNode(&self, node: &Node, deep: bool) -> Fallible<Root<Node>> {
|
fn ImportNode(&self, node: &Node, deep: bool) -> Fallible<Root<Node>> {
|
||||||
// Step 1.
|
// Step 1.
|
||||||
if node.is_document() {
|
if node.is::<Document>() {
|
||||||
return Err(Error::NotSupported);
|
return Err(Error::NotSupported);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1323,7 +1320,7 @@ impl DocumentMethods for Document {
|
||||||
// https://dom.spec.whatwg.org/#dom-document-adoptnode
|
// https://dom.spec.whatwg.org/#dom-document-adoptnode
|
||||||
fn AdoptNode(&self, node: &Node) -> Fallible<Root<Node>> {
|
fn AdoptNode(&self, node: &Node) -> Fallible<Root<Node>> {
|
||||||
// Step 1.
|
// Step 1.
|
||||||
if node.is_document() {
|
if node.is::<Document>() {
|
||||||
return Err(Error::NotSupported);
|
return Err(Error::NotSupported);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1338,17 +1335,17 @@ impl DocumentMethods for Document {
|
||||||
fn CreateEvent(&self, mut interface: DOMString) -> Fallible<Root<Event>> {
|
fn CreateEvent(&self, mut interface: DOMString) -> Fallible<Root<Event>> {
|
||||||
interface.make_ascii_lowercase();
|
interface.make_ascii_lowercase();
|
||||||
match &*interface {
|
match &*interface {
|
||||||
"uievents" | "uievent" => Ok(EventCast::from_root(
|
"uievents" | "uievent" => Ok(Root::upcast::<Event>(
|
||||||
UIEvent::new_uninitialized(&self.window))),
|
UIEvent::new_uninitialized(&self.window))),
|
||||||
"mouseevents" | "mouseevent" => Ok(EventCast::from_root(
|
"mouseevents" | "mouseevent" => Ok(Root::upcast::<Event>(
|
||||||
MouseEvent::new_uninitialized(&self.window))),
|
MouseEvent::new_uninitialized(&self.window))),
|
||||||
"customevent" => Ok(EventCast::from_root(
|
"customevent" => Ok(Root::upcast::<Event>(
|
||||||
CustomEvent::new_uninitialized(GlobalRef::Window(&self.window)))),
|
CustomEvent::new_uninitialized(GlobalRef::Window(&self.window)))),
|
||||||
"htmlevents" | "events" | "event" => Ok(Event::new_uninitialized(
|
"htmlevents" | "events" | "event" => Ok(Event::new_uninitialized(
|
||||||
GlobalRef::Window(&self.window))),
|
GlobalRef::Window(&self.window))),
|
||||||
"keyboardevent" | "keyevents" => Ok(EventCast::from_root(
|
"keyboardevent" | "keyevents" => Ok(Root::upcast::<Event>(
|
||||||
KeyboardEvent::new_uninitialized(&self.window))),
|
KeyboardEvent::new_uninitialized(&self.window))),
|
||||||
"messageevent" => Ok(EventCast::from_root(
|
"messageevent" => Ok(Root::upcast::<Event>(
|
||||||
MessageEvent::new_uninitialized(GlobalRef::Window(&self.window)))),
|
MessageEvent::new_uninitialized(GlobalRef::Window(&self.window)))),
|
||||||
_ => Err(Error::NotSupported)
|
_ => Err(Error::NotSupported)
|
||||||
}
|
}
|
||||||
|
@ -1384,15 +1381,15 @@ impl DocumentMethods for Document {
|
||||||
let title = self.GetDocumentElement().and_then(|root| {
|
let title = self.GetDocumentElement().and_then(|root| {
|
||||||
if root.r().namespace() == &ns!(SVG) && root.r().local_name() == &atom!("svg") {
|
if root.r().namespace() == &ns!(SVG) && root.r().local_name() == &atom!("svg") {
|
||||||
// Step 1.
|
// Step 1.
|
||||||
NodeCast::from_ref(root.r()).child_elements().find(|node| {
|
root.upcast::<Node>().child_elements().find(|node| {
|
||||||
node.r().namespace() == &ns!(SVG) &&
|
node.r().namespace() == &ns!(SVG) &&
|
||||||
node.r().local_name() == &atom!("title")
|
node.r().local_name() == &atom!("title")
|
||||||
}).map(NodeCast::from_root)
|
}).map(Root::upcast::<Node>)
|
||||||
} else {
|
} else {
|
||||||
// Step 2.
|
// Step 2.
|
||||||
NodeCast::from_ref(root.r())
|
root.upcast::<Node>()
|
||||||
.traverse_preorder()
|
.traverse_preorder()
|
||||||
.find(|node| node.r().is_htmltitleelement())
|
.find(|node| node.r().is::<HTMLTitleElement>())
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -1415,25 +1412,25 @@ impl DocumentMethods for Document {
|
||||||
|
|
||||||
let elem = if root.r().namespace() == &ns!(SVG) &&
|
let elem = if root.r().namespace() == &ns!(SVG) &&
|
||||||
root.r().local_name() == &atom!("svg") {
|
root.r().local_name() == &atom!("svg") {
|
||||||
let elem = NodeCast::from_ref(root.r()).child_elements().find(|node| {
|
let elem = root.upcast::<Node>().child_elements().find(|node| {
|
||||||
node.r().namespace() == &ns!(SVG) &&
|
node.r().namespace() == &ns!(SVG) &&
|
||||||
node.r().local_name() == &atom!("title")
|
node.r().local_name() == &atom!("title")
|
||||||
});
|
});
|
||||||
match elem {
|
match elem {
|
||||||
Some(elem) => NodeCast::from_root(elem),
|
Some(elem) => Root::upcast::<Node>(elem),
|
||||||
None => {
|
None => {
|
||||||
let name = QualName::new(ns!(SVG), atom!("title"));
|
let name = QualName::new(ns!(SVG), atom!("title"));
|
||||||
let elem = Element::create(name, None, self,
|
let elem = Element::create(name, None, self,
|
||||||
ElementCreator::ScriptCreated);
|
ElementCreator::ScriptCreated);
|
||||||
NodeCast::from_ref(root.r())
|
root.upcast::<Node>()
|
||||||
.AppendChild(NodeCast::from_ref(elem.r()))
|
.AppendChild(elem.upcast::<Node>())
|
||||||
.unwrap()
|
.unwrap()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else if root.r().namespace() == &ns!(HTML) {
|
} else if root.r().namespace() == &ns!(HTML) {
|
||||||
let elem = NodeCast::from_ref(root.r())
|
let elem = root.upcast::<Node>()
|
||||||
.traverse_preorder()
|
.traverse_preorder()
|
||||||
.find(|node| node.r().is_htmltitleelement());
|
.find(|node| node.r().is::<HTMLTitleElement>());
|
||||||
match elem {
|
match elem {
|
||||||
Some(elem) => elem,
|
Some(elem) => elem,
|
||||||
None => {
|
None => {
|
||||||
|
@ -1442,8 +1439,8 @@ impl DocumentMethods for Document {
|
||||||
let name = QualName::new(ns!(HTML), atom!("title"));
|
let name = QualName::new(ns!(HTML), atom!("title"));
|
||||||
let elem = Element::create(name, None, self,
|
let elem = Element::create(name, None, self,
|
||||||
ElementCreator::ScriptCreated);
|
ElementCreator::ScriptCreated);
|
||||||
NodeCast::from_ref(head.r())
|
head.upcast::<Node>()
|
||||||
.AppendChild(NodeCast::from_ref(elem.r()))
|
.AppendChild(elem.upcast::<Node>())
|
||||||
.unwrap()
|
.unwrap()
|
||||||
},
|
},
|
||||||
None => return,
|
None => return,
|
||||||
|
@ -1460,9 +1457,9 @@ impl DocumentMethods for Document {
|
||||||
// https://html.spec.whatwg.org/multipage/#dom-document-head
|
// https://html.spec.whatwg.org/multipage/#dom-document-head
|
||||||
fn GetHead(&self) -> Option<Root<HTMLHeadElement>> {
|
fn GetHead(&self) -> Option<Root<HTMLHeadElement>> {
|
||||||
self.get_html_element().and_then(|root| {
|
self.get_html_element().and_then(|root| {
|
||||||
let node = NodeCast::from_ref(root.r());
|
let node = root.upcast::<Node>();
|
||||||
node.children()
|
node.children()
|
||||||
.filter_map(|c| HTMLHeadElementCast::to_ref(c.r()).map(Root::from_ref))
|
.filter_map(|c| c.downcast::<HTMLHeadElement>().map(Root::from_ref))
|
||||||
.next()
|
.next()
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
@ -1475,7 +1472,7 @@ impl DocumentMethods for Document {
|
||||||
// https://html.spec.whatwg.org/multipage/#dom-document-body
|
// https://html.spec.whatwg.org/multipage/#dom-document-body
|
||||||
fn GetBody(&self) -> Option<Root<HTMLElement>> {
|
fn GetBody(&self) -> Option<Root<HTMLElement>> {
|
||||||
self.get_html_element().and_then(|root| {
|
self.get_html_element().and_then(|root| {
|
||||||
let node = NodeCast::from_ref(root.r());
|
let node = root.upcast::<Node>();
|
||||||
node.children().find(|child| {
|
node.children().find(|child| {
|
||||||
match child.r().type_id() {
|
match child.r().type_id() {
|
||||||
NodeTypeId::Element(ElementTypeId::HTMLElement(HTMLElementTypeId::HTMLBodyElement)) |
|
NodeTypeId::Element(ElementTypeId::HTMLElement(HTMLElementTypeId::HTMLBodyElement)) |
|
||||||
|
@ -1483,7 +1480,7 @@ impl DocumentMethods for Document {
|
||||||
_ => false
|
_ => false
|
||||||
}
|
}
|
||||||
}).map(|node| {
|
}).map(|node| {
|
||||||
Root::from_ref(HTMLElementCast::to_ref(node.r()).unwrap())
|
Root::from_ref(node.downcast::<HTMLElement>().unwrap())
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
@ -1496,7 +1493,7 @@ impl DocumentMethods for Document {
|
||||||
None => return Err(Error::HierarchyRequest),
|
None => return Err(Error::HierarchyRequest),
|
||||||
};
|
};
|
||||||
|
|
||||||
let node = NodeCast::from_ref(new_body);
|
let node = new_body.upcast::<Node>();
|
||||||
match node.type_id() {
|
match node.type_id() {
|
||||||
NodeTypeId::Element(ElementTypeId::HTMLElement(HTMLElementTypeId::HTMLBodyElement)) |
|
NodeTypeId::Element(ElementTypeId::HTMLElement(HTMLElementTypeId::HTMLBodyElement)) |
|
||||||
NodeTypeId::Element(ElementTypeId::HTMLElement(HTMLElementTypeId::HTMLFrameSetElement)) => {}
|
NodeTypeId::Element(ElementTypeId::HTMLElement(HTMLElementTypeId::HTMLFrameSetElement)) => {}
|
||||||
|
@ -1512,9 +1509,9 @@ impl DocumentMethods for Document {
|
||||||
match (self.get_html_element(), &old_body) {
|
match (self.get_html_element(), &old_body) {
|
||||||
// Step 3.
|
// Step 3.
|
||||||
(Some(ref root), &Some(ref child)) => {
|
(Some(ref root), &Some(ref child)) => {
|
||||||
let root = NodeCast::from_ref(root.r());
|
let root = root.upcast::<Node>();
|
||||||
let child = NodeCast::from_ref(child.r());
|
let child = child.upcast::<Node>();
|
||||||
let new_body = NodeCast::from_ref(new_body);
|
let new_body = new_body.upcast::<Node>();
|
||||||
assert!(root.ReplaceChild(new_body, child).is_ok())
|
assert!(root.ReplaceChild(new_body, child).is_ok())
|
||||||
},
|
},
|
||||||
|
|
||||||
|
@ -1523,8 +1520,8 @@ impl DocumentMethods for Document {
|
||||||
|
|
||||||
// Step 5.
|
// Step 5.
|
||||||
(Some(ref root), &None) => {
|
(Some(ref root), &None) => {
|
||||||
let root = NodeCast::from_ref(root.r());
|
let root = root.upcast::<Node>();
|
||||||
let new_body = NodeCast::from_ref(new_body);
|
let new_body = new_body.upcast::<Node>();
|
||||||
assert!(root.AppendChild(new_body).is_ok());
|
assert!(root.AppendChild(new_body).is_ok());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1534,7 +1531,7 @@ impl DocumentMethods for Document {
|
||||||
// https://html.spec.whatwg.org/multipage/#dom-document-getelementsbyname
|
// https://html.spec.whatwg.org/multipage/#dom-document-getelementsbyname
|
||||||
fn GetElementsByName(&self, name: DOMString) -> Root<NodeList> {
|
fn GetElementsByName(&self, name: DOMString) -> Root<NodeList> {
|
||||||
self.create_node_list(|node| {
|
self.create_node_list(|node| {
|
||||||
let element = match ElementCast::to_ref(node) {
|
let element = match node.downcast::<Element>() {
|
||||||
Some(element) => element,
|
Some(element) => element,
|
||||||
None => return false,
|
None => return false,
|
||||||
};
|
};
|
||||||
|
@ -1550,7 +1547,7 @@ impl DocumentMethods for Document {
|
||||||
// https://html.spec.whatwg.org/multipage/#dom-document-images
|
// https://html.spec.whatwg.org/multipage/#dom-document-images
|
||||||
fn Images(&self) -> Root<HTMLCollection> {
|
fn Images(&self) -> Root<HTMLCollection> {
|
||||||
self.images.or_init(|| {
|
self.images.or_init(|| {
|
||||||
let root = NodeCast::from_ref(self);
|
let root = self.upcast::<Node>();
|
||||||
let filter = box ImagesFilter;
|
let filter = box ImagesFilter;
|
||||||
HTMLCollection::create(&self.window, root, filter)
|
HTMLCollection::create(&self.window, root, filter)
|
||||||
})
|
})
|
||||||
|
@ -1559,7 +1556,7 @@ impl DocumentMethods for Document {
|
||||||
// https://html.spec.whatwg.org/multipage/#dom-document-embeds
|
// https://html.spec.whatwg.org/multipage/#dom-document-embeds
|
||||||
fn Embeds(&self) -> Root<HTMLCollection> {
|
fn Embeds(&self) -> Root<HTMLCollection> {
|
||||||
self.embeds.or_init(|| {
|
self.embeds.or_init(|| {
|
||||||
let root = NodeCast::from_ref(self);
|
let root = self.upcast::<Node>();
|
||||||
let filter = box EmbedsFilter;
|
let filter = box EmbedsFilter;
|
||||||
HTMLCollection::create(&self.window, root, filter)
|
HTMLCollection::create(&self.window, root, filter)
|
||||||
})
|
})
|
||||||
|
@ -1573,7 +1570,7 @@ impl DocumentMethods for Document {
|
||||||
// https://html.spec.whatwg.org/multipage/#dom-document-links
|
// https://html.spec.whatwg.org/multipage/#dom-document-links
|
||||||
fn Links(&self) -> Root<HTMLCollection> {
|
fn Links(&self) -> Root<HTMLCollection> {
|
||||||
self.links.or_init(|| {
|
self.links.or_init(|| {
|
||||||
let root = NodeCast::from_ref(self);
|
let root = self.upcast::<Node>();
|
||||||
let filter = box LinksFilter;
|
let filter = box LinksFilter;
|
||||||
HTMLCollection::create(&self.window, root, filter)
|
HTMLCollection::create(&self.window, root, filter)
|
||||||
})
|
})
|
||||||
|
@ -1582,7 +1579,7 @@ impl DocumentMethods for Document {
|
||||||
// https://html.spec.whatwg.org/multipage/#dom-document-forms
|
// https://html.spec.whatwg.org/multipage/#dom-document-forms
|
||||||
fn Forms(&self) -> Root<HTMLCollection> {
|
fn Forms(&self) -> Root<HTMLCollection> {
|
||||||
self.forms.or_init(|| {
|
self.forms.or_init(|| {
|
||||||
let root = NodeCast::from_ref(self);
|
let root = self.upcast::<Node>();
|
||||||
let filter = box FormsFilter;
|
let filter = box FormsFilter;
|
||||||
HTMLCollection::create(&self.window, root, filter)
|
HTMLCollection::create(&self.window, root, filter)
|
||||||
})
|
})
|
||||||
|
@ -1591,7 +1588,7 @@ impl DocumentMethods for Document {
|
||||||
// https://html.spec.whatwg.org/multipage/#dom-document-scripts
|
// https://html.spec.whatwg.org/multipage/#dom-document-scripts
|
||||||
fn Scripts(&self) -> Root<HTMLCollection> {
|
fn Scripts(&self) -> Root<HTMLCollection> {
|
||||||
self.scripts.or_init(|| {
|
self.scripts.or_init(|| {
|
||||||
let root = NodeCast::from_ref(self);
|
let root = self.upcast::<Node>();
|
||||||
let filter = box ScriptsFilter;
|
let filter = box ScriptsFilter;
|
||||||
HTMLCollection::create(&self.window, root, filter)
|
HTMLCollection::create(&self.window, root, filter)
|
||||||
})
|
})
|
||||||
|
@ -1600,7 +1597,7 @@ impl DocumentMethods for Document {
|
||||||
// https://html.spec.whatwg.org/multipage/#dom-document-anchors
|
// https://html.spec.whatwg.org/multipage/#dom-document-anchors
|
||||||
fn Anchors(&self) -> Root<HTMLCollection> {
|
fn Anchors(&self) -> Root<HTMLCollection> {
|
||||||
self.anchors.or_init(|| {
|
self.anchors.or_init(|| {
|
||||||
let root = NodeCast::from_ref(self);
|
let root = self.upcast::<Node>();
|
||||||
let filter = box AnchorsFilter;
|
let filter = box AnchorsFilter;
|
||||||
HTMLCollection::create(&self.window, root, filter)
|
HTMLCollection::create(&self.window, root, filter)
|
||||||
})
|
})
|
||||||
|
@ -1610,7 +1607,7 @@ impl DocumentMethods for Document {
|
||||||
fn Applets(&self) -> Root<HTMLCollection> {
|
fn Applets(&self) -> Root<HTMLCollection> {
|
||||||
// FIXME: This should be return OBJECT elements containing applets.
|
// FIXME: This should be return OBJECT elements containing applets.
|
||||||
self.applets.or_init(|| {
|
self.applets.or_init(|| {
|
||||||
let root = NodeCast::from_ref(self);
|
let root = self.upcast::<Node>();
|
||||||
let filter = box AppletsFilter;
|
let filter = box AppletsFilter;
|
||||||
HTMLCollection::create(&self.window, root, filter)
|
HTMLCollection::create(&self.window, root, filter)
|
||||||
})
|
})
|
||||||
|
@ -1623,43 +1620,43 @@ impl DocumentMethods for Document {
|
||||||
|
|
||||||
// https://dom.spec.whatwg.org/#dom-parentnode-children
|
// https://dom.spec.whatwg.org/#dom-parentnode-children
|
||||||
fn Children(&self) -> Root<HTMLCollection> {
|
fn Children(&self) -> Root<HTMLCollection> {
|
||||||
HTMLCollection::children(&self.window, NodeCast::from_ref(self))
|
HTMLCollection::children(&self.window, self.upcast::<Node>())
|
||||||
}
|
}
|
||||||
|
|
||||||
// https://dom.spec.whatwg.org/#dom-parentnode-firstelementchild
|
// https://dom.spec.whatwg.org/#dom-parentnode-firstelementchild
|
||||||
fn GetFirstElementChild(&self) -> Option<Root<Element>> {
|
fn GetFirstElementChild(&self) -> Option<Root<Element>> {
|
||||||
NodeCast::from_ref(self).child_elements().next()
|
self.upcast::<Node>().child_elements().next()
|
||||||
}
|
}
|
||||||
|
|
||||||
// https://dom.spec.whatwg.org/#dom-parentnode-lastelementchild
|
// https://dom.spec.whatwg.org/#dom-parentnode-lastelementchild
|
||||||
fn GetLastElementChild(&self) -> Option<Root<Element>> {
|
fn GetLastElementChild(&self) -> Option<Root<Element>> {
|
||||||
NodeCast::from_ref(self).rev_children().filter_map(ElementCast::to_root).next()
|
self.upcast::<Node>().rev_children().filter_map(Root::downcast::<Element>).next()
|
||||||
}
|
}
|
||||||
|
|
||||||
// https://dom.spec.whatwg.org/#dom-parentnode-childelementcount
|
// https://dom.spec.whatwg.org/#dom-parentnode-childelementcount
|
||||||
fn ChildElementCount(&self) -> u32 {
|
fn ChildElementCount(&self) -> u32 {
|
||||||
NodeCast::from_ref(self).child_elements().count() as u32
|
self.upcast::<Node>().child_elements().count() as u32
|
||||||
}
|
}
|
||||||
|
|
||||||
// https://dom.spec.whatwg.org/#dom-parentnode-prepend
|
// https://dom.spec.whatwg.org/#dom-parentnode-prepend
|
||||||
fn Prepend(&self, nodes: Vec<NodeOrString>) -> ErrorResult {
|
fn Prepend(&self, nodes: Vec<NodeOrString>) -> ErrorResult {
|
||||||
NodeCast::from_ref(self).prepend(nodes)
|
self.upcast::<Node>().prepend(nodes)
|
||||||
}
|
}
|
||||||
|
|
||||||
// https://dom.spec.whatwg.org/#dom-parentnode-append
|
// https://dom.spec.whatwg.org/#dom-parentnode-append
|
||||||
fn Append(&self, nodes: Vec<NodeOrString>) -> ErrorResult {
|
fn Append(&self, nodes: Vec<NodeOrString>) -> ErrorResult {
|
||||||
NodeCast::from_ref(self).append(nodes)
|
self.upcast::<Node>().append(nodes)
|
||||||
}
|
}
|
||||||
|
|
||||||
// https://dom.spec.whatwg.org/#dom-parentnode-queryselector
|
// https://dom.spec.whatwg.org/#dom-parentnode-queryselector
|
||||||
fn QuerySelector(&self, selectors: DOMString) -> Fallible<Option<Root<Element>>> {
|
fn QuerySelector(&self, selectors: DOMString) -> Fallible<Option<Root<Element>>> {
|
||||||
let root = NodeCast::from_ref(self);
|
let root = self.upcast::<Node>();
|
||||||
root.query_selector(selectors)
|
root.query_selector(selectors)
|
||||||
}
|
}
|
||||||
|
|
||||||
// https://dom.spec.whatwg.org/#dom-parentnode-queryselectorall
|
// https://dom.spec.whatwg.org/#dom-parentnode-queryselectorall
|
||||||
fn QuerySelectorAll(&self, selectors: DOMString) -> Fallible<Root<NodeList>> {
|
fn QuerySelectorAll(&self, selectors: DOMString) -> Fallible<Root<NodeList>> {
|
||||||
let root = NodeCast::from_ref(self);
|
let root = self.upcast::<Node>();
|
||||||
root.query_selector_all(selectors)
|
root.query_selector_all(selectors)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1716,7 +1713,7 @@ impl DocumentMethods for Document {
|
||||||
}
|
}
|
||||||
impl CollectionFilter for NamedElementFilter {
|
impl CollectionFilter for NamedElementFilter {
|
||||||
fn filter(&self, elem: &Element, _root: &Node) -> bool {
|
fn filter(&self, elem: &Element, _root: &Node) -> bool {
|
||||||
filter_by_name(&self.name, NodeCast::from_ref(elem))
|
filter_by_name(&self.name, elem.upcast::<Node>())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// https://html.spec.whatwg.org/multipage/#dom-document-nameditem-filter
|
// https://html.spec.whatwg.org/multipage/#dom-document-nameditem-filter
|
||||||
|
@ -1725,7 +1722,7 @@ impl DocumentMethods for Document {
|
||||||
NodeTypeId::Element(ElementTypeId::HTMLElement(type_)) => type_,
|
NodeTypeId::Element(ElementTypeId::HTMLElement(type_)) => type_,
|
||||||
_ => return false,
|
_ => return false,
|
||||||
};
|
};
|
||||||
let elem = match ElementCast::to_ref(node) {
|
let elem = match node.downcast::<Element>() {
|
||||||
Some(elem) => elem,
|
Some(elem) => elem,
|
||||||
None => return false,
|
None => return false,
|
||||||
};
|
};
|
||||||
|
@ -1767,7 +1764,7 @@ impl DocumentMethods for Document {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
let name = Atom::from_slice(&name);
|
let name = Atom::from_slice(&name);
|
||||||
let root = NodeCast::from_ref(self);
|
let root = self.upcast::<Node>();
|
||||||
{
|
{
|
||||||
// Step 1.
|
// Step 1.
|
||||||
let mut elements = root.traverse_preorder().filter(|node| {
|
let mut elements = root.traverse_preorder().filter(|node| {
|
||||||
|
@ -1849,7 +1846,7 @@ impl DocumentProgressHandler {
|
||||||
let event = Event::new(GlobalRef::Window(window), "DOMContentLoaded".to_owned(),
|
let event = Event::new(GlobalRef::Window(window), "DOMContentLoaded".to_owned(),
|
||||||
EventBubbles::DoesNotBubble,
|
EventBubbles::DoesNotBubble,
|
||||||
EventCancelable::NotCancelable);
|
EventCancelable::NotCancelable);
|
||||||
let doctarget = EventTargetCast::from_ref(document.r());
|
let doctarget = document.upcast::<EventTarget>();
|
||||||
let _ = doctarget.DispatchEvent(event.r());
|
let _ = doctarget.DispatchEvent(event.r());
|
||||||
|
|
||||||
window.reflow(ReflowGoal::ForDisplay,
|
window.reflow(ReflowGoal::ForDisplay,
|
||||||
|
@ -1868,8 +1865,8 @@ impl DocumentProgressHandler {
|
||||||
let event = Event::new(GlobalRef::Window(window), "load".to_owned(),
|
let event = Event::new(GlobalRef::Window(window), "load".to_owned(),
|
||||||
EventBubbles::DoesNotBubble,
|
EventBubbles::DoesNotBubble,
|
||||||
EventCancelable::NotCancelable);
|
EventCancelable::NotCancelable);
|
||||||
let wintarget = EventTargetCast::from_ref(window);
|
let wintarget = window.upcast::<EventTarget>();
|
||||||
let doctarget = EventTargetCast::from_ref(document.r());
|
let doctarget = document.upcast::<EventTarget>();
|
||||||
event.r().set_trusted(true);
|
event.r().set_trusted(true);
|
||||||
let _ = wintarget.dispatch_event_with_target(doctarget, event.r());
|
let _ = wintarget.dispatch_event_with_target(doctarget, event.r());
|
||||||
|
|
||||||
|
@ -1881,7 +1878,7 @@ impl DocumentProgressHandler {
|
||||||
let event = Event::new(GlobalRef::Window(frame_window.r()), "load".to_owned(),
|
let event = Event::new(GlobalRef::Window(frame_window.r()), "load".to_owned(),
|
||||||
EventBubbles::DoesNotBubble,
|
EventBubbles::DoesNotBubble,
|
||||||
EventCancelable::NotCancelable);
|
EventCancelable::NotCancelable);
|
||||||
let target = EventTargetCast::from_ref(frame_element);
|
let target = frame_element.upcast::<EventTarget>();
|
||||||
event.r().fire(target);
|
event.r().fire(target);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -5,8 +5,8 @@
|
||||||
use dom::bindings::codegen::Bindings::DocumentFragmentBinding;
|
use dom::bindings::codegen::Bindings::DocumentFragmentBinding;
|
||||||
use dom::bindings::codegen::Bindings::DocumentFragmentBinding::DocumentFragmentMethods;
|
use dom::bindings::codegen::Bindings::DocumentFragmentBinding::DocumentFragmentMethods;
|
||||||
use dom::bindings::codegen::Bindings::WindowBinding::WindowMethods;
|
use dom::bindings::codegen::Bindings::WindowBinding::WindowMethods;
|
||||||
use dom::bindings::codegen::InheritTypes::{ElementCast, NodeCast};
|
|
||||||
use dom::bindings::codegen::UnionTypes::NodeOrString;
|
use dom::bindings::codegen::UnionTypes::NodeOrString;
|
||||||
|
use dom::bindings::conversions::Castable;
|
||||||
use dom::bindings::error::{ErrorResult, Fallible};
|
use dom::bindings::error::{ErrorResult, Fallible};
|
||||||
use dom::bindings::global::GlobalRef;
|
use dom::bindings::global::GlobalRef;
|
||||||
use dom::bindings::js::Root;
|
use dom::bindings::js::Root;
|
||||||
|
@ -48,14 +48,14 @@ impl DocumentFragmentMethods for DocumentFragment {
|
||||||
// https://dom.spec.whatwg.org/#dom-parentnode-children
|
// https://dom.spec.whatwg.org/#dom-parentnode-children
|
||||||
fn Children(&self) -> Root<HTMLCollection> {
|
fn Children(&self) -> Root<HTMLCollection> {
|
||||||
let window = window_from_node(self);
|
let window = window_from_node(self);
|
||||||
HTMLCollection::children(window.r(), NodeCast::from_ref(self))
|
HTMLCollection::children(window.r(), self.upcast::<Node>())
|
||||||
}
|
}
|
||||||
|
|
||||||
// https://dom.spec.whatwg.org/#dom-nonelementparentnode-getelementbyid
|
// https://dom.spec.whatwg.org/#dom-nonelementparentnode-getelementbyid
|
||||||
fn GetElementById(&self, id: DOMString) -> Option<Root<Element>> {
|
fn GetElementById(&self, id: DOMString) -> Option<Root<Element>> {
|
||||||
let node = NodeCast::from_ref(self);
|
let node = self.upcast::<Node>();
|
||||||
let id = Atom::from_slice(&id);
|
let id = Atom::from_slice(&id);
|
||||||
node.traverse_preorder().filter_map(ElementCast::to_root).find(|descendant| {
|
node.traverse_preorder().filter_map(Root::downcast::<Element>).find(|descendant| {
|
||||||
match descendant.get_attribute(&ns!(""), &atom!(id)) {
|
match descendant.get_attribute(&ns!(""), &atom!(id)) {
|
||||||
None => false,
|
None => false,
|
||||||
Some(attr) => *attr.value().as_atom() == id,
|
Some(attr) => *attr.value().as_atom() == id,
|
||||||
|
@ -65,38 +65,38 @@ impl DocumentFragmentMethods for DocumentFragment {
|
||||||
|
|
||||||
// https://dom.spec.whatwg.org/#dom-parentnode-firstelementchild
|
// https://dom.spec.whatwg.org/#dom-parentnode-firstelementchild
|
||||||
fn GetFirstElementChild(&self) -> Option<Root<Element>> {
|
fn GetFirstElementChild(&self) -> Option<Root<Element>> {
|
||||||
NodeCast::from_ref(self).child_elements().next()
|
self.upcast::<Node>().child_elements().next()
|
||||||
}
|
}
|
||||||
|
|
||||||
// https://dom.spec.whatwg.org/#dom-parentnode-lastelementchild
|
// https://dom.spec.whatwg.org/#dom-parentnode-lastelementchild
|
||||||
fn GetLastElementChild(&self) -> Option<Root<Element>> {
|
fn GetLastElementChild(&self) -> Option<Root<Element>> {
|
||||||
NodeCast::from_ref(self).rev_children().filter_map(ElementCast::to_root).next()
|
self.upcast::<Node>().rev_children().filter_map(Root::downcast::<Element>).next()
|
||||||
}
|
}
|
||||||
|
|
||||||
// https://dom.spec.whatwg.org/#dom-parentnode-childelementcount
|
// https://dom.spec.whatwg.org/#dom-parentnode-childelementcount
|
||||||
fn ChildElementCount(&self) -> u32 {
|
fn ChildElementCount(&self) -> u32 {
|
||||||
NodeCast::from_ref(self).child_elements().count() as u32
|
self.upcast::<Node>().child_elements().count() as u32
|
||||||
}
|
}
|
||||||
|
|
||||||
// https://dom.spec.whatwg.org/#dom-parentnode-prepend
|
// https://dom.spec.whatwg.org/#dom-parentnode-prepend
|
||||||
fn Prepend(&self, nodes: Vec<NodeOrString>) -> ErrorResult {
|
fn Prepend(&self, nodes: Vec<NodeOrString>) -> ErrorResult {
|
||||||
NodeCast::from_ref(self).prepend(nodes)
|
self.upcast::<Node>().prepend(nodes)
|
||||||
}
|
}
|
||||||
|
|
||||||
// https://dom.spec.whatwg.org/#dom-parentnode-append
|
// https://dom.spec.whatwg.org/#dom-parentnode-append
|
||||||
fn Append(&self, nodes: Vec<NodeOrString>) -> ErrorResult {
|
fn Append(&self, nodes: Vec<NodeOrString>) -> ErrorResult {
|
||||||
NodeCast::from_ref(self).append(nodes)
|
self.upcast::<Node>().append(nodes)
|
||||||
}
|
}
|
||||||
|
|
||||||
// https://dom.spec.whatwg.org/#dom-parentnode-queryselector
|
// https://dom.spec.whatwg.org/#dom-parentnode-queryselector
|
||||||
fn QuerySelector(&self, selectors: DOMString) -> Fallible<Option<Root<Element>>> {
|
fn QuerySelector(&self, selectors: DOMString) -> Fallible<Option<Root<Element>>> {
|
||||||
let root = NodeCast::from_ref(self);
|
let root = self.upcast::<Node>();
|
||||||
root.query_selector(selectors)
|
root.query_selector(selectors)
|
||||||
}
|
}
|
||||||
|
|
||||||
// https://dom.spec.whatwg.org/#dom-parentnode-queryselectorall
|
// https://dom.spec.whatwg.org/#dom-parentnode-queryselectorall
|
||||||
fn QuerySelectorAll(&self, selectors: DOMString) -> Fallible<Root<NodeList>> {
|
fn QuerySelectorAll(&self, selectors: DOMString) -> Fallible<Root<NodeList>> {
|
||||||
let root = NodeCast::from_ref(self);
|
let root = self.upcast::<Node>();
|
||||||
root.query_selector_all(selectors)
|
root.query_selector_all(selectors)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,8 +4,8 @@
|
||||||
|
|
||||||
use dom::bindings::codegen::Bindings::DocumentTypeBinding;
|
use dom::bindings::codegen::Bindings::DocumentTypeBinding;
|
||||||
use dom::bindings::codegen::Bindings::DocumentTypeBinding::DocumentTypeMethods;
|
use dom::bindings::codegen::Bindings::DocumentTypeBinding::DocumentTypeMethods;
|
||||||
use dom::bindings::codegen::InheritTypes::NodeCast;
|
|
||||||
use dom::bindings::codegen::UnionTypes::NodeOrString;
|
use dom::bindings::codegen::UnionTypes::NodeOrString;
|
||||||
|
use dom::bindings::conversions::Castable;
|
||||||
use dom::bindings::error::ErrorResult;
|
use dom::bindings::error::ErrorResult;
|
||||||
use dom::bindings::js::Root;
|
use dom::bindings::js::Root;
|
||||||
use dom::document::Document;
|
use dom::document::Document;
|
||||||
|
@ -83,22 +83,22 @@ impl DocumentTypeMethods for DocumentType {
|
||||||
|
|
||||||
// https://dom.spec.whatwg.org/#dom-childnode-before
|
// https://dom.spec.whatwg.org/#dom-childnode-before
|
||||||
fn Before(&self, nodes: Vec<NodeOrString>) -> ErrorResult {
|
fn Before(&self, nodes: Vec<NodeOrString>) -> ErrorResult {
|
||||||
NodeCast::from_ref(self).before(nodes)
|
self.upcast::<Node>().before(nodes)
|
||||||
}
|
}
|
||||||
|
|
||||||
// https://dom.spec.whatwg.org/#dom-childnode-after
|
// https://dom.spec.whatwg.org/#dom-childnode-after
|
||||||
fn After(&self, nodes: Vec<NodeOrString>) -> ErrorResult {
|
fn After(&self, nodes: Vec<NodeOrString>) -> ErrorResult {
|
||||||
NodeCast::from_ref(self).after(nodes)
|
self.upcast::<Node>().after(nodes)
|
||||||
}
|
}
|
||||||
|
|
||||||
// https://dom.spec.whatwg.org/#dom-childnode-replacewith
|
// https://dom.spec.whatwg.org/#dom-childnode-replacewith
|
||||||
fn ReplaceWith(&self, nodes: Vec<NodeOrString>) -> ErrorResult {
|
fn ReplaceWith(&self, nodes: Vec<NodeOrString>) -> ErrorResult {
|
||||||
NodeCast::from_ref(self).replace_with(nodes)
|
self.upcast::<Node>().replace_with(nodes)
|
||||||
}
|
}
|
||||||
|
|
||||||
// https://dom.spec.whatwg.org/#dom-childnode-remove
|
// https://dom.spec.whatwg.org/#dom-childnode-remove
|
||||||
fn Remove(&self) {
|
fn Remove(&self) {
|
||||||
let node = NodeCast::from_ref(self);
|
let node = self.upcast::<Node>();
|
||||||
node.remove_self();
|
node.remove_self();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,7 +7,7 @@ use dom::bindings::codegen::Bindings::DOMImplementationBinding;
|
||||||
use dom::bindings::codegen::Bindings::DOMImplementationBinding::DOMImplementationMethods;
|
use dom::bindings::codegen::Bindings::DOMImplementationBinding::DOMImplementationMethods;
|
||||||
use dom::bindings::codegen::Bindings::DocumentBinding::DocumentMethods;
|
use dom::bindings::codegen::Bindings::DocumentBinding::DocumentMethods;
|
||||||
use dom::bindings::codegen::Bindings::NodeBinding::NodeMethods;
|
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::error::Fallible;
|
||||||
use dom::bindings::global::GlobalRef;
|
use dom::bindings::global::GlobalRef;
|
||||||
use dom::bindings::js::{JS, Root};
|
use dom::bindings::js::{JS, Root};
|
||||||
|
@ -20,6 +20,7 @@ use dom::htmlbodyelement::HTMLBodyElement;
|
||||||
use dom::htmlheadelement::HTMLHeadElement;
|
use dom::htmlheadelement::HTMLHeadElement;
|
||||||
use dom::htmlhtmlelement::HTMLHtmlElement;
|
use dom::htmlhtmlelement::HTMLHtmlElement;
|
||||||
use dom::htmltitleelement::HTMLTitleElement;
|
use dom::htmltitleelement::HTMLTitleElement;
|
||||||
|
use dom::node::Node;
|
||||||
use dom::text::Text;
|
use dom::text::Text;
|
||||||
use std::borrow::ToOwned;
|
use std::borrow::ToOwned;
|
||||||
use util::str::DOMString;
|
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.
|
// Step 4.
|
||||||
match maybe_doctype {
|
match maybe_doctype {
|
||||||
None => (),
|
None => (),
|
||||||
Some(ref doctype) => {
|
Some(ref doctype) => {
|
||||||
let doc_type = NodeCast::from_ref(*doctype);
|
let doc_type = doctype.upcast::<Node>();
|
||||||
assert!(doc_node.AppendChild(doc_type).is_ok())
|
assert!(doc_node.AppendChild(doc_type).is_ok())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -91,7 +92,7 @@ impl DOMImplementationMethods for DOMImplementation {
|
||||||
match maybe_elem {
|
match maybe_elem {
|
||||||
None => (),
|
None => (),
|
||||||
Some(ref elem) => {
|
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.
|
// 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());
|
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.
|
// Step 4.
|
||||||
let doc_node = NodeCast::from_ref(doc.r());
|
let doc_node = doc.upcast::<Node>();
|
||||||
let doc_html = NodeCast::from_root(
|
let doc_html = Root::upcast::<Node>(
|
||||||
HTMLHtmlElement::new("html".to_owned(), None, doc.r()));
|
HTMLHtmlElement::new("html".to_owned(), None, doc.r()));
|
||||||
assert!(doc_node.AppendChild(doc_html.r()).is_ok());
|
assert!(doc_node.AppendChild(doc_html.r()).is_ok());
|
||||||
|
|
||||||
{
|
{
|
||||||
// Step 5.
|
// Step 5.
|
||||||
let doc_head = NodeCast::from_root(
|
let doc_head = Root::upcast::<Node>(
|
||||||
HTMLHeadElement::new("head".to_owned(), None, doc.r()));
|
HTMLHeadElement::new("head".to_owned(), None, doc.r()));
|
||||||
assert!(doc_html.r().AppendChild(doc_head.r()).is_ok());
|
assert!(doc_html.r().AppendChild(doc_head.r()).is_ok());
|
||||||
|
|
||||||
|
@ -137,20 +138,20 @@ impl DOMImplementationMethods for DOMImplementation {
|
||||||
None => (),
|
None => (),
|
||||||
Some(title_str) => {
|
Some(title_str) => {
|
||||||
// Step 6.1.
|
// Step 6.1.
|
||||||
let doc_title = NodeCast::from_root(
|
let doc_title = Root::upcast::<Node>(
|
||||||
HTMLTitleElement::new("title".to_owned(), None, doc.r()));
|
HTMLTitleElement::new("title".to_owned(), None, doc.r()));
|
||||||
assert!(doc_head.r().AppendChild(doc_title.r()).is_ok());
|
assert!(doc_head.r().AppendChild(doc_title.r()).is_ok());
|
||||||
|
|
||||||
// Step 6.2.
|
// Step 6.2.
|
||||||
let title_text = Text::new(title_str, doc.r());
|
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.
|
// Step 7.
|
||||||
let doc_body = HTMLBodyElement::new("body".to_owned(), None, doc.r());
|
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.
|
// Step 8.
|
||||||
|
|
|
@ -19,39 +19,44 @@ use dom::bindings::codegen::Bindings::HTMLInputElementBinding::HTMLInputElementM
|
||||||
use dom::bindings::codegen::Bindings::HTMLTemplateElementBinding::HTMLTemplateElementMethods;
|
use dom::bindings::codegen::Bindings::HTMLTemplateElementBinding::HTMLTemplateElementMethods;
|
||||||
use dom::bindings::codegen::Bindings::NamedNodeMapBinding::NamedNodeMapMethods;
|
use dom::bindings::codegen::Bindings::NamedNodeMapBinding::NamedNodeMapMethods;
|
||||||
use dom::bindings::codegen::Bindings::NodeBinding::NodeMethods;
|
use dom::bindings::codegen::Bindings::NodeBinding::NodeMethods;
|
||||||
use dom::bindings::codegen::InheritTypes::{CharacterDataCast, DocumentDerived, ElementCast};
|
use dom::bindings::codegen::InheritTypes::{ElementTypeId, HTMLElementTypeId, NodeTypeId};
|
||||||
use dom::bindings::codegen::InheritTypes::{ElementDerived, ElementTypeId, EventTargetCast};
|
|
||||||
use dom::bindings::codegen::InheritTypes::{HTMLAnchorElementCast, HTMLBodyElementCast};
|
|
||||||
use dom::bindings::codegen::InheritTypes::{HTMLElementTypeId, HTMLFieldSetElementDerived, HTMLFontElementCast};
|
|
||||||
use dom::bindings::codegen::InheritTypes::{HTMLIFrameElementCast, HTMLInputElementCast};
|
|
||||||
use dom::bindings::codegen::InheritTypes::{HTMLLegendElementDerived, HTMLOptGroupElementDerived};
|
|
||||||
use dom::bindings::codegen::InheritTypes::{HTMLTableCellElementCast, HTMLTableElementCast};
|
|
||||||
use dom::bindings::codegen::InheritTypes::{HTMLTableRowElementCast, HTMLTableSectionElementCast};
|
|
||||||
use dom::bindings::codegen::InheritTypes::{HTMLTemplateElementCast, HTMLTextAreaElementCast};
|
|
||||||
use dom::bindings::codegen::InheritTypes::{NodeCast, NodeTypeId, TextCast};
|
|
||||||
use dom::bindings::codegen::UnionTypes::NodeOrString;
|
use dom::bindings::codegen::UnionTypes::NodeOrString;
|
||||||
|
use dom::bindings::conversions::Castable;
|
||||||
use dom::bindings::error::{Error, ErrorResult, Fallible};
|
use dom::bindings::error::{Error, ErrorResult, Fallible};
|
||||||
use dom::bindings::global::GlobalRef;
|
use dom::bindings::global::GlobalRef;
|
||||||
use dom::bindings::js::{JS, LayoutJS, MutNullableHeap};
|
use dom::bindings::js::{JS, LayoutJS, MutNullableHeap};
|
||||||
use dom::bindings::js::{Root, RootedReference};
|
use dom::bindings::js::{Root, RootedReference};
|
||||||
use dom::bindings::utils::XMLName::InvalidXMLName;
|
use dom::bindings::utils::XMLName::InvalidXMLName;
|
||||||
use dom::bindings::utils::{namespace_from_domstring, validate_and_extract, xml_name_type};
|
use dom::bindings::utils::{namespace_from_domstring, validate_and_extract, xml_name_type};
|
||||||
|
use dom::characterdata::CharacterData;
|
||||||
use dom::create::create_element;
|
use dom::create::create_element;
|
||||||
use dom::document::{Document, LayoutDocumentHelpers};
|
use dom::document::{Document, LayoutDocumentHelpers};
|
||||||
use dom::domrect::DOMRect;
|
use dom::domrect::DOMRect;
|
||||||
use dom::domrectlist::DOMRectList;
|
use dom::domrectlist::DOMRectList;
|
||||||
use dom::domtokenlist::DOMTokenList;
|
use dom::domtokenlist::DOMTokenList;
|
||||||
use dom::event::Event;
|
use dom::event::Event;
|
||||||
|
use dom::eventtarget::EventTarget;
|
||||||
|
use dom::htmlanchorelement::HTMLAnchorElement;
|
||||||
|
use dom::htmlbodyelement::HTMLBodyElement;
|
||||||
use dom::htmlcollection::HTMLCollection;
|
use dom::htmlcollection::HTMLCollection;
|
||||||
|
use dom::htmlfieldsetelement::HTMLFieldSetElement;
|
||||||
|
use dom::htmlfontelement::HTMLFontElement;
|
||||||
|
use dom::htmliframeelement::HTMLIFrameElement;
|
||||||
use dom::htmlinputelement::{HTMLInputElement, RawLayoutHTMLInputElementHelpers};
|
use dom::htmlinputelement::{HTMLInputElement, RawLayoutHTMLInputElementHelpers};
|
||||||
use dom::htmltablecellelement::HTMLTableCellElementLayoutHelpers;
|
use dom::htmllegendelement::HTMLLegendElement;
|
||||||
|
use dom::htmloptgroupelement::HTMLOptGroupElement;
|
||||||
|
use dom::htmltablecellelement::{HTMLTableCellElement, HTMLTableCellElementLayoutHelpers};
|
||||||
use dom::htmltableelement::HTMLTableElement;
|
use dom::htmltableelement::HTMLTableElement;
|
||||||
use dom::htmltextareaelement::RawLayoutHTMLTextAreaElementHelpers;
|
use dom::htmltablerowelement::HTMLTableRowElement;
|
||||||
|
use dom::htmltablesectionelement::HTMLTableSectionElement;
|
||||||
|
use dom::htmltemplateelement::HTMLTemplateElement;
|
||||||
|
use dom::htmltextareaelement::{HTMLTextAreaElement, RawLayoutHTMLTextAreaElementHelpers};
|
||||||
use dom::namednodemap::NamedNodeMap;
|
use dom::namednodemap::NamedNodeMap;
|
||||||
use dom::node::{CLICK_IN_PROGRESS, LayoutNodeHelpers, Node};
|
use dom::node::{CLICK_IN_PROGRESS, LayoutNodeHelpers, Node};
|
||||||
use dom::node::{NodeDamage, SEQUENTIALLY_FOCUSABLE};
|
use dom::node::{NodeDamage, SEQUENTIALLY_FOCUSABLE};
|
||||||
use dom::node::{document_from_node, window_from_node};
|
use dom::node::{document_from_node, window_from_node};
|
||||||
use dom::nodelist::NodeList;
|
use dom::nodelist::NodeList;
|
||||||
|
use dom::text::Text;
|
||||||
use dom::virtualmethods::{VirtualMethods, vtable_for};
|
use dom::virtualmethods::{VirtualMethods, vtable_for};
|
||||||
use html5ever::serialize;
|
use html5ever::serialize;
|
||||||
use html5ever::serialize::SerializeOpts;
|
use html5ever::serialize::SerializeOpts;
|
||||||
|
@ -281,15 +286,15 @@ impl LayoutElementHelpers for LayoutJS<Element> {
|
||||||
unsafe fn synthesize_presentational_hints_for_legacy_attributes<V>(&self, hints: &mut V)
|
unsafe fn synthesize_presentational_hints_for_legacy_attributes<V>(&self, hints: &mut V)
|
||||||
where V: VecLike<DeclarationBlock<Vec<PropertyDeclaration>>>
|
where V: VecLike<DeclarationBlock<Vec<PropertyDeclaration>>>
|
||||||
{
|
{
|
||||||
let bgcolor = if let Some(this) = HTMLBodyElementCast::to_layout_js(self) {
|
let bgcolor = if let Some(this) = self.downcast::<HTMLBodyElement>() {
|
||||||
(*this.unsafe_get()).get_background_color()
|
(*this.unsafe_get()).get_background_color()
|
||||||
} else if let Some(this) = HTMLTableElementCast::to_layout_js(self) {
|
} else if let Some(this) = self.downcast::<HTMLTableElement>() {
|
||||||
(*this.unsafe_get()).get_background_color()
|
(*this.unsafe_get()).get_background_color()
|
||||||
} else if let Some(this) = HTMLTableCellElementCast::to_layout_js(self) {
|
} else if let Some(this) = self.downcast::<HTMLTableCellElement>() {
|
||||||
this.get_background_color()
|
this.get_background_color()
|
||||||
} else if let Some(this) = HTMLTableRowElementCast::to_layout_js(self) {
|
} else if let Some(this) = self.downcast::<HTMLTableRowElement>() {
|
||||||
(*this.unsafe_get()).get_background_color()
|
(*this.unsafe_get()).get_background_color()
|
||||||
} else if let Some(this) = HTMLTableSectionElementCast::to_layout_js(self) {
|
} else if let Some(this) = self.downcast::<HTMLTableSectionElement>() {
|
||||||
(*this.unsafe_get()).get_background_color()
|
(*this.unsafe_get()).get_background_color()
|
||||||
} else {
|
} else {
|
||||||
None
|
None
|
||||||
|
@ -301,7 +306,7 @@ impl LayoutElementHelpers for LayoutJS<Element> {
|
||||||
CSSColor { parsed: Color::RGBA(color), authored: None }))));
|
CSSColor { parsed: Color::RGBA(color), authored: None }))));
|
||||||
}
|
}
|
||||||
|
|
||||||
let background = if let Some(this) = HTMLBodyElementCast::to_layout_js(self) {
|
let background = if let Some(this) = self.downcast::<HTMLBodyElement>() {
|
||||||
(*this.unsafe_get()).get_background()
|
(*this.unsafe_get()).get_background()
|
||||||
} else {
|
} else {
|
||||||
None
|
None
|
||||||
|
@ -313,9 +318,9 @@ impl LayoutElementHelpers for LayoutJS<Element> {
|
||||||
background_image::SpecifiedValue(Some(specified::Image::Url(url)))))));
|
background_image::SpecifiedValue(Some(specified::Image::Url(url)))))));
|
||||||
}
|
}
|
||||||
|
|
||||||
let color = if let Some(this) = HTMLFontElementCast::to_layout_js(self) {
|
let color = if let Some(this) = self.downcast::<HTMLFontElement>() {
|
||||||
(*this.unsafe_get()).get_color()
|
(*this.unsafe_get()).get_color()
|
||||||
} else if let Some(this) = HTMLBodyElementCast::to_layout_js(self) {
|
} else if let Some(this) = self.downcast::<HTMLBodyElement>() {
|
||||||
// https://html.spec.whatwg.org/multipage/#the-page:the-body-element-20
|
// https://html.spec.whatwg.org/multipage/#the-page:the-body-element-20
|
||||||
(*this.unsafe_get()).get_color()
|
(*this.unsafe_get()).get_color()
|
||||||
} else {
|
} else {
|
||||||
|
@ -330,7 +335,7 @@ impl LayoutElementHelpers for LayoutJS<Element> {
|
||||||
}))));
|
}))));
|
||||||
}
|
}
|
||||||
|
|
||||||
let font_family = if let Some(this) = HTMLFontElementCast::to_layout_js(self) {
|
let font_family = if let Some(this) = self.downcast::<HTMLFontElement>() {
|
||||||
(*this.unsafe_get()).get_face()
|
(*this.unsafe_get()).get_face()
|
||||||
} else {
|
} else {
|
||||||
None
|
None
|
||||||
|
@ -345,7 +350,7 @@ impl LayoutElementHelpers for LayoutJS<Element> {
|
||||||
font_family)])))));
|
font_family)])))));
|
||||||
}
|
}
|
||||||
|
|
||||||
let font_size = if let Some(this) = HTMLFontElementCast::to_layout_js(self) {
|
let font_size = if let Some(this) = self.downcast::<HTMLFontElement>() {
|
||||||
(*this.unsafe_get()).get_size()
|
(*this.unsafe_get()).get_size()
|
||||||
} else {
|
} else {
|
||||||
None
|
None
|
||||||
|
@ -358,7 +363,7 @@ impl LayoutElementHelpers for LayoutJS<Element> {
|
||||||
font_size::SpecifiedValue(font_size)))))
|
font_size::SpecifiedValue(font_size)))))
|
||||||
}
|
}
|
||||||
|
|
||||||
let cellspacing = if let Some(this) = HTMLTableElementCast::to_layout_js(self) {
|
let cellspacing = if let Some(this) = self.downcast::<HTMLTableElement>() {
|
||||||
(*this.unsafe_get()).get_cellspacing()
|
(*this.unsafe_get()).get_cellspacing()
|
||||||
} else {
|
} else {
|
||||||
None
|
None
|
||||||
|
@ -375,7 +380,7 @@ impl LayoutElementHelpers for LayoutJS<Element> {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
let size = if let Some(this) = HTMLInputElementCast::to_layout_js(self) {
|
let size = if let Some(this) = self.downcast::<HTMLInputElement>() {
|
||||||
// FIXME(pcwalton): More use of atoms, please!
|
// FIXME(pcwalton): More use of atoms, please!
|
||||||
// FIXME(Ms2ger): this is nonsense! Invalid values also end up as
|
// FIXME(Ms2ger): this is nonsense! Invalid values also end up as
|
||||||
// a text field
|
// a text field
|
||||||
|
@ -401,11 +406,11 @@ impl LayoutElementHelpers for LayoutJS<Element> {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
let width = if let Some(this) = HTMLIFrameElementCast::to_layout_js(self) {
|
let width = if let Some(this) = self.downcast::<HTMLIFrameElement>() {
|
||||||
(*this.unsafe_get()).get_width()
|
(*this.unsafe_get()).get_width()
|
||||||
} else if let Some(this) = HTMLTableElementCast::to_layout_js(self) {
|
} else if let Some(this) = self.downcast::<HTMLTableElement>() {
|
||||||
(*this.unsafe_get()).get_width()
|
(*this.unsafe_get()).get_width()
|
||||||
} else if let Some(this) = HTMLTableCellElementCast::to_layout_js(self) {
|
} else if let Some(this) = self.downcast::<HTMLTableCellElement>() {
|
||||||
this.get_width()
|
this.get_width()
|
||||||
} else {
|
} else {
|
||||||
LengthOrPercentageOrAuto::Auto
|
LengthOrPercentageOrAuto::Auto
|
||||||
|
@ -428,7 +433,7 @@ impl LayoutElementHelpers for LayoutJS<Element> {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
let height = if let Some(this) = HTMLIFrameElementCast::to_layout_js(self) {
|
let height = if let Some(this) = self.downcast::<HTMLIFrameElement>() {
|
||||||
(*this.unsafe_get()).get_height()
|
(*this.unsafe_get()).get_height()
|
||||||
} else {
|
} else {
|
||||||
LengthOrPercentageOrAuto::Auto
|
LengthOrPercentageOrAuto::Auto
|
||||||
|
@ -451,7 +456,7 @@ impl LayoutElementHelpers for LayoutJS<Element> {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
let cols = if let Some(this) = HTMLTextAreaElementCast::to_layout_js(self) {
|
let cols = if let Some(this) = self.downcast::<HTMLTextAreaElement>() {
|
||||||
match (*this.unsafe_get()).get_cols_for_layout() {
|
match (*this.unsafe_get()).get_cols_for_layout() {
|
||||||
0 => None,
|
0 => None,
|
||||||
c => Some(c as i32),
|
c => Some(c as i32),
|
||||||
|
@ -473,7 +478,7 @@ impl LayoutElementHelpers for LayoutJS<Element> {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
let rows = if let Some(this) = HTMLTextAreaElementCast::to_layout_js(self) {
|
let rows = if let Some(this) = self.downcast::<HTMLTextAreaElement>() {
|
||||||
match (*this.unsafe_get()).get_rows_for_layout() {
|
match (*this.unsafe_get()).get_rows_for_layout() {
|
||||||
0 => None,
|
0 => None,
|
||||||
r => Some(r as i32),
|
r => Some(r as i32),
|
||||||
|
@ -493,7 +498,7 @@ impl LayoutElementHelpers for LayoutJS<Element> {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
let border = if let Some(this) = HTMLTableElementCast::to_layout_js(self) {
|
let border = if let Some(this) = self.downcast::<HTMLTableElement>() {
|
||||||
(*this.unsafe_get()).get_border()
|
(*this.unsafe_get()).get_border()
|
||||||
} else {
|
} else {
|
||||||
None
|
None
|
||||||
|
@ -522,7 +527,7 @@ impl LayoutElementHelpers for LayoutJS<Element> {
|
||||||
-> Option<u32> {
|
-> Option<u32> {
|
||||||
match attribute {
|
match attribute {
|
||||||
UnsignedIntegerAttribute::ColSpan => {
|
UnsignedIntegerAttribute::ColSpan => {
|
||||||
if let Some(this) = HTMLTableCellElementCast::to_layout_js(self) {
|
if let Some(this) = self.downcast::<HTMLTableCellElement>() {
|
||||||
this.get_colspan()
|
this.get_colspan()
|
||||||
} else {
|
} else {
|
||||||
// Don't panic since `display` can cause this to be called on arbitrary
|
// Don't panic since `display` can cause this to be called on arbitrary
|
||||||
|
@ -539,7 +544,7 @@ impl LayoutElementHelpers for LayoutJS<Element> {
|
||||||
if (*self.unsafe_get()).namespace != ns!(HTML) {
|
if (*self.unsafe_get()).namespace != ns!(HTML) {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
let node = NodeCast::from_layout_js(&self);
|
let node = self.upcast::<Node>();
|
||||||
node.owner_doc_for_layout().is_html_document_for_layout()
|
node.owner_doc_for_layout().is_html_document_for_layout()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -580,7 +585,7 @@ impl LayoutElementHelpers for LayoutJS<Element> {
|
||||||
#[allow(unsafe_code)]
|
#[allow(unsafe_code)]
|
||||||
fn get_checked_state_for_layout(&self) -> bool {
|
fn get_checked_state_for_layout(&self) -> bool {
|
||||||
// TODO option and menuitem can also have a checked state.
|
// TODO option and menuitem can also have a checked state.
|
||||||
match HTMLInputElementCast::to_layout_js(self) {
|
match self.downcast::<HTMLInputElement>() {
|
||||||
Some(input) => unsafe {
|
Some(input) => unsafe {
|
||||||
(*input.unsafe_get()).get_checked_state_for_layout()
|
(*input.unsafe_get()).get_checked_state_for_layout()
|
||||||
},
|
},
|
||||||
|
@ -592,7 +597,7 @@ impl LayoutElementHelpers for LayoutJS<Element> {
|
||||||
#[allow(unsafe_code)]
|
#[allow(unsafe_code)]
|
||||||
fn get_indeterminate_state_for_layout(&self) -> bool {
|
fn get_indeterminate_state_for_layout(&self) -> bool {
|
||||||
// TODO progress elements can also be matched with :indeterminate
|
// TODO progress elements can also be matched with :indeterminate
|
||||||
match HTMLInputElementCast::to_layout_js(self) {
|
match self.downcast::<HTMLInputElement>() {
|
||||||
Some(input) => unsafe {
|
Some(input) => unsafe {
|
||||||
(*input.unsafe_get()).get_indeterminate_state_for_layout()
|
(*input.unsafe_get()).get_indeterminate_state_for_layout()
|
||||||
},
|
},
|
||||||
|
@ -618,7 +623,7 @@ pub enum StylePriority {
|
||||||
|
|
||||||
impl Element {
|
impl Element {
|
||||||
pub fn html_element_in_html_document(&self) -> bool {
|
pub fn html_element_in_html_document(&self) -> bool {
|
||||||
let node = NodeCast::from_ref(self);
|
let node = self.upcast::<Node>();
|
||||||
self.namespace == ns!(HTML) && node.is_in_html_doc()
|
self.namespace == ns!(HTML) && node.is_in_html_doc()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -779,7 +784,7 @@ impl Element {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn serialize(&self, traversal_scope: TraversalScope) -> Fallible<DOMString> {
|
pub fn serialize(&self, traversal_scope: TraversalScope) -> Fallible<DOMString> {
|
||||||
let node = NodeCast::from_ref(self);
|
let node = self.upcast::<Node>();
|
||||||
let mut writer = vec![];
|
let mut writer = vec![];
|
||||||
match serialize(&mut writer, &node,
|
match serialize(&mut writer, &node,
|
||||||
SerializeOpts {
|
SerializeOpts {
|
||||||
|
@ -793,17 +798,17 @@ impl Element {
|
||||||
|
|
||||||
// https://html.spec.whatwg.org/multipage/#root-element
|
// https://html.spec.whatwg.org/multipage/#root-element
|
||||||
pub fn get_root_element(&self) -> Root<Element> {
|
pub fn get_root_element(&self) -> Root<Element> {
|
||||||
let node = NodeCast::from_ref(self);
|
let node = self.upcast::<Node>();
|
||||||
node.inclusive_ancestors()
|
node.inclusive_ancestors()
|
||||||
.filter_map(ElementCast::to_root)
|
.filter_map(Root::downcast::<Element>)
|
||||||
.last()
|
.last()
|
||||||
.expect("We know inclusive_ancestors will return `self` which is an element")
|
.expect("We know inclusive_ancestors will return `self` which is an element")
|
||||||
}
|
}
|
||||||
|
|
||||||
// https://dom.spec.whatwg.org/#locate-a-namespace-prefix
|
// https://dom.spec.whatwg.org/#locate-a-namespace-prefix
|
||||||
pub fn lookup_prefix(&self, namespace: Namespace) -> Option<DOMString> {
|
pub fn lookup_prefix(&self, namespace: Namespace) -> Option<DOMString> {
|
||||||
for node in NodeCast::from_ref(self).inclusive_ancestors() {
|
for node in self.upcast::<Node>().inclusive_ancestors() {
|
||||||
match ElementCast::to_ref(node.r()) {
|
match node.downcast::<Element>() {
|
||||||
Some(element) => {
|
Some(element) => {
|
||||||
// Step 1.
|
// Step 1.
|
||||||
if *element.namespace() == namespace {
|
if *element.namespace() == namespace {
|
||||||
|
@ -836,7 +841,7 @@ impl Element {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
// TODO: Check whether the element is being rendered (i.e. not hidden).
|
// TODO: Check whether the element is being rendered (i.e. not hidden).
|
||||||
let node = NodeCast::from_ref(self);
|
let node = self.upcast::<Node>();
|
||||||
if node.get_flag(SEQUENTIALLY_FOCUSABLE) {
|
if node.get_flag(SEQUENTIALLY_FOCUSABLE) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -853,7 +858,7 @@ impl Element {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn is_actually_disabled(&self) -> bool {
|
pub fn is_actually_disabled(&self) -> bool {
|
||||||
let node = NodeCast::from_ref(self);
|
let node = self.upcast::<Node>();
|
||||||
match node.type_id() {
|
match node.type_id() {
|
||||||
NodeTypeId::Element(ElementTypeId::HTMLElement(HTMLElementTypeId::HTMLButtonElement)) |
|
NodeTypeId::Element(ElementTypeId::HTMLElement(HTMLElementTypeId::HTMLButtonElement)) |
|
||||||
NodeTypeId::Element(ElementTypeId::HTMLElement(HTMLElementTypeId::HTMLInputElement)) |
|
NodeTypeId::Element(ElementTypeId::HTMLElement(HTMLElementTypeId::HTMLInputElement)) |
|
||||||
|
@ -884,7 +889,7 @@ impl Element {
|
||||||
let attr = Attr::new(&window, local_name, value, name, namespace, prefix, Some(self));
|
let attr = Attr::new(&window, local_name, value, name, namespace, prefix, Some(self));
|
||||||
self.attrs.borrow_mut().push(JS::from_rooted(&attr));
|
self.attrs.borrow_mut().push(JS::from_rooted(&attr));
|
||||||
if in_empty_ns {
|
if in_empty_ns {
|
||||||
vtable_for(NodeCast::from_ref(self)).attribute_mutated(
|
vtable_for(self.upcast::<Node>()).attribute_mutated(
|
||||||
&attr, AttributeMutation::Set(None));
|
&attr, AttributeMutation::Set(None));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -969,7 +974,7 @@ impl Element {
|
||||||
pub fn parse_attribute(&self, namespace: &Namespace, local_name: &Atom,
|
pub fn parse_attribute(&self, namespace: &Namespace, local_name: &Atom,
|
||||||
value: DOMString) -> AttrValue {
|
value: DOMString) -> AttrValue {
|
||||||
if *namespace == ns!("") {
|
if *namespace == ns!("") {
|
||||||
vtable_for(&NodeCast::from_ref(self))
|
vtable_for(&self.upcast::<Node>())
|
||||||
.parse_plain_attribute(local_name, value)
|
.parse_plain_attribute(local_name, value)
|
||||||
} else {
|
} else {
|
||||||
AttrValue::String(value)
|
AttrValue::String(value)
|
||||||
|
@ -996,7 +1001,7 @@ impl Element {
|
||||||
let attr = (*self.attrs.borrow())[idx].root();
|
let attr = (*self.attrs.borrow())[idx].root();
|
||||||
self.attrs.borrow_mut().remove(idx);
|
self.attrs.borrow_mut().remove(idx);
|
||||||
attr.set_owner(None);
|
attr.set_owner(None);
|
||||||
let node = NodeCast::from_ref(self);
|
let node = self.upcast::<Node>();
|
||||||
if attr.namespace() == &ns!("") {
|
if attr.namespace() == &ns!("") {
|
||||||
vtable_for(node).attribute_mutated(&attr, AttributeMutation::Removed);
|
vtable_for(node).attribute_mutated(&attr, AttributeMutation::Removed);
|
||||||
}
|
}
|
||||||
|
@ -1006,7 +1011,7 @@ impl Element {
|
||||||
|
|
||||||
pub fn has_class(&self, name: &Atom) -> bool {
|
pub fn has_class(&self, name: &Atom) -> bool {
|
||||||
let quirks_mode = {
|
let quirks_mode = {
|
||||||
let node = NodeCast::from_ref(self);
|
let node = self.upcast::<Node>();
|
||||||
let owner_doc = node.owner_doc();
|
let owner_doc = node.owner_doc();
|
||||||
owner_doc.r().quirks_mode()
|
owner_doc.r().quirks_mode()
|
||||||
};
|
};
|
||||||
|
@ -1172,7 +1177,7 @@ impl ElementMethods for Element {
|
||||||
fn Attributes(&self) -> Root<NamedNodeMap> {
|
fn Attributes(&self) -> Root<NamedNodeMap> {
|
||||||
self.attr_list.or_init(|| {
|
self.attr_list.or_init(|| {
|
||||||
let doc = {
|
let doc = {
|
||||||
let node = NodeCast::from_ref(self);
|
let node = self.upcast::<Node>();
|
||||||
node.owner_doc()
|
node.owner_doc()
|
||||||
};
|
};
|
||||||
let window = doc.r().window();
|
let window = doc.r().window();
|
||||||
|
@ -1272,26 +1277,26 @@ impl ElementMethods for Element {
|
||||||
// https://dom.spec.whatwg.org/#dom-element-getelementsbytagname
|
// https://dom.spec.whatwg.org/#dom-element-getelementsbytagname
|
||||||
fn GetElementsByTagName(&self, localname: DOMString) -> Root<HTMLCollection> {
|
fn GetElementsByTagName(&self, localname: DOMString) -> Root<HTMLCollection> {
|
||||||
let window = window_from_node(self);
|
let window = window_from_node(self);
|
||||||
HTMLCollection::by_tag_name(window.r(), NodeCast::from_ref(self), localname)
|
HTMLCollection::by_tag_name(window.r(), self.upcast::<Node>(), localname)
|
||||||
}
|
}
|
||||||
|
|
||||||
// https://dom.spec.whatwg.org/#dom-element-getelementsbytagnamens
|
// https://dom.spec.whatwg.org/#dom-element-getelementsbytagnamens
|
||||||
fn GetElementsByTagNameNS(&self, maybe_ns: Option<DOMString>,
|
fn GetElementsByTagNameNS(&self, maybe_ns: Option<DOMString>,
|
||||||
localname: DOMString) -> Root<HTMLCollection> {
|
localname: DOMString) -> Root<HTMLCollection> {
|
||||||
let window = window_from_node(self);
|
let window = window_from_node(self);
|
||||||
HTMLCollection::by_tag_name_ns(window.r(), NodeCast::from_ref(self), localname, maybe_ns)
|
HTMLCollection::by_tag_name_ns(window.r(), self.upcast::<Node>(), localname, maybe_ns)
|
||||||
}
|
}
|
||||||
|
|
||||||
// https://dom.spec.whatwg.org/#dom-element-getelementsbyclassname
|
// https://dom.spec.whatwg.org/#dom-element-getelementsbyclassname
|
||||||
fn GetElementsByClassName(&self, classes: DOMString) -> Root<HTMLCollection> {
|
fn GetElementsByClassName(&self, classes: DOMString) -> Root<HTMLCollection> {
|
||||||
let window = window_from_node(self);
|
let window = window_from_node(self);
|
||||||
HTMLCollection::by_class_name(window.r(), NodeCast::from_ref(self), classes)
|
HTMLCollection::by_class_name(window.r(), self.upcast::<Node>(), classes)
|
||||||
}
|
}
|
||||||
|
|
||||||
// https://drafts.csswg.org/cssom-view/#dom-element-getclientrects
|
// https://drafts.csswg.org/cssom-view/#dom-element-getclientrects
|
||||||
fn GetClientRects(&self) -> Root<DOMRectList> {
|
fn GetClientRects(&self) -> Root<DOMRectList> {
|
||||||
let win = window_from_node(self);
|
let win = window_from_node(self);
|
||||||
let node = NodeCast::from_ref(self);
|
let node = self.upcast::<Node>();
|
||||||
let raw_rects = node.get_content_boxes();
|
let raw_rects = node.get_content_boxes();
|
||||||
let rects = raw_rects.iter().map(|rect| {
|
let rects = raw_rects.iter().map(|rect| {
|
||||||
DOMRect::new(GlobalRef::Window(win.r()),
|
DOMRect::new(GlobalRef::Window(win.r()),
|
||||||
|
@ -1306,7 +1311,7 @@ impl ElementMethods for Element {
|
||||||
// https://drafts.csswg.org/cssom-view/#dom-element-getboundingclientrect
|
// https://drafts.csswg.org/cssom-view/#dom-element-getboundingclientrect
|
||||||
fn GetBoundingClientRect(&self) -> Root<DOMRect> {
|
fn GetBoundingClientRect(&self) -> Root<DOMRect> {
|
||||||
let win = window_from_node(self);
|
let win = window_from_node(self);
|
||||||
let node = NodeCast::from_ref(self);
|
let node = self.upcast::<Node>();
|
||||||
let rect = node.get_bounding_content_box();
|
let rect = node.get_bounding_content_box();
|
||||||
DOMRect::new(GlobalRef::Window(win.r()),
|
DOMRect::new(GlobalRef::Window(win.r()),
|
||||||
rect.origin.x.to_f64_px(),
|
rect.origin.x.to_f64_px(),
|
||||||
|
@ -1317,25 +1322,25 @@ impl ElementMethods for Element {
|
||||||
|
|
||||||
// https://drafts.csswg.org/cssom-view/#dom-element-clienttop
|
// https://drafts.csswg.org/cssom-view/#dom-element-clienttop
|
||||||
fn ClientTop(&self) -> i32 {
|
fn ClientTop(&self) -> i32 {
|
||||||
let node = NodeCast::from_ref(self);
|
let node = self.upcast::<Node>();
|
||||||
node.get_client_rect().origin.y
|
node.get_client_rect().origin.y
|
||||||
}
|
}
|
||||||
|
|
||||||
// https://drafts.csswg.org/cssom-view/#dom-element-clientleft
|
// https://drafts.csswg.org/cssom-view/#dom-element-clientleft
|
||||||
fn ClientLeft(&self) -> i32 {
|
fn ClientLeft(&self) -> i32 {
|
||||||
let node = NodeCast::from_ref(self);
|
let node = self.upcast::<Node>();
|
||||||
node.get_client_rect().origin.x
|
node.get_client_rect().origin.x
|
||||||
}
|
}
|
||||||
|
|
||||||
// https://drafts.csswg.org/cssom-view/#dom-element-clientwidth
|
// https://drafts.csswg.org/cssom-view/#dom-element-clientwidth
|
||||||
fn ClientWidth(&self) -> i32 {
|
fn ClientWidth(&self) -> i32 {
|
||||||
let node = NodeCast::from_ref(self);
|
let node = self.upcast::<Node>();
|
||||||
node.get_client_rect().size.width
|
node.get_client_rect().size.width
|
||||||
}
|
}
|
||||||
|
|
||||||
// https://drafts.csswg.org/cssom-view/#dom-element-clientheight
|
// https://drafts.csswg.org/cssom-view/#dom-element-clientheight
|
||||||
fn ClientHeight(&self) -> i32 {
|
fn ClientHeight(&self) -> i32 {
|
||||||
let node = NodeCast::from_ref(self);
|
let node = self.upcast::<Node>();
|
||||||
node.get_client_rect().size.height
|
node.get_client_rect().size.height
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1347,17 +1352,17 @@ impl ElementMethods for Element {
|
||||||
|
|
||||||
/// https://w3c.github.io/DOM-Parsing/#widl-Element-innerHTML
|
/// https://w3c.github.io/DOM-Parsing/#widl-Element-innerHTML
|
||||||
fn SetInnerHTML(&self, value: DOMString) -> Fallible<()> {
|
fn SetInnerHTML(&self, value: DOMString) -> Fallible<()> {
|
||||||
let context_node = NodeCast::from_ref(self);
|
let context_node = self.upcast::<Node>();
|
||||||
// Step 1.
|
// Step 1.
|
||||||
let frag = try!(context_node.parse_fragment(value));
|
let frag = try!(context_node.parse_fragment(value));
|
||||||
// Step 2.
|
// Step 2.
|
||||||
// https://github.com/w3c/DOM-Parsing/issues/1
|
// https://github.com/w3c/DOM-Parsing/issues/1
|
||||||
let target = if let Some(template) = HTMLTemplateElementCast::to_ref(self) {
|
let target = if let Some(template) = self.downcast::<HTMLTemplateElement>() {
|
||||||
NodeCast::from_root(template.Content())
|
Root::upcast::<Node>(template.Content())
|
||||||
} else {
|
} else {
|
||||||
Root::from_ref(context_node)
|
Root::from_ref(context_node)
|
||||||
};
|
};
|
||||||
Node::replace_all(Some(NodeCast::from_ref(&*frag)), &target);
|
Node::replace_all(Some(frag.upcast::<Node>()), &target);
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1369,7 +1374,7 @@ impl ElementMethods for Element {
|
||||||
// https://dvcs.w3.org/hg/innerhtml/raw-file/tip/index.html#widl-Element-outerHTML
|
// https://dvcs.w3.org/hg/innerhtml/raw-file/tip/index.html#widl-Element-outerHTML
|
||||||
fn SetOuterHTML(&self, value: DOMString) -> Fallible<()> {
|
fn SetOuterHTML(&self, value: DOMString) -> Fallible<()> {
|
||||||
let context_document = document_from_node(self);
|
let context_document = document_from_node(self);
|
||||||
let context_node = NodeCast::from_ref(self);
|
let context_node = self.upcast::<Node>();
|
||||||
// Step 1.
|
// Step 1.
|
||||||
let context_parent = match context_node.GetParentNode() {
|
let context_parent = match context_node.GetParentNode() {
|
||||||
None => {
|
None => {
|
||||||
|
@ -1388,7 +1393,7 @@ impl ElementMethods for Element {
|
||||||
let body_elem = Element::create(QualName::new(ns!(HTML), atom!(body)),
|
let body_elem = Element::create(QualName::new(ns!(HTML), atom!(body)),
|
||||||
None, context_document.r(),
|
None, context_document.r(),
|
||||||
ElementCreator::ScriptCreated);
|
ElementCreator::ScriptCreated);
|
||||||
NodeCast::from_root(body_elem)
|
Root::upcast::<Node>(body_elem)
|
||||||
},
|
},
|
||||||
_ => context_node.GetParentNode().unwrap()
|
_ => context_node.GetParentNode().unwrap()
|
||||||
};
|
};
|
||||||
|
@ -1396,84 +1401,84 @@ impl ElementMethods for Element {
|
||||||
// Step 5.
|
// Step 5.
|
||||||
let frag = try!(parent.r().parse_fragment(value));
|
let frag = try!(parent.r().parse_fragment(value));
|
||||||
// Step 6.
|
// Step 6.
|
||||||
try!(context_parent.r().ReplaceChild(NodeCast::from_ref(frag.r()),
|
try!(context_parent.r().ReplaceChild(frag.upcast::<Node>(),
|
||||||
context_node));
|
context_node));
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
// https://dom.spec.whatwg.org/#dom-nondocumenttypechildnode-previouselementsibling
|
// https://dom.spec.whatwg.org/#dom-nondocumenttypechildnode-previouselementsibling
|
||||||
fn GetPreviousElementSibling(&self) -> Option<Root<Element>> {
|
fn GetPreviousElementSibling(&self) -> Option<Root<Element>> {
|
||||||
NodeCast::from_ref(self).preceding_siblings()
|
self.upcast::<Node>().preceding_siblings()
|
||||||
.filter_map(ElementCast::to_root).next()
|
.filter_map(Root::downcast::<Element>).next()
|
||||||
}
|
}
|
||||||
|
|
||||||
// https://dom.spec.whatwg.org/#dom-nondocumenttypechildnode-nextelementsibling
|
// https://dom.spec.whatwg.org/#dom-nondocumenttypechildnode-nextelementsibling
|
||||||
fn GetNextElementSibling(&self) -> Option<Root<Element>> {
|
fn GetNextElementSibling(&self) -> Option<Root<Element>> {
|
||||||
NodeCast::from_ref(self).following_siblings()
|
self.upcast::<Node>().following_siblings()
|
||||||
.filter_map(ElementCast::to_root).next()
|
.filter_map(Root::downcast::<Element>).next()
|
||||||
}
|
}
|
||||||
|
|
||||||
// https://dom.spec.whatwg.org/#dom-parentnode-children
|
// https://dom.spec.whatwg.org/#dom-parentnode-children
|
||||||
fn Children(&self) -> Root<HTMLCollection> {
|
fn Children(&self) -> Root<HTMLCollection> {
|
||||||
let window = window_from_node(self);
|
let window = window_from_node(self);
|
||||||
HTMLCollection::children(window.r(), NodeCast::from_ref(self))
|
HTMLCollection::children(window.r(), self.upcast::<Node>())
|
||||||
}
|
}
|
||||||
|
|
||||||
// https://dom.spec.whatwg.org/#dom-parentnode-firstelementchild
|
// https://dom.spec.whatwg.org/#dom-parentnode-firstelementchild
|
||||||
fn GetFirstElementChild(&self) -> Option<Root<Element>> {
|
fn GetFirstElementChild(&self) -> Option<Root<Element>> {
|
||||||
NodeCast::from_ref(self).child_elements().next()
|
self.upcast::<Node>().child_elements().next()
|
||||||
}
|
}
|
||||||
|
|
||||||
// https://dom.spec.whatwg.org/#dom-parentnode-lastelementchild
|
// https://dom.spec.whatwg.org/#dom-parentnode-lastelementchild
|
||||||
fn GetLastElementChild(&self) -> Option<Root<Element>> {
|
fn GetLastElementChild(&self) -> Option<Root<Element>> {
|
||||||
NodeCast::from_ref(self).rev_children().filter_map(ElementCast::to_root).next()
|
self.upcast::<Node>().rev_children().filter_map(Root::downcast::<Element>).next()
|
||||||
}
|
}
|
||||||
|
|
||||||
// https://dom.spec.whatwg.org/#dom-parentnode-childelementcount
|
// https://dom.spec.whatwg.org/#dom-parentnode-childelementcount
|
||||||
fn ChildElementCount(&self) -> u32 {
|
fn ChildElementCount(&self) -> u32 {
|
||||||
NodeCast::from_ref(self).child_elements().count() as u32
|
self.upcast::<Node>().child_elements().count() as u32
|
||||||
}
|
}
|
||||||
|
|
||||||
// https://dom.spec.whatwg.org/#dom-parentnode-prepend
|
// https://dom.spec.whatwg.org/#dom-parentnode-prepend
|
||||||
fn Prepend(&self, nodes: Vec<NodeOrString>) -> ErrorResult {
|
fn Prepend(&self, nodes: Vec<NodeOrString>) -> ErrorResult {
|
||||||
NodeCast::from_ref(self).prepend(nodes)
|
self.upcast::<Node>().prepend(nodes)
|
||||||
}
|
}
|
||||||
|
|
||||||
// https://dom.spec.whatwg.org/#dom-parentnode-append
|
// https://dom.spec.whatwg.org/#dom-parentnode-append
|
||||||
fn Append(&self, nodes: Vec<NodeOrString>) -> ErrorResult {
|
fn Append(&self, nodes: Vec<NodeOrString>) -> ErrorResult {
|
||||||
NodeCast::from_ref(self).append(nodes)
|
self.upcast::<Node>().append(nodes)
|
||||||
}
|
}
|
||||||
|
|
||||||
// https://dom.spec.whatwg.org/#dom-parentnode-queryselector
|
// https://dom.spec.whatwg.org/#dom-parentnode-queryselector
|
||||||
fn QuerySelector(&self, selectors: DOMString) -> Fallible<Option<Root<Element>>> {
|
fn QuerySelector(&self, selectors: DOMString) -> Fallible<Option<Root<Element>>> {
|
||||||
let root = NodeCast::from_ref(self);
|
let root = self.upcast::<Node>();
|
||||||
root.query_selector(selectors)
|
root.query_selector(selectors)
|
||||||
}
|
}
|
||||||
|
|
||||||
// https://dom.spec.whatwg.org/#dom-parentnode-queryselectorall
|
// https://dom.spec.whatwg.org/#dom-parentnode-queryselectorall
|
||||||
fn QuerySelectorAll(&self, selectors: DOMString) -> Fallible<Root<NodeList>> {
|
fn QuerySelectorAll(&self, selectors: DOMString) -> Fallible<Root<NodeList>> {
|
||||||
let root = NodeCast::from_ref(self);
|
let root = self.upcast::<Node>();
|
||||||
root.query_selector_all(selectors)
|
root.query_selector_all(selectors)
|
||||||
}
|
}
|
||||||
|
|
||||||
// https://dom.spec.whatwg.org/#dom-childnode-before
|
// https://dom.spec.whatwg.org/#dom-childnode-before
|
||||||
fn Before(&self, nodes: Vec<NodeOrString>) -> ErrorResult {
|
fn Before(&self, nodes: Vec<NodeOrString>) -> ErrorResult {
|
||||||
NodeCast::from_ref(self).before(nodes)
|
self.upcast::<Node>().before(nodes)
|
||||||
}
|
}
|
||||||
|
|
||||||
// https://dom.spec.whatwg.org/#dom-childnode-after
|
// https://dom.spec.whatwg.org/#dom-childnode-after
|
||||||
fn After(&self, nodes: Vec<NodeOrString>) -> ErrorResult {
|
fn After(&self, nodes: Vec<NodeOrString>) -> ErrorResult {
|
||||||
NodeCast::from_ref(self).after(nodes)
|
self.upcast::<Node>().after(nodes)
|
||||||
}
|
}
|
||||||
|
|
||||||
// https://dom.spec.whatwg.org/#dom-childnode-replacewith
|
// https://dom.spec.whatwg.org/#dom-childnode-replacewith
|
||||||
fn ReplaceWith(&self, nodes: Vec<NodeOrString>) -> ErrorResult {
|
fn ReplaceWith(&self, nodes: Vec<NodeOrString>) -> ErrorResult {
|
||||||
NodeCast::from_ref(self).replace_with(nodes)
|
self.upcast::<Node>().replace_with(nodes)
|
||||||
}
|
}
|
||||||
|
|
||||||
// https://dom.spec.whatwg.org/#dom-childnode-remove
|
// https://dom.spec.whatwg.org/#dom-childnode-remove
|
||||||
fn Remove(&self) {
|
fn Remove(&self) {
|
||||||
let node = NodeCast::from_ref(self);
|
let node = self.upcast::<Node>();
|
||||||
node.remove_self();
|
node.remove_self();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1492,9 +1497,9 @@ impl ElementMethods for Element {
|
||||||
match parse_author_origin_selector_list_from_str(&selectors) {
|
match parse_author_origin_selector_list_from_str(&selectors) {
|
||||||
Err(()) => Err(Error::Syntax),
|
Err(()) => Err(Error::Syntax),
|
||||||
Ok(ref selectors) => {
|
Ok(ref selectors) => {
|
||||||
let root = NodeCast::from_ref(self);
|
let root = self.upcast::<Node>();
|
||||||
for element in root.inclusive_ancestors() {
|
for element in root.inclusive_ancestors() {
|
||||||
if let Some(element) = ElementCast::to_root(element) {
|
if let Some(element) = Root::downcast::<Element>(element) {
|
||||||
if matches(selectors, &element, None) {
|
if matches(selectors, &element, None) {
|
||||||
return Ok(Some(element));
|
return Ok(Some(element));
|
||||||
}
|
}
|
||||||
|
@ -1508,13 +1513,13 @@ impl ElementMethods for Element {
|
||||||
|
|
||||||
impl VirtualMethods for Element {
|
impl VirtualMethods for Element {
|
||||||
fn super_type(&self) -> Option<&VirtualMethods> {
|
fn super_type(&self) -> Option<&VirtualMethods> {
|
||||||
let node: &Node = NodeCast::from_ref(self);
|
let node: &Node = self.upcast::<Node>();
|
||||||
Some(node as &VirtualMethods)
|
Some(node as &VirtualMethods)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn attribute_mutated(&self, attr: &Attr, mutation: AttributeMutation) {
|
fn attribute_mutated(&self, attr: &Attr, mutation: AttributeMutation) {
|
||||||
self.super_type().unwrap().attribute_mutated(attr, mutation);
|
self.super_type().unwrap().attribute_mutated(attr, mutation);
|
||||||
let node = NodeCast::from_ref(self);
|
let node = self.upcast::<Node>();
|
||||||
let doc = node.owner_doc();
|
let doc = node.owner_doc();
|
||||||
let damage = match attr.local_name() {
|
let damage = match attr.local_name() {
|
||||||
&atom!(style) => {
|
&atom!(style) => {
|
||||||
|
@ -1607,7 +1612,7 @@ impl VirtualMethods for Element {
|
||||||
|
|
||||||
impl<'a> ::selectors::Element for Root<Element> {
|
impl<'a> ::selectors::Element for Root<Element> {
|
||||||
fn parent_element(&self) -> Option<Root<Element>> {
|
fn parent_element(&self) -> Option<Root<Element>> {
|
||||||
NodeCast::from_ref(&**self).GetParentElement()
|
self.upcast::<Node>().GetParentElement()
|
||||||
}
|
}
|
||||||
|
|
||||||
fn first_child_element(&self) -> Option<Root<Element>> {
|
fn first_child_element(&self) -> Option<Root<Element>> {
|
||||||
|
@ -1615,34 +1620,34 @@ impl<'a> ::selectors::Element for Root<Element> {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn last_child_element(&self) -> Option<Root<Element>> {
|
fn last_child_element(&self) -> Option<Root<Element>> {
|
||||||
self.node.rev_children().filter_map(ElementCast::to_root).next()
|
self.node.rev_children().filter_map(Root::downcast::<Element>).next()
|
||||||
}
|
}
|
||||||
|
|
||||||
fn prev_sibling_element(&self) -> Option<Root<Element>> {
|
fn prev_sibling_element(&self) -> Option<Root<Element>> {
|
||||||
self.node.preceding_siblings().filter_map(ElementCast::to_root).next()
|
self.node.preceding_siblings().filter_map(Root::downcast::<Element>).next()
|
||||||
}
|
}
|
||||||
|
|
||||||
fn next_sibling_element(&self) -> Option<Root<Element>> {
|
fn next_sibling_element(&self) -> Option<Root<Element>> {
|
||||||
self.node.following_siblings().filter_map(ElementCast::to_root).next()
|
self.node.following_siblings().filter_map(Root::downcast::<Element>).next()
|
||||||
}
|
}
|
||||||
|
|
||||||
fn is_root(&self) -> bool {
|
fn is_root(&self) -> bool {
|
||||||
match self.node.GetParentNode() {
|
match self.node.GetParentNode() {
|
||||||
None => false,
|
None => false,
|
||||||
Some(node) => node.is_document(),
|
Some(node) => node.is::<Document>(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn is_empty(&self) -> bool {
|
fn is_empty(&self) -> bool {
|
||||||
self.node.children().all(|node| !node.is_element() && match TextCast::to_ref(&*node) {
|
self.node.children().all(|node| !node.is::<Element>() && match node.downcast::<Text>() {
|
||||||
None => true,
|
None => true,
|
||||||
Some(text) => CharacterDataCast::from_ref(text).data().is_empty()
|
Some(text) => text.upcast::<CharacterData>().data().is_empty()
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
fn is_link(&self) -> bool {
|
fn is_link(&self) -> bool {
|
||||||
// FIXME: This is HTML only.
|
// FIXME: This is HTML only.
|
||||||
let node = NodeCast::from_ref(&**self);
|
let node = self.upcast::<Node>();
|
||||||
match node.type_id() {
|
match node.type_id() {
|
||||||
// https://html.spec.whatwg.org/multipage/#selector-link
|
// https://html.spec.whatwg.org/multipage/#selector-link
|
||||||
NodeTypeId::Element(ElementTypeId::HTMLElement(HTMLElementTypeId::HTMLAnchorElement)) |
|
NodeTypeId::Element(ElementTypeId::HTMLElement(HTMLElementTypeId::HTMLAnchorElement)) |
|
||||||
|
@ -1696,14 +1701,14 @@ impl<'a> ::selectors::Element for Root<Element> {
|
||||||
Element::get_enabled_state(self)
|
Element::get_enabled_state(self)
|
||||||
}
|
}
|
||||||
fn get_checked_state(&self) -> bool {
|
fn get_checked_state(&self) -> bool {
|
||||||
let input_element: Option<&HTMLInputElement> = HTMLInputElementCast::to_ref(&**self);
|
let input_element: Option<&HTMLInputElement> = self.downcast::<HTMLInputElement>();
|
||||||
match input_element {
|
match input_element {
|
||||||
Some(input) => input.Checked(),
|
Some(input) => input.Checked(),
|
||||||
None => false,
|
None => false,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
fn get_indeterminate_state(&self) -> bool {
|
fn get_indeterminate_state(&self) -> bool {
|
||||||
let input_element: Option<&HTMLInputElement> = HTMLInputElementCast::to_ref(&**self);
|
let input_element: Option<&HTMLInputElement> = self.downcast::<HTMLInputElement>();
|
||||||
match input_element {
|
match input_element {
|
||||||
Some(input) => input.get_indeterminate_state(),
|
Some(input) => input.get_indeterminate_state(),
|
||||||
None => false,
|
None => false,
|
||||||
|
@ -1724,7 +1729,7 @@ impl<'a> ::selectors::Element for Root<Element> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
fn has_servo_nonzero_border(&self) -> bool {
|
fn has_servo_nonzero_border(&self) -> bool {
|
||||||
let table_element: Option<&HTMLTableElement> = HTMLTableElementCast::to_ref(&**self);
|
let table_element: Option<&HTMLTableElement> = self.downcast::<HTMLTableElement>();
|
||||||
match table_element {
|
match table_element {
|
||||||
None => false,
|
None => false,
|
||||||
Some(this) => {
|
Some(this) => {
|
||||||
|
@ -1769,14 +1774,14 @@ impl<'a> ::selectors::Element for Root<Element> {
|
||||||
|
|
||||||
impl Element {
|
impl Element {
|
||||||
pub fn as_maybe_activatable(&self) -> Option<&Activatable> {
|
pub fn as_maybe_activatable(&self) -> Option<&Activatable> {
|
||||||
let node = NodeCast::from_ref(self);
|
let node = self.upcast::<Node>();
|
||||||
let element = match node.type_id() {
|
let element = match node.type_id() {
|
||||||
NodeTypeId::Element(ElementTypeId::HTMLElement(HTMLElementTypeId::HTMLInputElement)) => {
|
NodeTypeId::Element(ElementTypeId::HTMLElement(HTMLElementTypeId::HTMLInputElement)) => {
|
||||||
let element = HTMLInputElementCast::to_ref(self).unwrap();
|
let element = self.downcast::<HTMLInputElement>().unwrap();
|
||||||
Some(element as &Activatable)
|
Some(element as &Activatable)
|
||||||
},
|
},
|
||||||
NodeTypeId::Element(ElementTypeId::HTMLElement(HTMLElementTypeId::HTMLAnchorElement)) => {
|
NodeTypeId::Element(ElementTypeId::HTMLElement(HTMLElementTypeId::HTMLAnchorElement)) => {
|
||||||
let element = HTMLAnchorElementCast::to_ref(self).unwrap();
|
let element = self.downcast::<HTMLAnchorElement>().unwrap();
|
||||||
Some(element as &Activatable)
|
Some(element as &Activatable)
|
||||||
},
|
},
|
||||||
_ => {
|
_ => {
|
||||||
|
@ -1793,12 +1798,12 @@ impl Element {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn click_in_progress(&self) -> bool {
|
pub fn click_in_progress(&self) -> bool {
|
||||||
let node = NodeCast::from_ref(self);
|
let node = self.upcast::<Node>();
|
||||||
node.get_flag(CLICK_IN_PROGRESS)
|
node.get_flag(CLICK_IN_PROGRESS)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn set_click_in_progress(&self, click: bool) {
|
pub fn set_click_in_progress(&self, click: bool) {
|
||||||
let node = NodeCast::from_ref(self);
|
let node = self.upcast::<Node>();
|
||||||
node.set_flag(CLICK_IN_PROGRESS, click)
|
node.set_flag(CLICK_IN_PROGRESS, click)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1807,9 +1812,9 @@ impl Element {
|
||||||
match self.as_maybe_activatable() {
|
match self.as_maybe_activatable() {
|
||||||
Some(el) => Some(Root::from_ref(el.as_element())),
|
Some(el) => Some(Root::from_ref(el.as_element())),
|
||||||
None => {
|
None => {
|
||||||
let node = NodeCast::from_ref(self);
|
let node = self.upcast::<Node>();
|
||||||
for node in node.ancestors() {
|
for node in node.ancestors() {
|
||||||
if let Some(node) = ElementCast::to_ref(node.r()) {
|
if let Some(node) = node.downcast::<Element>() {
|
||||||
if node.as_maybe_activatable().is_some() {
|
if node.as_maybe_activatable().is_some() {
|
||||||
return Some(Root::from_ref(node))
|
return Some(Root::from_ref(node))
|
||||||
}
|
}
|
||||||
|
@ -1833,7 +1838,7 @@ impl Element {
|
||||||
// the script can generate more click events from the handler)
|
// the script can generate more click events from the handler)
|
||||||
assert!(!self.click_in_progress());
|
assert!(!self.click_in_progress());
|
||||||
|
|
||||||
let target = EventTargetCast::from_ref(self);
|
let target = self.upcast::<EventTarget>();
|
||||||
// Step 2 (requires canvas support)
|
// Step 2 (requires canvas support)
|
||||||
// Step 3
|
// Step 3
|
||||||
self.set_click_in_progress(true);
|
self.set_click_in_progress(true);
|
||||||
|
@ -1870,7 +1875,7 @@ impl Element {
|
||||||
};
|
};
|
||||||
self.event_state.set(state);
|
self.event_state.set(state);
|
||||||
|
|
||||||
let node = NodeCast::from_ref(self);
|
let node = self.upcast::<Node>();
|
||||||
node.dirty(NodeDamage::NodeStyleDamaged);
|
node.dirty(NodeDamage::NodeStyleDamaged);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1917,20 +1922,20 @@ impl Element {
|
||||||
|
|
||||||
impl Element {
|
impl Element {
|
||||||
pub fn check_ancestors_disabled_state_for_form_control(&self) {
|
pub fn check_ancestors_disabled_state_for_form_control(&self) {
|
||||||
let node = NodeCast::from_ref(self);
|
let node = self.upcast::<Node>();
|
||||||
if self.get_disabled_state() { return; }
|
if self.get_disabled_state() { return; }
|
||||||
for ancestor in node.ancestors() {
|
for ancestor in node.ancestors() {
|
||||||
let ancestor = ancestor;
|
let ancestor = ancestor;
|
||||||
let ancestor = ancestor.r();
|
let ancestor = ancestor.r();
|
||||||
if !ancestor.is_htmlfieldsetelement() { continue; }
|
if !ancestor.is::<HTMLFieldSetElement>() { continue; }
|
||||||
if !ElementCast::to_ref(ancestor).unwrap().get_disabled_state() { continue; }
|
if !ancestor.downcast::<Element>().unwrap().get_disabled_state() { continue; }
|
||||||
if ancestor.is_parent_of(node) {
|
if ancestor.is_parent_of(node) {
|
||||||
self.set_disabled_state(true);
|
self.set_disabled_state(true);
|
||||||
self.set_enabled_state(false);
|
self.set_enabled_state(false);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
match ancestor.children()
|
match ancestor.children()
|
||||||
.find(|child| child.r().is_htmllegendelement())
|
.find(|child| child.r().is::<HTMLLegendElement>())
|
||||||
{
|
{
|
||||||
Some(ref legend) => {
|
Some(ref legend) => {
|
||||||
// XXXabinader: should we save previous ancestor to avoid this iteration?
|
// XXXabinader: should we save previous ancestor to avoid this iteration?
|
||||||
|
@ -1946,9 +1951,9 @@ impl Element {
|
||||||
|
|
||||||
pub fn check_parent_disabled_state_for_option(&self) {
|
pub fn check_parent_disabled_state_for_option(&self) {
|
||||||
if self.get_disabled_state() { return; }
|
if self.get_disabled_state() { return; }
|
||||||
let node = NodeCast::from_ref(self);
|
let node = self.upcast::<Node>();
|
||||||
if let Some(ref parent) = node.GetParentNode() {
|
if let Some(ref parent) = node.GetParentNode() {
|
||||||
if parent.r().is_htmloptgroupelement() && ElementCast::to_ref(parent.r()).unwrap().get_disabled_state() {
|
if parent.r().is::<HTMLOptGroupElement>() && parent.downcast::<Element>().unwrap().get_disabled_state() {
|
||||||
self.set_disabled_state(true);
|
self.set_disabled_state(true);
|
||||||
self.set_enabled_state(false);
|
self.set_enabled_state(false);
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,7 +6,7 @@ use dom::bindings::cell::DOMRefCell;
|
||||||
use dom::bindings::codegen::Bindings::ErrorEventBinding;
|
use dom::bindings::codegen::Bindings::ErrorEventBinding;
|
||||||
use dom::bindings::codegen::Bindings::ErrorEventBinding::ErrorEventMethods;
|
use dom::bindings::codegen::Bindings::ErrorEventBinding::ErrorEventMethods;
|
||||||
use dom::bindings::codegen::Bindings::EventBinding::EventMethods;
|
use dom::bindings::codegen::Bindings::EventBinding::EventMethods;
|
||||||
use dom::bindings::codegen::InheritTypes::EventCast;
|
use dom::bindings::conversions::Castable;
|
||||||
use dom::bindings::error::Fallible;
|
use dom::bindings::error::Fallible;
|
||||||
use dom::bindings::global::GlobalRef;
|
use dom::bindings::global::GlobalRef;
|
||||||
use dom::bindings::js::{MutHeapJSVal, Root};
|
use dom::bindings::js::{MutHeapJSVal, Root};
|
||||||
|
@ -59,7 +59,7 @@ impl ErrorEvent {
|
||||||
error: HandleValue) -> Root<ErrorEvent> {
|
error: HandleValue) -> Root<ErrorEvent> {
|
||||||
let ev = ErrorEvent::new_uninitialized(global);
|
let ev = ErrorEvent::new_uninitialized(global);
|
||||||
{
|
{
|
||||||
let event = EventCast::from_ref(ev.r());
|
let event = ev.upcast::<Event>();
|
||||||
event.InitEvent(type_, bubbles == EventBubbles::Bubbles,
|
event.InitEvent(type_, bubbles == EventBubbles::Bubbles,
|
||||||
cancelable == EventCancelable::Cancelable);
|
cancelable == EventCancelable::Cancelable);
|
||||||
*ev.message.borrow_mut() = message;
|
*ev.message.borrow_mut() = message;
|
||||||
|
|
|
@ -5,7 +5,7 @@
|
||||||
use devtools_traits::{StartedTimelineMarker, TimelineMarker, TimelineMarkerType};
|
use devtools_traits::{StartedTimelineMarker, TimelineMarker, TimelineMarkerType};
|
||||||
use dom::bindings::callback::ExceptionHandling::Report;
|
use dom::bindings::callback::ExceptionHandling::Report;
|
||||||
use dom::bindings::codegen::Bindings::EventBinding::EventMethods;
|
use dom::bindings::codegen::Bindings::EventBinding::EventMethods;
|
||||||
use dom::bindings::codegen::InheritTypes::{EventTargetCast, NodeCast};
|
use dom::bindings::conversions::Castable;
|
||||||
use dom::bindings::global::{GlobalRoot, global_object_for_reflector};
|
use dom::bindings::global::{GlobalRoot, global_object_for_reflector};
|
||||||
use dom::bindings::js::{JS, Root, RootedReference};
|
use dom::bindings::js::{JS, Root, RootedReference};
|
||||||
use dom::bindings::trace::RootedVec;
|
use dom::bindings::trace::RootedVec;
|
||||||
|
@ -148,9 +148,9 @@ pub fn dispatch_event(target: &EventTarget, pseudo_target: Option<&EventTarget>,
|
||||||
event.set_dispatching(true);
|
event.set_dispatching(true);
|
||||||
|
|
||||||
let mut chain: RootedVec<JS<EventTarget>> = RootedVec::new();
|
let mut chain: RootedVec<JS<EventTarget>> = RootedVec::new();
|
||||||
if let Some(target_node) = NodeCast::to_ref(target) {
|
if let Some(target_node) = target.downcast::<Node>() {
|
||||||
for ancestor in target_node.ancestors() {
|
for ancestor in target_node.ancestors() {
|
||||||
let ancestor_target = EventTargetCast::from_ref(ancestor.r());
|
let ancestor_target = ancestor.upcast::<EventTarget>();
|
||||||
chain.push(JS::from_ref(ancestor_target))
|
chain.push(JS::from_ref(ancestor_target))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -161,7 +161,7 @@ pub fn dispatch_event(target: &EventTarget, pseudo_target: Option<&EventTarget>,
|
||||||
let target = event.GetTarget();
|
let target = event.GetTarget();
|
||||||
match target {
|
match target {
|
||||||
Some(ref target) => {
|
Some(ref target) => {
|
||||||
let node: Option<&Node> = NodeCast::to_ref(target.r());
|
let node: Option<&Node> = target.downcast::<Node>();
|
||||||
match node {
|
match node {
|
||||||
Some(node) => {
|
Some(node) => {
|
||||||
let vtable = vtable_for(&node);
|
let vtable = vtable_for(&node);
|
||||||
|
|
|
@ -5,7 +5,7 @@
|
||||||
use dom::bindings::codegen::Bindings::BlobBinding::BlobMethods;
|
use dom::bindings::codegen::Bindings::BlobBinding::BlobMethods;
|
||||||
use dom::bindings::codegen::Bindings::EventHandlerBinding::EventHandlerNonNull;
|
use dom::bindings::codegen::Bindings::EventHandlerBinding::EventHandlerNonNull;
|
||||||
use dom::bindings::codegen::Bindings::FileReaderBinding::{self, FileReaderConstants, FileReaderMethods};
|
use dom::bindings::codegen::Bindings::FileReaderBinding::{self, FileReaderConstants, FileReaderMethods};
|
||||||
use dom::bindings::codegen::InheritTypes::{EventCast, EventTargetCast};
|
use dom::bindings::conversions::Castable;
|
||||||
use dom::bindings::error::{Error, ErrorResult, Fallible};
|
use dom::bindings::error::{Error, ErrorResult, Fallible};
|
||||||
use dom::bindings::global::{GlobalField, GlobalRef};
|
use dom::bindings::global::{GlobalField, GlobalRef};
|
||||||
use dom::bindings::js::{JS, MutNullableHeap, Root};
|
use dom::bindings::js::{JS, MutNullableHeap, Root};
|
||||||
|
@ -13,7 +13,7 @@ use dom::bindings::refcounted::Trusted;
|
||||||
use dom::bindings::utils::{Reflectable, reflect_dom_object};
|
use dom::bindings::utils::{Reflectable, reflect_dom_object};
|
||||||
use dom::blob::Blob;
|
use dom::blob::Blob;
|
||||||
use dom::domexception::{DOMErrorName, DOMException};
|
use dom::domexception::{DOMErrorName, DOMException};
|
||||||
use dom::event::{EventBubbles, EventCancelable};
|
use dom::event::{Event, EventBubbles, EventCancelable};
|
||||||
use dom::eventtarget::EventTarget;
|
use dom::eventtarget::EventTarget;
|
||||||
use dom::progressevent::ProgressEvent;
|
use dom::progressevent::ProgressEvent;
|
||||||
use encoding::all::UTF_8;
|
use encoding::all::UTF_8;
|
||||||
|
@ -325,8 +325,8 @@ impl FileReader {
|
||||||
type_, EventBubbles::DoesNotBubble, EventCancelable::NotCancelable,
|
type_, EventBubbles::DoesNotBubble, EventCancelable::NotCancelable,
|
||||||
total.is_some(), loaded, total.unwrap_or(0));
|
total.is_some(), loaded, total.unwrap_or(0));
|
||||||
|
|
||||||
let target = EventTargetCast::from_ref(self);
|
let target = self.upcast::<EventTarget>();
|
||||||
let event = EventCast::from_ref(progressevent.r());
|
let event = progressevent.upcast::<Event>();
|
||||||
event.fire(target);
|
event.fire(target);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -5,9 +5,9 @@
|
||||||
use dom::bindings::cell::DOMRefCell;
|
use dom::bindings::cell::DOMRefCell;
|
||||||
use dom::bindings::codegen::Bindings::FormDataBinding;
|
use dom::bindings::codegen::Bindings::FormDataBinding;
|
||||||
use dom::bindings::codegen::Bindings::FormDataBinding::FormDataMethods;
|
use dom::bindings::codegen::Bindings::FormDataBinding::FormDataMethods;
|
||||||
use dom::bindings::codegen::InheritTypes::FileCast;
|
|
||||||
use dom::bindings::codegen::UnionTypes::FileOrString;
|
use dom::bindings::codegen::UnionTypes::FileOrString;
|
||||||
use dom::bindings::codegen::UnionTypes::FileOrString::{eFile, eString};
|
use dom::bindings::codegen::UnionTypes::FileOrString::{eFile, eString};
|
||||||
|
use dom::bindings::conversions::Castable;
|
||||||
use dom::bindings::error::{Fallible};
|
use dom::bindings::error::{Fallible};
|
||||||
use dom::bindings::global::{GlobalField, GlobalRef};
|
use dom::bindings::global::{GlobalField, GlobalRef};
|
||||||
use dom::bindings::js::{JS, Root};
|
use dom::bindings::js::{JS, Root};
|
||||||
|
@ -116,7 +116,7 @@ impl FormDataMethods for FormData {
|
||||||
impl FormData {
|
impl FormData {
|
||||||
fn get_file_from_blob(&self, value: &Blob, filename: Option<DOMString>) -> Root<File> {
|
fn get_file_from_blob(&self, value: &Blob, filename: Option<DOMString>) -> Root<File> {
|
||||||
let global = self.global.root();
|
let global = self.global.root();
|
||||||
let f: Option<&File> = FileCast::to_ref(value);
|
let f: Option<&File> = value.downcast::<File>();
|
||||||
let name = filename.unwrap_or(f.map(|inner| inner.name().clone()).unwrap_or("blob".to_owned()));
|
let name = filename.unwrap_or(f.map(|inner| inner.name().clone()).unwrap_or("blob".to_owned()));
|
||||||
File::new(global.r(), value, name)
|
File::new(global.r(), value, name)
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,8 +10,7 @@ use dom::bindings::codegen::Bindings::HTMLAnchorElementBinding;
|
||||||
use dom::bindings::codegen::Bindings::HTMLAnchorElementBinding::HTMLAnchorElementMethods;
|
use dom::bindings::codegen::Bindings::HTMLAnchorElementBinding::HTMLAnchorElementMethods;
|
||||||
use dom::bindings::codegen::Bindings::MouseEventBinding::MouseEventMethods;
|
use dom::bindings::codegen::Bindings::MouseEventBinding::MouseEventMethods;
|
||||||
use dom::bindings::codegen::Bindings::NodeBinding::NodeMethods;
|
use dom::bindings::codegen::Bindings::NodeBinding::NodeMethods;
|
||||||
use dom::bindings::codegen::InheritTypes::{ElementCast, HTMLElementCast};
|
use dom::bindings::conversions::Castable;
|
||||||
use dom::bindings::codegen::InheritTypes::{HTMLImageElementDerived, MouseEventCast, NodeCast};
|
|
||||||
use dom::bindings::js::{JS, MutNullableHeap, Root};
|
use dom::bindings::js::{JS, MutNullableHeap, Root};
|
||||||
use dom::document::Document;
|
use dom::document::Document;
|
||||||
use dom::domtokenlist::DOMTokenList;
|
use dom::domtokenlist::DOMTokenList;
|
||||||
|
@ -19,6 +18,8 @@ use dom::element::Element;
|
||||||
use dom::event::Event;
|
use dom::event::Event;
|
||||||
use dom::eventtarget::EventTarget;
|
use dom::eventtarget::EventTarget;
|
||||||
use dom::htmlelement::HTMLElement;
|
use dom::htmlelement::HTMLElement;
|
||||||
|
use dom::htmlimageelement::HTMLImageElement;
|
||||||
|
use dom::mouseevent::MouseEvent;
|
||||||
use dom::node::{Node, document_from_node, window_from_node};
|
use dom::node::{Node, document_from_node, window_from_node};
|
||||||
use dom::virtualmethods::VirtualMethods;
|
use dom::virtualmethods::VirtualMethods;
|
||||||
use num::ToPrimitive;
|
use num::ToPrimitive;
|
||||||
|
@ -55,7 +56,7 @@ impl HTMLAnchorElement {
|
||||||
|
|
||||||
impl VirtualMethods for HTMLAnchorElement {
|
impl VirtualMethods for HTMLAnchorElement {
|
||||||
fn super_type(&self) -> Option<&VirtualMethods> {
|
fn super_type(&self) -> Option<&VirtualMethods> {
|
||||||
let htmlelement: &HTMLElement = HTMLElementCast::from_ref(self);
|
let htmlelement: &HTMLElement = self.upcast::<HTMLElement>();
|
||||||
Some(htmlelement as &VirtualMethods)
|
Some(htmlelement as &VirtualMethods)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -70,20 +71,20 @@ impl VirtualMethods for HTMLAnchorElement {
|
||||||
impl HTMLAnchorElementMethods for HTMLAnchorElement {
|
impl HTMLAnchorElementMethods for HTMLAnchorElement {
|
||||||
// https://html.spec.whatwg.org/multipage/#dom-a-text
|
// https://html.spec.whatwg.org/multipage/#dom-a-text
|
||||||
fn Text(&self) -> DOMString {
|
fn Text(&self) -> DOMString {
|
||||||
let node = NodeCast::from_ref(self);
|
let node = self.upcast::<Node>();
|
||||||
node.GetTextContent().unwrap()
|
node.GetTextContent().unwrap()
|
||||||
}
|
}
|
||||||
|
|
||||||
// https://html.spec.whatwg.org/multipage/#dom-a-text
|
// https://html.spec.whatwg.org/multipage/#dom-a-text
|
||||||
fn SetText(&self, value: DOMString) {
|
fn SetText(&self, value: DOMString) {
|
||||||
let node = NodeCast::from_ref(self);
|
let node = self.upcast::<Node>();
|
||||||
node.SetTextContent(Some(value))
|
node.SetTextContent(Some(value))
|
||||||
}
|
}
|
||||||
|
|
||||||
// https://html.spec.whatwg.org/multipage/#dom-a-rellist
|
// https://html.spec.whatwg.org/multipage/#dom-a-rellist
|
||||||
fn RelList(&self) -> Root<DOMTokenList> {
|
fn RelList(&self) -> Root<DOMTokenList> {
|
||||||
self.rel_list.or_init(|| {
|
self.rel_list.or_init(|| {
|
||||||
DOMTokenList::new(ElementCast::from_ref(self), &atom!("rel"))
|
DOMTokenList::new(self.upcast::<Element>(), &atom!("rel"))
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -114,7 +115,7 @@ impl HTMLAnchorElementMethods for HTMLAnchorElement {
|
||||||
|
|
||||||
impl Activatable for HTMLAnchorElement {
|
impl Activatable for HTMLAnchorElement {
|
||||||
fn as_element(&self) -> &Element {
|
fn as_element(&self) -> &Element {
|
||||||
ElementCast::from_ref(self)
|
self.upcast::<Element>()
|
||||||
}
|
}
|
||||||
|
|
||||||
fn is_instance_activatable(&self) -> bool {
|
fn is_instance_activatable(&self) -> bool {
|
||||||
|
@ -123,7 +124,7 @@ impl Activatable for HTMLAnchorElement {
|
||||||
// hyperlink"
|
// hyperlink"
|
||||||
// https://html.spec.whatwg.org/multipage/#the-a-element
|
// https://html.spec.whatwg.org/multipage/#the-a-element
|
||||||
// "The activation behaviour of a elements *that create hyperlinks*"
|
// "The activation behaviour of a elements *that create hyperlinks*"
|
||||||
ElementCast::from_ref(self).has_attribute(&atom!("href"))
|
self.upcast::<Element>().has_attribute(&atom!("href"))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -145,13 +146,13 @@ impl Activatable for HTMLAnchorElement {
|
||||||
}
|
}
|
||||||
//TODO: Step 2. Check if browsing context is specified and act accordingly.
|
//TODO: Step 2. Check if browsing context is specified and act accordingly.
|
||||||
//Step 3. Handle <img ismap/>.
|
//Step 3. Handle <img ismap/>.
|
||||||
let element = ElementCast::from_ref(self);
|
let element = self.upcast::<Element>();
|
||||||
let mouse_event = MouseEventCast::to_ref(event).unwrap();
|
let mouse_event = event.downcast::<MouseEvent>().unwrap();
|
||||||
let mut ismap_suffix = None;
|
let mut ismap_suffix = None;
|
||||||
if let Some(element) = ElementCast::to_ref(target) {
|
if let Some(element) = target.downcast::<Element>() {
|
||||||
if target.is_htmlimageelement() && element.has_attribute(&atom!("ismap")) {
|
if target.is::<HTMLImageElement>() && element.has_attribute(&atom!("ismap")) {
|
||||||
|
|
||||||
let target_node = NodeCast::from_ref(element);
|
let target_node = element.upcast::<Node>();
|
||||||
let rect = window_from_node(target_node).r().content_box_query(
|
let rect = window_from_node(target_node).r().content_box_query(
|
||||||
target_node.to_trusted_node_address());
|
target_node.to_trusted_node_address());
|
||||||
ismap_suffix = Some(
|
ismap_suffix = Some(
|
||||||
|
|
|
@ -5,7 +5,7 @@
|
||||||
use dom::attr::AttrValue;
|
use dom::attr::AttrValue;
|
||||||
use dom::bindings::codegen::Bindings::HTMLAppletElementBinding;
|
use dom::bindings::codegen::Bindings::HTMLAppletElementBinding;
|
||||||
use dom::bindings::codegen::Bindings::HTMLAppletElementBinding::HTMLAppletElementMethods;
|
use dom::bindings::codegen::Bindings::HTMLAppletElementBinding::HTMLAppletElementMethods;
|
||||||
use dom::bindings::codegen::InheritTypes::HTMLElementCast;
|
use dom::bindings::conversions::Castable;
|
||||||
use dom::bindings::js::Root;
|
use dom::bindings::js::Root;
|
||||||
use dom::document::Document;
|
use dom::document::Document;
|
||||||
use dom::htmlelement::HTMLElement;
|
use dom::htmlelement::HTMLElement;
|
||||||
|
@ -48,7 +48,7 @@ impl HTMLAppletElementMethods for HTMLAppletElement {
|
||||||
|
|
||||||
impl VirtualMethods for HTMLAppletElement {
|
impl VirtualMethods for HTMLAppletElement {
|
||||||
fn super_type(&self) -> Option<&VirtualMethods> {
|
fn super_type(&self) -> Option<&VirtualMethods> {
|
||||||
Some(HTMLElementCast::from_ref(self) as &VirtualMethods)
|
Some(self.upcast::<HTMLElement>() as &VirtualMethods)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn parse_plain_attribute(&self, name: &Atom, value: DOMString) -> AttrValue {
|
fn parse_plain_attribute(&self, name: &Atom, value: DOMString) -> AttrValue {
|
||||||
|
|
|
@ -5,11 +5,12 @@
|
||||||
use dom::attr::AttrValue;
|
use dom::attr::AttrValue;
|
||||||
use dom::bindings::codegen::Bindings::HTMLAreaElementBinding;
|
use dom::bindings::codegen::Bindings::HTMLAreaElementBinding;
|
||||||
use dom::bindings::codegen::Bindings::HTMLAreaElementBinding::HTMLAreaElementMethods;
|
use dom::bindings::codegen::Bindings::HTMLAreaElementBinding::HTMLAreaElementMethods;
|
||||||
use dom::bindings::codegen::InheritTypes::{ElementCast, HTMLElementCast};
|
use dom::bindings::conversions::Castable;
|
||||||
use dom::bindings::js::{JS, MutNullableHeap, Root};
|
use dom::bindings::js::{JS, MutNullableHeap, Root};
|
||||||
use dom::bindings::utils::Reflectable;
|
use dom::bindings::utils::Reflectable;
|
||||||
use dom::document::Document;
|
use dom::document::Document;
|
||||||
use dom::domtokenlist::DOMTokenList;
|
use dom::domtokenlist::DOMTokenList;
|
||||||
|
use dom::element::Element;
|
||||||
use dom::htmlelement::HTMLElement;
|
use dom::htmlelement::HTMLElement;
|
||||||
use dom::node::Node;
|
use dom::node::Node;
|
||||||
use dom::virtualmethods::VirtualMethods;
|
use dom::virtualmethods::VirtualMethods;
|
||||||
|
@ -42,7 +43,7 @@ impl HTMLAreaElement {
|
||||||
|
|
||||||
impl VirtualMethods for HTMLAreaElement {
|
impl VirtualMethods for HTMLAreaElement {
|
||||||
fn super_type(&self) -> Option<&VirtualMethods> {
|
fn super_type(&self) -> Option<&VirtualMethods> {
|
||||||
let htmlelement: &HTMLElement = HTMLElementCast::from_ref(self);
|
let htmlelement: &HTMLElement = self.upcast::<HTMLElement>();
|
||||||
Some(htmlelement as &VirtualMethods)
|
Some(htmlelement as &VirtualMethods)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -58,7 +59,7 @@ impl HTMLAreaElementMethods for HTMLAreaElement {
|
||||||
// https://html.spec.whatwg.org/multipage/#dom-area-rellist
|
// https://html.spec.whatwg.org/multipage/#dom-area-rellist
|
||||||
fn RelList(&self) -> Root<DOMTokenList> {
|
fn RelList(&self) -> Root<DOMTokenList> {
|
||||||
self.rel_list.or_init(|| {
|
self.rel_list.or_init(|| {
|
||||||
DOMTokenList::new(ElementCast::from_ref(self), &atom!("rel"))
|
DOMTokenList::new(self.upcast::<Element>(), &atom!("rel"))
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,10 +4,10 @@
|
||||||
|
|
||||||
use dom::attr::Attr;
|
use dom::attr::Attr;
|
||||||
use dom::bindings::codegen::Bindings::HTMLBaseElementBinding;
|
use dom::bindings::codegen::Bindings::HTMLBaseElementBinding;
|
||||||
use dom::bindings::codegen::InheritTypes::{ElementCast, HTMLElementCast};
|
use dom::bindings::conversions::Castable;
|
||||||
use dom::bindings::js::Root;
|
use dom::bindings::js::Root;
|
||||||
use dom::document::Document;
|
use dom::document::Document;
|
||||||
use dom::element::AttributeMutation;
|
use dom::element::{AttributeMutation, Element};
|
||||||
use dom::htmlelement::HTMLElement;
|
use dom::htmlelement::HTMLElement;
|
||||||
use dom::node::{Node, document_from_node};
|
use dom::node::{Node, document_from_node};
|
||||||
use dom::virtualmethods::VirtualMethods;
|
use dom::virtualmethods::VirtualMethods;
|
||||||
|
@ -36,7 +36,7 @@ impl HTMLBaseElement {
|
||||||
|
|
||||||
/// https://html.spec.whatwg.org/multipage/#frozen-base-url
|
/// https://html.spec.whatwg.org/multipage/#frozen-base-url
|
||||||
pub fn frozen_base_url(&self) -> Url {
|
pub fn frozen_base_url(&self) -> Url {
|
||||||
let href = ElementCast::from_ref(self).get_attribute(&ns!(""), &atom!("href"))
|
let href = self.upcast::<Element>().get_attribute(&ns!(""), &atom!("href"))
|
||||||
.expect("The frozen base url is only defined for base elements \
|
.expect("The frozen base url is only defined for base elements \
|
||||||
that have a base url.");
|
that have a base url.");
|
||||||
let document = document_from_node(self);
|
let document = document_from_node(self);
|
||||||
|
@ -52,7 +52,7 @@ impl HTMLBaseElement {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ElementCast::from_ref(self).has_attribute(&atom!("href")) {
|
if self.upcast::<Element>().has_attribute(&atom!("href")) {
|
||||||
let document = document_from_node(self);
|
let document = document_from_node(self);
|
||||||
document.refresh_base_element();
|
document.refresh_base_element();
|
||||||
}
|
}
|
||||||
|
@ -61,7 +61,7 @@ impl HTMLBaseElement {
|
||||||
|
|
||||||
impl VirtualMethods for HTMLBaseElement {
|
impl VirtualMethods for HTMLBaseElement {
|
||||||
fn super_type(&self) -> Option<&VirtualMethods> {
|
fn super_type(&self) -> Option<&VirtualMethods> {
|
||||||
Some(HTMLElementCast::from_ref(self) as &VirtualMethods)
|
Some(self.upcast::<HTMLElement>() as &VirtualMethods)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn attribute_mutated(&self, attr: &Attr, mutation: AttributeMutation) {
|
fn attribute_mutated(&self, attr: &Attr, mutation: AttributeMutation) {
|
||||||
|
|
|
@ -8,11 +8,12 @@ use dom::bindings::cell::DOMRefCell;
|
||||||
use dom::bindings::codegen::Bindings::EventHandlerBinding::EventHandlerNonNull;
|
use dom::bindings::codegen::Bindings::EventHandlerBinding::EventHandlerNonNull;
|
||||||
use dom::bindings::codegen::Bindings::HTMLBodyElementBinding::{self, HTMLBodyElementMethods};
|
use dom::bindings::codegen::Bindings::HTMLBodyElementBinding::{self, HTMLBodyElementMethods};
|
||||||
use dom::bindings::codegen::Bindings::WindowBinding::WindowMethods;
|
use dom::bindings::codegen::Bindings::WindowBinding::WindowMethods;
|
||||||
use dom::bindings::codegen::InheritTypes::{ElementCast, EventTargetCast, HTMLElementCast};
|
use dom::bindings::conversions::Castable;
|
||||||
use dom::bindings::js::Root;
|
use dom::bindings::js::Root;
|
||||||
use dom::bindings::utils::Reflectable;
|
use dom::bindings::utils::Reflectable;
|
||||||
use dom::document::Document;
|
use dom::document::Document;
|
||||||
use dom::element::{AttributeMutation, RawLayoutElementHelpers};
|
use dom::element::{AttributeMutation, Element, RawLayoutElementHelpers};
|
||||||
|
use dom::eventtarget::EventTarget;
|
||||||
use dom::htmlelement::HTMLElement;
|
use dom::htmlelement::HTMLElement;
|
||||||
use dom::node::{Node, document_from_node, window_from_node};
|
use dom::node::{Node, document_from_node, window_from_node};
|
||||||
use dom::virtualmethods::VirtualMethods;
|
use dom::virtualmethods::VirtualMethods;
|
||||||
|
@ -67,7 +68,7 @@ impl HTMLBodyElementMethods for HTMLBodyElement {
|
||||||
|
|
||||||
// https://html.spec.whatwg.org/multipage/#dom-body-text
|
// https://html.spec.whatwg.org/multipage/#dom-body-text
|
||||||
fn SetText(&self, value: DOMString) {
|
fn SetText(&self, value: DOMString) {
|
||||||
let element = ElementCast::from_ref(self);
|
let element = self.upcast::<Element>();
|
||||||
let color = str::parse_legacy_color(&value).ok();
|
let color = str::parse_legacy_color(&value).ok();
|
||||||
element.set_attribute(&Atom::from_slice("text"), AttrValue::Color(value, color));
|
element.set_attribute(&Atom::from_slice("text"), AttrValue::Color(value, color));
|
||||||
}
|
}
|
||||||
|
@ -106,7 +107,7 @@ impl HTMLBodyElement {
|
||||||
#[allow(unsafe_code)]
|
#[allow(unsafe_code)]
|
||||||
pub fn get_color(&self) -> Option<RGBA> {
|
pub fn get_color(&self) -> Option<RGBA> {
|
||||||
unsafe {
|
unsafe {
|
||||||
ElementCast::from_ref(self)
|
self.upcast::<Element>()
|
||||||
.get_attr_for_layout(&ns!(""), &atom!("text"))
|
.get_attr_for_layout(&ns!(""), &atom!("text"))
|
||||||
.and_then(AttrValue::as_color)
|
.and_then(AttrValue::as_color)
|
||||||
.cloned()
|
.cloned()
|
||||||
|
@ -123,7 +124,7 @@ impl HTMLBodyElement {
|
||||||
|
|
||||||
impl VirtualMethods for HTMLBodyElement {
|
impl VirtualMethods for HTMLBodyElement {
|
||||||
fn super_type(&self) -> Option<&VirtualMethods> {
|
fn super_type(&self) -> Option<&VirtualMethods> {
|
||||||
let element: &HTMLElement = HTMLElementCast::from_ref(self);
|
let element: &HTMLElement = self.upcast::<HTMLElement>();
|
||||||
Some(element as &VirtualMethods)
|
Some(element as &VirtualMethods)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -180,8 +181,8 @@ impl VirtualMethods for HTMLBodyElement {
|
||||||
&atom!(onlanguagechange) | &atom!(onmessage) | &atom!(onoffline) | &atom!(ononline) |
|
&atom!(onlanguagechange) | &atom!(onmessage) | &atom!(onoffline) | &atom!(ononline) |
|
||||||
&atom!(onpagehide) | &atom!(onpageshow) | &atom!(onpopstate) | &atom!(onstorage) |
|
&atom!(onpagehide) | &atom!(onpageshow) | &atom!(onpopstate) | &atom!(onstorage) |
|
||||||
&atom!(onresize) | &atom!(onunload) | &atom!(onerror)
|
&atom!(onresize) | &atom!(onunload) | &atom!(onerror)
|
||||||
=> EventTargetCast::from_ref(window.r()), // forwarded event
|
=> window.upcast::<EventTarget>(), // forwarded event
|
||||||
_ => EventTargetCast::from_ref(self),
|
_ => self.upcast::<EventTarget>(),
|
||||||
};
|
};
|
||||||
evtarget.set_event_handler_uncompiled(cx, url, reflector,
|
evtarget.set_event_handler_uncompiled(cx, url, reflector,
|
||||||
&name[2..],
|
&name[2..],
|
||||||
|
|
|
@ -6,14 +6,14 @@ use dom::activation::Activatable;
|
||||||
use dom::attr::Attr;
|
use dom::attr::Attr;
|
||||||
use dom::bindings::codegen::Bindings::HTMLButtonElementBinding;
|
use dom::bindings::codegen::Bindings::HTMLButtonElementBinding;
|
||||||
use dom::bindings::codegen::Bindings::HTMLButtonElementBinding::HTMLButtonElementMethods;
|
use dom::bindings::codegen::Bindings::HTMLButtonElementBinding::HTMLButtonElementMethods;
|
||||||
use dom::bindings::codegen::InheritTypes::{ElementCast, HTMLButtonElementCast, HTMLElementCast};
|
use dom::bindings::conversions::Castable;
|
||||||
use dom::bindings::codegen::InheritTypes::{HTMLFieldSetElementDerived, NodeCast};
|
|
||||||
use dom::bindings::js::Root;
|
use dom::bindings::js::Root;
|
||||||
use dom::document::Document;
|
use dom::document::Document;
|
||||||
use dom::element::{AttributeMutation, Element, IN_ENABLED_STATE};
|
use dom::element::{AttributeMutation, Element, IN_ENABLED_STATE};
|
||||||
use dom::event::Event;
|
use dom::event::Event;
|
||||||
use dom::eventtarget::EventTarget;
|
use dom::eventtarget::EventTarget;
|
||||||
use dom::htmlelement::HTMLElement;
|
use dom::htmlelement::HTMLElement;
|
||||||
|
use dom::htmlfieldsetelement::HTMLFieldSetElement;
|
||||||
use dom::htmlformelement::{FormControl, FormSubmitter};
|
use dom::htmlformelement::{FormControl, FormSubmitter};
|
||||||
use dom::htmlformelement::{SubmittedFrom, HTMLFormElement};
|
use dom::htmlformelement::{SubmittedFrom, HTMLFormElement};
|
||||||
use dom::node::{Node, document_from_node, window_from_node};
|
use dom::node::{Node, document_from_node, window_from_node};
|
||||||
|
@ -82,7 +82,7 @@ impl HTMLButtonElementMethods for HTMLButtonElement {
|
||||||
|
|
||||||
// https://html.spec.whatwg.org/multipage/#dom-button-type
|
// https://html.spec.whatwg.org/multipage/#dom-button-type
|
||||||
fn Type(&self) -> DOMString {
|
fn Type(&self) -> DOMString {
|
||||||
let elem = ElementCast::from_ref(self);
|
let elem = self.upcast::<Element>();
|
||||||
let mut ty = elem.get_string_attribute(&atom!("type"));
|
let mut ty = elem.get_string_attribute(&atom!("type"));
|
||||||
ty.make_ascii_lowercase();
|
ty.make_ascii_lowercase();
|
||||||
// https://html.spec.whatwg.org/multipage/#attr-button-type
|
// https://html.spec.whatwg.org/multipage/#attr-button-type
|
||||||
|
@ -135,7 +135,7 @@ impl HTMLButtonElementMethods for HTMLButtonElement {
|
||||||
|
|
||||||
impl VirtualMethods for HTMLButtonElement {
|
impl VirtualMethods for HTMLButtonElement {
|
||||||
fn super_type(&self) -> Option<&VirtualMethods> {
|
fn super_type(&self) -> Option<&VirtualMethods> {
|
||||||
let htmlelement: &HTMLElement = HTMLElementCast::from_ref(self);
|
let htmlelement: &HTMLElement = self.upcast::<HTMLElement>();
|
||||||
Some(htmlelement as &VirtualMethods)
|
Some(htmlelement as &VirtualMethods)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -143,7 +143,7 @@ impl VirtualMethods for HTMLButtonElement {
|
||||||
self.super_type().unwrap().attribute_mutated(attr, mutation);
|
self.super_type().unwrap().attribute_mutated(attr, mutation);
|
||||||
match attr.local_name() {
|
match attr.local_name() {
|
||||||
&atom!(disabled) => {
|
&atom!(disabled) => {
|
||||||
let el = ElementCast::from_ref(self);
|
let el = self.upcast::<Element>();
|
||||||
match mutation {
|
match mutation {
|
||||||
AttributeMutation::Set(Some(_)) => {}
|
AttributeMutation::Set(Some(_)) => {}
|
||||||
AttributeMutation::Set(None) => {
|
AttributeMutation::Set(None) => {
|
||||||
|
@ -166,7 +166,7 @@ impl VirtualMethods for HTMLButtonElement {
|
||||||
s.bind_to_tree(tree_in_doc);
|
s.bind_to_tree(tree_in_doc);
|
||||||
}
|
}
|
||||||
|
|
||||||
let el = ElementCast::from_ref(self);
|
let el = self.upcast::<Element>();
|
||||||
el.check_ancestors_disabled_state_for_form_control();
|
el.check_ancestors_disabled_state_for_form_control();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -175,9 +175,9 @@ impl VirtualMethods for HTMLButtonElement {
|
||||||
s.unbind_from_tree(tree_in_doc);
|
s.unbind_from_tree(tree_in_doc);
|
||||||
}
|
}
|
||||||
|
|
||||||
let node = NodeCast::from_ref(self);
|
let node = self.upcast::<Node>();
|
||||||
let el = ElementCast::from_ref(self);
|
let el = self.upcast::<Element>();
|
||||||
if node.ancestors().any(|ancestor| ancestor.r().is_htmlfieldsetelement()) {
|
if node.ancestors().any(|ancestor| ancestor.r().is::<HTMLFieldSetElement>()) {
|
||||||
el.check_ancestors_disabled_state_for_form_control();
|
el.check_ancestors_disabled_state_for_form_control();
|
||||||
} else {
|
} else {
|
||||||
el.check_disabled_attribute();
|
el.check_disabled_attribute();
|
||||||
|
@ -189,12 +189,12 @@ impl FormControl for HTMLButtonElement {}
|
||||||
|
|
||||||
impl<'a> Activatable for &'a HTMLButtonElement {
|
impl<'a> Activatable for &'a HTMLButtonElement {
|
||||||
fn as_element(&self) -> &Element {
|
fn as_element(&self) -> &Element {
|
||||||
ElementCast::from_ref(*self)
|
self.upcast::<Element>()
|
||||||
}
|
}
|
||||||
|
|
||||||
fn is_instance_activatable(&self) -> bool {
|
fn is_instance_activatable(&self) -> bool {
|
||||||
//https://html.spec.whatwg.org/multipage/#the-button-element
|
//https://html.spec.whatwg.org/multipage/#the-button-element
|
||||||
let el = ElementCast::from_ref(*self);
|
let el = self.upcast::<Element>();
|
||||||
!(el.get_disabled_state())
|
!(el.get_disabled_state())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -226,14 +226,14 @@ impl<'a> Activatable for &'a HTMLButtonElement {
|
||||||
#[allow(unsafe_code)]
|
#[allow(unsafe_code)]
|
||||||
fn implicit_submission(&self, ctrlKey: bool, shiftKey: bool, altKey: bool, metaKey: bool) {
|
fn implicit_submission(&self, ctrlKey: bool, shiftKey: bool, altKey: bool, metaKey: bool) {
|
||||||
let doc = document_from_node(*self);
|
let doc = document_from_node(*self);
|
||||||
let node = NodeCast::from_ref(doc.r());
|
let node = doc.upcast::<Node>();
|
||||||
let owner = self.form_owner();
|
let owner = self.form_owner();
|
||||||
let elem = ElementCast::from_ref(*self);
|
let elem = self.upcast::<Element>();
|
||||||
if owner.is_none() || elem.click_in_progress() {
|
if owner.is_none() || elem.click_in_progress() {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
node.query_selector_iter("button[type=submit]".to_owned()).unwrap()
|
node.query_selector_iter("button[type=submit]".to_owned()).unwrap()
|
||||||
.filter_map(HTMLButtonElementCast::to_root)
|
.filter_map(Root::downcast::<HTMLButtonElement>)
|
||||||
.find(|r| r.r().form_owner() == owner)
|
.find(|r| r.r().form_owner() == owner)
|
||||||
.map(|s| s.r().synthetic_click_activation(ctrlKey, shiftKey, altKey, metaKey));
|
.map(|s| s.r().synthetic_click_activation(ctrlKey, shiftKey, altKey, metaKey));
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,14 +8,14 @@ use dom::bindings::cell::DOMRefCell;
|
||||||
use dom::bindings::codegen::Bindings::HTMLCanvasElementBinding;
|
use dom::bindings::codegen::Bindings::HTMLCanvasElementBinding;
|
||||||
use dom::bindings::codegen::Bindings::HTMLCanvasElementBinding::HTMLCanvasElementMethods;
|
use dom::bindings::codegen::Bindings::HTMLCanvasElementBinding::HTMLCanvasElementMethods;
|
||||||
use dom::bindings::codegen::Bindings::WebGLRenderingContextBinding::WebGLContextAttributes;
|
use dom::bindings::codegen::Bindings::WebGLRenderingContextBinding::WebGLContextAttributes;
|
||||||
use dom::bindings::codegen::InheritTypes::{ElementCast, HTMLElementCast};
|
|
||||||
use dom::bindings::codegen::UnionTypes::CanvasRenderingContext2DOrWebGLRenderingContext;
|
use dom::bindings::codegen::UnionTypes::CanvasRenderingContext2DOrWebGLRenderingContext;
|
||||||
|
use dom::bindings::conversions::Castable;
|
||||||
use dom::bindings::global::GlobalRef;
|
use dom::bindings::global::GlobalRef;
|
||||||
use dom::bindings::js::{HeapGCValue, JS, LayoutJS, Root};
|
use dom::bindings::js::{HeapGCValue, JS, LayoutJS, Root};
|
||||||
use dom::bindings::utils::{Reflectable};
|
use dom::bindings::utils::{Reflectable};
|
||||||
use dom::canvasrenderingcontext2d::{CanvasRenderingContext2D, LayoutCanvasRenderingContext2DHelpers};
|
use dom::canvasrenderingcontext2d::{CanvasRenderingContext2D, LayoutCanvasRenderingContext2DHelpers};
|
||||||
use dom::document::Document;
|
use dom::document::Document;
|
||||||
use dom::element::AttributeMutation;
|
use dom::element::{AttributeMutation, Element};
|
||||||
use dom::htmlelement::HTMLElement;
|
use dom::htmlelement::HTMLElement;
|
||||||
use dom::node::{Node, window_from_node};
|
use dom::node::{Node, window_from_node};
|
||||||
use dom::virtualmethods::VirtualMethods;
|
use dom::virtualmethods::VirtualMethods;
|
||||||
|
@ -225,7 +225,7 @@ impl HTMLCanvasElementMethods for HTMLCanvasElement {
|
||||||
|
|
||||||
// https://html.spec.whatwg.org/multipage/#dom-canvas-width
|
// https://html.spec.whatwg.org/multipage/#dom-canvas-width
|
||||||
fn SetWidth(&self, width: u32) {
|
fn SetWidth(&self, width: u32) {
|
||||||
let elem = ElementCast::from_ref(self);
|
let elem = self.upcast::<Element>();
|
||||||
elem.set_uint_attribute(&atom!("width"), width)
|
elem.set_uint_attribute(&atom!("width"), width)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -236,7 +236,7 @@ impl HTMLCanvasElementMethods for HTMLCanvasElement {
|
||||||
|
|
||||||
// https://html.spec.whatwg.org/multipage/#dom-canvas-height
|
// https://html.spec.whatwg.org/multipage/#dom-canvas-height
|
||||||
fn SetHeight(&self, height: u32) {
|
fn SetHeight(&self, height: u32) {
|
||||||
let elem = ElementCast::from_ref(self);
|
let elem = self.upcast::<Element>();
|
||||||
elem.set_uint_attribute(&atom!("height"), height)
|
elem.set_uint_attribute(&atom!("height"), height)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -264,7 +264,7 @@ impl HTMLCanvasElementMethods for HTMLCanvasElement {
|
||||||
|
|
||||||
impl VirtualMethods for HTMLCanvasElement {
|
impl VirtualMethods for HTMLCanvasElement {
|
||||||
fn super_type(&self) -> Option<&VirtualMethods> {
|
fn super_type(&self) -> Option<&VirtualMethods> {
|
||||||
let element: &HTMLElement = HTMLElementCast::from_ref(self);
|
let element: &HTMLElement = self.upcast::<HTMLElement>();
|
||||||
Some(element as &VirtualMethods)
|
Some(element as &VirtualMethods)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -4,7 +4,7 @@
|
||||||
|
|
||||||
use dom::bindings::codegen::Bindings::HTMLCollectionBinding;
|
use dom::bindings::codegen::Bindings::HTMLCollectionBinding;
|
||||||
use dom::bindings::codegen::Bindings::HTMLCollectionBinding::HTMLCollectionMethods;
|
use dom::bindings::codegen::Bindings::HTMLCollectionBinding::HTMLCollectionMethods;
|
||||||
use dom::bindings::codegen::InheritTypes::{ElementCast, NodeCast};
|
use dom::bindings::conversions::Castable;
|
||||||
use dom::bindings::global::GlobalRef;
|
use dom::bindings::global::GlobalRef;
|
||||||
use dom::bindings::js::{JS, Root};
|
use dom::bindings::js::{JS, Root};
|
||||||
use dom::bindings::trace::JSTraceable;
|
use dom::bindings::trace::JSTraceable;
|
||||||
|
@ -154,7 +154,7 @@ impl HTMLCollection {
|
||||||
struct ElementChildFilter;
|
struct ElementChildFilter;
|
||||||
impl CollectionFilter for ElementChildFilter {
|
impl CollectionFilter for ElementChildFilter {
|
||||||
fn filter(&self, elem: &Element, root: &Node) -> bool {
|
fn filter(&self, elem: &Element, root: &Node) -> bool {
|
||||||
root.is_parent_of(NodeCast::from_ref(elem))
|
root.is_parent_of(elem.upcast::<Node>())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
HTMLCollection::create(window, root, box ElementChildFilter)
|
HTMLCollection::create(window, root, box ElementChildFilter)
|
||||||
|
@ -186,7 +186,7 @@ impl<'a> Iterator for HTMLCollectionElementsIter<'a> {
|
||||||
let filter = self.filter;
|
let filter = self.filter;
|
||||||
let root = self.root.r();
|
let root = self.root.r();
|
||||||
self.node_iter.by_ref()
|
self.node_iter.by_ref()
|
||||||
.filter_map(ElementCast::to_root)
|
.filter_map(Root::downcast::<Element>)
|
||||||
.filter(|element| filter.filter(element.r(), root))
|
.filter(|element| filter.filter(element.r(), root))
|
||||||
.next()
|
.next()
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,12 +4,13 @@
|
||||||
|
|
||||||
use dom::bindings::codegen::Bindings::HTMLDataListElementBinding;
|
use dom::bindings::codegen::Bindings::HTMLDataListElementBinding;
|
||||||
use dom::bindings::codegen::Bindings::HTMLDataListElementBinding::HTMLDataListElementMethods;
|
use dom::bindings::codegen::Bindings::HTMLDataListElementBinding::HTMLDataListElementMethods;
|
||||||
use dom::bindings::codegen::InheritTypes::{HTMLOptionElementDerived, NodeCast};
|
use dom::bindings::conversions::Castable;
|
||||||
use dom::bindings::js::Root;
|
use dom::bindings::js::Root;
|
||||||
use dom::document::Document;
|
use dom::document::Document;
|
||||||
use dom::element::Element;
|
use dom::element::Element;
|
||||||
use dom::htmlcollection::{CollectionFilter, HTMLCollection};
|
use dom::htmlcollection::{CollectionFilter, HTMLCollection};
|
||||||
use dom::htmlelement::HTMLElement;
|
use dom::htmlelement::HTMLElement;
|
||||||
|
use dom::htmloptionelement::HTMLOptionElement;
|
||||||
use dom::node::{Node, window_from_node};
|
use dom::node::{Node, window_from_node};
|
||||||
use util::str::DOMString;
|
use util::str::DOMString;
|
||||||
|
|
||||||
|
@ -44,10 +45,10 @@ impl HTMLDataListElementMethods for HTMLDataListElement {
|
||||||
struct HTMLDataListOptionsFilter;
|
struct HTMLDataListOptionsFilter;
|
||||||
impl CollectionFilter for HTMLDataListOptionsFilter {
|
impl CollectionFilter for HTMLDataListOptionsFilter {
|
||||||
fn filter(&self, elem: &Element, _root: &Node) -> bool {
|
fn filter(&self, elem: &Element, _root: &Node) -> bool {
|
||||||
elem.is_htmloptionelement()
|
elem.is::<HTMLOptionElement>()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
let node = NodeCast::from_ref(self);
|
let node = self.upcast::<Node>();
|
||||||
let filter = box HTMLDataListOptionsFilter;
|
let filter = box HTMLDataListOptionsFilter;
|
||||||
let window = window_from_node(node);
|
let window = window_from_node(node);
|
||||||
HTMLCollection::create(window.r(), node, filter)
|
HTMLCollection::create(window.r(), node, filter)
|
||||||
|
|
|
@ -9,11 +9,8 @@ use dom::bindings::codegen::Bindings::HTMLElementBinding;
|
||||||
use dom::bindings::codegen::Bindings::HTMLElementBinding::HTMLElementMethods;
|
use dom::bindings::codegen::Bindings::HTMLElementBinding::HTMLElementMethods;
|
||||||
use dom::bindings::codegen::Bindings::HTMLInputElementBinding::HTMLInputElementMethods;
|
use dom::bindings::codegen::Bindings::HTMLInputElementBinding::HTMLInputElementMethods;
|
||||||
use dom::bindings::codegen::Bindings::WindowBinding::WindowMethods;
|
use dom::bindings::codegen::Bindings::WindowBinding::WindowMethods;
|
||||||
use dom::bindings::codegen::InheritTypes::{ElementCast, ElementTypeId};
|
use dom::bindings::codegen::InheritTypes::{ElementTypeId, HTMLElementTypeId, NodeTypeId};
|
||||||
use dom::bindings::codegen::InheritTypes::{EventTargetCast, HTMLBodyElementDerived};
|
use dom::bindings::conversions::Castable;
|
||||||
use dom::bindings::codegen::InheritTypes::{HTMLElementTypeId, HTMLFrameSetElementDerived};
|
|
||||||
use dom::bindings::codegen::InheritTypes::{HTMLHtmlElementDerived, HTMLInputElementCast};
|
|
||||||
use dom::bindings::codegen::InheritTypes::{NodeCast, NodeTypeId};
|
|
||||||
use dom::bindings::error::{Error, ErrorResult};
|
use dom::bindings::error::{Error, ErrorResult};
|
||||||
use dom::bindings::js::{JS, MutNullableHeap, Root};
|
use dom::bindings::js::{JS, MutNullableHeap, Root};
|
||||||
use dom::bindings::utils::Reflectable;
|
use dom::bindings::utils::Reflectable;
|
||||||
|
@ -21,6 +18,10 @@ use dom::cssstyledeclaration::{CSSModificationAccess, CSSStyleDeclaration};
|
||||||
use dom::document::Document;
|
use dom::document::Document;
|
||||||
use dom::domstringmap::DOMStringMap;
|
use dom::domstringmap::DOMStringMap;
|
||||||
use dom::element::{AttributeMutation, Element, EventState};
|
use dom::element::{AttributeMutation, Element, EventState};
|
||||||
|
use dom::eventtarget::EventTarget;
|
||||||
|
use dom::htmlbodyelement::HTMLBodyElement;
|
||||||
|
use dom::htmlframesetelement::HTMLFrameSetElement;
|
||||||
|
use dom::htmlhtmlelement::HTMLHtmlElement;
|
||||||
use dom::htmlinputelement::HTMLInputElement;
|
use dom::htmlinputelement::HTMLInputElement;
|
||||||
use dom::node::{Node, SEQUENTIALLY_FOCUSABLE};
|
use dom::node::{Node, SEQUENTIALLY_FOCUSABLE};
|
||||||
use dom::node::{document_from_node, window_from_node};
|
use dom::node::{document_from_node, window_from_node};
|
||||||
|
@ -70,13 +71,13 @@ impl HTMLElement {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn is_body_or_frameset(&self) -> bool {
|
fn is_body_or_frameset(&self) -> bool {
|
||||||
let eventtarget = EventTargetCast::from_ref(self);
|
let eventtarget = self.upcast::<EventTarget>();
|
||||||
eventtarget.is_htmlbodyelement() || eventtarget.is_htmlframesetelement()
|
eventtarget.is::<HTMLBodyElement>() || eventtarget.is::<HTMLFrameSetElement>()
|
||||||
}
|
}
|
||||||
|
|
||||||
fn update_sequentially_focusable_status(&self) {
|
fn update_sequentially_focusable_status(&self) {
|
||||||
let element = ElementCast::from_ref(self);
|
let element = self.upcast::<Element>();
|
||||||
let node = NodeCast::from_ref(self);
|
let node = self.upcast::<Node>();
|
||||||
if element.has_attribute(&atom!("tabindex")) {
|
if element.has_attribute(&atom!("tabindex")) {
|
||||||
node.set_flag(SEQUENTIALLY_FOCUSABLE, true);
|
node.set_flag(SEQUENTIALLY_FOCUSABLE, true);
|
||||||
} else {
|
} else {
|
||||||
|
@ -117,7 +118,7 @@ impl HTMLElementMethods for HTMLElement {
|
||||||
fn Style(&self) -> Root<CSSStyleDeclaration> {
|
fn Style(&self) -> Root<CSSStyleDeclaration> {
|
||||||
self.style_decl.or_init(|| {
|
self.style_decl.or_init(|| {
|
||||||
let global = window_from_node(self);
|
let global = window_from_node(self);
|
||||||
CSSStyleDeclaration::new(global.r(), ElementCast::from_ref(self), None, CSSModificationAccess::ReadWrite)
|
CSSStyleDeclaration::new(global.r(), self.upcast::<Element>(), None, CSSModificationAccess::ReadWrite)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -150,7 +151,7 @@ impl HTMLElementMethods for HTMLElement {
|
||||||
let win = window_from_node(self);
|
let win = window_from_node(self);
|
||||||
win.r().GetOnload()
|
win.r().GetOnload()
|
||||||
} else {
|
} else {
|
||||||
let target = EventTargetCast::from_ref(self);
|
let target = self.upcast::<EventTarget>();
|
||||||
target.get_event_handler_common("load")
|
target.get_event_handler_common("load")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -161,20 +162,20 @@ impl HTMLElementMethods for HTMLElement {
|
||||||
let win = window_from_node(self);
|
let win = window_from_node(self);
|
||||||
win.r().SetOnload(listener)
|
win.r().SetOnload(listener)
|
||||||
} else {
|
} else {
|
||||||
let target = EventTargetCast::from_ref(self);
|
let target = self.upcast::<EventTarget>();
|
||||||
target.set_event_handler_common("load", listener)
|
target.set_event_handler_common("load", listener)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// https://html.spec.whatwg.org/multipage/#dom-click
|
// https://html.spec.whatwg.org/multipage/#dom-click
|
||||||
fn Click(&self) {
|
fn Click(&self) {
|
||||||
let maybe_input: Option<&HTMLInputElement> = HTMLInputElementCast::to_ref(self);
|
let maybe_input: Option<&HTMLInputElement> = self.downcast::<HTMLInputElement>();
|
||||||
if let Some(i) = maybe_input {
|
if let Some(i) = maybe_input {
|
||||||
if i.Disabled() {
|
if i.Disabled() {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
let element = ElementCast::from_ref(self);
|
let element = self.upcast::<Element>();
|
||||||
// https://www.w3.org/Bugs/Public/show_bug.cgi?id=27430 ?
|
// https://www.w3.org/Bugs/Public/show_bug.cgi?id=27430 ?
|
||||||
element.as_maybe_activatable().map(|a| a.synthetic_click_activation(false, false, false, false));
|
element.as_maybe_activatable().map(|a| a.synthetic_click_activation(false, false, false, false));
|
||||||
}
|
}
|
||||||
|
@ -183,7 +184,7 @@ impl HTMLElementMethods for HTMLElement {
|
||||||
fn Focus(&self) {
|
fn Focus(&self) {
|
||||||
// TODO: Mark the element as locked for focus and run the focusing steps.
|
// TODO: Mark the element as locked for focus and run the focusing steps.
|
||||||
// https://html.spec.whatwg.org/multipage/#focusing-steps
|
// https://html.spec.whatwg.org/multipage/#focusing-steps
|
||||||
let element = ElementCast::from_ref(self);
|
let element = self.upcast::<Element>();
|
||||||
let document = document_from_node(self);
|
let document = document_from_node(self);
|
||||||
let document = document.r();
|
let document = document.r();
|
||||||
document.begin_focus_transaction();
|
document.begin_focus_transaction();
|
||||||
|
@ -194,7 +195,7 @@ impl HTMLElementMethods for HTMLElement {
|
||||||
// https://html.spec.whatwg.org/multipage/#dom-blur
|
// https://html.spec.whatwg.org/multipage/#dom-blur
|
||||||
fn Blur(&self) {
|
fn Blur(&self) {
|
||||||
// TODO: Run the unfocusing steps.
|
// TODO: Run the unfocusing steps.
|
||||||
let el = ElementCast::from_ref(self);
|
let el = self.upcast::<Element>();
|
||||||
if !el.get_focus_state() {
|
if !el.get_focus_state() {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -207,11 +208,11 @@ impl HTMLElementMethods for HTMLElement {
|
||||||
|
|
||||||
// https://drafts.csswg.org/cssom-view/#extensions-to-the-htmlelement-interface
|
// https://drafts.csswg.org/cssom-view/#extensions-to-the-htmlelement-interface
|
||||||
fn GetOffsetParent(&self) -> Option<Root<Element>> {
|
fn GetOffsetParent(&self) -> Option<Root<Element>> {
|
||||||
if self.is_htmlbodyelement() || self.is_htmlhtmlelement() {
|
if self.is::<HTMLBodyElement>() || self.is::<HTMLHtmlElement>() {
|
||||||
return None;
|
return None;
|
||||||
}
|
}
|
||||||
|
|
||||||
let node = NodeCast::from_ref(self);
|
let node = self.upcast::<Node>();
|
||||||
let window = window_from_node(self);
|
let window = window_from_node(self);
|
||||||
let (element, _) = window.offset_parent_query(node.to_trusted_node_address());
|
let (element, _) = window.offset_parent_query(node.to_trusted_node_address());
|
||||||
|
|
||||||
|
@ -220,11 +221,11 @@ impl HTMLElementMethods for HTMLElement {
|
||||||
|
|
||||||
// https://drafts.csswg.org/cssom-view/#extensions-to-the-htmlelement-interface
|
// https://drafts.csswg.org/cssom-view/#extensions-to-the-htmlelement-interface
|
||||||
fn OffsetTop(&self) -> i32 {
|
fn OffsetTop(&self) -> i32 {
|
||||||
if self.is_htmlbodyelement() {
|
if self.is::<HTMLBodyElement>() {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
let node = NodeCast::from_ref(self);
|
let node = self.upcast::<Node>();
|
||||||
let window = window_from_node(self);
|
let window = window_from_node(self);
|
||||||
let (_, rect) = window.offset_parent_query(node.to_trusted_node_address());
|
let (_, rect) = window.offset_parent_query(node.to_trusted_node_address());
|
||||||
|
|
||||||
|
@ -233,11 +234,11 @@ impl HTMLElementMethods for HTMLElement {
|
||||||
|
|
||||||
// https://drafts.csswg.org/cssom-view/#extensions-to-the-htmlelement-interface
|
// https://drafts.csswg.org/cssom-view/#extensions-to-the-htmlelement-interface
|
||||||
fn OffsetLeft(&self) -> i32 {
|
fn OffsetLeft(&self) -> i32 {
|
||||||
if self.is_htmlbodyelement() {
|
if self.is::<HTMLBodyElement>() {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
let node = NodeCast::from_ref(self);
|
let node = self.upcast::<Node>();
|
||||||
let window = window_from_node(self);
|
let window = window_from_node(self);
|
||||||
let (_, rect) = window.offset_parent_query(node.to_trusted_node_address());
|
let (_, rect) = window.offset_parent_query(node.to_trusted_node_address());
|
||||||
|
|
||||||
|
@ -246,7 +247,7 @@ impl HTMLElementMethods for HTMLElement {
|
||||||
|
|
||||||
// https://drafts.csswg.org/cssom-view/#extensions-to-the-htmlelement-interface
|
// https://drafts.csswg.org/cssom-view/#extensions-to-the-htmlelement-interface
|
||||||
fn OffsetWidth(&self) -> i32 {
|
fn OffsetWidth(&self) -> i32 {
|
||||||
let node = NodeCast::from_ref(self);
|
let node = self.upcast::<Node>();
|
||||||
let window = window_from_node(self);
|
let window = window_from_node(self);
|
||||||
let (_, rect) = window.offset_parent_query(node.to_trusted_node_address());
|
let (_, rect) = window.offset_parent_query(node.to_trusted_node_address());
|
||||||
|
|
||||||
|
@ -255,7 +256,7 @@ impl HTMLElementMethods for HTMLElement {
|
||||||
|
|
||||||
// https://drafts.csswg.org/cssom-view/#extensions-to-the-htmlelement-interface
|
// https://drafts.csswg.org/cssom-view/#extensions-to-the-htmlelement-interface
|
||||||
fn OffsetHeight(&self) -> i32 {
|
fn OffsetHeight(&self) -> i32 {
|
||||||
let node = NodeCast::from_ref(self);
|
let node = self.upcast::<Node>();
|
||||||
let window = window_from_node(self);
|
let window = window_from_node(self);
|
||||||
let (_, rect) = window.offset_parent_query(node.to_trusted_node_address());
|
let (_, rect) = window.offset_parent_query(node.to_trusted_node_address());
|
||||||
|
|
||||||
|
@ -285,12 +286,12 @@ impl HTMLElement {
|
||||||
.nth(1).map_or(false, |ch| ch >= 'a' && ch <= 'z') {
|
.nth(1).map_or(false, |ch| ch >= 'a' && ch <= 'z') {
|
||||||
return Err(Error::Syntax);
|
return Err(Error::Syntax);
|
||||||
}
|
}
|
||||||
let element = ElementCast::from_ref(self);
|
let element = self.upcast::<Element>();
|
||||||
element.set_custom_attribute(to_snake_case(name), value)
|
element.set_custom_attribute(to_snake_case(name), value)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn get_custom_attr(&self, local_name: DOMString) -> Option<DOMString> {
|
pub fn get_custom_attr(&self, local_name: DOMString) -> Option<DOMString> {
|
||||||
let element = ElementCast::from_ref(self);
|
let element = self.upcast::<Element>();
|
||||||
let local_name = Atom::from_slice(&to_snake_case(local_name));
|
let local_name = Atom::from_slice(&to_snake_case(local_name));
|
||||||
element.get_attribute(&ns!(""), &local_name).map(|attr| {
|
element.get_attribute(&ns!(""), &local_name).map(|attr| {
|
||||||
(**attr.r().value()).to_owned()
|
(**attr.r().value()).to_owned()
|
||||||
|
@ -298,7 +299,7 @@ impl HTMLElement {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn delete_custom_attr(&self, local_name: DOMString) {
|
pub fn delete_custom_attr(&self, local_name: DOMString) {
|
||||||
let element = ElementCast::from_ref(self);
|
let element = self.upcast::<Element>();
|
||||||
let local_name = Atom::from_slice(&to_snake_case(local_name));
|
let local_name = Atom::from_slice(&to_snake_case(local_name));
|
||||||
element.remove_attribute(&ns!(""), &local_name);
|
element.remove_attribute(&ns!(""), &local_name);
|
||||||
}
|
}
|
||||||
|
@ -306,7 +307,7 @@ impl HTMLElement {
|
||||||
|
|
||||||
impl VirtualMethods for HTMLElement {
|
impl VirtualMethods for HTMLElement {
|
||||||
fn super_type(&self) -> Option<&VirtualMethods> {
|
fn super_type(&self) -> Option<&VirtualMethods> {
|
||||||
let element: &Element = ElementCast::from_ref(self);
|
let element: &Element = self.upcast::<Element>();
|
||||||
Some(element as &VirtualMethods)
|
Some(element as &VirtualMethods)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -318,7 +319,7 @@ impl VirtualMethods for HTMLElement {
|
||||||
let (cx, url, reflector) = (window.r().get_cx(),
|
let (cx, url, reflector) = (window.r().get_cx(),
|
||||||
window.r().get_url(),
|
window.r().get_url(),
|
||||||
window.r().reflector().get_jsobject());
|
window.r().reflector().get_jsobject());
|
||||||
let evtarget = EventTargetCast::from_ref(self);
|
let evtarget = self.upcast::<EventTarget>();
|
||||||
evtarget.set_event_handler_uncompiled(cx, url, reflector,
|
evtarget.set_event_handler_uncompiled(cx, url, reflector,
|
||||||
&name[2..],
|
&name[2..],
|
||||||
(**attr.value()).to_owned());
|
(**attr.value()).to_owned());
|
||||||
|
|
|
@ -5,15 +5,15 @@
|
||||||
use dom::attr::Attr;
|
use dom::attr::Attr;
|
||||||
use dom::bindings::codegen::Bindings::HTMLFieldSetElementBinding;
|
use dom::bindings::codegen::Bindings::HTMLFieldSetElementBinding;
|
||||||
use dom::bindings::codegen::Bindings::HTMLFieldSetElementBinding::HTMLFieldSetElementMethods;
|
use dom::bindings::codegen::Bindings::HTMLFieldSetElementBinding::HTMLFieldSetElementMethods;
|
||||||
use dom::bindings::codegen::InheritTypes::{ElementCast, ElementTypeId, HTMLElementCast};
|
use dom::bindings::codegen::InheritTypes::{ElementTypeId, HTMLElementTypeId, NodeTypeId};
|
||||||
use dom::bindings::codegen::InheritTypes::{HTMLElementTypeId, HTMLLegendElementDerived};
|
use dom::bindings::conversions::Castable;
|
||||||
use dom::bindings::codegen::InheritTypes::{NodeCast, NodeTypeId};
|
|
||||||
use dom::bindings::js::{Root, RootedReference};
|
use dom::bindings::js::{Root, RootedReference};
|
||||||
use dom::document::Document;
|
use dom::document::Document;
|
||||||
use dom::element::{AttributeMutation, Element, IN_ENABLED_STATE};
|
use dom::element::{AttributeMutation, Element, IN_ENABLED_STATE};
|
||||||
use dom::htmlcollection::{CollectionFilter, HTMLCollection};
|
use dom::htmlcollection::{CollectionFilter, HTMLCollection};
|
||||||
use dom::htmlelement::HTMLElement;
|
use dom::htmlelement::HTMLElement;
|
||||||
use dom::htmlformelement::{FormControl, HTMLFormElement};
|
use dom::htmlformelement::{FormControl, HTMLFormElement};
|
||||||
|
use dom::htmllegendelement::HTMLLegendElement;
|
||||||
use dom::node::{Node, window_from_node};
|
use dom::node::{Node, window_from_node};
|
||||||
use dom::validitystate::ValidityState;
|
use dom::validitystate::ValidityState;
|
||||||
use dom::virtualmethods::VirtualMethods;
|
use dom::virtualmethods::VirtualMethods;
|
||||||
|
@ -56,7 +56,7 @@ impl HTMLFieldSetElementMethods for HTMLFieldSetElement {
|
||||||
TAG_NAMES.iter().any(|&tag_name| tag_name == &**elem.local_name())
|
TAG_NAMES.iter().any(|&tag_name| tag_name == &**elem.local_name())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
let node = NodeCast::from_ref(self);
|
let node = self.upcast::<Node>();
|
||||||
let filter = box ElementsFilter;
|
let filter = box ElementsFilter;
|
||||||
let window = window_from_node(node);
|
let window = window_from_node(node);
|
||||||
HTMLCollection::create(window.r(), node, filter)
|
HTMLCollection::create(window.r(), node, filter)
|
||||||
|
@ -82,7 +82,7 @@ impl HTMLFieldSetElementMethods for HTMLFieldSetElement {
|
||||||
|
|
||||||
impl VirtualMethods for HTMLFieldSetElement {
|
impl VirtualMethods for HTMLFieldSetElement {
|
||||||
fn super_type(&self) -> Option<&VirtualMethods> {
|
fn super_type(&self) -> Option<&VirtualMethods> {
|
||||||
let htmlelement: &HTMLElement = HTMLElementCast::from_ref(self);
|
let htmlelement: &HTMLElement = self.upcast::<HTMLElement>();
|
||||||
Some(htmlelement as &VirtualMethods)
|
Some(htmlelement as &VirtualMethods)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -98,15 +98,15 @@ impl VirtualMethods for HTMLFieldSetElement {
|
||||||
},
|
},
|
||||||
AttributeMutation::Removed => false,
|
AttributeMutation::Removed => false,
|
||||||
};
|
};
|
||||||
let node = NodeCast::from_ref(self);
|
let node = self.upcast::<Node>();
|
||||||
let el = ElementCast::from_ref(self);
|
let el = self.upcast::<Element>();
|
||||||
el.set_disabled_state(disabled_state);
|
el.set_disabled_state(disabled_state);
|
||||||
el.set_enabled_state(!disabled_state);
|
el.set_enabled_state(!disabled_state);
|
||||||
let mut found_legend = false;
|
let mut found_legend = false;
|
||||||
let children = node.children().filter(|node| {
|
let children = node.children().filter(|node| {
|
||||||
if found_legend {
|
if found_legend {
|
||||||
true
|
true
|
||||||
} else if node.is_htmllegendelement() {
|
} else if node.is::<HTMLLegendElement>() {
|
||||||
found_legend = true;
|
found_legend = true;
|
||||||
false
|
false
|
||||||
} else {
|
} else {
|
||||||
|
@ -136,13 +136,13 @@ impl VirtualMethods for HTMLFieldSetElement {
|
||||||
});
|
});
|
||||||
if disabled_state {
|
if disabled_state {
|
||||||
for field in fields {
|
for field in fields {
|
||||||
let el = ElementCast::to_ref(field.r()).unwrap();
|
let el = field.downcast::<Element>().unwrap();
|
||||||
el.set_disabled_state(true);
|
el.set_disabled_state(true);
|
||||||
el.set_enabled_state(false);
|
el.set_enabled_state(false);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
for field in fields {
|
for field in fields {
|
||||||
let el = ElementCast::to_ref(field.r()).unwrap();
|
let el = field.downcast::<Element>().unwrap();
|
||||||
el.check_disabled_attribute();
|
el.check_disabled_attribute();
|
||||||
el.check_ancestors_disabled_state_for_form_control();
|
el.check_ancestors_disabled_state_for_form_control();
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,10 +7,10 @@ use dom::attr::{Attr, AttrValue};
|
||||||
use dom::bindings::cell::DOMRefCell;
|
use dom::bindings::cell::DOMRefCell;
|
||||||
use dom::bindings::codegen::Bindings::HTMLFontElementBinding;
|
use dom::bindings::codegen::Bindings::HTMLFontElementBinding;
|
||||||
use dom::bindings::codegen::Bindings::HTMLFontElementBinding::HTMLFontElementMethods;
|
use dom::bindings::codegen::Bindings::HTMLFontElementBinding::HTMLFontElementMethods;
|
||||||
use dom::bindings::codegen::InheritTypes::{ElementCast, HTMLElementCast};
|
use dom::bindings::conversions::Castable;
|
||||||
use dom::bindings::js::Root;
|
use dom::bindings::js::Root;
|
||||||
use dom::document::Document;
|
use dom::document::Document;
|
||||||
use dom::element::{AttributeMutation, RawLayoutElementHelpers};
|
use dom::element::{AttributeMutation, Element, RawLayoutElementHelpers};
|
||||||
use dom::htmlelement::HTMLElement;
|
use dom::htmlelement::HTMLElement;
|
||||||
use dom::node::Node;
|
use dom::node::Node;
|
||||||
use dom::virtualmethods::VirtualMethods;
|
use dom::virtualmethods::VirtualMethods;
|
||||||
|
@ -63,7 +63,7 @@ impl HTMLFontElementMethods for HTMLFontElement {
|
||||||
|
|
||||||
// https://html.spec.whatwg.org/multipage/#dom-font-size
|
// https://html.spec.whatwg.org/multipage/#dom-font-size
|
||||||
fn SetSize(&self, value: DOMString) {
|
fn SetSize(&self, value: DOMString) {
|
||||||
let element = ElementCast::from_ref(self);
|
let element = self.upcast::<Element>();
|
||||||
let length = parse_length(&value);
|
let length = parse_length(&value);
|
||||||
element.set_attribute(&Atom::from_slice("size"), AttrValue::Length(value, length));
|
element.set_attribute(&Atom::from_slice("size"), AttrValue::Length(value, length));
|
||||||
}
|
}
|
||||||
|
@ -71,7 +71,7 @@ impl HTMLFontElementMethods for HTMLFontElement {
|
||||||
|
|
||||||
impl VirtualMethods for HTMLFontElement {
|
impl VirtualMethods for HTMLFontElement {
|
||||||
fn super_type(&self) -> Option<&VirtualMethods> {
|
fn super_type(&self) -> Option<&VirtualMethods> {
|
||||||
let htmlelement = HTMLElementCast::from_ref(self);
|
let htmlelement = self.upcast::<HTMLElement>();
|
||||||
Some(htmlelement as &VirtualMethods)
|
Some(htmlelement as &VirtualMethods)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -122,7 +122,7 @@ impl HTMLFontElement {
|
||||||
#[allow(unsafe_code)]
|
#[allow(unsafe_code)]
|
||||||
pub fn get_size(&self) -> Option<specified::Length> {
|
pub fn get_size(&self) -> Option<specified::Length> {
|
||||||
unsafe {
|
unsafe {
|
||||||
ElementCast::from_ref(self)
|
self.upcast::<Element>()
|
||||||
.get_attr_for_layout(&ns!(""), &atom!("size"))
|
.get_attr_for_layout(&ns!(""), &atom!("size"))
|
||||||
.and_then(AttrValue::as_length)
|
.and_then(AttrValue::as_length)
|
||||||
.cloned()
|
.cloned()
|
||||||
|
|
|
@ -9,21 +9,20 @@ use dom::bindings::codegen::Bindings::HTMLButtonElementBinding::HTMLButtonElemen
|
||||||
use dom::bindings::codegen::Bindings::HTMLFormElementBinding;
|
use dom::bindings::codegen::Bindings::HTMLFormElementBinding;
|
||||||
use dom::bindings::codegen::Bindings::HTMLFormElementBinding::HTMLFormElementMethods;
|
use dom::bindings::codegen::Bindings::HTMLFormElementBinding::HTMLFormElementMethods;
|
||||||
use dom::bindings::codegen::Bindings::HTMLInputElementBinding::HTMLInputElementMethods;
|
use dom::bindings::codegen::Bindings::HTMLInputElementBinding::HTMLInputElementMethods;
|
||||||
use dom::bindings::codegen::InheritTypes::{ElementBase, ElementCast};
|
use dom::bindings::codegen::InheritTypes::{ElementTypeId, HTMLElementTypeId, NodeTypeId};
|
||||||
use dom::bindings::codegen::InheritTypes::{ElementTypeId, EventTargetCast};
|
use dom::bindings::conversions::{Castable, DerivedFrom};
|
||||||
use dom::bindings::codegen::InheritTypes::{HTMLDataListElementCast, HTMLElementCast};
|
|
||||||
use dom::bindings::codegen::InheritTypes::{HTMLElementTypeId, HTMLFormElementCast};
|
|
||||||
use dom::bindings::codegen::InheritTypes::{HTMLInputElementCast, HTMLTextAreaElementCast};
|
|
||||||
use dom::bindings::codegen::InheritTypes::{NodeCast, NodeTypeId};
|
|
||||||
use dom::bindings::global::GlobalRef;
|
use dom::bindings::global::GlobalRef;
|
||||||
use dom::bindings::js::{Root};
|
use dom::bindings::js::{Root};
|
||||||
use dom::bindings::utils::Reflectable;
|
use dom::bindings::utils::Reflectable;
|
||||||
use dom::document::Document;
|
use dom::document::Document;
|
||||||
use dom::element::Element;
|
use dom::element::Element;
|
||||||
use dom::event::{Event, EventBubbles, EventCancelable};
|
use dom::event::{Event, EventBubbles, EventCancelable};
|
||||||
|
use dom::eventtarget::EventTarget;
|
||||||
use dom::htmlbuttonelement::{HTMLButtonElement};
|
use dom::htmlbuttonelement::{HTMLButtonElement};
|
||||||
|
use dom::htmldatalistelement::HTMLDataListElement;
|
||||||
use dom::htmlelement::HTMLElement;
|
use dom::htmlelement::HTMLElement;
|
||||||
use dom::htmlinputelement::HTMLInputElement;
|
use dom::htmlinputelement::HTMLInputElement;
|
||||||
|
use dom::htmltextareaelement::HTMLTextAreaElement;
|
||||||
use dom::node::{Node, document_from_node, window_from_node};
|
use dom::node::{Node, document_from_node, window_from_node};
|
||||||
use dom::virtualmethods::VirtualMethods;
|
use dom::virtualmethods::VirtualMethods;
|
||||||
use hyper::header::ContentType;
|
use hyper::header::ContentType;
|
||||||
|
@ -164,7 +163,7 @@ impl HTMLFormElement {
|
||||||
"submit".to_owned(),
|
"submit".to_owned(),
|
||||||
EventBubbles::Bubbles,
|
EventBubbles::Bubbles,
|
||||||
EventCancelable::Cancelable);
|
EventCancelable::Cancelable);
|
||||||
let target = EventTargetCast::from_ref(self);
|
let target = self.upcast::<EventTarget>();
|
||||||
event.r().fire(target);
|
event.r().fire(target);
|
||||||
if event.r().DefaultPrevented() {
|
if event.r().DefaultPrevented() {
|
||||||
return;
|
return;
|
||||||
|
@ -219,24 +218,24 @@ impl HTMLFormElement {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn get_unclean_dataset(&self, submitter: Option<FormSubmitter>) -> Vec<FormDatum> {
|
fn get_unclean_dataset(&self, submitter: Option<FormSubmitter>) -> Vec<FormDatum> {
|
||||||
let node = NodeCast::from_ref(self);
|
let node = self.upcast::<Node>();
|
||||||
// TODO: This is an incorrect way of getting controls owned
|
// TODO: This is an incorrect way of getting controls owned
|
||||||
// by the form, but good enough until html5ever lands
|
// by the form, but good enough until html5ever lands
|
||||||
node.traverse_preorder().filter_map(|child| {
|
node.traverse_preorder().filter_map(|child| {
|
||||||
match ElementCast::to_ref(child.r()) {
|
match child.downcast::<Element>() {
|
||||||
Some(el) if !el.get_disabled_state() => (),
|
Some(el) if !el.get_disabled_state() => (),
|
||||||
_ => return None,
|
_ => return None,
|
||||||
}
|
}
|
||||||
|
|
||||||
if child.r().ancestors()
|
if child.r().ancestors()
|
||||||
.any(|a| HTMLDataListElementCast::to_root(a).is_some()) {
|
.any(|a| Root::downcast::<HTMLDataListElement>(a).is_some()) {
|
||||||
return None;
|
return None;
|
||||||
}
|
}
|
||||||
match child.r().type_id() {
|
match child.r().type_id() {
|
||||||
NodeTypeId::Element(ElementTypeId::HTMLElement(element)) => {
|
NodeTypeId::Element(ElementTypeId::HTMLElement(element)) => {
|
||||||
match element {
|
match element {
|
||||||
HTMLElementTypeId::HTMLInputElement => {
|
HTMLElementTypeId::HTMLInputElement => {
|
||||||
let input = HTMLInputElementCast::to_ref(child.r()).unwrap();
|
let input = child.downcast::<HTMLInputElement>().unwrap();
|
||||||
input.get_form_datum(submitter)
|
input.get_form_datum(submitter)
|
||||||
}
|
}
|
||||||
HTMLElementTypeId::HTMLButtonElement |
|
HTMLElementTypeId::HTMLButtonElement |
|
||||||
|
@ -317,20 +316,20 @@ impl HTMLFormElement {
|
||||||
"reset".to_owned(),
|
"reset".to_owned(),
|
||||||
EventBubbles::Bubbles,
|
EventBubbles::Bubbles,
|
||||||
EventCancelable::Cancelable);
|
EventCancelable::Cancelable);
|
||||||
let target = EventTargetCast::from_ref(self);
|
let target = self.upcast::<EventTarget>();
|
||||||
event.r().fire(target);
|
event.r().fire(target);
|
||||||
if event.r().DefaultPrevented() {
|
if event.r().DefaultPrevented() {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
let node = NodeCast::from_ref(self);
|
let node = self.upcast::<Node>();
|
||||||
|
|
||||||
// TODO: This is an incorrect way of getting controls owned
|
// TODO: This is an incorrect way of getting controls owned
|
||||||
// by the form, but good enough until html5ever lands
|
// by the form, but good enough until html5ever lands
|
||||||
for child in node.traverse_preorder() {
|
for child in node.traverse_preorder() {
|
||||||
match child.r().type_id() {
|
match child.r().type_id() {
|
||||||
NodeTypeId::Element(ElementTypeId::HTMLElement(HTMLElementTypeId::HTMLInputElement)) => {
|
NodeTypeId::Element(ElementTypeId::HTMLElement(HTMLElementTypeId::HTMLInputElement)) => {
|
||||||
let input = HTMLInputElementCast::to_ref(child.r()).unwrap();
|
let input = child.downcast::<HTMLInputElement>().unwrap();
|
||||||
input.reset()
|
input.reset()
|
||||||
}
|
}
|
||||||
// TODO HTMLKeygenElement unimplemented
|
// TODO HTMLKeygenElement unimplemented
|
||||||
|
@ -343,7 +342,7 @@ impl HTMLFormElement {
|
||||||
{}
|
{}
|
||||||
}
|
}
|
||||||
NodeTypeId::Element(ElementTypeId::HTMLElement(HTMLElementTypeId::HTMLTextAreaElement)) => {
|
NodeTypeId::Element(ElementTypeId::HTMLElement(HTMLElementTypeId::HTMLTextAreaElement)) => {
|
||||||
let textarea = HTMLTextAreaElementCast::to_ref(child.r()).unwrap();
|
let textarea = child.downcast::<HTMLTextAreaElement>().unwrap();
|
||||||
textarea.reset()
|
textarea.reset()
|
||||||
}
|
}
|
||||||
NodeTypeId::Element(ElementTypeId::HTMLElement(HTMLElementTypeId::HTMLOutputElement)) => {
|
NodeTypeId::Element(ElementTypeId::HTMLElement(HTMLElementTypeId::HTMLOutputElement)) => {
|
||||||
|
@ -465,7 +464,7 @@ impl<'a> FormSubmitter<'a> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub trait FormControl: ElementBase + Reflectable {
|
pub trait FormControl: DerivedFrom<Element> + Reflectable {
|
||||||
// FIXME: This is wrong (https://github.com/servo/servo/issues/3553)
|
// FIXME: This is wrong (https://github.com/servo/servo/issues/3553)
|
||||||
// but we need html5ever to do it correctly
|
// but we need html5ever to do it correctly
|
||||||
fn form_owner(&self) -> Option<Root<HTMLFormElement>> {
|
fn form_owner(&self) -> Option<Root<HTMLFormElement>> {
|
||||||
|
@ -477,7 +476,7 @@ pub trait FormControl: ElementBase + Reflectable {
|
||||||
let owner = doc.r().GetElementById(owner);
|
let owner = doc.r().GetElementById(owner);
|
||||||
match owner {
|
match owner {
|
||||||
Some(ref o) => {
|
Some(ref o) => {
|
||||||
let maybe_form = HTMLFormElementCast::to_ref(o.r());
|
let maybe_form = o.downcast::<HTMLFormElement>();
|
||||||
if maybe_form.is_some() {
|
if maybe_form.is_some() {
|
||||||
return maybe_form.map(Root::from_ref);
|
return maybe_form.map(Root::from_ref);
|
||||||
}
|
}
|
||||||
|
@ -485,9 +484,9 @@ pub trait FormControl: ElementBase + Reflectable {
|
||||||
_ => ()
|
_ => ()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
let node = NodeCast::from_ref(elem);
|
let node = elem.upcast::<Node>();
|
||||||
for ancestor in node.ancestors() {
|
for ancestor in node.ancestors() {
|
||||||
if let Some(ancestor) = HTMLFormElementCast::to_ref(ancestor.r()) {
|
if let Some(ancestor) = ancestor.downcast::<HTMLFormElement>() {
|
||||||
return Some(Root::from_ref(ancestor))
|
return Some(Root::from_ref(ancestor))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -510,13 +509,13 @@ pub trait FormControl: ElementBase + Reflectable {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn to_element(&self) -> &Element {
|
fn to_element(&self) -> &Element {
|
||||||
ElementCast::from_ref(self)
|
self.upcast::<Element>()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl VirtualMethods for HTMLFormElement {
|
impl VirtualMethods for HTMLFormElement {
|
||||||
fn super_type(&self) -> Option<&VirtualMethods> {
|
fn super_type(&self) -> Option<&VirtualMethods> {
|
||||||
Some(HTMLElementCast::from_ref(self) as &VirtualMethods)
|
Some(self.upcast::<HTMLElement>() as &VirtualMethods)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn parse_plain_attribute(&self, name: &Atom, value: DOMString) -> AttrValue {
|
fn parse_plain_attribute(&self, name: &Atom, value: DOMString) -> AttrValue {
|
||||||
|
|
|
@ -3,7 +3,7 @@
|
||||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||||
|
|
||||||
use dom::bindings::codegen::Bindings::HTMLHeadElementBinding;
|
use dom::bindings::codegen::Bindings::HTMLHeadElementBinding;
|
||||||
use dom::bindings::codegen::InheritTypes::HTMLElementCast;
|
use dom::bindings::conversions::Castable;
|
||||||
use dom::bindings::js::Root;
|
use dom::bindings::js::Root;
|
||||||
use dom::document::Document;
|
use dom::document::Document;
|
||||||
use dom::htmlelement::HTMLElement;
|
use dom::htmlelement::HTMLElement;
|
||||||
|
@ -37,7 +37,7 @@ impl HTMLHeadElement {
|
||||||
|
|
||||||
impl VirtualMethods for HTMLHeadElement {
|
impl VirtualMethods for HTMLHeadElement {
|
||||||
fn super_type(&self) -> Option<&VirtualMethods> {
|
fn super_type(&self) -> Option<&VirtualMethods> {
|
||||||
let htmlelement: &HTMLElement = HTMLElementCast::from_ref(self);
|
let htmlelement: &HTMLElement = self.upcast::<HTMLElement>();
|
||||||
Some(htmlelement as &VirtualMethods)
|
Some(htmlelement as &VirtualMethods)
|
||||||
}
|
}
|
||||||
fn bind_to_tree(&self, _tree_in_doc: bool) {
|
fn bind_to_tree(&self, _tree_in_doc: bool) {
|
||||||
|
|
|
@ -6,16 +6,16 @@ use dom::attr::{Attr, AttrHelpersForLayout, AttrValue};
|
||||||
use dom::bindings::codegen::Bindings::HTMLIFrameElementBinding;
|
use dom::bindings::codegen::Bindings::HTMLIFrameElementBinding;
|
||||||
use dom::bindings::codegen::Bindings::HTMLIFrameElementBinding::HTMLIFrameElementMethods;
|
use dom::bindings::codegen::Bindings::HTMLIFrameElementBinding::HTMLIFrameElementMethods;
|
||||||
use dom::bindings::codegen::Bindings::WindowBinding::WindowMethods;
|
use dom::bindings::codegen::Bindings::WindowBinding::WindowMethods;
|
||||||
use dom::bindings::codegen::InheritTypes::{ElementCast, EventCast, EventTargetCast};
|
use dom::bindings::conversions::{Castable, ToJSValConvertible};
|
||||||
use dom::bindings::codegen::InheritTypes::{HTMLElementCast, NodeCast};
|
|
||||||
use dom::bindings::conversions::ToJSValConvertible;
|
|
||||||
use dom::bindings::error::{Error, ErrorResult, Fallible};
|
use dom::bindings::error::{Error, ErrorResult, Fallible};
|
||||||
use dom::bindings::global::GlobalRef;
|
use dom::bindings::global::GlobalRef;
|
||||||
use dom::bindings::js::{Root, LayoutJS};
|
use dom::bindings::js::{Root, LayoutJS};
|
||||||
use dom::bindings::utils::Reflectable;
|
use dom::bindings::utils::Reflectable;
|
||||||
use dom::customevent::CustomEvent;
|
use dom::customevent::CustomEvent;
|
||||||
use dom::document::Document;
|
use dom::document::Document;
|
||||||
use dom::element::{self, AttributeMutation};
|
use dom::element::{self, AttributeMutation, Element};
|
||||||
|
use dom::event::Event;
|
||||||
|
use dom::eventtarget::EventTarget;
|
||||||
use dom::htmlelement::HTMLElement;
|
use dom::htmlelement::HTMLElement;
|
||||||
use dom::node::{Node, window_from_node};
|
use dom::node::{Node, window_from_node};
|
||||||
use dom::urlhelper::UrlHelper;
|
use dom::urlhelper::UrlHelper;
|
||||||
|
@ -67,7 +67,7 @@ impl HTMLIFrameElement {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn get_url(&self) -> Option<Url> {
|
pub fn get_url(&self) -> Option<Url> {
|
||||||
let element = ElementCast::from_ref(self);
|
let element = self.upcast::<Element>();
|
||||||
element.get_attribute(&ns!(""), &atom!("src")).and_then(|src| {
|
element.get_attribute(&ns!(""), &atom!("src")).and_then(|src| {
|
||||||
let url = src.r().value();
|
let url = src.r().value();
|
||||||
if url.is_empty() {
|
if url.is_empty() {
|
||||||
|
@ -148,8 +148,8 @@ impl HTMLIFrameElement {
|
||||||
true,
|
true,
|
||||||
true,
|
true,
|
||||||
detail.handle());
|
detail.handle());
|
||||||
let target = EventTargetCast::from_ref(self);
|
let target = self.upcast::<EventTarget>();
|
||||||
let event = EventCast::from_ref(custom_event.r());
|
let event = custom_event.upcast::<Event>();
|
||||||
event.fire(target);
|
event.fire(target);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -161,7 +161,7 @@ impl HTMLIFrameElement {
|
||||||
#[allow(unsafe_code)]
|
#[allow(unsafe_code)]
|
||||||
pub fn get_width(&self) -> LengthOrPercentageOrAuto {
|
pub fn get_width(&self) -> LengthOrPercentageOrAuto {
|
||||||
unsafe {
|
unsafe {
|
||||||
element::get_attr_for_layout(ElementCast::from_ref(&*self),
|
element::get_attr_for_layout(self.upcast::<Element>(),
|
||||||
&ns!(""),
|
&ns!(""),
|
||||||
&atom!("width")).map(|attribute| {
|
&atom!("width")).map(|attribute| {
|
||||||
str::parse_length(&**attribute.value_for_layout())
|
str::parse_length(&**attribute.value_for_layout())
|
||||||
|
@ -172,7 +172,7 @@ impl HTMLIFrameElement {
|
||||||
#[allow(unsafe_code)]
|
#[allow(unsafe_code)]
|
||||||
pub fn get_height(&self) -> LengthOrPercentageOrAuto {
|
pub fn get_height(&self) -> LengthOrPercentageOrAuto {
|
||||||
unsafe {
|
unsafe {
|
||||||
element::get_attr_for_layout(ElementCast::from_ref(&*self),
|
element::get_attr_for_layout(self.upcast::<Element>(),
|
||||||
&ns!(""),
|
&ns!(""),
|
||||||
&atom!("height")).map(|attribute| {
|
&atom!("height")).map(|attribute| {
|
||||||
str::parse_length(&**attribute.value_for_layout())
|
str::parse_length(&**attribute.value_for_layout())
|
||||||
|
@ -227,7 +227,7 @@ impl HTMLIFrameElementLayoutMethods for LayoutJS<HTMLIFrameElement> {
|
||||||
|
|
||||||
pub fn Navigate(iframe: &HTMLIFrameElement, direction: NavigationDirection) -> Fallible<()> {
|
pub fn Navigate(iframe: &HTMLIFrameElement, direction: NavigationDirection) -> Fallible<()> {
|
||||||
if iframe.Mozbrowser() {
|
if iframe.Mozbrowser() {
|
||||||
let node = NodeCast::from_ref(iframe);
|
let node = iframe.upcast::<Node>();
|
||||||
if node.is_in_doc() {
|
if node.is_in_doc() {
|
||||||
let window = window_from_node(iframe);
|
let window = window_from_node(iframe);
|
||||||
let window = window.r();
|
let window = window.r();
|
||||||
|
@ -249,25 +249,25 @@ pub fn Navigate(iframe: &HTMLIFrameElement, direction: NavigationDirection) -> F
|
||||||
impl HTMLIFrameElementMethods for HTMLIFrameElement {
|
impl HTMLIFrameElementMethods for HTMLIFrameElement {
|
||||||
// https://html.spec.whatwg.org/multipage/#dom-iframe-src
|
// https://html.spec.whatwg.org/multipage/#dom-iframe-src
|
||||||
fn Src(&self) -> DOMString {
|
fn Src(&self) -> DOMString {
|
||||||
let element = ElementCast::from_ref(self);
|
let element = self.upcast::<Element>();
|
||||||
element.get_string_attribute(&atom!("src"))
|
element.get_string_attribute(&atom!("src"))
|
||||||
}
|
}
|
||||||
|
|
||||||
// https://html.spec.whatwg.org/multipage/#dom-iframe-src
|
// https://html.spec.whatwg.org/multipage/#dom-iframe-src
|
||||||
fn SetSrc(&self, src: DOMString) {
|
fn SetSrc(&self, src: DOMString) {
|
||||||
let element = ElementCast::from_ref(self);
|
let element = self.upcast::<Element>();
|
||||||
element.set_url_attribute(&atom!("src"), src)
|
element.set_url_attribute(&atom!("src"), src)
|
||||||
}
|
}
|
||||||
|
|
||||||
// https://html.spec.whatwg.org/multipage/#dom-iframe-sandbox
|
// https://html.spec.whatwg.org/multipage/#dom-iframe-sandbox
|
||||||
fn Sandbox(&self) -> DOMString {
|
fn Sandbox(&self) -> DOMString {
|
||||||
let element = ElementCast::from_ref(self);
|
let element = self.upcast::<Element>();
|
||||||
element.get_string_attribute(&atom!("sandbox"))
|
element.get_string_attribute(&atom!("sandbox"))
|
||||||
}
|
}
|
||||||
|
|
||||||
// https://html.spec.whatwg.org/multipage/#dom-iframe-sandbox
|
// https://html.spec.whatwg.org/multipage/#dom-iframe-sandbox
|
||||||
fn SetSandbox(&self, sandbox: DOMString) {
|
fn SetSandbox(&self, sandbox: DOMString) {
|
||||||
let element = ElementCast::from_ref(self);
|
let element = self.upcast::<Element>();
|
||||||
element.set_tokenlist_attribute(&atom!("sandbox"), sandbox);
|
element.set_tokenlist_attribute(&atom!("sandbox"), sandbox);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -311,7 +311,7 @@ impl HTMLIFrameElementMethods for HTMLIFrameElement {
|
||||||
// https://developer.mozilla.org/en-US/docs/Web/HTML/Element/iframe#attr-mozbrowser
|
// https://developer.mozilla.org/en-US/docs/Web/HTML/Element/iframe#attr-mozbrowser
|
||||||
fn Mozbrowser(&self) -> bool {
|
fn Mozbrowser(&self) -> bool {
|
||||||
if mozbrowser_enabled() {
|
if mozbrowser_enabled() {
|
||||||
let element = ElementCast::from_ref(self);
|
let element = self.upcast::<Element>();
|
||||||
element.has_attribute(&Atom::from_slice("mozbrowser"))
|
element.has_attribute(&Atom::from_slice("mozbrowser"))
|
||||||
} else {
|
} else {
|
||||||
false
|
false
|
||||||
|
@ -321,7 +321,7 @@ impl HTMLIFrameElementMethods for HTMLIFrameElement {
|
||||||
// https://developer.mozilla.org/en-US/docs/Web/HTML/Element/iframe#attr-mozbrowser
|
// https://developer.mozilla.org/en-US/docs/Web/HTML/Element/iframe#attr-mozbrowser
|
||||||
fn SetMozbrowser(&self, value: bool) -> ErrorResult {
|
fn SetMozbrowser(&self, value: bool) -> ErrorResult {
|
||||||
if mozbrowser_enabled() {
|
if mozbrowser_enabled() {
|
||||||
let element = ElementCast::from_ref(self);
|
let element = self.upcast::<Element>();
|
||||||
element.set_bool_attribute(&Atom::from_slice("mozbrowser"), value);
|
element.set_bool_attribute(&Atom::from_slice("mozbrowser"), value);
|
||||||
}
|
}
|
||||||
Ok(())
|
Ok(())
|
||||||
|
@ -360,7 +360,7 @@ impl HTMLIFrameElementMethods for HTMLIFrameElement {
|
||||||
|
|
||||||
impl VirtualMethods for HTMLIFrameElement {
|
impl VirtualMethods for HTMLIFrameElement {
|
||||||
fn super_type(&self) -> Option<&VirtualMethods> {
|
fn super_type(&self) -> Option<&VirtualMethods> {
|
||||||
let htmlelement: &HTMLElement = HTMLElementCast::from_ref(self);
|
let htmlelement: &HTMLElement = self.upcast::<HTMLElement>();
|
||||||
Some(htmlelement as &VirtualMethods)
|
Some(htmlelement as &VirtualMethods)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -386,7 +386,7 @@ impl VirtualMethods for HTMLIFrameElement {
|
||||||
},
|
},
|
||||||
&atom!(src) => {
|
&atom!(src) => {
|
||||||
if let AttributeMutation::Set(_) = mutation {
|
if let AttributeMutation::Set(_) = mutation {
|
||||||
if NodeCast::from_ref(self).is_in_doc() {
|
if self.upcast::<Node>().is_in_doc() {
|
||||||
self.process_the_iframe_attributes();
|
self.process_the_iframe_attributes();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,15 +8,15 @@ use dom::bindings::cell::DOMRefCell;
|
||||||
use dom::bindings::codegen::Bindings::HTMLImageElementBinding;
|
use dom::bindings::codegen::Bindings::HTMLImageElementBinding;
|
||||||
use dom::bindings::codegen::Bindings::HTMLImageElementBinding::HTMLImageElementMethods;
|
use dom::bindings::codegen::Bindings::HTMLImageElementBinding::HTMLImageElementMethods;
|
||||||
use dom::bindings::codegen::Bindings::WindowBinding::WindowMethods;
|
use dom::bindings::codegen::Bindings::WindowBinding::WindowMethods;
|
||||||
use dom::bindings::codegen::InheritTypes::{ElementCast, EventTargetCast};
|
use dom::bindings::conversions::Castable;
|
||||||
use dom::bindings::codegen::InheritTypes::{HTMLElementCast, NodeCast};
|
|
||||||
use dom::bindings::error::Fallible;
|
use dom::bindings::error::Fallible;
|
||||||
use dom::bindings::global::GlobalRef;
|
use dom::bindings::global::GlobalRef;
|
||||||
use dom::bindings::js::{LayoutJS, Root};
|
use dom::bindings::js::{LayoutJS, Root};
|
||||||
use dom::bindings::refcounted::Trusted;
|
use dom::bindings::refcounted::Trusted;
|
||||||
use dom::document::Document;
|
use dom::document::Document;
|
||||||
use dom::element::AttributeMutation;
|
use dom::element::{AttributeMutation, Element};
|
||||||
use dom::event::{Event, EventBubbles, EventCancelable};
|
use dom::event::{Event, EventBubbles, EventCancelable};
|
||||||
|
use dom::eventtarget::EventTarget;
|
||||||
use dom::htmlelement::HTMLElement;
|
use dom::htmlelement::HTMLElement;
|
||||||
use dom::node::{Node, NodeDamage, document_from_node, window_from_node};
|
use dom::node::{Node, NodeDamage, document_from_node, window_from_node};
|
||||||
use dom::virtualmethods::VirtualMethods;
|
use dom::virtualmethods::VirtualMethods;
|
||||||
|
@ -74,7 +74,7 @@ impl Runnable for ImageResponseHandlerRunnable {
|
||||||
};
|
};
|
||||||
|
|
||||||
// Mark the node dirty
|
// Mark the node dirty
|
||||||
let node = NodeCast::from_ref(element.r());
|
let node = element.upcast::<Node>();
|
||||||
let document = document_from_node(node);
|
let document = document_from_node(node);
|
||||||
document.r().content_changed(node, NodeDamage::OtherNodeDamage);
|
document.r().content_changed(node, NodeDamage::OtherNodeDamage);
|
||||||
|
|
||||||
|
@ -85,7 +85,7 @@ impl Runnable for ImageResponseHandlerRunnable {
|
||||||
EventBubbles::DoesNotBubble,
|
EventBubbles::DoesNotBubble,
|
||||||
EventCancelable::NotCancelable);
|
EventCancelable::NotCancelable);
|
||||||
let event = event.r();
|
let event = event.r();
|
||||||
let target = EventTargetCast::from_ref(node);
|
let target = node.upcast::<EventTarget>();
|
||||||
event.fire(target);
|
event.fire(target);
|
||||||
|
|
||||||
// Trigger reflow
|
// Trigger reflow
|
||||||
|
@ -97,7 +97,7 @@ impl HTMLImageElement {
|
||||||
/// Makes the local `image` member match the status of the `src` attribute and starts
|
/// Makes the local `image` member match the status of the `src` attribute and starts
|
||||||
/// prefetching the image. This method must be called after `src` is changed.
|
/// prefetching the image. This method must be called after `src` is changed.
|
||||||
fn update_image(&self, value: Option<(DOMString, Url)>) {
|
fn update_image(&self, value: Option<(DOMString, Url)>) {
|
||||||
let node = NodeCast::from_ref(self);
|
let node = self.upcast::<Node>();
|
||||||
let document = node.owner_doc();
|
let document = node.owner_doc();
|
||||||
let window = document.r().window();
|
let window = document.r().window();
|
||||||
let image_cache = window.image_cache_task();
|
let image_cache = window.image_cache_task();
|
||||||
|
@ -204,33 +204,33 @@ impl HTMLImageElementMethods for HTMLImageElement {
|
||||||
|
|
||||||
// https://html.spec.whatwg.org/multipage/#dom-img-ismap
|
// https://html.spec.whatwg.org/multipage/#dom-img-ismap
|
||||||
fn SetIsMap(&self, is_map: bool) {
|
fn SetIsMap(&self, is_map: bool) {
|
||||||
let element = ElementCast::from_ref(self);
|
let element = self.upcast::<Element>();
|
||||||
element.set_string_attribute(&atom!("ismap"), is_map.to_string())
|
element.set_string_attribute(&atom!("ismap"), is_map.to_string())
|
||||||
}
|
}
|
||||||
|
|
||||||
// https://html.spec.whatwg.org/multipage/#dom-img-width
|
// https://html.spec.whatwg.org/multipage/#dom-img-width
|
||||||
fn Width(&self) -> u32 {
|
fn Width(&self) -> u32 {
|
||||||
let node = NodeCast::from_ref(self);
|
let node = self.upcast::<Node>();
|
||||||
let rect = node.get_bounding_content_box();
|
let rect = node.get_bounding_content_box();
|
||||||
rect.size.width.to_px() as u32
|
rect.size.width.to_px() as u32
|
||||||
}
|
}
|
||||||
|
|
||||||
// https://html.spec.whatwg.org/multipage/#dom-img-width
|
// https://html.spec.whatwg.org/multipage/#dom-img-width
|
||||||
fn SetWidth(&self, width: u32) {
|
fn SetWidth(&self, width: u32) {
|
||||||
let elem = ElementCast::from_ref(self);
|
let elem = self.upcast::<Element>();
|
||||||
elem.set_uint_attribute(&atom!("width"), width)
|
elem.set_uint_attribute(&atom!("width"), width)
|
||||||
}
|
}
|
||||||
|
|
||||||
// https://html.spec.whatwg.org/multipage/#dom-img-height
|
// https://html.spec.whatwg.org/multipage/#dom-img-height
|
||||||
fn Height(&self) -> u32 {
|
fn Height(&self) -> u32 {
|
||||||
let node = NodeCast::from_ref(self);
|
let node = self.upcast::<Node>();
|
||||||
let rect = node.get_bounding_content_box();
|
let rect = node.get_bounding_content_box();
|
||||||
rect.size.height.to_px() as u32
|
rect.size.height.to_px() as u32
|
||||||
}
|
}
|
||||||
|
|
||||||
// https://html.spec.whatwg.org/multipage/#dom-img-height
|
// https://html.spec.whatwg.org/multipage/#dom-img-height
|
||||||
fn SetHeight(&self, height: u32) {
|
fn SetHeight(&self, height: u32) {
|
||||||
let elem = ElementCast::from_ref(self);
|
let elem = self.upcast::<Element>();
|
||||||
elem.set_uint_attribute(&atom!("height"), height)
|
elem.set_uint_attribute(&atom!("height"), height)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -299,7 +299,7 @@ impl HTMLImageElementMethods for HTMLImageElement {
|
||||||
|
|
||||||
impl VirtualMethods for HTMLImageElement {
|
impl VirtualMethods for HTMLImageElement {
|
||||||
fn super_type(&self) -> Option<&VirtualMethods> {
|
fn super_type(&self) -> Option<&VirtualMethods> {
|
||||||
let htmlelement: &HTMLElement = HTMLElementCast::from_ref(self);
|
let htmlelement: &HTMLElement = self.upcast::<HTMLElement>();
|
||||||
Some(htmlelement as &VirtualMethods)
|
Some(htmlelement as &VirtualMethods)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -11,9 +11,7 @@ use dom::bindings::codegen::Bindings::EventBinding::EventMethods;
|
||||||
use dom::bindings::codegen::Bindings::HTMLInputElementBinding;
|
use dom::bindings::codegen::Bindings::HTMLInputElementBinding;
|
||||||
use dom::bindings::codegen::Bindings::HTMLInputElementBinding::HTMLInputElementMethods;
|
use dom::bindings::codegen::Bindings::HTMLInputElementBinding::HTMLInputElementMethods;
|
||||||
use dom::bindings::codegen::Bindings::KeyboardEventBinding::KeyboardEventMethods;
|
use dom::bindings::codegen::Bindings::KeyboardEventBinding::KeyboardEventMethods;
|
||||||
use dom::bindings::codegen::InheritTypes::{ElementCast, EventTargetCast, HTMLElementCast};
|
use dom::bindings::conversions::Castable;
|
||||||
use dom::bindings::codegen::InheritTypes::{HTMLFieldSetElementDerived, HTMLInputElementCast};
|
|
||||||
use dom::bindings::codegen::InheritTypes::{KeyboardEventCast, NodeCast};
|
|
||||||
use dom::bindings::global::GlobalRef;
|
use dom::bindings::global::GlobalRef;
|
||||||
use dom::bindings::js::{JS, LayoutJS, Root, RootedReference};
|
use dom::bindings::js::{JS, LayoutJS, Root, RootedReference};
|
||||||
use dom::document::Document;
|
use dom::document::Document;
|
||||||
|
@ -21,6 +19,7 @@ use dom::element::{AttributeMutation, Element, IN_ENABLED_STATE, RawLayoutElemen
|
||||||
use dom::event::{Event, EventBubbles, EventCancelable};
|
use dom::event::{Event, EventBubbles, EventCancelable};
|
||||||
use dom::eventtarget::EventTarget;
|
use dom::eventtarget::EventTarget;
|
||||||
use dom::htmlelement::HTMLElement;
|
use dom::htmlelement::HTMLElement;
|
||||||
|
use dom::htmlfieldsetelement::HTMLFieldSetElement;
|
||||||
use dom::htmlformelement::{FormControl, FormDatum, FormSubmitter, HTMLFormElement};
|
use dom::htmlformelement::{FormControl, FormDatum, FormSubmitter, HTMLFormElement};
|
||||||
use dom::htmlformelement::{ResetFrom, SubmittedFrom};
|
use dom::htmlformelement::{ResetFrom, SubmittedFrom};
|
||||||
use dom::keyboardevent::KeyboardEvent;
|
use dom::keyboardevent::KeyboardEvent;
|
||||||
|
@ -165,7 +164,7 @@ impl LayoutHTMLInputElementHelpers for LayoutJS<HTMLInputElement> {
|
||||||
|
|
||||||
#[allow(unsafe_code)]
|
#[allow(unsafe_code)]
|
||||||
unsafe fn get_raw_attr_value(input: LayoutJS<HTMLInputElement>) -> Option<String> {
|
unsafe fn get_raw_attr_value(input: LayoutJS<HTMLInputElement>) -> Option<String> {
|
||||||
let elem = ElementCast::from_layout_js(&input);
|
let elem = input.upcast::<Element>();
|
||||||
(*elem.unsafe_get()).get_attr_val_for_layout(&ns!(""), &atom!("value"))
|
(*elem.unsafe_get()).get_attr_val_for_layout(&ns!(""), &atom!("value"))
|
||||||
.map(|s| s.to_owned())
|
.map(|s| s.to_owned())
|
||||||
}
|
}
|
||||||
|
@ -354,13 +353,13 @@ fn broadcast_radio_checked(broadcaster: &HTMLInputElement, group: Option<&Atom>)
|
||||||
//TODO: if not in document, use root ancestor instead of document
|
//TODO: if not in document, use root ancestor instead of document
|
||||||
let owner = broadcaster.form_owner();
|
let owner = broadcaster.form_owner();
|
||||||
let doc = document_from_node(broadcaster);
|
let doc = document_from_node(broadcaster);
|
||||||
let doc_node = NodeCast::from_ref(doc.r());
|
let doc_node = doc.upcast::<Node>();
|
||||||
|
|
||||||
// This function is a workaround for lifetime constraint difficulties.
|
// This function is a workaround for lifetime constraint difficulties.
|
||||||
fn do_broadcast(doc_node: &Node, broadcaster: &HTMLInputElement,
|
fn do_broadcast(doc_node: &Node, broadcaster: &HTMLInputElement,
|
||||||
owner: Option<&HTMLFormElement>, group: Option<&Atom>) {
|
owner: Option<&HTMLFormElement>, group: Option<&Atom>) {
|
||||||
let iter = doc_node.query_selector_iter("input[type=radio]".to_owned())
|
let iter = doc_node.query_selector_iter("input[type=radio]".to_owned()).unwrap()
|
||||||
.unwrap().filter_map(HTMLInputElementCast::to_root)
|
.filter_map(Root::downcast::<HTMLInputElement>)
|
||||||
.filter(|r| in_same_group(r.r(), owner, group) && broadcaster != r.r());
|
.filter(|r| in_same_group(r.r(), owner, group) && broadcaster != r.r());
|
||||||
for ref r in iter {
|
for ref r in iter {
|
||||||
if r.r().Checked() {
|
if r.r().Checked() {
|
||||||
|
@ -389,7 +388,7 @@ fn in_same_group(other: &HTMLInputElement, owner: Option<&HTMLFormElement>,
|
||||||
impl HTMLInputElement {
|
impl HTMLInputElement {
|
||||||
fn force_relayout(&self) {
|
fn force_relayout(&self) {
|
||||||
let doc = document_from_node(self);
|
let doc = document_from_node(self);
|
||||||
let node = NodeCast::from_ref(self);
|
let node = self.upcast::<Node>();
|
||||||
doc.r().content_changed(node, NodeDamage::OtherNodeDamage)
|
doc.r().content_changed(node, NodeDamage::OtherNodeDamage)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -440,7 +439,7 @@ impl HTMLInputElement {
|
||||||
// https://html.spec.whatwg.org/multipage/#radio-button-group
|
// https://html.spec.whatwg.org/multipage/#radio-button-group
|
||||||
fn get_radio_group_name(&self) -> Option<Atom> {
|
fn get_radio_group_name(&self) -> Option<Atom> {
|
||||||
//TODO: determine form owner
|
//TODO: determine form owner
|
||||||
let elem = ElementCast::from_ref(self);
|
let elem = self.upcast::<Element>();
|
||||||
elem.get_attribute(&ns!(""), &atom!("name"))
|
elem.get_attribute(&ns!(""), &atom!("name"))
|
||||||
.map(|name| name.value().as_atom().clone())
|
.map(|name| name.value().as_atom().clone())
|
||||||
}
|
}
|
||||||
|
@ -469,7 +468,7 @@ impl HTMLInputElement {
|
||||||
fn mutable(&self) -> bool {
|
fn mutable(&self) -> bool {
|
||||||
// https://html.spec.whatwg.org/multipage/#the-input-element:concept-fe-mutable
|
// https://html.spec.whatwg.org/multipage/#the-input-element:concept-fe-mutable
|
||||||
// https://html.spec.whatwg.org/multipage/#the-readonly-attribute:concept-fe-mutable
|
// https://html.spec.whatwg.org/multipage/#the-readonly-attribute:concept-fe-mutable
|
||||||
let el = ElementCast::from_ref(self);
|
let el = self.upcast::<Element>();
|
||||||
!(el.get_disabled_state() || self.ReadOnly())
|
!(el.get_disabled_state() || self.ReadOnly())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -492,7 +491,7 @@ impl HTMLInputElement {
|
||||||
|
|
||||||
impl VirtualMethods for HTMLInputElement {
|
impl VirtualMethods for HTMLInputElement {
|
||||||
fn super_type(&self) -> Option<&VirtualMethods> {
|
fn super_type(&self) -> Option<&VirtualMethods> {
|
||||||
let htmlelement: &HTMLElement = HTMLElementCast::from_ref(self);
|
let htmlelement: &HTMLElement = self.upcast::<HTMLElement>();
|
||||||
Some(htmlelement as &VirtualMethods)
|
Some(htmlelement as &VirtualMethods)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -508,7 +507,7 @@ impl VirtualMethods for HTMLInputElement {
|
||||||
},
|
},
|
||||||
AttributeMutation::Removed => false,
|
AttributeMutation::Removed => false,
|
||||||
};
|
};
|
||||||
let el = ElementCast::from_ref(self);
|
let el = self.upcast::<Element>();
|
||||||
el.set_disabled_state(disabled_state);
|
el.set_disabled_state(disabled_state);
|
||||||
el.set_enabled_state(!disabled_state);
|
el.set_enabled_state(!disabled_state);
|
||||||
el.check_ancestors_disabled_state_for_form_control();
|
el.check_ancestors_disabled_state_for_form_control();
|
||||||
|
@ -593,7 +592,7 @@ impl VirtualMethods for HTMLInputElement {
|
||||||
s.bind_to_tree(tree_in_doc);
|
s.bind_to_tree(tree_in_doc);
|
||||||
}
|
}
|
||||||
|
|
||||||
let el = ElementCast::from_ref(self);
|
let el = self.upcast::<Element>();
|
||||||
el.check_ancestors_disabled_state_for_form_control();
|
el.check_ancestors_disabled_state_for_form_control();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -602,9 +601,9 @@ impl VirtualMethods for HTMLInputElement {
|
||||||
s.unbind_from_tree(tree_in_doc);
|
s.unbind_from_tree(tree_in_doc);
|
||||||
}
|
}
|
||||||
|
|
||||||
let node = NodeCast::from_ref(self);
|
let node = self.upcast::<Node>();
|
||||||
let el = ElementCast::from_ref(self);
|
let el = self.upcast::<Element>();
|
||||||
if node.ancestors().any(|ancestor| ancestor.r().is_htmlfieldsetelement()) {
|
if node.ancestors().any(|ancestor| ancestor.is::<HTMLFieldSetElement>()) {
|
||||||
el.check_ancestors_disabled_state_for_form_control();
|
el.check_ancestors_disabled_state_for_form_control();
|
||||||
} else {
|
} else {
|
||||||
el.check_disabled_attribute();
|
el.check_disabled_attribute();
|
||||||
|
@ -628,11 +627,11 @@ impl VirtualMethods for HTMLInputElement {
|
||||||
//TODO: set the editing position for text inputs
|
//TODO: set the editing position for text inputs
|
||||||
|
|
||||||
let doc = document_from_node(self);
|
let doc = document_from_node(self);
|
||||||
doc.r().request_focus(ElementCast::from_ref(self));
|
doc.r().request_focus(self.upcast::<Element>());
|
||||||
} else if &*event.Type() == "keydown" && !event.DefaultPrevented() &&
|
} else if &*event.Type() == "keydown" && !event.DefaultPrevented() &&
|
||||||
(self.input_type.get() == InputType::InputText ||
|
(self.input_type.get() == InputType::InputText ||
|
||||||
self.input_type.get() == InputType::InputPassword) {
|
self.input_type.get() == InputType::InputPassword) {
|
||||||
let keyevent: Option<&KeyboardEvent> = KeyboardEventCast::to_ref(event);
|
let keyevent: Option<&KeyboardEvent> = event.downcast::<KeyboardEvent>();
|
||||||
keyevent.map(|keyevent| {
|
keyevent.map(|keyevent| {
|
||||||
// This can't be inlined, as holding on to textinput.borrow_mut()
|
// This can't be inlined, as holding on to textinput.borrow_mut()
|
||||||
// during self.implicit_submission will cause a panic.
|
// during self.implicit_submission will cause a panic.
|
||||||
|
@ -663,7 +662,7 @@ impl FormControl for HTMLInputElement {}
|
||||||
|
|
||||||
impl Activatable for HTMLInputElement {
|
impl Activatable for HTMLInputElement {
|
||||||
fn as_element(&self) -> &Element {
|
fn as_element(&self) -> &Element {
|
||||||
ElementCast::from_ref(self)
|
self.upcast::<Element>()
|
||||||
}
|
}
|
||||||
|
|
||||||
fn is_instance_activatable(&self) -> bool {
|
fn is_instance_activatable(&self) -> bool {
|
||||||
|
@ -708,11 +707,12 @@ impl Activatable for HTMLInputElement {
|
||||||
//TODO: if not in document, use root ancestor instead of document
|
//TODO: if not in document, use root ancestor instead of document
|
||||||
let owner = self.form_owner();
|
let owner = self.form_owner();
|
||||||
let doc = document_from_node(self);
|
let doc = document_from_node(self);
|
||||||
let doc_node = NodeCast::from_ref(doc.r());
|
let doc_node = doc.upcast::<Node>();
|
||||||
let group = self.get_radio_group_name();;
|
let group = self.get_radio_group_name();;
|
||||||
|
|
||||||
|
// Safe since we only manipulate the DOM tree after finding an element
|
||||||
let checked_member = doc_node.query_selector_iter("input[type=radio]".to_owned()).unwrap()
|
let checked_member = doc_node.query_selector_iter("input[type=radio]".to_owned()).unwrap()
|
||||||
.filter_map(HTMLInputElementCast::to_root)
|
.filter_map(Root::downcast::<HTMLInputElement>)
|
||||||
.find(|r| {
|
.find(|r| {
|
||||||
in_same_group(r.r(), owner.r(), group.as_ref()) &&
|
in_same_group(r.r(), owner.r(), group.as_ref()) &&
|
||||||
r.r().Checked()
|
r.r().Checked()
|
||||||
|
@ -813,14 +813,14 @@ impl Activatable for HTMLInputElement {
|
||||||
"input".to_owned(),
|
"input".to_owned(),
|
||||||
EventBubbles::Bubbles,
|
EventBubbles::Bubbles,
|
||||||
EventCancelable::NotCancelable);
|
EventCancelable::NotCancelable);
|
||||||
let target = EventTargetCast::from_ref(self);
|
let target = self.upcast::<EventTarget>();
|
||||||
event.r().fire(target);
|
event.r().fire(target);
|
||||||
|
|
||||||
let event = Event::new(GlobalRef::Window(win.r()),
|
let event = Event::new(GlobalRef::Window(win.r()),
|
||||||
"change".to_owned(),
|
"change".to_owned(),
|
||||||
EventBubbles::Bubbles,
|
EventBubbles::Bubbles,
|
||||||
EventCancelable::NotCancelable);
|
EventCancelable::NotCancelable);
|
||||||
let target = EventTargetCast::from_ref(self);
|
let target = self.upcast::<EventTarget>();
|
||||||
event.r().fire(target);
|
event.r().fire(target);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
@ -832,20 +832,20 @@ impl Activatable for HTMLInputElement {
|
||||||
#[allow(unsafe_code)]
|
#[allow(unsafe_code)]
|
||||||
fn implicit_submission(&self, ctrlKey: bool, shiftKey: bool, altKey: bool, metaKey: bool) {
|
fn implicit_submission(&self, ctrlKey: bool, shiftKey: bool, altKey: bool, metaKey: bool) {
|
||||||
let doc = document_from_node(self);
|
let doc = document_from_node(self);
|
||||||
let node = NodeCast::from_ref(doc.r());
|
let node = doc.upcast::<Node>();
|
||||||
let owner = self.form_owner();
|
let owner = self.form_owner();
|
||||||
let form = match owner {
|
let form = match owner {
|
||||||
None => return,
|
None => return,
|
||||||
Some(ref f) => f
|
Some(ref f) => f
|
||||||
};
|
};
|
||||||
|
|
||||||
let elem = ElementCast::from_ref(self);
|
let elem = self.upcast::<Element>();
|
||||||
if elem.click_in_progress() {
|
if elem.click_in_progress() {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
let submit_button;
|
let submit_button;
|
||||||
submit_button = node.query_selector_iter("input[type=submit]".to_owned()).unwrap()
|
submit_button = node.query_selector_iter("input[type=submit]".to_owned()).unwrap()
|
||||||
.filter_map(HTMLInputElementCast::to_root)
|
.filter_map(Root::downcast::<HTMLInputElement>)
|
||||||
.find(|r| r.r().form_owner() == owner);
|
.find(|r| r.r().form_owner() == owner);
|
||||||
match submit_button {
|
match submit_button {
|
||||||
Some(ref button) => {
|
Some(ref button) => {
|
||||||
|
@ -855,7 +855,7 @@ impl Activatable for HTMLInputElement {
|
||||||
}
|
}
|
||||||
None => {
|
None => {
|
||||||
let inputs = node.query_selector_iter("input".to_owned()).unwrap()
|
let inputs = node.query_selector_iter("input".to_owned()).unwrap()
|
||||||
.filter_map(HTMLInputElementCast::to_root)
|
.filter_map(Root::downcast::<HTMLInputElement>)
|
||||||
.filter(|input| {
|
.filter(|input| {
|
||||||
input.r().form_owner() == owner && match &*input.r().Type() {
|
input.r().form_owner() == owner && match &*input.r().Type() {
|
||||||
"text" | "search" | "url" | "tel" |
|
"text" | "search" | "url" | "tel" |
|
||||||
|
|
|
@ -8,8 +8,7 @@ use dom::attr::{Attr, AttrValue};
|
||||||
use dom::bindings::codegen::Bindings::HTMLLinkElementBinding;
|
use dom::bindings::codegen::Bindings::HTMLLinkElementBinding;
|
||||||
use dom::bindings::codegen::Bindings::HTMLLinkElementBinding::HTMLLinkElementMethods;
|
use dom::bindings::codegen::Bindings::HTMLLinkElementBinding::HTMLLinkElementMethods;
|
||||||
use dom::bindings::codegen::Bindings::WindowBinding::WindowMethods;
|
use dom::bindings::codegen::Bindings::WindowBinding::WindowMethods;
|
||||||
use dom::bindings::codegen::InheritTypes::{ElementCast, EventTargetCast};
|
use dom::bindings::conversions::Castable;
|
||||||
use dom::bindings::codegen::InheritTypes::{HTMLElementCast, NodeCast};
|
|
||||||
use dom::bindings::global::GlobalRef;
|
use dom::bindings::global::GlobalRef;
|
||||||
use dom::bindings::js::{JS, MutNullableHeap, Root};
|
use dom::bindings::js::{JS, MutNullableHeap, Root};
|
||||||
use dom::bindings::js::{RootedReference};
|
use dom::bindings::js::{RootedReference};
|
||||||
|
@ -18,6 +17,7 @@ use dom::document::Document;
|
||||||
use dom::domtokenlist::DOMTokenList;
|
use dom::domtokenlist::DOMTokenList;
|
||||||
use dom::element::{AttributeMutation, Element};
|
use dom::element::{AttributeMutation, Element};
|
||||||
use dom::event::{Event, EventBubbles, EventCancelable};
|
use dom::event::{Event, EventBubbles, EventCancelable};
|
||||||
|
use dom::eventtarget::EventTarget;
|
||||||
use dom::htmlelement::HTMLElement;
|
use dom::htmlelement::HTMLElement;
|
||||||
use dom::node::{Node, window_from_node};
|
use dom::node::{Node, window_from_node};
|
||||||
use dom::virtualmethods::VirtualMethods;
|
use dom::virtualmethods::VirtualMethods;
|
||||||
|
@ -89,16 +89,16 @@ fn is_favicon(value: &Option<String>) -> bool {
|
||||||
|
|
||||||
impl VirtualMethods for HTMLLinkElement {
|
impl VirtualMethods for HTMLLinkElement {
|
||||||
fn super_type(&self) -> Option<&VirtualMethods> {
|
fn super_type(&self) -> Option<&VirtualMethods> {
|
||||||
let htmlelement: &HTMLElement = HTMLElementCast::from_ref(self);
|
let htmlelement: &HTMLElement = self.upcast::<HTMLElement>();
|
||||||
Some(htmlelement as &VirtualMethods)
|
Some(htmlelement as &VirtualMethods)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn attribute_mutated(&self, attr: &Attr, mutation: AttributeMutation) {
|
fn attribute_mutated(&self, attr: &Attr, mutation: AttributeMutation) {
|
||||||
self.super_type().unwrap().attribute_mutated(attr, mutation);
|
self.super_type().unwrap().attribute_mutated(attr, mutation);
|
||||||
if !NodeCast::from_ref(self).is_in_doc() || mutation == AttributeMutation::Removed {
|
if !self.upcast::<Node>().is_in_doc() || mutation == AttributeMutation::Removed {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
let rel = get_attr(ElementCast::from_ref(self), &atom!(rel));
|
let rel = get_attr(self.upcast::<Element>(), &atom!(rel));
|
||||||
match attr.local_name() {
|
match attr.local_name() {
|
||||||
&atom!(href) => {
|
&atom!(href) => {
|
||||||
if is_stylesheet(&rel) {
|
if is_stylesheet(&rel) {
|
||||||
|
@ -129,7 +129,7 @@ impl VirtualMethods for HTMLLinkElement {
|
||||||
}
|
}
|
||||||
|
|
||||||
if tree_in_doc {
|
if tree_in_doc {
|
||||||
let element = ElementCast::from_ref(self);
|
let element = self.upcast::<Element>();
|
||||||
|
|
||||||
let rel = get_attr(element, &atom!("rel"));
|
let rel = get_attr(element, &atom!("rel"));
|
||||||
let href = get_attr(element, &atom!("href"));
|
let href = get_attr(element, &atom!("href"));
|
||||||
|
@ -154,7 +154,7 @@ impl HTMLLinkElement {
|
||||||
let window = window.r();
|
let window = window.r();
|
||||||
match UrlParser::new().base_url(&window.get_url()).parse(href) {
|
match UrlParser::new().base_url(&window.get_url()).parse(href) {
|
||||||
Ok(url) => {
|
Ok(url) => {
|
||||||
let element = ElementCast::from_ref(self);
|
let element = self.upcast::<Element>();
|
||||||
|
|
||||||
let mq_attribute = element.get_attribute(&ns!(""), &atom!("media"));
|
let mq_attribute = element.get_attribute(&ns!(""), &atom!("media"));
|
||||||
let value = mq_attribute.r().map(|a| a.value());
|
let value = mq_attribute.r().map(|a| a.value());
|
||||||
|
@ -225,7 +225,7 @@ impl HTMLLinkElementMethods for HTMLLinkElement {
|
||||||
// https://html.spec.whatwg.org/multipage/#dom-link-rellist
|
// https://html.spec.whatwg.org/multipage/#dom-link-rellist
|
||||||
fn RelList(&self) -> Root<DOMTokenList> {
|
fn RelList(&self) -> Root<DOMTokenList> {
|
||||||
self.rel_list.or_init(|| {
|
self.rel_list.or_init(|| {
|
||||||
DOMTokenList::new(ElementCast::from_ref(self), &atom!("rel"))
|
DOMTokenList::new(self.upcast::<Element>(), &atom!("rel"))
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -267,7 +267,7 @@ impl StylesheetLoadResponder for StylesheetLoadDispatcher {
|
||||||
let event = Event::new(GlobalRef::Window(window.r()), "load".to_owned(),
|
let event = Event::new(GlobalRef::Window(window.r()), "load".to_owned(),
|
||||||
EventBubbles::DoesNotBubble,
|
EventBubbles::DoesNotBubble,
|
||||||
EventCancelable::NotCancelable);
|
EventCancelable::NotCancelable);
|
||||||
let target = EventTargetCast::from_ref(elem.r());
|
let target = elem.upcast::<EventTarget>();
|
||||||
event.r().fire(target);
|
event.r().fire(target);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,9 +4,10 @@
|
||||||
|
|
||||||
use dom::bindings::codegen::Bindings::HTMLMetaElementBinding;
|
use dom::bindings::codegen::Bindings::HTMLMetaElementBinding;
|
||||||
use dom::bindings::codegen::Bindings::HTMLMetaElementBinding::HTMLMetaElementMethods;
|
use dom::bindings::codegen::Bindings::HTMLMetaElementBinding::HTMLMetaElementMethods;
|
||||||
use dom::bindings::codegen::InheritTypes::{ElementCast, HTMLElementCast, NodeCast};
|
use dom::bindings::conversions::Castable;
|
||||||
use dom::bindings::js::{Root, RootedReference};
|
use dom::bindings::js::{Root, RootedReference};
|
||||||
use dom::document::Document;
|
use dom::document::Document;
|
||||||
|
use dom::element::Element;
|
||||||
use dom::htmlelement::HTMLElement;
|
use dom::htmlelement::HTMLElement;
|
||||||
use dom::node::{Node, window_from_node};
|
use dom::node::{Node, window_from_node};
|
||||||
use dom::virtualmethods::VirtualMethods;
|
use dom::virtualmethods::VirtualMethods;
|
||||||
|
@ -38,7 +39,7 @@ impl HTMLMetaElement {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn process_attributes(&self) {
|
fn process_attributes(&self) {
|
||||||
let element = ElementCast::from_ref(self);
|
let element = self.upcast::<Element>();
|
||||||
if let Some(name) = element.get_attribute(&ns!(""), &atom!("name")).r() {
|
if let Some(name) = element.get_attribute(&ns!(""), &atom!("name")).r() {
|
||||||
let name = name.value().to_ascii_lowercase();
|
let name = name.value().to_ascii_lowercase();
|
||||||
let name = name.trim_matches(HTML_SPACE_CHARACTERS);
|
let name = name.trim_matches(HTML_SPACE_CHARACTERS);
|
||||||
|
@ -51,12 +52,12 @@ impl HTMLMetaElement {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn translate_viewport(&self) {
|
fn translate_viewport(&self) {
|
||||||
let element = ElementCast::from_ref(self);
|
let element = self.upcast::<Element>();
|
||||||
if let Some(content) = element.get_attribute(&ns!(""), &atom!("content")).r() {
|
if let Some(content) = element.get_attribute(&ns!(""), &atom!("content")).r() {
|
||||||
let content = content.value();
|
let content = content.value();
|
||||||
if !content.is_empty() {
|
if !content.is_empty() {
|
||||||
if let Some(translated_rule) = ViewportRule::from_meta(&**content) {
|
if let Some(translated_rule) = ViewportRule::from_meta(&**content) {
|
||||||
let node = NodeCast::from_ref(self);
|
let node = self.upcast::<Node>();
|
||||||
let win = window_from_node(node);
|
let win = window_from_node(node);
|
||||||
let LayoutChan(ref layout_chan) = win.r().layout_chan();
|
let LayoutChan(ref layout_chan) = win.r().layout_chan();
|
||||||
|
|
||||||
|
@ -83,7 +84,7 @@ impl HTMLMetaElementMethods for HTMLMetaElement {
|
||||||
|
|
||||||
impl VirtualMethods for HTMLMetaElement {
|
impl VirtualMethods for HTMLMetaElement {
|
||||||
fn super_type(&self) -> Option<&VirtualMethods> {
|
fn super_type(&self) -> Option<&VirtualMethods> {
|
||||||
let htmlelement: &HTMLElement = HTMLElementCast::from_ref(self);
|
let htmlelement: &HTMLElement = self.upcast::<HTMLElement>();
|
||||||
Some(htmlelement as &VirtualMethods)
|
Some(htmlelement as &VirtualMethods)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -6,10 +6,10 @@ use dom::attr::Attr;
|
||||||
use dom::bindings::cell::DOMRefCell;
|
use dom::bindings::cell::DOMRefCell;
|
||||||
use dom::bindings::codegen::Bindings::HTMLObjectElementBinding;
|
use dom::bindings::codegen::Bindings::HTMLObjectElementBinding;
|
||||||
use dom::bindings::codegen::Bindings::HTMLObjectElementBinding::HTMLObjectElementMethods;
|
use dom::bindings::codegen::Bindings::HTMLObjectElementBinding::HTMLObjectElementMethods;
|
||||||
use dom::bindings::codegen::InheritTypes::{ElementCast, HTMLElementCast};
|
use dom::bindings::conversions::Castable;
|
||||||
use dom::bindings::js::Root;
|
use dom::bindings::js::Root;
|
||||||
use dom::document::Document;
|
use dom::document::Document;
|
||||||
use dom::element::AttributeMutation;
|
use dom::element::{AttributeMutation, Element};
|
||||||
use dom::htmlelement::HTMLElement;
|
use dom::htmlelement::HTMLElement;
|
||||||
use dom::htmlformelement::{FormControl, HTMLFormElement};
|
use dom::htmlformelement::{FormControl, HTMLFormElement};
|
||||||
use dom::node::{Node, window_from_node};
|
use dom::node::{Node, window_from_node};
|
||||||
|
@ -53,7 +53,7 @@ impl<'a> ProcessDataURL for &'a HTMLObjectElement {
|
||||||
// Makes the local `data` member match the status of the `data` attribute and starts
|
// Makes the local `data` member match the status of the `data` attribute and starts
|
||||||
/// prefetching the image. This method must be called after `data` is changed.
|
/// prefetching the image. This method must be called after `data` is changed.
|
||||||
fn process_data_url(&self) {
|
fn process_data_url(&self) {
|
||||||
let elem = ElementCast::from_ref(*self);
|
let elem = self.upcast::<Element>();
|
||||||
|
|
||||||
// TODO: support other values
|
// TODO: support other values
|
||||||
match (elem.get_attribute(&ns!(""), &atom!("type")),
|
match (elem.get_attribute(&ns!(""), &atom!("type")),
|
||||||
|
@ -92,7 +92,7 @@ impl HTMLObjectElementMethods for HTMLObjectElement {
|
||||||
|
|
||||||
impl VirtualMethods for HTMLObjectElement {
|
impl VirtualMethods for HTMLObjectElement {
|
||||||
fn super_type(&self) -> Option<&VirtualMethods> {
|
fn super_type(&self) -> Option<&VirtualMethods> {
|
||||||
let htmlelement: &HTMLElement = HTMLElementCast::from_ref(self);
|
let htmlelement: &HTMLElement = self.upcast::<HTMLElement>();
|
||||||
Some(htmlelement as &VirtualMethods)
|
Some(htmlelement as &VirtualMethods)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -5,13 +5,13 @@
|
||||||
use dom::attr::Attr;
|
use dom::attr::Attr;
|
||||||
use dom::bindings::codegen::Bindings::HTMLOptGroupElementBinding;
|
use dom::bindings::codegen::Bindings::HTMLOptGroupElementBinding;
|
||||||
use dom::bindings::codegen::Bindings::HTMLOptGroupElementBinding::HTMLOptGroupElementMethods;
|
use dom::bindings::codegen::Bindings::HTMLOptGroupElementBinding::HTMLOptGroupElementMethods;
|
||||||
use dom::bindings::codegen::InheritTypes::{ElementCast, HTMLElementCast, HTMLOptionElementCast};
|
use dom::bindings::conversions::Castable;
|
||||||
use dom::bindings::codegen::InheritTypes::{HTMLOptionElementDerived, NodeCast};
|
|
||||||
use dom::bindings::js::Root;
|
use dom::bindings::js::Root;
|
||||||
use dom::document::Document;
|
use dom::document::Document;
|
||||||
use dom::element::{AttributeMutation, IN_ENABLED_STATE};
|
use dom::element::{AttributeMutation, Element, IN_ENABLED_STATE};
|
||||||
use dom::htmlelement::HTMLElement;
|
use dom::htmlelement::HTMLElement;
|
||||||
use dom::node::{Node};
|
use dom::htmloptionelement::HTMLOptionElement;
|
||||||
|
use dom::node::Node;
|
||||||
use dom::virtualmethods::VirtualMethods;
|
use dom::virtualmethods::VirtualMethods;
|
||||||
use util::str::DOMString;
|
use util::str::DOMString;
|
||||||
|
|
||||||
|
@ -50,7 +50,7 @@ impl HTMLOptGroupElementMethods for HTMLOptGroupElement {
|
||||||
|
|
||||||
impl VirtualMethods for HTMLOptGroupElement {
|
impl VirtualMethods for HTMLOptGroupElement {
|
||||||
fn super_type(&self) -> Option<&VirtualMethods> {
|
fn super_type(&self) -> Option<&VirtualMethods> {
|
||||||
let htmlelement: &HTMLElement = HTMLElementCast::from_ref(self);
|
let htmlelement: &HTMLElement = self.upcast::<HTMLElement>();
|
||||||
Some(htmlelement as &VirtualMethods)
|
Some(htmlelement as &VirtualMethods)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -66,22 +66,21 @@ impl VirtualMethods for HTMLOptGroupElement {
|
||||||
},
|
},
|
||||||
AttributeMutation::Removed => false,
|
AttributeMutation::Removed => false,
|
||||||
};
|
};
|
||||||
let node = NodeCast::from_ref(self);
|
let el = self.upcast::<Element>();
|
||||||
let el = ElementCast::from_ref(self);
|
|
||||||
el.set_disabled_state(disabled_state);
|
el.set_disabled_state(disabled_state);
|
||||||
el.set_enabled_state(!disabled_state);
|
el.set_enabled_state(!disabled_state);
|
||||||
let options = node.children().filter(|child| {
|
let options = el.upcast::<Node>().children().filter(|child| {
|
||||||
child.is_htmloptionelement()
|
child.is::<HTMLOptionElement>()
|
||||||
}).map(|child| Root::from_ref(HTMLOptionElementCast::to_ref(child.r()).unwrap()));
|
}).map(|child| Root::from_ref(child.downcast::<HTMLOptionElement>().unwrap()));
|
||||||
if disabled_state {
|
if disabled_state {
|
||||||
for option in options {
|
for option in options {
|
||||||
let el = ElementCast::from_ref(option.r());
|
let el = option.upcast::<Element>();
|
||||||
el.set_disabled_state(true);
|
el.set_disabled_state(true);
|
||||||
el.set_enabled_state(false);
|
el.set_enabled_state(false);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
for option in options {
|
for option in options {
|
||||||
let el = ElementCast::from_ref(option.r());
|
let el = option.upcast::<Element>();
|
||||||
el.check_disabled_attribute();
|
el.check_disabled_attribute();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,14 +7,15 @@ use dom::bindings::codegen::Bindings::CharacterDataBinding::CharacterDataMethods
|
||||||
use dom::bindings::codegen::Bindings::HTMLOptionElementBinding;
|
use dom::bindings::codegen::Bindings::HTMLOptionElementBinding;
|
||||||
use dom::bindings::codegen::Bindings::HTMLOptionElementBinding::HTMLOptionElementMethods;
|
use dom::bindings::codegen::Bindings::HTMLOptionElementBinding::HTMLOptionElementMethods;
|
||||||
use dom::bindings::codegen::Bindings::NodeBinding::NodeMethods;
|
use dom::bindings::codegen::Bindings::NodeBinding::NodeMethods;
|
||||||
use dom::bindings::codegen::InheritTypes::{CharacterDataCast, ElementCast};
|
use dom::bindings::conversions::Castable;
|
||||||
use dom::bindings::codegen::InheritTypes::{HTMLElementCast, HTMLScriptElementDerived};
|
|
||||||
use dom::bindings::codegen::InheritTypes::{NodeCast, TextDerived};
|
|
||||||
use dom::bindings::js::Root;
|
use dom::bindings::js::Root;
|
||||||
|
use dom::characterdata::CharacterData;
|
||||||
use dom::document::Document;
|
use dom::document::Document;
|
||||||
use dom::element::{AttributeMutation, Element, IN_ENABLED_STATE};
|
use dom::element::{AttributeMutation, Element, IN_ENABLED_STATE};
|
||||||
use dom::htmlelement::HTMLElement;
|
use dom::htmlelement::HTMLElement;
|
||||||
use dom::node::{Node};
|
use dom::htmlscriptelement::HTMLScriptElement;
|
||||||
|
use dom::node::Node;
|
||||||
|
use dom::text::Text;
|
||||||
use dom::virtualmethods::VirtualMethods;
|
use dom::virtualmethods::VirtualMethods;
|
||||||
use std::cell::Cell;
|
use std::cell::Cell;
|
||||||
use util::str::{DOMString, split_html_space_chars, str_join};
|
use util::str::{DOMString, split_html_space_chars, str_join};
|
||||||
|
@ -54,16 +55,16 @@ impl HTMLOptionElement {
|
||||||
|
|
||||||
fn collect_text(element: &Element, value: &mut DOMString) {
|
fn collect_text(element: &Element, value: &mut DOMString) {
|
||||||
let svg_script = *element.namespace() == ns!(SVG) && element.local_name() == &atom!("script");
|
let svg_script = *element.namespace() == ns!(SVG) && element.local_name() == &atom!("script");
|
||||||
let html_script = element.is_htmlscriptelement();
|
let html_script = element.is::<HTMLScriptElement>();
|
||||||
if svg_script || html_script {
|
if svg_script || html_script {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
for child in NodeCast::from_ref(element).children() {
|
for child in element.upcast::<Node>().children() {
|
||||||
if child.r().is_text() {
|
if child.is::<Text>() {
|
||||||
let characterdata = CharacterDataCast::to_ref(child.r()).unwrap();
|
let characterdata = child.downcast::<CharacterData>().unwrap();
|
||||||
value.push_str(&characterdata.Data());
|
value.push_str(&characterdata.Data());
|
||||||
} else if let Some(element_child) = ElementCast::to_ref(&*child) {
|
} else if let Some(element_child) = child.downcast::<Element>() {
|
||||||
collect_text(element_child, value);
|
collect_text(element_child, value);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -75,13 +76,13 @@ impl HTMLOptionElementMethods for HTMLOptionElement {
|
||||||
|
|
||||||
// https://html.spec.whatwg.org/multipage/#dom-option-disabled
|
// https://html.spec.whatwg.org/multipage/#dom-option-disabled
|
||||||
fn SetDisabled(&self, disabled: bool) {
|
fn SetDisabled(&self, disabled: bool) {
|
||||||
let elem = ElementCast::from_ref(self);
|
let elem = self.upcast::<Element>();
|
||||||
elem.set_bool_attribute(&atom!("disabled"), disabled)
|
elem.set_bool_attribute(&atom!("disabled"), disabled)
|
||||||
}
|
}
|
||||||
|
|
||||||
// https://html.spec.whatwg.org/multipage/#dom-option-text
|
// https://html.spec.whatwg.org/multipage/#dom-option-text
|
||||||
fn Text(&self) -> DOMString {
|
fn Text(&self) -> DOMString {
|
||||||
let element = ElementCast::from_ref(self);
|
let element = self.upcast::<Element>();
|
||||||
let mut content = String::new();
|
let mut content = String::new();
|
||||||
collect_text(element, &mut content);
|
collect_text(element, &mut content);
|
||||||
str_join(split_html_space_chars(&content), " ")
|
str_join(split_html_space_chars(&content), " ")
|
||||||
|
@ -89,13 +90,13 @@ impl HTMLOptionElementMethods for HTMLOptionElement {
|
||||||
|
|
||||||
// https://html.spec.whatwg.org/multipage/#dom-option-text
|
// https://html.spec.whatwg.org/multipage/#dom-option-text
|
||||||
fn SetText(&self, value: DOMString) {
|
fn SetText(&self, value: DOMString) {
|
||||||
let node = NodeCast::from_ref(self);
|
let node = self.upcast::<Node>();
|
||||||
node.SetTextContent(Some(value))
|
node.SetTextContent(Some(value))
|
||||||
}
|
}
|
||||||
|
|
||||||
// https://html.spec.whatwg.org/multipage/#attr-option-value
|
// https://html.spec.whatwg.org/multipage/#attr-option-value
|
||||||
fn Value(&self) -> DOMString {
|
fn Value(&self) -> DOMString {
|
||||||
let element = ElementCast::from_ref(self);
|
let element = self.upcast::<Element>();
|
||||||
let attr = &atom!("value");
|
let attr = &atom!("value");
|
||||||
if element.has_attribute(attr) {
|
if element.has_attribute(attr) {
|
||||||
element.get_string_attribute(attr)
|
element.get_string_attribute(attr)
|
||||||
|
@ -109,7 +110,7 @@ impl HTMLOptionElementMethods for HTMLOptionElement {
|
||||||
|
|
||||||
// https://html.spec.whatwg.org/multipage/#attr-option-label
|
// https://html.spec.whatwg.org/multipage/#attr-option-label
|
||||||
fn Label(&self) -> DOMString {
|
fn Label(&self) -> DOMString {
|
||||||
let element = ElementCast::from_ref(self);
|
let element = self.upcast::<Element>();
|
||||||
let attr = &atom!("label");
|
let attr = &atom!("label");
|
||||||
if element.has_attribute(attr) {
|
if element.has_attribute(attr) {
|
||||||
element.get_string_attribute(attr)
|
element.get_string_attribute(attr)
|
||||||
|
@ -143,7 +144,7 @@ impl HTMLOptionElementMethods for HTMLOptionElement {
|
||||||
|
|
||||||
impl VirtualMethods for HTMLOptionElement {
|
impl VirtualMethods for HTMLOptionElement {
|
||||||
fn super_type(&self) -> Option<&VirtualMethods> {
|
fn super_type(&self) -> Option<&VirtualMethods> {
|
||||||
let htmlelement: &HTMLElement = HTMLElementCast::from_ref(self);
|
let htmlelement: &HTMLElement = self.upcast::<HTMLElement>();
|
||||||
Some(htmlelement as &VirtualMethods)
|
Some(htmlelement as &VirtualMethods)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -151,7 +152,7 @@ impl VirtualMethods for HTMLOptionElement {
|
||||||
self.super_type().unwrap().attribute_mutated(attr, mutation);
|
self.super_type().unwrap().attribute_mutated(attr, mutation);
|
||||||
match attr.local_name() {
|
match attr.local_name() {
|
||||||
&atom!(disabled) => {
|
&atom!(disabled) => {
|
||||||
let el = ElementCast::from_ref(self);
|
let el = self.upcast::<Element>();
|
||||||
match mutation {
|
match mutation {
|
||||||
AttributeMutation::Set(_) => {
|
AttributeMutation::Set(_) => {
|
||||||
el.set_disabled_state(true);
|
el.set_disabled_state(true);
|
||||||
|
@ -189,7 +190,7 @@ impl VirtualMethods for HTMLOptionElement {
|
||||||
s.bind_to_tree(tree_in_doc);
|
s.bind_to_tree(tree_in_doc);
|
||||||
}
|
}
|
||||||
|
|
||||||
let el = ElementCast::from_ref(self);
|
let el = self.upcast::<Element>();
|
||||||
el.check_parent_disabled_state_for_option();
|
el.check_parent_disabled_state_for_option();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -198,8 +199,8 @@ impl VirtualMethods for HTMLOptionElement {
|
||||||
s.unbind_from_tree(tree_in_doc);
|
s.unbind_from_tree(tree_in_doc);
|
||||||
}
|
}
|
||||||
|
|
||||||
let node = NodeCast::from_ref(self);
|
let node = self.upcast::<Node>();
|
||||||
let el = ElementCast::from_ref(self);
|
let el = self.upcast::<Element>();
|
||||||
if node.GetParentNode().is_some() {
|
if node.GetParentNode().is_some() {
|
||||||
el.check_parent_disabled_state_for_option();
|
el.check_parent_disabled_state_for_option();
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -10,16 +10,16 @@ use dom::bindings::codegen::Bindings::DocumentBinding::DocumentMethods;
|
||||||
use dom::bindings::codegen::Bindings::HTMLScriptElementBinding;
|
use dom::bindings::codegen::Bindings::HTMLScriptElementBinding;
|
||||||
use dom::bindings::codegen::Bindings::HTMLScriptElementBinding::HTMLScriptElementMethods;
|
use dom::bindings::codegen::Bindings::HTMLScriptElementBinding::HTMLScriptElementMethods;
|
||||||
use dom::bindings::codegen::Bindings::NodeBinding::NodeMethods;
|
use dom::bindings::codegen::Bindings::NodeBinding::NodeMethods;
|
||||||
use dom::bindings::codegen::InheritTypes::{ElementCast, EventTargetCast, HTMLElementCast};
|
use dom::bindings::conversions::Castable;
|
||||||
use dom::bindings::codegen::InheritTypes::{HTMLScriptElementCast, NodeCast};
|
|
||||||
use dom::bindings::global::GlobalRef;
|
use dom::bindings::global::GlobalRef;
|
||||||
use dom::bindings::js::RootedReference;
|
use dom::bindings::js::RootedReference;
|
||||||
use dom::bindings::js::{JS, Root};
|
use dom::bindings::js::{JS, Root};
|
||||||
use dom::bindings::refcounted::Trusted;
|
use dom::bindings::refcounted::Trusted;
|
||||||
use dom::bindings::trace::JSTraceable;
|
use dom::bindings::trace::JSTraceable;
|
||||||
use dom::document::Document;
|
use dom::document::Document;
|
||||||
use dom::element::{AttributeMutation, ElementCreator};
|
use dom::element::{AttributeMutation, Element, ElementCreator};
|
||||||
use dom::event::{Event, EventBubbles, EventCancelable};
|
use dom::event::{Event, EventBubbles, EventCancelable};
|
||||||
|
use dom::eventtarget::EventTarget;
|
||||||
use dom::htmlelement::HTMLElement;
|
use dom::htmlelement::HTMLElement;
|
||||||
use dom::node::{ChildrenMutation, CloneChildrenFlag, Node};
|
use dom::node::{ChildrenMutation, CloneChildrenFlag, Node};
|
||||||
use dom::node::{document_from_node, window_from_node};
|
use dom::node::{document_from_node, window_from_node};
|
||||||
|
@ -180,7 +180,7 @@ impl HTMLScriptElement {
|
||||||
self.parser_inserted.set(false);
|
self.parser_inserted.set(false);
|
||||||
|
|
||||||
// Step 3.
|
// Step 3.
|
||||||
let element = ElementCast::from_ref(self);
|
let element = self.upcast::<Element>();
|
||||||
if was_parser_inserted && element.has_attribute(&atom!("async")) {
|
if was_parser_inserted && element.has_attribute(&atom!("async")) {
|
||||||
self.non_blocking.set(true);
|
self.non_blocking.set(true);
|
||||||
}
|
}
|
||||||
|
@ -190,7 +190,7 @@ impl HTMLScriptElement {
|
||||||
return NextParserState::Continue;
|
return NextParserState::Continue;
|
||||||
}
|
}
|
||||||
// Step 5.
|
// Step 5.
|
||||||
let node = NodeCast::from_ref(self);
|
let node = self.upcast::<Node>();
|
||||||
if !node.is_in_doc() {
|
if !node.is_in_doc() {
|
||||||
return NextParserState::Continue;
|
return NextParserState::Continue;
|
||||||
}
|
}
|
||||||
|
@ -454,7 +454,7 @@ impl HTMLScriptElement {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn is_javascript(&self) -> bool {
|
pub fn is_javascript(&self) -> bool {
|
||||||
let element = ElementCast::from_ref(self);
|
let element = self.upcast::<Element>();
|
||||||
let type_attr = element.get_attribute(&ns!(""), &atom!("type"));
|
let type_attr = element.get_attribute(&ns!(""), &atom!("type"));
|
||||||
let is_js = match type_attr.as_ref().map(|s| s.value()) {
|
let is_js = match type_attr.as_ref().map(|s| s.value()) {
|
||||||
Some(ref s) if s.is_empty() => {
|
Some(ref s) if s.is_empty() => {
|
||||||
|
@ -508,14 +508,14 @@ impl HTMLScriptElement {
|
||||||
bubbles,
|
bubbles,
|
||||||
cancelable);
|
cancelable);
|
||||||
let event = event.r();
|
let event = event.r();
|
||||||
let target = EventTargetCast::from_ref(self);
|
let target = self.upcast::<EventTarget>();
|
||||||
event.fire(target)
|
event.fire(target)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl VirtualMethods for HTMLScriptElement {
|
impl VirtualMethods for HTMLScriptElement {
|
||||||
fn super_type(&self) -> Option<&VirtualMethods> {
|
fn super_type(&self) -> Option<&VirtualMethods> {
|
||||||
let htmlelement: &HTMLElement = HTMLElementCast::from_ref(self);
|
let htmlelement: &HTMLElement = self.upcast::<HTMLElement>();
|
||||||
Some(htmlelement as &VirtualMethods)
|
Some(htmlelement as &VirtualMethods)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -524,7 +524,7 @@ impl VirtualMethods for HTMLScriptElement {
|
||||||
match attr.local_name() {
|
match attr.local_name() {
|
||||||
&atom!("src") => {
|
&atom!("src") => {
|
||||||
if let AttributeMutation::Set(_) = mutation {
|
if let AttributeMutation::Set(_) = mutation {
|
||||||
if !self.parser_inserted.get() && NodeCast::from_ref(self).is_in_doc() {
|
if !self.parser_inserted.get() && self.upcast::<Node>().is_in_doc() {
|
||||||
self.prepare();
|
self.prepare();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -537,7 +537,7 @@ impl VirtualMethods for HTMLScriptElement {
|
||||||
if let Some(ref s) = self.super_type() {
|
if let Some(ref s) = self.super_type() {
|
||||||
s.children_changed(mutation);
|
s.children_changed(mutation);
|
||||||
}
|
}
|
||||||
let node = NodeCast::from_ref(self);
|
let node = self.upcast::<Node>();
|
||||||
if !self.parser_inserted.get() && node.is_in_doc() {
|
if !self.parser_inserted.get() && node.is_in_doc() {
|
||||||
self.prepare();
|
self.prepare();
|
||||||
}
|
}
|
||||||
|
@ -561,7 +561,7 @@ impl VirtualMethods for HTMLScriptElement {
|
||||||
|
|
||||||
// https://html.spec.whatwg.org/multipage/#already-started
|
// https://html.spec.whatwg.org/multipage/#already-started
|
||||||
if self.already_started.get() {
|
if self.already_started.get() {
|
||||||
let copy_elem = HTMLScriptElementCast::to_ref(copy).unwrap();
|
let copy_elem = copy.downcast::<HTMLScriptElement>().unwrap();
|
||||||
copy_elem.mark_already_started();
|
copy_elem.mark_already_started();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -575,12 +575,12 @@ impl HTMLScriptElementMethods for HTMLScriptElement {
|
||||||
|
|
||||||
// https://html.spec.whatwg.org/multipage/#dom-script-text
|
// https://html.spec.whatwg.org/multipage/#dom-script-text
|
||||||
fn Text(&self) -> DOMString {
|
fn Text(&self) -> DOMString {
|
||||||
Node::collect_text_contents(NodeCast::from_ref(self).children())
|
Node::collect_text_contents(self.upcast::<Node>().children())
|
||||||
}
|
}
|
||||||
|
|
||||||
// https://html.spec.whatwg.org/multipage/#dom-script-text
|
// https://html.spec.whatwg.org/multipage/#dom-script-text
|
||||||
fn SetText(&self, value: DOMString) {
|
fn SetText(&self, value: DOMString) {
|
||||||
let node = NodeCast::from_ref(self);
|
let node = self.upcast::<Node>();
|
||||||
node.SetTextContent(Some(value))
|
node.SetTextContent(Some(value))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,13 +5,14 @@
|
||||||
use dom::attr::{Attr, AttrValue};
|
use dom::attr::{Attr, AttrValue};
|
||||||
use dom::bindings::codegen::Bindings::HTMLSelectElementBinding;
|
use dom::bindings::codegen::Bindings::HTMLSelectElementBinding;
|
||||||
use dom::bindings::codegen::Bindings::HTMLSelectElementBinding::HTMLSelectElementMethods;
|
use dom::bindings::codegen::Bindings::HTMLSelectElementBinding::HTMLSelectElementMethods;
|
||||||
use dom::bindings::codegen::InheritTypes::{ElementCast, HTMLElementCast, HTMLFieldSetElementDerived, NodeCast};
|
|
||||||
use dom::bindings::codegen::UnionTypes::HTMLElementOrLong;
|
use dom::bindings::codegen::UnionTypes::HTMLElementOrLong;
|
||||||
use dom::bindings::codegen::UnionTypes::HTMLOptionElementOrHTMLOptGroupElement;
|
use dom::bindings::codegen::UnionTypes::HTMLOptionElementOrHTMLOptGroupElement;
|
||||||
|
use dom::bindings::conversions::Castable;
|
||||||
use dom::bindings::js::Root;
|
use dom::bindings::js::Root;
|
||||||
use dom::document::Document;
|
use dom::document::Document;
|
||||||
use dom::element::{AttributeMutation, IN_ENABLED_STATE};
|
use dom::element::{AttributeMutation, Element, IN_ENABLED_STATE};
|
||||||
use dom::htmlelement::HTMLElement;
|
use dom::htmlelement::HTMLElement;
|
||||||
|
use dom::htmlfieldsetelement::HTMLFieldSetElement;
|
||||||
use dom::htmlformelement::{FormControl, HTMLFormElement};
|
use dom::htmlformelement::{FormControl, HTMLFormElement};
|
||||||
use dom::node::{Node, window_from_node};
|
use dom::node::{Node, window_from_node};
|
||||||
use dom::validitystate::ValidityState;
|
use dom::validitystate::ValidityState;
|
||||||
|
@ -100,14 +101,14 @@ impl HTMLSelectElementMethods for HTMLSelectElement {
|
||||||
|
|
||||||
impl VirtualMethods for HTMLSelectElement {
|
impl VirtualMethods for HTMLSelectElement {
|
||||||
fn super_type(&self) -> Option<&VirtualMethods> {
|
fn super_type(&self) -> Option<&VirtualMethods> {
|
||||||
let htmlelement: &HTMLElement = HTMLElementCast::from_ref(self);
|
let htmlelement: &HTMLElement = self.upcast::<HTMLElement>();
|
||||||
Some(htmlelement as &VirtualMethods)
|
Some(htmlelement as &VirtualMethods)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn attribute_mutated(&self, attr: &Attr, mutation: AttributeMutation) {
|
fn attribute_mutated(&self, attr: &Attr, mutation: AttributeMutation) {
|
||||||
self.super_type().unwrap().attribute_mutated(attr, mutation);
|
self.super_type().unwrap().attribute_mutated(attr, mutation);
|
||||||
if attr.local_name() == &atom!(disabled) {
|
if attr.local_name() == &atom!(disabled) {
|
||||||
let el = ElementCast::from_ref(self);
|
let el = self.upcast::<Element>();
|
||||||
match mutation {
|
match mutation {
|
||||||
AttributeMutation::Set(_) => {
|
AttributeMutation::Set(_) => {
|
||||||
el.set_disabled_state(true);
|
el.set_disabled_state(true);
|
||||||
|
@ -127,7 +128,7 @@ impl VirtualMethods for HTMLSelectElement {
|
||||||
s.bind_to_tree(tree_in_doc);
|
s.bind_to_tree(tree_in_doc);
|
||||||
}
|
}
|
||||||
|
|
||||||
let el = ElementCast::from_ref(self);
|
let el = self.upcast::<Element>();
|
||||||
el.check_ancestors_disabled_state_for_form_control();
|
el.check_ancestors_disabled_state_for_form_control();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -136,9 +137,9 @@ impl VirtualMethods for HTMLSelectElement {
|
||||||
s.unbind_from_tree(tree_in_doc);
|
s.unbind_from_tree(tree_in_doc);
|
||||||
}
|
}
|
||||||
|
|
||||||
let node = NodeCast::from_ref(self);
|
let node = self.upcast::<Node>();
|
||||||
let el = ElementCast::from_ref(self);
|
let el = self.upcast::<Element>();
|
||||||
if node.ancestors().any(|ancestor| ancestor.r().is_htmlfieldsetelement()) {
|
if node.ancestors().any(|ancestor| ancestor.r().is::<HTMLFieldSetElement>()) {
|
||||||
el.check_ancestors_disabled_state_for_form_control();
|
el.check_ancestors_disabled_state_for_form_control();
|
||||||
} else {
|
} else {
|
||||||
el.check_disabled_attribute();
|
el.check_disabled_attribute();
|
||||||
|
|
|
@ -5,9 +5,10 @@
|
||||||
use cssparser::Parser as CssParser;
|
use cssparser::Parser as CssParser;
|
||||||
use dom::bindings::codegen::Bindings::HTMLStyleElementBinding;
|
use dom::bindings::codegen::Bindings::HTMLStyleElementBinding;
|
||||||
use dom::bindings::codegen::Bindings::NodeBinding::NodeMethods;
|
use dom::bindings::codegen::Bindings::NodeBinding::NodeMethods;
|
||||||
use dom::bindings::codegen::InheritTypes::{ElementCast, HTMLElementCast, NodeCast};
|
use dom::bindings::conversions::Castable;
|
||||||
use dom::bindings::js::Root;
|
use dom::bindings::js::Root;
|
||||||
use dom::document::Document;
|
use dom::document::Document;
|
||||||
|
use dom::element::Element;
|
||||||
use dom::htmlelement::HTMLElement;
|
use dom::htmlelement::HTMLElement;
|
||||||
use dom::node::{ChildrenMutation, Node, window_from_node};
|
use dom::node::{ChildrenMutation, Node, window_from_node};
|
||||||
use dom::virtualmethods::VirtualMethods;
|
use dom::virtualmethods::VirtualMethods;
|
||||||
|
@ -39,8 +40,8 @@ impl HTMLStyleElement {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn parse_own_css(&self) {
|
pub fn parse_own_css(&self) {
|
||||||
let node = NodeCast::from_ref(self);
|
let node = self.upcast::<Node>();
|
||||||
let element = ElementCast::from_ref(self);
|
let element = self.upcast::<Element>();
|
||||||
assert!(node.is_in_doc());
|
assert!(node.is_in_doc());
|
||||||
|
|
||||||
let win = window_from_node(node);
|
let win = window_from_node(node);
|
||||||
|
@ -64,7 +65,7 @@ impl HTMLStyleElement {
|
||||||
|
|
||||||
impl VirtualMethods for HTMLStyleElement {
|
impl VirtualMethods for HTMLStyleElement {
|
||||||
fn super_type(&self) -> Option<&VirtualMethods> {
|
fn super_type(&self) -> Option<&VirtualMethods> {
|
||||||
let htmlelement: &HTMLElement = HTMLElementCast::from_ref(self);
|
let htmlelement: &HTMLElement = self.upcast::<HTMLElement>();
|
||||||
Some(htmlelement as &VirtualMethods)
|
Some(htmlelement as &VirtualMethods)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -72,7 +73,7 @@ impl VirtualMethods for HTMLStyleElement {
|
||||||
if let Some(ref s) = self.super_type() {
|
if let Some(ref s) = self.super_type() {
|
||||||
s.children_changed(mutation);
|
s.children_changed(mutation);
|
||||||
}
|
}
|
||||||
let node = NodeCast::from_ref(self);
|
let node = self.upcast::<Node>();
|
||||||
if node.is_in_doc() {
|
if node.is_in_doc() {
|
||||||
self.parse_own_css();
|
self.parse_own_css();
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,12 +6,13 @@ use cssparser::RGBA;
|
||||||
use dom::attr::{Attr, AttrValue};
|
use dom::attr::{Attr, AttrValue};
|
||||||
use dom::bindings::codegen::Bindings::HTMLTableCellElementBinding::HTMLTableCellElementMethods;
|
use dom::bindings::codegen::Bindings::HTMLTableCellElementBinding::HTMLTableCellElementMethods;
|
||||||
use dom::bindings::codegen::Bindings::NodeBinding::NodeMethods;
|
use dom::bindings::codegen::Bindings::NodeBinding::NodeMethods;
|
||||||
use dom::bindings::codegen::InheritTypes::{HTMLElementCast, HTMLTableCellElementDerived};
|
use dom::bindings::conversions::Castable;
|
||||||
use dom::bindings::codegen::InheritTypes::{HTMLTableRowElementDerived, NodeCast};
|
|
||||||
use dom::bindings::js::LayoutJS;
|
use dom::bindings::js::LayoutJS;
|
||||||
use dom::document::Document;
|
use dom::document::Document;
|
||||||
use dom::element::AttributeMutation;
|
use dom::element::AttributeMutation;
|
||||||
use dom::htmlelement::HTMLElement;
|
use dom::htmlelement::HTMLElement;
|
||||||
|
use dom::htmltablerowelement::HTMLTableRowElement;
|
||||||
|
use dom::node::Node;
|
||||||
use dom::virtualmethods::VirtualMethods;
|
use dom::virtualmethods::VirtualMethods;
|
||||||
use std::cell::Cell;
|
use std::cell::Cell;
|
||||||
use std::cmp::max;
|
use std::cmp::max;
|
||||||
|
@ -56,14 +57,16 @@ impl HTMLTableCellElementMethods for HTMLTableCellElement {
|
||||||
|
|
||||||
// https://html.spec.whatwg.org/multipage/#dom-tdth-cellindex
|
// https://html.spec.whatwg.org/multipage/#dom-tdth-cellindex
|
||||||
fn CellIndex(&self) -> i32 {
|
fn CellIndex(&self) -> i32 {
|
||||||
let self_node = NodeCast::from_ref(self);
|
let self_node = self.upcast::<Node>();
|
||||||
|
|
||||||
let parent_children = match self_node.GetParentNode() {
|
let parent_children = match self_node.GetParentNode() {
|
||||||
Some(ref parent_node) if parent_node.is_htmltablerowelement() => parent_node.children(),
|
Some(ref parent_node) if parent_node.is::<HTMLTableRowElement>() => {
|
||||||
|
parent_node.children()
|
||||||
|
},
|
||||||
_ => return -1,
|
_ => return -1,
|
||||||
};
|
};
|
||||||
|
|
||||||
parent_children.filter(|c| c.is_htmltablecellelement())
|
parent_children.filter(|c| c.is::<HTMLTableCellElement>())
|
||||||
.position(|c| c.r() == self_node)
|
.position(|c| c.r() == self_node)
|
||||||
.map(|p| p as i32).unwrap_or(-1)
|
.map(|p| p as i32).unwrap_or(-1)
|
||||||
}
|
}
|
||||||
|
@ -99,7 +102,7 @@ impl HTMLTableCellElementLayoutHelpers for LayoutJS<HTMLTableCellElement> {
|
||||||
|
|
||||||
impl VirtualMethods for HTMLTableCellElement {
|
impl VirtualMethods for HTMLTableCellElement {
|
||||||
fn super_type(&self) -> Option<&VirtualMethods> {
|
fn super_type(&self) -> Option<&VirtualMethods> {
|
||||||
let htmlelement: &HTMLElement = HTMLElementCast::from_ref(self);
|
let htmlelement: &HTMLElement = self.upcast::<HTMLElement>();
|
||||||
Some(htmlelement as &VirtualMethods)
|
Some(htmlelement as &VirtualMethods)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -7,12 +7,10 @@ use dom::attr::{Attr, AttrValue};
|
||||||
use dom::bindings::codegen::Bindings::HTMLTableElementBinding;
|
use dom::bindings::codegen::Bindings::HTMLTableElementBinding;
|
||||||
use dom::bindings::codegen::Bindings::HTMLTableElementBinding::HTMLTableElementMethods;
|
use dom::bindings::codegen::Bindings::HTMLTableElementBinding::HTMLTableElementMethods;
|
||||||
use dom::bindings::codegen::Bindings::NodeBinding::NodeMethods;
|
use dom::bindings::codegen::Bindings::NodeBinding::NodeMethods;
|
||||||
use dom::bindings::codegen::InheritTypes::ElementCast;
|
use dom::bindings::conversions::Castable;
|
||||||
use dom::bindings::codegen::InheritTypes::{HTMLElementCast, HTMLTableCaptionElementCast};
|
|
||||||
use dom::bindings::codegen::InheritTypes::{HTMLTableSectionElementDerived, NodeCast};
|
|
||||||
use dom::bindings::js::{Root, RootedReference};
|
use dom::bindings::js::{Root, RootedReference};
|
||||||
use dom::document::Document;
|
use dom::document::Document;
|
||||||
use dom::element::AttributeMutation;
|
use dom::element::{AttributeMutation, Element};
|
||||||
use dom::htmlelement::HTMLElement;
|
use dom::htmlelement::HTMLElement;
|
||||||
use dom::htmltablecaptionelement::HTMLTableCaptionElement;
|
use dom::htmltablecaptionelement::HTMLTableCaptionElement;
|
||||||
use dom::htmltablesectionelement::HTMLTableSectionElement;
|
use dom::htmltablesectionelement::HTMLTableSectionElement;
|
||||||
|
@ -54,24 +52,24 @@ impl HTMLTableElement {
|
||||||
impl HTMLTableElementMethods for HTMLTableElement {
|
impl HTMLTableElementMethods for HTMLTableElement {
|
||||||
// https://html.spec.whatwg.org/multipage/#dom-table-caption
|
// https://html.spec.whatwg.org/multipage/#dom-table-caption
|
||||||
fn GetCaption(&self) -> Option<Root<HTMLTableCaptionElement>> {
|
fn GetCaption(&self) -> Option<Root<HTMLTableCaptionElement>> {
|
||||||
let node = NodeCast::from_ref(self);
|
let node = self.upcast::<Node>();
|
||||||
node.children()
|
node.children()
|
||||||
.filter_map(|c| {
|
.filter_map(|c| {
|
||||||
HTMLTableCaptionElementCast::to_ref(c.r()).map(Root::from_ref)
|
c.downcast::<HTMLTableCaptionElement>().map(Root::from_ref)
|
||||||
})
|
})
|
||||||
.next()
|
.next()
|
||||||
}
|
}
|
||||||
|
|
||||||
// https://html.spec.whatwg.org/multipage/#dom-table-caption
|
// https://html.spec.whatwg.org/multipage/#dom-table-caption
|
||||||
fn SetCaption(&self, new_caption: Option<&HTMLTableCaptionElement>) {
|
fn SetCaption(&self, new_caption: Option<&HTMLTableCaptionElement>) {
|
||||||
let node = NodeCast::from_ref(self);
|
let node = self.upcast::<Node>();
|
||||||
|
|
||||||
if let Some(ref caption) = self.GetCaption() {
|
if let Some(ref caption) = self.GetCaption() {
|
||||||
NodeCast::from_ref(caption.r()).remove_self();
|
caption.upcast::<Node>().remove_self();
|
||||||
}
|
}
|
||||||
|
|
||||||
if let Some(caption) = new_caption {
|
if let Some(caption) = new_caption {
|
||||||
assert!(node.InsertBefore(NodeCast::from_ref(caption),
|
assert!(node.InsertBefore(caption.upcast::<Node>(),
|
||||||
node.GetFirstChild().as_ref().map(|n| n.r())).is_ok());
|
node.GetFirstChild().as_ref().map(|n| n.r())).is_ok());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -88,13 +86,13 @@ impl HTMLTableElementMethods for HTMLTableElement {
|
||||||
caption
|
caption
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
HTMLElementCast::from_root(caption)
|
Root::upcast::<HTMLElement>(caption)
|
||||||
}
|
}
|
||||||
|
|
||||||
// https://html.spec.whatwg.org/multipage/#dom-table-deletecaption
|
// https://html.spec.whatwg.org/multipage/#dom-table-deletecaption
|
||||||
fn DeleteCaption(&self) {
|
fn DeleteCaption(&self) {
|
||||||
if let Some(caption) = self.GetCaption() {
|
if let Some(caption) = self.GetCaption() {
|
||||||
NodeCast::from_ref(caption.r()).remove_self();
|
caption.upcast::<Node>().remove_self();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -103,15 +101,15 @@ impl HTMLTableElementMethods for HTMLTableElement {
|
||||||
let tbody = HTMLTableSectionElement::new("tbody".to_owned(),
|
let tbody = HTMLTableSectionElement::new("tbody".to_owned(),
|
||||||
None,
|
None,
|
||||||
document_from_node(self).r());
|
document_from_node(self).r());
|
||||||
let node = NodeCast::from_ref(self);
|
let node = self.upcast::<Node>();
|
||||||
let last_tbody =
|
let last_tbody =
|
||||||
node.rev_children()
|
node.rev_children()
|
||||||
.filter_map(ElementCast::to_root)
|
.filter_map(Root::downcast::<Element>)
|
||||||
.find(|n| n.is_htmltablesectionelement() && n.local_name() == &atom!("tbody"));
|
.find(|n| n.is::<HTMLTableSectionElement>() && n.local_name() == &atom!("tbody"));
|
||||||
let reference_element =
|
let reference_element =
|
||||||
last_tbody.and_then(|t| NodeCast::from_root(t).GetNextSibling());
|
last_tbody.and_then(|t| Root::upcast::<Node>(t).GetNextSibling());
|
||||||
|
|
||||||
assert!(node.InsertBefore(NodeCast::from_ref(tbody.r()),
|
assert!(node.InsertBefore(tbody.upcast::<Node>(),
|
||||||
reference_element.r()).is_ok());
|
reference_element.r()).is_ok());
|
||||||
tbody
|
tbody
|
||||||
}
|
}
|
||||||
|
@ -144,7 +142,7 @@ impl HTMLTableElement {
|
||||||
|
|
||||||
impl VirtualMethods for HTMLTableElement {
|
impl VirtualMethods for HTMLTableElement {
|
||||||
fn super_type(&self) -> Option<&VirtualMethods> {
|
fn super_type(&self) -> Option<&VirtualMethods> {
|
||||||
let htmlelement: &HTMLElement = HTMLElementCast::from_ref(self);
|
let htmlelement: &HTMLElement = self.upcast::<HTMLElement>();
|
||||||
Some(htmlelement as &VirtualMethods)
|
Some(htmlelement as &VirtualMethods)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -6,8 +6,7 @@ use cssparser::RGBA;
|
||||||
use dom::attr::Attr;
|
use dom::attr::Attr;
|
||||||
use dom::bindings::codegen::Bindings::HTMLTableRowElementBinding::{self, HTMLTableRowElementMethods};
|
use dom::bindings::codegen::Bindings::HTMLTableRowElementBinding::{self, HTMLTableRowElementMethods};
|
||||||
use dom::bindings::codegen::Bindings::NodeBinding::NodeMethods;
|
use dom::bindings::codegen::Bindings::NodeBinding::NodeMethods;
|
||||||
use dom::bindings::codegen::InheritTypes::{HTMLElementCast, HTMLTableDataCellElementDerived};
|
use dom::bindings::conversions::Castable;
|
||||||
use dom::bindings::codegen::InheritTypes::{HTMLTableHeaderCellElementDerived, NodeCast};
|
|
||||||
use dom::bindings::error::{ErrorResult, Fallible};
|
use dom::bindings::error::{ErrorResult, Fallible};
|
||||||
use dom::bindings::js::{JS, MutNullableHeap, Root, RootedReference};
|
use dom::bindings::js::{JS, MutNullableHeap, Root, RootedReference};
|
||||||
use dom::document::Document;
|
use dom::document::Document;
|
||||||
|
@ -15,6 +14,7 @@ use dom::element::{AttributeMutation, Element};
|
||||||
use dom::htmlcollection::{CollectionFilter, HTMLCollection};
|
use dom::htmlcollection::{CollectionFilter, HTMLCollection};
|
||||||
use dom::htmlelement::HTMLElement;
|
use dom::htmlelement::HTMLElement;
|
||||||
use dom::htmltabledatacellelement::HTMLTableDataCellElement;
|
use dom::htmltabledatacellelement::HTMLTableDataCellElement;
|
||||||
|
use dom::htmltableheadercellelement::HTMLTableHeaderCellElement;
|
||||||
use dom::node::{Node, window_from_node};
|
use dom::node::{Node, window_from_node};
|
||||||
use dom::virtualmethods::VirtualMethods;
|
use dom::virtualmethods::VirtualMethods;
|
||||||
use std::cell::Cell;
|
use std::cell::Cell;
|
||||||
|
@ -25,8 +25,8 @@ use util::str::{self, DOMString};
|
||||||
struct CellsFilter;
|
struct CellsFilter;
|
||||||
impl CollectionFilter for CellsFilter {
|
impl CollectionFilter for CellsFilter {
|
||||||
fn filter(&self, elem: &Element, root: &Node) -> bool {
|
fn filter(&self, elem: &Element, root: &Node) -> bool {
|
||||||
(elem.is_htmltableheadercellelement() || elem.is_htmltabledatacellelement())
|
(elem.is::<HTMLTableHeaderCellElement>() || elem.is::<HTMLTableDataCellElement>())
|
||||||
&& NodeCast::from_ref(elem).GetParentNode().r() == Some(root)
|
&& elem.upcast::<Node>().GetParentNode().r() == Some(root)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -72,13 +72,13 @@ impl HTMLTableRowElementMethods for HTMLTableRowElement {
|
||||||
self.cells.or_init(|| {
|
self.cells.or_init(|| {
|
||||||
let window = window_from_node(self);
|
let window = window_from_node(self);
|
||||||
let filter = box CellsFilter;
|
let filter = box CellsFilter;
|
||||||
HTMLCollection::create(window.r(), NodeCast::from_ref(self), filter)
|
HTMLCollection::create(window.r(), self.upcast::<Node>(), filter)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
// https://html.spec.whatwg.org/multipage/#dom-tr-insertcell
|
// https://html.spec.whatwg.org/multipage/#dom-tr-insertcell
|
||||||
fn InsertCell(&self, index: i32) -> Fallible<Root<HTMLElement>> {
|
fn InsertCell(&self, index: i32) -> Fallible<Root<HTMLElement>> {
|
||||||
let node = NodeCast::from_ref(self);
|
let node = self.upcast::<Node>();
|
||||||
node.insert_cell_or_row(
|
node.insert_cell_or_row(
|
||||||
index,
|
index,
|
||||||
|| self.Cells(),
|
|| self.Cells(),
|
||||||
|
@ -87,17 +87,17 @@ impl HTMLTableRowElementMethods for HTMLTableRowElement {
|
||||||
|
|
||||||
// https://html.spec.whatwg.org/multipage/#dom-tr-deletecell
|
// https://html.spec.whatwg.org/multipage/#dom-tr-deletecell
|
||||||
fn DeleteCell(&self, index: i32) -> ErrorResult {
|
fn DeleteCell(&self, index: i32) -> ErrorResult {
|
||||||
let node = NodeCast::from_ref(self);
|
let node = self.upcast::<Node>();
|
||||||
node.delete_cell_or_row(
|
node.delete_cell_or_row(
|
||||||
index,
|
index,
|
||||||
|| self.Cells(),
|
|| self.Cells(),
|
||||||
|n| n.is_htmltabledatacellelement())
|
|n| n.is::<HTMLTableDataCellElement>())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl VirtualMethods for HTMLTableRowElement {
|
impl VirtualMethods for HTMLTableRowElement {
|
||||||
fn super_type(&self) -> Option<&VirtualMethods> {
|
fn super_type(&self) -> Option<&VirtualMethods> {
|
||||||
let htmlelement: &HTMLElement = HTMLElementCast::from_ref(self);
|
let htmlelement: &HTMLElement = self.upcast::<HTMLElement>();
|
||||||
Some(htmlelement as &VirtualMethods)
|
Some(htmlelement as &VirtualMethods)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -6,7 +6,7 @@ use cssparser::RGBA;
|
||||||
use dom::attr::Attr;
|
use dom::attr::Attr;
|
||||||
use dom::bindings::codegen::Bindings::HTMLTableSectionElementBinding::{self, HTMLTableSectionElementMethods};
|
use dom::bindings::codegen::Bindings::HTMLTableSectionElementBinding::{self, HTMLTableSectionElementMethods};
|
||||||
use dom::bindings::codegen::Bindings::NodeBinding::NodeMethods;
|
use dom::bindings::codegen::Bindings::NodeBinding::NodeMethods;
|
||||||
use dom::bindings::codegen::InheritTypes::{HTMLElementCast, HTMLTableRowElementDerived, NodeCast};
|
use dom::bindings::conversions::Castable;
|
||||||
use dom::bindings::error::{ErrorResult, Fallible};
|
use dom::bindings::error::{ErrorResult, Fallible};
|
||||||
use dom::bindings::js::{Root, RootedReference};
|
use dom::bindings::js::{Root, RootedReference};
|
||||||
use dom::document::Document;
|
use dom::document::Document;
|
||||||
|
@ -50,20 +50,20 @@ impl HTMLTableSectionElement {
|
||||||
struct RowsFilter;
|
struct RowsFilter;
|
||||||
impl CollectionFilter for RowsFilter {
|
impl CollectionFilter for RowsFilter {
|
||||||
fn filter(&self, elem: &Element, root: &Node) -> bool {
|
fn filter(&self, elem: &Element, root: &Node) -> bool {
|
||||||
elem.is_htmltablerowelement()
|
elem.is::<HTMLTableRowElement>()
|
||||||
&& NodeCast::from_ref(elem).GetParentNode().r() == Some(root)
|
&& elem.upcast::<Node>().GetParentNode().r() == Some(root)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl HTMLTableSectionElementMethods for HTMLTableSectionElement {
|
impl HTMLTableSectionElementMethods for HTMLTableSectionElement {
|
||||||
// https://html.spec.whatwg.org/multipage/#dom-tbody-rows
|
// https://html.spec.whatwg.org/multipage/#dom-tbody-rows
|
||||||
fn Rows(&self) -> Root<HTMLCollection> {
|
fn Rows(&self) -> Root<HTMLCollection> {
|
||||||
HTMLCollection::create(&window_from_node(self), NodeCast::from_ref(self), box RowsFilter)
|
HTMLCollection::create(&window_from_node(self), self.upcast::<Node>(), box RowsFilter)
|
||||||
}
|
}
|
||||||
|
|
||||||
// https://html.spec.whatwg.org/multipage/#dom-tbody-insertrow
|
// https://html.spec.whatwg.org/multipage/#dom-tbody-insertrow
|
||||||
fn InsertRow(&self, index: i32) -> Fallible<Root<HTMLElement>> {
|
fn InsertRow(&self, index: i32) -> Fallible<Root<HTMLElement>> {
|
||||||
let node = NodeCast::from_ref(self);
|
let node = self.upcast::<Node>();
|
||||||
node.insert_cell_or_row(
|
node.insert_cell_or_row(
|
||||||
index,
|
index,
|
||||||
|| self.Rows(),
|
|| self.Rows(),
|
||||||
|
@ -72,17 +72,17 @@ impl HTMLTableSectionElementMethods for HTMLTableSectionElement {
|
||||||
|
|
||||||
// https://html.spec.whatwg.org/multipage/#dom-tbody-deleterow
|
// https://html.spec.whatwg.org/multipage/#dom-tbody-deleterow
|
||||||
fn DeleteRow(&self, index: i32) -> ErrorResult {
|
fn DeleteRow(&self, index: i32) -> ErrorResult {
|
||||||
let node = NodeCast::from_ref(self);
|
let node = self.upcast::<Node>();
|
||||||
node.delete_cell_or_row(
|
node.delete_cell_or_row(
|
||||||
index,
|
index,
|
||||||
|| self.Rows(),
|
|| self.Rows(),
|
||||||
|n| n.is_htmltablerowelement())
|
|n| n.is::<HTMLTableRowElement>())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl VirtualMethods for HTMLTableSectionElement {
|
impl VirtualMethods for HTMLTableSectionElement {
|
||||||
fn super_type(&self) -> Option<&VirtualMethods> {
|
fn super_type(&self) -> Option<&VirtualMethods> {
|
||||||
let htmlelement: &HTMLElement = HTMLElementCast::from_ref(self);
|
let htmlelement: &HTMLElement = self.upcast::<HTMLElement>();
|
||||||
Some(htmlelement as &VirtualMethods)
|
Some(htmlelement as &VirtualMethods)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -6,7 +6,7 @@ use dom::bindings::codegen::Bindings::DocumentBinding::DocumentMethods;
|
||||||
use dom::bindings::codegen::Bindings::HTMLTemplateElementBinding;
|
use dom::bindings::codegen::Bindings::HTMLTemplateElementBinding;
|
||||||
use dom::bindings::codegen::Bindings::HTMLTemplateElementBinding::HTMLTemplateElementMethods;
|
use dom::bindings::codegen::Bindings::HTMLTemplateElementBinding::HTMLTemplateElementMethods;
|
||||||
use dom::bindings::codegen::Bindings::NodeBinding::NodeMethods;
|
use dom::bindings::codegen::Bindings::NodeBinding::NodeMethods;
|
||||||
use dom::bindings::codegen::InheritTypes::{HTMLElementCast, HTMLTemplateElementCast, NodeCast};
|
use dom::bindings::conversions::Castable;
|
||||||
use dom::bindings::js::{JS, MutNullableHeap, Root};
|
use dom::bindings::js::{JS, MutNullableHeap, Root};
|
||||||
use dom::document::Document;
|
use dom::document::Document;
|
||||||
use dom::documentfragment::DocumentFragment;
|
use dom::documentfragment::DocumentFragment;
|
||||||
|
@ -55,7 +55,7 @@ impl HTMLTemplateElementMethods for HTMLTemplateElement {
|
||||||
|
|
||||||
impl VirtualMethods for HTMLTemplateElement {
|
impl VirtualMethods for HTMLTemplateElement {
|
||||||
fn super_type(&self) -> Option<&VirtualMethods> {
|
fn super_type(&self) -> Option<&VirtualMethods> {
|
||||||
Some(HTMLElementCast::from_ref(self) as &VirtualMethods)
|
Some(self.upcast::<HTMLElement>() as &VirtualMethods)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// https://html.spec.whatwg.org/multipage/#template-adopting-steps
|
/// https://html.spec.whatwg.org/multipage/#template-adopting-steps
|
||||||
|
@ -64,7 +64,7 @@ impl VirtualMethods for HTMLTemplateElement {
|
||||||
// Step 1.
|
// Step 1.
|
||||||
let doc = document_from_node(self).appropriate_template_contents_owner_document();
|
let doc = document_from_node(self).appropriate_template_contents_owner_document();
|
||||||
// Step 2.
|
// Step 2.
|
||||||
Node::adopt(NodeCast::from_ref(&*self.Content()), &doc);
|
Node::adopt(self.Content().upcast::<Node>(), &doc);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// https://html.spec.whatwg.org/multipage/#the-template-element:concept-node-clone-ext
|
/// https://html.spec.whatwg.org/multipage/#the-template-element:concept-node-clone-ext
|
||||||
|
@ -75,11 +75,11 @@ impl VirtualMethods for HTMLTemplateElement {
|
||||||
// Step 1.
|
// Step 1.
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
let copy = HTMLTemplateElementCast::to_ref(copy).unwrap();
|
let copy = copy.downcast::<HTMLTemplateElement>().unwrap();
|
||||||
// Steps 2-3.
|
// Steps 2-3.
|
||||||
let copy_contents = NodeCast::from_root(copy.Content());
|
let copy_contents = Root::upcast::<Node>(copy.Content());
|
||||||
let copy_contents_doc = copy_contents.owner_doc();
|
let copy_contents_doc = copy_contents.owner_doc();
|
||||||
for child in NodeCast::from_root(self.Content()).children() {
|
for child in Root::upcast::<Node>(self.Content()).children() {
|
||||||
let copy_child = Node::clone(
|
let copy_child = Node::clone(
|
||||||
&child, Some(©_contents_doc), CloneChildrenFlag::CloneChildren);
|
&child, Some(©_contents_doc), CloneChildrenFlag::CloneChildren);
|
||||||
copy_contents.AppendChild(©_child).unwrap();
|
copy_contents.AppendChild(©_child).unwrap();
|
||||||
|
|
|
@ -8,16 +8,16 @@ use dom::bindings::codegen::Bindings::EventBinding::EventMethods;
|
||||||
use dom::bindings::codegen::Bindings::HTMLTextAreaElementBinding;
|
use dom::bindings::codegen::Bindings::HTMLTextAreaElementBinding;
|
||||||
use dom::bindings::codegen::Bindings::HTMLTextAreaElementBinding::HTMLTextAreaElementMethods;
|
use dom::bindings::codegen::Bindings::HTMLTextAreaElementBinding::HTMLTextAreaElementMethods;
|
||||||
use dom::bindings::codegen::Bindings::NodeBinding::NodeMethods;
|
use dom::bindings::codegen::Bindings::NodeBinding::NodeMethods;
|
||||||
use dom::bindings::codegen::InheritTypes::{ElementCast, EventTargetCast};
|
use dom::bindings::conversions::Castable;
|
||||||
use dom::bindings::codegen::InheritTypes::{HTMLElementCast, HTMLFieldSetElementDerived};
|
|
||||||
use dom::bindings::codegen::InheritTypes::{KeyboardEventCast, NodeCast};
|
|
||||||
use dom::bindings::global::GlobalRef;
|
use dom::bindings::global::GlobalRef;
|
||||||
use dom::bindings::js::{LayoutJS, Root};
|
use dom::bindings::js::{LayoutJS, Root};
|
||||||
use dom::bindings::refcounted::Trusted;
|
use dom::bindings::refcounted::Trusted;
|
||||||
use dom::document::Document;
|
use dom::document::Document;
|
||||||
use dom::element::{AttributeMutation, IN_ENABLED_STATE};
|
use dom::element::{AttributeMutation, IN_ENABLED_STATE, Element};
|
||||||
use dom::event::{Event, EventBubbles, EventCancelable};
|
use dom::event::{Event, EventBubbles, EventCancelable};
|
||||||
|
use dom::eventtarget::EventTarget;
|
||||||
use dom::htmlelement::HTMLElement;
|
use dom::htmlelement::HTMLElement;
|
||||||
|
use dom::htmlfieldsetelement::HTMLFieldSetElement;
|
||||||
use dom::htmlformelement::{FormControl, HTMLFormElement};
|
use dom::htmlformelement::{FormControl, HTMLFormElement};
|
||||||
use dom::keyboardevent::KeyboardEvent;
|
use dom::keyboardevent::KeyboardEvent;
|
||||||
use dom::node::{ChildrenMutation, Node, NodeDamage};
|
use dom::node::{ChildrenMutation, Node, NodeDamage};
|
||||||
|
@ -169,13 +169,13 @@ impl HTMLTextAreaElementMethods for HTMLTextAreaElement {
|
||||||
|
|
||||||
// https://html.spec.whatwg.org/multipage/#dom-textarea-defaultvalue
|
// https://html.spec.whatwg.org/multipage/#dom-textarea-defaultvalue
|
||||||
fn DefaultValue(&self) -> DOMString {
|
fn DefaultValue(&self) -> DOMString {
|
||||||
let node = NodeCast::from_ref(self);
|
let node = self.upcast::<Node>();
|
||||||
node.GetTextContent().unwrap()
|
node.GetTextContent().unwrap()
|
||||||
}
|
}
|
||||||
|
|
||||||
// https://html.spec.whatwg.org/multipage/#dom-textarea-defaultvalue
|
// https://html.spec.whatwg.org/multipage/#dom-textarea-defaultvalue
|
||||||
fn SetDefaultValue(&self, value: DOMString) {
|
fn SetDefaultValue(&self, value: DOMString) {
|
||||||
let node = NodeCast::from_ref(self);
|
let node = self.upcast::<Node>();
|
||||||
node.SetTextContent(Some(value));
|
node.SetTextContent(Some(value));
|
||||||
|
|
||||||
// if the element's dirty value flag is false, then the element's
|
// if the element's dirty value flag is false, then the element's
|
||||||
|
@ -218,7 +218,7 @@ impl HTMLTextAreaElement {
|
||||||
impl HTMLTextAreaElement {
|
impl HTMLTextAreaElement {
|
||||||
fn force_relayout(&self) {
|
fn force_relayout(&self) {
|
||||||
let doc = document_from_node(self);
|
let doc = document_from_node(self);
|
||||||
let node = NodeCast::from_ref(self);
|
let node = self.upcast::<Node>();
|
||||||
doc.r().content_changed(node, NodeDamage::OtherNodeDamage)
|
doc.r().content_changed(node, NodeDamage::OtherNodeDamage)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -230,14 +230,14 @@ impl HTMLTextAreaElement {
|
||||||
EventBubbles::DoesNotBubble,
|
EventBubbles::DoesNotBubble,
|
||||||
EventCancelable::NotCancelable);
|
EventCancelable::NotCancelable);
|
||||||
|
|
||||||
let target = EventTargetCast::from_ref(self);
|
let target = self.upcast::<EventTarget>();
|
||||||
target.dispatch_event(event.r());
|
target.dispatch_event(event.r());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl VirtualMethods for HTMLTextAreaElement {
|
impl VirtualMethods for HTMLTextAreaElement {
|
||||||
fn super_type(&self) -> Option<&VirtualMethods> {
|
fn super_type(&self) -> Option<&VirtualMethods> {
|
||||||
let htmlelement: &HTMLElement = HTMLElementCast::from_ref(self);
|
let htmlelement: &HTMLElement = self.upcast::<HTMLElement>();
|
||||||
Some(htmlelement as &VirtualMethods)
|
Some(htmlelement as &VirtualMethods)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -245,7 +245,7 @@ impl VirtualMethods for HTMLTextAreaElement {
|
||||||
self.super_type().unwrap().attribute_mutated(attr, mutation);
|
self.super_type().unwrap().attribute_mutated(attr, mutation);
|
||||||
match attr.local_name() {
|
match attr.local_name() {
|
||||||
&atom!(disabled) => {
|
&atom!(disabled) => {
|
||||||
let el = ElementCast::from_ref(self);
|
let el = self.upcast::<Element>();
|
||||||
match mutation {
|
match mutation {
|
||||||
AttributeMutation::Set(_) => {
|
AttributeMutation::Set(_) => {
|
||||||
el.set_disabled_state(true);
|
el.set_disabled_state(true);
|
||||||
|
@ -279,7 +279,7 @@ impl VirtualMethods for HTMLTextAreaElement {
|
||||||
s.bind_to_tree(tree_in_doc);
|
s.bind_to_tree(tree_in_doc);
|
||||||
}
|
}
|
||||||
|
|
||||||
let el = ElementCast::from_ref(self);
|
let el = self.upcast::<Element>();
|
||||||
el.check_ancestors_disabled_state_for_form_control();
|
el.check_ancestors_disabled_state_for_form_control();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -296,9 +296,9 @@ impl VirtualMethods for HTMLTextAreaElement {
|
||||||
s.unbind_from_tree(tree_in_doc);
|
s.unbind_from_tree(tree_in_doc);
|
||||||
}
|
}
|
||||||
|
|
||||||
let node = NodeCast::from_ref(self);
|
let node = self.upcast::<Node>();
|
||||||
let el = ElementCast::from_ref(self);
|
let el = self.upcast::<Element>();
|
||||||
if node.ancestors().any(|ancestor| ancestor.r().is_htmlfieldsetelement()) {
|
if node.ancestors().any(|ancestor| ancestor.r().is::<HTMLFieldSetElement>()) {
|
||||||
el.check_ancestors_disabled_state_for_form_control();
|
el.check_ancestors_disabled_state_for_form_control();
|
||||||
} else {
|
} else {
|
||||||
el.check_disabled_attribute();
|
el.check_disabled_attribute();
|
||||||
|
@ -324,9 +324,9 @@ impl VirtualMethods for HTMLTextAreaElement {
|
||||||
//TODO: set the editing position for text inputs
|
//TODO: set the editing position for text inputs
|
||||||
|
|
||||||
let doc = document_from_node(self);
|
let doc = document_from_node(self);
|
||||||
doc.r().request_focus(ElementCast::from_ref(self));
|
doc.r().request_focus(self.upcast::<Element>());
|
||||||
} else if &*event.Type() == "keydown" && !event.DefaultPrevented() {
|
} else if &*event.Type() == "keydown" && !event.DefaultPrevented() {
|
||||||
let keyevent: Option<&KeyboardEvent> = KeyboardEventCast::to_ref(event);
|
let keyevent: Option<&KeyboardEvent> = event.downcast::<KeyboardEvent>();
|
||||||
keyevent.map(|kevent| {
|
keyevent.map(|kevent| {
|
||||||
match self.textinput.borrow_mut().handle_keydown(kevent) {
|
match self.textinput.borrow_mut().handle_keydown(kevent) {
|
||||||
KeyReaction::TriggerDefaultAction => (),
|
KeyReaction::TriggerDefaultAction => (),
|
||||||
|
|
|
@ -5,9 +5,9 @@
|
||||||
use dom::bindings::codegen::Bindings::HTMLTitleElementBinding;
|
use dom::bindings::codegen::Bindings::HTMLTitleElementBinding;
|
||||||
use dom::bindings::codegen::Bindings::HTMLTitleElementBinding::HTMLTitleElementMethods;
|
use dom::bindings::codegen::Bindings::HTMLTitleElementBinding::HTMLTitleElementMethods;
|
||||||
use dom::bindings::codegen::Bindings::NodeBinding::NodeMethods;
|
use dom::bindings::codegen::Bindings::NodeBinding::NodeMethods;
|
||||||
use dom::bindings::codegen::InheritTypes::{CharacterDataCast, HTMLElementCast};
|
use dom::bindings::conversions::Castable;
|
||||||
use dom::bindings::codegen::InheritTypes::{NodeCast, TextCast};
|
|
||||||
use dom::bindings::js::Root;
|
use dom::bindings::js::Root;
|
||||||
|
use dom::characterdata::CharacterData;
|
||||||
use dom::document::Document;
|
use dom::document::Document;
|
||||||
use dom::htmlelement::HTMLElement;
|
use dom::htmlelement::HTMLElement;
|
||||||
use dom::node::{ChildrenMutation, Node};
|
use dom::node::{ChildrenMutation, Node};
|
||||||
|
@ -39,12 +39,12 @@ impl HTMLTitleElement {
|
||||||
impl HTMLTitleElementMethods for HTMLTitleElement {
|
impl HTMLTitleElementMethods for HTMLTitleElement {
|
||||||
// https://html.spec.whatwg.org/multipage/#dom-title-text
|
// https://html.spec.whatwg.org/multipage/#dom-title-text
|
||||||
fn Text(&self) -> DOMString {
|
fn Text(&self) -> DOMString {
|
||||||
let node = NodeCast::from_ref(self);
|
let node = self.upcast::<Node>();
|
||||||
let mut content = String::new();
|
let mut content = String::new();
|
||||||
for child in node.children() {
|
for child in node.children() {
|
||||||
let text: Option<&Text> = TextCast::to_ref(child.r());
|
let text: Option<&Text> = child.downcast::<Text>();
|
||||||
match text {
|
match text {
|
||||||
Some(text) => content.push_str(&CharacterDataCast::from_ref(text).data()),
|
Some(text) => content.push_str(&text.upcast::<CharacterData>().data()),
|
||||||
None => (),
|
None => (),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -53,14 +53,14 @@ impl HTMLTitleElementMethods for HTMLTitleElement {
|
||||||
|
|
||||||
// https://html.spec.whatwg.org/multipage/#dom-title-text
|
// https://html.spec.whatwg.org/multipage/#dom-title-text
|
||||||
fn SetText(&self, value: DOMString) {
|
fn SetText(&self, value: DOMString) {
|
||||||
let node = NodeCast::from_ref(self);
|
let node = self.upcast::<Node>();
|
||||||
node.SetTextContent(Some(value))
|
node.SetTextContent(Some(value))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl VirtualMethods for HTMLTitleElement {
|
impl VirtualMethods for HTMLTitleElement {
|
||||||
fn super_type(&self) -> Option<&VirtualMethods> {
|
fn super_type(&self) -> Option<&VirtualMethods> {
|
||||||
let htmlelement: &HTMLElement = HTMLElementCast::from_ref(self);
|
let htmlelement: &HTMLElement = self.upcast::<HTMLElement>();
|
||||||
Some(htmlelement as &VirtualMethods)
|
Some(htmlelement as &VirtualMethods)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -68,14 +68,14 @@ impl VirtualMethods for HTMLTitleElement {
|
||||||
if let Some(ref s) = self.super_type() {
|
if let Some(ref s) = self.super_type() {
|
||||||
s.children_changed(mutation);
|
s.children_changed(mutation);
|
||||||
}
|
}
|
||||||
let node = NodeCast::from_ref(self);
|
let node = self.upcast::<Node>();
|
||||||
if node.is_in_doc() {
|
if node.is_in_doc() {
|
||||||
node.owner_doc().title_changed();
|
node.owner_doc().title_changed();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn bind_to_tree(&self, is_in_doc: bool) {
|
fn bind_to_tree(&self, is_in_doc: bool) {
|
||||||
let node = NodeCast::from_ref(self);
|
let node = self.upcast::<Node>();
|
||||||
if is_in_doc {
|
if is_in_doc {
|
||||||
let document = node.owner_doc();
|
let document = node.owner_doc();
|
||||||
document.r().title_changed();
|
document.r().title_changed();
|
||||||
|
|
|
@ -5,11 +5,12 @@
|
||||||
use dom::bindings::codegen::Bindings::KeyboardEventBinding;
|
use dom::bindings::codegen::Bindings::KeyboardEventBinding;
|
||||||
use dom::bindings::codegen::Bindings::KeyboardEventBinding::{KeyboardEventConstants, KeyboardEventMethods};
|
use dom::bindings::codegen::Bindings::KeyboardEventBinding::{KeyboardEventConstants, KeyboardEventMethods};
|
||||||
use dom::bindings::codegen::Bindings::UIEventBinding::UIEventMethods;
|
use dom::bindings::codegen::Bindings::UIEventBinding::UIEventMethods;
|
||||||
use dom::bindings::codegen::InheritTypes::{EventCast, UIEventCast};
|
use dom::bindings::conversions::Castable;
|
||||||
use dom::bindings::error::Fallible;
|
use dom::bindings::error::Fallible;
|
||||||
use dom::bindings::global::GlobalRef;
|
use dom::bindings::global::GlobalRef;
|
||||||
use dom::bindings::js::{Root, RootedReference};
|
use dom::bindings::js::{Root, RootedReference};
|
||||||
use dom::bindings::utils::{Reflectable, reflect_dom_object};
|
use dom::bindings::utils::{Reflectable, reflect_dom_object};
|
||||||
|
use dom::event::Event;
|
||||||
use dom::uievent::UIEvent;
|
use dom::uievent::UIEvent;
|
||||||
use dom::window::Window;
|
use dom::window::Window;
|
||||||
use msg::constellation_msg;
|
use msg::constellation_msg;
|
||||||
|
@ -761,12 +762,12 @@ impl KeyboardEventMethods for KeyboardEvent {
|
||||||
_modifiersListArg: DOMString,
|
_modifiersListArg: DOMString,
|
||||||
repeat: bool,
|
repeat: bool,
|
||||||
_locale: DOMString) {
|
_locale: DOMString) {
|
||||||
let event = EventCast::from_ref(self);
|
let event = self.upcast::<Event>();
|
||||||
if event.dispatching() {
|
if event.dispatching() {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
let uievent = UIEventCast::from_ref(self);
|
let uievent = self.upcast::<UIEvent>();
|
||||||
uievent.InitUIEvent(typeArg, canBubbleArg, cancelableArg, viewArg, 0);
|
uievent.InitUIEvent(typeArg, canBubbleArg, cancelableArg, viewArg, 0);
|
||||||
*self.key_string.borrow_mut() = keyArg;
|
*self.key_string.borrow_mut() = keyArg;
|
||||||
self.location.set(locationArg);
|
self.location.set(locationArg);
|
||||||
|
|
|
@ -6,9 +6,10 @@
|
||||||
macro_rules! make_getter(
|
macro_rules! make_getter(
|
||||||
( $attr:ident, $htmlname:expr ) => (
|
( $attr:ident, $htmlname:expr ) => (
|
||||||
fn $attr(&self) -> DOMString {
|
fn $attr(&self) -> DOMString {
|
||||||
use dom::bindings::codegen::InheritTypes::ElementCast;
|
use dom::bindings::conversions::Castable;
|
||||||
|
use dom::element::Element;
|
||||||
use string_cache::Atom;
|
use string_cache::Atom;
|
||||||
let element = ElementCast::from_ref(self);
|
let element = self.upcast::<Element>();
|
||||||
element.get_string_attribute(&Atom::from_slice($htmlname))
|
element.get_string_attribute(&Atom::from_slice($htmlname))
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
@ -21,9 +22,10 @@ macro_rules! make_getter(
|
||||||
macro_rules! make_bool_getter(
|
macro_rules! make_bool_getter(
|
||||||
( $attr:ident, $htmlname:expr ) => (
|
( $attr:ident, $htmlname:expr ) => (
|
||||||
fn $attr(&self) -> bool {
|
fn $attr(&self) -> bool {
|
||||||
use dom::bindings::codegen::InheritTypes::ElementCast;
|
use dom::bindings::conversions::Castable;
|
||||||
|
use dom::element::Element;
|
||||||
use string_cache::Atom;
|
use string_cache::Atom;
|
||||||
let element = ElementCast::from_ref(self);
|
let element = self.upcast::<Element>();
|
||||||
// FIXME(pcwalton): Do this at compile time, not runtime.
|
// FIXME(pcwalton): Do this at compile time, not runtime.
|
||||||
element.has_attribute(&Atom::from_slice($htmlname))
|
element.has_attribute(&Atom::from_slice($htmlname))
|
||||||
}
|
}
|
||||||
|
@ -37,9 +39,10 @@ macro_rules! make_bool_getter(
|
||||||
macro_rules! make_uint_getter(
|
macro_rules! make_uint_getter(
|
||||||
($attr:ident, $htmlname:expr, $default:expr) => (
|
($attr:ident, $htmlname:expr, $default:expr) => (
|
||||||
fn $attr(&self) -> u32 {
|
fn $attr(&self) -> u32 {
|
||||||
use dom::bindings::codegen::InheritTypes::ElementCast;
|
use dom::bindings::conversions::Castable;
|
||||||
|
use dom::element::Element;
|
||||||
use string_cache::Atom;
|
use string_cache::Atom;
|
||||||
let element = ElementCast::from_ref(self);
|
let element = self.upcast::<Element>();
|
||||||
// FIXME(pcwalton): Do this at compile time, not runtime.
|
// FIXME(pcwalton): Do this at compile time, not runtime.
|
||||||
element.get_uint_attribute(&Atom::from_slice($htmlname), $default)
|
element.get_uint_attribute(&Atom::from_slice($htmlname), $default)
|
||||||
}
|
}
|
||||||
|
@ -56,9 +59,10 @@ macro_rules! make_uint_getter(
|
||||||
macro_rules! make_url_getter(
|
macro_rules! make_url_getter(
|
||||||
( $attr:ident, $htmlname:expr ) => (
|
( $attr:ident, $htmlname:expr ) => (
|
||||||
fn $attr(&self) -> DOMString {
|
fn $attr(&self) -> DOMString {
|
||||||
use dom::bindings::codegen::InheritTypes::ElementCast;
|
use dom::bindings::conversions::Castable;
|
||||||
|
use dom::element::Element;
|
||||||
use string_cache::Atom;
|
use string_cache::Atom;
|
||||||
let element = ElementCast::from_ref(self);
|
let element = self.upcast::<Element>();
|
||||||
// FIXME(pcwalton): Do this at compile time, not runtime.
|
// FIXME(pcwalton): Do this at compile time, not runtime.
|
||||||
element.get_url_attribute(&Atom::from_slice($htmlname))
|
element.get_url_attribute(&Atom::from_slice($htmlname))
|
||||||
}
|
}
|
||||||
|
@ -73,9 +77,10 @@ macro_rules! make_url_getter(
|
||||||
macro_rules! make_url_or_base_getter(
|
macro_rules! make_url_or_base_getter(
|
||||||
( $attr:ident, $htmlname:expr ) => (
|
( $attr:ident, $htmlname:expr ) => (
|
||||||
fn $attr(&self) -> DOMString {
|
fn $attr(&self) -> DOMString {
|
||||||
use dom::bindings::codegen::InheritTypes::ElementCast;
|
use dom::bindings::conversions::Castable;
|
||||||
|
use dom::element::Element;
|
||||||
use string_cache::Atom;
|
use string_cache::Atom;
|
||||||
let element = ElementCast::from_ref(self);
|
let element = self.upcast::<Element>();
|
||||||
let url = element.get_url_attribute(&Atom::from_slice($htmlname));
|
let url = element.get_url_attribute(&Atom::from_slice($htmlname));
|
||||||
if url.is_empty() {
|
if url.is_empty() {
|
||||||
let window = window_from_node(self);
|
let window = window_from_node(self);
|
||||||
|
@ -94,11 +99,12 @@ macro_rules! make_url_or_base_getter(
|
||||||
macro_rules! make_enumerated_getter(
|
macro_rules! make_enumerated_getter(
|
||||||
( $attr:ident, $htmlname:expr, $default:expr, $(($choices: pat))|+) => (
|
( $attr:ident, $htmlname:expr, $default:expr, $(($choices: pat))|+) => (
|
||||||
fn $attr(&self) -> DOMString {
|
fn $attr(&self) -> DOMString {
|
||||||
use dom::bindings::codegen::InheritTypes::ElementCast;
|
use dom::bindings::conversions::Castable;
|
||||||
|
use dom::element::Element;
|
||||||
use std::ascii::AsciiExt;
|
use std::ascii::AsciiExt;
|
||||||
use std::borrow::ToOwned;
|
use std::borrow::ToOwned;
|
||||||
use string_cache::Atom;
|
use string_cache::Atom;
|
||||||
let element = ElementCast::from_ref(self);
|
let element = self.upcast::<Element>();
|
||||||
let mut val = element.get_string_attribute(&Atom::from_slice($htmlname));
|
let mut val = element.get_string_attribute(&Atom::from_slice($htmlname));
|
||||||
val.make_ascii_lowercase();
|
val.make_ascii_lowercase();
|
||||||
// https://html.spec.whatwg.org/multipage/#attr-fs-method
|
// https://html.spec.whatwg.org/multipage/#attr-fs-method
|
||||||
|
@ -119,9 +125,10 @@ macro_rules! make_enumerated_getter(
|
||||||
macro_rules! make_setter(
|
macro_rules! make_setter(
|
||||||
( $attr:ident, $htmlname:expr ) => (
|
( $attr:ident, $htmlname:expr ) => (
|
||||||
fn $attr(&self, value: DOMString) {
|
fn $attr(&self, value: DOMString) {
|
||||||
use dom::bindings::codegen::InheritTypes::ElementCast;
|
use dom::bindings::conversions::Castable;
|
||||||
|
use dom::element::Element;
|
||||||
use string_cache::Atom;
|
use string_cache::Atom;
|
||||||
let element = ElementCast::from_ref(self);
|
let element = self.upcast::<Element>();
|
||||||
// FIXME(pcwalton): Do this at compile time, not at runtime.
|
// FIXME(pcwalton): Do this at compile time, not at runtime.
|
||||||
element.set_string_attribute(&Atom::from_slice($htmlname), value)
|
element.set_string_attribute(&Atom::from_slice($htmlname), value)
|
||||||
}
|
}
|
||||||
|
@ -132,9 +139,10 @@ macro_rules! make_setter(
|
||||||
macro_rules! make_bool_setter(
|
macro_rules! make_bool_setter(
|
||||||
( $attr:ident, $htmlname:expr ) => (
|
( $attr:ident, $htmlname:expr ) => (
|
||||||
fn $attr(&self, value: bool) {
|
fn $attr(&self, value: bool) {
|
||||||
use dom::bindings::codegen::InheritTypes::ElementCast;
|
use dom::bindings::conversions::Castable;
|
||||||
|
use dom::element::Element;
|
||||||
use string_cache::Atom;
|
use string_cache::Atom;
|
||||||
let element = ElementCast::from_ref(self);
|
let element = self.upcast::<Element>();
|
||||||
// FIXME(pcwalton): Do this at compile time, not at runtime.
|
// FIXME(pcwalton): Do this at compile time, not at runtime.
|
||||||
element.set_bool_attribute(&Atom::from_slice($htmlname), value)
|
element.set_bool_attribute(&Atom::from_slice($htmlname), value)
|
||||||
}
|
}
|
||||||
|
@ -145,7 +153,8 @@ macro_rules! make_bool_setter(
|
||||||
macro_rules! make_uint_setter(
|
macro_rules! make_uint_setter(
|
||||||
($attr:ident, $htmlname:expr, $default:expr) => (
|
($attr:ident, $htmlname:expr, $default:expr) => (
|
||||||
fn $attr(&self, value: u32) {
|
fn $attr(&self, value: u32) {
|
||||||
use dom::bindings::codegen::InheritTypes::ElementCast;
|
use dom::bindings::conversions::Castable;
|
||||||
|
use dom::element::Element;
|
||||||
use dom::values::UNSIGNED_LONG_MAX;
|
use dom::values::UNSIGNED_LONG_MAX;
|
||||||
use string_cache::Atom;
|
use string_cache::Atom;
|
||||||
let value = if value > UNSIGNED_LONG_MAX {
|
let value = if value > UNSIGNED_LONG_MAX {
|
||||||
|
@ -153,7 +162,7 @@ macro_rules! make_uint_setter(
|
||||||
} else {
|
} else {
|
||||||
value
|
value
|
||||||
};
|
};
|
||||||
let element = ElementCast::from_ref(self);
|
let element = self.upcast::<Element>();
|
||||||
// FIXME(pcwalton): Do this at compile time, not at runtime.
|
// FIXME(pcwalton): Do this at compile time, not at runtime.
|
||||||
element.set_uint_attribute(&Atom::from_slice($htmlname), value)
|
element.set_uint_attribute(&Atom::from_slice($htmlname), value)
|
||||||
}
|
}
|
||||||
|
@ -167,7 +176,8 @@ macro_rules! make_uint_setter(
|
||||||
macro_rules! make_limited_uint_setter(
|
macro_rules! make_limited_uint_setter(
|
||||||
($attr:ident, $htmlname:expr, $default:expr) => (
|
($attr:ident, $htmlname:expr, $default:expr) => (
|
||||||
fn $attr(&self, value: u32) -> $crate::dom::bindings::error::ErrorResult {
|
fn $attr(&self, value: u32) -> $crate::dom::bindings::error::ErrorResult {
|
||||||
use dom::bindings::codegen::InheritTypes::ElementCast;
|
use dom::bindings::conversions::Castable;
|
||||||
|
use dom::element::Element;
|
||||||
use dom::values::UNSIGNED_LONG_MAX;
|
use dom::values::UNSIGNED_LONG_MAX;
|
||||||
use string_cache::Atom;
|
use string_cache::Atom;
|
||||||
let value = if value == 0 {
|
let value = if value == 0 {
|
||||||
|
@ -177,7 +187,7 @@ macro_rules! make_limited_uint_setter(
|
||||||
} else {
|
} else {
|
||||||
value
|
value
|
||||||
};
|
};
|
||||||
let element = ElementCast::from_ref(self);
|
let element = self.upcast::<Element>();
|
||||||
// FIXME(pcwalton): Do this at compile time, not runtime.
|
// FIXME(pcwalton): Do this at compile time, not runtime.
|
||||||
element.set_uint_attribute(&Atom::from_slice($htmlname), value);
|
element.set_uint_attribute(&Atom::from_slice($htmlname), value);
|
||||||
Ok(())
|
Ok(())
|
||||||
|
@ -195,9 +205,10 @@ macro_rules! make_limited_uint_setter(
|
||||||
macro_rules! make_atomic_setter(
|
macro_rules! make_atomic_setter(
|
||||||
( $attr:ident, $htmlname:expr ) => (
|
( $attr:ident, $htmlname:expr ) => (
|
||||||
fn $attr(&self, value: DOMString) {
|
fn $attr(&self, value: DOMString) {
|
||||||
use dom::bindings::codegen::InheritTypes::ElementCast;
|
use dom::bindings::conversions::Castable;
|
||||||
|
use dom::element::Element;
|
||||||
use string_cache::Atom;
|
use string_cache::Atom;
|
||||||
let element = ElementCast::from_ref(self);
|
let element = self.upcast::<Element>();
|
||||||
// FIXME(pcwalton): Do this at compile time, not at runtime.
|
// FIXME(pcwalton): Do this at compile time, not at runtime.
|
||||||
element.set_atomic_attribute(&Atom::from_slice($htmlname), value)
|
element.set_atomic_attribute(&Atom::from_slice($htmlname), value)
|
||||||
}
|
}
|
||||||
|
@ -239,12 +250,16 @@ macro_rules! no_jsmanaged_fields(
|
||||||
macro_rules! define_event_handler(
|
macro_rules! define_event_handler(
|
||||||
($handler: ident, $event_type: ident, $getter: ident, $setter: ident) => (
|
($handler: ident, $event_type: ident, $getter: ident, $setter: ident) => (
|
||||||
fn $getter(&self) -> Option<::std::rc::Rc<$handler>> {
|
fn $getter(&self) -> Option<::std::rc::Rc<$handler>> {
|
||||||
let eventtarget = EventTargetCast::from_ref(self);
|
use dom::bindings::conversions::Castable;
|
||||||
|
use dom::eventtarget::EventTarget;
|
||||||
|
let eventtarget = self.upcast::<EventTarget>();
|
||||||
eventtarget.get_event_handler_common(stringify!($event_type))
|
eventtarget.get_event_handler_common(stringify!($event_type))
|
||||||
}
|
}
|
||||||
|
|
||||||
fn $setter(&self, listener: Option<::std::rc::Rc<$handler>>) {
|
fn $setter(&self, listener: Option<::std::rc::Rc<$handler>>) {
|
||||||
let eventtarget = EventTargetCast::from_ref(self);
|
use dom::bindings::conversions::Castable;
|
||||||
|
use dom::eventtarget::EventTarget;
|
||||||
|
let eventtarget = self.upcast::<EventTarget>();
|
||||||
eventtarget.set_event_handler_common(stringify!($event_type), listener)
|
eventtarget.set_event_handler_common(stringify!($event_type), listener)
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
|
@ -5,7 +5,7 @@
|
||||||
use dom::bindings::codegen::Bindings::EventBinding::EventMethods;
|
use dom::bindings::codegen::Bindings::EventBinding::EventMethods;
|
||||||
use dom::bindings::codegen::Bindings::MessageEventBinding;
|
use dom::bindings::codegen::Bindings::MessageEventBinding;
|
||||||
use dom::bindings::codegen::Bindings::MessageEventBinding::MessageEventMethods;
|
use dom::bindings::codegen::Bindings::MessageEventBinding::MessageEventMethods;
|
||||||
use dom::bindings::codegen::InheritTypes::EventCast;
|
use dom::bindings::conversions::Castable;
|
||||||
use dom::bindings::error::Fallible;
|
use dom::bindings::error::Fallible;
|
||||||
use dom::bindings::global::GlobalRef;
|
use dom::bindings::global::GlobalRef;
|
||||||
use dom::bindings::js::Root;
|
use dom::bindings::js::Root;
|
||||||
|
@ -51,7 +51,7 @@ impl MessageEvent {
|
||||||
-> Root<MessageEvent> {
|
-> Root<MessageEvent> {
|
||||||
let ev = MessageEvent::new_initialized(global, data, origin, lastEventId);
|
let ev = MessageEvent::new_initialized(global, data, origin, lastEventId);
|
||||||
{
|
{
|
||||||
let event = EventCast::from_ref(ev.r());
|
let event = ev.upcast::<Event>();
|
||||||
event.InitEvent(type_, bubbles, cancelable);
|
event.InitEvent(type_, bubbles, cancelable);
|
||||||
}
|
}
|
||||||
ev
|
ev
|
||||||
|
@ -78,7 +78,7 @@ impl MessageEvent {
|
||||||
let messageevent = MessageEvent::new(
|
let messageevent = MessageEvent::new(
|
||||||
scope, "message".to_owned(), false, false, message,
|
scope, "message".to_owned(), false, false, message,
|
||||||
"".to_owned(), "".to_owned());
|
"".to_owned(), "".to_owned());
|
||||||
let event = EventCast::from_ref(messageevent.r());
|
let event = messageevent.upcast::<Event>();
|
||||||
event.fire(target);
|
event.fire(target);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -151,8 +151,8 @@
|
||||||
//! # use script::dom::node::Node;
|
//! # use script::dom::node::Node;
|
||||||
//! # use script::dom::htmlelement::HTMLElement;
|
//! # use script::dom::htmlelement::HTMLElement;
|
||||||
//! fn f(element: &Element) {
|
//! fn f(element: &Element) {
|
||||||
//! let base: &Node = NodeCast::from_ref(element);
|
//! let base: &Node = element.upcast::<Node>();
|
||||||
//! let derived: Option<&HTMLElement> = HTMLElementCast::to_ref(element);
|
//! let derived: Option<&HTMLElement> = element.downcast::<HTMLElement>();
|
||||||
//! }
|
//! }
|
||||||
//! ```
|
//! ```
|
||||||
//!
|
//!
|
||||||
|
|
|
@ -5,7 +5,7 @@
|
||||||
use dom::bindings::codegen::Bindings::MouseEventBinding;
|
use dom::bindings::codegen::Bindings::MouseEventBinding;
|
||||||
use dom::bindings::codegen::Bindings::MouseEventBinding::MouseEventMethods;
|
use dom::bindings::codegen::Bindings::MouseEventBinding::MouseEventMethods;
|
||||||
use dom::bindings::codegen::Bindings::UIEventBinding::UIEventMethods;
|
use dom::bindings::codegen::Bindings::UIEventBinding::UIEventMethods;
|
||||||
use dom::bindings::codegen::InheritTypes::{EventCast, UIEventCast};
|
use dom::bindings::conversions::Castable;
|
||||||
use dom::bindings::error::Fallible;
|
use dom::bindings::error::Fallible;
|
||||||
use dom::bindings::global::GlobalRef;
|
use dom::bindings::global::GlobalRef;
|
||||||
use dom::bindings::js::{JS, MutNullableHeap, Root, RootedReference};
|
use dom::bindings::js::{JS, MutNullableHeap, Root, RootedReference};
|
||||||
|
@ -189,12 +189,12 @@ impl MouseEventMethods for MouseEvent {
|
||||||
metaKeyArg: bool,
|
metaKeyArg: bool,
|
||||||
buttonArg: i16,
|
buttonArg: i16,
|
||||||
relatedTargetArg: Option<&EventTarget>) {
|
relatedTargetArg: Option<&EventTarget>) {
|
||||||
let event: &Event = EventCast::from_ref(self);
|
let event: &Event = self.upcast::<Event>();
|
||||||
if event.dispatching() {
|
if event.dispatching() {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
let uievent: &UIEvent = UIEventCast::from_ref(self);
|
let uievent: &UIEvent = self.upcast::<UIEvent>();
|
||||||
uievent.InitUIEvent(typeArg, canBubbleArg, cancelableArg, viewArg, detailArg);
|
uievent.InitUIEvent(typeArg, canBubbleArg, cancelableArg, viewArg, detailArg);
|
||||||
self.screen_x.set(screenXArg);
|
self.screen_x.set(screenXArg);
|
||||||
self.screen_y.set(screenYArg);
|
self.screen_y.set(screenYArg);
|
||||||
|
|
|
@ -19,17 +19,10 @@ use dom::bindings::codegen::Bindings::NamedNodeMapBinding::NamedNodeMapMethods;
|
||||||
use dom::bindings::codegen::Bindings::NodeBinding::{NodeConstants, NodeMethods};
|
use dom::bindings::codegen::Bindings::NodeBinding::{NodeConstants, NodeMethods};
|
||||||
use dom::bindings::codegen::Bindings::NodeListBinding::NodeListMethods;
|
use dom::bindings::codegen::Bindings::NodeListBinding::NodeListMethods;
|
||||||
use dom::bindings::codegen::Bindings::ProcessingInstructionBinding::ProcessingInstructionMethods;
|
use dom::bindings::codegen::Bindings::ProcessingInstructionBinding::ProcessingInstructionMethods;
|
||||||
use dom::bindings::codegen::InheritTypes::HTMLElementBase;
|
use dom::bindings::codegen::InheritTypes::{CharacterDataTypeId, ElementTypeId, EventTargetTypeId};
|
||||||
use dom::bindings::codegen::InheritTypes::HTMLElementCast;
|
use dom::bindings::codegen::InheritTypes::{HTMLElementTypeId, NodeTypeId};
|
||||||
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::UnionTypes::NodeOrString;
|
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::error::{Error, ErrorResult, Fallible};
|
||||||
use dom::bindings::global::GlobalRef;
|
use dom::bindings::global::GlobalRef;
|
||||||
use dom::bindings::js::Root;
|
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
|
// TODO(cgaebel): Is it worth it to build a bloom filter here
|
||||||
// (instead of passing `None`)? Probably.
|
// (instead of passing `None`)? Probably.
|
||||||
self.iterator.by_ref().filter_map(|node| {
|
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) {
|
if matches(selectors, &element, None) {
|
||||||
return Some(NodeCast::from_root(element))
|
return Some(Root::upcast::<Node>(element))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
None
|
None
|
||||||
|
@ -424,7 +417,7 @@ impl Node {
|
||||||
match self.type_id() {
|
match self.type_id() {
|
||||||
NodeTypeId::DocumentType => 0,
|
NodeTypeId::DocumentType => 0,
|
||||||
NodeTypeId::CharacterData(_) => {
|
NodeTypeId::CharacterData(_) => {
|
||||||
CharacterDataCast::to_ref(self).unwrap().Length()
|
self.downcast::<CharacterData>().unwrap().Length()
|
||||||
},
|
},
|
||||||
_ => self.children_count(),
|
_ => self.children_count(),
|
||||||
}
|
}
|
||||||
|
@ -725,7 +718,7 @@ impl Node {
|
||||||
Err(()) => Err(Error::Syntax),
|
Err(()) => Err(Error::Syntax),
|
||||||
// Step 3.
|
// Step 3.
|
||||||
Ok(ref selectors) => {
|
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)
|
matches(selectors, element, None)
|
||||||
}))
|
}))
|
||||||
}
|
}
|
||||||
|
@ -795,7 +788,7 @@ impl Node {
|
||||||
|
|
||||||
pub fn child_elements(&self) -> ChildElementIterator {
|
pub fn child_elements(&self) -> ChildElementIterator {
|
||||||
fn to_temporary(node: Root<Node>) -> Option<Root<Element>> {
|
fn to_temporary(node: Root<Node>) -> Option<Root<Element>> {
|
||||||
ElementCast::to_root(node)
|
Root::downcast::<Element>(node)
|
||||||
}
|
}
|
||||||
self.children()
|
self.children()
|
||||||
.filter_map(to_temporary as fn(_) -> _)
|
.filter_map(to_temporary as fn(_) -> _)
|
||||||
|
@ -832,7 +825,7 @@ impl Node {
|
||||||
systemId: "".to_owned(),
|
systemId: "".to_owned(),
|
||||||
|
|
||||||
attrs: {
|
attrs: {
|
||||||
let e: Option<&Element> = ElementCast::to_ref(self);
|
let e: Option<&Element> = self.downcast::<Element>();
|
||||||
match e {
|
match e {
|
||||||
Some(element) => element.summarize(),
|
Some(element) => element.summarize(),
|
||||||
None => vec!(),
|
None => vec!(),
|
||||||
|
@ -843,7 +836,7 @@ impl Node {
|
||||||
self.owner_doc()
|
self.owner_doc()
|
||||||
.r()
|
.r()
|
||||||
.GetDocumentElement()
|
.GetDocumentElement()
|
||||||
.map(|elem| NodeCast::from_ref(elem.r()) == self)
|
.map(|elem| elem.upcast::<Node>() == self)
|
||||||
.unwrap_or(false),
|
.unwrap_or(false),
|
||||||
|
|
||||||
shortValue: self.GetNodeValue().unwrap_or("".to_owned()), //FIXME: truncate
|
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
|
// 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>> {
|
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 context_document = document_from_node(self);
|
||||||
let fragment = DocumentFragment::new(context_document.r());
|
let fragment = DocumentFragment::new(context_document.r());
|
||||||
if context_document.r().is_html_document() {
|
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);
|
parse_html_fragment(context_node, markup, fragment_node);
|
||||||
} else {
|
} else {
|
||||||
// FIXME: XML case
|
// 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>>
|
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>,
|
where F: Fn() -> Root<HTMLCollection>,
|
||||||
G: Fn() -> Root<I>,
|
G: Fn() -> Root<I>,
|
||||||
I: NodeBase + HTMLElementBase + Reflectable,
|
I: DerivedFrom<Node> + DerivedFrom<HTMLElement> + Reflectable,
|
||||||
{
|
{
|
||||||
if index < -1 {
|
if index < -1 {
|
||||||
return Err(Error::IndexSize);
|
return Err(Error::IndexSize);
|
||||||
|
@ -882,7 +875,7 @@ impl Node {
|
||||||
None
|
None
|
||||||
} else {
|
} else {
|
||||||
match get_items().elements_iter()
|
match get_items().elements_iter()
|
||||||
.map(NodeCast::from_root)
|
.map(Root::upcast::<Node>)
|
||||||
.map(Some)
|
.map(Some)
|
||||||
.chain(iter::once(None))
|
.chain(iter::once(None))
|
||||||
.nth(index as usize) {
|
.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()));
|
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`
|
/// Used by `HTMLTableSectionElement::DeleteRow` and `HTMLTableRowElement::DeleteCell`
|
||||||
|
@ -907,9 +900,9 @@ impl Node {
|
||||||
let element = match index {
|
let element = match index {
|
||||||
index if index < -1 => return Err(Error::IndexSize),
|
index if index < -1 => return Err(Error::IndexSize),
|
||||||
-1 => {
|
-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()
|
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))
|
.filter(|elem| is_delete_type(elem))
|
||||||
.next()) {
|
.next()) {
|
||||||
Some(element) => element,
|
Some(element) => element,
|
||||||
|
@ -922,7 +915,7 @@ impl Node {
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
NodeCast::from_ref(element.r()).remove_self();
|
element.upcast::<Node>().remove_self();
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -994,7 +987,7 @@ impl LayoutNodeHelpers for LayoutJS<Node> {
|
||||||
#[inline]
|
#[inline]
|
||||||
#[allow(unsafe_code)]
|
#[allow(unsafe_code)]
|
||||||
unsafe fn is_element_for_layout(&self) -> bool {
|
unsafe fn is_element_for_layout(&self) -> bool {
|
||||||
(*self.unsafe_get()).is_element()
|
(*self.unsafe_get()).is::<Element>()
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
|
@ -1300,7 +1293,7 @@ pub enum CloneChildrenFlag {
|
||||||
fn as_uintptr<T>(t: &T) -> uintptr_t { t as *const T as uintptr_t }
|
fn as_uintptr<T>(t: &T) -> uintptr_t { t as *const T as uintptr_t }
|
||||||
|
|
||||||
impl Node {
|
impl Node {
|
||||||
pub fn reflect_node<N: Reflectable + NodeBase>
|
pub fn reflect_node<N: DerivedFrom<Node> + Reflectable>
|
||||||
(node: Box<N>,
|
(node: Box<N>,
|
||||||
document: &Document,
|
document: &Document,
|
||||||
wrap_fn: extern "Rust" fn(*mut JSContext, GlobalRef, Box<N>) -> Root<N>)
|
wrap_fn: extern "Rust" fn(*mut JSContext, GlobalRef, Box<N>) -> Root<N>)
|
||||||
|
@ -1384,12 +1377,12 @@ impl Node {
|
||||||
// Step 4-5.
|
// Step 4-5.
|
||||||
match node.type_id() {
|
match node.type_id() {
|
||||||
NodeTypeId::CharacterData(CharacterDataTypeId::Text) => {
|
NodeTypeId::CharacterData(CharacterDataTypeId::Text) => {
|
||||||
if parent.is_document() {
|
if parent.is::<Document>() {
|
||||||
return Err(Error::HierarchyRequest);
|
return Err(Error::HierarchyRequest);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
NodeTypeId::DocumentType => {
|
NodeTypeId::DocumentType => {
|
||||||
if !parent.is_document() {
|
if !parent.is::<Document>() {
|
||||||
return Err(Error::HierarchyRequest);
|
return Err(Error::HierarchyRequest);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
@ -1407,7 +1400,7 @@ impl Node {
|
||||||
NodeTypeId::DocumentFragment => {
|
NodeTypeId::DocumentFragment => {
|
||||||
// Step 6.1.1(b)
|
// Step 6.1.1(b)
|
||||||
if node.children()
|
if node.children()
|
||||||
.any(|c| c.r().is_text())
|
.any(|c| c.r().is::<Text>())
|
||||||
{
|
{
|
||||||
return Err(Error::HierarchyRequest);
|
return Err(Error::HierarchyRequest);
|
||||||
}
|
}
|
||||||
|
@ -1452,7 +1445,7 @@ impl Node {
|
||||||
Some(child) => {
|
Some(child) => {
|
||||||
if parent.children()
|
if parent.children()
|
||||||
.take_while(|c| c.r() != child)
|
.take_while(|c| c.r() != child)
|
||||||
.any(|c| c.r().is_element())
|
.any(|c| c.r().is::<Element>())
|
||||||
{
|
{
|
||||||
return Err(Error::HierarchyRequest);
|
return Err(Error::HierarchyRequest);
|
||||||
}
|
}
|
||||||
|
@ -1626,23 +1619,23 @@ impl Node {
|
||||||
// XXXabinader: clone() for each node as trait?
|
// XXXabinader: clone() for each node as trait?
|
||||||
let copy: Root<Node> = match node.type_id() {
|
let copy: Root<Node> = match node.type_id() {
|
||||||
NodeTypeId::DocumentType => {
|
NodeTypeId::DocumentType => {
|
||||||
let doctype: &DocumentType = DocumentTypeCast::to_ref(node).unwrap();
|
let doctype: &DocumentType = node.downcast::<DocumentType>().unwrap();
|
||||||
let doctype = DocumentType::new(doctype.name().clone(),
|
let doctype = DocumentType::new(doctype.name().clone(),
|
||||||
Some(doctype.public_id().clone()),
|
Some(doctype.public_id().clone()),
|
||||||
Some(doctype.system_id().clone()), document.r());
|
Some(doctype.system_id().clone()), document.r());
|
||||||
NodeCast::from_root(doctype)
|
Root::upcast::<Node>(doctype)
|
||||||
},
|
},
|
||||||
NodeTypeId::DocumentFragment => {
|
NodeTypeId::DocumentFragment => {
|
||||||
let doc_fragment = DocumentFragment::new(document.r());
|
let doc_fragment = DocumentFragment::new(document.r());
|
||||||
NodeCast::from_root(doc_fragment)
|
Root::upcast::<Node>(doc_fragment)
|
||||||
},
|
},
|
||||||
NodeTypeId::CharacterData(CharacterDataTypeId::Comment) => {
|
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());
|
let comment = Comment::new(cdata.Data(), document.r());
|
||||||
NodeCast::from_root(comment)
|
Root::upcast::<Node>(comment)
|
||||||
},
|
},
|
||||||
NodeTypeId::Document => {
|
NodeTypeId::Document => {
|
||||||
let document = DocumentCast::to_ref(node).unwrap();
|
let document = node.downcast::<Document>().unwrap();
|
||||||
let is_html_doc = match document.is_html_document() {
|
let is_html_doc = match document.is_html_document() {
|
||||||
true => IsHTMLDocument::HTMLDocument,
|
true => IsHTMLDocument::HTMLDocument,
|
||||||
false => IsHTMLDocument::NonHTMLDocument,
|
false => IsHTMLDocument::NonHTMLDocument,
|
||||||
|
@ -1652,10 +1645,10 @@ impl Node {
|
||||||
let document = Document::new(window, Some((*document.url()).clone()),
|
let document = Document::new(window, Some((*document.url()).clone()),
|
||||||
is_html_doc, None,
|
is_html_doc, None,
|
||||||
None, DocumentSource::NotFromParser, loader);
|
None, DocumentSource::NotFromParser, loader);
|
||||||
NodeCast::from_root(document)
|
Root::upcast::<Node>(document)
|
||||||
},
|
},
|
||||||
NodeTypeId::Element(..) => {
|
NodeTypeId::Element(..) => {
|
||||||
let element = ElementCast::to_ref(node).unwrap();
|
let element = node.downcast::<Element>().unwrap();
|
||||||
let name = QualName {
|
let name = QualName {
|
||||||
ns: element.namespace().clone(),
|
ns: element.namespace().clone(),
|
||||||
local: element.local_name().clone()
|
local: element.local_name().clone()
|
||||||
|
@ -1663,23 +1656,23 @@ impl Node {
|
||||||
let element = Element::create(name,
|
let element = Element::create(name,
|
||||||
element.prefix().as_ref().map(|p| Atom::from_slice(&p)),
|
element.prefix().as_ref().map(|p| Atom::from_slice(&p)),
|
||||||
document.r(), ElementCreator::ScriptCreated);
|
document.r(), ElementCreator::ScriptCreated);
|
||||||
NodeCast::from_root(element)
|
Root::upcast::<Node>(element)
|
||||||
},
|
},
|
||||||
NodeTypeId::CharacterData(CharacterDataTypeId::Text) => {
|
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());
|
let text = Text::new(cdata.Data(), document.r());
|
||||||
NodeCast::from_root(text)
|
Root::upcast::<Node>(text)
|
||||||
},
|
},
|
||||||
NodeTypeId::CharacterData(CharacterDataTypeId::ProcessingInstruction) => {
|
NodeTypeId::CharacterData(CharacterDataTypeId::ProcessingInstruction) => {
|
||||||
let pi = ProcessingInstructionCast::to_ref(node).unwrap();
|
let pi = node.downcast::<ProcessingInstruction>().unwrap();
|
||||||
let pi = ProcessingInstruction::new(pi.Target(),
|
let pi = ProcessingInstruction::new(pi.Target(),
|
||||||
CharacterDataCast::from_ref(pi).Data(), document.r());
|
pi.upcast::<CharacterData>().Data(), document.r());
|
||||||
NodeCast::from_root(pi)
|
Root::upcast::<Node>(pi)
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
// Step 3.
|
// Step 3.
|
||||||
let document = match DocumentCast::to_ref(copy.r()) {
|
let document = match copy.downcast::<Document>() {
|
||||||
Some(doc) => Root::from_ref(doc),
|
Some(doc) => Root::from_ref(doc),
|
||||||
None => Root::from_ref(document.r()),
|
None => Root::from_ref(document.r()),
|
||||||
};
|
};
|
||||||
|
@ -1688,14 +1681,14 @@ impl Node {
|
||||||
// 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() {
|
||||||
NodeTypeId::Document => {
|
NodeTypeId::Document => {
|
||||||
let node_doc = DocumentCast::to_ref(node).unwrap();
|
let node_doc = node.downcast::<Document>().unwrap();
|
||||||
let copy_doc = DocumentCast::to_ref(copy.r()).unwrap();
|
let copy_doc = copy.downcast::<Document>().unwrap();
|
||||||
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());
|
||||||
},
|
},
|
||||||
NodeTypeId::Element(..) => {
|
NodeTypeId::Element(..) => {
|
||||||
let node_elem = ElementCast::to_ref(node).unwrap();
|
let node_elem = node.downcast::<Element>().unwrap();
|
||||||
let copy_elem = ElementCast::to_ref(copy.r()).unwrap();
|
let copy_elem = copy.downcast::<Element>().unwrap();
|
||||||
|
|
||||||
for attr in node_elem.attrs().iter().map(JS::root) {
|
for attr in node_elem.attrs().iter().map(JS::root) {
|
||||||
copy_elem.push_new_attribute(attr.local_name().clone(),
|
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 {
|
pub fn collect_text_contents<T: Iterator<Item=Root<Node>>>(iterator: T) -> String {
|
||||||
let mut content = String::new();
|
let mut content = String::new();
|
||||||
for node in iterator {
|
for node in iterator {
|
||||||
let text = TextCast::to_ref(node.r());
|
let text = node.downcast::<Text>();
|
||||||
match text {
|
match text {
|
||||||
Some(text) => content.push_str(&CharacterDataCast::from_ref(text).Data()),
|
Some(text) => content.push_str(&text.upcast::<CharacterData>().Data()),
|
||||||
None => (),
|
None => (),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1759,7 +1752,7 @@ impl Node {
|
||||||
|
|
||||||
match node.type_id() {
|
match node.type_id() {
|
||||||
NodeTypeId::Element(_) => {
|
NodeTypeId::Element(_) => {
|
||||||
let element = ElementCast::to_ref(node).unwrap();
|
let element = node.downcast::<Element>().unwrap();
|
||||||
// Step 1.
|
// Step 1.
|
||||||
if *element.namespace() != ns!("") && *element.prefix() == prefix {
|
if *element.namespace() != ns!("") && *element.prefix() == prefix {
|
||||||
return element.namespace().clone()
|
return element.namespace().clone()
|
||||||
|
@ -1785,16 +1778,16 @@ impl Node {
|
||||||
// Step 3.
|
// Step 3.
|
||||||
None => ns!(""),
|
None => ns!(""),
|
||||||
// Step 4.
|
// Step 4.
|
||||||
Some(parent) => Node::locate_namespace(NodeCast::from_ref(parent.r()), prefix)
|
Some(parent) => Node::locate_namespace(parent.upcast::<Node>(), prefix)
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
NodeTypeId::Document => {
|
NodeTypeId::Document => {
|
||||||
match DocumentCast::to_ref(node).unwrap().GetDocumentElement().r() {
|
match node.downcast::<Document>().unwrap().GetDocumentElement().r() {
|
||||||
// Step 1.
|
// Step 1.
|
||||||
None => ns!(""),
|
None => ns!(""),
|
||||||
// Step 2.
|
// Step 2.
|
||||||
Some(document_element) => {
|
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.
|
// Step 1.
|
||||||
None => ns!(""),
|
None => ns!(""),
|
||||||
// Step 2.
|
// 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 {
|
fn NodeName(&self) -> DOMString {
|
||||||
match self.type_id() {
|
match self.type_id() {
|
||||||
NodeTypeId::Element(..) => {
|
NodeTypeId::Element(..) => {
|
||||||
let elem: &Element = ElementCast::to_ref(self).unwrap();
|
let elem: &Element = self.downcast::<Element>().unwrap();
|
||||||
elem.TagName()
|
elem.TagName()
|
||||||
}
|
}
|
||||||
NodeTypeId::CharacterData(CharacterDataTypeId::Text) => "#text".to_owned(),
|
NodeTypeId::CharacterData(CharacterDataTypeId::Text) => "#text".to_owned(),
|
||||||
NodeTypeId::CharacterData(CharacterDataTypeId::ProcessingInstruction) => {
|
NodeTypeId::CharacterData(CharacterDataTypeId::ProcessingInstruction) => {
|
||||||
let processing_instruction: &ProcessingInstruction =
|
let processing_instruction: &ProcessingInstruction =
|
||||||
ProcessingInstructionCast::to_ref(self).unwrap();
|
self.downcast::<ProcessingInstruction>().unwrap();
|
||||||
processing_instruction.Target()
|
processing_instruction.Target()
|
||||||
}
|
}
|
||||||
NodeTypeId::CharacterData(CharacterDataTypeId::Comment) => "#comment".to_owned(),
|
NodeTypeId::CharacterData(CharacterDataTypeId::Comment) => "#comment".to_owned(),
|
||||||
NodeTypeId::DocumentType => {
|
NodeTypeId::DocumentType => {
|
||||||
let doctype: &DocumentType = DocumentTypeCast::to_ref(self).unwrap();
|
let doctype: &DocumentType = self.downcast::<DocumentType>().unwrap();
|
||||||
doctype.name().clone()
|
doctype.name().clone()
|
||||||
},
|
},
|
||||||
NodeTypeId::DocumentFragment => "#document-fragment".to_owned(),
|
NodeTypeId::DocumentFragment => "#document-fragment".to_owned(),
|
||||||
|
@ -1877,7 +1870,7 @@ impl NodeMethods for Node {
|
||||||
|
|
||||||
// https://dom.spec.whatwg.org/#dom-node-parentelement
|
// https://dom.spec.whatwg.org/#dom-node-parentelement
|
||||||
fn GetParentElement(&self) -> Option<Root<Element>> {
|
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
|
// https://dom.spec.whatwg.org/#dom-node-haschildnodes
|
||||||
|
@ -1918,7 +1911,7 @@ impl NodeMethods for Node {
|
||||||
fn GetNodeValue(&self) -> Option<DOMString> {
|
fn GetNodeValue(&self) -> Option<DOMString> {
|
||||||
match self.type_id() {
|
match self.type_id() {
|
||||||
NodeTypeId::CharacterData(..) => {
|
NodeTypeId::CharacterData(..) => {
|
||||||
let chardata: &CharacterData = CharacterDataCast::to_ref(self).unwrap();
|
let chardata: &CharacterData = self.downcast::<CharacterData>().unwrap();
|
||||||
Some(chardata.Data())
|
Some(chardata.Data())
|
||||||
}
|
}
|
||||||
_ => {
|
_ => {
|
||||||
|
@ -1946,7 +1939,7 @@ impl NodeMethods for Node {
|
||||||
Some(content)
|
Some(content)
|
||||||
}
|
}
|
||||||
NodeTypeId::CharacterData(..) => {
|
NodeTypeId::CharacterData(..) => {
|
||||||
let characterdata: &CharacterData = CharacterDataCast::to_ref(self).unwrap();
|
let characterdata: &CharacterData = self.downcast::<CharacterData>().unwrap();
|
||||||
Some(characterdata.Data())
|
Some(characterdata.Data())
|
||||||
}
|
}
|
||||||
NodeTypeId::DocumentType |
|
NodeTypeId::DocumentType |
|
||||||
|
@ -1967,14 +1960,14 @@ impl NodeMethods for Node {
|
||||||
None
|
None
|
||||||
} else {
|
} else {
|
||||||
let document = self.owner_doc();
|
let document = self.owner_doc();
|
||||||
Some(NodeCast::from_root(document.r().CreateTextNode(value)))
|
Some(Root::upcast::<Node>(document.r().CreateTextNode(value)))
|
||||||
};
|
};
|
||||||
|
|
||||||
// Step 3.
|
// Step 3.
|
||||||
Node::replace_all(node.r(), self);
|
Node::replace_all(node.r(), self);
|
||||||
}
|
}
|
||||||
NodeTypeId::CharacterData(..) => {
|
NodeTypeId::CharacterData(..) => {
|
||||||
let characterdata: &CharacterData = CharacterDataCast::to_ref(self).unwrap();
|
let characterdata: &CharacterData = self.downcast::<CharacterData>().unwrap();
|
||||||
characterdata.SetData(value);
|
characterdata.SetData(value);
|
||||||
|
|
||||||
// Notify the document that the content of this node is different
|
// Notify the document that the content of this node is different
|
||||||
|
@ -2019,21 +2012,21 @@ impl NodeMethods for Node {
|
||||||
|
|
||||||
// Step 4-5.
|
// Step 4-5.
|
||||||
match node.type_id() {
|
match node.type_id() {
|
||||||
NodeTypeId::CharacterData(CharacterDataTypeId::Text) if self.is_document() =>
|
NodeTypeId::CharacterData(CharacterDataTypeId::Text) if self.is::<Document>() =>
|
||||||
return Err(Error::HierarchyRequest),
|
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),
|
NodeTypeId::Document => return Err(Error::HierarchyRequest),
|
||||||
_ => ()
|
_ => ()
|
||||||
}
|
}
|
||||||
|
|
||||||
// Step 6.
|
// Step 6.
|
||||||
if self.is_document() {
|
if self.is::<Document>() {
|
||||||
match node.type_id() {
|
match node.type_id() {
|
||||||
// Step 6.1
|
// Step 6.1
|
||||||
NodeTypeId::DocumentFragment => {
|
NodeTypeId::DocumentFragment => {
|
||||||
// Step 6.1.1(b)
|
// Step 6.1.1(b)
|
||||||
if node.children()
|
if node.children()
|
||||||
.any(|c| c.is_text())
|
.any(|c| c.is::<Text>())
|
||||||
{
|
{
|
||||||
return Err(Error::HierarchyRequest);
|
return Err(Error::HierarchyRequest);
|
||||||
}
|
}
|
||||||
|
@ -2042,7 +2035,7 @@ impl NodeMethods for Node {
|
||||||
// Step 6.1.2
|
// Step 6.1.2
|
||||||
1 => {
|
1 => {
|
||||||
if self.child_elements()
|
if self.child_elements()
|
||||||
.any(|c| NodeCast::from_ref(c.r()) != child) {
|
.any(|c| c.upcast::<Node>() != child) {
|
||||||
return Err(Error::HierarchyRequest);
|
return Err(Error::HierarchyRequest);
|
||||||
}
|
}
|
||||||
if child.following_siblings()
|
if child.following_siblings()
|
||||||
|
@ -2057,7 +2050,7 @@ impl NodeMethods for Node {
|
||||||
// Step 6.2
|
// Step 6.2
|
||||||
NodeTypeId::Element(..) => {
|
NodeTypeId::Element(..) => {
|
||||||
if self.child_elements()
|
if self.child_elements()
|
||||||
.any(|c| NodeCast::from_ref(c.r()) != child) {
|
.any(|c| c.upcast::<Node>() != child) {
|
||||||
return Err(Error::HierarchyRequest);
|
return Err(Error::HierarchyRequest);
|
||||||
}
|
}
|
||||||
if child.following_siblings()
|
if child.following_siblings()
|
||||||
|
@ -2076,7 +2069,7 @@ impl NodeMethods for Node {
|
||||||
}
|
}
|
||||||
if self.children()
|
if self.children()
|
||||||
.take_while(|c| c.r() != child)
|
.take_while(|c| c.r() != child)
|
||||||
.any(|c| c.is_element())
|
.any(|c| c.is::<Element>())
|
||||||
{
|
{
|
||||||
return Err(Error::HierarchyRequest);
|
return Err(Error::HierarchyRequest);
|
||||||
}
|
}
|
||||||
|
@ -2142,16 +2135,16 @@ impl NodeMethods for Node {
|
||||||
fn Normalize(&self) {
|
fn Normalize(&self) {
|
||||||
let mut prev_text: Option<Root<Text>> = None;
|
let mut prev_text: Option<Root<Text>> = None;
|
||||||
for child in self.children() {
|
for child in self.children() {
|
||||||
match TextCast::to_ref(child.r()) {
|
match child.downcast::<Text>() {
|
||||||
Some(text) => {
|
Some(text) => {
|
||||||
let characterdata: &CharacterData = CharacterDataCast::from_ref(text);
|
let characterdata: &CharacterData = text.upcast::<CharacterData>();
|
||||||
if characterdata.Length() == 0 {
|
if characterdata.Length() == 0 {
|
||||||
Node::remove(&*child, self, SuppressObserver::Unsuppressed);
|
Node::remove(&*child, self, SuppressObserver::Unsuppressed);
|
||||||
} else {
|
} else {
|
||||||
match prev_text {
|
match prev_text {
|
||||||
Some(ref text_node) => {
|
Some(ref text_node) => {
|
||||||
let prev_characterdata =
|
let prev_characterdata =
|
||||||
CharacterDataCast::from_ref(text_node.r());
|
text_node.upcast::<CharacterData>();
|
||||||
prev_characterdata.append_data(&**characterdata.data());
|
prev_characterdata.append_data(&**characterdata.data());
|
||||||
Node::remove(&*child, self, SuppressObserver::Unsuppressed);
|
Node::remove(&*child, self, SuppressObserver::Unsuppressed);
|
||||||
},
|
},
|
||||||
|
@ -2179,34 +2172,34 @@ impl NodeMethods for Node {
|
||||||
// https://dom.spec.whatwg.org/#dom-node-isequalnode
|
// https://dom.spec.whatwg.org/#dom-node-isequalnode
|
||||||
fn IsEqualNode(&self, maybe_node: Option<&Node>) -> bool {
|
fn IsEqualNode(&self, maybe_node: Option<&Node>) -> bool {
|
||||||
fn is_equal_doctype(node: &Node, other: &Node) -> bool {
|
fn is_equal_doctype(node: &Node, other: &Node) -> bool {
|
||||||
let doctype: &DocumentType = DocumentTypeCast::to_ref(node).unwrap();
|
let doctype: &DocumentType = node.downcast::<DocumentType>().unwrap();
|
||||||
let other_doctype: &DocumentType = DocumentTypeCast::to_ref(other).unwrap();
|
let other_doctype: &DocumentType = other.downcast::<DocumentType>().unwrap();
|
||||||
(*doctype.name() == *other_doctype.name()) &&
|
(*doctype.name() == *other_doctype.name()) &&
|
||||||
(*doctype.public_id() == *other_doctype.public_id()) &&
|
(*doctype.public_id() == *other_doctype.public_id()) &&
|
||||||
(*doctype.system_id() == *other_doctype.system_id())
|
(*doctype.system_id() == *other_doctype.system_id())
|
||||||
}
|
}
|
||||||
fn is_equal_element(node: &Node, other: &Node) -> bool {
|
fn is_equal_element(node: &Node, other: &Node) -> bool {
|
||||||
let element: &Element = ElementCast::to_ref(node).unwrap();
|
let element: &Element = node.downcast::<Element>().unwrap();
|
||||||
let other_element: &Element = ElementCast::to_ref(other).unwrap();
|
let other_element: &Element = other.downcast::<Element>().unwrap();
|
||||||
(*element.namespace() == *other_element.namespace()) &&
|
(*element.namespace() == *other_element.namespace()) &&
|
||||||
(*element.prefix() == *other_element.prefix()) &&
|
(*element.prefix() == *other_element.prefix()) &&
|
||||||
(*element.local_name() == *other_element.local_name()) &&
|
(*element.local_name() == *other_element.local_name()) &&
|
||||||
(element.attrs().len() == other_element.attrs().len())
|
(element.attrs().len() == other_element.attrs().len())
|
||||||
}
|
}
|
||||||
fn is_equal_processinginstruction(node: &Node, other: &Node) -> bool {
|
fn is_equal_processinginstruction(node: &Node, other: &Node) -> bool {
|
||||||
let pi: &ProcessingInstruction = ProcessingInstructionCast::to_ref(node).unwrap();
|
let pi: &ProcessingInstruction = node.downcast::<ProcessingInstruction>().unwrap();
|
||||||
let other_pi: &ProcessingInstruction = ProcessingInstructionCast::to_ref(other).unwrap();
|
let other_pi: &ProcessingInstruction = other.downcast::<ProcessingInstruction>().unwrap();
|
||||||
(*pi.target() == *other_pi.target()) &&
|
(*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 {
|
fn is_equal_characterdata(node: &Node, other: &Node) -> bool {
|
||||||
let characterdata: &CharacterData = CharacterDataCast::to_ref(node).unwrap();
|
let characterdata: &CharacterData = node.downcast::<CharacterData>().unwrap();
|
||||||
let other_characterdata: &CharacterData = CharacterDataCast::to_ref(other).unwrap();
|
let other_characterdata: &CharacterData = other.downcast::<CharacterData>().unwrap();
|
||||||
*characterdata.data() == *other_characterdata.data()
|
*characterdata.data() == *other_characterdata.data()
|
||||||
}
|
}
|
||||||
fn is_equal_element_attrs(node: &Node, other: &Node) -> bool {
|
fn is_equal_element_attrs(node: &Node, other: &Node) -> bool {
|
||||||
let element: &Element = ElementCast::to_ref(node).unwrap();
|
let element: &Element = node.downcast::<Element>().unwrap();
|
||||||
let other_element: &Element = ElementCast::to_ref(other).unwrap();
|
let other_element: &Element = other.downcast::<Element>().unwrap();
|
||||||
assert!(element.attrs().len() == other_element.attrs().len());
|
assert!(element.attrs().len() == other_element.attrs().len());
|
||||||
// FIXME(https://github.com/rust-lang/rust/issues/23338)
|
// FIXME(https://github.com/rust-lang/rust/issues/23338)
|
||||||
let attrs = element.attrs();
|
let attrs = element.attrs();
|
||||||
|
@ -2334,9 +2327,9 @@ impl NodeMethods for Node {
|
||||||
|
|
||||||
// Step 2.
|
// Step 2.
|
||||||
match self.type_id() {
|
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 => {
|
NodeTypeId::Document => {
|
||||||
DocumentCast::to_ref(self).unwrap().GetDocumentElement().and_then(|element| {
|
self.downcast::<Document>().unwrap().GetDocumentElement().and_then(|element| {
|
||||||
element.r().lookup_prefix(namespace)
|
element.r().lookup_prefix(namespace)
|
||||||
})
|
})
|
||||||
},
|
},
|
||||||
|
@ -2382,19 +2375,19 @@ pub struct TrustedNodeAddress(pub *const c_void);
|
||||||
#[allow(unsafe_code)]
|
#[allow(unsafe_code)]
|
||||||
unsafe impl Send for TrustedNodeAddress {}
|
unsafe impl Send for TrustedNodeAddress {}
|
||||||
|
|
||||||
pub fn document_from_node<T: NodeBase + Reflectable>(derived: &T) -> Root<Document> {
|
pub fn document_from_node<T: DerivedFrom<Node> + Reflectable>(derived: &T) -> Root<Document> {
|
||||||
let node: &Node = NodeCast::from_ref(derived);
|
let node: &Node = derived.upcast::<Node>();
|
||||||
node.owner_doc()
|
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);
|
let document = document_from_node(derived);
|
||||||
Root::from_ref(document.r().window())
|
Root::from_ref(document.r().window())
|
||||||
}
|
}
|
||||||
|
|
||||||
impl VirtualMethods for Node {
|
impl VirtualMethods for Node {
|
||||||
fn super_type(&self) -> Option<&VirtualMethods> {
|
fn super_type(&self) -> Option<&VirtualMethods> {
|
||||||
let eventtarget: &EventTarget = EventTargetCast::from_ref(self);
|
let eventtarget: &EventTarget = self.upcast::<EventTarget>();
|
||||||
Some(eventtarget as &VirtualMethods)
|
Some(eventtarget as &VirtualMethods)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -5,7 +5,7 @@
|
||||||
use dom::bindings::codegen::Bindings::EventBinding::EventMethods;
|
use dom::bindings::codegen::Bindings::EventBinding::EventMethods;
|
||||||
use dom::bindings::codegen::Bindings::ProgressEventBinding;
|
use dom::bindings::codegen::Bindings::ProgressEventBinding;
|
||||||
use dom::bindings::codegen::Bindings::ProgressEventBinding::ProgressEventMethods;
|
use dom::bindings::codegen::Bindings::ProgressEventBinding::ProgressEventMethods;
|
||||||
use dom::bindings::codegen::InheritTypes::EventCast;
|
use dom::bindings::conversions::Castable;
|
||||||
use dom::bindings::error::Fallible;
|
use dom::bindings::error::Fallible;
|
||||||
use dom::bindings::global::GlobalRef;
|
use dom::bindings::global::GlobalRef;
|
||||||
use dom::bindings::js::Root;
|
use dom::bindings::js::Root;
|
||||||
|
@ -37,7 +37,7 @@ impl ProgressEvent {
|
||||||
global,
|
global,
|
||||||
ProgressEventBinding::Wrap);
|
ProgressEventBinding::Wrap);
|
||||||
{
|
{
|
||||||
let event = EventCast::from_ref(ev.r());
|
let event = ev.upcast::<Event>();
|
||||||
event.InitEvent(type_, can_bubble == EventBubbles::Bubbles, cancelable == EventCancelable::Cancelable);
|
event.InitEvent(type_, can_bubble == EventBubbles::Bubbles, cancelable == EventCancelable::Cancelable);
|
||||||
}
|
}
|
||||||
ev
|
ev
|
||||||
|
|
|
@ -10,15 +10,17 @@ use dom::bindings::codegen::Bindings::RangeBinding::RangeMethods;
|
||||||
use dom::bindings::codegen::Bindings::RangeBinding::{self, RangeConstants};
|
use dom::bindings::codegen::Bindings::RangeBinding::{self, RangeConstants};
|
||||||
use dom::bindings::codegen::Bindings::TextBinding::TextMethods;
|
use dom::bindings::codegen::Bindings::TextBinding::TextMethods;
|
||||||
use dom::bindings::codegen::Bindings::WindowBinding::WindowMethods;
|
use dom::bindings::codegen::Bindings::WindowBinding::WindowMethods;
|
||||||
use dom::bindings::codegen::InheritTypes::{CharacterDataCast, CharacterDataTypeId};
|
use dom::bindings::codegen::InheritTypes::{CharacterDataTypeId, NodeTypeId};
|
||||||
use dom::bindings::codegen::InheritTypes::{NodeCast, NodeTypeId, TextCast, TextDerived};
|
use dom::bindings::conversions::Castable;
|
||||||
use dom::bindings::error::{Error, ErrorResult, Fallible};
|
use dom::bindings::error::{Error, ErrorResult, Fallible};
|
||||||
use dom::bindings::global::GlobalRef;
|
use dom::bindings::global::GlobalRef;
|
||||||
use dom::bindings::js::{JS, Root, RootedReference};
|
use dom::bindings::js::{JS, Root, RootedReference};
|
||||||
use dom::bindings::utils::{Reflector, reflect_dom_object};
|
use dom::bindings::utils::{Reflector, reflect_dom_object};
|
||||||
|
use dom::characterdata::CharacterData;
|
||||||
use dom::document::Document;
|
use dom::document::Document;
|
||||||
use dom::documentfragment::DocumentFragment;
|
use dom::documentfragment::DocumentFragment;
|
||||||
use dom::node::Node;
|
use dom::node::Node;
|
||||||
|
use dom::text::Text;
|
||||||
use std::cell::RefCell;
|
use std::cell::RefCell;
|
||||||
use std::cmp::{Ord, Ordering, PartialEq, PartialOrd};
|
use std::cmp::{Ord, Ordering, PartialEq, PartialOrd};
|
||||||
use std::rc::Rc;
|
use std::rc::Rc;
|
||||||
|
@ -41,7 +43,7 @@ impl Range {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn new_with_doc(document: &Document) -> Root<Range> {
|
pub fn new_with_doc(document: &Document) -> Root<Range> {
|
||||||
let root = NodeCast::from_ref(document);
|
let root = document.upcast::<Node>();
|
||||||
Range::new(document, root, 0, root, 0)
|
Range::new(document, root, 0, root, 0)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -277,7 +279,7 @@ impl RangeMethods for Range {
|
||||||
let start = &inner.start;
|
let start = &inner.start;
|
||||||
let end = &inner.end;
|
let end = &inner.end;
|
||||||
let start_node = start.node();
|
let start_node = start.node();
|
||||||
let owner_doc = NodeCast::from_ref(start_node.r()).owner_doc();
|
let owner_doc = start_node.upcast::<Node>().owner_doc();
|
||||||
Range::new(owner_doc.r(), start_node.r(), start.offset,
|
Range::new(owner_doc.r(), start_node.r(), start.offset,
|
||||||
end.node().r(), end.offset)
|
end.node().r(), end.offset)
|
||||||
}
|
}
|
||||||
|
@ -360,14 +362,14 @@ impl RangeMethods for Range {
|
||||||
}
|
}
|
||||||
|
|
||||||
if end_node == start_node {
|
if end_node == start_node {
|
||||||
if let Some(text) = CharacterDataCast::to_ref(start_node.r()) {
|
if let Some(text) = start_node.downcast::<CharacterData>() {
|
||||||
// Step 4.1.
|
// Step 4.1.
|
||||||
let clone = start_node.CloneNode(true);
|
let clone = start_node.CloneNode(true);
|
||||||
// Step 4.2.
|
// Step 4.2.
|
||||||
let text = text.SubstringData(start_offset, end_offset - start_offset);
|
let text = text.SubstringData(start_offset, end_offset - start_offset);
|
||||||
CharacterDataCast::to_ref(clone.r()).unwrap().SetData(text.unwrap());
|
clone.downcast::<CharacterData>().unwrap().SetData(text.unwrap());
|
||||||
// Step 4.3.
|
// Step 4.3.
|
||||||
try!(NodeCast::from_ref(fragment.r()).AppendChild(clone.r()));
|
try!(fragment.upcast::<Node>().AppendChild(clone.r()));
|
||||||
// Step 4.4
|
// Step 4.4
|
||||||
return Ok(fragment);
|
return Ok(fragment);
|
||||||
}
|
}
|
||||||
|
@ -379,20 +381,20 @@ impl RangeMethods for Range {
|
||||||
|
|
||||||
if let Some(child) = first_contained_child {
|
if let Some(child) = first_contained_child {
|
||||||
// Step 13.
|
// Step 13.
|
||||||
if let Some(text) = CharacterDataCast::to_ref(child.r()) {
|
if let Some(text) = child.downcast::<CharacterData>() {
|
||||||
assert!(child == start_node);
|
assert!(child == start_node);
|
||||||
// Step 13.1.
|
// Step 13.1.
|
||||||
let clone = start_node.CloneNode(true); // CharacterData has no children.
|
let clone = start_node.CloneNode(true); // CharacterData has no children.
|
||||||
// Step 13.2
|
// Step 13.2
|
||||||
let text = text.SubstringData(start_offset, start_node.len() - start_offset);
|
let text = text.SubstringData(start_offset, start_node.len() - start_offset);
|
||||||
CharacterDataCast::to_ref(clone.r()).unwrap().SetData(text.unwrap());
|
clone.downcast::<CharacterData>().unwrap().SetData(text.unwrap());
|
||||||
// Step 13.3.
|
// Step 13.3.
|
||||||
try!(NodeCast::from_ref(fragment.r()).AppendChild(clone.r()));
|
try!(fragment.upcast::<Node>().AppendChild(clone.r()));
|
||||||
} else {
|
} else {
|
||||||
// Step 14.1.
|
// Step 14.1.
|
||||||
let clone = child.CloneNode(false);
|
let clone = child.CloneNode(false);
|
||||||
// Step 14.2.
|
// Step 14.2.
|
||||||
try!(NodeCast::from_ref(fragment.r()).AppendChild(clone.r()));
|
try!(fragment.upcast::<Node>().AppendChild(clone.r()));
|
||||||
// Step 14.3.
|
// Step 14.3.
|
||||||
let subrange = Range::new(clone.owner_doc().r(),
|
let subrange = Range::new(clone.owner_doc().r(),
|
||||||
start_node.r(),
|
start_node.r(),
|
||||||
|
@ -402,7 +404,7 @@ impl RangeMethods for Range {
|
||||||
// Step 14.4.
|
// Step 14.4.
|
||||||
let subfragment = try!(subrange.CloneContents());
|
let subfragment = try!(subrange.CloneContents());
|
||||||
// Step 14.5.
|
// Step 14.5.
|
||||||
try!(clone.AppendChild(NodeCast::from_ref(subfragment.r())));
|
try!(clone.AppendChild(subfragment.upcast::<Node>()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -411,25 +413,25 @@ impl RangeMethods for Range {
|
||||||
// Step 15.1.
|
// Step 15.1.
|
||||||
let clone = child.CloneNode(true);
|
let clone = child.CloneNode(true);
|
||||||
// Step 15.2.
|
// Step 15.2.
|
||||||
try!(NodeCast::from_ref(fragment.r()).AppendChild(clone.r()));
|
try!(fragment.upcast::<Node>().AppendChild(clone.r()));
|
||||||
}
|
}
|
||||||
|
|
||||||
if let Some(child) = last_contained_child {
|
if let Some(child) = last_contained_child {
|
||||||
// Step 16.
|
// Step 16.
|
||||||
if let Some(text) = CharacterDataCast::to_ref(child.r()) {
|
if let Some(text) = child.downcast::<CharacterData>() {
|
||||||
assert!(child == end_node);
|
assert!(child == end_node);
|
||||||
// Step 16.1.
|
// Step 16.1.
|
||||||
let clone = end_node.CloneNode(true); // CharacterData has no children.
|
let clone = end_node.CloneNode(true); // CharacterData has no children.
|
||||||
// Step 16.2.
|
// Step 16.2.
|
||||||
let text = text.SubstringData(0, end_offset);
|
let text = text.SubstringData(0, end_offset);
|
||||||
CharacterDataCast::to_ref(clone.r()).unwrap().SetData(text.unwrap());
|
clone.downcast::<CharacterData>().unwrap().SetData(text.unwrap());
|
||||||
// Step 16.3.
|
// Step 16.3.
|
||||||
try!(NodeCast::from_ref(fragment.r()).AppendChild(clone.r()));
|
try!(fragment.upcast::<Node>().AppendChild(clone.r()));
|
||||||
} else {
|
} else {
|
||||||
// Step 17.1.
|
// Step 17.1.
|
||||||
let clone = child.CloneNode(false);
|
let clone = child.CloneNode(false);
|
||||||
// Step 17.2.
|
// Step 17.2.
|
||||||
try!(NodeCast::from_ref(fragment.r()).AppendChild(clone.r()));
|
try!(fragment.upcast::<Node>().AppendChild(clone.r()));
|
||||||
// Step 17.3.
|
// Step 17.3.
|
||||||
let subrange = Range::new(clone.owner_doc().r(),
|
let subrange = Range::new(clone.owner_doc().r(),
|
||||||
child.r(),
|
child.r(),
|
||||||
|
@ -439,7 +441,7 @@ impl RangeMethods for Range {
|
||||||
// Step 17.4.
|
// Step 17.4.
|
||||||
let subfragment = try!(subrange.CloneContents());
|
let subfragment = try!(subrange.CloneContents());
|
||||||
// Step 17.5.
|
// Step 17.5.
|
||||||
try!(clone.AppendChild(NodeCast::from_ref(subfragment.r())));
|
try!(clone.AppendChild(subfragment.upcast::<Node>()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -468,14 +470,14 @@ impl RangeMethods for Range {
|
||||||
}
|
}
|
||||||
|
|
||||||
if end_node == start_node {
|
if end_node == start_node {
|
||||||
if let Some(end_data) = CharacterDataCast::to_ref(end_node.r()) {
|
if let Some(end_data) = end_node.downcast::<CharacterData>() {
|
||||||
// Step 4.1.
|
// Step 4.1.
|
||||||
let clone = end_node.CloneNode(true);
|
let clone = end_node.CloneNode(true);
|
||||||
// Step 4.2.
|
// Step 4.2.
|
||||||
let text = end_data.SubstringData(start_offset, end_offset - start_offset);
|
let text = end_data.SubstringData(start_offset, end_offset - start_offset);
|
||||||
CharacterDataCast::to_ref(clone.r()).unwrap().SetData(text.unwrap());
|
clone.downcast::<CharacterData>().unwrap().SetData(text.unwrap());
|
||||||
// Step 4.3.
|
// Step 4.3.
|
||||||
try!(NodeCast::from_ref(fragment.r()).AppendChild(clone.r()));
|
try!(fragment.upcast::<Node>().AppendChild(clone.r()));
|
||||||
// Step 4.4.
|
// Step 4.4.
|
||||||
try!(end_data.ReplaceData(start_offset,
|
try!(end_data.ReplaceData(start_offset,
|
||||||
end_offset - start_offset,
|
end_offset - start_offset,
|
||||||
|
@ -502,16 +504,16 @@ impl RangeMethods for Range {
|
||||||
};
|
};
|
||||||
|
|
||||||
if let Some(child) = first_contained_child {
|
if let Some(child) = first_contained_child {
|
||||||
if let Some(start_data) = CharacterDataCast::to_ref(child.r()) {
|
if let Some(start_data) = child.downcast::<CharacterData>() {
|
||||||
assert!(child == start_node);
|
assert!(child == start_node);
|
||||||
// Step 15.1.
|
// Step 15.1.
|
||||||
let clone = start_node.CloneNode(true);
|
let clone = start_node.CloneNode(true);
|
||||||
// Step 15.2.
|
// Step 15.2.
|
||||||
let text = start_data.SubstringData(start_offset,
|
let text = start_data.SubstringData(start_offset,
|
||||||
start_node.len() - start_offset);
|
start_node.len() - start_offset);
|
||||||
CharacterDataCast::to_ref(clone.r()).unwrap().SetData(text.unwrap());
|
clone.downcast::<CharacterData>().unwrap().SetData(text.unwrap());
|
||||||
// Step 15.3.
|
// Step 15.3.
|
||||||
try!(NodeCast::from_ref(fragment.r()).AppendChild(clone.r()));
|
try!(fragment.upcast::<Node>().AppendChild(clone.r()));
|
||||||
// Step 15.4.
|
// Step 15.4.
|
||||||
try!(start_data.ReplaceData(start_offset,
|
try!(start_data.ReplaceData(start_offset,
|
||||||
start_node.len() - start_offset,
|
start_node.len() - start_offset,
|
||||||
|
@ -520,7 +522,7 @@ impl RangeMethods for Range {
|
||||||
// Step 16.1.
|
// Step 16.1.
|
||||||
let clone = child.CloneNode(false);
|
let clone = child.CloneNode(false);
|
||||||
// Step 16.2.
|
// Step 16.2.
|
||||||
try!(NodeCast::from_ref(fragment.r()).AppendChild(clone.r()));
|
try!(fragment.upcast::<Node>().AppendChild(clone.r()));
|
||||||
// Step 16.3.
|
// Step 16.3.
|
||||||
let subrange = Range::new(clone.owner_doc().r(),
|
let subrange = Range::new(clone.owner_doc().r(),
|
||||||
start_node.r(),
|
start_node.r(),
|
||||||
|
@ -530,32 +532,32 @@ impl RangeMethods for Range {
|
||||||
// Step 16.4.
|
// Step 16.4.
|
||||||
let subfragment = try!(subrange.ExtractContents());
|
let subfragment = try!(subrange.ExtractContents());
|
||||||
// Step 16.5.
|
// Step 16.5.
|
||||||
try!(clone.AppendChild(NodeCast::from_ref(subfragment.r())));
|
try!(clone.AppendChild(subfragment.upcast::<Node>()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Step 17.
|
// Step 17.
|
||||||
for child in contained_children {
|
for child in contained_children {
|
||||||
try!(NodeCast::from_ref(fragment.r()).AppendChild(child.r()));
|
try!(fragment.upcast::<Node>().AppendChild(child.r()));
|
||||||
}
|
}
|
||||||
|
|
||||||
if let Some(child) = last_contained_child {
|
if let Some(child) = last_contained_child {
|
||||||
if let Some(end_data) = CharacterDataCast::to_ref(child.r()) {
|
if let Some(end_data) = child.downcast::<CharacterData>() {
|
||||||
assert!(child == end_node);
|
assert!(child == end_node);
|
||||||
// Step 18.1.
|
// Step 18.1.
|
||||||
let clone = end_node.CloneNode(true);
|
let clone = end_node.CloneNode(true);
|
||||||
// Step 18.2.
|
// Step 18.2.
|
||||||
let text = end_data.SubstringData(0, end_offset);
|
let text = end_data.SubstringData(0, end_offset);
|
||||||
CharacterDataCast::to_ref(clone.r()).unwrap().SetData(text.unwrap());
|
clone.downcast::<CharacterData>().unwrap().SetData(text.unwrap());
|
||||||
// Step 18.3.
|
// Step 18.3.
|
||||||
try!(NodeCast::from_ref(fragment.r()).AppendChild(clone.r()));
|
try!(fragment.upcast::<Node>().AppendChild(clone.r()));
|
||||||
// Step 18.4.
|
// Step 18.4.
|
||||||
try!(end_data.ReplaceData(0, end_offset, "".to_owned()));
|
try!(end_data.ReplaceData(0, end_offset, "".to_owned()));
|
||||||
} else {
|
} else {
|
||||||
// Step 19.1.
|
// Step 19.1.
|
||||||
let clone = child.CloneNode(false);
|
let clone = child.CloneNode(false);
|
||||||
// Step 19.2.
|
// Step 19.2.
|
||||||
try!(NodeCast::from_ref(fragment.r()).AppendChild(clone.r()));
|
try!(fragment.upcast::<Node>().AppendChild(clone.r()));
|
||||||
// Step 19.3.
|
// Step 19.3.
|
||||||
let subrange = Range::new(clone.owner_doc().r(),
|
let subrange = Range::new(clone.owner_doc().r(),
|
||||||
child.r(),
|
child.r(),
|
||||||
|
@ -565,7 +567,7 @@ impl RangeMethods for Range {
|
||||||
// Step 19.4.
|
// Step 19.4.
|
||||||
let subfragment = try!(subrange.ExtractContents());
|
let subfragment = try!(subrange.ExtractContents());
|
||||||
// Step 19.5.
|
// Step 19.5.
|
||||||
try!(clone.AppendChild(NodeCast::from_ref(subfragment.r())));
|
try!(clone.AppendChild(subfragment.upcast::<Node>()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -624,10 +626,10 @@ impl RangeMethods for Range {
|
||||||
// Step 7.
|
// Step 7.
|
||||||
let split_text;
|
let split_text;
|
||||||
let reference_node =
|
let reference_node =
|
||||||
match TextCast::to_ref(start_node.r()) {
|
match start_node.downcast::<Text>() {
|
||||||
Some(text) => {
|
Some(text) => {
|
||||||
split_text = try!(text.SplitText(start_offset));
|
split_text = try!(text.SplitText(start_offset));
|
||||||
let new_reference = NodeCast::from_root(split_text);
|
let new_reference = Root::upcast::<Node>(split_text);
|
||||||
assert!(new_reference.GetParentNode().r() == Some(parent.r()));
|
assert!(new_reference.GetParentNode().r() == Some(parent.r()));
|
||||||
Some(new_reference)
|
Some(new_reference)
|
||||||
},
|
},
|
||||||
|
@ -672,8 +674,8 @@ impl RangeMethods for Range {
|
||||||
let start = self.StartContainer();
|
let start = self.StartContainer();
|
||||||
let end = self.EndContainer();
|
let end = self.EndContainer();
|
||||||
|
|
||||||
if start.inclusive_ancestors().any(|n| !n.is_inclusive_ancestor_of(end.r()) && !n.is_text()) ||
|
if start.inclusive_ancestors().any(|n| !n.is_inclusive_ancestor_of(end.r()) && !n.is::<Text>()) ||
|
||||||
end.inclusive_ancestors().any(|n| !n.is_inclusive_ancestor_of(start.r()) && !n.is_text()) {
|
end.inclusive_ancestors().any(|n| !n.is_inclusive_ancestor_of(start.r()) && !n.is::<Text>()) {
|
||||||
return Err(Error::InvalidState);
|
return Err(Error::InvalidState);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -695,7 +697,7 @@ impl RangeMethods for Range {
|
||||||
try!(self.InsertNode(new_parent));
|
try!(self.InsertNode(new_parent));
|
||||||
|
|
||||||
// Step 6.
|
// Step 6.
|
||||||
let _ = try!(new_parent.AppendChild(NodeCast::from_ref(fragment.r())));
|
let _ = try!(new_parent.AppendChild(fragment.upcast::<Node>()));
|
||||||
|
|
||||||
// Step 7.
|
// Step 7.
|
||||||
self.SelectNode(new_parent)
|
self.SelectNode(new_parent)
|
||||||
|
|
|
@ -8,7 +8,6 @@
|
||||||
use document_loader::LoadType;
|
use document_loader::LoadType;
|
||||||
use dom::bindings::cell::DOMRefCell;
|
use dom::bindings::cell::DOMRefCell;
|
||||||
use dom::bindings::codegen::Bindings::ServoHTMLParserBinding;
|
use dom::bindings::codegen::Bindings::ServoHTMLParserBinding;
|
||||||
use dom::bindings::codegen::InheritTypes::NodeCast;
|
|
||||||
use dom::bindings::global::GlobalRef;
|
use dom::bindings::global::GlobalRef;
|
||||||
use dom::bindings::js::{JS, Root};
|
use dom::bindings::js::{JS, Root};
|
||||||
use dom::bindings::refcounted::Trusted;
|
use dom::bindings::refcounted::Trusted;
|
||||||
|
@ -49,7 +48,7 @@ impl Sink {
|
||||||
NodeOrText::AppendNode(n) => n.root(),
|
NodeOrText::AppendNode(n) => n.root(),
|
||||||
NodeOrText::AppendText(t) => {
|
NodeOrText::AppendText(t) => {
|
||||||
let text = Text::new(t.into(), &self.document);
|
let text = Text::new(t.into(), &self.document);
|
||||||
NodeCast::from_root(text)
|
Root::upcast::<Node>(text)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,13 +4,14 @@
|
||||||
|
|
||||||
use dom::bindings::codegen::Bindings::StorageBinding;
|
use dom::bindings::codegen::Bindings::StorageBinding;
|
||||||
use dom::bindings::codegen::Bindings::StorageBinding::StorageMethods;
|
use dom::bindings::codegen::Bindings::StorageBinding::StorageMethods;
|
||||||
use dom::bindings::codegen::InheritTypes::{EventCast, EventTargetCast};
|
use dom::bindings::conversions::Castable;
|
||||||
use dom::bindings::error::{Error, ErrorResult};
|
use dom::bindings::error::{Error, ErrorResult};
|
||||||
use dom::bindings::global::{GlobalField, GlobalRef};
|
use dom::bindings::global::{GlobalField, GlobalRef};
|
||||||
use dom::bindings::js::{Root, RootedReference};
|
use dom::bindings::js::{Root, RootedReference};
|
||||||
use dom::bindings::refcounted::Trusted;
|
use dom::bindings::refcounted::Trusted;
|
||||||
use dom::bindings::utils::{Reflector, reflect_dom_object};
|
use dom::bindings::utils::{Reflector, reflect_dom_object};
|
||||||
use dom::event::{EventBubbles, EventCancelable};
|
use dom::event::{Event, EventBubbles, EventCancelable};
|
||||||
|
use dom::eventtarget::EventTarget;
|
||||||
use dom::storageevent::StorageEvent;
|
use dom::storageevent::StorageEvent;
|
||||||
use dom::urlhelper::UrlHelper;
|
use dom::urlhelper::UrlHelper;
|
||||||
use ipc_channel::ipc;
|
use ipc_channel::ipc;
|
||||||
|
@ -192,7 +193,7 @@ impl MainThreadRunnable for StorageEventRunnable {
|
||||||
ev_url.to_string(),
|
ev_url.to_string(),
|
||||||
Some(storage)
|
Some(storage)
|
||||||
);
|
);
|
||||||
let event = EventCast::from_ref(storage_event.r());
|
let event = storage_event.upcast::<Event>();
|
||||||
|
|
||||||
let root_page = script_task.root_page();
|
let root_page = script_task.root_page();
|
||||||
for it_page in root_page.iter() {
|
for it_page in root_page.iter() {
|
||||||
|
@ -202,7 +203,7 @@ impl MainThreadRunnable for StorageEventRunnable {
|
||||||
// TODO: Such a Document object is not necessarily fully active, but events fired on such
|
// TODO: Such a Document object is not necessarily fully active, but events fired on such
|
||||||
// objects are ignored by the event loop until the Document becomes fully active again.
|
// objects are ignored by the event loop until the Document becomes fully active again.
|
||||||
if ev_window.pipeline() != it_window.pipeline() {
|
if ev_window.pipeline() != it_window.pipeline() {
|
||||||
let target = EventTargetCast::from_ref(it_window);
|
let target = it_window.upcast::<EventTarget>();
|
||||||
event.fire(target);
|
event.fire(target);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,7 +5,7 @@
|
||||||
use dom::bindings::codegen::Bindings::EventBinding::{EventMethods};
|
use dom::bindings::codegen::Bindings::EventBinding::{EventMethods};
|
||||||
use dom::bindings::codegen::Bindings::StorageEventBinding;
|
use dom::bindings::codegen::Bindings::StorageEventBinding;
|
||||||
use dom::bindings::codegen::Bindings::StorageEventBinding::{StorageEventMethods};
|
use dom::bindings::codegen::Bindings::StorageEventBinding::{StorageEventMethods};
|
||||||
use dom::bindings::codegen::InheritTypes::EventCast;
|
use dom::bindings::conversions::Castable;
|
||||||
use dom::bindings::error::Fallible;
|
use dom::bindings::error::Fallible;
|
||||||
use dom::bindings::global::GlobalRef;
|
use dom::bindings::global::GlobalRef;
|
||||||
use dom::bindings::js::{JS, MutNullableHeap, Root, RootedReference};
|
use dom::bindings::js::{JS, MutNullableHeap, Root, RootedReference};
|
||||||
|
@ -55,7 +55,7 @@ impl StorageEvent {
|
||||||
global,
|
global,
|
||||||
StorageEventBinding::Wrap);
|
StorageEventBinding::Wrap);
|
||||||
{
|
{
|
||||||
let event = EventCast::from_ref(ev.r());
|
let event = ev.upcast::<Event>();
|
||||||
event.InitEvent(type_, bubbles == EventBubbles::Bubbles, cancelable == EventCancelable::Cancelable);
|
event.InitEvent(type_, bubbles == EventBubbles::Bubbles, cancelable == EventCancelable::Cancelable);
|
||||||
}
|
}
|
||||||
ev
|
ev
|
||||||
|
|
|
@ -7,7 +7,7 @@ use dom::bindings::codegen::Bindings::DocumentBinding::DocumentMethods;
|
||||||
use dom::bindings::codegen::Bindings::NodeBinding::NodeMethods;
|
use dom::bindings::codegen::Bindings::NodeBinding::NodeMethods;
|
||||||
use dom::bindings::codegen::Bindings::TextBinding::{self, TextMethods};
|
use dom::bindings::codegen::Bindings::TextBinding::{self, TextMethods};
|
||||||
use dom::bindings::codegen::Bindings::WindowBinding::WindowMethods;
|
use dom::bindings::codegen::Bindings::WindowBinding::WindowMethods;
|
||||||
use dom::bindings::codegen::InheritTypes::{CharacterDataCast, NodeCast, TextDerived};
|
use dom::bindings::conversions::Castable;
|
||||||
use dom::bindings::error::{Error, Fallible};
|
use dom::bindings::error::{Error, Fallible};
|
||||||
use dom::bindings::global::GlobalRef;
|
use dom::bindings::global::GlobalRef;
|
||||||
use dom::bindings::js::Root;
|
use dom::bindings::js::Root;
|
||||||
|
@ -44,7 +44,7 @@ impl Text {
|
||||||
impl TextMethods for Text {
|
impl TextMethods for Text {
|
||||||
// https://dom.spec.whatwg.org/#dom-text-splittextoffset
|
// https://dom.spec.whatwg.org/#dom-text-splittextoffset
|
||||||
fn SplitText(&self, offset: u32) -> Fallible<Root<Text>> {
|
fn SplitText(&self, offset: u32) -> Fallible<Root<Text>> {
|
||||||
let cdata = CharacterDataCast::from_ref(self);
|
let cdata = self.upcast::<CharacterData>();
|
||||||
// Step 1.
|
// Step 1.
|
||||||
let length = cdata.Length();
|
let length = cdata.Length();
|
||||||
if offset > length {
|
if offset > length {
|
||||||
|
@ -56,14 +56,14 @@ impl TextMethods for Text {
|
||||||
// Step 4.
|
// Step 4.
|
||||||
let new_data = cdata.SubstringData(offset, count).unwrap();
|
let new_data = cdata.SubstringData(offset, count).unwrap();
|
||||||
// Step 5.
|
// Step 5.
|
||||||
let node = NodeCast::from_ref(self);
|
let node = self.upcast::<Node>();
|
||||||
let owner_doc = node.owner_doc();
|
let owner_doc = node.owner_doc();
|
||||||
let new_node = owner_doc.r().CreateTextNode(new_data);
|
let new_node = owner_doc.r().CreateTextNode(new_data);
|
||||||
// Step 6.
|
// Step 6.
|
||||||
let parent = node.GetParentNode();
|
let parent = node.GetParentNode();
|
||||||
if let Some(ref parent) = parent {
|
if let Some(ref parent) = parent {
|
||||||
// Step 7.
|
// Step 7.
|
||||||
parent.r().InsertBefore(NodeCast::from_ref(new_node.r()),
|
parent.r().InsertBefore(new_node.upcast::<Node>(),
|
||||||
node.GetNextSibling().r())
|
node.GetNextSibling().r())
|
||||||
.unwrap();
|
.unwrap();
|
||||||
// TODO: Ranges.
|
// TODO: Ranges.
|
||||||
|
@ -80,14 +80,14 @@ impl TextMethods for Text {
|
||||||
|
|
||||||
// https://dom.spec.whatwg.org/#dom-text-wholetext
|
// https://dom.spec.whatwg.org/#dom-text-wholetext
|
||||||
fn WholeText(&self) -> DOMString {
|
fn WholeText(&self) -> DOMString {
|
||||||
let first = NodeCast::from_ref(self).inclusively_preceding_siblings()
|
let first = self.upcast::<Node>().inclusively_preceding_siblings()
|
||||||
.take_while(|node| node.r().is_text())
|
.take_while(|node| node.r().is::<Text>())
|
||||||
.last().unwrap();
|
.last().unwrap();
|
||||||
let nodes = first.r().inclusively_following_siblings()
|
let nodes = first.r().inclusively_following_siblings()
|
||||||
.take_while(|node| node.r().is_text());
|
.take_while(|node| node.r().is::<Text>());
|
||||||
let mut text = DOMString::new();
|
let mut text = DOMString::new();
|
||||||
for ref node in nodes {
|
for ref node in nodes {
|
||||||
let cdata = CharacterDataCast::to_ref(node.r()).unwrap();
|
let cdata = node.downcast::<CharacterData>().unwrap();
|
||||||
text.push_str(&cdata.data());
|
text.push_str(&cdata.data());
|
||||||
}
|
}
|
||||||
text
|
text
|
||||||
|
|
|
@ -5,7 +5,7 @@
|
||||||
use dom::bindings::codegen::Bindings::EventBinding::EventMethods;
|
use dom::bindings::codegen::Bindings::EventBinding::EventMethods;
|
||||||
use dom::bindings::codegen::Bindings::UIEventBinding;
|
use dom::bindings::codegen::Bindings::UIEventBinding;
|
||||||
use dom::bindings::codegen::Bindings::UIEventBinding::UIEventMethods;
|
use dom::bindings::codegen::Bindings::UIEventBinding::UIEventMethods;
|
||||||
use dom::bindings::codegen::InheritTypes::EventCast;
|
use dom::bindings::conversions::Castable;
|
||||||
use dom::bindings::error::Fallible;
|
use dom::bindings::error::Fallible;
|
||||||
use dom::bindings::global::GlobalRef;
|
use dom::bindings::global::GlobalRef;
|
||||||
use dom::bindings::js::Root;
|
use dom::bindings::js::Root;
|
||||||
|
@ -86,7 +86,7 @@ impl UIEventMethods for UIEvent {
|
||||||
cancelable: bool,
|
cancelable: bool,
|
||||||
view: Option<&Window>,
|
view: Option<&Window>,
|
||||||
detail: i32) {
|
detail: i32) {
|
||||||
let event: &Event = EventCast::from_ref(self);
|
let event: &Event = self.upcast::<Event>();
|
||||||
if event.dispatching() {
|
if event.dispatching() {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,9 +4,10 @@
|
||||||
|
|
||||||
use dom::bindings::codegen::Bindings::DocumentBinding::DocumentMethods;
|
use dom::bindings::codegen::Bindings::DocumentBinding::DocumentMethods;
|
||||||
use dom::bindings::codegen::Bindings::NodeBinding::NodeMethods;
|
use dom::bindings::codegen::Bindings::NodeBinding::NodeMethods;
|
||||||
use dom::bindings::codegen::InheritTypes::NodeCast;
|
use dom::bindings::conversions::Castable;
|
||||||
use dom::bindings::js::{RootedReference};
|
use dom::bindings::js::{RootedReference};
|
||||||
use dom::htmlheadelement::HTMLHeadElement;
|
use dom::htmlheadelement::HTMLHeadElement;
|
||||||
|
use dom::node::Node;
|
||||||
use std::borrow::ToOwned;
|
use std::borrow::ToOwned;
|
||||||
use std::fs::read_dir;
|
use std::fs::read_dir;
|
||||||
use std::path::PathBuf;
|
use std::path::PathBuf;
|
||||||
|
@ -16,7 +17,7 @@ use util::resource_files::resources_dir_path;
|
||||||
|
|
||||||
pub fn load_script(head: &HTMLHeadElement) {
|
pub fn load_script(head: &HTMLHeadElement) {
|
||||||
if let Some(ref path_str) = opts::get().userscripts {
|
if let Some(ref path_str) = opts::get().userscripts {
|
||||||
let node = NodeCast::from_ref(head);
|
let node = head.upcast::<Node>();
|
||||||
let first_child = node.GetFirstChild();
|
let first_child = node.GetFirstChild();
|
||||||
let doc = node.owner_doc();
|
let doc = node.owner_doc();
|
||||||
let doc = doc.r();
|
let doc = doc.r();
|
||||||
|
@ -43,7 +44,7 @@ pub fn load_script(head: &HTMLHeadElement) {
|
||||||
let new_script = doc.CreateElement("script".to_owned()).unwrap();
|
let new_script = doc.CreateElement("script".to_owned()).unwrap();
|
||||||
let new_script = new_script.r();
|
let new_script = new_script.r();
|
||||||
new_script.set_string_attribute(&atom!("src"), name);
|
new_script.set_string_attribute(&atom!("src"), name);
|
||||||
let new_script_node = NodeCast::from_ref(new_script);
|
let new_script_node = new_script.upcast::<Node>();
|
||||||
node.InsertBefore(new_script_node, first_child.r()).unwrap();
|
node.InsertBefore(new_script_node, first_child.r()).unwrap();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,43 +3,43 @@
|
||||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||||
|
|
||||||
use dom::attr::{Attr, AttrValue};
|
use dom::attr::{Attr, AttrValue};
|
||||||
use dom::bindings::codegen::InheritTypes::ElementCast;
|
|
||||||
use dom::bindings::codegen::InheritTypes::ElementTypeId;
|
use dom::bindings::codegen::InheritTypes::ElementTypeId;
|
||||||
use dom::bindings::codegen::InheritTypes::HTMLAnchorElementCast;
|
|
||||||
use dom::bindings::codegen::InheritTypes::HTMLAppletElementCast;
|
|
||||||
use dom::bindings::codegen::InheritTypes::HTMLAreaElementCast;
|
|
||||||
use dom::bindings::codegen::InheritTypes::HTMLBaseElementCast;
|
|
||||||
use dom::bindings::codegen::InheritTypes::HTMLBodyElementCast;
|
|
||||||
use dom::bindings::codegen::InheritTypes::HTMLButtonElementCast;
|
|
||||||
use dom::bindings::codegen::InheritTypes::HTMLCanvasElementCast;
|
|
||||||
use dom::bindings::codegen::InheritTypes::HTMLElementCast;
|
|
||||||
use dom::bindings::codegen::InheritTypes::HTMLElementTypeId;
|
use dom::bindings::codegen::InheritTypes::HTMLElementTypeId;
|
||||||
use dom::bindings::codegen::InheritTypes::HTMLFieldSetElementCast;
|
|
||||||
use dom::bindings::codegen::InheritTypes::HTMLFontElementCast;
|
|
||||||
use dom::bindings::codegen::InheritTypes::HTMLFormElementCast;
|
|
||||||
use dom::bindings::codegen::InheritTypes::HTMLHeadElementCast;
|
|
||||||
use dom::bindings::codegen::InheritTypes::HTMLIFrameElementCast;
|
|
||||||
use dom::bindings::codegen::InheritTypes::HTMLImageElementCast;
|
|
||||||
use dom::bindings::codegen::InheritTypes::HTMLInputElementCast;
|
|
||||||
use dom::bindings::codegen::InheritTypes::HTMLLinkElementCast;
|
|
||||||
use dom::bindings::codegen::InheritTypes::HTMLMetaElementCast;
|
|
||||||
use dom::bindings::codegen::InheritTypes::HTMLObjectElementCast;
|
|
||||||
use dom::bindings::codegen::InheritTypes::HTMLOptGroupElementCast;
|
|
||||||
use dom::bindings::codegen::InheritTypes::HTMLOptionElementCast;
|
|
||||||
use dom::bindings::codegen::InheritTypes::HTMLScriptElementCast;
|
|
||||||
use dom::bindings::codegen::InheritTypes::HTMLSelectElementCast;
|
|
||||||
use dom::bindings::codegen::InheritTypes::HTMLStyleElementCast;
|
|
||||||
use dom::bindings::codegen::InheritTypes::HTMLTableCellElementCast;
|
|
||||||
use dom::bindings::codegen::InheritTypes::HTMLTableElementCast;
|
|
||||||
use dom::bindings::codegen::InheritTypes::HTMLTableRowElementCast;
|
|
||||||
use dom::bindings::codegen::InheritTypes::HTMLTableSectionElementCast;
|
|
||||||
use dom::bindings::codegen::InheritTypes::HTMLTemplateElementCast;
|
|
||||||
use dom::bindings::codegen::InheritTypes::HTMLTextAreaElementCast;
|
|
||||||
use dom::bindings::codegen::InheritTypes::HTMLTitleElementCast;
|
|
||||||
use dom::bindings::codegen::InheritTypes::NodeTypeId;
|
use dom::bindings::codegen::InheritTypes::NodeTypeId;
|
||||||
|
use dom::bindings::conversions::Castable;
|
||||||
use dom::document::Document;
|
use dom::document::Document;
|
||||||
use dom::element::AttributeMutation;
|
use dom::element::{AttributeMutation, Element};
|
||||||
use dom::event::Event;
|
use dom::event::Event;
|
||||||
|
use dom::htmlanchorelement::HTMLAnchorElement;
|
||||||
|
use dom::htmlappletelement::HTMLAppletElement;
|
||||||
|
use dom::htmlareaelement::HTMLAreaElement;
|
||||||
|
use dom::htmlbaseelement::HTMLBaseElement;
|
||||||
|
use dom::htmlbodyelement::HTMLBodyElement;
|
||||||
|
use dom::htmlbuttonelement::HTMLButtonElement;
|
||||||
|
use dom::htmlcanvaselement::HTMLCanvasElement;
|
||||||
|
use dom::htmlelement::HTMLElement;
|
||||||
|
use dom::htmlfieldsetelement::HTMLFieldSetElement;
|
||||||
|
use dom::htmlfontelement::HTMLFontElement;
|
||||||
|
use dom::htmlformelement::HTMLFormElement;
|
||||||
|
use dom::htmlheadelement::HTMLHeadElement;
|
||||||
|
use dom::htmliframeelement::HTMLIFrameElement;
|
||||||
|
use dom::htmlimageelement::HTMLImageElement;
|
||||||
|
use dom::htmlinputelement::HTMLInputElement;
|
||||||
|
use dom::htmllinkelement::HTMLLinkElement;
|
||||||
|
use dom::htmlmetaelement::HTMLMetaElement;
|
||||||
|
use dom::htmlobjectelement::HTMLObjectElement;
|
||||||
|
use dom::htmloptgroupelement::HTMLOptGroupElement;
|
||||||
|
use dom::htmloptionelement::HTMLOptionElement;
|
||||||
|
use dom::htmlscriptelement::HTMLScriptElement;
|
||||||
|
use dom::htmlselectelement::HTMLSelectElement;
|
||||||
|
use dom::htmlstyleelement::HTMLStyleElement;
|
||||||
|
use dom::htmltablecellelement::HTMLTableCellElement;
|
||||||
|
use dom::htmltableelement::HTMLTableElement;
|
||||||
|
use dom::htmltablerowelement::HTMLTableRowElement;
|
||||||
|
use dom::htmltablesectionelement::HTMLTableSectionElement;
|
||||||
|
use dom::htmltemplateelement::HTMLTemplateElement;
|
||||||
|
use dom::htmltextareaelement::HTMLTextAreaElement;
|
||||||
|
use dom::htmltitleelement::HTMLTitleElement;
|
||||||
use dom::node::{ChildrenMutation, CloneChildrenFlag, Node};
|
use dom::node::{ChildrenMutation, CloneChildrenFlag, Node};
|
||||||
use string_cache::Atom;
|
use string_cache::Atom;
|
||||||
use util::str::DOMString;
|
use util::str::DOMString;
|
||||||
|
@ -123,130 +123,130 @@ pub trait VirtualMethods {
|
||||||
pub fn vtable_for(node: &Node) -> &VirtualMethods {
|
pub fn vtable_for(node: &Node) -> &VirtualMethods {
|
||||||
match node.type_id() {
|
match node.type_id() {
|
||||||
NodeTypeId::Element(ElementTypeId::HTMLElement(HTMLElementTypeId::HTMLAnchorElement)) => {
|
NodeTypeId::Element(ElementTypeId::HTMLElement(HTMLElementTypeId::HTMLAnchorElement)) => {
|
||||||
let element = HTMLAnchorElementCast::to_ref(node).unwrap();
|
let element = node.downcast::<HTMLAnchorElement>().unwrap();
|
||||||
element as &VirtualMethods
|
element as &VirtualMethods
|
||||||
}
|
}
|
||||||
NodeTypeId::Element(ElementTypeId::HTMLElement(HTMLElementTypeId::HTMLAppletElement)) => {
|
NodeTypeId::Element(ElementTypeId::HTMLElement(HTMLElementTypeId::HTMLAppletElement)) => {
|
||||||
HTMLAppletElementCast::to_ref(node).unwrap() as &VirtualMethods
|
node.downcast::<HTMLAppletElement>().unwrap() as &VirtualMethods
|
||||||
}
|
}
|
||||||
NodeTypeId::Element(ElementTypeId::HTMLElement(HTMLElementTypeId::HTMLAreaElement)) => {
|
NodeTypeId::Element(ElementTypeId::HTMLElement(HTMLElementTypeId::HTMLAreaElement)) => {
|
||||||
let element = HTMLAreaElementCast::to_ref(node).unwrap();
|
let element = node.downcast::<HTMLAreaElement>().unwrap();
|
||||||
element as &VirtualMethods
|
element as &VirtualMethods
|
||||||
}
|
}
|
||||||
NodeTypeId::Element(ElementTypeId::HTMLElement(HTMLElementTypeId::HTMLBaseElement)) => {
|
NodeTypeId::Element(ElementTypeId::HTMLElement(HTMLElementTypeId::HTMLBaseElement)) => {
|
||||||
let element = HTMLBaseElementCast::to_ref(node).unwrap();
|
let element = node.downcast::<HTMLBaseElement>().unwrap();
|
||||||
element as &VirtualMethods
|
element as &VirtualMethods
|
||||||
}
|
}
|
||||||
NodeTypeId::Element(ElementTypeId::HTMLElement(HTMLElementTypeId::HTMLBodyElement)) => {
|
NodeTypeId::Element(ElementTypeId::HTMLElement(HTMLElementTypeId::HTMLBodyElement)) => {
|
||||||
let element = HTMLBodyElementCast::to_ref(node).unwrap();
|
let element = node.downcast::<HTMLBodyElement>().unwrap();
|
||||||
element as &VirtualMethods
|
element as &VirtualMethods
|
||||||
}
|
}
|
||||||
NodeTypeId::Element(ElementTypeId::HTMLElement(HTMLElementTypeId::HTMLButtonElement)) => {
|
NodeTypeId::Element(ElementTypeId::HTMLElement(HTMLElementTypeId::HTMLButtonElement)) => {
|
||||||
let element = HTMLButtonElementCast::to_ref(node).unwrap();
|
let element = node.downcast::<HTMLButtonElement>().unwrap();
|
||||||
element as &VirtualMethods
|
element as &VirtualMethods
|
||||||
}
|
}
|
||||||
NodeTypeId::Element(ElementTypeId::HTMLElement(HTMLElementTypeId::HTMLCanvasElement)) => {
|
NodeTypeId::Element(ElementTypeId::HTMLElement(HTMLElementTypeId::HTMLCanvasElement)) => {
|
||||||
let element = HTMLCanvasElementCast::to_ref(node).unwrap();
|
let element = node.downcast::<HTMLCanvasElement>().unwrap();
|
||||||
element as &VirtualMethods
|
element as &VirtualMethods
|
||||||
}
|
}
|
||||||
NodeTypeId::Element(ElementTypeId::HTMLElement(HTMLElementTypeId::HTMLFieldSetElement)) => {
|
NodeTypeId::Element(ElementTypeId::HTMLElement(HTMLElementTypeId::HTMLFieldSetElement)) => {
|
||||||
let element = HTMLFieldSetElementCast::to_ref(node).unwrap();
|
let element = node.downcast::<HTMLFieldSetElement>().unwrap();
|
||||||
element as &VirtualMethods
|
element as &VirtualMethods
|
||||||
}
|
}
|
||||||
NodeTypeId::Element(ElementTypeId::HTMLElement(HTMLElementTypeId::HTMLFontElement)) => {
|
NodeTypeId::Element(ElementTypeId::HTMLElement(HTMLElementTypeId::HTMLFontElement)) => {
|
||||||
let element = HTMLFontElementCast::to_ref(node).unwrap();
|
let element = node.downcast::<HTMLFontElement>().unwrap();
|
||||||
element as &VirtualMethods
|
element as &VirtualMethods
|
||||||
}
|
}
|
||||||
NodeTypeId::Element(ElementTypeId::HTMLElement(HTMLElementTypeId::HTMLFormElement)) => {
|
NodeTypeId::Element(ElementTypeId::HTMLElement(HTMLElementTypeId::HTMLFormElement)) => {
|
||||||
let element = HTMLFormElementCast::to_ref(node).unwrap();
|
let element = node.downcast::<HTMLFormElement>().unwrap();
|
||||||
element as &VirtualMethods
|
element as &VirtualMethods
|
||||||
}
|
}
|
||||||
NodeTypeId::Element(ElementTypeId::HTMLElement(HTMLElementTypeId::HTMLHeadElement)) => {
|
NodeTypeId::Element(ElementTypeId::HTMLElement(HTMLElementTypeId::HTMLHeadElement)) => {
|
||||||
let element = HTMLHeadElementCast::to_ref(node).unwrap();
|
let element = node.downcast::<HTMLHeadElement>().unwrap();
|
||||||
element as &VirtualMethods
|
element as &VirtualMethods
|
||||||
}
|
}
|
||||||
NodeTypeId::Element(ElementTypeId::HTMLElement(HTMLElementTypeId::HTMLImageElement)) => {
|
NodeTypeId::Element(ElementTypeId::HTMLElement(HTMLElementTypeId::HTMLImageElement)) => {
|
||||||
let element = HTMLImageElementCast::to_ref(node).unwrap();
|
let element = node.downcast::<HTMLImageElement>().unwrap();
|
||||||
element as &VirtualMethods
|
element as &VirtualMethods
|
||||||
}
|
}
|
||||||
NodeTypeId::Element(ElementTypeId::HTMLElement(HTMLElementTypeId::HTMLIFrameElement)) => {
|
NodeTypeId::Element(ElementTypeId::HTMLElement(HTMLElementTypeId::HTMLIFrameElement)) => {
|
||||||
let element = HTMLIFrameElementCast::to_ref(node).unwrap();
|
let element = node.downcast::<HTMLIFrameElement>().unwrap();
|
||||||
element as &VirtualMethods
|
element as &VirtualMethods
|
||||||
}
|
}
|
||||||
NodeTypeId::Element(ElementTypeId::HTMLElement(HTMLElementTypeId::HTMLInputElement)) => {
|
NodeTypeId::Element(ElementTypeId::HTMLElement(HTMLElementTypeId::HTMLInputElement)) => {
|
||||||
let element = HTMLInputElementCast::to_ref(node).unwrap();
|
let element = node.downcast::<HTMLInputElement>().unwrap();
|
||||||
element as &VirtualMethods
|
element as &VirtualMethods
|
||||||
}
|
}
|
||||||
NodeTypeId::Element(ElementTypeId::HTMLElement(HTMLElementTypeId::HTMLLinkElement)) => {
|
NodeTypeId::Element(ElementTypeId::HTMLElement(HTMLElementTypeId::HTMLLinkElement)) => {
|
||||||
let element = HTMLLinkElementCast::to_ref(node).unwrap();
|
let element = node.downcast::<HTMLLinkElement>().unwrap();
|
||||||
element as &VirtualMethods
|
element as &VirtualMethods
|
||||||
}
|
}
|
||||||
NodeTypeId::Element(ElementTypeId::HTMLElement(HTMLElementTypeId::HTMLMetaElement)) => {
|
NodeTypeId::Element(ElementTypeId::HTMLElement(HTMLElementTypeId::HTMLMetaElement)) => {
|
||||||
let element = HTMLMetaElementCast::to_ref(node).unwrap();
|
let element = node.downcast::<HTMLMetaElement>().unwrap();
|
||||||
element as &VirtualMethods
|
element as &VirtualMethods
|
||||||
}
|
}
|
||||||
NodeTypeId::Element(ElementTypeId::HTMLElement(HTMLElementTypeId::HTMLObjectElement)) => {
|
NodeTypeId::Element(ElementTypeId::HTMLElement(HTMLElementTypeId::HTMLObjectElement)) => {
|
||||||
let element = HTMLObjectElementCast::to_ref(node).unwrap();
|
let element = node.downcast::<HTMLObjectElement>().unwrap();
|
||||||
element as &VirtualMethods
|
element as &VirtualMethods
|
||||||
}
|
}
|
||||||
NodeTypeId::Element(ElementTypeId::HTMLElement(HTMLElementTypeId::HTMLOptGroupElement)) => {
|
NodeTypeId::Element(ElementTypeId::HTMLElement(HTMLElementTypeId::HTMLOptGroupElement)) => {
|
||||||
let element = HTMLOptGroupElementCast::to_ref(node).unwrap();
|
let element = node.downcast::<HTMLOptGroupElement>().unwrap();
|
||||||
element as &VirtualMethods
|
element as &VirtualMethods
|
||||||
}
|
}
|
||||||
NodeTypeId::Element(ElementTypeId::HTMLElement(HTMLElementTypeId::HTMLOptionElement)) => {
|
NodeTypeId::Element(ElementTypeId::HTMLElement(HTMLElementTypeId::HTMLOptionElement)) => {
|
||||||
let element = HTMLOptionElementCast::to_ref(node).unwrap();
|
let element = node.downcast::<HTMLOptionElement>().unwrap();
|
||||||
element as &VirtualMethods
|
element as &VirtualMethods
|
||||||
}
|
}
|
||||||
NodeTypeId::Element(ElementTypeId::HTMLElement(HTMLElementTypeId::HTMLScriptElement)) => {
|
NodeTypeId::Element(ElementTypeId::HTMLElement(HTMLElementTypeId::HTMLScriptElement)) => {
|
||||||
let element = HTMLScriptElementCast::to_ref(node).unwrap();
|
let element = node.downcast::<HTMLScriptElement>().unwrap();
|
||||||
element as &VirtualMethods
|
element as &VirtualMethods
|
||||||
}
|
}
|
||||||
NodeTypeId::Element(ElementTypeId::HTMLElement(HTMLElementTypeId::HTMLSelectElement)) => {
|
NodeTypeId::Element(ElementTypeId::HTMLElement(HTMLElementTypeId::HTMLSelectElement)) => {
|
||||||
let element = HTMLSelectElementCast::to_ref(node).unwrap();
|
let element = node.downcast::<HTMLSelectElement>().unwrap();
|
||||||
element as &VirtualMethods
|
element as &VirtualMethods
|
||||||
}
|
}
|
||||||
NodeTypeId::Element(ElementTypeId::HTMLElement(HTMLElementTypeId::HTMLStyleElement)) => {
|
NodeTypeId::Element(ElementTypeId::HTMLElement(HTMLElementTypeId::HTMLStyleElement)) => {
|
||||||
let element = HTMLStyleElementCast::to_ref(node).unwrap();
|
let element = node.downcast::<HTMLStyleElement>().unwrap();
|
||||||
element as &VirtualMethods
|
element as &VirtualMethods
|
||||||
}
|
}
|
||||||
NodeTypeId::Element(ElementTypeId::HTMLElement(HTMLElementTypeId::HTMLTableElement)) => {
|
NodeTypeId::Element(ElementTypeId::HTMLElement(HTMLElementTypeId::HTMLTableElement)) => {
|
||||||
let element =
|
let element =
|
||||||
HTMLTableElementCast::to_ref(node).unwrap();
|
node.downcast::<HTMLTableElement>().unwrap();
|
||||||
element as &VirtualMethods
|
element as &VirtualMethods
|
||||||
}
|
}
|
||||||
NodeTypeId::Element(ElementTypeId::HTMLElement(HTMLElementTypeId::HTMLTableCellElement(_))) => {
|
NodeTypeId::Element(ElementTypeId::HTMLElement(HTMLElementTypeId::HTMLTableCellElement(_))) => {
|
||||||
let element =
|
let element =
|
||||||
HTMLTableCellElementCast::to_ref(node).unwrap();
|
node.downcast::<HTMLTableCellElement>().unwrap();
|
||||||
element as &VirtualMethods
|
element as &VirtualMethods
|
||||||
}
|
}
|
||||||
NodeTypeId::Element(ElementTypeId::HTMLElement(HTMLElementTypeId::HTMLTableRowElement)) => {
|
NodeTypeId::Element(ElementTypeId::HTMLElement(HTMLElementTypeId::HTMLTableRowElement)) => {
|
||||||
let element =
|
let element =
|
||||||
HTMLTableRowElementCast::to_ref(node).unwrap();
|
node.downcast::<HTMLTableRowElement>().unwrap();
|
||||||
element as &VirtualMethods
|
element as &VirtualMethods
|
||||||
}
|
}
|
||||||
NodeTypeId::Element(ElementTypeId::HTMLElement(HTMLElementTypeId::HTMLTableSectionElement)) => {
|
NodeTypeId::Element(ElementTypeId::HTMLElement(HTMLElementTypeId::HTMLTableSectionElement)) => {
|
||||||
let element =
|
let element =
|
||||||
HTMLTableSectionElementCast::to_ref(node).unwrap();
|
node.downcast::<HTMLTableSectionElement>().unwrap();
|
||||||
element as &VirtualMethods
|
element as &VirtualMethods
|
||||||
}
|
}
|
||||||
NodeTypeId::Element(ElementTypeId::HTMLElement(HTMLElementTypeId::HTMLTemplateElement)) => {
|
NodeTypeId::Element(ElementTypeId::HTMLElement(HTMLElementTypeId::HTMLTemplateElement)) => {
|
||||||
HTMLTemplateElementCast::to_ref(node).unwrap() as &VirtualMethods
|
node.downcast::<HTMLTemplateElement>().unwrap() as &VirtualMethods
|
||||||
}
|
}
|
||||||
NodeTypeId::Element(ElementTypeId::HTMLElement(HTMLElementTypeId::HTMLTextAreaElement)) => {
|
NodeTypeId::Element(ElementTypeId::HTMLElement(HTMLElementTypeId::HTMLTextAreaElement)) => {
|
||||||
let element = HTMLTextAreaElementCast::to_ref(node).unwrap();
|
let element = node.downcast::<HTMLTextAreaElement>().unwrap();
|
||||||
element as &VirtualMethods
|
element as &VirtualMethods
|
||||||
}
|
}
|
||||||
NodeTypeId::Element(ElementTypeId::HTMLElement(HTMLElementTypeId::HTMLTitleElement)) => {
|
NodeTypeId::Element(ElementTypeId::HTMLElement(HTMLElementTypeId::HTMLTitleElement)) => {
|
||||||
let element =
|
let element =
|
||||||
HTMLTitleElementCast::to_ref(node).unwrap();
|
node.downcast::<HTMLTitleElement>().unwrap();
|
||||||
element as &VirtualMethods
|
element as &VirtualMethods
|
||||||
}
|
}
|
||||||
NodeTypeId::Element(ElementTypeId::Element) => {
|
NodeTypeId::Element(ElementTypeId::Element) => {
|
||||||
let element = ElementCast::to_ref(node).unwrap();
|
let element = node.downcast::<Element>().unwrap();
|
||||||
element as &VirtualMethods
|
element as &VirtualMethods
|
||||||
}
|
}
|
||||||
NodeTypeId::Element(_) => {
|
NodeTypeId::Element(_) => {
|
||||||
let element = HTMLElementCast::to_ref(node).unwrap();
|
let element = node.downcast::<HTMLElement>().unwrap();
|
||||||
element as &VirtualMethods
|
element as &VirtualMethods
|
||||||
}
|
}
|
||||||
_ => {
|
_ => {
|
||||||
|
|
|
@ -6,10 +6,10 @@ use dom::bindings::codegen::Bindings::EventBinding::EventMethods;
|
||||||
use dom::bindings::codegen::Bindings::WebGLContextEventBinding;
|
use dom::bindings::codegen::Bindings::WebGLContextEventBinding;
|
||||||
use dom::bindings::codegen::Bindings::WebGLContextEventBinding::WebGLContextEventInit;
|
use dom::bindings::codegen::Bindings::WebGLContextEventBinding::WebGLContextEventInit;
|
||||||
use dom::bindings::codegen::Bindings::WebGLContextEventBinding::WebGLContextEventMethods;
|
use dom::bindings::codegen::Bindings::WebGLContextEventBinding::WebGLContextEventMethods;
|
||||||
use dom::bindings::codegen::InheritTypes::EventCast;
|
use dom::bindings::conversions::Castable;
|
||||||
use dom::bindings::error::Fallible;
|
use dom::bindings::error::Fallible;
|
||||||
use dom::bindings::global::GlobalRef;
|
use dom::bindings::global::GlobalRef;
|
||||||
use dom::bindings::js::{Root, RootedReference};
|
use dom::bindings::js::Root;
|
||||||
use dom::bindings::utils::reflect_dom_object;
|
use dom::bindings::utils::reflect_dom_object;
|
||||||
use dom::event::{Event, EventBubbles, EventCancelable};
|
use dom::event::{Event, EventBubbles, EventCancelable};
|
||||||
use util::str::DOMString;
|
use util::str::DOMString;
|
||||||
|
@ -46,7 +46,7 @@ impl WebGLContextEvent {
|
||||||
WebGLContextEventBinding::Wrap);
|
WebGLContextEventBinding::Wrap);
|
||||||
|
|
||||||
{
|
{
|
||||||
let parent = EventCast::from_ref(event.r());
|
let parent = event.upcast::<Event>();
|
||||||
parent.InitEvent(type_, bubbles == EventBubbles::Bubbles, cancelable == EventCancelable::Cancelable);
|
parent.InitEvent(type_, bubbles == EventBubbles::Bubbles, cancelable == EventCancelable::Cancelable);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -8,16 +8,16 @@ use canvas_traits::{WebGLFramebufferBindingRequest, WebGLShaderParameter};
|
||||||
use dom::bindings::codegen::Bindings::WebGLRenderingContextBinding::WebGLRenderingContextConstants as constants;
|
use dom::bindings::codegen::Bindings::WebGLRenderingContextBinding::WebGLRenderingContextConstants as constants;
|
||||||
use dom::bindings::codegen::Bindings::WebGLRenderingContextBinding::{WebGLRenderingContextMethods};
|
use dom::bindings::codegen::Bindings::WebGLRenderingContextBinding::{WebGLRenderingContextMethods};
|
||||||
use dom::bindings::codegen::Bindings::WebGLRenderingContextBinding::{self, WebGLContextAttributes};
|
use dom::bindings::codegen::Bindings::WebGLRenderingContextBinding::{self, WebGLContextAttributes};
|
||||||
use dom::bindings::codegen::InheritTypes::{EventCast, EventTargetCast, NodeCast};
|
|
||||||
use dom::bindings::codegen::UnionTypes::ImageDataOrHTMLImageElementOrHTMLCanvasElementOrHTMLVideoElement;
|
use dom::bindings::codegen::UnionTypes::ImageDataOrHTMLImageElementOrHTMLCanvasElementOrHTMLVideoElement;
|
||||||
use dom::bindings::conversions::ToJSValConvertible;
|
use dom::bindings::conversions::{Castable, ToJSValConvertible};
|
||||||
use dom::bindings::global::{GlobalField, GlobalRef};
|
use dom::bindings::global::{GlobalField, GlobalRef};
|
||||||
use dom::bindings::js::{JS, LayoutJS, MutNullableHeap, Root};
|
use dom::bindings::js::{JS, LayoutJS, MutNullableHeap, Root};
|
||||||
use dom::bindings::utils::{Reflector, reflect_dom_object};
|
use dom::bindings::utils::{Reflector, reflect_dom_object};
|
||||||
use dom::event::{EventBubbles, EventCancelable};
|
use dom::event::{Event, EventBubbles, EventCancelable};
|
||||||
|
use dom::eventtarget::EventTarget;
|
||||||
use dom::htmlcanvaselement::HTMLCanvasElement;
|
use dom::htmlcanvaselement::HTMLCanvasElement;
|
||||||
use dom::htmlcanvaselement::utils as canvas_utils;
|
use dom::htmlcanvaselement::utils as canvas_utils;
|
||||||
use dom::node::{NodeDamage, window_from_node};
|
use dom::node::{Node, NodeDamage, window_from_node};
|
||||||
use dom::webglbuffer::WebGLBuffer;
|
use dom::webglbuffer::WebGLBuffer;
|
||||||
use dom::webglcontextevent::WebGLContextEvent;
|
use dom::webglcontextevent::WebGLContextEvent;
|
||||||
use dom::webglframebuffer::WebGLFramebuffer;
|
use dom::webglframebuffer::WebGLFramebuffer;
|
||||||
|
@ -121,11 +121,7 @@ impl WebGLRenderingContext {
|
||||||
EventBubbles::DoesNotBubble,
|
EventBubbles::DoesNotBubble,
|
||||||
EventCancelable::Cancelable,
|
EventCancelable::Cancelable,
|
||||||
msg);
|
msg);
|
||||||
|
event.upcast::<Event>().fire(canvas.upcast::<EventTarget>());
|
||||||
let event = EventCast::from_ref(event.r());
|
|
||||||
let target = EventTargetCast::from_ref(canvas);
|
|
||||||
|
|
||||||
event.fire(target);
|
|
||||||
None
|
None
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -158,7 +154,7 @@ impl WebGLRenderingContext {
|
||||||
|
|
||||||
fn mark_as_dirty(&self) {
|
fn mark_as_dirty(&self) {
|
||||||
let canvas = self.canvas.root();
|
let canvas = self.canvas.root();
|
||||||
let node = NodeCast::from_ref(canvas.r());
|
let node = canvas.upcast::<Node>();
|
||||||
node.dirty(NodeDamage::OtherNodeDamage);
|
node.dirty(NodeDamage::OtherNodeDamage);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,9 +6,7 @@ use dom::bindings::cell::DOMRefCell;
|
||||||
use dom::bindings::codegen::Bindings::EventHandlerBinding::EventHandlerNonNull;
|
use dom::bindings::codegen::Bindings::EventHandlerBinding::EventHandlerNonNull;
|
||||||
use dom::bindings::codegen::Bindings::WebSocketBinding;
|
use dom::bindings::codegen::Bindings::WebSocketBinding;
|
||||||
use dom::bindings::codegen::Bindings::WebSocketBinding::{BinaryType, WebSocketMethods};
|
use dom::bindings::codegen::Bindings::WebSocketBinding::{BinaryType, WebSocketMethods};
|
||||||
use dom::bindings::codegen::InheritTypes::EventCast;
|
use dom::bindings::conversions::{Castable, ToJSValConvertible};
|
||||||
use dom::bindings::codegen::InheritTypes::EventTargetCast;
|
|
||||||
use dom::bindings::conversions::ToJSValConvertible;
|
|
||||||
use dom::bindings::error::{Error, Fallible};
|
use dom::bindings::error::{Error, Fallible};
|
||||||
use dom::bindings::global::{GlobalField, GlobalRef};
|
use dom::bindings::global::{GlobalField, GlobalRef};
|
||||||
use dom::bindings::js::Root;
|
use dom::bindings::js::Root;
|
||||||
|
@ -456,7 +454,7 @@ impl Runnable for ConnectionEstablishedTask {
|
||||||
let event = Event::new(global.r(), "open".to_owned(),
|
let event = Event::new(global.r(), "open".to_owned(),
|
||||||
EventBubbles::DoesNotBubble,
|
EventBubbles::DoesNotBubble,
|
||||||
EventCancelable::NotCancelable);
|
EventCancelable::NotCancelable);
|
||||||
event.fire(EventTargetCast::from_ref(ws.r()));
|
event.fire(ws.upcast::<EventTarget>());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -498,7 +496,7 @@ impl Runnable for CloseTask {
|
||||||
"error".to_owned(),
|
"error".to_owned(),
|
||||||
EventBubbles::DoesNotBubble,
|
EventBubbles::DoesNotBubble,
|
||||||
EventCancelable::Cancelable);
|
EventCancelable::Cancelable);
|
||||||
let target = EventTargetCast::from_ref(ws);
|
let target = ws.upcast::<EventTarget>();
|
||||||
event.r().fire(target);
|
event.r().fire(target);
|
||||||
}
|
}
|
||||||
let rsn = ws.reason.borrow();
|
let rsn = ws.reason.borrow();
|
||||||
|
@ -513,8 +511,8 @@ impl Runnable for CloseTask {
|
||||||
ws.clean_close.get(),
|
ws.clean_close.get(),
|
||||||
ws.code.get(),
|
ws.code.get(),
|
||||||
rsn_clone);
|
rsn_clone);
|
||||||
let target = EventTargetCast::from_ref(ws);
|
let target = ws.upcast::<EventTarget>();
|
||||||
let event = EventCast::from_ref(close_event.r());
|
let event = close_event.upcast::<Event>();
|
||||||
event.fire(target);
|
event.fire(target);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -564,7 +562,7 @@ impl Runnable for MessageReceivedTask {
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
let target = EventTargetCast::from_ref(ws.r());
|
let target = ws.upcast::<EventTarget>();
|
||||||
MessageEvent::dispatch_jsval(target, global.r(), message.handle());
|
MessageEvent::dispatch_jsval(target, global.r(), message.handle());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -11,7 +11,7 @@ use dom::bindings::codegen::Bindings::EventHandlerBinding::{EventHandlerNonNull,
|
||||||
use dom::bindings::codegen::Bindings::FunctionBinding::Function;
|
use dom::bindings::codegen::Bindings::FunctionBinding::Function;
|
||||||
use dom::bindings::codegen::Bindings::WindowBinding::{ScrollBehavior, ScrollToOptions};
|
use dom::bindings::codegen::Bindings::WindowBinding::{ScrollBehavior, ScrollToOptions};
|
||||||
use dom::bindings::codegen::Bindings::WindowBinding::{self, FrameRequestCallback, WindowMethods};
|
use dom::bindings::codegen::Bindings::WindowBinding::{self, FrameRequestCallback, WindowMethods};
|
||||||
use dom::bindings::codegen::InheritTypes::{ElementCast, EventTargetCast, NodeCast};
|
use dom::bindings::conversions::Castable;
|
||||||
use dom::bindings::error::{Error, Fallible, report_pending_exception};
|
use dom::bindings::error::{Error, Fallible, report_pending_exception};
|
||||||
use dom::bindings::global::GlobalRef;
|
use dom::bindings::global::GlobalRef;
|
||||||
use dom::bindings::global::global_object_for_js_object;
|
use dom::bindings::global::global_object_for_js_object;
|
||||||
|
@ -28,7 +28,7 @@ use dom::element::Element;
|
||||||
use dom::eventtarget::EventTarget;
|
use dom::eventtarget::EventTarget;
|
||||||
use dom::location::Location;
|
use dom::location::Location;
|
||||||
use dom::navigator::Navigator;
|
use dom::navigator::Navigator;
|
||||||
use dom::node::{TrustedNodeAddress, from_untrusted_node_address, window_from_node};
|
use dom::node::{Node, TrustedNodeAddress, from_untrusted_node_address, window_from_node};
|
||||||
use dom::performance::Performance;
|
use dom::performance::Performance;
|
||||||
use dom::screen::Screen;
|
use dom::screen::Screen;
|
||||||
use dom::storage::Storage;
|
use dom::storage::Storage;
|
||||||
|
@ -794,7 +794,7 @@ impl<'a, T: Reflectable> ScriptHelpers for &'a T {
|
||||||
impl Window {
|
impl Window {
|
||||||
pub fn clear_js_runtime(&self) {
|
pub fn clear_js_runtime(&self) {
|
||||||
let document = self.Document();
|
let document = self.Document();
|
||||||
NodeCast::from_ref(document.r()).teardown();
|
document.upcast::<Node>().teardown();
|
||||||
|
|
||||||
// The above code may not catch all DOM objects
|
// The above code may not catch all DOM objects
|
||||||
// (e.g. DOM objects removed from the tree that haven't
|
// (e.g. DOM objects removed from the tree that haven't
|
||||||
|
@ -835,7 +835,7 @@ impl Window {
|
||||||
let body = self.Document().GetBody();
|
let body = self.Document().GetBody();
|
||||||
let (x, y) = match body {
|
let (x, y) = match body {
|
||||||
Some(e) => {
|
Some(e) => {
|
||||||
let node = NodeCast::from_ref(e.r());
|
let node = e.upcast::<Node>();
|
||||||
let content_size = node.get_bounding_content_box();
|
let content_size = node.get_bounding_content_box();
|
||||||
|
|
||||||
let content_height = content_size.size.height.to_f64_px();
|
let content_height = content_size.size.height.to_f64_px();
|
||||||
|
@ -901,7 +901,7 @@ impl Window {
|
||||||
Some(root) => root,
|
Some(root) => root,
|
||||||
None => return,
|
None => return,
|
||||||
};
|
};
|
||||||
let root = NodeCast::from_ref(root);
|
let root = root.upcast::<Node>();
|
||||||
|
|
||||||
let window_size = match self.window_size.get() {
|
let window_size = match self.window_size.get() {
|
||||||
Some(window_size) => window_size,
|
Some(window_size) => window_size,
|
||||||
|
@ -973,7 +973,7 @@ impl Window {
|
||||||
None => return,
|
None => return,
|
||||||
};
|
};
|
||||||
|
|
||||||
let root = NodeCast::from_ref(root);
|
let root = root.upcast::<Node>();
|
||||||
if query_type == ReflowQueryType::NoQuery && !root.get_has_dirty_descendants() {
|
if query_type == ReflowQueryType::NoQuery && !root.get_has_dirty_descendants() {
|
||||||
debug!("root has no dirty descendants; avoiding reflow (reason {:?})", reason);
|
debug!("root has no dirty descendants; avoiding reflow (reason {:?})", reason);
|
||||||
return
|
return
|
||||||
|
@ -1055,7 +1055,7 @@ impl Window {
|
||||||
let js_runtime = js_runtime.as_ref().unwrap();
|
let js_runtime = js_runtime.as_ref().unwrap();
|
||||||
let element = response.node_address.and_then(|parent_node_address| {
|
let element = response.node_address.and_then(|parent_node_address| {
|
||||||
let node = from_untrusted_node_address(js_runtime.rt(), parent_node_address);
|
let node = from_untrusted_node_address(js_runtime.rt(), parent_node_address);
|
||||||
ElementCast::to_root(node)
|
Root::downcast::<Element>(node)
|
||||||
});
|
});
|
||||||
(element, response.rect)
|
(element, response.rect)
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,7 +6,7 @@ use devtools_traits::{DevtoolsPageInfo, ScriptToDevtoolsControlMsg};
|
||||||
use dom::bindings::codegen::Bindings::EventHandlerBinding::EventHandlerNonNull;
|
use dom::bindings::codegen::Bindings::EventHandlerBinding::EventHandlerNonNull;
|
||||||
use dom::bindings::codegen::Bindings::WorkerBinding;
|
use dom::bindings::codegen::Bindings::WorkerBinding;
|
||||||
use dom::bindings::codegen::Bindings::WorkerBinding::WorkerMethods;
|
use dom::bindings::codegen::Bindings::WorkerBinding::WorkerMethods;
|
||||||
use dom::bindings::codegen::InheritTypes::{EventCast, EventTargetCast};
|
use dom::bindings::conversions::Castable;
|
||||||
use dom::bindings::error::{Error, ErrorResult, Fallible};
|
use dom::bindings::error::{Error, ErrorResult, Fallible};
|
||||||
use dom::bindings::global::{GlobalField, GlobalRef};
|
use dom::bindings::global::{GlobalField, GlobalRef};
|
||||||
use dom::bindings::js::Root;
|
use dom::bindings::js::Root;
|
||||||
|
@ -115,7 +115,7 @@ impl Worker {
|
||||||
let worker = address.root();
|
let worker = address.root();
|
||||||
|
|
||||||
let global = worker.r().global.root();
|
let global = worker.r().global.root();
|
||||||
let target = EventTargetCast::from_ref(worker.r());
|
let target = worker.upcast::<EventTarget>();
|
||||||
let _ar = JSAutoRequest::new(global.r().get_cx());
|
let _ar = JSAutoRequest::new(global.r().get_cx());
|
||||||
let _ac = JSAutoCompartment::new(global.r().get_cx(), target.reflector().get_jsobject().get());
|
let _ac = JSAutoCompartment::new(global.r().get_cx(), target.reflector().get_jsobject().get());
|
||||||
let mut message = RootedValue::new(global.r().get_cx(), UndefinedValue());
|
let mut message = RootedValue::new(global.r().get_cx(), UndefinedValue());
|
||||||
|
@ -126,7 +126,7 @@ impl Worker {
|
||||||
pub fn dispatch_simple_error(address: TrustedWorkerAddress) {
|
pub fn dispatch_simple_error(address: TrustedWorkerAddress) {
|
||||||
let worker = address.root();
|
let worker = address.root();
|
||||||
let global = worker.r().global.root();
|
let global = worker.r().global.root();
|
||||||
let target = EventTargetCast::from_ref(worker.r());
|
let target = worker.upcast::<EventTarget>();
|
||||||
|
|
||||||
let event = Event::new(global.r(),
|
let event = Event::new(global.r(),
|
||||||
"error".to_owned(),
|
"error".to_owned(),
|
||||||
|
@ -140,11 +140,11 @@ impl Worker {
|
||||||
let worker = address.root();
|
let worker = address.root();
|
||||||
let global = worker.r().global.root();
|
let global = worker.r().global.root();
|
||||||
let error = RootedValue::new(global.r().get_cx(), UndefinedValue());
|
let error = RootedValue::new(global.r().get_cx(), UndefinedValue());
|
||||||
let target = EventTargetCast::from_ref(worker.r());
|
let target = worker.upcast::<EventTarget>();
|
||||||
let errorevent = ErrorEvent::new(global.r(), "error".to_owned(),
|
let errorevent = ErrorEvent::new(global.r(), "error".to_owned(),
|
||||||
EventBubbles::Bubbles, EventCancelable::Cancelable,
|
EventBubbles::Bubbles, EventCancelable::Cancelable,
|
||||||
message, filename, lineno, colno, error.handle());
|
message, filename, lineno, colno, error.handle());
|
||||||
let event = EventCast::from_ref(errorevent.r());
|
let event = errorevent.upcast::<Event>();
|
||||||
event.fire(target);
|
event.fire(target);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,13 +5,14 @@
|
||||||
use devtools_traits::{DevtoolScriptControlMsg, ScriptToDevtoolsControlMsg};
|
use devtools_traits::{DevtoolScriptControlMsg, ScriptToDevtoolsControlMsg};
|
||||||
use dom::bindings::codegen::Bindings::FunctionBinding::Function;
|
use dom::bindings::codegen::Bindings::FunctionBinding::Function;
|
||||||
use dom::bindings::codegen::Bindings::WorkerGlobalScopeBinding::WorkerGlobalScopeMethods;
|
use dom::bindings::codegen::Bindings::WorkerGlobalScopeBinding::WorkerGlobalScopeMethods;
|
||||||
use dom::bindings::codegen::InheritTypes::DedicatedWorkerGlobalScopeCast;
|
use dom::bindings::conversions::Castable;
|
||||||
use dom::bindings::error::{Error, ErrorResult, Fallible, report_pending_exception};
|
use dom::bindings::error::{Error, ErrorResult, Fallible, report_pending_exception};
|
||||||
use dom::bindings::global::GlobalRef;
|
use dom::bindings::global::GlobalRef;
|
||||||
use dom::bindings::js::{JS, MutNullableHeap, Root};
|
use dom::bindings::js::{JS, MutNullableHeap, Root};
|
||||||
use dom::bindings::utils::Reflectable;
|
use dom::bindings::utils::Reflectable;
|
||||||
use dom::console::Console;
|
use dom::console::Console;
|
||||||
use dom::crypto::Crypto;
|
use dom::crypto::Crypto;
|
||||||
|
use dom::dedicatedworkerglobalscope::DedicatedWorkerGlobalScope;
|
||||||
use dom::eventtarget::EventTarget;
|
use dom::eventtarget::EventTarget;
|
||||||
use dom::window::{base64_atob, base64_btoa};
|
use dom::window::{base64_atob, base64_btoa};
|
||||||
use dom::workerlocation::WorkerLocation;
|
use dom::workerlocation::WorkerLocation;
|
||||||
|
@ -295,7 +296,7 @@ impl WorkerGlobalScope {
|
||||||
|
|
||||||
pub fn script_chan(&self) -> Box<ScriptChan + Send> {
|
pub fn script_chan(&self) -> Box<ScriptChan + Send> {
|
||||||
let dedicated =
|
let dedicated =
|
||||||
DedicatedWorkerGlobalScopeCast::to_ref(self);
|
self.downcast::<DedicatedWorkerGlobalScope>();
|
||||||
match dedicated {
|
match dedicated {
|
||||||
Some(dedicated) => dedicated.script_chan(),
|
Some(dedicated) => dedicated.script_chan(),
|
||||||
None => panic!("need to implement a sender for SharedWorker"),
|
None => panic!("need to implement a sender for SharedWorker"),
|
||||||
|
@ -304,7 +305,7 @@ impl WorkerGlobalScope {
|
||||||
|
|
||||||
pub fn pipeline(&self) -> PipelineId {
|
pub fn pipeline(&self) -> PipelineId {
|
||||||
let dedicated =
|
let dedicated =
|
||||||
DedicatedWorkerGlobalScopeCast::to_ref(self);
|
self.downcast::<DedicatedWorkerGlobalScope>();
|
||||||
match dedicated {
|
match dedicated {
|
||||||
Some(dedicated) => dedicated.pipeline(),
|
Some(dedicated) => dedicated.pipeline(),
|
||||||
None => panic!("need to add a pipeline for SharedWorker"),
|
None => panic!("need to add a pipeline for SharedWorker"),
|
||||||
|
@ -313,7 +314,7 @@ impl WorkerGlobalScope {
|
||||||
|
|
||||||
pub fn new_script_pair(&self) -> (Box<ScriptChan + Send>, Box<ScriptPort + Send>) {
|
pub fn new_script_pair(&self) -> (Box<ScriptChan + Send>, Box<ScriptPort + Send>) {
|
||||||
let dedicated =
|
let dedicated =
|
||||||
DedicatedWorkerGlobalScopeCast::to_ref(self);
|
self.downcast::<DedicatedWorkerGlobalScope>();
|
||||||
match dedicated {
|
match dedicated {
|
||||||
Some(dedicated) => dedicated.new_script_pair(),
|
Some(dedicated) => dedicated.new_script_pair(),
|
||||||
None => panic!("need to implement creating isolated event loops for SharedWorker"),
|
None => panic!("need to implement creating isolated event loops for SharedWorker"),
|
||||||
|
@ -322,7 +323,7 @@ impl WorkerGlobalScope {
|
||||||
|
|
||||||
pub fn process_event(&self, msg: CommonScriptMsg) {
|
pub fn process_event(&self, msg: CommonScriptMsg) {
|
||||||
let dedicated =
|
let dedicated =
|
||||||
DedicatedWorkerGlobalScopeCast::to_ref(self);
|
self.downcast::<DedicatedWorkerGlobalScope>();
|
||||||
match dedicated {
|
match dedicated {
|
||||||
Some(dedicated) => dedicated.process_event(msg),
|
Some(dedicated) => dedicated.process_event(msg),
|
||||||
None => panic!("need to implement processing single events for SharedWorker"),
|
None => panic!("need to implement processing single events for SharedWorker"),
|
||||||
|
|
|
@ -10,10 +10,9 @@ use dom::bindings::codegen::Bindings::XMLHttpRequestBinding;
|
||||||
use dom::bindings::codegen::Bindings::XMLHttpRequestBinding::XMLHttpRequestMethods;
|
use dom::bindings::codegen::Bindings::XMLHttpRequestBinding::XMLHttpRequestMethods;
|
||||||
use dom::bindings::codegen::Bindings::XMLHttpRequestBinding::XMLHttpRequestResponseType;
|
use dom::bindings::codegen::Bindings::XMLHttpRequestBinding::XMLHttpRequestResponseType;
|
||||||
use dom::bindings::codegen::Bindings::XMLHttpRequestBinding::XMLHttpRequestResponseType::{Json, Text, _empty};
|
use dom::bindings::codegen::Bindings::XMLHttpRequestBinding::XMLHttpRequestResponseType::{Json, Text, _empty};
|
||||||
use dom::bindings::codegen::InheritTypes::{EventCast, EventTargetCast};
|
|
||||||
use dom::bindings::codegen::UnionTypes::StringOrURLSearchParams;
|
use dom::bindings::codegen::UnionTypes::StringOrURLSearchParams;
|
||||||
use dom::bindings::codegen::UnionTypes::StringOrURLSearchParams::{eString, eURLSearchParams};
|
use dom::bindings::codegen::UnionTypes::StringOrURLSearchParams::{eString, eURLSearchParams};
|
||||||
use dom::bindings::conversions::ToJSValConvertible;
|
use dom::bindings::conversions::{Castable, ToJSValConvertible};
|
||||||
use dom::bindings::error::{Error, ErrorResult, Fallible};
|
use dom::bindings::error::{Error, ErrorResult, Fallible};
|
||||||
use dom::bindings::global::{GlobalField, GlobalRef, GlobalRoot};
|
use dom::bindings::global::{GlobalField, GlobalRef, GlobalRoot};
|
||||||
use dom::bindings::js::Root;
|
use dom::bindings::js::Root;
|
||||||
|
@ -23,6 +22,7 @@ use dom::bindings::str::ByteString;
|
||||||
use dom::bindings::utils::{Reflectable, reflect_dom_object};
|
use dom::bindings::utils::{Reflectable, reflect_dom_object};
|
||||||
use dom::document::Document;
|
use dom::document::Document;
|
||||||
use dom::event::{Event, EventBubbles, EventCancelable};
|
use dom::event::{Event, EventBubbles, EventCancelable};
|
||||||
|
use dom::eventtarget::EventTarget;
|
||||||
use dom::progressevent::ProgressEvent;
|
use dom::progressevent::ProgressEvent;
|
||||||
use dom::xmlhttprequesteventtarget::XMLHttpRequestEventTarget;
|
use dom::xmlhttprequesteventtarget::XMLHttpRequestEventTarget;
|
||||||
use dom::xmlhttprequestupload::XMLHttpRequestUpload;
|
use dom::xmlhttprequestupload::XMLHttpRequestUpload;
|
||||||
|
@ -493,7 +493,7 @@ impl XMLHttpRequestMethods for XMLHttpRequest {
|
||||||
|
|
||||||
if !self.sync.get() {
|
if !self.sync.get() {
|
||||||
// Step 8
|
// Step 8
|
||||||
let event_target = EventTargetCast::from_ref(&*self.upload);
|
let event_target = self.upload.upcast::<EventTarget>();
|
||||||
if event_target.has_handlers() {
|
if event_target.has_handlers() {
|
||||||
self.upload_events.set(true);
|
self.upload_events.set(true);
|
||||||
}
|
}
|
||||||
|
@ -737,7 +737,7 @@ impl XMLHttpRequest {
|
||||||
"readystatechange".to_owned(),
|
"readystatechange".to_owned(),
|
||||||
EventBubbles::DoesNotBubble,
|
EventBubbles::DoesNotBubble,
|
||||||
EventCancelable::Cancelable);
|
EventCancelable::Cancelable);
|
||||||
let target = EventTargetCast::from_ref(self);
|
let target = self.upcast::<EventTarget>();
|
||||||
event.r().fire(target);
|
event.r().fire(target);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -921,11 +921,11 @@ impl XMLHttpRequest {
|
||||||
total.is_some(), loaded,
|
total.is_some(), loaded,
|
||||||
total.unwrap_or(0));
|
total.unwrap_or(0));
|
||||||
let target = if upload {
|
let target = if upload {
|
||||||
EventTargetCast::from_ref(&*self.upload)
|
self.upload.upcast::<EventTarget>()
|
||||||
} else {
|
} else {
|
||||||
EventTargetCast::from_ref(self)
|
self.upcast::<EventTarget>()
|
||||||
};
|
};
|
||||||
let event = EventCast::from_ref(progressevent.r());
|
let event = progressevent.upcast::<Event>();
|
||||||
event.fire(target);
|
event.fire(target);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -4,7 +4,6 @@
|
||||||
|
|
||||||
use dom::bindings::codegen::Bindings::EventHandlerBinding::EventHandlerNonNull;
|
use dom::bindings::codegen::Bindings::EventHandlerBinding::EventHandlerNonNull;
|
||||||
use dom::bindings::codegen::Bindings::XMLHttpRequestEventTargetBinding::XMLHttpRequestEventTargetMethods;
|
use dom::bindings::codegen::Bindings::XMLHttpRequestEventTargetBinding::XMLHttpRequestEventTargetMethods;
|
||||||
use dom::bindings::codegen::InheritTypes::EventTargetCast;
|
|
||||||
use dom::eventtarget::EventTarget;
|
use dom::eventtarget::EventTarget;
|
||||||
|
|
||||||
#[dom_struct]
|
#[dom_struct]
|
||||||
|
|
|
@ -19,6 +19,7 @@
|
||||||
#![feature(iter_arith)]
|
#![feature(iter_arith)]
|
||||||
#![feature(mpsc_select)]
|
#![feature(mpsc_select)]
|
||||||
#![feature(nonzero)]
|
#![feature(nonzero)]
|
||||||
|
#![feature(on_unimplemented)]
|
||||||
#![feature(plugin)]
|
#![feature(plugin)]
|
||||||
#![feature(ref_slice)]
|
#![feature(ref_slice)]
|
||||||
#![feature(slice_patterns)]
|
#![feature(slice_patterns)]
|
||||||
|
|
|
@ -8,21 +8,22 @@ use document_loader::DocumentLoader;
|
||||||
use dom::bindings::codegen::Bindings::DocumentBinding::DocumentMethods;
|
use dom::bindings::codegen::Bindings::DocumentBinding::DocumentMethods;
|
||||||
use dom::bindings::codegen::Bindings::HTMLTemplateElementBinding::HTMLTemplateElementMethods;
|
use dom::bindings::codegen::Bindings::HTMLTemplateElementBinding::HTMLTemplateElementMethods;
|
||||||
use dom::bindings::codegen::Bindings::NodeBinding::NodeMethods;
|
use dom::bindings::codegen::Bindings::NodeBinding::NodeMethods;
|
||||||
use dom::bindings::codegen::InheritTypes::{CharacterDataCast, CharacterDataTypeId};
|
use dom::bindings::codegen::InheritTypes::{CharacterDataTypeId, NodeTypeId};
|
||||||
use dom::bindings::codegen::InheritTypes::{DocumentTypeCast, ElementCast};
|
use dom::bindings::conversions::Castable;
|
||||||
use dom::bindings::codegen::InheritTypes::{HTMLFormElementDerived, HTMLScriptElementCast};
|
|
||||||
use dom::bindings::codegen::InheritTypes::{HTMLTemplateElementCast, NodeCast};
|
|
||||||
use dom::bindings::codegen::InheritTypes::{NodeTypeId, ProcessingInstructionCast};
|
|
||||||
use dom::bindings::js::{JS, Root};
|
use dom::bindings::js::{JS, Root};
|
||||||
use dom::bindings::js::{RootedReference};
|
use dom::bindings::js::{RootedReference};
|
||||||
|
use dom::characterdata::CharacterData;
|
||||||
use dom::comment::Comment;
|
use dom::comment::Comment;
|
||||||
use dom::document::Document;
|
use dom::document::Document;
|
||||||
use dom::document::{DocumentSource, IsHTMLDocument};
|
use dom::document::{DocumentSource, IsHTMLDocument};
|
||||||
use dom::documenttype::DocumentType;
|
use dom::documenttype::DocumentType;
|
||||||
use dom::element::{Element, ElementCreator};
|
use dom::element::{Element, ElementCreator};
|
||||||
|
use dom::htmlformelement::HTMLFormElement;
|
||||||
use dom::htmlscriptelement::HTMLScriptElement;
|
use dom::htmlscriptelement::HTMLScriptElement;
|
||||||
|
use dom::htmltemplateelement::HTMLTemplateElement;
|
||||||
use dom::node::Node;
|
use dom::node::Node;
|
||||||
use dom::node::{document_from_node, window_from_node};
|
use dom::node::{document_from_node, window_from_node};
|
||||||
|
use dom::processinginstruction::ProcessingInstruction;
|
||||||
use dom::servohtmlparser;
|
use dom::servohtmlparser;
|
||||||
use dom::servohtmlparser::{FragmentContext, ServoHTMLParser};
|
use dom::servohtmlparser::{FragmentContext, ServoHTMLParser};
|
||||||
use encoding::types::Encoding;
|
use encoding::types::Encoding;
|
||||||
|
@ -45,15 +46,15 @@ impl<'a> TreeSink for servohtmlparser::Sink {
|
||||||
|
|
||||||
fn get_document(&mut self) -> JS<Node> {
|
fn get_document(&mut self) -> JS<Node> {
|
||||||
let doc = self.document.root();
|
let doc = self.document.root();
|
||||||
let node = NodeCast::from_ref(doc.r());
|
let node = doc.upcast::<Node>();
|
||||||
JS::from_ref(node)
|
JS::from_ref(node)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn get_template_contents(&self, target: JS<Node>) -> JS<Node> {
|
fn get_template_contents(&self, target: JS<Node>) -> JS<Node> {
|
||||||
let target = target.root();
|
let target = target.root();
|
||||||
let template = HTMLTemplateElementCast::to_ref(&*target)
|
let template = target.downcast::<HTMLTemplateElement>()
|
||||||
.expect("tried to get template contents of non-HTMLTemplateElement in HTML parsing");
|
.expect("tried to get template contents of non-HTMLTemplateElement in HTML parsing");
|
||||||
JS::from_ref(NodeCast::from_ref(&*template.Content()))
|
JS::from_ref(template.Content().upcast::<Node>())
|
||||||
}
|
}
|
||||||
|
|
||||||
fn same_node(&self, x: JS<Node>, y: JS<Node>) -> bool {
|
fn same_node(&self, x: JS<Node>, y: JS<Node>) -> bool {
|
||||||
|
@ -62,7 +63,7 @@ impl<'a> TreeSink for servohtmlparser::Sink {
|
||||||
|
|
||||||
fn elem_name(&self, target: JS<Node>) -> QualName {
|
fn elem_name(&self, target: JS<Node>) -> QualName {
|
||||||
let node: Root<Node> = target.root();
|
let node: Root<Node> = target.root();
|
||||||
let elem = ElementCast::to_ref(node.r())
|
let elem = node.downcast::<Element>()
|
||||||
.expect("tried to get name of non-Element in HTML parsing");
|
.expect("tried to get name of non-Element in HTML parsing");
|
||||||
QualName {
|
QualName {
|
||||||
ns: elem.namespace().clone(),
|
ns: elem.namespace().clone(),
|
||||||
|
@ -80,14 +81,14 @@ impl<'a> TreeSink for servohtmlparser::Sink {
|
||||||
elem.r().set_attribute_from_parser(attr.name, attr.value.into(), None);
|
elem.r().set_attribute_from_parser(attr.name, attr.value.into(), None);
|
||||||
}
|
}
|
||||||
|
|
||||||
let node = NodeCast::from_ref(elem.r());
|
let node = elem.upcast::<Node>();
|
||||||
JS::from_ref(node)
|
JS::from_ref(node)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn create_comment(&mut self, text: StrTendril) -> JS<Node> {
|
fn create_comment(&mut self, text: StrTendril) -> JS<Node> {
|
||||||
let doc = self.document.root();
|
let doc = self.document.root();
|
||||||
let comment = Comment::new(text.into(), doc.r());
|
let comment = Comment::new(text.into(), doc.r());
|
||||||
let node = NodeCast::from_root(comment);
|
let node = Root::upcast::<Node>(comment);
|
||||||
JS::from_rooted(&node)
|
JS::from_rooted(&node)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -126,17 +127,17 @@ impl<'a> TreeSink for servohtmlparser::Sink {
|
||||||
fn append_doctype_to_document(&mut self, name: StrTendril, public_id: StrTendril,
|
fn append_doctype_to_document(&mut self, name: StrTendril, public_id: StrTendril,
|
||||||
system_id: StrTendril) {
|
system_id: StrTendril) {
|
||||||
let doc = self.document.root();
|
let doc = self.document.root();
|
||||||
let doc_node = NodeCast::from_ref(doc.r());
|
let doc_node = doc.upcast::<Node>();
|
||||||
let doctype = DocumentType::new(
|
let doctype = DocumentType::new(
|
||||||
name.into(), Some(public_id.into()), Some(system_id.into()), doc.r());
|
name.into(), Some(public_id.into()), Some(system_id.into()), doc.r());
|
||||||
let node: Root<Node> = NodeCast::from_root(doctype);
|
let node: Root<Node> = Root::upcast::<Node>(doctype);
|
||||||
|
|
||||||
assert!(doc_node.AppendChild(node.r()).is_ok());
|
assert!(doc_node.AppendChild(node.r()).is_ok());
|
||||||
}
|
}
|
||||||
|
|
||||||
fn add_attrs_if_missing(&mut self, target: JS<Node>, attrs: Vec<Attribute>) {
|
fn add_attrs_if_missing(&mut self, target: JS<Node>, attrs: Vec<Attribute>) {
|
||||||
let node: Root<Node> = target.root();
|
let node: Root<Node> = target.root();
|
||||||
let elem = ElementCast::to_ref(node.r())
|
let elem = node.downcast::<Element>()
|
||||||
.expect("tried to set attrs on non-Element in HTML parsing");
|
.expect("tried to set attrs on non-Element in HTML parsing");
|
||||||
for attr in attrs {
|
for attr in attrs {
|
||||||
elem.set_attribute_from_parser(attr.name, attr.value.into(), None);
|
elem.set_attribute_from_parser(attr.name, attr.value.into(), None);
|
||||||
|
@ -152,13 +153,13 @@ impl<'a> TreeSink for servohtmlparser::Sink {
|
||||||
|
|
||||||
fn mark_script_already_started(&mut self, node: JS<Node>) {
|
fn mark_script_already_started(&mut self, node: JS<Node>) {
|
||||||
let node: Root<Node> = node.root();
|
let node: Root<Node> = node.root();
|
||||||
let script: Option<&HTMLScriptElement> = HTMLScriptElementCast::to_ref(node.r());
|
let script: Option<&HTMLScriptElement> = node.downcast::<HTMLScriptElement>();
|
||||||
script.map(|script| script.mark_already_started());
|
script.map(|script| script.mark_already_started());
|
||||||
}
|
}
|
||||||
|
|
||||||
fn complete_script(&mut self, node: JS<Node>) -> NextParserState {
|
fn complete_script(&mut self, node: JS<Node>) -> NextParserState {
|
||||||
let node: Root<Node> = node.root();
|
let node: Root<Node> = node.root();
|
||||||
let script: Option<&HTMLScriptElement> = HTMLScriptElementCast::to_ref(node.r());
|
let script: Option<&HTMLScriptElement> = node.downcast::<HTMLScriptElement>();
|
||||||
if let Some(script) = script {
|
if let Some(script) = script {
|
||||||
return script.prepare();
|
return script.prepare();
|
||||||
}
|
}
|
||||||
|
@ -183,7 +184,7 @@ impl<'a> Serializable for &'a Node {
|
||||||
let node = *self;
|
let node = *self;
|
||||||
match (traversal_scope, node.type_id()) {
|
match (traversal_scope, node.type_id()) {
|
||||||
(_, NodeTypeId::Element(..)) => {
|
(_, NodeTypeId::Element(..)) => {
|
||||||
let elem = ElementCast::to_ref(node).unwrap();
|
let elem = node.downcast::<Element>().unwrap();
|
||||||
let name = QualName::new(elem.namespace().clone(),
|
let name = QualName::new(elem.namespace().clone(),
|
||||||
elem.local_name().clone());
|
elem.local_name().clone());
|
||||||
if traversal_scope == IncludeNode {
|
if traversal_scope == IncludeNode {
|
||||||
|
@ -201,9 +202,9 @@ impl<'a> Serializable for &'a Node {
|
||||||
try!(serializer.start_elem(name.clone(), attr_refs));
|
try!(serializer.start_elem(name.clone(), attr_refs));
|
||||||
}
|
}
|
||||||
|
|
||||||
let children = if let Some(tpl) = HTMLTemplateElementCast::to_ref(node) {
|
let children = if let Some(tpl) = node.downcast::<HTMLTemplateElement>() {
|
||||||
// https://github.com/w3c/DOM-Parsing/issues/1
|
// https://github.com/w3c/DOM-Parsing/issues/1
|
||||||
NodeCast::from_ref(&*tpl.Content()).children()
|
tpl.Content().upcast::<Node>().children()
|
||||||
} else {
|
} else {
|
||||||
node.children()
|
node.children()
|
||||||
};
|
};
|
||||||
|
@ -228,23 +229,23 @@ impl<'a> Serializable for &'a Node {
|
||||||
(ChildrenOnly, _) => Ok(()),
|
(ChildrenOnly, _) => Ok(()),
|
||||||
|
|
||||||
(IncludeNode, NodeTypeId::DocumentType) => {
|
(IncludeNode, NodeTypeId::DocumentType) => {
|
||||||
let doctype = DocumentTypeCast::to_ref(node).unwrap();
|
let doctype = node.downcast::<DocumentType>().unwrap();
|
||||||
serializer.write_doctype(&doctype.name())
|
serializer.write_doctype(&doctype.name())
|
||||||
},
|
},
|
||||||
|
|
||||||
(IncludeNode, NodeTypeId::CharacterData(CharacterDataTypeId::Text)) => {
|
(IncludeNode, NodeTypeId::CharacterData(CharacterDataTypeId::Text)) => {
|
||||||
let cdata = CharacterDataCast::to_ref(node).unwrap();
|
let cdata = node.downcast::<CharacterData>().unwrap();
|
||||||
serializer.write_text(&cdata.data())
|
serializer.write_text(&cdata.data())
|
||||||
},
|
},
|
||||||
|
|
||||||
(IncludeNode, NodeTypeId::CharacterData(CharacterDataTypeId::Comment)) => {
|
(IncludeNode, NodeTypeId::CharacterData(CharacterDataTypeId::Comment)) => {
|
||||||
let cdata = CharacterDataCast::to_ref(node).unwrap();
|
let cdata = node.downcast::<CharacterData>().unwrap();
|
||||||
serializer.write_comment(&cdata.data())
|
serializer.write_comment(&cdata.data())
|
||||||
},
|
},
|
||||||
|
|
||||||
(IncludeNode, NodeTypeId::CharacterData(CharacterDataTypeId::ProcessingInstruction)) => {
|
(IncludeNode, NodeTypeId::CharacterData(CharacterDataTypeId::ProcessingInstruction)) => {
|
||||||
let pi = ProcessingInstructionCast::to_ref(node).unwrap();
|
let pi = node.downcast::<ProcessingInstruction>().unwrap();
|
||||||
let data = CharacterDataCast::from_ref(pi).data();
|
let data = pi.upcast::<CharacterData>().data();
|
||||||
serializer.write_processing_instruction(&pi.target(), &data)
|
serializer.write_processing_instruction(&pi.target(), &data)
|
||||||
},
|
},
|
||||||
|
|
||||||
|
@ -295,7 +296,7 @@ pub fn parse_html_fragment(context_node: &Node,
|
||||||
|
|
||||||
// Step 11.
|
// Step 11.
|
||||||
let form = context_node.inclusive_ancestors()
|
let form = context_node.inclusive_ancestors()
|
||||||
.find(|element| element.r().is_htmlformelement());
|
.find(|element| element.r().is::<HTMLFormElement>());
|
||||||
let fragment_context = FragmentContext {
|
let fragment_context = FragmentContext {
|
||||||
context_elem: context_node,
|
context_elem: context_node,
|
||||||
form_elem: form.r(),
|
form_elem: form.r(),
|
||||||
|
@ -304,7 +305,7 @@ pub fn parse_html_fragment(context_node: &Node,
|
||||||
|
|
||||||
// Step 14.
|
// Step 14.
|
||||||
let root_element = document.r().GetDocumentElement().expect("no document element");
|
let root_element = document.r().GetDocumentElement().expect("no document element");
|
||||||
let root_node = NodeCast::from_ref(root_element.r());
|
let root_node = root_element.upcast::<Node>();
|
||||||
for child in root_node.children() {
|
for child in root_node.children() {
|
||||||
output.AppendChild(child.r()).unwrap();
|
output.AppendChild(child.r()).unwrap();
|
||||||
}
|
}
|
||||||
|
|
|
@ -23,9 +23,7 @@ use devtools_traits::{DevtoolScriptControlMsg, DevtoolsPageInfo};
|
||||||
use document_loader::{DocumentLoader, LoadType, NotifierData};
|
use document_loader::{DocumentLoader, LoadType, NotifierData};
|
||||||
use dom::bindings::cell::DOMRefCell;
|
use dom::bindings::cell::DOMRefCell;
|
||||||
use dom::bindings::codegen::Bindings::DocumentBinding::{DocumentMethods, DocumentReadyState};
|
use dom::bindings::codegen::Bindings::DocumentBinding::{DocumentMethods, DocumentReadyState};
|
||||||
use dom::bindings::codegen::InheritTypes::{ElementCast, EventCast, EventTargetCast, NodeCast};
|
use dom::bindings::conversions::{Castable, FromJSValConvertible, StringificationBehavior};
|
||||||
use dom::bindings::conversions::FromJSValConvertible;
|
|
||||||
use dom::bindings::conversions::StringificationBehavior;
|
|
||||||
use dom::bindings::global::GlobalRef;
|
use dom::bindings::global::GlobalRef;
|
||||||
use dom::bindings::js::{JS, RootCollection, trace_roots};
|
use dom::bindings::js::{JS, RootCollection, trace_roots};
|
||||||
use dom::bindings::js::{Root, RootCollectionPtr, RootedReference};
|
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::{Document, DocumentProgressHandler, IsHTMLDocument};
|
||||||
use dom::document::{DocumentProgressTask, DocumentSource, MouseEventType};
|
use dom::document::{DocumentProgressTask, DocumentSource, MouseEventType};
|
||||||
use dom::element::Element;
|
use dom::element::Element;
|
||||||
use dom::event::{EventBubbles, EventCancelable};
|
use dom::event::{Event, EventBubbles, EventCancelable};
|
||||||
use dom::node::{NodeDamage, window_from_node};
|
use dom::eventtarget::EventTarget;
|
||||||
|
use dom::node::{Node, NodeDamage, window_from_node};
|
||||||
use dom::servohtmlparser::{ParserContext, ServoHTMLParser};
|
use dom::servohtmlparser::{ParserContext, ServoHTMLParser};
|
||||||
use dom::uievent::UIEvent;
|
use dom::uievent::UIEvent;
|
||||||
use dom::window::{ReflowReason, ScriptHelpers, Window};
|
use dom::window::{ReflowReason, ScriptHelpers, Window};
|
||||||
|
@ -1256,12 +1255,12 @@ impl ScriptTask {
|
||||||
let current_url = it_page.document().url().serialize();
|
let current_url = it_page.document().url().serialize();
|
||||||
urls.push(current_url.clone());
|
urls.push(current_url.clone());
|
||||||
|
|
||||||
for child in NodeCast::from_ref(&*it_page.document()).traverse_preorder() {
|
for child in it_page.document().upcast::<Node>().traverse_preorder() {
|
||||||
let target = EventTargetCast::from_ref(&*child);
|
let target = child.upcast::<EventTarget>();
|
||||||
dom_tree_size += heap_size_of_self_and_children(target);
|
dom_tree_size += heap_size_of_self_and_children(target);
|
||||||
}
|
}
|
||||||
let window = it_page.window();
|
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);
|
dom_tree_size += heap_size_of_self_and_children(target);
|
||||||
|
|
||||||
reports.push(Report {
|
reports.push(Report {
|
||||||
|
@ -1324,7 +1323,7 @@ impl ScriptTask {
|
||||||
let frame_element = doc.find_iframe(subpage_id);
|
let frame_element = doc.find_iframe(subpage_id);
|
||||||
|
|
||||||
if let Some(ref frame_element) = frame_element {
|
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().begin_focus_transaction();
|
||||||
doc.r().request_focus(element);
|
doc.r().request_focus(element);
|
||||||
doc.r().commit_focus_transaction(FocusType::Parent);
|
doc.r().commit_focus_transaction(FocusType::Parent);
|
||||||
|
@ -1626,7 +1625,7 @@ impl ScriptTask {
|
||||||
DocumentSource::FromParser,
|
DocumentSource::FromParser,
|
||||||
loader);
|
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);
|
window.r().init_browsing_context(document.r(), frame_element);
|
||||||
|
|
||||||
// Create the root frame
|
// Create the root frame
|
||||||
|
@ -1673,7 +1672,7 @@ impl ScriptTask {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn scroll_fragment_point(&self, pipeline_id: PipelineId, node: &Element) {
|
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 rect = node.get_bounding_content_box();
|
||||||
let point = Point2D::new(rect.origin.x.to_f32_px(), rect.origin.y.to_f32_px());
|
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.
|
// 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.
|
// Notify Constellation about anchors that are no longer mouse over targets.
|
||||||
for target in &*prev_mouse_over_targets {
|
for target in &*prev_mouse_over_targets {
|
||||||
if !mouse_over_targets.contains(target) {
|
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 event = ConstellationMsg::NodeStatus(None);
|
||||||
let ConstellationChan(ref chan) = self.constellation_chan;
|
let ConstellationChan(ref chan) = self.constellation_chan;
|
||||||
chan.send(event).unwrap();
|
chan.send(event).unwrap();
|
||||||
|
@ -1744,7 +1743,7 @@ impl ScriptTask {
|
||||||
// Notify Constellation about the topmost anchor mouse over target.
|
// Notify Constellation about the topmost anchor mouse over target.
|
||||||
for target in &*mouse_over_targets {
|
for target in &*mouse_over_targets {
|
||||||
let target = target.root();
|
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"))
|
let status = target.r().get_attribute(&ns!(""), &atom!("href"))
|
||||||
.and_then(|href| {
|
.and_then(|href| {
|
||||||
let value = href.value();
|
let value = href.value();
|
||||||
|
@ -1845,9 +1844,9 @@ impl ScriptTask {
|
||||||
"resize".to_owned(), EventBubbles::DoesNotBubble,
|
"resize".to_owned(), EventBubbles::DoesNotBubble,
|
||||||
EventCancelable::NotCancelable, Some(window.r()),
|
EventCancelable::NotCancelable, Some(window.r()),
|
||||||
0i32);
|
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);
|
event.fire(wintarget);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1906,7 +1905,7 @@ impl ScriptTask {
|
||||||
// Kick off the initial reflow of the page.
|
// Kick off the initial reflow of the page.
|
||||||
debug!("kicking off initial reflow of {:?}", final_url);
|
debug!("kicking off initial reflow of {:?}", final_url);
|
||||||
document.r().disarm_reflow_timeout();
|
document.r().disarm_reflow_timeout();
|
||||||
document.r().content_changed(NodeCast::from_ref(document.r()),
|
document.r().content_changed(document.upcast::<Node>(),
|
||||||
NodeDamage::OtherNodeDamage);
|
NodeDamage::OtherNodeDamage);
|
||||||
let window = window_from_node(document.r());
|
let window = window_from_node(document.r());
|
||||||
window.r().reflow(ReflowGoal::ForDisplay, ReflowQueryType::NoQuery, ReflowReason::FirstLoad);
|
window.r().reflow(ReflowGoal::ForDisplay, ReflowQueryType::NoQuery, ReflowReason::FirstLoad);
|
||||||
|
|
|
@ -7,10 +7,10 @@ use dom::bindings::codegen::Bindings::ElementBinding::ElementMethods;
|
||||||
use dom::bindings::codegen::Bindings::HTMLIFrameElementBinding::HTMLIFrameElementMethods;
|
use dom::bindings::codegen::Bindings::HTMLIFrameElementBinding::HTMLIFrameElementMethods;
|
||||||
use dom::bindings::codegen::Bindings::NodeBinding::NodeMethods;
|
use dom::bindings::codegen::Bindings::NodeBinding::NodeMethods;
|
||||||
use dom::bindings::codegen::Bindings::NodeListBinding::NodeListMethods;
|
use dom::bindings::codegen::Bindings::NodeListBinding::NodeListMethods;
|
||||||
use dom::bindings::codegen::InheritTypes::{ElementCast, HTMLIFrameElementCast, NodeCast};
|
use dom::bindings::conversions::{Castable, FromJSValConvertible, StringificationBehavior};
|
||||||
use dom::bindings::conversions::FromJSValConvertible;
|
|
||||||
use dom::bindings::conversions::StringificationBehavior;
|
|
||||||
use dom::bindings::js::Root;
|
use dom::bindings::js::Root;
|
||||||
|
use dom::element::Element;
|
||||||
|
use dom::htmliframeelement::HTMLIFrameElement;
|
||||||
use dom::node::Node;
|
use dom::node::Node;
|
||||||
use dom::window::ScriptHelpers;
|
use dom::window::ScriptHelpers;
|
||||||
use ipc_channel::ipc::IpcSender;
|
use ipc_channel::ipc::IpcSender;
|
||||||
|
@ -27,7 +27,7 @@ use url::Url;
|
||||||
fn find_node_by_unique_id(page: &Rc<Page>, pipeline: PipelineId, node_id: String) -> Option<Root<Node>> {
|
fn find_node_by_unique_id(page: &Rc<Page>, pipeline: PipelineId, node_id: String) -> Option<Root<Node>> {
|
||||||
let page = get_page(&*page, pipeline);
|
let page = get_page(&*page, pipeline);
|
||||||
let document = page.document();
|
let document = page.document();
|
||||||
let node = NodeCast::from_ref(document.r());
|
let node = document.upcast::<Node>();
|
||||||
|
|
||||||
for candidate in node.traverse_preorder() {
|
for candidate in node.traverse_preorder() {
|
||||||
if candidate.r().get_unique_id() == node_id {
|
if candidate.r().get_unique_id() == node_id {
|
||||||
|
@ -94,7 +94,7 @@ pub fn handle_get_frame_id(page: &Rc<Page>,
|
||||||
WebDriverFrameId::Element(x) => {
|
WebDriverFrameId::Element(x) => {
|
||||||
match find_node_by_unique_id(page, pipeline, x) {
|
match find_node_by_unique_id(page, pipeline, x) {
|
||||||
Some(ref node) => {
|
Some(ref node) => {
|
||||||
match HTMLIFrameElementCast::to_ref(node.r()) {
|
match node.downcast::<HTMLIFrameElement>() {
|
||||||
Some(ref elem) => Ok(elem.GetContentWindow()),
|
Some(ref elem) => Ok(elem.GetContentWindow()),
|
||||||
None => Err(())
|
None => Err(())
|
||||||
}
|
}
|
||||||
|
@ -116,7 +116,7 @@ pub fn handle_find_element_css(page: &Rc<Page>, _pipeline: PipelineId, selector:
|
||||||
reply: IpcSender<Result<Option<String>, ()>>) {
|
reply: IpcSender<Result<Option<String>, ()>>) {
|
||||||
reply.send(match page.document().r().QuerySelector(selector.clone()) {
|
reply.send(match page.document().r().QuerySelector(selector.clone()) {
|
||||||
Ok(node) => {
|
Ok(node) => {
|
||||||
let result = node.map(|x| NodeCast::from_ref(x.r()).get_unique_id());
|
let result = node.map(|x| x.upcast::<Node>().get_unique_id());
|
||||||
Ok(result)
|
Ok(result)
|
||||||
}
|
}
|
||||||
Err(_) => Err(())
|
Err(_) => Err(())
|
||||||
|
@ -147,7 +147,7 @@ pub fn handle_get_active_element(page: &Rc<Page>,
|
||||||
_pipeline: PipelineId,
|
_pipeline: PipelineId,
|
||||||
reply: IpcSender<Option<String>>) {
|
reply: IpcSender<Option<String>>) {
|
||||||
reply.send(page.document().r().GetActiveElement().map(
|
reply.send(page.document().r().GetActiveElement().map(
|
||||||
|elem| NodeCast::from_ref(elem.r()).get_unique_id())).unwrap();
|
|elem| elem.upcast::<Node>().get_unique_id())).unwrap();
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn handle_get_title(page: &Rc<Page>, _pipeline: PipelineId, reply: IpcSender<String>) {
|
pub fn handle_get_title(page: &Rc<Page>, _pipeline: PipelineId, reply: IpcSender<String>) {
|
||||||
|
@ -172,7 +172,7 @@ pub fn handle_get_name(page: &Rc<Page>,
|
||||||
reply: IpcSender<Result<String, ()>>) {
|
reply: IpcSender<Result<String, ()>>) {
|
||||||
reply.send(match find_node_by_unique_id(&*page, pipeline, node_id) {
|
reply.send(match find_node_by_unique_id(&*page, pipeline, node_id) {
|
||||||
Some(node) => {
|
Some(node) => {
|
||||||
let element = ElementCast::to_ref(node.r()).unwrap();
|
let element = node.downcast::<Element>().unwrap();
|
||||||
Ok(element.TagName())
|
Ok(element.TagName())
|
||||||
},
|
},
|
||||||
None => Err(())
|
None => Err(())
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue