mirror of
https://github.com/servo/servo.git
synced 2025-08-06 14:10:11 +01:00
Call synthetic_click_activation for all clicks
Moved synthetic_click_actiavtion out of Activatable trait so it can be called by all elements (not just activatable). Calls appropriately from click. Also updates the isdisabled check in click to check for all types of elements
This commit is contained in:
parent
57a96ece0c
commit
d6678a184b
9 changed files with 95 additions and 66 deletions
|
@ -29,55 +29,70 @@ pub trait Activatable {
|
|||
|
||||
// https://html.spec.whatwg.org/multipage/#implicit-submission
|
||||
fn implicit_submission(&self, ctrlKey: bool, shiftKey: bool, altKey: bool, metaKey: bool);
|
||||
}
|
||||
|
||||
// https://html.spec.whatwg.org/multipage/#run-synthetic-click-activation-steps
|
||||
fn synthetic_click_activation(&self,
|
||||
/// 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,
|
||||
ctrlKey: bool,
|
||||
shiftKey: bool,
|
||||
altKey: bool,
|
||||
metaKey: bool) {
|
||||
let element = self.as_element();
|
||||
// Step 1
|
||||
if element.click_in_progress() {
|
||||
return;
|
||||
}
|
||||
// Step 2
|
||||
element.set_click_in_progress(true);
|
||||
// Step 3
|
||||
self.pre_click_activation();
|
||||
metaKey: 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();
|
||||
let mouse = MouseEvent::new(win.r(),
|
||||
DOMString::from("click"),
|
||||
EventBubbles::DoesNotBubble,
|
||||
EventCancelable::NotCancelable,
|
||||
Some(win.r()),
|
||||
1,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
ctrlKey,
|
||||
shiftKey,
|
||||
altKey,
|
||||
metaKey,
|
||||
0,
|
||||
None);
|
||||
let event = mouse.upcast::<Event>();
|
||||
event.fire(target);
|
||||
// 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.r(),
|
||||
DOMString::from("click"),
|
||||
EventBubbles::DoesNotBubble,
|
||||
EventCancelable::NotCancelable,
|
||||
Some(win.r()),
|
||||
1,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
ctrlKey,
|
||||
shiftKey,
|
||||
altKey,
|
||||
metaKey,
|
||||
0,
|
||||
None);
|
||||
let event = mouse.upcast::<Event>();
|
||||
if source == ActivationSource::FromClick {
|
||||
event.set_trusted(false);
|
||||
}
|
||||
target.dispatch_event(event);
|
||||
|
||||
// Step 5
|
||||
// Step 5
|
||||
if let Some(a) = activatable {
|
||||
if event.DefaultPrevented() {
|
||||
self.canceled_activation();
|
||||
a.canceled_activation();
|
||||
} else {
|
||||
// post click activation
|
||||
self.activation_behavior(event, target);
|
||||
a.activation_behavior(event, target);
|
||||
}
|
||||
|
||||
// Step 6
|
||||
element.set_click_in_progress(false);
|
||||
}
|
||||
|
||||
// Step 6
|
||||
element.set_click_in_progress(false);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue