mirror of
https://github.com/servo/servo.git
synced 2025-07-22 23:03:42 +01:00
Auto merge of #23770 - matharumanpreet00:update_cursor_on_scroll, r=paulrouget
track and update cursor while scrolling <!-- Please describe your changes on the following line: --> This PR follows PR #23313 to fix the issue #12604 by adding a field `cursor_pos: DevicePoint` to `IOCompositor` and adding a `update_cursor()` method. This is based on the improvements suggested by @paulrouget in this [feedback](https://github.com/servo/servo/pull/23313#issuecomment-489017975) comment. This is my first time contributing to open source, i would love any feedback. --- <!-- Thank you for contributing to Servo! Please replace each `[ ]` by `[X]` when the step is complete, and replace `___` with appropriate data: --> - [X] `./mach build -d` does not report any errors - [X] `./mach test-tidy` does not report any errors - [X] These changes fix #12604 (GitHub issue number if applicable) <!-- Either: --> - [ ] There are tests for these changes OR - [X] These changes do not require tests because they aren't testable, as discussed in the comments on #12604 <!-- Also, please make sure that "Allow edits from maintainers" checkbox is checked, so that we can help you if you get stuck somewhere along the way.--> <!-- Pull requests that do not address these steps are welcome, but they will require additional verification as part of the review process. --> <!-- Reviewable:start --> --- This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/servo/23770) <!-- Reviewable:end -->
This commit is contained in:
commit
c57e9bb938
1 changed files with 20 additions and 10 deletions
|
@ -196,6 +196,9 @@ pub struct IOCompositor<Window: WindowMethods + ?Sized> {
|
|||
/// Current mouse cursor.
|
||||
cursor: Cursor,
|
||||
|
||||
/// Current cursor position.
|
||||
cursor_pos: DevicePoint,
|
||||
|
||||
output_file: Option<String>,
|
||||
|
||||
is_running_problem_test: bool,
|
||||
|
@ -318,6 +321,7 @@ impl<Window: WindowMethods + ?Sized> IOCompositor<Window> {
|
|||
webxr_main_thread: state.webxr_main_thread,
|
||||
pending_paint_metrics: HashMap::new(),
|
||||
cursor: Cursor::None,
|
||||
cursor_pos: DevicePoint::new(0.0, 0.0),
|
||||
output_file,
|
||||
is_running_problem_test,
|
||||
exit_after_load,
|
||||
|
@ -359,6 +363,20 @@ impl<Window: WindowMethods + ?Sized> IOCompositor<Window> {
|
|||
self.webrender.deinit();
|
||||
}
|
||||
|
||||
pub fn update_cursor(&mut self, hit_test_results: HitTestResult) {
|
||||
if let Some(item) = hit_test_results.items.first() {
|
||||
if let Some(cursor) = Cursor::from_u8(item.tag.1 as _) {
|
||||
if cursor != self.cursor {
|
||||
self.cursor = cursor;
|
||||
let msg = ConstellationMsg::SetCursor(cursor);
|
||||
if let Err(e) = self.constellation_chan.send(msg) {
|
||||
warn!("Sending event to constellation failed ({:?}).", e);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub fn maybe_start_shutting_down(&mut self) {
|
||||
if self.shutdown_state == ShutdownState::NotShuttingDown {
|
||||
debug!("Shutting down the constellation for WindowEvent::Quit");
|
||||
|
@ -479,6 +497,7 @@ impl<Window: WindowMethods + ?Sized> IOCompositor<Window> {
|
|||
|
||||
(Msg::NewScrollFrameReady(recomposite_needed), ShutdownState::NotShuttingDown) => {
|
||||
self.waiting_for_results_of_scroll = false;
|
||||
self.update_cursor(self.hit_test_at_point(self.cursor_pos));
|
||||
if recomposite_needed {
|
||||
self.composition_request = CompositionRequest::CompositeNow(
|
||||
CompositingReason::NewWebRenderScrollFrame,
|
||||
|
@ -762,16 +781,7 @@ impl<Window: WindowMethods + ?Sized> IOCompositor<Window> {
|
|||
if let Err(e) = self.constellation_chan.send(msg) {
|
||||
warn!("Sending event to constellation failed ({:?}).", e);
|
||||
}
|
||||
|
||||
if let Some(cursor) = Cursor::from_u8(item.tag.1 as _) {
|
||||
if cursor != self.cursor {
|
||||
self.cursor = cursor;
|
||||
let msg = ConstellationMsg::SetCursor(cursor);
|
||||
if let Err(e) = self.constellation_chan.send(msg) {
|
||||
warn!("Sending event to constellation failed ({:?}).", e);
|
||||
}
|
||||
}
|
||||
}
|
||||
self.update_cursor(results);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue