mirror of
https://github.com/servo/servo.git
synced 2025-07-30 18:50:36 +01:00
Rework ScriptThread::handle_input_event
for behaviour and performance (#36619)
Rework `ScriptThread::handle_input_event` for correct behaviour and better performance 1. Only trigger click event with primary button, according to spec 2. Avoid unnecessary clone of `ConstellationInputEvent` This is a follow up of #36413 Testing: Manually tested. Right mouse won't trigger click event now. Fixes: #35666 cc @jdm @xiaochengh Signed-off-by: Euclid Ye <yezhizhenjiakang@gmail.com>
This commit is contained in:
parent
76ee127af8
commit
990ed8891f
2 changed files with 31 additions and 33 deletions
|
@ -336,11 +336,6 @@ pub struct ScriptThread {
|
||||||
#[no_trace]
|
#[no_trace]
|
||||||
layout_factory: Arc<dyn LayoutFactory>,
|
layout_factory: Arc<dyn LayoutFactory>,
|
||||||
|
|
||||||
// Mouse down button: TO BE REMOVED. Not needed as click event should only
|
|
||||||
// triggered for primary button
|
|
||||||
#[no_trace]
|
|
||||||
mouse_down_button: Cell<Option<MouseButton>>,
|
|
||||||
|
|
||||||
// Mouse down point.
|
// Mouse down point.
|
||||||
// In future, this shall be mouse_down_point for primary button
|
// In future, this shall be mouse_down_point for primary button
|
||||||
#[no_trace]
|
#[no_trace]
|
||||||
|
@ -959,7 +954,6 @@ impl ScriptThread {
|
||||||
gpu_id_hub: Arc::new(IdentityHub::default()),
|
gpu_id_hub: Arc::new(IdentityHub::default()),
|
||||||
inherited_secure_context: state.inherited_secure_context,
|
inherited_secure_context: state.inherited_secure_context,
|
||||||
layout_factory,
|
layout_factory,
|
||||||
mouse_down_button: Cell::new(None),
|
|
||||||
relative_mouse_down_point: Cell::new(Point2D::zero()),
|
relative_mouse_down_point: Cell::new(Point2D::zero()),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -3354,14 +3348,6 @@ impl ScriptThread {
|
||||||
return;
|
return;
|
||||||
};
|
};
|
||||||
|
|
||||||
if let InputEvent::MouseButton(mouse_button_event) = event.event {
|
|
||||||
if mouse_button_event.action == MouseButtonAction::Down {
|
|
||||||
self.mouse_down_button.set(Some(mouse_button_event.button));
|
|
||||||
self.relative_mouse_down_point.set(mouse_button_event.point)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
document.note_pending_input_event(event.clone());
|
|
||||||
|
|
||||||
// Also send a 'click' event with same hit-test result if this is release
|
// Also send a 'click' event with same hit-test result if this is release
|
||||||
|
|
||||||
// MAYBE? TODO: https://developer.mozilla.org/en-US/docs/Web/API/Element/click_event
|
// MAYBE? TODO: https://developer.mozilla.org/en-US/docs/Web/API/Element/click_event
|
||||||
|
@ -3370,30 +3356,42 @@ impl ScriptThread {
|
||||||
// that contained both elements.
|
// that contained both elements.
|
||||||
|
|
||||||
// But spec doesn't specify this https://w3c.github.io/uievents/#event-type-click
|
// But spec doesn't specify this https://w3c.github.io/uievents/#event-type-click
|
||||||
|
// "The click event type MUST be dispatched on the topmost event target indicated by
|
||||||
|
// the pointer, when the user presses down and releases the primary pointer button"
|
||||||
|
|
||||||
// Servo-specific: Trigger if within 10px of the down point
|
// Servo-specific: Trigger if within 10px of the down point
|
||||||
if let InputEvent::MouseButton(mouse_button_event) = event.event {
|
if let InputEvent::MouseButton(mouse_button_event) = event.event {
|
||||||
if let (Some(mouse_down_button), MouseButtonAction::Up) =
|
if let MouseButton::Left = mouse_button_event.button {
|
||||||
(self.mouse_down_button.get(), mouse_button_event.action)
|
match mouse_button_event.action {
|
||||||
{
|
MouseButtonAction::Up => {
|
||||||
let pixel_dist = self.relative_mouse_down_point.get() - mouse_button_event.point;
|
let pixel_dist =
|
||||||
let pixel_dist = (pixel_dist.x * pixel_dist.x + pixel_dist.y * pixel_dist.y).sqrt();
|
self.relative_mouse_down_point.get() - mouse_button_event.point;
|
||||||
if mouse_down_button == mouse_button_event.button &&
|
let pixel_dist =
|
||||||
pixel_dist < 10.0 * document.window().device_pixel_ratio().get()
|
(pixel_dist.x * pixel_dist.x + pixel_dist.y * pixel_dist.y).sqrt();
|
||||||
{
|
if pixel_dist < 10.0 * document.window().device_pixel_ratio().get() {
|
||||||
document.note_pending_input_event(ConstellationInputEvent {
|
document.note_pending_input_event(event.clone());
|
||||||
hit_test_result: event.hit_test_result,
|
document.note_pending_input_event(ConstellationInputEvent {
|
||||||
pressed_mouse_buttons: event.pressed_mouse_buttons,
|
hit_test_result: event.hit_test_result,
|
||||||
active_keyboard_modifiers: event.active_keyboard_modifiers,
|
pressed_mouse_buttons: event.pressed_mouse_buttons,
|
||||||
event: InputEvent::MouseButton(MouseButtonEvent {
|
active_keyboard_modifiers: event.active_keyboard_modifiers,
|
||||||
action: MouseButtonAction::Click,
|
event: InputEvent::MouseButton(MouseButtonEvent {
|
||||||
button: mouse_button_event.button,
|
action: MouseButtonAction::Click,
|
||||||
point: mouse_button_event.point,
|
button: mouse_button_event.button,
|
||||||
}),
|
point: mouse_button_event.point,
|
||||||
});
|
}),
|
||||||
|
});
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
},
|
||||||
|
MouseButtonAction::Down => {
|
||||||
|
self.relative_mouse_down_point.set(mouse_button_event.point)
|
||||||
|
},
|
||||||
|
MouseButtonAction::Click => {},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
document.note_pending_input_event(event);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Handle a "navigate an iframe" message from the constellation.
|
/// Handle a "navigate an iframe" message from the constellation.
|
||||||
|
|
|
@ -51,7 +51,7 @@ pub struct MouseButtonEvent {
|
||||||
pub point: DevicePoint,
|
pub point: DevicePoint,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone, Copy, Debug, Deserialize, PartialEq, Serialize)]
|
#[derive(Clone, Copy, Debug, Deserialize, Serialize)]
|
||||||
pub enum MouseButton {
|
pub enum MouseButton {
|
||||||
Left,
|
Left,
|
||||||
Middle,
|
Middle,
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue