Commit 3aa7a6ea authored by pkotwicz's avatar pkotwicz Committed by Commit bot

Do not show the mouse cursor when the display is rotated in TouchView

BUG=462883
TEST=Manual, see bug

Review URL: https://codereview.chromium.org/971753008

Cr-Commit-Position: refs/heads/master@{#322010}
parent 2b40a33e
...@@ -586,25 +586,34 @@ void DisplayController::UpdateMouseLocationAfterDisplayChange() { ...@@ -586,25 +586,34 @@ void DisplayController::UpdateMouseLocationAfterDisplayChange() {
#if defined(USE_OZONE) #if defined(USE_OZONE)
gfx::Point target_location_in_screen = target_location_in_root; gfx::Point target_location_in_screen = target_location_in_root;
::wm::ConvertPointToScreen(dst_root_window, &target_location_in_screen); ::wm::ConvertPointToScreen(dst_root_window, &target_location_in_screen);
int64 target_display_id = const gfx::Display& target_display =
display_manager->FindDisplayContainingPoint(target_location_in_screen) display_manager->FindDisplayContainingPoint(target_location_in_screen);
.id(); int64 target_display_id = target_display.id();
// Do not move the cursor if the cursor's location did not change. This avoids // Do not move the cursor if the cursor's location did not change. This avoids
// moving (and showing) the cursor on startup. // moving (and showing) the cursor:
// - |cursor_location_in_screen_coords_for_restore_| is checked to ensure that // - At startup.
// the cursor is moved when the cursor's native position does not change but // - When the device is rotated in maximized mode.
// the scale factor or rotation of the display it is on have changed. // |cursor_display_id_for_restore_| is checked to ensure that the cursor is
// - |cursor_display_id_for_restore_| is checked to ensure that the cursor is // moved when the cursor's native position does not change but the display
// moved when the cursor's native position and screen position do not change // that it is on has changed. This occurs when swapping the primary display.
// but the display that it is on has changed. This occurs when swapping the
// primary display.
if (target_location_in_native != if (target_location_in_native !=
cursor_location_in_native_coords_for_restore_ || cursor_location_in_native_coords_for_restore_ ||
target_location_in_screen !=
cursor_location_in_screen_coords_for_restore_ ||
target_display_id != cursor_display_id_for_restore_) { target_display_id != cursor_display_id_for_restore_) {
dst_root_window->MoveCursorTo(target_location_in_root); dst_root_window->MoveCursorTo(target_location_in_root);
} else if (target_location_in_screen !=
cursor_location_in_screen_coords_for_restore_) {
// The cursor's native position did not change but its screen position did
// change. This occurs when the scale factor or the rotation of the display
// that the cursor is on changes.
Shell::GetInstance()->cursor_manager()->SetDisplay(target_display);
// Update the cursor's root location. This ends up dispatching a synthetic
// mouse move. The synthetic mouse move updates the composited cursor's
// location and hover effects. Synthetic mouse moves do not affect the
// cursor's visibility.
dst_root_window->GetHost()->dispatcher()->OnCursorMovedToRootLocation(
target_location_in_root);
} }
#else #else
dst_root_window->MoveCursorTo(target_location_in_root); dst_root_window->MoveCursorTo(target_location_in_root);
......
...@@ -208,7 +208,10 @@ void WindowEventDispatcher::OnHostLostMouseGrab() { ...@@ -208,7 +208,10 @@ void WindowEventDispatcher::OnHostLostMouseGrab() {
void WindowEventDispatcher::OnCursorMovedToRootLocation( void WindowEventDispatcher::OnCursorMovedToRootLocation(
const gfx::Point& root_location) { const gfx::Point& root_location) {
SetLastMouseLocation(window(), root_location); SetLastMouseLocation(window(), root_location);
synthesize_mouse_move_ = false;
// Synthesize a mouse move in case the cursor's location in root coordinates
// changed but its position in WindowTreeHost coordinates did not.
PostSynthesizeMouseMove();
} }
void WindowEventDispatcher::OnPostNotifiedWindowDestroying(Window* window) { void WindowEventDispatcher::OnPostNotifiedWindowDestroying(Window* window) {
......
...@@ -2540,4 +2540,36 @@ TEST_F(WindowEventDispatcherTest, TouchMovesMarkedWhenCausingScroll) { ...@@ -2540,4 +2540,36 @@ TEST_F(WindowEventDispatcherTest, TouchMovesMarkedWhenCausingScroll) {
root_window()->RemovePreTargetHandler(&recorder); root_window()->RemovePreTargetHandler(&recorder);
} }
// OnCursorMovedToRootLocation() is sometimes called instead of
// WindowTreeHost::MoveCursorTo() when the cursor did not move but the
// cursor's position in root coordinates has changed (e.g. when the displays's
// scale factor changed). Test that hover effects are properly updated.
TEST_F(WindowEventDispatcherTest, OnCursorMovedToRootLocationUpdatesHover) {
WindowEventDispatcher* dispatcher = host()->dispatcher();
scoped_ptr<Window> w(CreateNormalWindow(1, root_window(), nullptr));
w->SetBounds(gfx::Rect(20, 20, 20, 20));
w->Show();
// Move the cursor off of |w|.
dispatcher->OnCursorMovedToRootLocation(gfx::Point(100, 100));
EventFilterRecorder recorder;
w->AddPreTargetHandler(&recorder);
dispatcher->OnCursorMovedToRootLocation(gfx::Point(22, 22));
RunAllPendingInMessageLoop();
EXPECT_TRUE(recorder.HasReceivedEvent(ui::ET_MOUSE_ENTERED));
recorder.Reset();
// The cursor should not be over |w| after changing the device scale factor to
// 2x. A ET_MOUSE_EXITED event should have been sent to |w|.
test_screen()->SetDeviceScaleFactor(2.f);
dispatcher->OnCursorMovedToRootLocation(gfx::Point(11, 11));
RunAllPendingInMessageLoop();
EXPECT_TRUE(recorder.HasReceivedEvent(ui::ET_MOUSE_EXITED));
w->RemovePreTargetHandler(&recorder);
}
} // namespace aura } // namespace aura
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