Commit ccfa74c4 authored by Mitsuru Oshima's avatar Mitsuru Oshima Committed by Commit Bot

Do not move the cursor if the cursor is invisible

Do not move the cursor if the cursor is invisible
when display configuration is changed. This was to
make sure that X11's cursor stays inside a display, as
reconfiguring display can potentially move the cursor
to outside of displays.

I think this is no longer a concern, and I'll
replace this with just a notification after merged to 65.

This also fixes the test harness that assumes the cursor
is visible by default but wasn't.

BUG=773479
TEST=covered by unit test. also tested on device.

Change-Id: I7debc957145318352f7ee3c858031091eb2a8e56
Reviewed-on: https://chromium-review.googlesource.com/890056
Commit-Queue: Mitsuru Oshima <oshima@chromium.org>
Reviewed-by: default avatarAhmed Fakhry <afakhry@chromium.org>
Cr-Commit-Position: refs/heads/master@{#533720}
parent b1df7b96
......@@ -469,7 +469,14 @@ void WindowTreeHostManager::UpdateMouseLocationAfterDisplayChange() {
if (target_location_in_native !=
cursor_location_in_native_coords_for_restore_ ||
target_display_id != cursor_display_id_for_restore_) {
// TODO(oshima): Moving the cursor was necessary for x11, but We
// probably do not have to do this any more on ozone. Consider
// just notifying the cursor location change.
if (Shell::Get()->cursor_manager() &&
Shell::Get()->cursor_manager()->IsCursorVisible()) {
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
......
......@@ -1571,6 +1571,33 @@ TEST_F(WindowTreeHostManagerTest, UpdateMouseLocationAfterDisplayChange) {
EXPECT_EQ("450,10", env->last_mouse_location().ToString());
}
TEST_F(WindowTreeHostManagerTest,
DontUpdateInvisibleCursorLocationAfterDisplayChange) {
UpdateDisplay("500x300");
aura::Window::Windows root_windows = Shell::GetAllRootWindows();
aura::Env* env = aura::Env::GetInstance();
ui::test::EventGenerator generator(root_windows[0]);
// Logical cursor location is updated to keep the same physical location.
generator.MoveMouseToInHost(350, 150);
EXPECT_EQ("350,150", env->last_mouse_location().ToString());
UpdateDisplay("300x500/r");
EXPECT_EQ("250,150", env->last_mouse_location().ToString());
// Logical cursor location change shouldn't change when the cursor isn't
// visible.
UpdateDisplay("500x300");
generator.MoveMouseToInHost(350, 150);
EXPECT_EQ("350,150", env->last_mouse_location().ToString());
Shell::Get()->cursor_manager()->HideCursor();
UpdateDisplay("300x500/r");
EXPECT_EQ("350,150", env->last_mouse_location().ToString());
}
TEST_F(WindowTreeHostManagerTest,
UpdateMouseLocationAfterDisplayChange_2ndOnLeft) {
// Set the 2nd display on the left.
......
......@@ -174,6 +174,12 @@ void AshTestHelper::SetUp(bool start_session, bool provide_local_state) {
std::unique_ptr<aura::InputStateLookup>());
Shell* shell = Shell::Get();
// Cursor is visible by default in tests.
// CursorManager is null on MASH.
if (shell->cursor_manager())
shell->cursor_manager()->ShowCursor();
if (provide_local_state) {
auto pref_service = std::make_unique<TestingPrefServiceSimple>();
Shell::RegisterLocalStatePrefs(pref_service->registry());
......
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