[email protected] | 55ad8c1 | 2014-01-17 18:24:33 | [diff] [blame] | 1 | // Copyright 2014 The Chromium Authors. All rights reserved. |
[email protected] | 8d625fb | 2012-07-18 16:40:06 | [diff] [blame] | 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
[email protected] | 55ad8c1 | 2014-01-17 18:24:33 | [diff] [blame] | 5 | #include "ash/screen_util.h" |
[email protected] | 8d625fb | 2012-07-18 16:40:06 | [diff] [blame] | 6 | |
Ahmed Fakhry | 4f8e372 | 2017-10-31 21:01:58 | [diff] [blame^] | 7 | #include "ash/public/cpp/config.h" |
[email protected] | 8d625fb | 2012-07-18 16:40:06 | [diff] [blame] | 8 | #include "ash/shell.h" |
estade | a23d6ceb | 2017-02-15 00:47:09 | [diff] [blame] | 9 | #include "ash/test/ash_test_base.h" |
[email protected] | 8d625fb | 2012-07-18 16:40:06 | [diff] [blame] | 10 | #include "ash/wm/window_util.h" |
| 11 | #include "ui/aura/env.h" |
[email protected] | 8d625fb | 2012-07-18 16:40:06 | [diff] [blame] | 12 | #include "ui/aura/window.h" |
[email protected] | fcc51c95 | 2014-02-21 21:31:26 | [diff] [blame] | 13 | #include "ui/aura/window_event_dispatcher.h" |
rjkroege | 72f8154f | 2016-10-29 00:49:02 | [diff] [blame] | 14 | #include "ui/display/manager/display_manager.h" |
Ahmed Fakhry | 4f8e372 | 2017-10-31 21:01:58 | [diff] [blame^] | 15 | #include "ui/display/unified_desktop_utils.h" |
[email protected] | 8d625fb | 2012-07-18 16:40:06 | [diff] [blame] | 16 | #include "ui/views/widget/widget.h" |
| 17 | #include "ui/views/widget/widget_delegate.h" |
yhanada | 698af19 | 2017-02-23 10:57:07 | [diff] [blame] | 18 | #include "ui/wm/core/coordinate_conversion.h" |
[email protected] | 8d625fb | 2012-07-18 16:40:06 | [diff] [blame] | 19 | |
| 20 | namespace ash { |
[email protected] | 8d625fb | 2012-07-18 16:40:06 | [diff] [blame] | 21 | |
estade | a23d6ceb | 2017-02-15 00:47:09 | [diff] [blame] | 22 | using ScreenUtilTest = AshTestBase; |
[email protected] | 8d625fb | 2012-07-18 16:40:06 | [diff] [blame] | 23 | |
estade | a23d6ceb | 2017-02-15 00:47:09 | [diff] [blame] | 24 | TEST_F(ScreenUtilTest, Bounds) { |
[email protected] | f634dd3 | 2012-07-23 22:49:07 | [diff] [blame] | 25 | UpdateDisplay("600x600,500x500"); |
[email protected] | a2e6af1 | 2013-01-07 21:40:35 | [diff] [blame] | 26 | views::Widget* primary = views::Widget::CreateWindowWithContextAndBounds( |
| 27 | NULL, CurrentContext(), gfx::Rect(10, 10, 100, 100)); |
[email protected] | 8d625fb | 2012-07-18 16:40:06 | [diff] [blame] | 28 | primary->Show(); |
[email protected] | a2e6af1 | 2013-01-07 21:40:35 | [diff] [blame] | 29 | views::Widget* secondary = views::Widget::CreateWindowWithContextAndBounds( |
| 30 | NULL, CurrentContext(), gfx::Rect(610, 10, 100, 100)); |
[email protected] | 8d625fb | 2012-07-18 16:40:06 | [diff] [blame] | 31 | secondary->Show(); |
| 32 | |
jamescook | cf8b648f | 2016-06-01 19:58:17 | [diff] [blame] | 33 | // Maximized bounds. By default the shelf is 47px tall (ash::kShelfSize). |
tdanderson | 0b7905b | 2016-06-22 21:53:03 | [diff] [blame] | 34 | EXPECT_EQ( |
estade | a23d6ceb | 2017-02-15 00:47:09 | [diff] [blame] | 35 | gfx::Rect(0, 0, 600, 552).ToString(), |
tdanderson | 0b7905b | 2016-06-22 21:53:03 | [diff] [blame] | 36 | ScreenUtil::GetMaximizedWindowBoundsInParent(primary->GetNativeView()) |
| 37 | .ToString()); |
| 38 | EXPECT_EQ( |
estade | a23d6ceb | 2017-02-15 00:47:09 | [diff] [blame] | 39 | gfx::Rect(0, 0, 500, 452).ToString(), |
tdanderson | 0b7905b | 2016-06-22 21:53:03 | [diff] [blame] | 40 | ScreenUtil::GetMaximizedWindowBoundsInParent(secondary->GetNativeView()) |
| 41 | .ToString()); |
[email protected] | 8d625fb | 2012-07-18 16:40:06 | [diff] [blame] | 42 | |
[email protected] | 8d625fb | 2012-07-18 16:40:06 | [diff] [blame] | 43 | // Display bounds |
| 44 | EXPECT_EQ("0,0 600x600", |
jamescook | b8dcef52 | 2016-06-25 14:42:55 | [diff] [blame] | 45 | ScreenUtil::GetDisplayBoundsInParent(primary->GetNativeView()) |
| 46 | .ToString()); |
[email protected] | 8d625fb | 2012-07-18 16:40:06 | [diff] [blame] | 47 | EXPECT_EQ("0,0 500x500", |
jamescook | b8dcef52 | 2016-06-25 14:42:55 | [diff] [blame] | 48 | ScreenUtil::GetDisplayBoundsInParent(secondary->GetNativeView()) |
| 49 | .ToString()); |
[email protected] | 8d625fb | 2012-07-18 16:40:06 | [diff] [blame] | 50 | |
| 51 | // Work area bounds |
tdanderson | 0b7905b | 2016-06-22 21:53:03 | [diff] [blame] | 52 | EXPECT_EQ( |
estade | a23d6ceb | 2017-02-15 00:47:09 | [diff] [blame] | 53 | gfx::Rect(0, 0, 600, 552).ToString(), |
tdanderson | 0b7905b | 2016-06-22 21:53:03 | [diff] [blame] | 54 | ScreenUtil::GetDisplayWorkAreaBoundsInParent(primary->GetNativeView()) |
| 55 | .ToString()); |
| 56 | EXPECT_EQ( |
estade | a23d6ceb | 2017-02-15 00:47:09 | [diff] [blame] | 57 | gfx::Rect(0, 0, 500, 452).ToString(), |
tdanderson | 0b7905b | 2016-06-22 21:53:03 | [diff] [blame] | 58 | ScreenUtil::GetDisplayWorkAreaBoundsInParent(secondary->GetNativeView()) |
| 59 | .ToString()); |
[email protected] | 8d625fb | 2012-07-18 16:40:06 | [diff] [blame] | 60 | } |
[email protected] | 8d625fb | 2012-07-18 16:40:06 | [diff] [blame] | 61 | |
[email protected] | 805155f | 2013-04-10 02:11:20 | [diff] [blame] | 62 | // Test verifies a stable handling of secondary screen widget changes |
| 63 | // (crbug.com/226132). |
estade | a23d6ceb | 2017-02-15 00:47:09 | [diff] [blame] | 64 | TEST_F(ScreenUtilTest, StabilityTest) { |
[email protected] | 805155f | 2013-04-10 02:11:20 | [diff] [blame] | 65 | UpdateDisplay("600x600,500x500"); |
| 66 | views::Widget* secondary = views::Widget::CreateWindowWithContextAndBounds( |
| 67 | NULL, CurrentContext(), gfx::Rect(610, 10, 100, 100)); |
| 68 | EXPECT_EQ(Shell::GetAllRootWindows()[1], |
jamescook | b8dcef52 | 2016-06-25 14:42:55 | [diff] [blame] | 69 | secondary->GetNativeView()->GetRootWindow()); |
[email protected] | 805155f | 2013-04-10 02:11:20 | [diff] [blame] | 70 | secondary->Show(); |
| 71 | secondary->Maximize(); |
| 72 | secondary->Show(); |
| 73 | secondary->SetFullscreen(true); |
| 74 | secondary->Hide(); |
| 75 | secondary->Close(); |
| 76 | } |
| 77 | |
estade | a23d6ceb | 2017-02-15 00:47:09 | [diff] [blame] | 78 | TEST_F(ScreenUtilTest, ConvertRect) { |
[email protected] | f634dd3 | 2012-07-23 22:49:07 | [diff] [blame] | 79 | UpdateDisplay("600x600,500x500"); |
[email protected] | 8d625fb | 2012-07-18 16:40:06 | [diff] [blame] | 80 | |
[email protected] | a2e6af1 | 2013-01-07 21:40:35 | [diff] [blame] | 81 | views::Widget* primary = views::Widget::CreateWindowWithContextAndBounds( |
| 82 | NULL, CurrentContext(), gfx::Rect(10, 10, 100, 100)); |
[email protected] | 8d625fb | 2012-07-18 16:40:06 | [diff] [blame] | 83 | primary->Show(); |
[email protected] | a2e6af1 | 2013-01-07 21:40:35 | [diff] [blame] | 84 | views::Widget* secondary = views::Widget::CreateWindowWithContextAndBounds( |
| 85 | NULL, CurrentContext(), gfx::Rect(610, 10, 100, 100)); |
[email protected] | 8d625fb | 2012-07-18 16:40:06 | [diff] [blame] | 86 | secondary->Show(); |
| 87 | |
yhanada | 698af19 | 2017-02-23 10:57:07 | [diff] [blame] | 88 | gfx::Rect r1(10, 10, 100, 100); |
| 89 | ::wm::ConvertRectFromScreen(primary->GetNativeView(), &r1); |
| 90 | EXPECT_EQ("0,0 100x100", r1.ToString()); |
[email protected] | 8d625fb | 2012-07-18 16:40:06 | [diff] [blame] | 91 | |
yhanada | 698af19 | 2017-02-23 10:57:07 | [diff] [blame] | 92 | gfx::Rect r2(620, 20, 100, 100); |
| 93 | ::wm::ConvertRectFromScreen(secondary->GetNativeView(), &r2); |
| 94 | EXPECT_EQ("10,10 100x100", r2.ToString()); |
| 95 | |
| 96 | gfx::Rect r3(30, 30, 100, 100); |
| 97 | ::wm::ConvertRectToScreen(primary->GetNativeView(), &r3); |
| 98 | EXPECT_EQ("40,40 100x100", r3.ToString()); |
| 99 | |
| 100 | gfx::Rect r4(40, 40, 100, 100); |
| 101 | ::wm::ConvertRectToScreen(secondary->GetNativeView(), &r4); |
| 102 | EXPECT_EQ("650,50 100x100", r4.ToString()); |
[email protected] | 8d625fb | 2012-07-18 16:40:06 | [diff] [blame] | 103 | } |
| 104 | |
estade | a23d6ceb | 2017-02-15 00:47:09 | [diff] [blame] | 105 | TEST_F(ScreenUtilTest, ShelfDisplayBoundsInUnifiedDesktop) { |
rjkroege | 72f8154f | 2016-10-29 00:49:02 | [diff] [blame] | 106 | display_manager()->SetUnifiedDesktopEnabled(true); |
oshima | 96f6a50 | 2015-05-02 08:43:32 | [diff] [blame] | 107 | |
| 108 | views::Widget* widget = views::Widget::CreateWindowWithContextAndBounds( |
| 109 | NULL, CurrentContext(), gfx::Rect(10, 10, 100, 100)); |
sky | 00f0b89 | 2017-05-05 17:06:24 | [diff] [blame] | 110 | aura::Window* window = widget->GetNativeWindow(); |
oshima | 96f6a50 | 2015-05-02 08:43:32 | [diff] [blame] | 111 | |
| 112 | UpdateDisplay("500x400"); |
sky | 00f0b89 | 2017-05-05 17:06:24 | [diff] [blame] | 113 | EXPECT_EQ("0,0 500x400", |
| 114 | ScreenUtil::GetDisplayBoundsWithShelf(window).ToString()); |
oshima | 96f6a50 | 2015-05-02 08:43:32 | [diff] [blame] | 115 | |
| 116 | UpdateDisplay("500x400,600x400"); |
sky | 00f0b89 | 2017-05-05 17:06:24 | [diff] [blame] | 117 | EXPECT_EQ("0,0 500x400", |
| 118 | ScreenUtil::GetDisplayBoundsWithShelf(window).ToString()); |
oshima | 96f6a50 | 2015-05-02 08:43:32 | [diff] [blame] | 119 | |
| 120 | // Move to the 2nd physical display. Shelf's display still should be |
| 121 | // the first. |
| 122 | widget->SetBounds(gfx::Rect(800, 0, 100, 100)); |
| 123 | ASSERT_EQ("800,0 100x100", widget->GetWindowBoundsInScreen().ToString()); |
| 124 | |
sky | 00f0b89 | 2017-05-05 17:06:24 | [diff] [blame] | 125 | EXPECT_EQ("0,0 500x400", |
| 126 | ScreenUtil::GetDisplayBoundsWithShelf(window).ToString()); |
oshima | 96f6a50 | 2015-05-02 08:43:32 | [diff] [blame] | 127 | |
| 128 | UpdateDisplay("600x500"); |
sky | 00f0b89 | 2017-05-05 17:06:24 | [diff] [blame] | 129 | EXPECT_EQ("0,0 600x500", |
| 130 | ScreenUtil::GetDisplayBoundsWithShelf(window).ToString()); |
oshima | 96f6a50 | 2015-05-02 08:43:32 | [diff] [blame] | 131 | } |
| 132 | |
Ahmed Fakhry | 4f8e372 | 2017-10-31 21:01:58 | [diff] [blame^] | 133 | TEST_F(ScreenUtilTest, ShelfDisplayBoundsInUnifiedDesktopGrid) { |
| 134 | // TODO: requires unified desktop mode. http://crbug.com/581462. |
| 135 | if (Shell::GetAshConfig() == Config::MASH) |
| 136 | return; |
| 137 | |
| 138 | UpdateDisplay("500x400,400x600,300x600,200x300,600x200,350x400"); |
| 139 | display_manager()->SetUnifiedDesktopEnabled(true); |
| 140 | |
| 141 | views::Widget* widget = views::Widget::CreateWindowWithContextAndBounds( |
| 142 | NULL, CurrentContext(), gfx::Rect(10, 10, 100, 100)); |
| 143 | aura::Window* window = widget->GetNativeWindow(); |
| 144 | |
| 145 | display::DisplayIdList list = display_manager()->GetCurrentDisplayIdList(); |
| 146 | ASSERT_EQ(6u, list.size()); |
| 147 | // Create a 3 x 2 vertical layout matrix and set it. |
| 148 | // [500 x 400] [400 x 600] |
| 149 | // [300 x 600] [200 x 300] |
| 150 | // [600 x 200] [350 x 400] |
| 151 | display::UnifiedDesktopLayoutMatrix matrix; |
| 152 | matrix.resize(3u); |
| 153 | matrix[0].emplace_back(list[0]); |
| 154 | matrix[0].emplace_back(list[1]); |
| 155 | matrix[1].emplace_back(list[2]); |
| 156 | matrix[1].emplace_back(list[3]); |
| 157 | matrix[2].emplace_back(list[4]); |
| 158 | matrix[2].emplace_back(list[5]); |
| 159 | display_manager()->SetUnifiedDesktopMatrix(matrix); |
| 160 | display::Screen* screen = display::Screen::GetScreen(); |
| 161 | EXPECT_EQ(gfx::Size(766, 1254), screen->GetPrimaryDisplay().size()); |
| 162 | |
| 163 | // Regardless of where the window is, the shelf is always in the top left |
| 164 | // display in the matrix. |
| 165 | EXPECT_EQ(gfx::Rect(0, 0, 499, 400), |
| 166 | ScreenUtil::GetDisplayBoundsWithShelf(window)); |
| 167 | |
| 168 | // Move to the bottom right display. |
| 169 | widget->SetBounds(gfx::Rect(620, 940, 100, 100)); |
| 170 | EXPECT_EQ(gfx::Rect(0, 0, 499, 400), |
| 171 | ScreenUtil::GetDisplayBoundsWithShelf(window)); |
| 172 | } |
| 173 | |
[email protected] | 8d625fb | 2012-07-18 16:40:06 | [diff] [blame] | 174 | } // namespace ash |