mirror of
https://github.com/servo/servo.git
synced 2025-08-03 12:40:06 +01:00
libservo: Allow embedders to signal when the cursor has left the WebView
(#37317)
Currently, the hover state will stay when the mouse moves out of the webview, this PR fixes it Testing: Hover on the `About` on servo.org, and then move the mouse up to the browser UI, see the hover state resets Signed-off-by: Tony <legendmastertony@gmail.com>
This commit is contained in:
parent
0896341285
commit
b9fcc95992
7 changed files with 125 additions and 27 deletions
|
@ -360,21 +360,33 @@ impl ServoRenderer {
|
|||
.send_transaction(self.webrender_document, transaction);
|
||||
}
|
||||
|
||||
pub(crate) fn update_cursor(&mut self, pos: DevicePoint, result: &CompositorHitTestResult) {
|
||||
self.cursor_pos = pos;
|
||||
|
||||
let cursor = match result.cursor {
|
||||
Some(cursor) if cursor != self.cursor => cursor,
|
||||
_ => return,
|
||||
};
|
||||
|
||||
let Some(webview_id) = self
|
||||
pub(crate) fn update_cursor_from_hittest(
|
||||
&mut self,
|
||||
pos: DevicePoint,
|
||||
result: &CompositorHitTestResult,
|
||||
) {
|
||||
if let Some(webview_id) = self
|
||||
.pipeline_to_webview_map
|
||||
.get(&result.pipeline_id)
|
||||
.cloned()
|
||||
else {
|
||||
.copied()
|
||||
{
|
||||
self.update_cursor(pos, webview_id, result.cursor);
|
||||
} else {
|
||||
warn!("Couldn't update cursor for non-WebView-associated pipeline");
|
||||
return;
|
||||
};
|
||||
}
|
||||
|
||||
pub(crate) fn update_cursor(
|
||||
&mut self,
|
||||
pos: DevicePoint,
|
||||
webview_id: WebViewId,
|
||||
cursor: Option<Cursor>,
|
||||
) {
|
||||
self.cursor_pos = pos;
|
||||
|
||||
let cursor = match cursor {
|
||||
Some(cursor) if cursor != self.cursor => cursor,
|
||||
_ => return,
|
||||
};
|
||||
|
||||
self.cursor = cursor;
|
||||
|
@ -631,7 +643,9 @@ impl IOCompositor {
|
|||
.borrow()
|
||||
.hit_test_at_point(point, details_for_pipeline);
|
||||
if let Ok(result) = result {
|
||||
self.global.borrow_mut().update_cursor(point, &result);
|
||||
self.global
|
||||
.borrow_mut()
|
||||
.update_cursor_from_hittest(point, &result);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -385,8 +385,13 @@ impl WebViewRenderer {
|
|||
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);
|
||||
InputEvent::MouseButton(_) |
|
||||
InputEvent::MouseLeave(_) |
|
||||
InputEvent::MouseMove(_) |
|
||||
InputEvent::Wheel(_) => {
|
||||
self.global
|
||||
.borrow_mut()
|
||||
.update_cursor_from_hittest(point, &result);
|
||||
},
|
||||
_ => unreachable!("Unexpected input event type: {event:?}"),
|
||||
}
|
||||
|
@ -428,7 +433,9 @@ impl WebViewRenderer {
|
|||
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);
|
||||
self.global
|
||||
.borrow_mut()
|
||||
.update_cursor_from_hittest(point, &result);
|
||||
},
|
||||
_ => unreachable!("Unexpected input event type: {event:?}"),
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue