Chromium Code Reviews
[email protected] (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(455)

Unified Diff: ash/display/display_controller.cc

Issue 99163006: GetDisplayNearestPoint returns nearest display when point is outside of any display (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: GetDisplayNearestPoint returns nearest display when point is outside of any display Created 6 years, 12 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
« no previous file with comments | « no previous file | ash/display/display_controller_unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: ash/display/display_controller.cc
diff --git a/ash/display/display_controller.cc b/ash/display/display_controller.cc
index 09927b31c0901893c383dba83be500a20efb406e..d66af7d88e5a600839ab8fb7e40a39a249d9f7f0 100644
--- a/ash/display/display_controller.cc
+++ b/ash/display/display_controller.cc
@@ -567,11 +567,27 @@ const gfx::Display& DisplayController::GetDisplayNearestWindow(
const gfx::Display& DisplayController::GetDisplayNearestPoint(
const gfx::Point& point) const {
- // Fallback to the primary display if there is no root display containing
- // the |point|.
const gfx::Display& display =
GetDisplayManager()->FindDisplayContainingPoint(point);
- return display.is_valid() ? display : GetPrimaryDisplay();
+ if (display.is_valid())
+ return display;
+
+ // Fallback to the display that has the shortest Manhattan distance from
+ // the |point|. This is correct in the only areas that matter, namely in the
+ // corners between the physical screens.
+ int min_distance = INT_MAX;
+ const gfx::Display* nearest_display = NULL;
+ for (size_t i = 0; i < GetDisplayManager()->GetNumDisplays(); ++i) {
+ const gfx::Display& display = GetDisplayManager()->GetDisplayAt(i);
+ int distance = display.bounds().ManhattanDistanceToPoint(point);
+ if (distance < min_distance) {
+ min_distance = distance;
+ nearest_display = &display;
+ }
+ }
+ // There should always be at least one display that is less than INT_MAX away.
+ DCHECK(nearest_display);
+ return *nearest_display;
}
const gfx::Display& DisplayController::GetDisplayMatching(
@@ -707,8 +723,7 @@ void DisplayController::PreDisplayConfigurationChange(bool clear_focus) {
focus_activation_store_->Store(clear_focus);
gfx::Point point_in_screen = Shell::GetScreen()->GetCursorScreenPoint();
- gfx::Display display =
- Shell::GetScreen()->GetDisplayNearestPoint(point_in_screen);
+ gfx::Display display = GetDisplayNearestPoint(point_in_screen);
aura::Window* root_window = GetRootWindowForDisplayId(display.id());
aura::client::ScreenPositionClient* client =
« no previous file with comments | « no previous file | ash/display/display_controller_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698