mirror of
https://github.com/servo/servo.git
synced 2025-08-03 12:40:06 +01:00
Revert "Remove duplication in dispatch_pending_point_input_events" (#37482)
Revert "Remove duplication in dispatch_pending_point_input_events" (https://github.com/servo/servo/pull/37426) which causes a serious bug. Signed-off-by: batu_hoang <longvatrong111@gmail.com>
This commit is contained in:
parent
3b73b83a9f
commit
1044f8fbf5
2 changed files with 50 additions and 46 deletions
|
@ -658,7 +658,6 @@ 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,
|
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
|
|
||||||
|
@ -672,7 +671,6 @@ 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,
|
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
|
|
||||||
|
@ -701,7 +699,6 @@ 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,14 +315,7 @@ impl WebViewRenderer {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// This function performs hit testing for point input events
|
pub(crate) fn dispatch_point_input_event(&mut self, mut event: InputEvent) -> bool {
|
||||||
/// 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 {
|
||||||
|
@ -331,9 +324,7 @@ 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() &&
|
if !self.webrender_frame_ready.get() || !self.pending_point_input_events.borrow().is_empty()
|
||||||
self.pending_point_input_events.borrow().is_empty() &&
|
|
||||||
retried)
|
|
||||||
{
|
{
|
||||||
self.pending_point_input_events
|
self.pending_point_input_events
|
||||||
.borrow_mut()
|
.borrow_mut()
|
||||||
|
@ -350,12 +341,9 @@ impl WebViewRenderer {
|
||||||
{
|
{
|
||||||
Ok(hit_test_results) => hit_test_results,
|
Ok(hit_test_results) => hit_test_results,
|
||||||
Err(HitTestError::EpochMismatch) => {
|
Err(HitTestError::EpochMismatch) => {
|
||||||
if !retried {
|
self.pending_point_input_events
|
||||||
self.pending_point_input_events
|
.borrow_mut()
|
||||||
.borrow_mut()
|
.push_back(event);
|
||||||
.push_back(event);
|
|
||||||
}
|
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
},
|
},
|
||||||
_ => {
|
_ => {
|
||||||
|
@ -383,21 +371,42 @@ 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) {
|
||||||
loop {
|
while let Some(mut event) = self.pending_point_input_events.borrow_mut().pop_front() {
|
||||||
let event = {
|
// Events that do not need to do hit testing are sent directly to the
|
||||||
let mut pending = self.pending_point_input_events.borrow_mut();
|
// constellation to filter down.
|
||||||
pending.pop_front()
|
let Some(point) = event.point() else {
|
||||||
|
continue;
|
||||||
};
|
};
|
||||||
|
|
||||||
let event = match event {
|
// If we can't find a pipeline to send this event to, we cannot continue.
|
||||||
Some(ev) => ev,
|
let get_pipeline_details = |pipeline_id| self.pipelines.get(&pipeline_id);
|
||||||
None => break,
|
let Ok(result) = self
|
||||||
};
|
.global
|
||||||
// We don't need to process more if 1 event failed to dispatch.
|
.borrow()
|
||||||
// All events are point events
|
.hit_test_at_point(point, get_pipeline_details)
|
||||||
if !self.dispatch_point_input_event(event, true) {
|
else {
|
||||||
|
// 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:?}).");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -468,11 +477,11 @@ impl WebViewRenderer {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
self.dispatch_point_input_event(event, false);
|
self.dispatch_point_input_event(event);
|
||||||
}
|
}
|
||||||
|
|
||||||
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), false)
|
self.dispatch_point_input_event(InputEvent::Touch(event))
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn on_touch_event(&mut self, event: TouchEvent) {
|
pub(crate) fn on_touch_event(&mut self, event: TouchEvent) {
|
||||||
|
@ -736,19 +745,17 @@ 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)), false);
|
self.dispatch_point_input_event(InputEvent::MouseMove(MouseMoveEvent::new(point)));
|
||||||
self.dispatch_point_input_event(
|
self.dispatch_point_input_event(InputEvent::MouseButton(MouseButtonEvent::new(
|
||||||
InputEvent::MouseButton(MouseButtonEvent::new(
|
MouseButtonAction::Down,
|
||||||
MouseButtonAction::Down,
|
button,
|
||||||
button,
|
point,
|
||||||
point,
|
)));
|
||||||
)),
|
self.dispatch_point_input_event(InputEvent::MouseButton(MouseButtonEvent::new(
|
||||||
false,
|
MouseButtonAction::Up,
|
||||||
);
|
button,
|
||||||
self.dispatch_point_input_event(
|
point,
|
||||||
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