mirror of
https://github.com/servo/servo.git
synced 2025-08-05 13:40:08 +01:00
Remove duplication in dispatch_pending_point_input_events (#37426)
Follow up to: https://github.com/servo/servo/pull/37285#pullrequestreview-2916829212, this PR removes duplicate code. cc: @xiaochengh --------- Signed-off-by: batu_hoang <longvatrong111@gmail.com>
This commit is contained in:
parent
5d42ab05fb
commit
810c0e6891
2 changed files with 46 additions and 50 deletions
|
@ -658,6 +658,7 @@ impl IOCompositor {
|
||||||
webview_renderer.dispatch_point_input_event(
|
webview_renderer.dispatch_point_input_event(
|
||||||
InputEvent::MouseButton(MouseButtonEvent::new(action, button, point))
|
InputEvent::MouseButton(MouseButtonEvent::new(action, button, point))
|
||||||
.with_webdriver_message_id(message_id),
|
.with_webdriver_message_id(message_id),
|
||||||
|
false,
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
|
|
||||||
|
@ -671,6 +672,7 @@ impl IOCompositor {
|
||||||
webview_renderer.dispatch_point_input_event(
|
webview_renderer.dispatch_point_input_event(
|
||||||
InputEvent::MouseMove(MouseMoveEvent::new(point))
|
InputEvent::MouseMove(MouseMoveEvent::new(point))
|
||||||
.with_webdriver_message_id(message_id),
|
.with_webdriver_message_id(message_id),
|
||||||
|
false,
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
|
|
||||||
|
@ -699,6 +701,7 @@ impl IOCompositor {
|
||||||
webview_renderer.dispatch_point_input_event(
|
webview_renderer.dispatch_point_input_event(
|
||||||
InputEvent::Wheel(WheelEvent::new(delta, point))
|
InputEvent::Wheel(WheelEvent::new(delta, point))
|
||||||
.with_webdriver_message_id(message_id),
|
.with_webdriver_message_id(message_id),
|
||||||
|
false,
|
||||||
);
|
);
|
||||||
webview_renderer.on_webdriver_wheel_action(scroll_delta, point);
|
webview_renderer.on_webdriver_wheel_action(scroll_delta, point);
|
||||||
},
|
},
|
||||||
|
|
|
@ -315,7 +315,14 @@ impl WebViewRenderer {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn dispatch_point_input_event(&mut self, mut event: InputEvent) -> bool {
|
/// This function performs hit testing for point input events
|
||||||
|
/// before dispatching them to the constellation.
|
||||||
|
/// Return `true` if the event was successfully dispatched.
|
||||||
|
///
|
||||||
|
/// We may want to retry the event if the hit test failed due to
|
||||||
|
/// epoch mismatch. To avoid infinite loops, we only retry once.
|
||||||
|
/// The `retried` parameter indicates whether the event has already been retried.
|
||||||
|
pub(crate) fn dispatch_point_input_event(&self, mut event: InputEvent, retried: bool) -> bool {
|
||||||
// Events that do not need to do hit testing are sent directly to the
|
// Events that do not need to do hit testing are sent directly to the
|
||||||
// constellation to filter down.
|
// constellation to filter down.
|
||||||
let Some(point) = event.point() else {
|
let Some(point) = event.point() else {
|
||||||
|
@ -324,7 +331,9 @@ impl WebViewRenderer {
|
||||||
|
|
||||||
// Delay the event if the epoch is not synchronized yet (new frame is not ready),
|
// Delay the event if the epoch is not synchronized yet (new frame is not ready),
|
||||||
// or hit test result would fail and the event is rejected anyway.
|
// or hit test result would fail and the event is rejected anyway.
|
||||||
if !self.webrender_frame_ready.get() || !self.pending_point_input_events.borrow().is_empty()
|
if !(self.webrender_frame_ready.get() &&
|
||||||
|
self.pending_point_input_events.borrow().is_empty() &&
|
||||||
|
retried)
|
||||||
{
|
{
|
||||||
self.pending_point_input_events
|
self.pending_point_input_events
|
||||||
.borrow_mut()
|
.borrow_mut()
|
||||||
|
@ -341,9 +350,12 @@ impl WebViewRenderer {
|
||||||
{
|
{
|
||||||
Ok(hit_test_results) => hit_test_results,
|
Ok(hit_test_results) => hit_test_results,
|
||||||
Err(HitTestError::EpochMismatch) => {
|
Err(HitTestError::EpochMismatch) => {
|
||||||
self.pending_point_input_events
|
if !retried {
|
||||||
.borrow_mut()
|
self.pending_point_input_events
|
||||||
.push_back(event);
|
.borrow_mut()
|
||||||
|
.push_back(event);
|
||||||
|
}
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
},
|
},
|
||||||
_ => {
|
_ => {
|
||||||
|
@ -371,42 +383,21 @@ impl WebViewRenderer {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: This function duplicates a lot of `dispatch_point_input_event.
|
|
||||||
// Perhaps it should just be called here instead.
|
|
||||||
pub(crate) fn dispatch_pending_point_input_events(&self) {
|
pub(crate) fn dispatch_pending_point_input_events(&self) {
|
||||||
while let Some(mut event) = self.pending_point_input_events.borrow_mut().pop_front() {
|
loop {
|
||||||
// Events that do not need to do hit testing are sent directly to the
|
let event = {
|
||||||
// constellation to filter down.
|
let mut pending = self.pending_point_input_events.borrow_mut();
|
||||||
let Some(point) = event.point() else {
|
pending.pop_front()
|
||||||
continue;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
// If we can't find a pipeline to send this event to, we cannot continue.
|
let event = match event {
|
||||||
let get_pipeline_details = |pipeline_id| self.pipelines.get(&pipeline_id);
|
Some(ev) => ev,
|
||||||
let Ok(result) = self
|
None => break,
|
||||||
.global
|
};
|
||||||
.borrow()
|
// We don't need to process more if 1 event failed to dispatch.
|
||||||
.hit_test_at_point(point, get_pipeline_details)
|
// All events are point events
|
||||||
else {
|
if !self.dispatch_point_input_event(event, true) {
|
||||||
// Don't need to process pending input events in this frame any more.
|
|
||||||
// TODO: Add multiple retry later if needed.
|
|
||||||
return;
|
return;
|
||||||
};
|
|
||||||
|
|
||||||
match event {
|
|
||||||
InputEvent::Touch(ref mut touch_event) => {
|
|
||||||
touch_event.init_sequence_id(self.touch_handler.current_sequence_id);
|
|
||||||
},
|
|
||||||
InputEvent::MouseButton(_) | InputEvent::MouseMove(_) | InputEvent::Wheel(_) => {
|
|
||||||
self.global.borrow_mut().update_cursor(point, &result);
|
|
||||||
},
|
|
||||||
_ => unreachable!("Unexpected input event type: {event:?}"),
|
|
||||||
}
|
|
||||||
|
|
||||||
if let Err(error) = self.global.borrow().constellation_sender.send(
|
|
||||||
EmbedderToConstellationMessage::ForwardInputEvent(self.id, event, Some(result)),
|
|
||||||
) {
|
|
||||||
warn!("Sending event to constellation failed ({error:?}).");
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -477,11 +468,11 @@ impl WebViewRenderer {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
self.dispatch_point_input_event(event);
|
self.dispatch_point_input_event(event, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn send_touch_event(&mut self, event: TouchEvent) -> bool {
|
fn send_touch_event(&mut self, event: TouchEvent) -> bool {
|
||||||
self.dispatch_point_input_event(InputEvent::Touch(event))
|
self.dispatch_point_input_event(InputEvent::Touch(event), false)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn on_touch_event(&mut self, event: TouchEvent) {
|
pub(crate) fn on_touch_event(&mut self, event: TouchEvent) {
|
||||||
|
@ -745,17 +736,19 @@ impl WebViewRenderer {
|
||||||
/// <http://w3c.github.io/touch-events/#mouse-events>
|
/// <http://w3c.github.io/touch-events/#mouse-events>
|
||||||
fn simulate_mouse_click(&mut self, point: DevicePoint) {
|
fn simulate_mouse_click(&mut self, point: DevicePoint) {
|
||||||
let button = MouseButton::Left;
|
let button = MouseButton::Left;
|
||||||
self.dispatch_point_input_event(InputEvent::MouseMove(MouseMoveEvent::new(point)));
|
self.dispatch_point_input_event(InputEvent::MouseMove(MouseMoveEvent::new(point)), false);
|
||||||
self.dispatch_point_input_event(InputEvent::MouseButton(MouseButtonEvent::new(
|
self.dispatch_point_input_event(
|
||||||
MouseButtonAction::Down,
|
InputEvent::MouseButton(MouseButtonEvent::new(
|
||||||
button,
|
MouseButtonAction::Down,
|
||||||
point,
|
button,
|
||||||
)));
|
point,
|
||||||
self.dispatch_point_input_event(InputEvent::MouseButton(MouseButtonEvent::new(
|
)),
|
||||||
MouseButtonAction::Up,
|
false,
|
||||||
button,
|
);
|
||||||
point,
|
self.dispatch_point_input_event(
|
||||||
)));
|
InputEvent::MouseButton(MouseButtonEvent::new(MouseButtonAction::Up, button, point)),
|
||||||
|
false,
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn notify_scroll_event(
|
pub(crate) fn notify_scroll_event(
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue