mirror of
https://github.com/servo/servo.git
synced 2025-08-06 14:10:11 +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
|
@ -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;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue