mirror of
https://github.com/servo/servo.git
synced 2025-07-23 07:13:52 +01:00
Clean up the cast calls
This commit is contained in:
parent
13ea3ac413
commit
68014af78e
66 changed files with 412 additions and 718 deletions
|
@ -44,12 +44,12 @@ use script::dom::bindings::codegen::InheritTypes::{CharacterDataTypeId, ElementT
|
|||
use script::dom::bindings::codegen::InheritTypes::{HTMLElementTypeId, NodeTypeId};
|
||||
use script::dom::bindings::conversions::Castable;
|
||||
use script::dom::bindings::js::LayoutJS;
|
||||
use script::dom::characterdata::{CharacterData, LayoutCharacterDataHelpers};
|
||||
use script::dom::characterdata::LayoutCharacterDataHelpers;
|
||||
use script::dom::element;
|
||||
use script::dom::element::{Element, LayoutElementHelpers, RawLayoutElementHelpers};
|
||||
use script::dom::htmlcanvaselement::{HTMLCanvasElement, LayoutHTMLCanvasElementHelpers};
|
||||
use script::dom::htmlcanvaselement::LayoutHTMLCanvasElementHelpers;
|
||||
use script::dom::htmliframeelement::HTMLIFrameElement;
|
||||
use script::dom::htmlimageelement::{HTMLImageElement, LayoutHTMLImageElementHelpers};
|
||||
use script::dom::htmlimageelement::LayoutHTMLImageElementHelpers;
|
||||
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};
|
||||
|
@ -358,7 +358,7 @@ impl<'le> LayoutElement<'le> {
|
|||
|
||||
pub fn as_node(&self) -> LayoutNode<'le> {
|
||||
LayoutNode {
|
||||
node: self.element.upcast::<Node>(),
|
||||
node: self.element.upcast(),
|
||||
chain: PhantomData,
|
||||
}
|
||||
}
|
||||
|
@ -377,7 +377,7 @@ fn as_element<'le>(node: LayoutJS<Node>) -> Option<LayoutElement<'le>> {
|
|||
impl<'le> ::selectors::Element for LayoutElement<'le> {
|
||||
fn parent_element(&self) -> Option<LayoutElement<'le>> {
|
||||
unsafe {
|
||||
self.element.upcast::<Node>().parent_node_ref().and_then(as_element)
|
||||
self.element.upcast().parent_node_ref().and_then(as_element)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -422,7 +422,7 @@ impl<'le> ::selectors::Element for LayoutElement<'le> {
|
|||
self.as_node().children().all(|node| match node.type_id() {
|
||||
NodeTypeId::Element(..) => false,
|
||||
NodeTypeId::CharacterData(CharacterDataTypeId::Text) => unsafe {
|
||||
node.node.downcast::<CharacterData>().unwrap().data_for_layout().is_empty()
|
||||
node.node.downcast().unwrap().data_for_layout().is_empty()
|
||||
},
|
||||
_ => true
|
||||
})
|
||||
|
@ -695,7 +695,7 @@ impl<'ln> ThreadSafeLayoutNode<'ln> {
|
|||
#[inline]
|
||||
pub fn as_element(&self) -> ThreadSafeLayoutElement<'ln> {
|
||||
unsafe {
|
||||
let element = match self.get_jsmanaged().downcast::<Element>() {
|
||||
let element = match self.get_jsmanaged().downcast() {
|
||||
Some(e) => e.unsafe_get(),
|
||||
None => panic!("not an element")
|
||||
};
|
||||
|
@ -786,12 +786,12 @@ impl<'ln> ThreadSafeLayoutNode<'ln> {
|
|||
|
||||
pub fn is_ignorable_whitespace(&self) -> bool {
|
||||
unsafe {
|
||||
let text: LayoutJS<Text> = match self.get_jsmanaged().downcast::<Text>() {
|
||||
let text: LayoutJS<Text> = match self.get_jsmanaged().downcast() {
|
||||
Some(text) => text,
|
||||
None => return false
|
||||
};
|
||||
|
||||
if !is_whitespace(text.upcast::<CharacterData>().data_for_layout()) {
|
||||
if !is_whitespace(text.upcast().data_for_layout()) {
|
||||
return false
|
||||
}
|
||||
|
||||
|
@ -814,8 +814,7 @@ impl<'ln> ThreadSafeLayoutNode<'ln> {
|
|||
pub fn get_unsigned_integer_attribute(self, attribute: UnsignedIntegerAttribute)
|
||||
-> Option<u32> {
|
||||
unsafe {
|
||||
let elem: Option<LayoutJS<Element>> = self.get_jsmanaged().downcast::<Element>();
|
||||
match elem {
|
||||
match self.get_jsmanaged().downcast::<Element>() {
|
||||
Some(element) => {
|
||||
element.get_unsigned_integer_attribute_for_layout(attribute)
|
||||
}
|
||||
|
@ -900,20 +899,17 @@ impl<'ln> ThreadSafeLayoutNode<'ln> {
|
|||
}
|
||||
|
||||
let this = unsafe { self.get_jsmanaged() };
|
||||
let text = this.downcast::<Text>();
|
||||
if let Some(text) = text {
|
||||
if let Some(text) = this.downcast::<Text>() {
|
||||
let data = unsafe {
|
||||
text.upcast::<CharacterData>().data_for_layout().to_owned()
|
||||
text.upcast().data_for_layout().to_owned()
|
||||
};
|
||||
return TextContent::Text(data);
|
||||
}
|
||||
let input = this.downcast::<HTMLInputElement>();
|
||||
if let Some(input) = input {
|
||||
if let Some(input) = this.downcast::<HTMLInputElement>() {
|
||||
let data = unsafe { input.get_value_for_layout() };
|
||||
return TextContent::Text(data);
|
||||
}
|
||||
let area = this.downcast::<HTMLTextAreaElement>();
|
||||
if let Some(area) = area {
|
||||
if let Some(area) = this.downcast::<HTMLTextAreaElement>() {
|
||||
let data = unsafe { area.get_value_for_layout() };
|
||||
return TextContent::Text(data);
|
||||
}
|
||||
|
@ -926,7 +922,7 @@ impl<'ln> ThreadSafeLayoutNode<'ln> {
|
|||
let this = unsafe {
|
||||
self.get_jsmanaged()
|
||||
};
|
||||
let input = this.downcast::<HTMLInputElement>();
|
||||
let input = this.downcast();
|
||||
if let Some(input) = input {
|
||||
let insertion_point = unsafe {
|
||||
input.get_insertion_point_for_layout()
|
||||
|
@ -954,7 +950,7 @@ impl<'ln> ThreadSafeLayoutNode<'ln> {
|
|||
/// FIXME(pcwalton): Don't copy URLs.
|
||||
pub fn image_url(&self) -> Option<Url> {
|
||||
unsafe {
|
||||
self.get_jsmanaged().downcast::<HTMLImageElement>()
|
||||
self.get_jsmanaged().downcast()
|
||||
.expect("not an image!")
|
||||
.image_url()
|
||||
}
|
||||
|
@ -962,28 +958,28 @@ impl<'ln> ThreadSafeLayoutNode<'ln> {
|
|||
|
||||
pub fn canvas_renderer_id(&self) -> Option<usize> {
|
||||
unsafe {
|
||||
let canvas_element = self.get_jsmanaged().downcast::<HTMLCanvasElement>();
|
||||
let canvas_element = self.get_jsmanaged().downcast();
|
||||
canvas_element.and_then(|elem| elem.get_renderer_id())
|
||||
}
|
||||
}
|
||||
|
||||
pub fn canvas_ipc_renderer(&self) -> Option<IpcSender<CanvasMsg>> {
|
||||
unsafe {
|
||||
let canvas_element = self.get_jsmanaged().downcast::<HTMLCanvasElement>();
|
||||
let canvas_element = self.get_jsmanaged().downcast();
|
||||
canvas_element.and_then(|elem| elem.get_ipc_renderer())
|
||||
}
|
||||
}
|
||||
|
||||
pub fn canvas_width(&self) -> u32 {
|
||||
unsafe {
|
||||
let canvas_element = self.get_jsmanaged().downcast::<HTMLCanvasElement>();
|
||||
let canvas_element = self.get_jsmanaged().downcast();
|
||||
canvas_element.unwrap().get_canvas_width()
|
||||
}
|
||||
}
|
||||
|
||||
pub fn canvas_height(&self) -> u32 {
|
||||
unsafe {
|
||||
let canvas_element = self.get_jsmanaged().downcast::<HTMLCanvasElement>();
|
||||
let canvas_element = self.get_jsmanaged().downcast();
|
||||
canvas_element.unwrap().get_canvas_height()
|
||||
}
|
||||
}
|
||||
|
|
|
@ -45,7 +45,7 @@ pub trait Activatable {
|
|||
// Step 4
|
||||
// https://html.spec.whatwg.org/multipage/#fire-a-synthetic-mouse-event
|
||||
let win = window_from_node(element);
|
||||
let target = element.upcast::<EventTarget>();
|
||||
let target = element.upcast();
|
||||
let mouse = MouseEvent::new(win.r(), "click".to_owned(),
|
||||
EventBubbles::DoesNotBubble, EventCancelable::NotCancelable, Some(win.r()), 1,
|
||||
0, 0, 0, 0, ctrlKey, shiftKey, altKey, metaKey,
|
||||
|
|
|
@ -12,7 +12,6 @@ use dom::bindings::js::{JS, MutNullableHeap};
|
|||
use dom::bindings::js::{LayoutJS, Root, RootedReference};
|
||||
use dom::bindings::utils::{Reflector, reflect_dom_object};
|
||||
use dom::element::{AttributeMutation, Element};
|
||||
use dom::node::Node;
|
||||
use dom::values::UNSIGNED_LONG_MAX;
|
||||
use dom::virtualmethods::vtable_for;
|
||||
use dom::window::Window;
|
||||
|
@ -288,7 +287,7 @@ impl Attr {
|
|||
assert!(Some(owner) == self.owner().r());
|
||||
mem::swap(&mut *self.value.borrow_mut(), &mut value);
|
||||
if self.namespace == ns!("") {
|
||||
vtable_for(owner.upcast::<Node>()).attribute_mutated(
|
||||
vtable_for(owner.upcast()).attribute_mutated(
|
||||
self, AttributeMutation::Set(Some(&value)));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -147,9 +147,7 @@ impl CanvasRenderingContext2D {
|
|||
}
|
||||
|
||||
fn mark_as_dirty(&self) {
|
||||
let canvas = self.canvas.root();
|
||||
let node = canvas.upcast::<Node>();
|
||||
node.dirty(NodeDamage::OtherNodeDamage);
|
||||
self.canvas.root().upcast::<Node>().dirty(NodeDamage::OtherNodeDamage);
|
||||
}
|
||||
|
||||
fn update_transform(&self) {
|
||||
|
|
|
@ -134,14 +134,12 @@ impl CharacterDataMethods for CharacterData {
|
|||
|
||||
// https://dom.spec.whatwg.org/#dom-nondocumenttypechildnode-previouselementsibling
|
||||
fn GetPreviousElementSibling(&self) -> Option<Root<Element>> {
|
||||
self.upcast::<Node>().preceding_siblings()
|
||||
.filter_map(Root::downcast::<Element>).next()
|
||||
self.upcast::<Node>().preceding_siblings().filter_map(Root::downcast).next()
|
||||
}
|
||||
|
||||
// https://dom.spec.whatwg.org/#dom-nondocumenttypechildnode-nextelementsibling
|
||||
fn GetNextElementSibling(&self) -> Option<Root<Element>> {
|
||||
self.upcast::<Node>().following_siblings()
|
||||
.filter_map(Root::downcast::<Element>).next()
|
||||
self.upcast::<Node>().following_siblings().filter_map(Root::downcast).next()
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -89,11 +89,11 @@ pub fn create_element(name: QualName, prefix: Option<Atom>,
|
|||
macro_rules! make(
|
||||
($ctor:ident) => ({
|
||||
let obj = $ctor::new((*name.local).to_owned(), prefix, document);
|
||||
Root::upcast::<Element>(obj)
|
||||
Root::upcast(obj)
|
||||
});
|
||||
($ctor:ident, $($arg:expr),+) => ({
|
||||
let obj = $ctor::new((*name.local).to_owned(), prefix, document, $($arg),+);
|
||||
Root::upcast::<Element>(obj)
|
||||
Root::upcast(obj)
|
||||
})
|
||||
);
|
||||
|
||||
|
|
|
@ -242,7 +242,7 @@ impl CSSStyleDeclarationMethods for CSSStyleDeclaration {
|
|||
}
|
||||
|
||||
let document = document_from_node(element);
|
||||
let node = element.upcast::<Node>();
|
||||
let node = element.upcast();
|
||||
document.r().content_changed(node, NodeDamage::NodeStyleDamaged);
|
||||
Ok(())
|
||||
}
|
||||
|
@ -276,7 +276,7 @@ impl CSSStyleDeclarationMethods for CSSStyleDeclaration {
|
|||
}
|
||||
|
||||
let document = document_from_node(element);
|
||||
let node = element.upcast::<Node>();
|
||||
let node = element.upcast();
|
||||
document.r().content_changed(node, NodeDamage::NodeStyleDamaged);
|
||||
Ok(())
|
||||
}
|
||||
|
|
|
@ -15,7 +15,6 @@ use dom::bindings::js::{Root, RootCollection};
|
|||
use dom::bindings::refcounted::LiveDOMReferences;
|
||||
use dom::bindings::structuredclone::StructuredCloneData;
|
||||
use dom::bindings::utils::Reflectable;
|
||||
use dom::eventtarget::EventTarget;
|
||||
use dom::messageevent::MessageEvent;
|
||||
use dom::worker::{SimpleWorkerErrorHandler, TrustedWorkerAddress, WorkerMessageHandler};
|
||||
use dom::workerglobalscope::WorkerGlobalScope;
|
||||
|
@ -289,7 +288,7 @@ impl DedicatedWorkerGlobalScope {
|
|||
match msg {
|
||||
WorkerScriptMsg::DOMMessage(data) => {
|
||||
let scope = self.upcast::<WorkerGlobalScope>();
|
||||
let target = self.upcast::<EventTarget>();
|
||||
let target = self.upcast();
|
||||
let _ar = JSAutoRequest::new(scope.get_cx());
|
||||
let _ac = JSAutoCompartment::new(scope.get_cx(), scope.reflector().get_jsobject().get());
|
||||
let mut message = RootedValue::new(scope.get_cx(), UndefinedValue());
|
||||
|
@ -323,7 +322,7 @@ impl DedicatedWorkerGlobalScope {
|
|||
fn handle_event(&self, event: MixedMessage) {
|
||||
match event {
|
||||
MixedMessage::FromDevtools(msg) => {
|
||||
let global_ref = GlobalRef::Worker(self.upcast::<WorkerGlobalScope>());
|
||||
let global_ref = GlobalRef::Worker(self.upcast());
|
||||
match msg {
|
||||
DevtoolScriptControlMsg::EvaluateJS(_pipe_id, string, sender) =>
|
||||
devtools::handle_evaluate_js(&global_ref, string, sender),
|
||||
|
|
|
@ -290,8 +290,7 @@ impl Document {
|
|||
let base = self.upcast::<Node>()
|
||||
.traverse_preorder()
|
||||
.filter_map(Root::downcast::<HTMLBaseElement>)
|
||||
.filter(|element| element.upcast::<Element>().has_attribute(&atom!("href")))
|
||||
.next();
|
||||
.find(|element| element.upcast::<Element>().has_attribute(&atom!("href")));
|
||||
self.base_element.set(base.r());
|
||||
}
|
||||
|
||||
|
@ -379,10 +378,7 @@ impl Document {
|
|||
element: &Element,
|
||||
id: Atom) {
|
||||
debug!("Adding named element to document {:p}: {:p} id={}", self, element, id);
|
||||
assert!({
|
||||
let node = element.upcast::<Node>();
|
||||
node.is_in_doc()
|
||||
});
|
||||
assert!(element.upcast::<Node>().is_in_doc());
|
||||
assert!(!id.is_empty());
|
||||
|
||||
let mut idmap = self.idmap.borrow_mut();
|
||||
|
@ -401,7 +397,7 @@ impl Document {
|
|||
let mut head: usize = 0;
|
||||
let root = root.upcast::<Node>();
|
||||
for node in root.traverse_preorder() {
|
||||
if let Some(elem) = node.downcast::<Element>() {
|
||||
if let Some(elem) = node.downcast() {
|
||||
if (*elements)[head].root().r() == elem {
|
||||
head += 1;
|
||||
}
|
||||
|
@ -420,7 +416,7 @@ impl Document {
|
|||
/// https://html.spec.whatwg.org/multipage/#the-indicated-part-of-the-document
|
||||
pub fn find_fragment_node(&self, fragid: &str) -> Option<Root<Element>> {
|
||||
self.GetElementById(fragid.to_owned()).or_else(|| {
|
||||
let check_anchor = |&node: &&HTMLAnchorElement| {
|
||||
let check_anchor = |node: &HTMLAnchorElement| {
|
||||
let elem = node.upcast::<Element>();
|
||||
elem.get_attribute(&ns!(""), &atom!("name")).map_or(false, |attr| {
|
||||
&**attr.r().value() == fragid
|
||||
|
@ -428,9 +424,9 @@ impl Document {
|
|||
};
|
||||
let doc_node = self.upcast::<Node>();
|
||||
doc_node.traverse_preorder()
|
||||
.filter_map(Root::downcast::<HTMLAnchorElement>)
|
||||
.find(|node| check_anchor(&node.r()))
|
||||
.map(Root::upcast::<Element>)
|
||||
.filter_map(Root::downcast)
|
||||
.find(|node| check_anchor(&node))
|
||||
.map(Root::upcast)
|
||||
})
|
||||
}
|
||||
|
||||
|
@ -606,7 +602,7 @@ impl Document {
|
|||
match mouse_event_type {
|
||||
MouseEventType::Click => el.authentic_click_activation(event),
|
||||
_ => {
|
||||
let target = node.upcast::<EventTarget>();
|
||||
let target = node.upcast();
|
||||
event.fire(target);
|
||||
},
|
||||
}
|
||||
|
@ -664,7 +660,7 @@ impl Document {
|
|||
if target_ref.get_hover_state() {
|
||||
target_ref.set_hover_state(false);
|
||||
|
||||
let target = target_ref.upcast::<EventTarget>();
|
||||
let target = target_ref.upcast();
|
||||
|
||||
self.fire_mouse_event(point, &target, "mouseout".to_owned());
|
||||
}
|
||||
|
@ -678,7 +674,7 @@ impl Document {
|
|||
if !target.get_hover_state() {
|
||||
target.set_hover_state(true);
|
||||
|
||||
let target = target.upcast::<EventTarget>();
|
||||
let target = target.upcast();
|
||||
|
||||
self.fire_mouse_event(point, target, "mouseover".to_owned());
|
||||
|
||||
|
@ -690,7 +686,7 @@ impl Document {
|
|||
let top_most_node =
|
||||
node::from_untrusted_node_address(js_runtime, mouse_over_addresses[0]);
|
||||
|
||||
let target = top_most_node.upcast::<EventTarget>();
|
||||
let target = top_most_node.upcast();
|
||||
self.fire_mouse_event(point, target, "mousemove".to_owned());
|
||||
}
|
||||
|
||||
|
@ -713,9 +709,9 @@ impl Document {
|
|||
let body = self.GetBody();
|
||||
|
||||
let target = match (&focused, &body) {
|
||||
(&Some(ref focused), _) => focused.upcast::<EventTarget>(),
|
||||
(&None, &Some(ref body)) => body.upcast::<EventTarget>(),
|
||||
(&None, &None) => self.window.upcast::<EventTarget>(),
|
||||
(&Some(ref focused), _) => focused.upcast(),
|
||||
(&None, &Some(ref body)) => body.upcast(),
|
||||
(&None, &None) => self.window.upcast(),
|
||||
};
|
||||
|
||||
let ctrl = modifiers.contains(CONTROL);
|
||||
|
@ -768,7 +764,7 @@ impl Document {
|
|||
// https://www.w3.org/Bugs/Public/show_bug.cgi?id=27337
|
||||
match key {
|
||||
Key::Space if !prevented && state == KeyState::Released => {
|
||||
let maybe_elem: Option<&Element> = target.downcast::<Element>();
|
||||
let maybe_elem = target.downcast::<Element>();
|
||||
if let Some(el) = maybe_elem {
|
||||
if let Some(a) = el.as_maybe_activatable() {
|
||||
a.synthetic_click_activation(ctrl, alt, shift, meta);
|
||||
|
@ -776,7 +772,7 @@ impl Document {
|
|||
}
|
||||
}
|
||||
Key::Enter if !prevented && state == KeyState::Released => {
|
||||
let maybe_elem: Option<&Element> = target.downcast::<Element>();
|
||||
let maybe_elem = target.downcast::<Element>();
|
||||
if let Some(el) = maybe_elem {
|
||||
if let Some(a) = el.as_maybe_activatable() {
|
||||
a.implicit_submission(ctrl, alt, shift, meta);
|
||||
|
@ -797,7 +793,7 @@ impl Document {
|
|||
match nodes.into_iter().next().unwrap() {
|
||||
NodeOrString::eNode(node) => Ok(node),
|
||||
NodeOrString::eString(string) => {
|
||||
Ok(Root::upcast::<Node>(self.CreateTextNode(string)))
|
||||
Ok(Root::upcast(self.CreateTextNode(string)))
|
||||
},
|
||||
}
|
||||
} else {
|
||||
|
@ -940,7 +936,8 @@ impl Document {
|
|||
|
||||
/// Find an iframe element in the document.
|
||||
pub fn find_iframe(&self, subpage_id: SubpageId) -> Option<Root<HTMLIFrameElement>> {
|
||||
self.upcast::<Node>().traverse_preorder()
|
||||
self.upcast::<Node>()
|
||||
.traverse_preorder()
|
||||
.filter_map(Root::downcast::<HTMLIFrameElement>)
|
||||
.find(|node| node.r().subpage_id() == Some(subpage_id))
|
||||
}
|
||||
|
@ -1073,10 +1070,7 @@ impl Document {
|
|||
}
|
||||
|
||||
fn get_html_element(&self) -> Option<Root<HTMLHtmlElement>> {
|
||||
self.GetDocumentElement()
|
||||
.r()
|
||||
.and_then(Castable::downcast::<HTMLHtmlElement>)
|
||||
.map(Root::from_ref)
|
||||
self.GetDocumentElement().and_then(Root::downcast)
|
||||
}
|
||||
|
||||
/// https://html.spec.whatwg.org/multipage/#appropriate-template-contents-owner-document
|
||||
|
@ -1131,7 +1125,7 @@ impl DocumentMethods for Document {
|
|||
match self.get_focused_element() {
|
||||
Some(element) => Some(element), // Step 3. and 4.
|
||||
None => match self.GetBody() { // Step 5.
|
||||
Some(body) => Some(Root::upcast::<Element>(body)),
|
||||
Some(body) => Some(Root::upcast(body)),
|
||||
None => self.GetDocumentElement(),
|
||||
}
|
||||
}
|
||||
|
@ -1186,32 +1180,28 @@ impl DocumentMethods for Document {
|
|||
|
||||
// https://dom.spec.whatwg.org/#dom-document-doctype
|
||||
fn GetDoctype(&self) -> Option<Root<DocumentType>> {
|
||||
let node = self.upcast::<Node>();
|
||||
node.children()
|
||||
.filter_map(|c| c.downcast::<DocumentType>().map(Root::from_ref))
|
||||
.next()
|
||||
self.upcast::<Node>().children().filter_map(Root::downcast).next()
|
||||
}
|
||||
|
||||
// https://dom.spec.whatwg.org/#dom-document-documentelement
|
||||
fn GetDocumentElement(&self) -> Option<Root<Element>> {
|
||||
let node = self.upcast::<Node>();
|
||||
node.child_elements().next()
|
||||
self.upcast::<Node>().child_elements().next()
|
||||
}
|
||||
|
||||
// https://dom.spec.whatwg.org/#dom-document-getelementsbytagname
|
||||
fn GetElementsByTagName(&self, tag_name: DOMString) -> Root<HTMLCollection> {
|
||||
HTMLCollection::by_tag_name(&self.window, self.upcast::<Node>(), tag_name)
|
||||
HTMLCollection::by_tag_name(&self.window, self.upcast(), tag_name)
|
||||
}
|
||||
|
||||
// https://dom.spec.whatwg.org/#dom-document-getelementsbytagnamens
|
||||
fn GetElementsByTagNameNS(&self, maybe_ns: Option<DOMString>, tag_name: DOMString)
|
||||
-> Root<HTMLCollection> {
|
||||
HTMLCollection::by_tag_name_ns(&self.window, self.upcast::<Node>(), tag_name, maybe_ns)
|
||||
HTMLCollection::by_tag_name_ns(&self.window, self.upcast(), tag_name, maybe_ns)
|
||||
}
|
||||
|
||||
// https://dom.spec.whatwg.org/#dom-document-getelementsbyclassname
|
||||
fn GetElementsByClassName(&self, classes: DOMString) -> Root<HTMLCollection> {
|
||||
HTMLCollection::by_class_name(&self.window, self.upcast::<Node>(), classes)
|
||||
HTMLCollection::by_class_name(&self.window, self.upcast(), classes)
|
||||
}
|
||||
|
||||
// https://dom.spec.whatwg.org/#dom-nonelementparentnode-getelementbyid
|
||||
|
@ -1335,19 +1325,20 @@ impl DocumentMethods for Document {
|
|||
fn CreateEvent(&self, mut interface: DOMString) -> Fallible<Root<Event>> {
|
||||
interface.make_ascii_lowercase();
|
||||
match &*interface {
|
||||
"uievents" | "uievent" => Ok(Root::upcast::<Event>(
|
||||
UIEvent::new_uninitialized(&self.window))),
|
||||
"mouseevents" | "mouseevent" => Ok(Root::upcast::<Event>(
|
||||
MouseEvent::new_uninitialized(&self.window))),
|
||||
"customevent" => Ok(Root::upcast::<Event>(
|
||||
CustomEvent::new_uninitialized(GlobalRef::Window(&self.window)))),
|
||||
"htmlevents" | "events" | "event" => Ok(Event::new_uninitialized(
|
||||
GlobalRef::Window(&self.window))),
|
||||
"keyboardevent" | "keyevents" => Ok(Root::upcast::<Event>(
|
||||
KeyboardEvent::new_uninitialized(&self.window))),
|
||||
"messageevent" => Ok(Root::upcast::<Event>(
|
||||
MessageEvent::new_uninitialized(GlobalRef::Window(&self.window)))),
|
||||
_ => Err(Error::NotSupported)
|
||||
"uievents" | "uievent" =>
|
||||
Ok(Root::upcast(UIEvent::new_uninitialized(&self.window))),
|
||||
"mouseevents" | "mouseevent" =>
|
||||
Ok(Root::upcast(MouseEvent::new_uninitialized(&self.window))),
|
||||
"customevent" =>
|
||||
Ok(Root::upcast(CustomEvent::new_uninitialized(GlobalRef::Window(&self.window)))),
|
||||
"htmlevents" | "events" | "event" =>
|
||||
Ok(Event::new_uninitialized(GlobalRef::Window(&self.window))),
|
||||
"keyboardevent" | "keyevents" =>
|
||||
Ok(Root::upcast(KeyboardEvent::new_uninitialized(&self.window))),
|
||||
"messageevent" =>
|
||||
Ok(Root::upcast(MessageEvent::new_uninitialized(GlobalRef::Window(&self.window)))),
|
||||
_ =>
|
||||
Err(Error::NotSupported),
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1389,7 +1380,7 @@ impl DocumentMethods for Document {
|
|||
// Step 2.
|
||||
root.upcast::<Node>()
|
||||
.traverse_preorder()
|
||||
.find(|node| node.r().is::<HTMLTitleElement>())
|
||||
.find(|node| node.is::<HTMLTitleElement>())
|
||||
}
|
||||
});
|
||||
|
||||
|
@ -1423,7 +1414,7 @@ impl DocumentMethods for Document {
|
|||
let elem = Element::create(name, None, self,
|
||||
ElementCreator::ScriptCreated);
|
||||
root.upcast::<Node>()
|
||||
.AppendChild(elem.upcast::<Node>())
|
||||
.AppendChild(elem.upcast())
|
||||
.unwrap()
|
||||
}
|
||||
}
|
||||
|
@ -1440,7 +1431,7 @@ impl DocumentMethods for Document {
|
|||
let elem = Element::create(name, None, self,
|
||||
ElementCreator::ScriptCreated);
|
||||
head.upcast::<Node>()
|
||||
.AppendChild(elem.upcast::<Node>())
|
||||
.AppendChild(elem.upcast())
|
||||
.unwrap()
|
||||
},
|
||||
None => return,
|
||||
|
@ -1457,10 +1448,7 @@ impl DocumentMethods for Document {
|
|||
// https://html.spec.whatwg.org/multipage/#dom-document-head
|
||||
fn GetHead(&self) -> Option<Root<HTMLHeadElement>> {
|
||||
self.get_html_element().and_then(|root| {
|
||||
let node = root.upcast::<Node>();
|
||||
node.children()
|
||||
.filter_map(|c| c.downcast::<HTMLHeadElement>().map(Root::from_ref))
|
||||
.next()
|
||||
root.upcast::<Node>().children().filter_map(Root::downcast).next()
|
||||
})
|
||||
}
|
||||
|
||||
|
@ -1479,9 +1467,7 @@ impl DocumentMethods for Document {
|
|||
NodeTypeId::Element(ElementTypeId::HTMLElement(HTMLElementTypeId::HTMLFrameSetElement)) => true,
|
||||
_ => false
|
||||
}
|
||||
}).map(|node| {
|
||||
Root::from_ref(node.downcast::<HTMLElement>().unwrap())
|
||||
})
|
||||
}).map(|node| Root::downcast(node).unwrap())
|
||||
})
|
||||
}
|
||||
|
||||
|
@ -1510,9 +1496,7 @@ impl DocumentMethods for Document {
|
|||
// Step 3.
|
||||
(Some(ref root), &Some(ref child)) => {
|
||||
let root = root.upcast::<Node>();
|
||||
let child = child.upcast::<Node>();
|
||||
let new_body = new_body.upcast::<Node>();
|
||||
assert!(root.ReplaceChild(new_body, child).is_ok())
|
||||
root.ReplaceChild(new_body.upcast(), child.upcast()).unwrap();
|
||||
},
|
||||
|
||||
// Step 4.
|
||||
|
@ -1521,8 +1505,7 @@ impl DocumentMethods for Document {
|
|||
// Step 5.
|
||||
(Some(ref root), &None) => {
|
||||
let root = root.upcast::<Node>();
|
||||
let new_body = new_body.upcast::<Node>();
|
||||
assert!(root.AppendChild(new_body).is_ok());
|
||||
root.AppendChild(new_body.upcast()).unwrap();
|
||||
}
|
||||
}
|
||||
Ok(())
|
||||
|
@ -1547,18 +1530,16 @@ impl DocumentMethods for Document {
|
|||
// https://html.spec.whatwg.org/multipage/#dom-document-images
|
||||
fn Images(&self) -> Root<HTMLCollection> {
|
||||
self.images.or_init(|| {
|
||||
let root = self.upcast::<Node>();
|
||||
let filter = box ImagesFilter;
|
||||
HTMLCollection::create(&self.window, root, filter)
|
||||
HTMLCollection::create(&self.window, self.upcast(), filter)
|
||||
})
|
||||
}
|
||||
|
||||
// https://html.spec.whatwg.org/multipage/#dom-document-embeds
|
||||
fn Embeds(&self) -> Root<HTMLCollection> {
|
||||
self.embeds.or_init(|| {
|
||||
let root = self.upcast::<Node>();
|
||||
let filter = box EmbedsFilter;
|
||||
HTMLCollection::create(&self.window, root, filter)
|
||||
HTMLCollection::create(&self.window, self.upcast(), filter)
|
||||
})
|
||||
}
|
||||
|
||||
|
@ -1570,36 +1551,32 @@ impl DocumentMethods for Document {
|
|||
// https://html.spec.whatwg.org/multipage/#dom-document-links
|
||||
fn Links(&self) -> Root<HTMLCollection> {
|
||||
self.links.or_init(|| {
|
||||
let root = self.upcast::<Node>();
|
||||
let filter = box LinksFilter;
|
||||
HTMLCollection::create(&self.window, root, filter)
|
||||
HTMLCollection::create(&self.window, self.upcast(), filter)
|
||||
})
|
||||
}
|
||||
|
||||
// https://html.spec.whatwg.org/multipage/#dom-document-forms
|
||||
fn Forms(&self) -> Root<HTMLCollection> {
|
||||
self.forms.or_init(|| {
|
||||
let root = self.upcast::<Node>();
|
||||
let filter = box FormsFilter;
|
||||
HTMLCollection::create(&self.window, root, filter)
|
||||
HTMLCollection::create(&self.window, self.upcast(), filter)
|
||||
})
|
||||
}
|
||||
|
||||
// https://html.spec.whatwg.org/multipage/#dom-document-scripts
|
||||
fn Scripts(&self) -> Root<HTMLCollection> {
|
||||
self.scripts.or_init(|| {
|
||||
let root = self.upcast::<Node>();
|
||||
let filter = box ScriptsFilter;
|
||||
HTMLCollection::create(&self.window, root, filter)
|
||||
HTMLCollection::create(&self.window, self.upcast(), filter)
|
||||
})
|
||||
}
|
||||
|
||||
// https://html.spec.whatwg.org/multipage/#dom-document-anchors
|
||||
fn Anchors(&self) -> Root<HTMLCollection> {
|
||||
self.anchors.or_init(|| {
|
||||
let root = self.upcast::<Node>();
|
||||
let filter = box AnchorsFilter;
|
||||
HTMLCollection::create(&self.window, root, filter)
|
||||
HTMLCollection::create(&self.window, self.upcast(), filter)
|
||||
})
|
||||
}
|
||||
|
||||
|
@ -1607,9 +1584,8 @@ impl DocumentMethods for Document {
|
|||
fn Applets(&self) -> Root<HTMLCollection> {
|
||||
// FIXME: This should be return OBJECT elements containing applets.
|
||||
self.applets.or_init(|| {
|
||||
let root = self.upcast::<Node>();
|
||||
let filter = box AppletsFilter;
|
||||
HTMLCollection::create(&self.window, root, filter)
|
||||
HTMLCollection::create(&self.window, self.upcast(), filter)
|
||||
})
|
||||
}
|
||||
|
||||
|
@ -1620,7 +1596,7 @@ impl DocumentMethods for Document {
|
|||
|
||||
// https://dom.spec.whatwg.org/#dom-parentnode-children
|
||||
fn Children(&self) -> Root<HTMLCollection> {
|
||||
HTMLCollection::children(&self.window, self.upcast::<Node>())
|
||||
HTMLCollection::children(&self.window, self.upcast())
|
||||
}
|
||||
|
||||
// https://dom.spec.whatwg.org/#dom-parentnode-firstelementchild
|
||||
|
@ -1630,7 +1606,7 @@ impl DocumentMethods for Document {
|
|||
|
||||
// https://dom.spec.whatwg.org/#dom-parentnode-lastelementchild
|
||||
fn GetLastElementChild(&self) -> Option<Root<Element>> {
|
||||
self.upcast::<Node>().rev_children().filter_map(Root::downcast::<Element>).next()
|
||||
self.upcast::<Node>().rev_children().filter_map(Root::downcast).next()
|
||||
}
|
||||
|
||||
// https://dom.spec.whatwg.org/#dom-parentnode-childelementcount
|
||||
|
@ -1713,7 +1689,7 @@ impl DocumentMethods for Document {
|
|||
}
|
||||
impl CollectionFilter for NamedElementFilter {
|
||||
fn filter(&self, elem: &Element, _root: &Node) -> bool {
|
||||
filter_by_name(&self.name, elem.upcast::<Node>())
|
||||
filter_by_name(&self.name, elem.upcast())
|
||||
}
|
||||
}
|
||||
// https://html.spec.whatwg.org/multipage/#dom-document-nameditem-filter
|
||||
|
@ -1866,9 +1842,8 @@ impl DocumentProgressHandler {
|
|||
EventBubbles::DoesNotBubble,
|
||||
EventCancelable::NotCancelable);
|
||||
let wintarget = window.upcast::<EventTarget>();
|
||||
let doctarget = document.upcast::<EventTarget>();
|
||||
event.r().set_trusted(true);
|
||||
let _ = wintarget.dispatch_event_with_target(doctarget, event.r());
|
||||
let _ = wintarget.dispatch_event_with_target(document.upcast(), &event);
|
||||
|
||||
let browsing_context = window.browsing_context();
|
||||
let browsing_context = browsing_context.as_ref().unwrap();
|
||||
|
@ -1878,8 +1853,7 @@ impl DocumentProgressHandler {
|
|||
let event = Event::new(GlobalRef::Window(frame_window.r()), "load".to_owned(),
|
||||
EventBubbles::DoesNotBubble,
|
||||
EventCancelable::NotCancelable);
|
||||
let target = frame_element.upcast::<EventTarget>();
|
||||
event.r().fire(target);
|
||||
event.fire(frame_element.upcast());
|
||||
};
|
||||
|
||||
document.r().notify_constellation_load();
|
||||
|
|
|
@ -48,7 +48,7 @@ impl DocumentFragmentMethods for DocumentFragment {
|
|||
// https://dom.spec.whatwg.org/#dom-parentnode-children
|
||||
fn Children(&self) -> Root<HTMLCollection> {
|
||||
let window = window_from_node(self);
|
||||
HTMLCollection::children(window.r(), self.upcast::<Node>())
|
||||
HTMLCollection::children(&window, self.upcast())
|
||||
}
|
||||
|
||||
// https://dom.spec.whatwg.org/#dom-nonelementparentnode-getelementbyid
|
||||
|
@ -90,13 +90,11 @@ impl DocumentFragmentMethods for DocumentFragment {
|
|||
|
||||
// https://dom.spec.whatwg.org/#dom-parentnode-queryselector
|
||||
fn QuerySelector(&self, selectors: DOMString) -> Fallible<Option<Root<Element>>> {
|
||||
let root = self.upcast::<Node>();
|
||||
root.query_selector(selectors)
|
||||
self.upcast::<Node>().query_selector(selectors)
|
||||
}
|
||||
|
||||
// https://dom.spec.whatwg.org/#dom-parentnode-queryselectorall
|
||||
fn QuerySelectorAll(&self, selectors: DOMString) -> Fallible<Root<NodeList>> {
|
||||
let root = self.upcast::<Node>();
|
||||
root.query_selector_all(selectors)
|
||||
self.upcast::<Node>().query_selector_all(selectors)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -98,7 +98,6 @@ impl DocumentTypeMethods for DocumentType {
|
|||
|
||||
// https://dom.spec.whatwg.org/#dom-childnode-remove
|
||||
fn Remove(&self) {
|
||||
let node = self.upcast::<Node>();
|
||||
node.remove_self();
|
||||
self.upcast::<Node>().remove_self();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -80,20 +80,13 @@ impl DOMImplementationMethods for DOMImplementation {
|
|||
let doc_node = doc.upcast::<Node>();
|
||||
|
||||
// Step 4.
|
||||
match maybe_doctype {
|
||||
None => (),
|
||||
Some(ref doctype) => {
|
||||
let doc_type = doctype.upcast::<Node>();
|
||||
assert!(doc_node.AppendChild(doc_type).is_ok())
|
||||
}
|
||||
if let Some(doc_type) = maybe_doctype {
|
||||
doc_node.AppendChild(doc_type.upcast()).unwrap();
|
||||
}
|
||||
|
||||
// Step 5.
|
||||
match maybe_elem {
|
||||
None => (),
|
||||
Some(ref elem) => {
|
||||
assert!(doc_node.AppendChild(elem.upcast::<Node>()).is_ok())
|
||||
}
|
||||
if let Some(ref elem) = maybe_elem {
|
||||
doc_node.AppendChild(elem.upcast()).unwrap();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -117,7 +110,7 @@ impl DOMImplementationMethods for DOMImplementation {
|
|||
// Step 3.
|
||||
let doc_node = doc.upcast::<Node>();
|
||||
let doc_type = DocumentType::new("html".to_owned(), None, None, doc.r());
|
||||
assert!(doc_node.AppendChild(doc_type.upcast::<Node>()).is_ok());
|
||||
doc_node.AppendChild(doc_type.upcast()).unwrap();
|
||||
}
|
||||
|
||||
{
|
||||
|
@ -125,13 +118,13 @@ impl DOMImplementationMethods for DOMImplementation {
|
|||
let doc_node = doc.upcast::<Node>();
|
||||
let doc_html = Root::upcast::<Node>(
|
||||
HTMLHtmlElement::new("html".to_owned(), None, doc.r()));
|
||||
assert!(doc_node.AppendChild(doc_html.r()).is_ok());
|
||||
doc_node.AppendChild(&doc_html).expect("Appending failed");
|
||||
|
||||
{
|
||||
// Step 5.
|
||||
let doc_head = Root::upcast::<Node>(
|
||||
HTMLHeadElement::new("head".to_owned(), None, doc.r()));
|
||||
assert!(doc_html.r().AppendChild(doc_head.r()).is_ok());
|
||||
doc_html.AppendChild(&doc_head).unwrap();
|
||||
|
||||
// Step 6.
|
||||
match title {
|
||||
|
@ -140,18 +133,18 @@ impl DOMImplementationMethods for DOMImplementation {
|
|||
// Step 6.1.
|
||||
let doc_title = Root::upcast::<Node>(
|
||||
HTMLTitleElement::new("title".to_owned(), None, doc.r()));
|
||||
assert!(doc_head.r().AppendChild(doc_title.r()).is_ok());
|
||||
doc_head.AppendChild(&doc_title).unwrap();
|
||||
|
||||
// Step 6.2.
|
||||
let title_text = Text::new(title_str, doc.r());
|
||||
assert!(doc_title.r().AppendChild(title_text.upcast::<Node>()).is_ok());
|
||||
doc_title.AppendChild(title_text.upcast()).unwrap();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Step 7.
|
||||
let doc_body = HTMLBodyElement::new("body".to_owned(), None, doc.r());
|
||||
assert!(doc_html.r().AppendChild(doc_body.upcast::<Node>()).is_ok());
|
||||
doc_html.AppendChild(doc_body.upcast()).unwrap();
|
||||
}
|
||||
|
||||
// Step 8.
|
||||
|
|
|
@ -35,7 +35,6 @@ use dom::domrect::DOMRect;
|
|||
use dom::domrectlist::DOMRectList;
|
||||
use dom::domtokenlist::DOMTokenList;
|
||||
use dom::event::Event;
|
||||
use dom::eventtarget::EventTarget;
|
||||
use dom::htmlanchorelement::HTMLAnchorElement;
|
||||
use dom::htmlbodyelement::HTMLBodyElement;
|
||||
use dom::htmlcollection::HTMLCollection;
|
||||
|
@ -544,8 +543,7 @@ impl LayoutElementHelpers for LayoutJS<Element> {
|
|||
if (*self.unsafe_get()).namespace != ns!(HTML) {
|
||||
return false
|
||||
}
|
||||
let node = self.upcast::<Node>();
|
||||
node.owner_doc_for_layout().is_html_document_for_layout()
|
||||
self.upcast::<Node>().owner_doc_for_layout().is_html_document_for_layout()
|
||||
}
|
||||
|
||||
#[allow(unsafe_code)]
|
||||
|
@ -623,8 +621,7 @@ pub enum StylePriority {
|
|||
|
||||
impl Element {
|
||||
pub fn html_element_in_html_document(&self) -> bool {
|
||||
let node = self.upcast::<Node>();
|
||||
self.namespace == ns!(HTML) && node.is_in_html_doc()
|
||||
self.namespace == ns!(HTML) && self.upcast::<Node>().is_in_html_doc()
|
||||
}
|
||||
|
||||
pub fn local_name(&self) -> &Atom {
|
||||
|
@ -784,9 +781,8 @@ impl Element {
|
|||
}
|
||||
|
||||
pub fn serialize(&self, traversal_scope: TraversalScope) -> Fallible<DOMString> {
|
||||
let node = self.upcast::<Node>();
|
||||
let mut writer = vec![];
|
||||
match serialize(&mut writer, &node,
|
||||
match serialize(&mut writer, &self.upcast::<Node>(),
|
||||
SerializeOpts {
|
||||
traversal_scope: traversal_scope,
|
||||
.. Default::default()
|
||||
|
@ -798,10 +794,7 @@ impl Element {
|
|||
|
||||
// https://html.spec.whatwg.org/multipage/#root-element
|
||||
pub fn get_root_element(&self) -> Root<Element> {
|
||||
let node = self.upcast::<Node>();
|
||||
node.inclusive_ancestors()
|
||||
.filter_map(Root::downcast::<Element>)
|
||||
.last()
|
||||
self.upcast::<Node>().inclusive_ancestors().filter_map(Root::downcast).last()
|
||||
.expect("We know inclusive_ancestors will return `self` which is an element")
|
||||
}
|
||||
|
||||
|
@ -889,8 +882,7 @@ impl Element {
|
|||
let attr = Attr::new(&window, local_name, value, name, namespace, prefix, Some(self));
|
||||
self.attrs.borrow_mut().push(JS::from_rooted(&attr));
|
||||
if in_empty_ns {
|
||||
vtable_for(self.upcast::<Node>()).attribute_mutated(
|
||||
&attr, AttributeMutation::Set(None));
|
||||
vtable_for(self.upcast()).attribute_mutated(&attr, AttributeMutation::Set(None));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -974,8 +966,7 @@ impl Element {
|
|||
pub fn parse_attribute(&self, namespace: &Namespace, local_name: &Atom,
|
||||
value: DOMString) -> AttrValue {
|
||||
if *namespace == ns!("") {
|
||||
vtable_for(&self.upcast::<Node>())
|
||||
.parse_plain_attribute(local_name, value)
|
||||
vtable_for(self.upcast()).parse_plain_attribute(local_name, value)
|
||||
} else {
|
||||
AttrValue::String(value)
|
||||
}
|
||||
|
@ -1001,20 +992,15 @@ impl Element {
|
|||
let attr = (*self.attrs.borrow())[idx].root();
|
||||
self.attrs.borrow_mut().remove(idx);
|
||||
attr.set_owner(None);
|
||||
let node = self.upcast::<Node>();
|
||||
if attr.namespace() == &ns!("") {
|
||||
vtable_for(node).attribute_mutated(&attr, AttributeMutation::Removed);
|
||||
vtable_for(self.upcast()).attribute_mutated(&attr, AttributeMutation::Removed);
|
||||
}
|
||||
attr
|
||||
})
|
||||
}
|
||||
|
||||
pub fn has_class(&self, name: &Atom) -> bool {
|
||||
let quirks_mode = {
|
||||
let node = self.upcast::<Node>();
|
||||
let owner_doc = node.owner_doc();
|
||||
owner_doc.r().quirks_mode()
|
||||
};
|
||||
let quirks_mode = document_from_node(self).quirks_mode();
|
||||
let is_equal = |lhs: &Atom, rhs: &Atom| match quirks_mode {
|
||||
NoQuirks | LimitedQuirks => lhs == rhs,
|
||||
Quirks => lhs.eq_ignore_ascii_case(&rhs)
|
||||
|
@ -1175,14 +1161,7 @@ impl ElementMethods for Element {
|
|||
|
||||
// https://dom.spec.whatwg.org/#dom-element-attributes
|
||||
fn Attributes(&self) -> Root<NamedNodeMap> {
|
||||
self.attr_list.or_init(|| {
|
||||
let doc = {
|
||||
let node = self.upcast::<Node>();
|
||||
node.owner_doc()
|
||||
};
|
||||
let window = doc.r().window();
|
||||
NamedNodeMap::new(window, self)
|
||||
})
|
||||
self.attr_list.or_init(|| NamedNodeMap::new(&window_from_node(self), self))
|
||||
}
|
||||
|
||||
// https://dom.spec.whatwg.org/#dom-element-getattribute
|
||||
|
@ -1277,27 +1256,26 @@ impl ElementMethods for Element {
|
|||
// https://dom.spec.whatwg.org/#dom-element-getelementsbytagname
|
||||
fn GetElementsByTagName(&self, localname: DOMString) -> Root<HTMLCollection> {
|
||||
let window = window_from_node(self);
|
||||
HTMLCollection::by_tag_name(window.r(), self.upcast::<Node>(), localname)
|
||||
HTMLCollection::by_tag_name(window.r(), self.upcast(), localname)
|
||||
}
|
||||
|
||||
// https://dom.spec.whatwg.org/#dom-element-getelementsbytagnamens
|
||||
fn GetElementsByTagNameNS(&self, maybe_ns: Option<DOMString>,
|
||||
localname: DOMString) -> Root<HTMLCollection> {
|
||||
let window = window_from_node(self);
|
||||
HTMLCollection::by_tag_name_ns(window.r(), self.upcast::<Node>(), localname, maybe_ns)
|
||||
HTMLCollection::by_tag_name_ns(window.r(), self.upcast(), localname, maybe_ns)
|
||||
}
|
||||
|
||||
// https://dom.spec.whatwg.org/#dom-element-getelementsbyclassname
|
||||
fn GetElementsByClassName(&self, classes: DOMString) -> Root<HTMLCollection> {
|
||||
let window = window_from_node(self);
|
||||
HTMLCollection::by_class_name(window.r(), self.upcast::<Node>(), classes)
|
||||
HTMLCollection::by_class_name(window.r(), self.upcast(), classes)
|
||||
}
|
||||
|
||||
// https://drafts.csswg.org/cssom-view/#dom-element-getclientrects
|
||||
fn GetClientRects(&self) -> Root<DOMRectList> {
|
||||
let win = window_from_node(self);
|
||||
let node = self.upcast::<Node>();
|
||||
let raw_rects = node.get_content_boxes();
|
||||
let raw_rects = self.upcast::<Node>().get_content_boxes();
|
||||
let rects = raw_rects.iter().map(|rect| {
|
||||
DOMRect::new(GlobalRef::Window(win.r()),
|
||||
rect.origin.x.to_f64_px(),
|
||||
|
@ -1311,8 +1289,7 @@ impl ElementMethods for Element {
|
|||
// https://drafts.csswg.org/cssom-view/#dom-element-getboundingclientrect
|
||||
fn GetBoundingClientRect(&self) -> Root<DOMRect> {
|
||||
let win = window_from_node(self);
|
||||
let node = self.upcast::<Node>();
|
||||
let rect = node.get_bounding_content_box();
|
||||
let rect = self.upcast::<Node>().get_bounding_content_box();
|
||||
DOMRect::new(GlobalRef::Window(win.r()),
|
||||
rect.origin.x.to_f64_px(),
|
||||
rect.origin.y.to_f64_px(),
|
||||
|
@ -1322,26 +1299,22 @@ impl ElementMethods for Element {
|
|||
|
||||
// https://drafts.csswg.org/cssom-view/#dom-element-clienttop
|
||||
fn ClientTop(&self) -> i32 {
|
||||
let node = self.upcast::<Node>();
|
||||
node.get_client_rect().origin.y
|
||||
self.upcast::<Node>().get_client_rect().origin.y
|
||||
}
|
||||
|
||||
// https://drafts.csswg.org/cssom-view/#dom-element-clientleft
|
||||
fn ClientLeft(&self) -> i32 {
|
||||
let node = self.upcast::<Node>();
|
||||
node.get_client_rect().origin.x
|
||||
self.upcast::<Node>().get_client_rect().origin.x
|
||||
}
|
||||
|
||||
// https://drafts.csswg.org/cssom-view/#dom-element-clientwidth
|
||||
fn ClientWidth(&self) -> i32 {
|
||||
let node = self.upcast::<Node>();
|
||||
node.get_client_rect().size.width
|
||||
self.upcast::<Node>().get_client_rect().size.width
|
||||
}
|
||||
|
||||
// https://drafts.csswg.org/cssom-view/#dom-element-clientheight
|
||||
fn ClientHeight(&self) -> i32 {
|
||||
let node = self.upcast::<Node>();
|
||||
node.get_client_rect().size.height
|
||||
self.upcast::<Node>().get_client_rect().size.height
|
||||
}
|
||||
|
||||
/// https://w3c.github.io/DOM-Parsing/#widl-Element-innerHTML
|
||||
|
@ -1358,11 +1331,11 @@ impl ElementMethods for Element {
|
|||
// Step 2.
|
||||
// https://github.com/w3c/DOM-Parsing/issues/1
|
||||
let target = if let Some(template) = self.downcast::<HTMLTemplateElement>() {
|
||||
Root::upcast::<Node>(template.Content())
|
||||
Root::upcast(template.Content())
|
||||
} else {
|
||||
Root::from_ref(context_node)
|
||||
};
|
||||
Node::replace_all(Some(frag.upcast::<Node>()), &target);
|
||||
Node::replace_all(Some(frag.upcast()), &target);
|
||||
Ok(())
|
||||
}
|
||||
|
||||
|
@ -1393,7 +1366,7 @@ impl ElementMethods for Element {
|
|||
let body_elem = Element::create(QualName::new(ns!(HTML), atom!(body)),
|
||||
None, context_document.r(),
|
||||
ElementCreator::ScriptCreated);
|
||||
Root::upcast::<Node>(body_elem)
|
||||
Root::upcast(body_elem)
|
||||
},
|
||||
_ => context_node.GetParentNode().unwrap()
|
||||
};
|
||||
|
@ -1401,27 +1374,24 @@ impl ElementMethods for Element {
|
|||
// Step 5.
|
||||
let frag = try!(parent.r().parse_fragment(value));
|
||||
// Step 6.
|
||||
try!(context_parent.r().ReplaceChild(frag.upcast::<Node>(),
|
||||
context_node));
|
||||
try!(context_parent.ReplaceChild(frag.upcast(), context_node));
|
||||
Ok(())
|
||||
}
|
||||
|
||||
// https://dom.spec.whatwg.org/#dom-nondocumenttypechildnode-previouselementsibling
|
||||
fn GetPreviousElementSibling(&self) -> Option<Root<Element>> {
|
||||
self.upcast::<Node>().preceding_siblings()
|
||||
.filter_map(Root::downcast::<Element>).next()
|
||||
self.upcast::<Node>().preceding_siblings().filter_map(Root::downcast).next()
|
||||
}
|
||||
|
||||
// https://dom.spec.whatwg.org/#dom-nondocumenttypechildnode-nextelementsibling
|
||||
fn GetNextElementSibling(&self) -> Option<Root<Element>> {
|
||||
self.upcast::<Node>().following_siblings()
|
||||
.filter_map(Root::downcast::<Element>).next()
|
||||
self.upcast::<Node>().following_siblings().filter_map(Root::downcast).next()
|
||||
}
|
||||
|
||||
// https://dom.spec.whatwg.org/#dom-parentnode-children
|
||||
fn Children(&self) -> Root<HTMLCollection> {
|
||||
let window = window_from_node(self);
|
||||
HTMLCollection::children(window.r(), self.upcast::<Node>())
|
||||
HTMLCollection::children(window.r(), self.upcast())
|
||||
}
|
||||
|
||||
// https://dom.spec.whatwg.org/#dom-parentnode-firstelementchild
|
||||
|
@ -1478,8 +1448,7 @@ impl ElementMethods for Element {
|
|||
|
||||
// https://dom.spec.whatwg.org/#dom-childnode-remove
|
||||
fn Remove(&self) {
|
||||
let node = self.upcast::<Node>();
|
||||
node.remove_self();
|
||||
self.upcast::<Node>().remove_self();
|
||||
}
|
||||
|
||||
// https://dom.spec.whatwg.org/#dom-element-matches
|
||||
|
@ -1513,8 +1482,7 @@ impl ElementMethods for Element {
|
|||
|
||||
impl VirtualMethods for Element {
|
||||
fn super_type(&self) -> Option<&VirtualMethods> {
|
||||
let node: &Node = self.upcast::<Node>();
|
||||
Some(node as &VirtualMethods)
|
||||
Some(self.upcast::<Node>() as &VirtualMethods)
|
||||
}
|
||||
|
||||
fn attribute_mutated(&self, attr: &Attr, mutation: AttributeMutation) {
|
||||
|
@ -1620,15 +1588,15 @@ impl<'a> ::selectors::Element for Root<Element> {
|
|||
}
|
||||
|
||||
fn last_child_element(&self) -> Option<Root<Element>> {
|
||||
self.node.rev_children().filter_map(Root::downcast::<Element>).next()
|
||||
self.node.rev_children().filter_map(Root::downcast).next()
|
||||
}
|
||||
|
||||
fn prev_sibling_element(&self) -> Option<Root<Element>> {
|
||||
self.node.preceding_siblings().filter_map(Root::downcast::<Element>).next()
|
||||
self.node.preceding_siblings().filter_map(Root::downcast).next()
|
||||
}
|
||||
|
||||
fn next_sibling_element(&self) -> Option<Root<Element>> {
|
||||
self.node.following_siblings().filter_map(Root::downcast::<Element>).next()
|
||||
self.node.following_siblings().filter_map(Root::downcast).next()
|
||||
}
|
||||
|
||||
fn is_root(&self) -> bool {
|
||||
|
@ -1701,15 +1669,13 @@ impl<'a> ::selectors::Element for Root<Element> {
|
|||
Element::get_enabled_state(self)
|
||||
}
|
||||
fn get_checked_state(&self) -> bool {
|
||||
let input_element: Option<&HTMLInputElement> = self.downcast::<HTMLInputElement>();
|
||||
match input_element {
|
||||
match self.downcast::<HTMLInputElement>() {
|
||||
Some(input) => input.Checked(),
|
||||
None => false,
|
||||
}
|
||||
}
|
||||
fn get_indeterminate_state(&self) -> bool {
|
||||
let input_element: Option<&HTMLInputElement> = self.downcast::<HTMLInputElement>();
|
||||
match input_element {
|
||||
match self.downcast::<HTMLInputElement>() {
|
||||
Some(input) => input.get_indeterminate_state(),
|
||||
None => false,
|
||||
}
|
||||
|
@ -1729,8 +1695,7 @@ impl<'a> ::selectors::Element for Root<Element> {
|
|||
}
|
||||
}
|
||||
fn has_servo_nonzero_border(&self) -> bool {
|
||||
let table_element: Option<&HTMLTableElement> = self.downcast::<HTMLTableElement>();
|
||||
match table_element {
|
||||
match self.downcast::<HTMLTableElement>() {
|
||||
None => false,
|
||||
Some(this) => {
|
||||
match this.get_border() {
|
||||
|
@ -1774,8 +1739,7 @@ impl<'a> ::selectors::Element for Root<Element> {
|
|||
|
||||
impl Element {
|
||||
pub fn as_maybe_activatable(&self) -> Option<&Activatable> {
|
||||
let node = self.upcast::<Node>();
|
||||
let element = match node.type_id() {
|
||||
let element = match self.upcast::<Node>().type_id() {
|
||||
NodeTypeId::Element(ElementTypeId::HTMLElement(HTMLElementTypeId::HTMLInputElement)) => {
|
||||
let element = self.downcast::<HTMLInputElement>().unwrap();
|
||||
Some(element as &Activatable)
|
||||
|
@ -1798,13 +1762,11 @@ impl Element {
|
|||
}
|
||||
|
||||
pub fn click_in_progress(&self) -> bool {
|
||||
let node = self.upcast::<Node>();
|
||||
node.get_flag(CLICK_IN_PROGRESS)
|
||||
self.upcast::<Node>().get_flag(CLICK_IN_PROGRESS)
|
||||
}
|
||||
|
||||
pub fn set_click_in_progress(&self, click: bool) {
|
||||
let node = self.upcast::<Node>();
|
||||
node.set_flag(CLICK_IN_PROGRESS, click)
|
||||
self.upcast::<Node>().set_flag(CLICK_IN_PROGRESS, click)
|
||||
}
|
||||
|
||||
// https://html.spec.whatwg.org/multipage/#nearest-activatable-element
|
||||
|
@ -1838,7 +1800,7 @@ impl Element {
|
|||
// the script can generate more click events from the handler)
|
||||
assert!(!self.click_in_progress());
|
||||
|
||||
let target = self.upcast::<EventTarget>();
|
||||
let target = self.upcast();
|
||||
// Step 2 (requires canvas support)
|
||||
// Step 3
|
||||
self.set_click_in_progress(true);
|
||||
|
|
|
@ -150,8 +150,7 @@ pub fn dispatch_event(target: &EventTarget, pseudo_target: Option<&EventTarget>,
|
|||
let mut chain: RootedVec<JS<EventTarget>> = RootedVec::new();
|
||||
if let Some(target_node) = target.downcast::<Node>() {
|
||||
for ancestor in target_node.ancestors() {
|
||||
let ancestor_target = ancestor.upcast::<EventTarget>();
|
||||
chain.push(JS::from_ref(ancestor_target))
|
||||
chain.push(JS::from_ref(ancestor.upcast()));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -161,14 +160,10 @@ pub fn dispatch_event(target: &EventTarget, pseudo_target: Option<&EventTarget>,
|
|||
let target = event.GetTarget();
|
||||
match target {
|
||||
Some(ref target) => {
|
||||
let node: Option<&Node> = target.downcast::<Node>();
|
||||
match node {
|
||||
Some(node) => {
|
||||
if let Some(node) = target.downcast::<Node>() {
|
||||
let vtable = vtable_for(&node);
|
||||
vtable.handle_event(event);
|
||||
}
|
||||
None => {}
|
||||
}
|
||||
}
|
||||
None => {}
|
||||
}
|
||||
|
|
|
@ -324,10 +324,7 @@ impl FileReader {
|
|||
let progressevent = ProgressEvent::new(global.r(),
|
||||
type_, EventBubbles::DoesNotBubble, EventCancelable::NotCancelable,
|
||||
total.is_some(), loaded, total.unwrap_or(0));
|
||||
|
||||
let target = self.upcast::<EventTarget>();
|
||||
let event = progressevent.upcast::<Event>();
|
||||
event.fire(target);
|
||||
progressevent.upcast::<Event>().fire(self.upcast());
|
||||
}
|
||||
|
||||
fn terminate_ongoing_reading(&self) {
|
||||
|
|
|
@ -116,7 +116,7 @@ impl FormDataMethods for FormData {
|
|||
impl FormData {
|
||||
fn get_file_from_blob(&self, value: &Blob, filename: Option<DOMString>) -> Root<File> {
|
||||
let global = self.global.root();
|
||||
let f: Option<&File> = value.downcast::<File>();
|
||||
let f = value.downcast::<File>();
|
||||
let name = filename.unwrap_or(f.map(|inner| inner.name().clone()).unwrap_or("blob".to_owned()));
|
||||
File::new(global.r(), value, name)
|
||||
}
|
||||
|
|
|
@ -56,8 +56,7 @@ impl HTMLAnchorElement {
|
|||
|
||||
impl VirtualMethods for HTMLAnchorElement {
|
||||
fn super_type(&self) -> Option<&VirtualMethods> {
|
||||
let htmlelement: &HTMLElement = self.upcast::<HTMLElement>();
|
||||
Some(htmlelement as &VirtualMethods)
|
||||
Some(self.upcast::<HTMLElement>() as &VirtualMethods)
|
||||
}
|
||||
|
||||
fn parse_plain_attribute(&self, name: &Atom, value: DOMString) -> AttrValue {
|
||||
|
@ -71,20 +70,18 @@ impl VirtualMethods for HTMLAnchorElement {
|
|||
impl HTMLAnchorElementMethods for HTMLAnchorElement {
|
||||
// https://html.spec.whatwg.org/multipage/#dom-a-text
|
||||
fn Text(&self) -> DOMString {
|
||||
let node = self.upcast::<Node>();
|
||||
node.GetTextContent().unwrap()
|
||||
self.upcast::<Node>().GetTextContent().unwrap()
|
||||
}
|
||||
|
||||
// https://html.spec.whatwg.org/multipage/#dom-a-text
|
||||
fn SetText(&self, value: DOMString) {
|
||||
let node = self.upcast::<Node>();
|
||||
node.SetTextContent(Some(value))
|
||||
self.upcast::<Node>().SetTextContent(Some(value))
|
||||
}
|
||||
|
||||
// https://html.spec.whatwg.org/multipage/#dom-a-rellist
|
||||
fn RelList(&self) -> Root<DOMTokenList> {
|
||||
self.rel_list.or_init(|| {
|
||||
DOMTokenList::new(self.upcast::<Element>(), &atom!("rel"))
|
||||
DOMTokenList::new(self.upcast(), &atom!("rel"))
|
||||
})
|
||||
}
|
||||
|
||||
|
|
|
@ -10,7 +10,6 @@ use dom::bindings::js::{JS, MutNullableHeap, Root};
|
|||
use dom::bindings::utils::Reflectable;
|
||||
use dom::document::Document;
|
||||
use dom::domtokenlist::DOMTokenList;
|
||||
use dom::element::Element;
|
||||
use dom::htmlelement::HTMLElement;
|
||||
use dom::node::Node;
|
||||
use dom::virtualmethods::VirtualMethods;
|
||||
|
@ -43,8 +42,7 @@ impl HTMLAreaElement {
|
|||
|
||||
impl VirtualMethods for HTMLAreaElement {
|
||||
fn super_type(&self) -> Option<&VirtualMethods> {
|
||||
let htmlelement: &HTMLElement = self.upcast::<HTMLElement>();
|
||||
Some(htmlelement as &VirtualMethods)
|
||||
Some(self.upcast::<HTMLElement>() as &VirtualMethods)
|
||||
}
|
||||
|
||||
fn parse_plain_attribute(&self, name: &Atom, value: DOMString) -> AttrValue {
|
||||
|
@ -59,7 +57,7 @@ impl HTMLAreaElementMethods for HTMLAreaElement {
|
|||
// https://html.spec.whatwg.org/multipage/#dom-area-rellist
|
||||
fn RelList(&self) -> Root<DOMTokenList> {
|
||||
self.rel_list.or_init(|| {
|
||||
DOMTokenList::new(self.upcast::<Element>(), &atom!("rel"))
|
||||
DOMTokenList::new(self.upcast(), &atom!("rel"))
|
||||
})
|
||||
}
|
||||
}
|
||||
|
|
|
@ -124,8 +124,7 @@ impl HTMLBodyElement {
|
|||
|
||||
impl VirtualMethods for HTMLBodyElement {
|
||||
fn super_type(&self) -> Option<&VirtualMethods> {
|
||||
let element: &HTMLElement = self.upcast::<HTMLElement>();
|
||||
Some(element as &VirtualMethods)
|
||||
Some(self.upcast::<HTMLElement>() as &VirtualMethods)
|
||||
}
|
||||
|
||||
fn bind_to_tree(&self, tree_in_doc: bool) {
|
||||
|
|
|
@ -82,8 +82,7 @@ impl HTMLButtonElementMethods for HTMLButtonElement {
|
|||
|
||||
// https://html.spec.whatwg.org/multipage/#dom-button-type
|
||||
fn Type(&self) -> DOMString {
|
||||
let elem = self.upcast::<Element>();
|
||||
let mut ty = elem.get_string_attribute(&atom!("type"));
|
||||
let mut ty = self.upcast::<Element>().get_string_attribute(&atom!("type"));
|
||||
ty.make_ascii_lowercase();
|
||||
// https://html.spec.whatwg.org/multipage/#attr-button-type
|
||||
match &*ty {
|
||||
|
@ -135,8 +134,7 @@ impl HTMLButtonElementMethods for HTMLButtonElement {
|
|||
|
||||
impl VirtualMethods for HTMLButtonElement {
|
||||
fn super_type(&self) -> Option<&VirtualMethods> {
|
||||
let htmlelement: &HTMLElement = self.upcast::<HTMLElement>();
|
||||
Some(htmlelement as &VirtualMethods)
|
||||
Some(self.upcast::<HTMLElement>() as &VirtualMethods)
|
||||
}
|
||||
|
||||
fn attribute_mutated(&self, attr: &Attr, mutation: AttributeMutation) {
|
||||
|
@ -166,8 +164,7 @@ impl VirtualMethods for HTMLButtonElement {
|
|||
s.bind_to_tree(tree_in_doc);
|
||||
}
|
||||
|
||||
let el = self.upcast::<Element>();
|
||||
el.check_ancestors_disabled_state_for_form_control();
|
||||
self.upcast::<Element>().check_ancestors_disabled_state_for_form_control();
|
||||
}
|
||||
|
||||
fn unbind_from_tree(&self, tree_in_doc: bool) {
|
||||
|
@ -189,13 +186,12 @@ impl FormControl for HTMLButtonElement {}
|
|||
|
||||
impl<'a> Activatable for &'a HTMLButtonElement {
|
||||
fn as_element(&self) -> &Element {
|
||||
self.upcast::<Element>()
|
||||
self.upcast()
|
||||
}
|
||||
|
||||
fn is_instance_activatable(&self) -> bool {
|
||||
//https://html.spec.whatwg.org/multipage/#the-button-element
|
||||
let el = self.upcast::<Element>();
|
||||
!(el.get_disabled_state())
|
||||
!self.upcast::<Element>().get_disabled_state()
|
||||
}
|
||||
|
||||
// https://html.spec.whatwg.org/multipage/#run-pre-click-activation-steps
|
||||
|
@ -228,8 +224,7 @@ impl<'a> Activatable for &'a HTMLButtonElement {
|
|||
let doc = document_from_node(*self);
|
||||
let node = doc.upcast::<Node>();
|
||||
let owner = self.form_owner();
|
||||
let elem = self.upcast::<Element>();
|
||||
if owner.is_none() || elem.click_in_progress() {
|
||||
if owner.is_none() || self.upcast::<Element>().click_in_progress() {
|
||||
return;
|
||||
}
|
||||
node.query_selector_iter("button[type=submit]".to_owned()).unwrap()
|
||||
|
|
|
@ -225,8 +225,7 @@ impl HTMLCanvasElementMethods for HTMLCanvasElement {
|
|||
|
||||
// https://html.spec.whatwg.org/multipage/#dom-canvas-width
|
||||
fn SetWidth(&self, width: u32) {
|
||||
let elem = self.upcast::<Element>();
|
||||
elem.set_uint_attribute(&atom!("width"), width)
|
||||
self.upcast::<Element>().set_uint_attribute(&atom!("width"), width)
|
||||
}
|
||||
|
||||
// https://html.spec.whatwg.org/multipage/#dom-canvas-height
|
||||
|
@ -236,8 +235,7 @@ impl HTMLCanvasElementMethods for HTMLCanvasElement {
|
|||
|
||||
// https://html.spec.whatwg.org/multipage/#dom-canvas-height
|
||||
fn SetHeight(&self, height: u32) {
|
||||
let elem = self.upcast::<Element>();
|
||||
elem.set_uint_attribute(&atom!("height"), height)
|
||||
self.upcast::<Element>().set_uint_attribute(&atom!("height"), height)
|
||||
}
|
||||
|
||||
// https://html.spec.whatwg.org/multipage/#dom-canvas-getcontext
|
||||
|
@ -264,8 +262,7 @@ impl HTMLCanvasElementMethods for HTMLCanvasElement {
|
|||
|
||||
impl VirtualMethods for HTMLCanvasElement {
|
||||
fn super_type(&self) -> Option<&VirtualMethods> {
|
||||
let element: &HTMLElement = self.upcast::<HTMLElement>();
|
||||
Some(element as &VirtualMethods)
|
||||
Some(self.upcast::<HTMLElement>() as &VirtualMethods)
|
||||
}
|
||||
|
||||
fn attribute_mutated(&self, attr: &Attr, mutation: AttributeMutation) {
|
||||
|
|
|
@ -154,7 +154,7 @@ impl HTMLCollection {
|
|||
struct ElementChildFilter;
|
||||
impl CollectionFilter for ElementChildFilter {
|
||||
fn filter(&self, elem: &Element, root: &Node) -> bool {
|
||||
root.is_parent_of(elem.upcast::<Node>())
|
||||
root.is_parent_of(elem.upcast())
|
||||
}
|
||||
}
|
||||
HTMLCollection::create(window, root, box ElementChildFilter)
|
||||
|
@ -186,8 +186,8 @@ impl<'a> Iterator for HTMLCollectionElementsIter<'a> {
|
|||
let filter = self.filter;
|
||||
let root = self.root.r();
|
||||
self.node_iter.by_ref()
|
||||
.filter_map(Root::downcast::<Element>)
|
||||
.filter(|element| filter.filter(element.r(), root))
|
||||
.filter_map(Root::downcast)
|
||||
.filter(|element| filter.filter(&element, root))
|
||||
.next()
|
||||
}
|
||||
}
|
||||
|
|
|
@ -48,9 +48,8 @@ impl HTMLDataListElementMethods for HTMLDataListElement {
|
|||
elem.is::<HTMLOptionElement>()
|
||||
}
|
||||
}
|
||||
let node = self.upcast::<Node>();
|
||||
let filter = box HTMLDataListOptionsFilter;
|
||||
let window = window_from_node(node);
|
||||
HTMLCollection::create(window.r(), node, filter)
|
||||
let window = window_from_node(self);
|
||||
HTMLCollection::create(window.r(), self.upcast(), filter)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -162,41 +162,37 @@ impl HTMLElementMethods for HTMLElement {
|
|||
let win = window_from_node(self);
|
||||
win.r().SetOnload(listener)
|
||||
} else {
|
||||
let target = self.upcast::<EventTarget>();
|
||||
target.set_event_handler_common("load", listener)
|
||||
self.upcast::<EventTarget>().set_event_handler_common("load", listener)
|
||||
}
|
||||
}
|
||||
|
||||
// https://html.spec.whatwg.org/multipage/#dom-click
|
||||
fn Click(&self) {
|
||||
let maybe_input: Option<&HTMLInputElement> = self.downcast::<HTMLInputElement>();
|
||||
if let Some(i) = maybe_input {
|
||||
if let Some(i) = self.downcast::<HTMLInputElement>() {
|
||||
if i.Disabled() {
|
||||
return;
|
||||
}
|
||||
}
|
||||
let element = self.upcast::<Element>();
|
||||
// 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));
|
||||
self.upcast::<Element>()
|
||||
.as_maybe_activatable()
|
||||
.map(|a| a.synthetic_click_activation(false, false, false, false));
|
||||
}
|
||||
|
||||
// https://html.spec.whatwg.org/multipage/#dom-focus
|
||||
fn Focus(&self) {
|
||||
// TODO: Mark the element as locked for focus and run the focusing steps.
|
||||
// https://html.spec.whatwg.org/multipage/#focusing-steps
|
||||
let element = self.upcast::<Element>();
|
||||
let document = document_from_node(self);
|
||||
let document = document.r();
|
||||
document.begin_focus_transaction();
|
||||
document.request_focus(element);
|
||||
document.request_focus(self.upcast());
|
||||
document.commit_focus_transaction(FocusType::Element);
|
||||
}
|
||||
|
||||
// https://html.spec.whatwg.org/multipage/#dom-blur
|
||||
fn Blur(&self) {
|
||||
// TODO: Run the unfocusing steps.
|
||||
let el = self.upcast::<Element>();
|
||||
if !el.get_focus_state() {
|
||||
if !self.upcast::<Element>().get_focus_state() {
|
||||
return;
|
||||
}
|
||||
// https://html.spec.whatwg.org/multipage/#unfocusing-steps
|
||||
|
@ -286,29 +282,25 @@ impl HTMLElement {
|
|||
.nth(1).map_or(false, |ch| ch >= 'a' && ch <= 'z') {
|
||||
return Err(Error::Syntax);
|
||||
}
|
||||
let element = self.upcast::<Element>();
|
||||
element.set_custom_attribute(to_snake_case(name), value)
|
||||
self.upcast::<Element>().set_custom_attribute(to_snake_case(name), value)
|
||||
}
|
||||
|
||||
pub fn get_custom_attr(&self, local_name: DOMString) -> Option<DOMString> {
|
||||
let element = self.upcast::<Element>();
|
||||
let local_name = Atom::from_slice(&to_snake_case(local_name));
|
||||
element.get_attribute(&ns!(""), &local_name).map(|attr| {
|
||||
self.upcast::<Element>().get_attribute(&ns!(""), &local_name).map(|attr| {
|
||||
(**attr.r().value()).to_owned()
|
||||
})
|
||||
}
|
||||
|
||||
pub fn delete_custom_attr(&self, local_name: DOMString) {
|
||||
let element = self.upcast::<Element>();
|
||||
let local_name = Atom::from_slice(&to_snake_case(local_name));
|
||||
element.remove_attribute(&ns!(""), &local_name);
|
||||
self.upcast::<Element>().remove_attribute(&ns!(""), &local_name);
|
||||
}
|
||||
}
|
||||
|
||||
impl VirtualMethods for HTMLElement {
|
||||
fn super_type(&self) -> Option<&VirtualMethods> {
|
||||
let element: &Element = self.upcast::<Element>();
|
||||
Some(element as &VirtualMethods)
|
||||
Some(self.upcast::<Element>() as &VirtualMethods)
|
||||
}
|
||||
|
||||
fn attribute_mutated(&self, attr: &Attr, mutation: AttributeMutation) {
|
||||
|
|
|
@ -56,10 +56,9 @@ impl HTMLFieldSetElementMethods for HTMLFieldSetElement {
|
|||
TAG_NAMES.iter().any(|&tag_name| tag_name == &**elem.local_name())
|
||||
}
|
||||
}
|
||||
let node = self.upcast::<Node>();
|
||||
let filter = box ElementsFilter;
|
||||
let window = window_from_node(node);
|
||||
HTMLCollection::create(window.r(), node, filter)
|
||||
let window = window_from_node(self);
|
||||
HTMLCollection::create(window.r(), self.upcast(), filter)
|
||||
}
|
||||
|
||||
// https://html.spec.whatwg.org/multipage/#dom-cva-validity
|
||||
|
@ -82,8 +81,7 @@ impl HTMLFieldSetElementMethods for HTMLFieldSetElement {
|
|||
|
||||
impl VirtualMethods for HTMLFieldSetElement {
|
||||
fn super_type(&self) -> Option<&VirtualMethods> {
|
||||
let htmlelement: &HTMLElement = self.upcast::<HTMLElement>();
|
||||
Some(htmlelement as &VirtualMethods)
|
||||
Some(self.upcast::<HTMLElement>() as &VirtualMethods)
|
||||
}
|
||||
|
||||
fn attribute_mutated(&self, attr: &Attr, mutation: AttributeMutation) {
|
||||
|
|
|
@ -71,8 +71,7 @@ impl HTMLFontElementMethods for HTMLFontElement {
|
|||
|
||||
impl VirtualMethods for HTMLFontElement {
|
||||
fn super_type(&self) -> Option<&VirtualMethods> {
|
||||
let htmlelement = self.upcast::<HTMLElement>();
|
||||
Some(htmlelement as &VirtualMethods)
|
||||
Some(self.upcast::<HTMLElement>() as &VirtualMethods)
|
||||
}
|
||||
|
||||
fn attribute_mutated(&self, attr: &Attr, mutation: AttributeMutation) {
|
||||
|
|
|
@ -17,7 +17,6 @@ use dom::bindings::utils::Reflectable;
|
|||
use dom::document::Document;
|
||||
use dom::element::Element;
|
||||
use dom::event::{Event, EventBubbles, EventCancelable};
|
||||
use dom::eventtarget::EventTarget;
|
||||
use dom::htmlbuttonelement::{HTMLButtonElement};
|
||||
use dom::htmldatalistelement::HTMLDataListElement;
|
||||
use dom::htmlelement::HTMLElement;
|
||||
|
@ -163,8 +162,7 @@ impl HTMLFormElement {
|
|||
"submit".to_owned(),
|
||||
EventBubbles::Bubbles,
|
||||
EventCancelable::Cancelable);
|
||||
let target = self.upcast::<EventTarget>();
|
||||
event.r().fire(target);
|
||||
event.fire(self.upcast());
|
||||
if event.r().DefaultPrevented() {
|
||||
return;
|
||||
}
|
||||
|
@ -316,21 +314,17 @@ impl HTMLFormElement {
|
|||
"reset".to_owned(),
|
||||
EventBubbles::Bubbles,
|
||||
EventCancelable::Cancelable);
|
||||
let target = self.upcast::<EventTarget>();
|
||||
event.r().fire(target);
|
||||
event.fire(self.upcast());
|
||||
if event.r().DefaultPrevented() {
|
||||
return;
|
||||
}
|
||||
|
||||
let node = self.upcast::<Node>();
|
||||
|
||||
// TODO: This is an incorrect way of getting controls owned
|
||||
// by the form, but good enough until html5ever lands
|
||||
for child in node.traverse_preorder() {
|
||||
for child in self.upcast::<Node>().traverse_preorder() {
|
||||
match child.r().type_id() {
|
||||
NodeTypeId::Element(ElementTypeId::HTMLElement(HTMLElementTypeId::HTMLInputElement)) => {
|
||||
let input = child.downcast::<HTMLInputElement>().unwrap();
|
||||
input.reset()
|
||||
child.downcast::<HTMLInputElement>().unwrap().reset();
|
||||
}
|
||||
// TODO HTMLKeygenElement unimplemented
|
||||
//NodeTypeId::Element(ElementTypeId::HTMLElement(HTMLElementTypeId::HTMLKeygenElement)) => {
|
||||
|
@ -342,8 +336,7 @@ impl HTMLFormElement {
|
|||
{}
|
||||
}
|
||||
NodeTypeId::Element(ElementTypeId::HTMLElement(HTMLElementTypeId::HTMLTextAreaElement)) => {
|
||||
let textarea = child.downcast::<HTMLTextAreaElement>().unwrap();
|
||||
textarea.reset()
|
||||
child.downcast::<HTMLTextAreaElement>().unwrap().reset();
|
||||
}
|
||||
NodeTypeId::Element(ElementTypeId::HTMLElement(HTMLElementTypeId::HTMLOutputElement)) => {
|
||||
// Unimplemented
|
||||
|
@ -484,13 +477,7 @@ pub trait FormControl: DerivedFrom<Element> + Reflectable {
|
|||
_ => ()
|
||||
}
|
||||
}
|
||||
let node = elem.upcast::<Node>();
|
||||
for ancestor in node.ancestors() {
|
||||
if let Some(ancestor) = ancestor.downcast::<HTMLFormElement>() {
|
||||
return Some(Root::from_ref(ancestor))
|
||||
}
|
||||
}
|
||||
None
|
||||
elem.upcast::<Node>().ancestors().filter_map(Root::downcast).next()
|
||||
}
|
||||
|
||||
fn get_form_attribute<InputFn, OwnerFn>(&self,
|
||||
|
@ -509,7 +496,7 @@ pub trait FormControl: DerivedFrom<Element> + Reflectable {
|
|||
}
|
||||
|
||||
fn to_element(&self) -> &Element {
|
||||
self.upcast::<Element>()
|
||||
self.upcast()
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -37,8 +37,7 @@ impl HTMLHeadElement {
|
|||
|
||||
impl VirtualMethods for HTMLHeadElement {
|
||||
fn super_type(&self) -> Option<&VirtualMethods> {
|
||||
let htmlelement: &HTMLElement = self.upcast::<HTMLElement>();
|
||||
Some(htmlelement as &VirtualMethods)
|
||||
Some(self.upcast::<HTMLElement>() as &VirtualMethods)
|
||||
}
|
||||
fn bind_to_tree(&self, _tree_in_doc: bool) {
|
||||
load_script(self);
|
||||
|
|
|
@ -15,7 +15,6 @@ use dom::customevent::CustomEvent;
|
|||
use dom::document::Document;
|
||||
use dom::element::{self, AttributeMutation, Element};
|
||||
use dom::event::Event;
|
||||
use dom::eventtarget::EventTarget;
|
||||
use dom::htmlelement::HTMLElement;
|
||||
use dom::node::{Node, window_from_node};
|
||||
use dom::urlhelper::UrlHelper;
|
||||
|
@ -148,9 +147,7 @@ impl HTMLIFrameElement {
|
|||
true,
|
||||
true,
|
||||
detail.handle());
|
||||
let target = self.upcast::<EventTarget>();
|
||||
let event = custom_event.upcast::<Event>();
|
||||
event.fire(target);
|
||||
custom_event.upcast::<Event>().fire(self.upcast());
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -161,7 +158,7 @@ impl HTMLIFrameElement {
|
|||
#[allow(unsafe_code)]
|
||||
pub fn get_width(&self) -> LengthOrPercentageOrAuto {
|
||||
unsafe {
|
||||
element::get_attr_for_layout(self.upcast::<Element>(),
|
||||
element::get_attr_for_layout(self.upcast(),
|
||||
&ns!(""),
|
||||
&atom!("width")).map(|attribute| {
|
||||
str::parse_length(&**attribute.value_for_layout())
|
||||
|
@ -172,7 +169,7 @@ impl HTMLIFrameElement {
|
|||
#[allow(unsafe_code)]
|
||||
pub fn get_height(&self) -> LengthOrPercentageOrAuto {
|
||||
unsafe {
|
||||
element::get_attr_for_layout(self.upcast::<Element>(),
|
||||
element::get_attr_for_layout(self.upcast(),
|
||||
&ns!(""),
|
||||
&atom!("height")).map(|attribute| {
|
||||
str::parse_length(&**attribute.value_for_layout())
|
||||
|
@ -227,8 +224,7 @@ impl HTMLIFrameElementLayoutMethods for LayoutJS<HTMLIFrameElement> {
|
|||
|
||||
pub fn Navigate(iframe: &HTMLIFrameElement, direction: NavigationDirection) -> Fallible<()> {
|
||||
if iframe.Mozbrowser() {
|
||||
let node = iframe.upcast::<Node>();
|
||||
if node.is_in_doc() {
|
||||
if iframe.upcast::<Node>().is_in_doc() {
|
||||
let window = window_from_node(iframe);
|
||||
let window = window.r();
|
||||
|
||||
|
@ -249,26 +245,22 @@ pub fn Navigate(iframe: &HTMLIFrameElement, direction: NavigationDirection) -> F
|
|||
impl HTMLIFrameElementMethods for HTMLIFrameElement {
|
||||
// https://html.spec.whatwg.org/multipage/#dom-iframe-src
|
||||
fn Src(&self) -> DOMString {
|
||||
let element = self.upcast::<Element>();
|
||||
element.get_string_attribute(&atom!("src"))
|
||||
self.upcast::<Element>().get_string_attribute(&atom!("src"))
|
||||
}
|
||||
|
||||
// https://html.spec.whatwg.org/multipage/#dom-iframe-src
|
||||
fn SetSrc(&self, src: DOMString) {
|
||||
let element = self.upcast::<Element>();
|
||||
element.set_url_attribute(&atom!("src"), src)
|
||||
self.upcast::<Element>().set_url_attribute(&atom!("src"), src)
|
||||
}
|
||||
|
||||
// https://html.spec.whatwg.org/multipage/#dom-iframe-sandbox
|
||||
fn Sandbox(&self) -> DOMString {
|
||||
let element = self.upcast::<Element>();
|
||||
element.get_string_attribute(&atom!("sandbox"))
|
||||
self.upcast::<Element>().get_string_attribute(&atom!("sandbox"))
|
||||
}
|
||||
|
||||
// https://html.spec.whatwg.org/multipage/#dom-iframe-sandbox
|
||||
fn SetSandbox(&self, sandbox: DOMString) {
|
||||
let element = self.upcast::<Element>();
|
||||
element.set_tokenlist_attribute(&atom!("sandbox"), sandbox);
|
||||
self.upcast::<Element>().set_tokenlist_attribute(&atom!("sandbox"), sandbox);
|
||||
}
|
||||
|
||||
// https://html.spec.whatwg.org/multipage/#dom-iframe-contentwindow
|
||||
|
@ -360,8 +352,7 @@ impl HTMLIFrameElementMethods for HTMLIFrameElement {
|
|||
|
||||
impl VirtualMethods for HTMLIFrameElement {
|
||||
fn super_type(&self) -> Option<&VirtualMethods> {
|
||||
let htmlelement: &HTMLElement = self.upcast::<HTMLElement>();
|
||||
Some(htmlelement as &VirtualMethods)
|
||||
Some(self.upcast::<HTMLElement>() as &VirtualMethods)
|
||||
}
|
||||
|
||||
fn attribute_mutated(&self, attr: &Attr, mutation: AttributeMutation) {
|
||||
|
|
|
@ -16,7 +16,6 @@ use dom::bindings::refcounted::Trusted;
|
|||
use dom::document::Document;
|
||||
use dom::element::{AttributeMutation, Element};
|
||||
use dom::event::{Event, EventBubbles, EventCancelable};
|
||||
use dom::eventtarget::EventTarget;
|
||||
use dom::htmlelement::HTMLElement;
|
||||
use dom::node::{Node, NodeDamage, document_from_node, window_from_node};
|
||||
use dom::virtualmethods::VirtualMethods;
|
||||
|
@ -74,9 +73,8 @@ impl Runnable for ImageResponseHandlerRunnable {
|
|||
};
|
||||
|
||||
// Mark the node dirty
|
||||
let node = element.upcast::<Node>();
|
||||
let document = document_from_node(node);
|
||||
document.r().content_changed(node, NodeDamage::OtherNodeDamage);
|
||||
let document = document_from_node(&*element);
|
||||
document.content_changed(element.upcast(), NodeDamage::OtherNodeDamage);
|
||||
|
||||
// Fire image.onload
|
||||
let window = window_from_node(document.r());
|
||||
|
@ -84,9 +82,7 @@ impl Runnable for ImageResponseHandlerRunnable {
|
|||
"load".to_owned(),
|
||||
EventBubbles::DoesNotBubble,
|
||||
EventCancelable::NotCancelable);
|
||||
let event = event.r();
|
||||
let target = node.upcast::<EventTarget>();
|
||||
event.fire(target);
|
||||
event.fire(element.upcast());
|
||||
|
||||
// Trigger reflow
|
||||
window.r().add_pending_reflow();
|
||||
|
@ -97,8 +93,7 @@ impl HTMLImageElement {
|
|||
/// 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.
|
||||
fn update_image(&self, value: Option<(DOMString, Url)>) {
|
||||
let node = self.upcast::<Node>();
|
||||
let document = node.owner_doc();
|
||||
let document = document_from_node(self);
|
||||
let window = document.r().window();
|
||||
let image_cache = window.image_cache_task();
|
||||
match value {
|
||||
|
@ -204,8 +199,7 @@ impl HTMLImageElementMethods for HTMLImageElement {
|
|||
|
||||
// https://html.spec.whatwg.org/multipage/#dom-img-ismap
|
||||
fn SetIsMap(&self, is_map: bool) {
|
||||
let element = self.upcast::<Element>();
|
||||
element.set_string_attribute(&atom!("ismap"), is_map.to_string())
|
||||
self.upcast::<Element>().set_string_attribute(&atom!("ismap"), is_map.to_string())
|
||||
}
|
||||
|
||||
// https://html.spec.whatwg.org/multipage/#dom-img-width
|
||||
|
@ -217,8 +211,7 @@ impl HTMLImageElementMethods for HTMLImageElement {
|
|||
|
||||
// https://html.spec.whatwg.org/multipage/#dom-img-width
|
||||
fn SetWidth(&self, width: u32) {
|
||||
let elem = self.upcast::<Element>();
|
||||
elem.set_uint_attribute(&atom!("width"), width)
|
||||
self.upcast::<Element>().set_uint_attribute(&atom!("width"), width)
|
||||
}
|
||||
|
||||
// https://html.spec.whatwg.org/multipage/#dom-img-height
|
||||
|
@ -230,8 +223,7 @@ impl HTMLImageElementMethods for HTMLImageElement {
|
|||
|
||||
// https://html.spec.whatwg.org/multipage/#dom-img-height
|
||||
fn SetHeight(&self, height: u32) {
|
||||
let elem = self.upcast::<Element>();
|
||||
elem.set_uint_attribute(&atom!("height"), height)
|
||||
self.upcast::<Element>().set_uint_attribute(&atom!("height"), height)
|
||||
}
|
||||
|
||||
// https://html.spec.whatwg.org/multipage/#dom-img-naturalwidth
|
||||
|
@ -299,8 +291,7 @@ impl HTMLImageElementMethods for HTMLImageElement {
|
|||
|
||||
impl VirtualMethods for HTMLImageElement {
|
||||
fn super_type(&self) -> Option<&VirtualMethods> {
|
||||
let htmlelement: &HTMLElement = self.upcast::<HTMLElement>();
|
||||
Some(htmlelement as &VirtualMethods)
|
||||
Some(self.upcast::<HTMLElement>() as &VirtualMethods)
|
||||
}
|
||||
|
||||
fn attribute_mutated(&self, attr: &Attr, mutation: AttributeMutation) {
|
||||
|
|
|
@ -353,7 +353,6 @@ fn broadcast_radio_checked(broadcaster: &HTMLInputElement, group: Option<&Atom>)
|
|||
//TODO: if not in document, use root ancestor instead of document
|
||||
let owner = broadcaster.form_owner();
|
||||
let doc = document_from_node(broadcaster);
|
||||
let doc_node = doc.upcast::<Node>();
|
||||
|
||||
// This function is a workaround for lifetime constraint difficulties.
|
||||
fn do_broadcast(doc_node: &Node, broadcaster: &HTMLInputElement,
|
||||
|
@ -368,7 +367,7 @@ fn broadcast_radio_checked(broadcaster: &HTMLInputElement, group: Option<&Atom>)
|
|||
}
|
||||
}
|
||||
|
||||
do_broadcast(doc_node, broadcaster, owner.r(), group)
|
||||
do_broadcast(doc.upcast(), broadcaster, owner.r(), group)
|
||||
}
|
||||
|
||||
// https://html.spec.whatwg.org/multipage/#radio-button-group
|
||||
|
@ -388,8 +387,7 @@ fn in_same_group(other: &HTMLInputElement, owner: Option<&HTMLFormElement>,
|
|||
impl HTMLInputElement {
|
||||
fn force_relayout(&self) {
|
||||
let doc = document_from_node(self);
|
||||
let node = self.upcast::<Node>();
|
||||
doc.r().content_changed(node, NodeDamage::OtherNodeDamage)
|
||||
doc.content_changed(self.upcast(), NodeDamage::OtherNodeDamage)
|
||||
}
|
||||
|
||||
fn radio_group_updated(&self, group: Option<&Atom>) {
|
||||
|
@ -439,8 +437,8 @@ impl HTMLInputElement {
|
|||
// https://html.spec.whatwg.org/multipage/#radio-button-group
|
||||
fn get_radio_group_name(&self) -> Option<Atom> {
|
||||
//TODO: determine form owner
|
||||
let elem = self.upcast::<Element>();
|
||||
elem.get_attribute(&ns!(""), &atom!("name"))
|
||||
self.upcast::<Element>()
|
||||
.get_attribute(&ns!(""), &atom!("name"))
|
||||
.map(|name| name.value().as_atom().clone())
|
||||
}
|
||||
|
||||
|
@ -468,8 +466,7 @@ impl HTMLInputElement {
|
|||
fn mutable(&self) -> bool {
|
||||
// https://html.spec.whatwg.org/multipage/#the-input-element:concept-fe-mutable
|
||||
// https://html.spec.whatwg.org/multipage/#the-readonly-attribute:concept-fe-mutable
|
||||
let el = self.upcast::<Element>();
|
||||
!(el.get_disabled_state() || self.ReadOnly())
|
||||
!(self.upcast::<Element>().get_disabled_state() || self.ReadOnly())
|
||||
}
|
||||
|
||||
// https://html.spec.whatwg.org/multipage/#the-input-element:concept-form-reset-control
|
||||
|
@ -491,8 +488,7 @@ impl HTMLInputElement {
|
|||
|
||||
impl VirtualMethods for HTMLInputElement {
|
||||
fn super_type(&self) -> Option<&VirtualMethods> {
|
||||
let htmlelement: &HTMLElement = self.upcast::<HTMLElement>();
|
||||
Some(htmlelement as &VirtualMethods)
|
||||
Some(self.upcast::<HTMLElement>() as &VirtualMethods)
|
||||
}
|
||||
|
||||
fn attribute_mutated(&self, attr: &Attr, mutation: AttributeMutation) {
|
||||
|
@ -592,8 +588,7 @@ impl VirtualMethods for HTMLInputElement {
|
|||
s.bind_to_tree(tree_in_doc);
|
||||
}
|
||||
|
||||
let el = self.upcast::<Element>();
|
||||
el.check_ancestors_disabled_state_for_form_control();
|
||||
self.upcast::<Element>().check_ancestors_disabled_state_for_form_control();
|
||||
}
|
||||
|
||||
fn unbind_from_tree(&self, tree_in_doc: bool) {
|
||||
|
@ -626,13 +621,11 @@ impl VirtualMethods for HTMLInputElement {
|
|||
|
||||
//TODO: set the editing position for text inputs
|
||||
|
||||
let doc = document_from_node(self);
|
||||
doc.r().request_focus(self.upcast::<Element>());
|
||||
document_from_node(self).request_focus(self.upcast());
|
||||
} else if &*event.Type() == "keydown" && !event.DefaultPrevented() &&
|
||||
(self.input_type.get() == InputType::InputText ||
|
||||
self.input_type.get() == InputType::InputPassword) {
|
||||
let keyevent: Option<&KeyboardEvent> = event.downcast::<KeyboardEvent>();
|
||||
keyevent.map(|keyevent| {
|
||||
if let Some(keyevent) = event.downcast::<KeyboardEvent>() {
|
||||
// This can't be inlined, as holding on to textinput.borrow_mut()
|
||||
// during self.implicit_submission will cause a panic.
|
||||
let action = self.textinput.borrow_mut().handle_keydown(keyevent);
|
||||
|
@ -653,7 +646,7 @@ impl VirtualMethods for HTMLInputElement {
|
|||
}
|
||||
Nothing => (),
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -662,7 +655,7 @@ impl FormControl for HTMLInputElement {}
|
|||
|
||||
impl Activatable for HTMLInputElement {
|
||||
fn as_element(&self) -> &Element {
|
||||
self.upcast::<Element>()
|
||||
self.upcast()
|
||||
}
|
||||
|
||||
fn is_instance_activatable(&self) -> bool {
|
||||
|
@ -809,19 +802,19 @@ impl Activatable for HTMLInputElement {
|
|||
// https://html.spec.whatwg.org/multipage/#radio-button-state-(type=radio):activation-behavior
|
||||
if self.mutable() {
|
||||
let win = window_from_node(self);
|
||||
let target = self.upcast();
|
||||
|
||||
let event = Event::new(GlobalRef::Window(win.r()),
|
||||
"input".to_owned(),
|
||||
EventBubbles::Bubbles,
|
||||
EventCancelable::NotCancelable);
|
||||
let target = self.upcast::<EventTarget>();
|
||||
event.r().fire(target);
|
||||
event.fire(target);
|
||||
|
||||
let event = Event::new(GlobalRef::Window(win.r()),
|
||||
"change".to_owned(),
|
||||
EventBubbles::Bubbles,
|
||||
EventCancelable::NotCancelable);
|
||||
let target = self.upcast::<EventTarget>();
|
||||
event.r().fire(target);
|
||||
event.fire(target);
|
||||
}
|
||||
},
|
||||
_ => ()
|
||||
|
@ -839,8 +832,7 @@ impl Activatable for HTMLInputElement {
|
|||
Some(ref f) => f
|
||||
};
|
||||
|
||||
let elem = self.upcast::<Element>();
|
||||
if elem.click_in_progress() {
|
||||
if self.upcast::<Element>().click_in_progress() {
|
||||
return;
|
||||
}
|
||||
let submit_button;
|
||||
|
|
|
@ -89,8 +89,7 @@ fn is_favicon(value: &Option<String>) -> bool {
|
|||
|
||||
impl VirtualMethods for HTMLLinkElement {
|
||||
fn super_type(&self) -> Option<&VirtualMethods> {
|
||||
let htmlelement: &HTMLElement = self.upcast::<HTMLElement>();
|
||||
Some(htmlelement as &VirtualMethods)
|
||||
Some(self.upcast::<HTMLElement>() as &VirtualMethods)
|
||||
}
|
||||
|
||||
fn attribute_mutated(&self, attr: &Attr, mutation: AttributeMutation) {
|
||||
|
@ -98,7 +97,7 @@ impl VirtualMethods for HTMLLinkElement {
|
|||
if !self.upcast::<Node>().is_in_doc() || mutation == AttributeMutation::Removed {
|
||||
return;
|
||||
}
|
||||
let rel = get_attr(self.upcast::<Element>(), &atom!(rel));
|
||||
let rel = get_attr(self.upcast(), &atom!(rel));
|
||||
match attr.local_name() {
|
||||
&atom!(href) => {
|
||||
if is_stylesheet(&rel) {
|
||||
|
@ -129,7 +128,7 @@ impl VirtualMethods for HTMLLinkElement {
|
|||
}
|
||||
|
||||
if tree_in_doc {
|
||||
let element = self.upcast::<Element>();
|
||||
let element = self.upcast();
|
||||
|
||||
let rel = get_attr(element, &atom!("rel"));
|
||||
let href = get_attr(element, &atom!("href"));
|
||||
|
@ -224,9 +223,7 @@ impl HTMLLinkElementMethods for HTMLLinkElement {
|
|||
|
||||
// https://html.spec.whatwg.org/multipage/#dom-link-rellist
|
||||
fn RelList(&self) -> Root<DOMTokenList> {
|
||||
self.rel_list.or_init(|| {
|
||||
DOMTokenList::new(self.upcast::<Element>(), &atom!("rel"))
|
||||
})
|
||||
self.rel_list.or_init(|| DOMTokenList::new(self.upcast(), &atom!("rel")))
|
||||
}
|
||||
|
||||
// https://html.spec.whatwg.org/multipage/#dom-link-charset
|
||||
|
@ -267,7 +264,6 @@ impl StylesheetLoadResponder for StylesheetLoadDispatcher {
|
|||
let event = Event::new(GlobalRef::Window(window.r()), "load".to_owned(),
|
||||
EventBubbles::DoesNotBubble,
|
||||
EventCancelable::NotCancelable);
|
||||
let target = elem.upcast::<EventTarget>();
|
||||
event.r().fire(target);
|
||||
event.fire(elem.upcast::<EventTarget>());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -57,8 +57,7 @@ impl HTMLMetaElement {
|
|||
let content = content.value();
|
||||
if !content.is_empty() {
|
||||
if let Some(translated_rule) = ViewportRule::from_meta(&**content) {
|
||||
let node = self.upcast::<Node>();
|
||||
let win = window_from_node(node);
|
||||
let win = window_from_node(self);
|
||||
let LayoutChan(ref layout_chan) = win.r().layout_chan();
|
||||
|
||||
layout_chan.send(Msg::AddMetaViewport(translated_rule)).unwrap();
|
||||
|
@ -84,8 +83,7 @@ impl HTMLMetaElementMethods for HTMLMetaElement {
|
|||
|
||||
impl VirtualMethods for HTMLMetaElement {
|
||||
fn super_type(&self) -> Option<&VirtualMethods> {
|
||||
let htmlelement: &HTMLElement = self.upcast::<HTMLElement>();
|
||||
Some(htmlelement as &VirtualMethods)
|
||||
Some(self.upcast::<HTMLElement>() as &VirtualMethods)
|
||||
}
|
||||
|
||||
fn bind_to_tree(&self, tree_in_doc: bool) {
|
||||
|
|
|
@ -92,8 +92,7 @@ impl HTMLObjectElementMethods for HTMLObjectElement {
|
|||
|
||||
impl VirtualMethods for HTMLObjectElement {
|
||||
fn super_type(&self) -> Option<&VirtualMethods> {
|
||||
let htmlelement: &HTMLElement = self.upcast::<HTMLElement>();
|
||||
Some(htmlelement as &VirtualMethods)
|
||||
Some(self.upcast::<HTMLElement>() as &VirtualMethods)
|
||||
}
|
||||
|
||||
fn attribute_mutated(&self, attr: &Attr, mutation: AttributeMutation) {
|
||||
|
|
|
@ -50,8 +50,7 @@ impl HTMLOptGroupElementMethods for HTMLOptGroupElement {
|
|||
|
||||
impl VirtualMethods for HTMLOptGroupElement {
|
||||
fn super_type(&self) -> Option<&VirtualMethods> {
|
||||
let htmlelement: &HTMLElement = self.upcast::<HTMLElement>();
|
||||
Some(htmlelement as &VirtualMethods)
|
||||
Some(self.upcast::<HTMLElement>() as &VirtualMethods)
|
||||
}
|
||||
|
||||
fn attribute_mutated(&self, attr: &Attr, mutation: AttributeMutation) {
|
||||
|
|
|
@ -64,7 +64,7 @@ fn collect_text(element: &Element, value: &mut DOMString) {
|
|||
if child.is::<Text>() {
|
||||
let characterdata = child.downcast::<CharacterData>().unwrap();
|
||||
value.push_str(&characterdata.Data());
|
||||
} else if let Some(element_child) = child.downcast::<Element>() {
|
||||
} else if let Some(element_child) = child.downcast() {
|
||||
collect_text(element_child, value);
|
||||
}
|
||||
}
|
||||
|
@ -76,22 +76,19 @@ impl HTMLOptionElementMethods for HTMLOptionElement {
|
|||
|
||||
// https://html.spec.whatwg.org/multipage/#dom-option-disabled
|
||||
fn SetDisabled(&self, disabled: bool) {
|
||||
let elem = self.upcast::<Element>();
|
||||
elem.set_bool_attribute(&atom!("disabled"), disabled)
|
||||
self.upcast::<Element>().set_bool_attribute(&atom!("disabled"), disabled)
|
||||
}
|
||||
|
||||
// https://html.spec.whatwg.org/multipage/#dom-option-text
|
||||
fn Text(&self) -> DOMString {
|
||||
let element = self.upcast::<Element>();
|
||||
let mut content = String::new();
|
||||
collect_text(element, &mut content);
|
||||
collect_text(self.upcast(), &mut content);
|
||||
str_join(split_html_space_chars(&content), " ")
|
||||
}
|
||||
|
||||
// https://html.spec.whatwg.org/multipage/#dom-option-text
|
||||
fn SetText(&self, value: DOMString) {
|
||||
let node = self.upcast::<Node>();
|
||||
node.SetTextContent(Some(value))
|
||||
self.upcast::<Node>().SetTextContent(Some(value))
|
||||
}
|
||||
|
||||
// https://html.spec.whatwg.org/multipage/#attr-option-value
|
||||
|
@ -144,8 +141,7 @@ impl HTMLOptionElementMethods for HTMLOptionElement {
|
|||
|
||||
impl VirtualMethods for HTMLOptionElement {
|
||||
fn super_type(&self) -> Option<&VirtualMethods> {
|
||||
let htmlelement: &HTMLElement = self.upcast::<HTMLElement>();
|
||||
Some(htmlelement as &VirtualMethods)
|
||||
Some(self.upcast::<HTMLElement>() as &VirtualMethods)
|
||||
}
|
||||
|
||||
fn attribute_mutated(&self, attr: &Attr, mutation: AttributeMutation) {
|
||||
|
@ -190,8 +186,7 @@ impl VirtualMethods for HTMLOptionElement {
|
|||
s.bind_to_tree(tree_in_doc);
|
||||
}
|
||||
|
||||
let el = self.upcast::<Element>();
|
||||
el.check_parent_disabled_state_for_option();
|
||||
self.upcast::<Element>().check_parent_disabled_state_for_option();
|
||||
}
|
||||
|
||||
fn unbind_from_tree(&self, tree_in_doc: bool) {
|
||||
|
|
|
@ -19,7 +19,6 @@ use dom::bindings::trace::JSTraceable;
|
|||
use dom::document::Document;
|
||||
use dom::element::{AttributeMutation, Element, ElementCreator};
|
||||
use dom::event::{Event, EventBubbles, EventCancelable};
|
||||
use dom::eventtarget::EventTarget;
|
||||
use dom::htmlelement::HTMLElement;
|
||||
use dom::node::{ChildrenMutation, CloneChildrenFlag, Node};
|
||||
use dom::node::{document_from_node, window_from_node};
|
||||
|
@ -190,8 +189,7 @@ impl HTMLScriptElement {
|
|||
return NextParserState::Continue;
|
||||
}
|
||||
// Step 5.
|
||||
let node = self.upcast::<Node>();
|
||||
if !node.is_in_doc() {
|
||||
if !self.upcast::<Node>().is_in_doc() {
|
||||
return NextParserState::Continue;
|
||||
}
|
||||
// Step 6, 7.
|
||||
|
@ -507,16 +505,13 @@ impl HTMLScriptElement {
|
|||
type_,
|
||||
bubbles,
|
||||
cancelable);
|
||||
let event = event.r();
|
||||
let target = self.upcast::<EventTarget>();
|
||||
event.fire(target)
|
||||
event.fire(self.upcast())
|
||||
}
|
||||
}
|
||||
|
||||
impl VirtualMethods for HTMLScriptElement {
|
||||
fn super_type(&self) -> Option<&VirtualMethods> {
|
||||
let htmlelement: &HTMLElement = self.upcast::<HTMLElement>();
|
||||
Some(htmlelement as &VirtualMethods)
|
||||
Some(self.upcast::<HTMLElement>() as &VirtualMethods)
|
||||
}
|
||||
|
||||
fn attribute_mutated(&self, attr: &Attr, mutation: AttributeMutation) {
|
||||
|
@ -537,8 +532,7 @@ impl VirtualMethods for HTMLScriptElement {
|
|||
if let Some(ref s) = self.super_type() {
|
||||
s.children_changed(mutation);
|
||||
}
|
||||
let node = self.upcast::<Node>();
|
||||
if !self.parser_inserted.get() && node.is_in_doc() {
|
||||
if !self.parser_inserted.get() && self.upcast::<Node>().is_in_doc() {
|
||||
self.prepare();
|
||||
}
|
||||
}
|
||||
|
@ -561,8 +555,7 @@ impl VirtualMethods for HTMLScriptElement {
|
|||
|
||||
// https://html.spec.whatwg.org/multipage/#already-started
|
||||
if self.already_started.get() {
|
||||
let copy_elem = copy.downcast::<HTMLScriptElement>().unwrap();
|
||||
copy_elem.mark_already_started();
|
||||
copy.downcast::<HTMLScriptElement>().unwrap().mark_already_started();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -580,8 +573,7 @@ impl HTMLScriptElementMethods for HTMLScriptElement {
|
|||
|
||||
// https://html.spec.whatwg.org/multipage/#dom-script-text
|
||||
fn SetText(&self, value: DOMString) {
|
||||
let node = self.upcast::<Node>();
|
||||
node.SetTextContent(Some(value))
|
||||
self.upcast::<Node>().SetTextContent(Some(value))
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -101,8 +101,7 @@ impl HTMLSelectElementMethods for HTMLSelectElement {
|
|||
|
||||
impl VirtualMethods for HTMLSelectElement {
|
||||
fn super_type(&self) -> Option<&VirtualMethods> {
|
||||
let htmlelement: &HTMLElement = self.upcast::<HTMLElement>();
|
||||
Some(htmlelement as &VirtualMethods)
|
||||
Some(self.upcast::<HTMLElement>() as &VirtualMethods)
|
||||
}
|
||||
|
||||
fn attribute_mutated(&self, attr: &Attr, mutation: AttributeMutation) {
|
||||
|
@ -128,8 +127,7 @@ impl VirtualMethods for HTMLSelectElement {
|
|||
s.bind_to_tree(tree_in_doc);
|
||||
}
|
||||
|
||||
let el = self.upcast::<Element>();
|
||||
el.check_ancestors_disabled_state_for_form_control();
|
||||
self.upcast::<Element>().check_ancestors_disabled_state_for_form_control();
|
||||
}
|
||||
|
||||
fn unbind_from_tree(&self, tree_in_doc: bool) {
|
||||
|
|
|
@ -65,16 +65,14 @@ impl HTMLStyleElement {
|
|||
|
||||
impl VirtualMethods for HTMLStyleElement {
|
||||
fn super_type(&self) -> Option<&VirtualMethods> {
|
||||
let htmlelement: &HTMLElement = self.upcast::<HTMLElement>();
|
||||
Some(htmlelement as &VirtualMethods)
|
||||
Some(self.upcast::<HTMLElement>() as &VirtualMethods)
|
||||
}
|
||||
|
||||
fn children_changed(&self, mutation: &ChildrenMutation) {
|
||||
if let Some(ref s) = self.super_type() {
|
||||
s.children_changed(mutation);
|
||||
}
|
||||
let node = self.upcast::<Node>();
|
||||
if node.is_in_doc() {
|
||||
if self.upcast::<Node>().is_in_doc() {
|
||||
self.parse_own_css();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -102,8 +102,7 @@ impl HTMLTableCellElementLayoutHelpers for LayoutJS<HTMLTableCellElement> {
|
|||
|
||||
impl VirtualMethods for HTMLTableCellElement {
|
||||
fn super_type(&self) -> Option<&VirtualMethods> {
|
||||
let htmlelement: &HTMLElement = self.upcast::<HTMLElement>();
|
||||
Some(htmlelement as &VirtualMethods)
|
||||
Some(self.upcast::<HTMLElement>() as &VirtualMethods)
|
||||
}
|
||||
|
||||
fn attribute_mutated(&self, attr: &Attr, mutation: AttributeMutation) {
|
||||
|
|
|
@ -52,25 +52,19 @@ impl HTMLTableElement {
|
|||
impl HTMLTableElementMethods for HTMLTableElement {
|
||||
// https://html.spec.whatwg.org/multipage/#dom-table-caption
|
||||
fn GetCaption(&self) -> Option<Root<HTMLTableCaptionElement>> {
|
||||
let node = self.upcast::<Node>();
|
||||
node.children()
|
||||
.filter_map(|c| {
|
||||
c.downcast::<HTMLTableCaptionElement>().map(Root::from_ref)
|
||||
})
|
||||
.next()
|
||||
self.upcast::<Node>().children().filter_map(Root::downcast).next()
|
||||
}
|
||||
|
||||
// https://html.spec.whatwg.org/multipage/#dom-table-caption
|
||||
fn SetCaption(&self, new_caption: Option<&HTMLTableCaptionElement>) {
|
||||
let node = self.upcast::<Node>();
|
||||
|
||||
if let Some(ref caption) = self.GetCaption() {
|
||||
caption.upcast::<Node>().remove_self();
|
||||
}
|
||||
|
||||
if let Some(caption) = new_caption {
|
||||
assert!(node.InsertBefore(caption.upcast::<Node>(),
|
||||
node.GetFirstChild().as_ref().map(|n| n.r())).is_ok());
|
||||
let node = self.upcast::<Node>();
|
||||
node.InsertBefore(caption.upcast(), node.GetFirstChild().r())
|
||||
.expect("Insertion failed");
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -86,7 +80,7 @@ impl HTMLTableElementMethods for HTMLTableElement {
|
|||
caption
|
||||
}
|
||||
};
|
||||
Root::upcast::<HTMLElement>(caption)
|
||||
Root::upcast(caption)
|
||||
}
|
||||
|
||||
// https://html.spec.whatwg.org/multipage/#dom-table-deletecaption
|
||||
|
@ -107,10 +101,10 @@ impl HTMLTableElementMethods for HTMLTableElement {
|
|||
.filter_map(Root::downcast::<Element>)
|
||||
.find(|n| n.is::<HTMLTableSectionElement>() && n.local_name() == &atom!("tbody"));
|
||||
let reference_element =
|
||||
last_tbody.and_then(|t| Root::upcast::<Node>(t).GetNextSibling());
|
||||
last_tbody.and_then(|t| t.upcast::<Node>().GetNextSibling());
|
||||
|
||||
assert!(node.InsertBefore(tbody.upcast::<Node>(),
|
||||
reference_element.r()).is_ok());
|
||||
node.InsertBefore(tbody.upcast(), reference_element.r())
|
||||
.expect("Insertion failed");
|
||||
tbody
|
||||
}
|
||||
|
||||
|
@ -142,8 +136,7 @@ impl HTMLTableElement {
|
|||
|
||||
impl VirtualMethods for HTMLTableElement {
|
||||
fn super_type(&self) -> Option<&VirtualMethods> {
|
||||
let htmlelement: &HTMLElement = self.upcast::<HTMLElement>();
|
||||
Some(htmlelement as &VirtualMethods)
|
||||
Some(self.upcast::<HTMLElement>() as &VirtualMethods)
|
||||
}
|
||||
|
||||
fn attribute_mutated(&self, attr: &Attr, mutation: AttributeMutation) {
|
||||
|
|
|
@ -72,7 +72,7 @@ impl HTMLTableRowElementMethods for HTMLTableRowElement {
|
|||
self.cells.or_init(|| {
|
||||
let window = window_from_node(self);
|
||||
let filter = box CellsFilter;
|
||||
HTMLCollection::create(window.r(), self.upcast::<Node>(), filter)
|
||||
HTMLCollection::create(window.r(), self.upcast(), filter)
|
||||
})
|
||||
}
|
||||
|
||||
|
@ -97,8 +97,7 @@ impl HTMLTableRowElementMethods for HTMLTableRowElement {
|
|||
|
||||
impl VirtualMethods for HTMLTableRowElement {
|
||||
fn super_type(&self) -> Option<&VirtualMethods> {
|
||||
let htmlelement: &HTMLElement = self.upcast::<HTMLElement>();
|
||||
Some(htmlelement as &VirtualMethods)
|
||||
Some(self.upcast::<HTMLElement>() as &VirtualMethods)
|
||||
}
|
||||
|
||||
fn attribute_mutated(&self, attr: &Attr, mutation: AttributeMutation) {
|
||||
|
|
|
@ -58,7 +58,7 @@ impl CollectionFilter for RowsFilter {
|
|||
impl HTMLTableSectionElementMethods for HTMLTableSectionElement {
|
||||
// https://html.spec.whatwg.org/multipage/#dom-tbody-rows
|
||||
fn Rows(&self) -> Root<HTMLCollection> {
|
||||
HTMLCollection::create(&window_from_node(self), self.upcast::<Node>(), box RowsFilter)
|
||||
HTMLCollection::create(&window_from_node(self), self.upcast(), box RowsFilter)
|
||||
}
|
||||
|
||||
// https://html.spec.whatwg.org/multipage/#dom-tbody-insertrow
|
||||
|
@ -82,8 +82,7 @@ impl HTMLTableSectionElementMethods for HTMLTableSectionElement {
|
|||
|
||||
impl VirtualMethods for HTMLTableSectionElement {
|
||||
fn super_type(&self) -> Option<&VirtualMethods> {
|
||||
let htmlelement: &HTMLElement = self.upcast::<HTMLElement>();
|
||||
Some(htmlelement as &VirtualMethods)
|
||||
Some(self.upcast::<HTMLElement>() as &VirtualMethods)
|
||||
}
|
||||
|
||||
fn attribute_mutated(&self, attr: &Attr, mutation: AttributeMutation) {
|
||||
|
|
|
@ -64,7 +64,7 @@ impl VirtualMethods for HTMLTemplateElement {
|
|||
// Step 1.
|
||||
let doc = document_from_node(self).appropriate_template_contents_owner_document();
|
||||
// Step 2.
|
||||
Node::adopt(self.Content().upcast::<Node>(), &doc);
|
||||
Node::adopt(self.Content().upcast(), &doc);
|
||||
}
|
||||
|
||||
/// https://html.spec.whatwg.org/multipage/#the-template-element:concept-node-clone-ext
|
||||
|
@ -79,7 +79,7 @@ impl VirtualMethods for HTMLTemplateElement {
|
|||
// Steps 2-3.
|
||||
let copy_contents = Root::upcast::<Node>(copy.Content());
|
||||
let copy_contents_doc = copy_contents.owner_doc();
|
||||
for child in Root::upcast::<Node>(self.Content()).children() {
|
||||
for child in self.Content().upcast::<Node>().children() {
|
||||
let copy_child = Node::clone(
|
||||
&child, Some(©_contents_doc), CloneChildrenFlag::CloneChildren);
|
||||
copy_contents.AppendChild(©_child).unwrap();
|
||||
|
|
|
@ -169,14 +169,12 @@ impl HTMLTextAreaElementMethods for HTMLTextAreaElement {
|
|||
|
||||
// https://html.spec.whatwg.org/multipage/#dom-textarea-defaultvalue
|
||||
fn DefaultValue(&self) -> DOMString {
|
||||
let node = self.upcast::<Node>();
|
||||
node.GetTextContent().unwrap()
|
||||
self.upcast::<Node>().GetTextContent().unwrap()
|
||||
}
|
||||
|
||||
// https://html.spec.whatwg.org/multipage/#dom-textarea-defaultvalue
|
||||
fn SetDefaultValue(&self, value: DOMString) {
|
||||
let node = self.upcast::<Node>();
|
||||
node.SetTextContent(Some(value));
|
||||
self.upcast::<Node>().SetTextContent(Some(value));
|
||||
|
||||
// if the element's dirty value flag is false, then the element's
|
||||
// raw value must be set to the value of the element's textContent IDL attribute
|
||||
|
@ -218,8 +216,7 @@ impl HTMLTextAreaElement {
|
|||
impl HTMLTextAreaElement {
|
||||
fn force_relayout(&self) {
|
||||
let doc = document_from_node(self);
|
||||
let node = self.upcast::<Node>();
|
||||
doc.r().content_changed(node, NodeDamage::OtherNodeDamage)
|
||||
doc.content_changed(self.upcast(), NodeDamage::OtherNodeDamage)
|
||||
}
|
||||
|
||||
fn dispatch_change_event(&self) {
|
||||
|
@ -230,15 +227,13 @@ impl HTMLTextAreaElement {
|
|||
EventBubbles::DoesNotBubble,
|
||||
EventCancelable::NotCancelable);
|
||||
|
||||
let target = self.upcast::<EventTarget>();
|
||||
target.dispatch_event(event.r());
|
||||
self.upcast::<EventTarget>().dispatch_event(&event);
|
||||
}
|
||||
}
|
||||
|
||||
impl VirtualMethods for HTMLTextAreaElement {
|
||||
fn super_type(&self) -> Option<&VirtualMethods> {
|
||||
let htmlelement: &HTMLElement = self.upcast::<HTMLElement>();
|
||||
Some(htmlelement as &VirtualMethods)
|
||||
Some(self.upcast::<HTMLElement>() as &VirtualMethods)
|
||||
}
|
||||
|
||||
fn attribute_mutated(&self, attr: &Attr, mutation: AttributeMutation) {
|
||||
|
@ -279,8 +274,7 @@ impl VirtualMethods for HTMLTextAreaElement {
|
|||
s.bind_to_tree(tree_in_doc);
|
||||
}
|
||||
|
||||
let el = self.upcast::<Element>();
|
||||
el.check_ancestors_disabled_state_for_form_control();
|
||||
self.upcast::<Element>().check_ancestors_disabled_state_for_form_control();
|
||||
}
|
||||
|
||||
fn parse_plain_attribute(&self, name: &Atom, value: DOMString) -> AttrValue {
|
||||
|
@ -298,7 +292,7 @@ impl VirtualMethods for HTMLTextAreaElement {
|
|||
|
||||
let node = self.upcast::<Node>();
|
||||
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();
|
||||
} else {
|
||||
el.check_disabled_attribute();
|
||||
|
@ -323,11 +317,9 @@ impl VirtualMethods for HTMLTextAreaElement {
|
|||
if &*event.Type() == "click" && !event.DefaultPrevented() {
|
||||
//TODO: set the editing position for text inputs
|
||||
|
||||
let doc = document_from_node(self);
|
||||
doc.r().request_focus(self.upcast::<Element>());
|
||||
document_from_node(self).request_focus(self.upcast());
|
||||
} else if &*event.Type() == "keydown" && !event.DefaultPrevented() {
|
||||
let keyevent: Option<&KeyboardEvent> = event.downcast::<KeyboardEvent>();
|
||||
keyevent.map(|kevent| {
|
||||
if let Some(kevent) = event.downcast::<KeyboardEvent>() {
|
||||
match self.textinput.borrow_mut().handle_keydown(kevent) {
|
||||
KeyReaction::TriggerDefaultAction => (),
|
||||
KeyReaction::DispatchInput => {
|
||||
|
@ -351,7 +343,7 @@ impl VirtualMethods for HTMLTextAreaElement {
|
|||
}
|
||||
KeyReaction::Nothing => (),
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -39,13 +39,10 @@ impl HTMLTitleElement {
|
|||
impl HTMLTitleElementMethods for HTMLTitleElement {
|
||||
// https://html.spec.whatwg.org/multipage/#dom-title-text
|
||||
fn Text(&self) -> DOMString {
|
||||
let node = self.upcast::<Node>();
|
||||
let mut content = String::new();
|
||||
for child in node.children() {
|
||||
let text: Option<&Text> = child.downcast::<Text>();
|
||||
match text {
|
||||
Some(text) => content.push_str(&text.upcast::<CharacterData>().data()),
|
||||
None => (),
|
||||
for child in self.upcast::<Node>().children() {
|
||||
if let Some(text) = child.downcast::<Text>() {
|
||||
content.push_str(&text.upcast::<CharacterData>().data());
|
||||
}
|
||||
}
|
||||
content
|
||||
|
@ -53,15 +50,13 @@ impl HTMLTitleElementMethods for HTMLTitleElement {
|
|||
|
||||
// https://html.spec.whatwg.org/multipage/#dom-title-text
|
||||
fn SetText(&self, value: DOMString) {
|
||||
let node = self.upcast::<Node>();
|
||||
node.SetTextContent(Some(value))
|
||||
self.upcast::<Node>().SetTextContent(Some(value))
|
||||
}
|
||||
}
|
||||
|
||||
impl VirtualMethods for HTMLTitleElement {
|
||||
fn super_type(&self) -> Option<&VirtualMethods> {
|
||||
let htmlelement: &HTMLElement = self.upcast::<HTMLElement>();
|
||||
Some(htmlelement as &VirtualMethods)
|
||||
Some(self.upcast::<HTMLElement>() as &VirtualMethods)
|
||||
}
|
||||
|
||||
fn children_changed(&self, mutation: &ChildrenMutation) {
|
||||
|
|
|
@ -762,13 +762,12 @@ impl KeyboardEventMethods for KeyboardEvent {
|
|||
_modifiersListArg: DOMString,
|
||||
repeat: bool,
|
||||
_locale: DOMString) {
|
||||
let event = self.upcast::<Event>();
|
||||
if event.dispatching() {
|
||||
if self.upcast::<Event>().dispatching() {
|
||||
return;
|
||||
}
|
||||
|
||||
let uievent = self.upcast::<UIEvent>();
|
||||
uievent.InitUIEvent(typeArg, canBubbleArg, cancelableArg, viewArg, 0);
|
||||
self.upcast::<UIEvent>()
|
||||
.InitUIEvent(typeArg, canBubbleArg, cancelableArg, viewArg, 0);
|
||||
*self.key_string.borrow_mut() = keyArg;
|
||||
self.location.set(locationArg);
|
||||
self.repeat.set(repeat);
|
||||
|
|
|
@ -78,8 +78,7 @@ impl MessageEvent {
|
|||
let messageevent = MessageEvent::new(
|
||||
scope, "message".to_owned(), false, false, message,
|
||||
"".to_owned(), "".to_owned());
|
||||
let event = messageevent.upcast::<Event>();
|
||||
event.fire(target);
|
||||
messageevent.upcast::<Event>().fire(target);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -151,8 +151,8 @@
|
|||
//! # use script::dom::node::Node;
|
||||
//! # use script::dom::htmlelement::HTMLElement;
|
||||
//! fn f(element: &Element) {
|
||||
//! let base: &Node = element.upcast::<Node>();
|
||||
//! let derived: Option<&HTMLElement> = element.downcast::<HTMLElement>();
|
||||
//! let base = element.upcast::<Node>();
|
||||
//! let derived = element.downcast::<HTMLElement>();
|
||||
//! }
|
||||
//! ```
|
||||
//!
|
||||
|
|
|
@ -189,13 +189,12 @@ impl MouseEventMethods for MouseEvent {
|
|||
metaKeyArg: bool,
|
||||
buttonArg: i16,
|
||||
relatedTargetArg: Option<&EventTarget>) {
|
||||
let event: &Event = self.upcast::<Event>();
|
||||
if event.dispatching() {
|
||||
if self.upcast::<Event>().dispatching() {
|
||||
return;
|
||||
}
|
||||
|
||||
let uievent: &UIEvent = self.upcast::<UIEvent>();
|
||||
uievent.InitUIEvent(typeArg, canBubbleArg, cancelableArg, viewArg, detailArg);
|
||||
self.upcast::<UIEvent>()
|
||||
.InitUIEvent(typeArg, canBubbleArg, cancelableArg, viewArg, detailArg);
|
||||
self.screen_x.set(screenXArg);
|
||||
self.screen_y.set(screenYArg);
|
||||
self.client_x.set(clientXArg);
|
||||
|
|
|
@ -355,9 +355,9 @@ impl<'a> Iterator for QuerySelectorIterator {
|
|||
// TODO(cgaebel): Is it worth it to build a bloom filter here
|
||||
// (instead of passing `None`)? Probably.
|
||||
self.iterator.by_ref().filter_map(|node| {
|
||||
if let Some(element) = Root::downcast::<Element>(node) {
|
||||
if let Some(element) = Root::downcast(node) {
|
||||
if matches(selectors, &element, None) {
|
||||
return Some(Root::upcast::<Node>(element))
|
||||
return Some(Root::upcast(element));
|
||||
}
|
||||
}
|
||||
None
|
||||
|
@ -718,7 +718,7 @@ impl Node {
|
|||
Err(()) => Err(Error::Syntax),
|
||||
// Step 3.
|
||||
Ok(ref selectors) => {
|
||||
Ok(self.traverse_preorder().filter_map(Root::downcast::<Element>).find(|element| {
|
||||
Ok(self.traverse_preorder().filter_map(Root::downcast).find(|element| {
|
||||
matches(selectors, element, None)
|
||||
}))
|
||||
}
|
||||
|
@ -787,12 +787,7 @@ impl Node {
|
|||
}
|
||||
|
||||
pub fn child_elements(&self) -> ChildElementIterator {
|
||||
fn to_temporary(node: Root<Node>) -> Option<Root<Element>> {
|
||||
Root::downcast::<Element>(node)
|
||||
}
|
||||
self.children()
|
||||
.filter_map(to_temporary as fn(_) -> _)
|
||||
.peekable()
|
||||
self.children().filter_map(Root::downcast as fn(_) -> _).peekable()
|
||||
}
|
||||
|
||||
pub fn remove_self(&self) {
|
||||
|
@ -823,18 +818,10 @@ impl Node {
|
|||
name: "".to_owned(),
|
||||
publicId: "".to_owned(),
|
||||
systemId: "".to_owned(),
|
||||
|
||||
attrs: {
|
||||
let e: Option<&Element> = self.downcast::<Element>();
|
||||
match e {
|
||||
Some(element) => element.summarize(),
|
||||
None => vec!(),
|
||||
}
|
||||
},
|
||||
attrs: self.downcast().map(Element::summarize).unwrap_or(vec![]),
|
||||
|
||||
isDocumentElement:
|
||||
self.owner_doc()
|
||||
.r()
|
||||
.GetDocumentElement()
|
||||
.map(|elem| elem.upcast::<Node>() == self)
|
||||
.unwrap_or(false),
|
||||
|
@ -846,12 +833,10 @@ impl Node {
|
|||
|
||||
// https://dvcs.w3.org/hg/innerhtml/raw-file/tip/index.html#dfn-concept-parse-fragment
|
||||
pub fn parse_fragment(&self, markup: DOMString) -> Fallible<Root<DocumentFragment>> {
|
||||
let context_node: &Node = self.upcast::<Node>();
|
||||
let context_document = document_from_node(self);
|
||||
let fragment = DocumentFragment::new(context_document.r());
|
||||
if context_document.r().is_html_document() {
|
||||
let fragment_node = fragment.upcast::<Node>();
|
||||
parse_html_fragment(context_node, markup, fragment_node);
|
||||
parse_html_fragment(self.upcast(), markup, fragment.upcast());
|
||||
} else {
|
||||
// FIXME: XML case
|
||||
unimplemented!();
|
||||
|
@ -1619,7 +1604,7 @@ impl Node {
|
|||
// XXXabinader: clone() for each node as trait?
|
||||
let copy: Root<Node> = match node.type_id() {
|
||||
NodeTypeId::DocumentType => {
|
||||
let doctype: &DocumentType = node.downcast::<DocumentType>().unwrap();
|
||||
let doctype = node.downcast::<DocumentType>().unwrap();
|
||||
let doctype = DocumentType::new(doctype.name().clone(),
|
||||
Some(doctype.public_id().clone()),
|
||||
Some(doctype.system_id().clone()), document.r());
|
||||
|
@ -1720,8 +1705,7 @@ impl Node {
|
|||
pub fn collect_text_contents<T: Iterator<Item=Root<Node>>>(iterator: T) -> String {
|
||||
let mut content = String::new();
|
||||
for node in iterator {
|
||||
let text = node.downcast::<Text>();
|
||||
match text {
|
||||
match node.downcast::<Text>() {
|
||||
Some(text) => content.push_str(&text.upcast::<CharacterData>().Data()),
|
||||
None => (),
|
||||
}
|
||||
|
@ -1778,7 +1762,7 @@ impl Node {
|
|||
// Step 3.
|
||||
None => ns!(""),
|
||||
// Step 4.
|
||||
Some(parent) => Node::locate_namespace(parent.upcast::<Node>(), prefix)
|
||||
Some(parent) => Node::locate_namespace(parent.upcast(), prefix)
|
||||
}
|
||||
},
|
||||
NodeTypeId::Document => {
|
||||
|
@ -1787,7 +1771,7 @@ impl Node {
|
|||
None => ns!(""),
|
||||
// Step 2.
|
||||
Some(document_element) => {
|
||||
Node::locate_namespace(document_element.upcast::<Node>(), prefix)
|
||||
Node::locate_namespace(document_element.upcast(), prefix)
|
||||
}
|
||||
}
|
||||
},
|
||||
|
@ -1797,7 +1781,7 @@ impl Node {
|
|||
// Step 1.
|
||||
None => ns!(""),
|
||||
// Step 2.
|
||||
Some(parent) => Node::locate_namespace(parent.upcast::<Node>(), prefix)
|
||||
Some(parent) => Node::locate_namespace(parent.upcast(), prefix)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1828,19 +1812,15 @@ impl NodeMethods for Node {
|
|||
fn NodeName(&self) -> DOMString {
|
||||
match self.type_id() {
|
||||
NodeTypeId::Element(..) => {
|
||||
let elem: &Element = self.downcast::<Element>().unwrap();
|
||||
elem.TagName()
|
||||
self.downcast::<Element>().unwrap().TagName()
|
||||
}
|
||||
NodeTypeId::CharacterData(CharacterDataTypeId::Text) => "#text".to_owned(),
|
||||
NodeTypeId::CharacterData(CharacterDataTypeId::ProcessingInstruction) => {
|
||||
let processing_instruction: &ProcessingInstruction =
|
||||
self.downcast::<ProcessingInstruction>().unwrap();
|
||||
processing_instruction.Target()
|
||||
self.downcast::<ProcessingInstruction>().unwrap().Target()
|
||||
}
|
||||
NodeTypeId::CharacterData(CharacterDataTypeId::Comment) => "#comment".to_owned(),
|
||||
NodeTypeId::DocumentType => {
|
||||
let doctype: &DocumentType = self.downcast::<DocumentType>().unwrap();
|
||||
doctype.name().clone()
|
||||
self.downcast::<DocumentType>().unwrap().name().clone()
|
||||
},
|
||||
NodeTypeId::DocumentFragment => "#document-fragment".to_owned(),
|
||||
NodeTypeId::Document => "#document".to_owned()
|
||||
|
@ -1870,7 +1850,7 @@ impl NodeMethods for Node {
|
|||
|
||||
// https://dom.spec.whatwg.org/#dom-node-parentelement
|
||||
fn GetParentElement(&self) -> Option<Root<Element>> {
|
||||
self.GetParentNode().and_then(Root::downcast::<Element>)
|
||||
self.GetParentNode().and_then(Root::downcast)
|
||||
}
|
||||
|
||||
// https://dom.spec.whatwg.org/#dom-node-haschildnodes
|
||||
|
@ -1911,7 +1891,7 @@ impl NodeMethods for Node {
|
|||
fn GetNodeValue(&self) -> Option<DOMString> {
|
||||
match self.type_id() {
|
||||
NodeTypeId::CharacterData(..) => {
|
||||
let chardata: &CharacterData = self.downcast::<CharacterData>().unwrap();
|
||||
let chardata = self.downcast::<CharacterData>().unwrap();
|
||||
Some(chardata.Data())
|
||||
}
|
||||
_ => {
|
||||
|
@ -1939,7 +1919,7 @@ impl NodeMethods for Node {
|
|||
Some(content)
|
||||
}
|
||||
NodeTypeId::CharacterData(..) => {
|
||||
let characterdata: &CharacterData = self.downcast::<CharacterData>().unwrap();
|
||||
let characterdata = self.downcast::<CharacterData>().unwrap();
|
||||
Some(characterdata.Data())
|
||||
}
|
||||
NodeTypeId::DocumentType |
|
||||
|
@ -1959,15 +1939,14 @@ impl NodeMethods for Node {
|
|||
let node = if value.is_empty() {
|
||||
None
|
||||
} else {
|
||||
let document = self.owner_doc();
|
||||
Some(Root::upcast::<Node>(document.r().CreateTextNode(value)))
|
||||
Some(Root::upcast(self.owner_doc().CreateTextNode(value)))
|
||||
};
|
||||
|
||||
// Step 3.
|
||||
Node::replace_all(node.r(), self);
|
||||
}
|
||||
NodeTypeId::CharacterData(..) => {
|
||||
let characterdata: &CharacterData = self.downcast::<CharacterData>().unwrap();
|
||||
let characterdata = self.downcast::<CharacterData>().unwrap();
|
||||
characterdata.SetData(value);
|
||||
|
||||
// Notify the document that the content of this node is different
|
||||
|
@ -2034,8 +2013,7 @@ impl NodeMethods for Node {
|
|||
0 => (),
|
||||
// Step 6.1.2
|
||||
1 => {
|
||||
if self.child_elements()
|
||||
.any(|c| c.upcast::<Node>() != child) {
|
||||
if self.child_elements().any(|c| c.upcast::<Node>() != child) {
|
||||
return Err(Error::HierarchyRequest);
|
||||
}
|
||||
if child.following_siblings()
|
||||
|
@ -2137,14 +2115,13 @@ impl NodeMethods for Node {
|
|||
for child in self.children() {
|
||||
match child.downcast::<Text>() {
|
||||
Some(text) => {
|
||||
let characterdata: &CharacterData = text.upcast::<CharacterData>();
|
||||
let characterdata = text.upcast::<CharacterData>();
|
||||
if characterdata.Length() == 0 {
|
||||
Node::remove(&*child, self, SuppressObserver::Unsuppressed);
|
||||
} else {
|
||||
match prev_text {
|
||||
Some(ref text_node) => {
|
||||
let prev_characterdata =
|
||||
text_node.upcast::<CharacterData>();
|
||||
let prev_characterdata = text_node.upcast::<CharacterData>();
|
||||
prev_characterdata.append_data(&**characterdata.data());
|
||||
Node::remove(&*child, self, SuppressObserver::Unsuppressed);
|
||||
},
|
||||
|
@ -2172,34 +2149,34 @@ impl NodeMethods for Node {
|
|||
// https://dom.spec.whatwg.org/#dom-node-isequalnode
|
||||
fn IsEqualNode(&self, maybe_node: Option<&Node>) -> bool {
|
||||
fn is_equal_doctype(node: &Node, other: &Node) -> bool {
|
||||
let doctype: &DocumentType = node.downcast::<DocumentType>().unwrap();
|
||||
let other_doctype: &DocumentType = other.downcast::<DocumentType>().unwrap();
|
||||
let doctype = node.downcast::<DocumentType>().unwrap();
|
||||
let other_doctype = other.downcast::<DocumentType>().unwrap();
|
||||
(*doctype.name() == *other_doctype.name()) &&
|
||||
(*doctype.public_id() == *other_doctype.public_id()) &&
|
||||
(*doctype.system_id() == *other_doctype.system_id())
|
||||
}
|
||||
fn is_equal_element(node: &Node, other: &Node) -> bool {
|
||||
let element: &Element = node.downcast::<Element>().unwrap();
|
||||
let other_element: &Element = other.downcast::<Element>().unwrap();
|
||||
let element = node.downcast::<Element>().unwrap();
|
||||
let other_element = other.downcast::<Element>().unwrap();
|
||||
(*element.namespace() == *other_element.namespace()) &&
|
||||
(*element.prefix() == *other_element.prefix()) &&
|
||||
(*element.local_name() == *other_element.local_name()) &&
|
||||
(element.attrs().len() == other_element.attrs().len())
|
||||
}
|
||||
fn is_equal_processinginstruction(node: &Node, other: &Node) -> bool {
|
||||
let pi: &ProcessingInstruction = node.downcast::<ProcessingInstruction>().unwrap();
|
||||
let other_pi: &ProcessingInstruction = other.downcast::<ProcessingInstruction>().unwrap();
|
||||
let pi = node.downcast::<ProcessingInstruction>().unwrap();
|
||||
let other_pi = other.downcast::<ProcessingInstruction>().unwrap();
|
||||
(*pi.target() == *other_pi.target()) &&
|
||||
(*pi.upcast::<CharacterData>().data() == *other_pi.upcast::<CharacterData>().data())
|
||||
}
|
||||
fn is_equal_characterdata(node: &Node, other: &Node) -> bool {
|
||||
let characterdata: &CharacterData = node.downcast::<CharacterData>().unwrap();
|
||||
let other_characterdata: &CharacterData = other.downcast::<CharacterData>().unwrap();
|
||||
let characterdata = node.downcast::<CharacterData>().unwrap();
|
||||
let other_characterdata = other.downcast::<CharacterData>().unwrap();
|
||||
*characterdata.data() == *other_characterdata.data()
|
||||
}
|
||||
fn is_equal_element_attrs(node: &Node, other: &Node) -> bool {
|
||||
let element: &Element = node.downcast::<Element>().unwrap();
|
||||
let other_element: &Element = other.downcast::<Element>().unwrap();
|
||||
let element = node.downcast::<Element>().unwrap();
|
||||
let other_element = other.downcast::<Element>().unwrap();
|
||||
assert!(element.attrs().len() == other_element.attrs().len());
|
||||
// FIXME(https://github.com/rust-lang/rust/issues/23338)
|
||||
let attrs = element.attrs();
|
||||
|
@ -2327,7 +2304,9 @@ impl NodeMethods for Node {
|
|||
|
||||
// Step 2.
|
||||
match self.type_id() {
|
||||
NodeTypeId::Element(..) => self.downcast::<Element>().unwrap().lookup_prefix(namespace),
|
||||
NodeTypeId::Element(..) => {
|
||||
self.downcast::<Element>().unwrap().lookup_prefix(namespace)
|
||||
},
|
||||
NodeTypeId::Document => {
|
||||
self.downcast::<Document>().unwrap().GetDocumentElement().and_then(|element| {
|
||||
element.r().lookup_prefix(namespace)
|
||||
|
@ -2376,8 +2355,7 @@ pub struct TrustedNodeAddress(pub *const c_void);
|
|||
unsafe impl Send for TrustedNodeAddress {}
|
||||
|
||||
pub fn document_from_node<T: DerivedFrom<Node> + Reflectable>(derived: &T) -> Root<Document> {
|
||||
let node: &Node = derived.upcast::<Node>();
|
||||
node.owner_doc()
|
||||
derived.upcast().owner_doc()
|
||||
}
|
||||
|
||||
pub fn window_from_node<T: DerivedFrom<Node> + Reflectable>(derived: &T) -> Root<Window> {
|
||||
|
@ -2387,8 +2365,7 @@ pub fn window_from_node<T: DerivedFrom<Node> + Reflectable>(derived: &T) -> Root
|
|||
|
||||
impl VirtualMethods for Node {
|
||||
fn super_type(&self) -> Option<&VirtualMethods> {
|
||||
let eventtarget: &EventTarget = self.upcast::<EventTarget>();
|
||||
Some(eventtarget as &VirtualMethods)
|
||||
Some(self.upcast::<EventTarget>() as &VirtualMethods)
|
||||
}
|
||||
|
||||
fn children_changed(&self, mutation: &ChildrenMutation) {
|
||||
|
|
|
@ -43,7 +43,7 @@ impl Range {
|
|||
}
|
||||
|
||||
pub fn new_with_doc(document: &Document) -> Root<Range> {
|
||||
let root = document.upcast::<Node>();
|
||||
let root = document.upcast();
|
||||
Range::new(document, root, 0, root, 0)
|
||||
}
|
||||
|
||||
|
@ -369,7 +369,7 @@ impl RangeMethods for Range {
|
|||
let text = text.SubstringData(start_offset, end_offset - start_offset);
|
||||
clone.downcast::<CharacterData>().unwrap().SetData(text.unwrap());
|
||||
// Step 4.3.
|
||||
try!(fragment.upcast::<Node>().AppendChild(clone.r()));
|
||||
try!(fragment.upcast::<Node>().AppendChild(&clone));
|
||||
// Step 4.4
|
||||
return Ok(fragment);
|
||||
}
|
||||
|
@ -389,12 +389,12 @@ impl RangeMethods for Range {
|
|||
let text = text.SubstringData(start_offset, start_node.len() - start_offset);
|
||||
clone.downcast::<CharacterData>().unwrap().SetData(text.unwrap());
|
||||
// Step 13.3.
|
||||
try!(fragment.upcast::<Node>().AppendChild(clone.r()));
|
||||
try!(fragment.upcast::<Node>().AppendChild(&clone));
|
||||
} else {
|
||||
// Step 14.1.
|
||||
let clone = child.CloneNode(false);
|
||||
// Step 14.2.
|
||||
try!(fragment.upcast::<Node>().AppendChild(clone.r()));
|
||||
try!(fragment.upcast::<Node>().AppendChild(&clone));
|
||||
// Step 14.3.
|
||||
let subrange = Range::new(clone.owner_doc().r(),
|
||||
start_node.r(),
|
||||
|
@ -404,7 +404,7 @@ impl RangeMethods for Range {
|
|||
// Step 14.4.
|
||||
let subfragment = try!(subrange.CloneContents());
|
||||
// Step 14.5.
|
||||
try!(clone.AppendChild(subfragment.upcast::<Node>()));
|
||||
try!(clone.AppendChild(subfragment.upcast()));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -413,7 +413,7 @@ impl RangeMethods for Range {
|
|||
// Step 15.1.
|
||||
let clone = child.CloneNode(true);
|
||||
// Step 15.2.
|
||||
try!(fragment.upcast::<Node>().AppendChild(clone.r()));
|
||||
try!(fragment.upcast::<Node>().AppendChild(&clone));
|
||||
}
|
||||
|
||||
if let Some(child) = last_contained_child {
|
||||
|
@ -426,12 +426,12 @@ impl RangeMethods for Range {
|
|||
let text = text.SubstringData(0, end_offset);
|
||||
clone.downcast::<CharacterData>().unwrap().SetData(text.unwrap());
|
||||
// Step 16.3.
|
||||
try!(fragment.upcast::<Node>().AppendChild(clone.r()));
|
||||
try!(fragment.upcast::<Node>().AppendChild(&clone));
|
||||
} else {
|
||||
// Step 17.1.
|
||||
let clone = child.CloneNode(false);
|
||||
// Step 17.2.
|
||||
try!(fragment.upcast::<Node>().AppendChild(clone.r()));
|
||||
try!(fragment.upcast::<Node>().AppendChild(&clone));
|
||||
// Step 17.3.
|
||||
let subrange = Range::new(clone.owner_doc().r(),
|
||||
child.r(),
|
||||
|
@ -441,7 +441,7 @@ impl RangeMethods for Range {
|
|||
// Step 17.4.
|
||||
let subfragment = try!(subrange.CloneContents());
|
||||
// Step 17.5.
|
||||
try!(clone.AppendChild(subfragment.upcast::<Node>()));
|
||||
try!(clone.AppendChild(subfragment.upcast()));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -477,7 +477,7 @@ impl RangeMethods for Range {
|
|||
let text = end_data.SubstringData(start_offset, end_offset - start_offset);
|
||||
clone.downcast::<CharacterData>().unwrap().SetData(text.unwrap());
|
||||
// Step 4.3.
|
||||
try!(fragment.upcast::<Node>().AppendChild(clone.r()));
|
||||
try!(fragment.upcast::<Node>().AppendChild(&clone));
|
||||
// Step 4.4.
|
||||
try!(end_data.ReplaceData(start_offset,
|
||||
end_offset - start_offset,
|
||||
|
@ -513,7 +513,7 @@ impl RangeMethods for Range {
|
|||
start_node.len() - start_offset);
|
||||
clone.downcast::<CharacterData>().unwrap().SetData(text.unwrap());
|
||||
// Step 15.3.
|
||||
try!(fragment.upcast::<Node>().AppendChild(clone.r()));
|
||||
try!(fragment.upcast::<Node>().AppendChild(&clone));
|
||||
// Step 15.4.
|
||||
try!(start_data.ReplaceData(start_offset,
|
||||
start_node.len() - start_offset,
|
||||
|
@ -522,7 +522,7 @@ impl RangeMethods for Range {
|
|||
// Step 16.1.
|
||||
let clone = child.CloneNode(false);
|
||||
// Step 16.2.
|
||||
try!(fragment.upcast::<Node>().AppendChild(clone.r()));
|
||||
try!(fragment.upcast::<Node>().AppendChild(&clone));
|
||||
// Step 16.3.
|
||||
let subrange = Range::new(clone.owner_doc().r(),
|
||||
start_node.r(),
|
||||
|
@ -532,13 +532,13 @@ impl RangeMethods for Range {
|
|||
// Step 16.4.
|
||||
let subfragment = try!(subrange.ExtractContents());
|
||||
// Step 16.5.
|
||||
try!(clone.AppendChild(subfragment.upcast::<Node>()));
|
||||
try!(clone.AppendChild(subfragment.upcast()));
|
||||
}
|
||||
}
|
||||
|
||||
// Step 17.
|
||||
for child in contained_children {
|
||||
try!(fragment.upcast::<Node>().AppendChild(child.r()));
|
||||
try!(fragment.upcast::<Node>().AppendChild(&child));
|
||||
}
|
||||
|
||||
if let Some(child) = last_contained_child {
|
||||
|
@ -550,14 +550,14 @@ impl RangeMethods for Range {
|
|||
let text = end_data.SubstringData(0, end_offset);
|
||||
clone.downcast::<CharacterData>().unwrap().SetData(text.unwrap());
|
||||
// Step 18.3.
|
||||
try!(fragment.upcast::<Node>().AppendChild(clone.r()));
|
||||
try!(fragment.upcast::<Node>().AppendChild(&clone));
|
||||
// Step 18.4.
|
||||
try!(end_data.ReplaceData(0, end_offset, "".to_owned()));
|
||||
} else {
|
||||
// Step 19.1.
|
||||
let clone = child.CloneNode(false);
|
||||
// Step 19.2.
|
||||
try!(fragment.upcast::<Node>().AppendChild(clone.r()));
|
||||
try!(fragment.upcast::<Node>().AppendChild(&clone));
|
||||
// Step 19.3.
|
||||
let subrange = Range::new(clone.owner_doc().r(),
|
||||
child.r(),
|
||||
|
@ -567,7 +567,7 @@ impl RangeMethods for Range {
|
|||
// Step 19.4.
|
||||
let subfragment = try!(subrange.ExtractContents());
|
||||
// Step 19.5.
|
||||
try!(clone.AppendChild(subfragment.upcast::<Node>()));
|
||||
try!(clone.AppendChild(subfragment.upcast()));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -697,7 +697,7 @@ impl RangeMethods for Range {
|
|||
try!(self.InsertNode(new_parent));
|
||||
|
||||
// Step 6.
|
||||
let _ = try!(new_parent.AppendChild(fragment.upcast::<Node>()));
|
||||
try!(new_parent.AppendChild(fragment.upcast()));
|
||||
|
||||
// Step 7.
|
||||
self.SelectNode(new_parent)
|
||||
|
|
|
@ -48,7 +48,7 @@ impl Sink {
|
|||
NodeOrText::AppendNode(n) => n.root(),
|
||||
NodeOrText::AppendText(t) => {
|
||||
let text = Text::new(t.into(), &self.document);
|
||||
Root::upcast::<Node>(text)
|
||||
Root::upcast(text)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -11,7 +11,6 @@ use dom::bindings::js::{Root, RootedReference};
|
|||
use dom::bindings::refcounted::Trusted;
|
||||
use dom::bindings::utils::{Reflector, reflect_dom_object};
|
||||
use dom::event::{Event, EventBubbles, EventCancelable};
|
||||
use dom::eventtarget::EventTarget;
|
||||
use dom::storageevent::StorageEvent;
|
||||
use dom::urlhelper::UrlHelper;
|
||||
use ipc_channel::ipc;
|
||||
|
@ -193,7 +192,6 @@ impl MainThreadRunnable for StorageEventRunnable {
|
|||
ev_url.to_string(),
|
||||
Some(storage)
|
||||
);
|
||||
let event = storage_event.upcast::<Event>();
|
||||
|
||||
let root_page = script_task.root_page();
|
||||
for it_page in root_page.iter() {
|
||||
|
@ -203,8 +201,7 @@ impl MainThreadRunnable for StorageEventRunnable {
|
|||
// 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.
|
||||
if ev_window.pipeline() != it_window.pipeline() {
|
||||
let target = it_window.upcast::<EventTarget>();
|
||||
event.fire(target);
|
||||
storage_event.upcast::<Event>().fire(it_window.upcast());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -63,9 +63,7 @@ impl TextMethods for Text {
|
|||
let parent = node.GetParentNode();
|
||||
if let Some(ref parent) = parent {
|
||||
// Step 7.
|
||||
parent.r().InsertBefore(new_node.upcast::<Node>(),
|
||||
node.GetNextSibling().r())
|
||||
.unwrap();
|
||||
parent.InsertBefore(new_node.upcast(), node.GetNextSibling().r()).unwrap();
|
||||
// TODO: Ranges.
|
||||
}
|
||||
// Step 8.
|
||||
|
|
|
@ -86,7 +86,7 @@ impl UIEventMethods for UIEvent {
|
|||
cancelable: bool,
|
||||
view: Option<&Window>,
|
||||
detail: i32) {
|
||||
let event: &Event = self.upcast::<Event>();
|
||||
let event = self.upcast::<Event>();
|
||||
if event.dispatching() {
|
||||
return;
|
||||
}
|
||||
|
|
|
@ -44,8 +44,7 @@ pub fn load_script(head: &HTMLHeadElement) {
|
|||
let new_script = doc.CreateElement("script".to_owned()).unwrap();
|
||||
let new_script = new_script.r();
|
||||
new_script.set_string_attribute(&atom!("src"), name);
|
||||
let new_script_node = new_script.upcast::<Node>();
|
||||
node.InsertBefore(new_script_node, first_child.r()).unwrap();
|
||||
node.InsertBefore(new_script.upcast(), first_child.r()).unwrap();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -123,131 +123,97 @@ pub trait VirtualMethods {
|
|||
pub fn vtable_for(node: &Node) -> &VirtualMethods {
|
||||
match node.type_id() {
|
||||
NodeTypeId::Element(ElementTypeId::HTMLElement(HTMLElementTypeId::HTMLAnchorElement)) => {
|
||||
let element = node.downcast::<HTMLAnchorElement>().unwrap();
|
||||
element as &VirtualMethods
|
||||
node.downcast::<HTMLAnchorElement>().unwrap() as &VirtualMethods
|
||||
}
|
||||
NodeTypeId::Element(ElementTypeId::HTMLElement(HTMLElementTypeId::HTMLAppletElement)) => {
|
||||
node.downcast::<HTMLAppletElement>().unwrap() as &VirtualMethods
|
||||
}
|
||||
NodeTypeId::Element(ElementTypeId::HTMLElement(HTMLElementTypeId::HTMLAreaElement)) => {
|
||||
let element = node.downcast::<HTMLAreaElement>().unwrap();
|
||||
element as &VirtualMethods
|
||||
node.downcast::<HTMLAreaElement>().unwrap() as &VirtualMethods
|
||||
}
|
||||
NodeTypeId::Element(ElementTypeId::HTMLElement(HTMLElementTypeId::HTMLBaseElement)) => {
|
||||
let element = node.downcast::<HTMLBaseElement>().unwrap();
|
||||
element as &VirtualMethods
|
||||
node.downcast::<HTMLBaseElement>().unwrap() as &VirtualMethods
|
||||
}
|
||||
NodeTypeId::Element(ElementTypeId::HTMLElement(HTMLElementTypeId::HTMLBodyElement)) => {
|
||||
let element = node.downcast::<HTMLBodyElement>().unwrap();
|
||||
element as &VirtualMethods
|
||||
node.downcast::<HTMLBodyElement>().unwrap() as &VirtualMethods
|
||||
}
|
||||
NodeTypeId::Element(ElementTypeId::HTMLElement(HTMLElementTypeId::HTMLButtonElement)) => {
|
||||
let element = node.downcast::<HTMLButtonElement>().unwrap();
|
||||
element as &VirtualMethods
|
||||
node.downcast::<HTMLButtonElement>().unwrap() as &VirtualMethods
|
||||
}
|
||||
NodeTypeId::Element(ElementTypeId::HTMLElement(HTMLElementTypeId::HTMLCanvasElement)) => {
|
||||
let element = node.downcast::<HTMLCanvasElement>().unwrap();
|
||||
element as &VirtualMethods
|
||||
node.downcast::<HTMLCanvasElement>().unwrap() as &VirtualMethods
|
||||
}
|
||||
NodeTypeId::Element(ElementTypeId::HTMLElement(HTMLElementTypeId::HTMLFieldSetElement)) => {
|
||||
let element = node.downcast::<HTMLFieldSetElement>().unwrap();
|
||||
element as &VirtualMethods
|
||||
node.downcast::<HTMLFieldSetElement>().unwrap() as &VirtualMethods
|
||||
}
|
||||
NodeTypeId::Element(ElementTypeId::HTMLElement(HTMLElementTypeId::HTMLFontElement)) => {
|
||||
let element = node.downcast::<HTMLFontElement>().unwrap();
|
||||
element as &VirtualMethods
|
||||
node.downcast::<HTMLFontElement>().unwrap() as &VirtualMethods
|
||||
}
|
||||
NodeTypeId::Element(ElementTypeId::HTMLElement(HTMLElementTypeId::HTMLFormElement)) => {
|
||||
let element = node.downcast::<HTMLFormElement>().unwrap();
|
||||
element as &VirtualMethods
|
||||
node.downcast::<HTMLFormElement>().unwrap() as &VirtualMethods
|
||||
}
|
||||
NodeTypeId::Element(ElementTypeId::HTMLElement(HTMLElementTypeId::HTMLHeadElement)) => {
|
||||
let element = node.downcast::<HTMLHeadElement>().unwrap();
|
||||
element as &VirtualMethods
|
||||
node.downcast::<HTMLHeadElement>().unwrap() as &VirtualMethods
|
||||
}
|
||||
NodeTypeId::Element(ElementTypeId::HTMLElement(HTMLElementTypeId::HTMLImageElement)) => {
|
||||
let element = node.downcast::<HTMLImageElement>().unwrap();
|
||||
element as &VirtualMethods
|
||||
node.downcast::<HTMLImageElement>().unwrap() as &VirtualMethods
|
||||
}
|
||||
NodeTypeId::Element(ElementTypeId::HTMLElement(HTMLElementTypeId::HTMLIFrameElement)) => {
|
||||
let element = node.downcast::<HTMLIFrameElement>().unwrap();
|
||||
element as &VirtualMethods
|
||||
node.downcast::<HTMLIFrameElement>().unwrap() as &VirtualMethods
|
||||
}
|
||||
NodeTypeId::Element(ElementTypeId::HTMLElement(HTMLElementTypeId::HTMLInputElement)) => {
|
||||
let element = node.downcast::<HTMLInputElement>().unwrap();
|
||||
element as &VirtualMethods
|
||||
node.downcast::<HTMLInputElement>().unwrap() as &VirtualMethods
|
||||
}
|
||||
NodeTypeId::Element(ElementTypeId::HTMLElement(HTMLElementTypeId::HTMLLinkElement)) => {
|
||||
let element = node.downcast::<HTMLLinkElement>().unwrap();
|
||||
element as &VirtualMethods
|
||||
node.downcast::<HTMLLinkElement>().unwrap() as &VirtualMethods
|
||||
}
|
||||
NodeTypeId::Element(ElementTypeId::HTMLElement(HTMLElementTypeId::HTMLMetaElement)) => {
|
||||
let element = node.downcast::<HTMLMetaElement>().unwrap();
|
||||
element as &VirtualMethods
|
||||
node.downcast::<HTMLMetaElement>().unwrap() as &VirtualMethods
|
||||
}
|
||||
NodeTypeId::Element(ElementTypeId::HTMLElement(HTMLElementTypeId::HTMLObjectElement)) => {
|
||||
let element = node.downcast::<HTMLObjectElement>().unwrap();
|
||||
element as &VirtualMethods
|
||||
node.downcast::<HTMLObjectElement>().unwrap() as &VirtualMethods
|
||||
}
|
||||
NodeTypeId::Element(ElementTypeId::HTMLElement(HTMLElementTypeId::HTMLOptGroupElement)) => {
|
||||
let element = node.downcast::<HTMLOptGroupElement>().unwrap();
|
||||
element as &VirtualMethods
|
||||
node.downcast::<HTMLOptGroupElement>().unwrap() as &VirtualMethods
|
||||
}
|
||||
NodeTypeId::Element(ElementTypeId::HTMLElement(HTMLElementTypeId::HTMLOptionElement)) => {
|
||||
let element = node.downcast::<HTMLOptionElement>().unwrap();
|
||||
element as &VirtualMethods
|
||||
node.downcast::<HTMLOptionElement>().unwrap() as &VirtualMethods
|
||||
}
|
||||
NodeTypeId::Element(ElementTypeId::HTMLElement(HTMLElementTypeId::HTMLScriptElement)) => {
|
||||
let element = node.downcast::<HTMLScriptElement>().unwrap();
|
||||
element as &VirtualMethods
|
||||
node.downcast::<HTMLScriptElement>().unwrap() as &VirtualMethods
|
||||
}
|
||||
NodeTypeId::Element(ElementTypeId::HTMLElement(HTMLElementTypeId::HTMLSelectElement)) => {
|
||||
let element = node.downcast::<HTMLSelectElement>().unwrap();
|
||||
element as &VirtualMethods
|
||||
node.downcast::<HTMLSelectElement>().unwrap() as &VirtualMethods
|
||||
}
|
||||
NodeTypeId::Element(ElementTypeId::HTMLElement(HTMLElementTypeId::HTMLStyleElement)) => {
|
||||
let element = node.downcast::<HTMLStyleElement>().unwrap();
|
||||
element as &VirtualMethods
|
||||
node.downcast::<HTMLStyleElement>().unwrap() as &VirtualMethods
|
||||
}
|
||||
NodeTypeId::Element(ElementTypeId::HTMLElement(HTMLElementTypeId::HTMLTableElement)) => {
|
||||
let element =
|
||||
node.downcast::<HTMLTableElement>().unwrap();
|
||||
element as &VirtualMethods
|
||||
node.downcast::<HTMLTableElement>().unwrap() as &VirtualMethods
|
||||
}
|
||||
NodeTypeId::Element(ElementTypeId::HTMLElement(HTMLElementTypeId::HTMLTableCellElement(_))) => {
|
||||
let element =
|
||||
node.downcast::<HTMLTableCellElement>().unwrap();
|
||||
element as &VirtualMethods
|
||||
node.downcast::<HTMLTableCellElement>().unwrap() as &VirtualMethods
|
||||
}
|
||||
NodeTypeId::Element(ElementTypeId::HTMLElement(HTMLElementTypeId::HTMLTableRowElement)) => {
|
||||
let element =
|
||||
node.downcast::<HTMLTableRowElement>().unwrap();
|
||||
element as &VirtualMethods
|
||||
node.downcast::<HTMLTableRowElement>().unwrap() as &VirtualMethods
|
||||
}
|
||||
NodeTypeId::Element(ElementTypeId::HTMLElement(HTMLElementTypeId::HTMLTableSectionElement)) => {
|
||||
let element =
|
||||
node.downcast::<HTMLTableSectionElement>().unwrap();
|
||||
element as &VirtualMethods
|
||||
node.downcast::<HTMLTableSectionElement>().unwrap() as &VirtualMethods
|
||||
}
|
||||
NodeTypeId::Element(ElementTypeId::HTMLElement(HTMLElementTypeId::HTMLTemplateElement)) => {
|
||||
node.downcast::<HTMLTemplateElement>().unwrap() as &VirtualMethods
|
||||
}
|
||||
NodeTypeId::Element(ElementTypeId::HTMLElement(HTMLElementTypeId::HTMLTextAreaElement)) => {
|
||||
let element = node.downcast::<HTMLTextAreaElement>().unwrap();
|
||||
element as &VirtualMethods
|
||||
node.downcast::<HTMLTextAreaElement>().unwrap() as &VirtualMethods
|
||||
}
|
||||
NodeTypeId::Element(ElementTypeId::HTMLElement(HTMLElementTypeId::HTMLTitleElement)) => {
|
||||
let element =
|
||||
node.downcast::<HTMLTitleElement>().unwrap();
|
||||
element as &VirtualMethods
|
||||
node.downcast::<HTMLTitleElement>().unwrap() as &VirtualMethods
|
||||
}
|
||||
NodeTypeId::Element(ElementTypeId::Element) => {
|
||||
let element = node.downcast::<Element>().unwrap();
|
||||
element as &VirtualMethods
|
||||
node.downcast::<Element>().unwrap() as &VirtualMethods
|
||||
}
|
||||
NodeTypeId::Element(_) => {
|
||||
let element = node.downcast::<HTMLElement>().unwrap();
|
||||
element as &VirtualMethods
|
||||
node.downcast::<HTMLElement>().unwrap() as &VirtualMethods
|
||||
}
|
||||
_ => {
|
||||
node as &VirtualMethods
|
||||
|
|
|
@ -14,7 +14,6 @@ use dom::bindings::global::{GlobalField, GlobalRef};
|
|||
use dom::bindings::js::{JS, LayoutJS, MutNullableHeap, Root};
|
||||
use dom::bindings::utils::{Reflector, reflect_dom_object};
|
||||
use dom::event::{Event, EventBubbles, EventCancelable};
|
||||
use dom::eventtarget::EventTarget;
|
||||
use dom::htmlcanvaselement::HTMLCanvasElement;
|
||||
use dom::htmlcanvaselement::utils as canvas_utils;
|
||||
use dom::node::{Node, NodeDamage, window_from_node};
|
||||
|
@ -121,7 +120,7 @@ impl WebGLRenderingContext {
|
|||
EventBubbles::DoesNotBubble,
|
||||
EventCancelable::Cancelable,
|
||||
msg);
|
||||
event.upcast::<Event>().fire(canvas.upcast::<EventTarget>());
|
||||
event.upcast::<Event>().fire(canvas.upcast());
|
||||
None
|
||||
}
|
||||
}
|
||||
|
@ -153,9 +152,7 @@ impl WebGLRenderingContext {
|
|||
}
|
||||
|
||||
fn mark_as_dirty(&self) {
|
||||
let canvas = self.canvas.root();
|
||||
let node = canvas.upcast::<Node>();
|
||||
node.dirty(NodeDamage::OtherNodeDamage);
|
||||
self.canvas.root().upcast::<Node>().dirty(NodeDamage::OtherNodeDamage);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -454,7 +454,7 @@ impl Runnable for ConnectionEstablishedTask {
|
|||
let event = Event::new(global.r(), "open".to_owned(),
|
||||
EventBubbles::DoesNotBubble,
|
||||
EventCancelable::NotCancelable);
|
||||
event.fire(ws.upcast::<EventTarget>());
|
||||
event.fire(ws.upcast());
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -496,8 +496,7 @@ impl Runnable for CloseTask {
|
|||
"error".to_owned(),
|
||||
EventBubbles::DoesNotBubble,
|
||||
EventCancelable::Cancelable);
|
||||
let target = ws.upcast::<EventTarget>();
|
||||
event.r().fire(target);
|
||||
event.fire(ws.upcast());
|
||||
}
|
||||
let rsn = ws.reason.borrow();
|
||||
let rsn_clone = rsn.clone();
|
||||
|
@ -511,9 +510,7 @@ impl Runnable for CloseTask {
|
|||
ws.clean_close.get(),
|
||||
ws.code.get(),
|
||||
rsn_clone);
|
||||
let target = ws.upcast::<EventTarget>();
|
||||
let event = close_event.upcast::<Event>();
|
||||
event.fire(target);
|
||||
close_event.upcast::<Event>().fire(ws.upcast());
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -562,7 +559,6 @@ impl Runnable for MessageReceivedTask {
|
|||
},
|
||||
}
|
||||
|
||||
let target = ws.upcast::<EventTarget>();
|
||||
MessageEvent::dispatch_jsval(target, global.r(), message.handle());
|
||||
MessageEvent::dispatch_jsval(ws.upcast(), global.r(), message.handle());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -793,8 +793,7 @@ impl<'a, T: Reflectable> ScriptHelpers for &'a T {
|
|||
|
||||
impl Window {
|
||||
pub fn clear_js_runtime(&self) {
|
||||
let document = self.Document();
|
||||
document.upcast::<Node>().teardown();
|
||||
self.Document().upcast::<Node>().teardown();
|
||||
|
||||
// The above code may not catch all DOM objects
|
||||
// (e.g. DOM objects removed from the tree that haven't
|
||||
|
@ -835,9 +834,7 @@ impl Window {
|
|||
let body = self.Document().GetBody();
|
||||
let (x, y) = match body {
|
||||
Some(e) => {
|
||||
let node = e.upcast::<Node>();
|
||||
let content_size = node.get_bounding_content_box();
|
||||
|
||||
let content_size = e.upcast::<Node>().get_bounding_content_box();
|
||||
let content_height = content_size.size.height.to_f64_px();
|
||||
let content_width = content_size.size.width.to_f64_px();
|
||||
(xfinite.max(0.0f64).min(content_width - width),
|
||||
|
@ -1055,7 +1052,7 @@ impl Window {
|
|||
let js_runtime = js_runtime.as_ref().unwrap();
|
||||
let element = response.node_address.and_then(|parent_node_address| {
|
||||
let node = from_untrusted_node_address(js_runtime.rt(), parent_node_address);
|
||||
Root::downcast::<Element>(node)
|
||||
Root::downcast(node)
|
||||
});
|
||||
(element, response.rect)
|
||||
}
|
||||
|
|
|
@ -115,7 +115,7 @@ impl Worker {
|
|||
let worker = address.root();
|
||||
|
||||
let global = worker.r().global.root();
|
||||
let target = worker.upcast::<EventTarget>();
|
||||
let target = worker.upcast();
|
||||
let _ar = JSAutoRequest::new(global.r().get_cx());
|
||||
let _ac = JSAutoCompartment::new(global.r().get_cx(), target.reflector().get_jsobject().get());
|
||||
let mut message = RootedValue::new(global.r().get_cx(), UndefinedValue());
|
||||
|
@ -126,13 +126,11 @@ impl Worker {
|
|||
pub fn dispatch_simple_error(address: TrustedWorkerAddress) {
|
||||
let worker = address.root();
|
||||
let global = worker.r().global.root();
|
||||
let target = worker.upcast::<EventTarget>();
|
||||
|
||||
let event = Event::new(global.r(),
|
||||
"error".to_owned(),
|
||||
EventBubbles::DoesNotBubble,
|
||||
EventCancelable::NotCancelable);
|
||||
event.r().fire(target);
|
||||
event.fire(worker.upcast());
|
||||
}
|
||||
|
||||
pub fn handle_error_message(address: TrustedWorkerAddress, message: DOMString,
|
||||
|
@ -140,12 +138,10 @@ impl Worker {
|
|||
let worker = address.root();
|
||||
let global = worker.r().global.root();
|
||||
let error = RootedValue::new(global.r().get_cx(), UndefinedValue());
|
||||
let target = worker.upcast::<EventTarget>();
|
||||
let errorevent = ErrorEvent::new(global.r(), "error".to_owned(),
|
||||
EventBubbles::Bubbles, EventCancelable::Cancelable,
|
||||
message, filename, lineno, colno, error.handle());
|
||||
let event = errorevent.upcast::<Event>();
|
||||
event.fire(target);
|
||||
errorevent.upcast::<Event>().fire(worker.upcast());
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -737,8 +737,7 @@ impl XMLHttpRequest {
|
|||
"readystatechange".to_owned(),
|
||||
EventBubbles::DoesNotBubble,
|
||||
EventCancelable::Cancelable);
|
||||
let target = self.upcast::<EventTarget>();
|
||||
event.r().fire(target);
|
||||
event.fire(self.upcast());
|
||||
}
|
||||
|
||||
fn process_headers_available(&self, cors_request: Option<CORSRequest>,
|
||||
|
@ -921,12 +920,11 @@ impl XMLHttpRequest {
|
|||
total.is_some(), loaded,
|
||||
total.unwrap_or(0));
|
||||
let target = if upload {
|
||||
self.upload.upcast::<EventTarget>()
|
||||
self.upload.upcast()
|
||||
} else {
|
||||
self.upcast::<EventTarget>()
|
||||
self.upcast()
|
||||
};
|
||||
let event = progressevent.upcast::<Event>();
|
||||
event.fire(target);
|
||||
progressevent.upcast::<Event>().fire(target);
|
||||
}
|
||||
|
||||
fn dispatch_upload_progress_event(&self, type_: DOMString, partial_load: Option<u64>) {
|
||||
|
|
|
@ -45,16 +45,14 @@ impl<'a> TreeSink for servohtmlparser::Sink {
|
|||
type Handle = JS<Node>;
|
||||
|
||||
fn get_document(&mut self) -> JS<Node> {
|
||||
let doc = self.document.root();
|
||||
let node = doc.upcast::<Node>();
|
||||
JS::from_ref(node)
|
||||
JS::from_ref(self.document.root().upcast())
|
||||
}
|
||||
|
||||
fn get_template_contents(&self, target: JS<Node>) -> JS<Node> {
|
||||
let target = target.root();
|
||||
let template = target.downcast::<HTMLTemplateElement>()
|
||||
.expect("tried to get template contents of non-HTMLTemplateElement in HTML parsing");
|
||||
JS::from_ref(template.Content().upcast::<Node>())
|
||||
JS::from_ref(template.Content().upcast())
|
||||
}
|
||||
|
||||
fn same_node(&self, x: JS<Node>, y: JS<Node>) -> bool {
|
||||
|
@ -81,15 +79,13 @@ impl<'a> TreeSink for servohtmlparser::Sink {
|
|||
elem.r().set_attribute_from_parser(attr.name, attr.value.into(), None);
|
||||
}
|
||||
|
||||
let node = elem.upcast::<Node>();
|
||||
JS::from_ref(node)
|
||||
JS::from_ref(elem.upcast())
|
||||
}
|
||||
|
||||
fn create_comment(&mut self, text: StrTendril) -> JS<Node> {
|
||||
let doc = self.document.root();
|
||||
let comment = Comment::new(text.into(), doc.r());
|
||||
let node = Root::upcast::<Node>(comment);
|
||||
JS::from_rooted(&node)
|
||||
JS::from_ref(comment.upcast())
|
||||
}
|
||||
|
||||
fn append_before_sibling(&mut self,
|
||||
|
@ -127,12 +123,9 @@ impl<'a> TreeSink for servohtmlparser::Sink {
|
|||
fn append_doctype_to_document(&mut self, name: StrTendril, public_id: StrTendril,
|
||||
system_id: StrTendril) {
|
||||
let doc = self.document.root();
|
||||
let doc_node = doc.upcast::<Node>();
|
||||
let doctype = DocumentType::new(
|
||||
name.into(), Some(public_id.into()), Some(system_id.into()), doc.r());
|
||||
let node: Root<Node> = Root::upcast::<Node>(doctype);
|
||||
|
||||
assert!(doc_node.AppendChild(node.r()).is_ok());
|
||||
doc.upcast::<Node>().AppendChild(doctype.upcast()).expect("Appending failed");
|
||||
}
|
||||
|
||||
fn add_attrs_if_missing(&mut self, target: JS<Node>, attrs: Vec<Attribute>) {
|
||||
|
@ -153,13 +146,13 @@ impl<'a> TreeSink for servohtmlparser::Sink {
|
|||
|
||||
fn mark_script_already_started(&mut self, node: JS<Node>) {
|
||||
let node: Root<Node> = node.root();
|
||||
let script: Option<&HTMLScriptElement> = node.downcast::<HTMLScriptElement>();
|
||||
let script = node.downcast::<HTMLScriptElement>();
|
||||
script.map(|script| script.mark_already_started());
|
||||
}
|
||||
|
||||
fn complete_script(&mut self, node: JS<Node>) -> NextParserState {
|
||||
let node: Root<Node> = node.root();
|
||||
let script: Option<&HTMLScriptElement> = node.downcast::<HTMLScriptElement>();
|
||||
let script = node.downcast::<HTMLScriptElement>();
|
||||
if let Some(script) = script {
|
||||
return script.prepare();
|
||||
}
|
||||
|
@ -305,8 +298,7 @@ pub fn parse_html_fragment(context_node: &Node,
|
|||
|
||||
// Step 14.
|
||||
let root_element = document.r().GetDocumentElement().expect("no document element");
|
||||
let root_node = root_element.upcast::<Node>();
|
||||
for child in root_node.children() {
|
||||
for child in root_element.upcast::<Node>().children() {
|
||||
output.AppendChild(child.r()).unwrap();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -34,7 +34,6 @@ use dom::document::{Document, DocumentProgressHandler, IsHTMLDocument};
|
|||
use dom::document::{DocumentProgressTask, DocumentSource, MouseEventType};
|
||||
use dom::element::Element;
|
||||
use dom::event::{Event, EventBubbles, EventCancelable};
|
||||
use dom::eventtarget::EventTarget;
|
||||
use dom::node::{Node, NodeDamage, window_from_node};
|
||||
use dom::servohtmlparser::{ParserContext, ServoHTMLParser};
|
||||
use dom::uievent::UIEvent;
|
||||
|
@ -1256,12 +1255,10 @@ impl ScriptTask {
|
|||
urls.push(current_url.clone());
|
||||
|
||||
for child in it_page.document().upcast::<Node>().traverse_preorder() {
|
||||
let target = child.upcast::<EventTarget>();
|
||||
dom_tree_size += heap_size_of_self_and_children(target);
|
||||
dom_tree_size += heap_size_of_self_and_children(&*child);
|
||||
}
|
||||
let window = it_page.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(&*window);
|
||||
|
||||
reports.push(Report {
|
||||
path: path![format!("url({})", current_url), "dom-tree"],
|
||||
|
@ -1323,9 +1320,8 @@ impl ScriptTask {
|
|||
let frame_element = doc.find_iframe(subpage_id);
|
||||
|
||||
if let Some(ref frame_element) = frame_element {
|
||||
let element = frame_element.upcast::<Element>();
|
||||
doc.r().begin_focus_transaction();
|
||||
doc.r().request_focus(element);
|
||||
doc.r().request_focus(frame_element.upcast());
|
||||
doc.r().commit_focus_transaction(FocusType::Parent);
|
||||
}
|
||||
}
|
||||
|
@ -1625,7 +1621,7 @@ impl ScriptTask {
|
|||
DocumentSource::FromParser,
|
||||
loader);
|
||||
|
||||
let frame_element = frame_element.r().map(Castable::upcast::<Element>);
|
||||
let frame_element = frame_element.r().map(Castable::upcast);
|
||||
window.r().init_browsing_context(document.r(), frame_element);
|
||||
|
||||
// Create the root frame
|
||||
|
@ -1671,9 +1667,8 @@ impl ScriptTask {
|
|||
}
|
||||
}
|
||||
|
||||
fn scroll_fragment_point(&self, pipeline_id: PipelineId, node: &Element) {
|
||||
let node = node.upcast::<Node>();
|
||||
let rect = node.get_bounding_content_box();
|
||||
fn scroll_fragment_point(&self, pipeline_id: PipelineId, element: &Element) {
|
||||
let rect = element.upcast::<Node>().get_bounding_content_box();
|
||||
let point = Point2D::new(rect.origin.x.to_f32_px(), rect.origin.y.to_f32_px());
|
||||
// FIXME(#2003, pcwalton): This is pretty bogus when multiple layers are involved.
|
||||
// Really what needs to happen is that this needs to go through layout to ask which
|
||||
|
@ -1844,10 +1839,7 @@ impl ScriptTask {
|
|||
"resize".to_owned(), EventBubbles::DoesNotBubble,
|
||||
EventCancelable::NotCancelable, Some(window.r()),
|
||||
0i32);
|
||||
let event = uievent.upcast::<Event>();
|
||||
|
||||
let wintarget = window.upcast::<EventTarget>();
|
||||
event.fire(wintarget);
|
||||
uievent.upcast::<Event>().fire(window.upcast());
|
||||
}
|
||||
|
||||
/// Initiate a non-blocking fetch for a specified resource. Stores the InProgressLoad
|
||||
|
@ -1905,7 +1897,7 @@ impl ScriptTask {
|
|||
// Kick off the initial reflow of the page.
|
||||
debug!("kicking off initial reflow of {:?}", final_url);
|
||||
document.r().disarm_reflow_timeout();
|
||||
document.r().content_changed(document.upcast::<Node>(),
|
||||
document.r().content_changed(document.upcast(),
|
||||
NodeDamage::OtherNodeDamage);
|
||||
let window = window_from_node(document.r());
|
||||
window.r().reflow(ReflowGoal::ForDisplay, ReflowQueryType::NoQuery, ReflowReason::FirstLoad);
|
||||
|
|
|
@ -116,8 +116,7 @@ pub fn handle_find_element_css(page: &Rc<Page>, _pipeline: PipelineId, selector:
|
|||
reply: IpcSender<Result<Option<String>, ()>>) {
|
||||
reply.send(match page.document().r().QuerySelector(selector.clone()) {
|
||||
Ok(node) => {
|
||||
let result = node.map(|x| x.upcast::<Node>().get_unique_id());
|
||||
Ok(result)
|
||||
Ok(node.map(|x| x.upcast::<Node>().get_unique_id()))
|
||||
}
|
||||
Err(_) => Err(())
|
||||
}).unwrap();
|
||||
|
@ -172,8 +171,7 @@ pub fn handle_get_name(page: &Rc<Page>,
|
|||
reply: IpcSender<Result<String, ()>>) {
|
||||
reply.send(match find_node_by_unique_id(&*page, pipeline, node_id) {
|
||||
Some(node) => {
|
||||
let element = node.downcast::<Element>().unwrap();
|
||||
Ok(element.TagName())
|
||||
Ok(node.downcast::<Element>().unwrap().TagName())
|
||||
},
|
||||
None => Err(())
|
||||
}).unwrap();
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue