diff options
author | Patrick Shaughnessy <pshaughn@comcast.net> | 2020-01-09 15:33:52 -0500 |
---|---|---|
committer | Patrick Shaughnessy <pshaughn@comcast.net> | 2020-02-12 15:57:37 -0500 |
commit | 01aba1fcc453192da64272dcc180135ce11e4ea7 (patch) | |
tree | 31f92472dca740a63a91a51188a0f3325a00481b /components/script/dom/activation.rs | |
parent | ed9b5843443db7164bda6eb6f3cb7caff2ff5a3c (diff) | |
download | servo-01aba1fcc453192da64272dcc180135ce11e4ea7.tar.gz servo-01aba1fcc453192da64272dcc180135ce11e4ea7.zip |
Event dispatch rewritten to resemble spec more often, activate on clicks better
Diffstat (limited to 'components/script/dom/activation.rs')
-rw-r--r-- | components/script/dom/activation.rs | 94 |
1 files changed, 11 insertions, 83 deletions
diff --git a/components/script/dom/activation.rs b/components/script/dom/activation.rs index a12874b9b43..4e6ac769885 100644 --- a/components/script/dom/activation.rs +++ b/components/script/dom/activation.rs @@ -2,17 +2,13 @@ * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at https://mozilla.org/MPL/2.0/. */ -use crate::dom::bindings::codegen::Bindings::EventBinding::EventMethods; -use crate::dom::bindings::inheritance::Castable; -use crate::dom::bindings::str::DOMString; use crate::dom::element::Element; -use crate::dom::event::{Event, EventBubbles, EventCancelable}; +use crate::dom::event::Event; use crate::dom::eventtarget::EventTarget; -use crate::dom::mouseevent::MouseEvent; +use crate::dom::htmlinputelement::InputActivationState; use crate::dom::node::window_from_node; use crate::dom::window::ReflowReason; use script_layout_interface::message::ReflowGoal; -use script_traits::MouseButton; /// Trait for elements with defined activation behavior pub trait Activatable { @@ -21,13 +17,17 @@ pub trait Activatable { // Is this particular instance of the element activatable? fn is_instance_activatable(&self) -> bool; - // https://html.spec.whatwg.org/multipage/#run-pre-click-activation-steps - fn pre_click_activation(&self); + // https://dom.spec.whatwg.org/#eventtarget-legacy-pre-activation-behavior + fn legacy_pre_activation_behavior(&self) -> Option<InputActivationState> { + None + } - // https://html.spec.whatwg.org/multipage/#run-canceled-activation-steps - fn canceled_activation(&self); + // https://dom.spec.whatwg.org/#eventtarget-legacy-canceled-activation-behavior + fn legacy_canceled_activation_behavior(&self, _state_before: Option<InputActivationState>) {} - // https://html.spec.whatwg.org/multipage/#run-post-click-activation-steps + // https://dom.spec.whatwg.org/#eventtarget-activation-behavior + // event and target are used only by HTMLAnchorElement, in the case + // where the target is an <img ismap> so the href gets coordinates appended fn activation_behavior(&self, event: &Event, target: &EventTarget); // https://html.spec.whatwg.org/multipage/#concept-selector-active @@ -45,75 +45,3 @@ pub trait Activatable { win.reflow(ReflowGoal::Full, ReflowReason::ElementStateChanged); } } - -/// Whether an activation was initiated via the click() method -#[derive(PartialEq)] -pub enum ActivationSource { - FromClick, - NotFromClick, -} - -// https://html.spec.whatwg.org/multipage/#run-synthetic-click-activation-steps -pub fn synthetic_click_activation( - element: &Element, - ctrl_key: bool, - shift_key: bool, - alt_key: bool, - meta_key: bool, - source: ActivationSource, -) { - // Step 1 - if element.click_in_progress() { - return; - } - // Step 2 - element.set_click_in_progress(true); - // Step 3 - let activatable = element.as_maybe_activatable(); - if let Some(a) = activatable { - a.pre_click_activation(); - } - - // 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 mouse = MouseEvent::new( - &win, - DOMString::from("click"), - EventBubbles::DoesNotBubble, - EventCancelable::NotCancelable, - Some(&win), - 1, - 0, - 0, - 0, - 0, - ctrl_key, - shift_key, - alt_key, - meta_key, - 0, - MouseButton::Left as u16, - None, - None, - ); - let event = mouse.upcast::<Event>(); - if source == ActivationSource::FromClick { - event.set_trusted(false); - } - target.dispatch_event(event); - - // Step 5 - if let Some(a) = activatable { - if event.DefaultPrevented() { - a.canceled_activation(); - } else { - // post click activation - a.activation_behavior(event, target); - } - } - - // Step 6 - element.set_click_in_progress(false); -} |