Commit 04bbbd55 authored by pkotwicz's avatar pkotwicz Committed by Commit bot

Fix initial hiding and centering cursor on ChromeOS

DisplayController::UpdateMouseLocationAfterDisplayChange() is now called during
startup:
- In Ozone once a channel to the GPU has been established
- In X11 as a result of
  DisplayChangeObserver::OnTouchscreenDeviceConfigurationChanged()

Moving the mouse on startup:
- Causes side effects such as mouse hover
- Causes a mouse event to be generated which causes
  CompoundEventFilter::SetCursorVisibilityOnEvent() to show the
  mouse cursor.

This CL makes DisplayController::UpdateMouseLocationAfterDisplayChange() move the
mouse only if necessary.

BUG=450860
TEST=Manual, see bug

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

Cr-Commit-Position: refs/heads/master@{#318708}
parent 131c261d
...@@ -39,6 +39,7 @@ ...@@ -39,6 +39,7 @@
#include "ui/compositor/compositor_vsync_manager.h" #include "ui/compositor/compositor_vsync_manager.h"
#include "ui/gfx/display.h" #include "ui/gfx/display.h"
#include "ui/gfx/screen.h" #include "ui/gfx/screen.h"
#include "ui/wm/core/coordinate_conversion.h"
#include "ui/wm/public/activation_client.h" #include "ui/wm/public/activation_client.h"
#if defined(OS_CHROMEOS) #if defined(OS_CHROMEOS)
...@@ -266,6 +267,7 @@ DisplayController::DisplayController() ...@@ -266,6 +267,7 @@ DisplayController::DisplayController()
focus_activation_store_(new FocusActivationStore()), focus_activation_store_(new FocusActivationStore()),
cursor_window_controller_(new CursorWindowController()), cursor_window_controller_(new CursorWindowController()),
mirror_window_controller_(new MirrorWindowController()), mirror_window_controller_(new MirrorWindowController()),
cursor_display_id_for_restore_(gfx::Display::kInvalidDisplayID),
weak_ptr_factory_(this) { weak_ptr_factory_(this) {
#if defined(OS_CHROMEOS) #if defined(OS_CHROMEOS)
if (base::SysInfo::IsRunningOnChromeOS()) if (base::SysInfo::IsRunningOnChromeOS())
...@@ -569,18 +571,44 @@ void DisplayController::EnsurePointerInDisplays() { ...@@ -569,18 +571,44 @@ void DisplayController::EnsurePointerInDisplays() {
if (closest_distance_squared < 0 || if (closest_distance_squared < 0 ||
closest_distance_squared > distance_squared) { closest_distance_squared > distance_squared) {
aura::Window* root_window = GetRootWindowForDisplayId(display.id()); aura::Window* root_window = GetRootWindowForDisplayId(display.id());
aura::client::ScreenPositionClient* client = ::wm::ConvertPointFromScreen(root_window, &center);
aura::client::GetScreenPositionClient(root_window);
client->ConvertPointFromScreen(root_window, &center);
root_window->GetHost()->ConvertPointToNativeScreen(&center); root_window->GetHost()->ConvertPointToNativeScreen(&center);
dst_root_window = root_window; dst_root_window = root_window;
target_location_in_native = center; target_location_in_native = center;
closest_distance_squared = distance_squared; closest_distance_squared = distance_squared;
} }
} }
gfx::Point target_location_in_root = target_location_in_native;
dst_root_window->GetHost()->ConvertPointFromNativeScreen( dst_root_window->GetHost()->ConvertPointFromNativeScreen(
&target_location_in_native); &target_location_in_root);
dst_root_window->MoveCursorTo(target_location_in_native);
#if defined(USE_OZONE)
gfx::Point target_location_in_screen = target_location_in_root;
::wm::ConvertPointToScreen(dst_root_window, &target_location_in_screen);
int64 target_display_id =
display_manager->FindDisplayContainingPoint(target_location_in_screen)
.id();
// Do not move the cursor if the cursor's location did not change. This avoids
// moving (and showing) the cursor on startup.
// - |cursor_location_in_screen_coords_for_restore_| is checked to ensure that
// the cursor is moved when the cursor's native position does not change but
// 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
// moved when the cursor's native position and screen position do not change
// but the display that it is on has changed. This occurs when swapping the
// primary display.
if (target_location_in_native !=
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_) {
dst_root_window->MoveCursorTo(target_location_in_root);
}
#else
dst_root_window->MoveCursorTo(target_location_in_root);
#endif
} }
bool DisplayController::UpdateWorkAreaOfDisplayNearestWindow( bool DisplayController::UpdateWorkAreaOfDisplayNearestWindow(
...@@ -713,14 +741,16 @@ void DisplayController::PreDisplayConfigurationChange(bool clear_focus) { ...@@ -713,14 +741,16 @@ void DisplayController::PreDisplayConfigurationChange(bool clear_focus) {
focus_activation_store_->Store(clear_focus); focus_activation_store_->Store(clear_focus);
gfx::Screen* screen = Shell::GetScreen(); gfx::Screen* screen = Shell::GetScreen();
gfx::Point point_in_screen = screen->GetCursorScreenPoint(); gfx::Point point_in_screen = screen->GetCursorScreenPoint();
cursor_location_in_screen_coords_for_restore_ = point_in_screen;
gfx::Display display = screen->GetDisplayNearestPoint(point_in_screen); gfx::Display display = screen->GetDisplayNearestPoint(point_in_screen);
aura::Window* root_window = GetRootWindowForDisplayId(display.id()); cursor_display_id_for_restore_ = display.id();
aura::client::ScreenPositionClient* client = gfx::Point point_in_native = point_in_screen;
aura::client::GetScreenPositionClient(root_window); aura::Window* root_window = GetRootWindowForDisplayId(display.id());
client->ConvertPointFromScreen(root_window, &point_in_screen); ::wm::ConvertPointFromScreen(root_window, &point_in_native);
root_window->GetHost()->ConvertPointToNativeScreen(&point_in_screen); root_window->GetHost()->ConvertPointToNativeScreen(&point_in_native);
cursor_location_in_native_coords_for_restore_ = point_in_screen; cursor_location_in_native_coords_for_restore_ = point_in_native;
} }
void DisplayController::PostDisplayConfigurationChange() { void DisplayController::PostDisplayConfigurationChange() {
......
...@@ -211,10 +211,16 @@ class ASH_EXPORT DisplayController : public gfx::DisplayObserver, ...@@ -211,10 +211,16 @@ class ASH_EXPORT DisplayController : public gfx::DisplayObserver,
scoped_ptr<CursorWindowController> cursor_window_controller_; scoped_ptr<CursorWindowController> cursor_window_controller_;
scoped_ptr<MirrorWindowController> mirror_window_controller_; scoped_ptr<MirrorWindowController> mirror_window_controller_;
// Stores the curent cursor location (in native coordinates) used to // Stores the current cursor location (in native coordinates and screen
// restore the cursor location when display configuration // coordinates respectively). The locations are used to restore the cursor
// changed. // location when the display configuration changes and to determine whether
// the mouse should be moved after a display configuration change.
gfx::Point cursor_location_in_native_coords_for_restore_; gfx::Point cursor_location_in_native_coords_for_restore_;
gfx::Point cursor_location_in_screen_coords_for_restore_;
// Stores the cursor's display. The id is used to determine whether the mouse
// should be moved after a display configuration change.
int64 cursor_display_id_for_restore_;
base::WeakPtrFactory<DisplayController> weak_ptr_factory_; base::WeakPtrFactory<DisplayController> weak_ptr_factory_;
......
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