summaryrefslogtreecommitdiffstats
path: root/ash
diff options
context:
space:
mode:
authorvarkha@chromium.org <varkha@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2014-01-07 12:23:28 +0000
committervarkha@chromium.org <varkha@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2014-01-07 12:23:28 +0000
commit361688514696e63a5da85baa57c61ad4166e8e00 (patch)
tree1c8649207e563b0ebeeb97c920d0821419d0bfdf /ash
parentd37720281b8336ebc00dd1bfaec76cd3c3006ba3 (diff)
downloadchromium_src-361688514696e63a5da85baa57c61ad4166e8e00.zip
chromium_src-361688514696e63a5da85baa57c61ad4166e8e00.tar.gz
chromium_src-361688514696e63a5da85baa57c61ad4166e8e00.tar.bz2
GetDisplayNearestPoint returns the nearest display when point is outside of any display.
BUG=146893 TEST=ash_unittests --gtest_filter=DisplayControllerTest.FindNearestDisplay Review URL: https://codereview.chromium.org/99163006 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@243273 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'ash')
-rw-r--r--ash/display/display_controller.cc25
-rw-r--r--ash/display/display_controller_unittest.cc47
-rw-r--r--ash/extended_desktop_unittest.cc4
3 files changed, 67 insertions, 9 deletions
diff --git a/ash/display/display_controller.cc b/ash/display/display_controller.cc
index 09927b3..d66af7d 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 =
diff --git a/ash/display/display_controller_unittest.cc b/ash/display/display_controller_unittest.cc
index 98f9304..ffcd6b0 100644
--- a/ash/display/display_controller_unittest.cc
+++ b/ash/display/display_controller_unittest.cc
@@ -641,7 +641,7 @@ TEST_F(DisplayControllerTest, SwapPrimary) {
EXPECT_EQ(secondary_display.id(),
Shell::GetScreen()->GetPrimaryDisplay().id());
EXPECT_EQ(primary_display.id(), ScreenAsh::GetSecondaryDisplay().id());
- EXPECT_EQ(secondary_display.id(),
+ EXPECT_EQ(primary_display.id(),
Shell::GetScreen()->GetDisplayNearestPoint(
gfx::Point(-100, -100)).id());
EXPECT_EQ(secondary_display.id(),
@@ -684,6 +684,49 @@ TEST_F(DisplayControllerTest, SwapPrimary) {
EXPECT_TRUE(primary_root->Contains(shelf_window));
}
+TEST_F(DisplayControllerTest, FindNearestDisplay) {
+ if (!SupportsMultipleDisplays())
+ return;
+
+ DisplayController* display_controller =
+ Shell::GetInstance()->display_controller();
+ internal::DisplayManager* display_manager =
+ Shell::GetInstance()->display_manager();
+
+ UpdateDisplay("200x200,300x300");
+ DisplayLayout display_layout(DisplayLayout::RIGHT, 50);
+ display_manager->SetLayoutForCurrentDisplays(display_layout);
+
+ gfx::Display primary_display = Shell::GetScreen()->GetPrimaryDisplay();
+ gfx::Display secondary_display = ScreenAsh::GetSecondaryDisplay();
+ EXPECT_NE(primary_display.id(), secondary_display.id());
+ aura::Window* primary_root =
+ display_controller->GetRootWindowForDisplayId(primary_display.id());
+ aura::Window* secondary_root =
+ display_controller->GetRootWindowForDisplayId(secondary_display.id());
+ EXPECT_NE(primary_root, secondary_root);
+
+ // Test that points outside of any display return the nearest display.
+ EXPECT_EQ(primary_display.id(), Shell::GetScreen()->GetDisplayNearestPoint(
+ gfx::Point(-100, 0)).id());
+ EXPECT_EQ(primary_display.id(), Shell::GetScreen()->GetDisplayNearestPoint(
+ gfx::Point(0, -100)).id());
+ EXPECT_EQ(primary_display.id(), Shell::GetScreen()->GetDisplayNearestPoint(
+ gfx::Point(100, 100)).id());
+ EXPECT_EQ(primary_display.id(), Shell::GetScreen()->GetDisplayNearestPoint(
+ gfx::Point(224, 25)).id());
+ EXPECT_EQ(secondary_display.id(), Shell::GetScreen()->GetDisplayNearestPoint(
+ gfx::Point(226, 25)).id());
+ EXPECT_EQ(secondary_display.id(), Shell::GetScreen()->GetDisplayNearestPoint(
+ gfx::Point(600, 100)).id());
+ EXPECT_EQ(primary_display.id(), Shell::GetScreen()->GetDisplayNearestPoint(
+ gfx::Point(174, 225)).id());
+ EXPECT_EQ(secondary_display.id(), Shell::GetScreen()->GetDisplayNearestPoint(
+ gfx::Point(176, 225)).id());
+ EXPECT_EQ(secondary_display.id(), Shell::GetScreen()->GetDisplayNearestPoint(
+ gfx::Point(300, 400)).id());
+}
+
TEST_F(DisplayControllerTest, SwapPrimaryForLegacyShelfLayout) {
if (!SupportsMultipleDisplays())
return;
@@ -735,7 +778,7 @@ TEST_F(DisplayControllerTest, SwapPrimaryForLegacyShelfLayout) {
EXPECT_EQ(secondary_display.id(),
Shell::GetScreen()->GetPrimaryDisplay().id());
EXPECT_EQ(primary_display.id(), ScreenAsh::GetSecondaryDisplay().id());
- EXPECT_EQ(secondary_display.id(),
+ EXPECT_EQ(primary_display.id(),
Shell::GetScreen()->GetDisplayNearestPoint(
gfx::Point(-100, -100)).id());
EXPECT_EQ(secondary_display.id(),
diff --git a/ash/extended_desktop_unittest.cc b/ash/extended_desktop_unittest.cc
index 225deca..1ba8297 100644
--- a/ash/extended_desktop_unittest.cc
+++ b/ash/extended_desktop_unittest.cc
@@ -351,8 +351,8 @@ TEST_F(ExtendedDesktopTest, GetRootWindowAt) {
// Zero origin.
EXPECT_EQ(root_windows[0], wm::GetRootWindowAt(gfx::Point(0, 0)));
- // Out of range point should return the primary root window
- EXPECT_EQ(root_windows[0], wm::GetRootWindowAt(gfx::Point(-600, 0)));
+ // Out of range point should return the nearest root window
+ EXPECT_EQ(root_windows[1], wm::GetRootWindowAt(gfx::Point(-600, 0)));
EXPECT_EQ(root_windows[0], wm::GetRootWindowAt(gfx::Point(701, 100)));
}