Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(2293)

Unified Diff: ash/display/display_controller.cc

Issue 13466022: Don't move cursor location when rotation /ui scaling has changed (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: ash/display/display_controller.cc
diff --git a/ash/display/display_controller.cc b/ash/display/display_controller.cc
index a7343c9eccadbb55a62cc90081371710e9712f03..30b3797e577bbe69c9bc0f663bc5cb40f7cbe0a1 100644
--- a/ash/display/display_controller.cc
+++ b/ash/display/display_controller.cc
@@ -24,6 +24,7 @@
#include "base/stringprintf.h"
#include "base/strings/string_number_conversions.h"
#include "base/values.h"
+#include "ui/aura/client/cursor_client.h"
#include "ui/aura/client/screen_position_client.h"
#include "ui/aura/env.h"
#include "ui/aura/root_window.h"
@@ -722,6 +723,76 @@ gfx::Display* DisplayController::GetSecondaryDisplay() {
display_manager->GetDisplayAt(1) : display_manager->GetDisplayAt(0);
}
+void DisplayController::EnsurePointerInDisplays() {
+ // Don't try to move the pointer during the boot/startup.
+ if (!HasPrimaryDisplay())
+ return;
+ gfx::Point location_in_screen = Shell::GetScreen()->GetCursorScreenPoint();
+ gfx::Point target_location;
+ int64 closest_distance_squared = -1;
+ internal::DisplayManager* display_manager = GetDisplayManager();
+
+ aura::RootWindow* dst_root_window = NULL;
+ for (size_t i = 0; i < display_manager->GetNumDisplays(); ++i) {
+ const gfx::Display* display = display_manager->GetDisplayAt(i);
+ aura::RootWindow* root_window = GetRootWindowForDisplayId(display->id());
+ if (display->bounds().Contains(location_in_screen)) {
+ dst_root_window = root_window;
+ target_location = location_in_screen;
Jun Mukai 2013/04/06 03:13:39 in which case do we still need to call MoveCursorT
oshima 2013/04/08 18:00:40 Yes, we need to update the cursor when screen was
+ break;
+ }
+ gfx::Point center = display->bounds().CenterPoint();
+ // Use the distance squared from the center of the dislay. This is not
+ // exactly "closest" display, but good enough to pick one
+ // appropriate (and there are at most two displays).
+ // We don't care about actual distance, only relative to other displays, so
+ // using the LengthSquared() is cheaper than Length().
+
+ int64 distance_squared = (center - location_in_screen).LengthSquared();
+ if (closest_distance_squared < 0 ||
+ closest_distance_squared > distance_squared) {
+ dst_root_window = root_window;
+ target_location = center;
+ closest_distance_squared = distance_squared;
+ }
+ }
Jun Mukai 2013/04/06 03:13:39 It seems that this method doesn't ensure it if dst
oshima 2013/04/08 18:00:40 good point. done.
+ if (dst_root_window) {
+ aura::client::ScreenPositionClient* client =
+ aura::client::GetScreenPositionClient(dst_root_window);
+ client->ConvertPointFromScreen(dst_root_window, &target_location);
+ dst_root_window->MoveCursorTo(target_location);
+ }
+}
+
+gfx::Point DisplayController::GetNativeMouseCursorLocation() const {
+ gfx::Point location = Shell::GetScreen()->GetCursorScreenPoint();
+ const gfx::Display& display =
+ Shell::GetScreen()->GetDisplayNearestPoint(location);
+ const aura::RootWindow* root_window =
+ root_windows_.find(display.id())->second;
+ aura::client::ScreenPositionClient* client =
+ aura::client::GetScreenPositionClient(root_window);
+ client->ConvertPointFromScreen(root_window, &location);
+ root_window->ConvertPointToNativeScreen(&location);
+ return location;
+}
+
+void DisplayController::UpdateMouseCursor(const gfx::Point& point_in_native) {
+ std::vector<aura::RootWindow*> root_windows = GetAllRootWindows();
+ for (std::vector<aura::RootWindow*>::iterator iter = root_windows.begin();
+ iter != root_windows.end();
+ ++iter) {
+ aura::RootWindow* root_window = *iter;
+ gfx::Rect bounds(root_window->GetHostOrigin(), root_window->GetHostSize());
Jun Mukai 2013/04/06 03:13:39 bounds_in_native?
oshima 2013/04/08 18:00:40 Done.
+ if (bounds.Contains(point_in_native)) {
+ gfx::Point point(point_in_native);
+ root_window->ConvertPointFromNativeScreen(&point);
+ root_window->MoveCursorTo(point);
+ break;
+ }
+ }
+}
+
void DisplayController::OnDisplayBoundsChanged(const gfx::Display& display) {
if (limiter_.get())
limiter_->SetThrottleTimeout(kAfterDisplayChangeThrottleTimeoutMs);

Powered by Google App Engine
This is Rietveld 408576698