Skip to content

Commit

Permalink
Ensure HideCursor is called when touch events are handled
Browse files Browse the repository at this point in the history
It's possible for the mouse cursor to get wedged into the hidden state
if the cursor is hidden when the CursorManager is destroyed (i.e. all
toplevel windows are closed). When a background extension is installed
the process/thread sticks around until a new browser window is launched.
The process-static CursorManager::last_cursor_visibility_state_ is used
to seed the initial visibility state of the cursor of the new
CursorManager that is created along with the new browser window. However
last_cursor_visibility_state_ does not currently get set to false when
the cursor is hidden due to processing touch events (there are no calls
to HideCursor).

This change adds a call to SetCursorVisibilityOnEvent(false) when
processing touch pressed events, to keep this variable in sync with
reality. When the new browser window is launched, it correctly
initializes the cursor state so that subsequent mouse moves will actually
show the cursor.

R=sadrul@chromium.org

Bug: 795566
Change-Id: I501083f6898fab863e34625cac468a8701a575f6
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2223990
Reviewed-by: Sadrul Chowdhury <sadrul@chromium.org>
Commit-Queue: Daniel Libby <dlibby@microsoft.com>
Cr-Commit-Position: refs/heads/master@{#773618}
  • Loading branch information
dlibby- authored and Commit Bot committed Jun 1, 2020
1 parent 783f49e commit 952f059
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
4 changes: 3 additions & 1 deletion ui/wm/core/compound_event_filter.cc
Original file line number Diff line number Diff line change
Expand Up @@ -229,8 +229,10 @@ void CompoundEventFilter::OnTouchEvent(ui::TouchEvent* event) {
ShouldHideCursorOnTouch(*event)) {
aura::Window* target = static_cast<aura::Window*>(event->target());
DCHECK(target);
if (!aura::Env::GetInstance()->IsMouseButtonDown())
if (!aura::Env::GetInstance()->IsMouseButtonDown()) {
SetMouseEventsEnableStateOnEvent(target, event, false);
SetCursorVisibilityOnEvent(target, event, false);
}
}
}

Expand Down
6 changes: 6 additions & 0 deletions ui/wm/core/compound_event_filter_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -127,36 +127,42 @@ TEST_F(CompoundEventFilterTest, TouchHidesCursor) {
gfx::Point(10, 10), ui::EventTimeForNow(), 0, 0);
DispatchEventUsingWindowDispatcher(&mouse0);
EXPECT_TRUE(cursor_client.IsMouseEventsEnabled());
EXPECT_TRUE(cursor_client.IsCursorVisible());

// This press is required for the GestureRecognizer to associate a target
// with kTouchId
ui::TouchEvent press0(ui::ET_TOUCH_PRESSED, gfx::Point(90, 90), GetTime(),
ui::PointerDetails(ui::EventPointerType::kTouch, 1));
DispatchEventUsingWindowDispatcher(&press0);
EXPECT_FALSE(cursor_client.IsMouseEventsEnabled());
EXPECT_FALSE(cursor_client.IsCursorVisible());

ui::TouchEvent move(ui::ET_TOUCH_MOVED, gfx::Point(10, 10), GetTime(),
ui::PointerDetails(ui::EventPointerType::kTouch, 1));
DispatchEventUsingWindowDispatcher(&move);
EXPECT_FALSE(cursor_client.IsMouseEventsEnabled());
EXPECT_FALSE(cursor_client.IsCursorVisible());

ui::TouchEvent release(ui::ET_TOUCH_RELEASED, gfx::Point(10, 10), GetTime(),
ui::PointerDetails(ui::EventPointerType::kTouch, 1));
DispatchEventUsingWindowDispatcher(&release);
EXPECT_FALSE(cursor_client.IsMouseEventsEnabled());
EXPECT_FALSE(cursor_client.IsCursorVisible());

ui::MouseEvent mouse1(ui::ET_MOUSE_MOVED, gfx::Point(10, 10),
gfx::Point(10, 10), ui::EventTimeForNow(), 0, 0);
// Move the cursor again. The cursor should be visible.
DispatchEventUsingWindowDispatcher(&mouse1);
EXPECT_TRUE(cursor_client.IsMouseEventsEnabled());
EXPECT_TRUE(cursor_client.IsCursorVisible());

// Now activate the window and press on it again.
ui::TouchEvent press1(ui::ET_TOUCH_PRESSED, gfx::Point(90, 90), GetTime(),
ui::PointerDetails(ui::EventPointerType::kTouch, 1));
GetActivationClient(root_window())->ActivateWindow(window.get());
DispatchEventUsingWindowDispatcher(&press1);
EXPECT_FALSE(cursor_client.IsMouseEventsEnabled());
EXPECT_FALSE(cursor_client.IsCursorVisible());
aura::Env::GetInstance()->RemovePreTargetHandler(compound_filter.get());
}
#endif // defined(OS_CHROMEOS) || defined(OS_WIN)
Expand Down

0 comments on commit 952f059

Please sign in to comment.