mirror of
https://github.com/servo/servo.git
synced 2025-07-30 02:30:21 +01:00
remove to_borrowed_ref, fix Activatable
This commit is contained in:
parent
b33c5427bc
commit
4678ec16bb
4 changed files with 18 additions and 26 deletions
|
@ -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]
|
#[inline]
|
||||||
#[allow(unrooted_must_root)]
|
#[allow(unrooted_must_root)]
|
||||||
pub fn to_layout_js<T: ${toBound}+Reflectable>(base: &LayoutJS<T>) -> Option<LayoutJS<${name}>> {
|
pub fn to_layout_js<T: ${toBound}+Reflectable>(base: &LayoutJS<T>) -> Option<LayoutJS<${name}>> {
|
||||||
|
|
|
@ -1854,7 +1854,7 @@ impl<'a> ::selectors::Element for Root<Element> {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub trait ActivationElementHelpers<'a> {
|
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 click_in_progress(self) -> bool;
|
||||||
fn set_click_in_progress(self, click: bool);
|
fn set_click_in_progress(self, click: bool);
|
||||||
fn nearest_activable_element(self) -> Option<Root<Element>>;
|
fn nearest_activable_element(self) -> Option<Root<Element>>;
|
||||||
|
@ -1862,15 +1862,15 @@ pub trait ActivationElementHelpers<'a> {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a> ActivationElementHelpers<'a> for &'a Element {
|
impl<'a> ActivationElementHelpers<'a> for &'a Element {
|
||||||
fn as_maybe_activatable(&'a self) -> Option<&'a (Activatable + 'a)> {
|
fn as_maybe_activatable(self) -> Option<&'a (Activatable + 'a)> {
|
||||||
let node = NodeCast::from_ref(*self);
|
let node = NodeCast::from_ref(self);
|
||||||
let element = match node.type_id() {
|
let element = match node.type_id() {
|
||||||
NodeTypeId::Element(ElementTypeId::HTMLElement(HTMLElementTypeId::HTMLInputElement)) => {
|
NodeTypeId::Element(ElementTypeId::HTMLElement(HTMLElementTypeId::HTMLInputElement)) => {
|
||||||
let element = HTMLInputElementCast::to_borrowed_ref(self).unwrap();
|
let element = HTMLInputElementCast::to_ref(self).unwrap();
|
||||||
Some(element as &'a (Activatable + 'a))
|
Some(element as &'a (Activatable + 'a))
|
||||||
},
|
},
|
||||||
NodeTypeId::Element(ElementTypeId::HTMLElement(HTMLElementTypeId::HTMLAnchorElement)) => {
|
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))
|
Some(element as &'a (Activatable + 'a))
|
||||||
},
|
},
|
||||||
_ => {
|
_ => {
|
||||||
|
|
|
@ -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 {
|
fn as_element<'b>(&'b self) -> &'b Element {
|
||||||
ElementCast::from_ref(*self)
|
ElementCast::from_ref(self)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn is_instance_activatable(&self) -> bool {
|
fn is_instance_activatable(&self) -> bool {
|
||||||
|
@ -113,7 +113,7 @@ impl<'a> Activatable for &'a HTMLAnchorElement {
|
||||||
// hyperlink"
|
// hyperlink"
|
||||||
// https://html.spec.whatwg.org/multipage/#the-a-element
|
// https://html.spec.whatwg.org/multipage/#the-a-element
|
||||||
// "The activation behaviour of a elements *that create hyperlinks*"
|
// "The activation behaviour of a elements *that create hyperlinks*"
|
||||||
ElementCast::from_ref(*self).has_attribute(&atom!("href"))
|
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
|
//https://html.spec.whatwg.org/multipage/#the-a-element:activation-behaviour
|
||||||
fn activation_behavior(&self, event: &Event, target: &EventTarget) {
|
fn activation_behavior(&self, event: &Event, target: &EventTarget) {
|
||||||
//Step 1. If the node document is not fully active, abort.
|
//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() {
|
if !doc.r().is_fully_active() {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
//TODO: Step 2. Check if browsing context is specified and act accordingly.
|
//TODO: Step 2. Check if browsing context is specified and act accordingly.
|
||||||
//Step 3. Handle <img ismap/>.
|
//Step 3. Handle <img ismap/>.
|
||||||
let element = ElementCast::from_ref(*self);
|
let element = ElementCast::from_ref(self);
|
||||||
let mouse_event = MouseEventCast::to_ref(event).unwrap();
|
let mouse_event = MouseEventCast::to_ref(event).unwrap();
|
||||||
let mut ismap_suffix = None;
|
let mut ismap_suffix = None;
|
||||||
if let Some(element) = ElementCast::to_ref(target) {
|
if let Some(element) = ElementCast::to_ref(target) {
|
||||||
|
|
|
@ -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 {
|
fn as_element<'b>(&'b self) -> &'b Element {
|
||||||
ElementCast::from_ref(*self)
|
ElementCast::from_ref(self)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn is_instance_activatable(&self) -> bool {
|
fn is_instance_activatable(&self) -> bool {
|
||||||
|
@ -698,7 +698,7 @@ impl<'a> Activatable for &'a HTMLInputElement {
|
||||||
InputType::InputRadio => {
|
InputType::InputRadio => {
|
||||||
//TODO: if not in document, use root ancestor instead of document
|
//TODO: if not in document, use root ancestor instead of document
|
||||||
let owner = self.form_owner();
|
let owner = self.form_owner();
|
||||||
let doc = document_from_node(*self);
|
let doc = document_from_node(self);
|
||||||
let doc_node = NodeCast::from_ref(doc.r());
|
let doc_node = NodeCast::from_ref(doc.r());
|
||||||
let group = self.get_radio_group_name();;
|
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/#checkbox-state-(type=checkbox):activation-behavior
|
||||||
// https://html.spec.whatwg.org/multipage/#radio-button-state-(type=radio):activation-behavior
|
// https://html.spec.whatwg.org/multipage/#radio-button-state-(type=radio):activation-behavior
|
||||||
if self.mutable() {
|
if self.mutable() {
|
||||||
let win = window_from_node(*self);
|
let win = window_from_node(self);
|
||||||
let event = Event::new(GlobalRef::Window(win.r()),
|
let event = Event::new(GlobalRef::Window(win.r()),
|
||||||
"input".to_owned(),
|
"input".to_owned(),
|
||||||
EventBubbles::Bubbles,
|
EventBubbles::Bubbles,
|
||||||
EventCancelable::NotCancelable);
|
EventCancelable::NotCancelable);
|
||||||
let target = EventTargetCast::from_ref(*self);
|
let target = EventTargetCast::from_ref(self);
|
||||||
event.r().fire(target);
|
event.r().fire(target);
|
||||||
|
|
||||||
let event = Event::new(GlobalRef::Window(win.r()),
|
let event = Event::new(GlobalRef::Window(win.r()),
|
||||||
"change".to_owned(),
|
"change".to_owned(),
|
||||||
EventBubbles::Bubbles,
|
EventBubbles::Bubbles,
|
||||||
EventCancelable::NotCancelable);
|
EventCancelable::NotCancelable);
|
||||||
let target = EventTargetCast::from_ref(*self);
|
let target = EventTargetCast::from_ref(self);
|
||||||
event.r().fire(target);
|
event.r().fire(target);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
@ -826,7 +826,7 @@ impl<'a> Activatable for &'a HTMLInputElement {
|
||||||
// https://html.spec.whatwg.org/multipage/#implicit-submission
|
// https://html.spec.whatwg.org/multipage/#implicit-submission
|
||||||
#[allow(unsafe_code)]
|
#[allow(unsafe_code)]
|
||||||
fn implicit_submission(&self, ctrlKey: bool, shiftKey: bool, altKey: bool, metaKey: bool) {
|
fn implicit_submission(&self, ctrlKey: bool, shiftKey: bool, altKey: bool, metaKey: bool) {
|
||||||
let doc = document_from_node(*self);
|
let doc = document_from_node(self);
|
||||||
let node = NodeCast::from_ref(doc.r());
|
let node = NodeCast::from_ref(doc.r());
|
||||||
let owner = self.form_owner();
|
let owner = self.form_owner();
|
||||||
let form = match owner {
|
let form = match owner {
|
||||||
|
@ -834,7 +834,7 @@ impl<'a> Activatable for &'a HTMLInputElement {
|
||||||
Some(ref f) => f
|
Some(ref f) => f
|
||||||
};
|
};
|
||||||
|
|
||||||
let elem = ElementCast::from_ref(*self);
|
let elem = ElementCast::from_ref(self);
|
||||||
if elem.click_in_progress() {
|
if elem.click_in_progress() {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue