Commit 1ba818ae authored by Xiaoqian Dai's avatar Xiaoqian Dai Committed by Chromium LUCI CQ

capture mode: do not update cursor if we're in cursor updating process.

It's possible that CursorSetter::UpdateCursor() can be called nested so
the cursor can be locked more than once. Do not allow update cursor if
we're in cursor updating process.

Bug: 1152945
Change-Id: I11d3361abf5322f180e9293cb6647490d19380af
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2569980
Commit-Queue: Xiaoqian Dai <xdai@chromium.org>
Reviewed-by: default avatarAhmed Fakhry <afakhry@chromium.org>
Cr-Commit-Position: refs/heads/master@{#833008}
parent 109bc30b
......@@ -271,6 +271,10 @@ class CaptureModeSession::CursorSetter {
if (original_cursor_locked_)
return;
if (in_cursor_update_)
return;
base::AutoReset<bool> auto_reset_in_cursor_update(&in_cursor_update_, true);
const ui::mojom::CursorType current_cursor_type =
cursor_manager_->GetCursor().type();
const ui::mojom::CursorType new_cursor_type = cursor.type();
......@@ -365,6 +369,11 @@ class CaptureModeSession::CursorSetter {
// True if the cursor has reset back to its original cursor. It's to prevent
// Reset() from setting the cursor to |original_cursor_| more than once.
bool was_cursor_reset_to_original_ = true;
// True if the cursor is currently being updated. This is to prevent
// UpdateCursor() is called nestly more than once and the mouse is locked
// multiple times.
bool in_cursor_update_ = false;
};
CaptureModeSession::CaptureModeSession(CaptureModeController* controller)
......
......@@ -1048,6 +1048,26 @@ TEST_F(CaptureModeTest, RegionCursorStates) {
event_generator->MoveMouseTo(gfx::Point(50, 50));
EXPECT_EQ(CursorType::kCell, cursor_manager->GetCursor().type());
// Enter tablet mode, the cursor should be hidden.
TabletModeControllerTestApi tablet_mode_controller_test_api;
// To avoid flaky failures due to mouse devices blocking entering tablet mode,
// we detach all mouse devices. This shouldn't affect testing the cursor
// status.
tablet_mode_controller_test_api.DetachAllMice();
tablet_mode_controller_test_api.EnterTabletMode();
EXPECT_FALSE(cursor_manager->IsCursorVisible());
EXPECT_TRUE(cursor_manager->IsCursorLocked());
// Move mouse but it should still be invisible.
event_generator->MoveMouseTo(gfx::Point(100, 100));
EXPECT_FALSE(cursor_manager->IsCursorVisible());
EXPECT_TRUE(cursor_manager->IsCursorLocked());
// Return to clamshell mode, mouse should appear again.
tablet_mode_controller_test_api.LeaveTabletMode();
EXPECT_TRUE(cursor_manager->IsCursorVisible());
EXPECT_EQ(CursorType::kCell, cursor_manager->GetCursor().type());
// Tests that when exiting capture mode that the cursor is restored to its
// original state.
controller->Stop();
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment