remove to_borrowed_ref, fix Activatable

This commit is contained in:
Manish Goregaokar 2015-08-27 02:27:42 +05:30
parent b33c5427bc
commit 4678ec16bb
4 changed files with 18 additions and 26 deletions

View file

@ -5807,14 +5807,6 @@ impl ${name}Cast {
}
}
#[inline]
pub fn to_borrowed_ref<'a, 'b, T: ${toBound}+Reflectable>(base: &'a &'b T) -> Option<&'a &'b ${name}> {
match base.${checkFn}() {
true => Some(unsafe { mem::transmute(base) }),
false => None
}
}
#[inline]
#[allow(unrooted_must_root)]
pub fn to_layout_js<T: ${toBound}+Reflectable>(base: &LayoutJS<T>) -> Option<LayoutJS<${name}>> {

View file

@ -1854,7 +1854,7 @@ impl<'a> ::selectors::Element for Root<Element> {
}
pub trait ActivationElementHelpers<'a> {
fn as_maybe_activatable(&'a self) -> Option<&'a (Activatable + 'a)>;
fn as_maybe_activatable(self) -> Option<&'a (Activatable + 'a)>;
fn click_in_progress(self) -> bool;
fn set_click_in_progress(self, click: bool);
fn nearest_activable_element(self) -> Option<Root<Element>>;
@ -1862,15 +1862,15 @@ pub trait ActivationElementHelpers<'a> {
}
impl<'a> ActivationElementHelpers<'a> for &'a Element {
fn as_maybe_activatable(&'a self) -> Option<&'a (Activatable + 'a)> {
let node = NodeCast::from_ref(*self);
fn as_maybe_activatable(self) -> Option<&'a (Activatable + 'a)> {
let node = NodeCast::from_ref(self);
let element = match node.type_id() {
NodeTypeId::Element(ElementTypeId::HTMLElement(HTMLElementTypeId::HTMLInputElement)) => {
let element = HTMLInputElementCast::to_borrowed_ref(self).unwrap();
let element = HTMLInputElementCast::to_ref(self).unwrap();
Some(element as &'a (Activatable + 'a))
},
NodeTypeId::Element(ElementTypeId::HTMLElement(HTMLElementTypeId::HTMLAnchorElement)) => {
let element = HTMLAnchorElementCast::to_borrowed_ref(self).unwrap();
let element = HTMLAnchorElementCast::to_ref(self).unwrap();
Some(element as &'a (Activatable + 'a))
},
_ => {

View file

@ -102,9 +102,9 @@ impl<'a> HTMLAnchorElementMethods for &'a HTMLAnchorElement {
}
}
impl<'a> Activatable for &'a HTMLAnchorElement {
impl Activatable for HTMLAnchorElement {
fn as_element<'b>(&'b self) -> &'b Element {
ElementCast::from_ref(*self)
ElementCast::from_ref(self)
}
fn is_instance_activatable(&self) -> bool {
@ -113,7 +113,7 @@ impl<'a> Activatable for &'a HTMLAnchorElement {
// hyperlink"
// https://html.spec.whatwg.org/multipage/#the-a-element
// "The activation behaviour of a elements *that create hyperlinks*"
ElementCast::from_ref(*self).has_attribute(&atom!("href"))
ElementCast::from_ref(self).has_attribute(&atom!("href"))
}
@ -129,13 +129,13 @@ impl<'a> Activatable for &'a HTMLAnchorElement {
//https://html.spec.whatwg.org/multipage/#the-a-element:activation-behaviour
fn activation_behavior(&self, event: &Event, target: &EventTarget) {
//Step 1. If the node document is not fully active, abort.
let doc = document_from_node(*self);
let doc = document_from_node(self);
if !doc.r().is_fully_active() {
return;
}
//TODO: Step 2. Check if browsing context is specified and act accordingly.
//Step 3. Handle <img ismap/>.
let element = ElementCast::from_ref(*self);
let element = ElementCast::from_ref(self);
let mouse_event = MouseEventCast::to_ref(event).unwrap();
let mut ismap_suffix = None;
if let Some(element) = ElementCast::to_ref(target) {

View file

@ -652,9 +652,9 @@ impl<'a> FormControl<'a> for &'a HTMLInputElement {
}
}
impl<'a> Activatable for &'a HTMLInputElement {
impl Activatable for HTMLInputElement {
fn as_element<'b>(&'b self) -> &'b Element {
ElementCast::from_ref(*self)
ElementCast::from_ref(self)
}
fn is_instance_activatable(&self) -> bool {
@ -698,7 +698,7 @@ impl<'a> Activatable for &'a HTMLInputElement {
InputType::InputRadio => {
//TODO: if not in document, use root ancestor instead of document
let owner = self.form_owner();
let doc = document_from_node(*self);
let doc = document_from_node(self);
let doc_node = NodeCast::from_ref(doc.r());
let group = self.get_radio_group_name();;
@ -803,19 +803,19 @@ impl<'a> Activatable for &'a HTMLInputElement {
// https://html.spec.whatwg.org/multipage/#checkbox-state-(type=checkbox):activation-behavior
// https://html.spec.whatwg.org/multipage/#radio-button-state-(type=radio):activation-behavior
if self.mutable() {
let win = window_from_node(*self);
let win = window_from_node(self);
let event = Event::new(GlobalRef::Window(win.r()),
"input".to_owned(),
EventBubbles::Bubbles,
EventCancelable::NotCancelable);
let target = EventTargetCast::from_ref(*self);
let target = EventTargetCast::from_ref(self);
event.r().fire(target);
let event = Event::new(GlobalRef::Window(win.r()),
"change".to_owned(),
EventBubbles::Bubbles,
EventCancelable::NotCancelable);
let target = EventTargetCast::from_ref(*self);
let target = EventTargetCast::from_ref(self);
event.r().fire(target);
}
},
@ -826,7 +826,7 @@ impl<'a> Activatable for &'a HTMLInputElement {
// https://html.spec.whatwg.org/multipage/#implicit-submission
#[allow(unsafe_code)]
fn implicit_submission(&self, ctrlKey: bool, shiftKey: bool, altKey: bool, metaKey: bool) {
let doc = document_from_node(*self);
let doc = document_from_node(self);
let node = NodeCast::from_ref(doc.r());
let owner = self.form_owner();
let form = match owner {
@ -834,7 +834,7 @@ impl<'a> Activatable for &'a HTMLInputElement {
Some(ref f) => f
};
let elem = ElementCast::from_ref(*self);
let elem = ElementCast::from_ref(self);
if elem.click_in_progress() {
return;
}