| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "ash/display/screen_position_controller.h" | 5 #include "ash/display/screen_position_controller.h" |
| 6 | 6 |
| 7 #include <memory> | 7 #include <memory> |
| 8 | 8 |
| 9 #include "ash/display/display_manager.h" | 9 #include "ash/display/display_manager.h" |
| 10 #include "ash/screen_util.h" | 10 #include "ash/screen_util.h" |
| 11 #include "ash/shell.h" | 11 #include "ash/shell.h" |
| 12 #include "ash/shell_window_ids.h" | 12 #include "ash/shell_window_ids.h" |
| 13 #include "ash/test/ash_test_base.h" | 13 #include "ash/test/ash_test_base.h" |
| 14 #include "ash/test/shell_test_api.h" | 14 #include "ash/test/shell_test_api.h" |
| 15 #include "ui/aura/env.h" | 15 #include "ui/aura/env.h" |
| 16 #include "ui/aura/test/test_window_delegate.h" | 16 #include "ui/aura/test/test_window_delegate.h" |
| 17 #include "ui/aura/window_tracker.h" | 17 #include "ui/aura/window_tracker.h" |
| 18 #include "ui/aura/window_tree_host.h" | 18 #include "ui/aura/window_tree_host.h" |
| 19 #include "ui/base/layout.h" | 19 #include "ui/base/layout.h" |
| 20 #include "ui/display/manager/display_layout.h" | 20 #include "ui/display/manager/display_layout.h" |
| 21 #include "ui/display/screen.h" |
| 21 #include "ui/events/test/event_generator.h" | 22 #include "ui/events/test/event_generator.h" |
| 22 #include "ui/gfx/screen.h" | |
| 23 | 23 |
| 24 #if defined(OS_WIN) | 24 #if defined(OS_WIN) |
| 25 // TODO(scottmg): RootWindow doesn't get resized immediately on Windows | 25 // TODO(scottmg): RootWindow doesn't get resized immediately on Windows |
| 26 // Ash. http://crbug.com/247916. | 26 // Ash. http://crbug.com/247916. |
| 27 #define MAYBE_ConvertHostPointToScreen DISABLED_ConvertHostPointToScreen | 27 #define MAYBE_ConvertHostPointToScreen DISABLED_ConvertHostPointToScreen |
| 28 #define MAYBE_ConvertHostPointToScreenHiDPI DISABLED_ConvertHostPointToScreenHiD
PI | 28 #define MAYBE_ConvertHostPointToScreenHiDPI DISABLED_ConvertHostPointToScreenHiD
PI |
| 29 #define MAYBE_ConvertHostPointToScreenRotate DISABLED_ConvertHostPointToScreenRo
tate | 29 #define MAYBE_ConvertHostPointToScreenRotate DISABLED_ConvertHostPointToScreenRo
tate |
| 30 #define MAYBE_ConvertHostPointToScreenUIScale DISABLED_ConvertHostPointToScreenU
IScale | 30 #define MAYBE_ConvertHostPointToScreenUIScale DISABLED_ConvertHostPointToScreenU
IScale |
| 31 #define MAYBE_ConvertToScreenWhileRemovingSecondaryDisplay \ | 31 #define MAYBE_ConvertToScreenWhileRemovingSecondaryDisplay \ |
| 32 DISABLED_ConvertToScreenWhileRemovingSecondaryDisplay | 32 DISABLED_ConvertToScreenWhileRemovingSecondaryDisplay |
| (...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 112 EXPECT_EQ("200x200", | 112 EXPECT_EQ("200x200", |
| 113 root_windows[0]->GetHost()->GetBounds().size().ToString()); | 113 root_windows[0]->GetHost()->GetBounds().size().ToString()); |
| 114 EXPECT_EQ("100,500", | 114 EXPECT_EQ("100,500", |
| 115 root_windows[1]->GetHost()->GetBounds().origin().ToString()); | 115 root_windows[1]->GetHost()->GetBounds().origin().ToString()); |
| 116 EXPECT_EQ("200x200", | 116 EXPECT_EQ("200x200", |
| 117 root_windows[1]->GetHost()->GetBounds().size().ToString()); | 117 root_windows[1]->GetHost()->GetBounds().size().ToString()); |
| 118 | 118 |
| 119 const gfx::Point window_pos(100, 100); | 119 const gfx::Point window_pos(100, 100); |
| 120 window_->SetBoundsInScreen( | 120 window_->SetBoundsInScreen( |
| 121 gfx::Rect(window_pos, gfx::Size(100, 100)), | 121 gfx::Rect(window_pos, gfx::Size(100, 100)), |
| 122 gfx::Screen::GetScreen()->GetDisplayNearestPoint(window_pos)); | 122 display::Screen::GetScreen()->GetDisplayNearestPoint(window_pos)); |
| 123 SetSecondaryDisplayLayout(display::DisplayPlacement::RIGHT); | 123 SetSecondaryDisplayLayout(display::DisplayPlacement::RIGHT); |
| 124 // The point is on the primary root window. | 124 // The point is on the primary root window. |
| 125 EXPECT_EQ("50,50", ConvertHostPointToScreen(50, 50)); | 125 EXPECT_EQ("50,50", ConvertHostPointToScreen(50, 50)); |
| 126 // The point is out of the all root windows. | 126 // The point is out of the all root windows. |
| 127 EXPECT_EQ("250,250", ConvertHostPointToScreen(250, 250)); | 127 EXPECT_EQ("250,250", ConvertHostPointToScreen(250, 250)); |
| 128 // The point is on the secondary display. | 128 // The point is on the secondary display. |
| 129 EXPECT_EQ("250,0", ConvertHostPointToScreen(50, 400)); | 129 EXPECT_EQ("250,0", ConvertHostPointToScreen(50, 400)); |
| 130 | 130 |
| 131 SetSecondaryDisplayLayout(display::DisplayPlacement::BOTTOM); | 131 SetSecondaryDisplayLayout(display::DisplayPlacement::BOTTOM); |
| 132 // The point is on the primary root window. | 132 // The point is on the primary root window. |
| (...skipping 16 matching lines...) Expand all Loading... |
| 149 EXPECT_EQ("50,50", ConvertHostPointToScreen(50, 50)); | 149 EXPECT_EQ("50,50", ConvertHostPointToScreen(50, 50)); |
| 150 // The point is out of the all root windows. | 150 // The point is out of the all root windows. |
| 151 EXPECT_EQ("250,250", ConvertHostPointToScreen(250, 250)); | 151 EXPECT_EQ("250,250", ConvertHostPointToScreen(250, 250)); |
| 152 // The point is on the secondary display. | 152 // The point is on the secondary display. |
| 153 EXPECT_EQ("50,-200", ConvertHostPointToScreen(50, 400)); | 153 EXPECT_EQ("50,-200", ConvertHostPointToScreen(50, 400)); |
| 154 | 154 |
| 155 SetSecondaryDisplayLayout(display::DisplayPlacement::RIGHT); | 155 SetSecondaryDisplayLayout(display::DisplayPlacement::RIGHT); |
| 156 const gfx::Point window_pos2(300, 100); | 156 const gfx::Point window_pos2(300, 100); |
| 157 window_->SetBoundsInScreen( | 157 window_->SetBoundsInScreen( |
| 158 gfx::Rect(window_pos2, gfx::Size(100, 100)), | 158 gfx::Rect(window_pos2, gfx::Size(100, 100)), |
| 159 gfx::Screen::GetScreen()->GetDisplayNearestPoint(window_pos2)); | 159 display::Screen::GetScreen()->GetDisplayNearestPoint(window_pos2)); |
| 160 // The point is on the secondary display. | 160 // The point is on the secondary display. |
| 161 EXPECT_EQ("250,50", ConvertHostPointToScreen(50, 50)); | 161 EXPECT_EQ("250,50", ConvertHostPointToScreen(50, 50)); |
| 162 // The point is out of the all root windows. | 162 // The point is out of the all root windows. |
| 163 EXPECT_EQ("450,250", ConvertHostPointToScreen(250, 250)); | 163 EXPECT_EQ("450,250", ConvertHostPointToScreen(250, 250)); |
| 164 // The point is on the primary root window. | 164 // The point is on the primary root window. |
| 165 EXPECT_EQ("50,0", ConvertHostPointToScreen(50, -400)); | 165 EXPECT_EQ("50,0", ConvertHostPointToScreen(50, -400)); |
| 166 | 166 |
| 167 SetSecondaryDisplayLayout(display::DisplayPlacement::BOTTOM); | 167 SetSecondaryDisplayLayout(display::DisplayPlacement::BOTTOM); |
| 168 // The point is on the secondary display. | 168 // The point is on the secondary display. |
| 169 EXPECT_EQ("50,250", ConvertHostPointToScreen(50, 50)); | 169 EXPECT_EQ("50,250", ConvertHostPointToScreen(50, 50)); |
| (...skipping 24 matching lines...) Expand all Loading... |
| 194 | 194 |
| 195 aura::Window::Windows root_windows = | 195 aura::Window::Windows root_windows = |
| 196 Shell::GetInstance()->GetAllRootWindows(); | 196 Shell::GetInstance()->GetAllRootWindows(); |
| 197 EXPECT_EQ("50,50 200x200", | 197 EXPECT_EQ("50,50 200x200", |
| 198 root_windows[0]->GetHost()->GetBounds().ToString()); | 198 root_windows[0]->GetHost()->GetBounds().ToString()); |
| 199 EXPECT_EQ("50,300 300x300", | 199 EXPECT_EQ("50,300 300x300", |
| 200 root_windows[1]->GetHost()->GetBounds().ToString()); | 200 root_windows[1]->GetHost()->GetBounds().ToString()); |
| 201 | 201 |
| 202 // Put |window_| to the primary 2x display. | 202 // Put |window_| to the primary 2x display. |
| 203 window_->SetBoundsInScreen(gfx::Rect(20, 20, 50, 50), | 203 window_->SetBoundsInScreen(gfx::Rect(20, 20, 50, 50), |
| 204 gfx::Screen::GetScreen()->GetPrimaryDisplay()); | 204 display::Screen::GetScreen()->GetPrimaryDisplay()); |
| 205 // (30, 30) means the host coordinate, so the point is still on the primary | 205 // (30, 30) means the host coordinate, so the point is still on the primary |
| 206 // root window. Since it's 2x, the specified native point was halved. | 206 // root window. Since it's 2x, the specified native point was halved. |
| 207 EXPECT_EQ("15,15", ConvertHostPointToScreen(30, 30)); | 207 EXPECT_EQ("15,15", ConvertHostPointToScreen(30, 30)); |
| 208 // Similar to above but the point is out of the all root windows. | 208 // Similar to above but the point is out of the all root windows. |
| 209 EXPECT_EQ("200,200", ConvertHostPointToScreen(400, 400)); | 209 EXPECT_EQ("200,200", ConvertHostPointToScreen(400, 400)); |
| 210 // Similar to above but the point is on the secondary display. | 210 // Similar to above but the point is on the secondary display. |
| 211 EXPECT_EQ("100,15", ConvertHostPointToScreen(200, 30)); | 211 EXPECT_EQ("100,15", ConvertHostPointToScreen(200, 30)); |
| 212 | 212 |
| 213 // On secondary display. The position on the 2nd host window is (150,200) | 213 // On secondary display. The position on the 2nd host window is (150,200) |
| 214 // so the screen position is (100,0) + (150,200). | 214 // so the screen position is (100,0) + (150,200). |
| 215 EXPECT_EQ("250,200", ConvertHostPointToScreen(150, 450)); | 215 EXPECT_EQ("250,200", ConvertHostPointToScreen(150, 450)); |
| 216 | 216 |
| 217 // At the edge but still in the primary display. Remaining of the primary | 217 // At the edge but still in the primary display. Remaining of the primary |
| 218 // display is (50, 50) but adding ~100 since it's 2x-display. | 218 // display is (50, 50) but adding ~100 since it's 2x-display. |
| 219 EXPECT_EQ("79,79", ConvertHostPointToScreen(158, 158)); | 219 EXPECT_EQ("79,79", ConvertHostPointToScreen(158, 158)); |
| 220 // At the edge of the secondary display. | 220 // At the edge of the secondary display. |
| 221 EXPECT_EQ("80,80", ConvertHostPointToScreen(160, 160)); | 221 EXPECT_EQ("80,80", ConvertHostPointToScreen(160, 160)); |
| 222 } | 222 } |
| 223 | 223 |
| 224 TEST_F(ScreenPositionControllerTest, MAYBE_ConvertHostPointToScreenRotate) { | 224 TEST_F(ScreenPositionControllerTest, MAYBE_ConvertHostPointToScreenRotate) { |
| 225 // 1st display is rotated 90 clockise, and 2nd display is rotated | 225 // 1st display is rotated 90 clockise, and 2nd display is rotated |
| 226 // 270 clockwise. | 226 // 270 clockwise. |
| 227 UpdateDisplay("100+100-200x200/r,100+500-200x200/l"); | 227 UpdateDisplay("100+100-200x200/r,100+500-200x200/l"); |
| 228 // Put |window_| to the 1st. | 228 // Put |window_| to the 1st. |
| 229 window_->SetBoundsInScreen(gfx::Rect(20, 20, 50, 50), | 229 window_->SetBoundsInScreen(gfx::Rect(20, 20, 50, 50), |
| 230 gfx::Screen::GetScreen()->GetPrimaryDisplay()); | 230 display::Screen::GetScreen()->GetPrimaryDisplay()); |
| 231 | 231 |
| 232 // The point is on the 1st host. | 232 // The point is on the 1st host. |
| 233 EXPECT_EQ("70,149", ConvertHostPointToScreen(50, 70)); | 233 EXPECT_EQ("70,149", ConvertHostPointToScreen(50, 70)); |
| 234 // The point is out of the host windows. | 234 // The point is out of the host windows. |
| 235 EXPECT_EQ("250,-51", ConvertHostPointToScreen(250, 250)); | 235 EXPECT_EQ("250,-51", ConvertHostPointToScreen(250, 250)); |
| 236 // The point is on the 2nd host. Point on 2nd host (30,150) - | 236 // The point is on the 2nd host. Point on 2nd host (30,150) - |
| 237 // rotate 270 clockwise -> (149, 30) - layout [+(200,0)] -> (349,30). | 237 // rotate 270 clockwise -> (149, 30) - layout [+(200,0)] -> (349,30). |
| 238 EXPECT_EQ("349,30", ConvertHostPointToScreen(30, 450)); | 238 EXPECT_EQ("349,30", ConvertHostPointToScreen(30, 450)); |
| 239 | 239 |
| 240 // Move |window_| to the 2nd. | 240 // Move |window_| to the 2nd. |
| (...skipping 11 matching lines...) Expand all Loading... |
| 252 // The point is on the 2nd host. Point on 2nd host (50,50) - | 252 // The point is on the 2nd host. Point on 2nd host (50,50) - |
| 253 // rotate 90 clockwise -> (50, 149) | 253 // rotate 90 clockwise -> (50, 149) |
| 254 EXPECT_EQ("50,149", ConvertHostPointToScreen(50, -350)); | 254 EXPECT_EQ("50,149", ConvertHostPointToScreen(50, -350)); |
| 255 } | 255 } |
| 256 | 256 |
| 257 TEST_F(ScreenPositionControllerTest, MAYBE_ConvertHostPointToScreenUIScale) { | 257 TEST_F(ScreenPositionControllerTest, MAYBE_ConvertHostPointToScreenUIScale) { |
| 258 // 1st display is 2x density with 1.5 UI scale. | 258 // 1st display is 2x density with 1.5 UI scale. |
| 259 UpdateDisplay("100+100-200x200*2@1.5,100+500-200x200"); | 259 UpdateDisplay("100+100-200x200*2@1.5,100+500-200x200"); |
| 260 // Put |window_| to the 1st. | 260 // Put |window_| to the 1st. |
| 261 window_->SetBoundsInScreen(gfx::Rect(20, 20, 50, 50), | 261 window_->SetBoundsInScreen(gfx::Rect(20, 20, 50, 50), |
| 262 gfx::Screen::GetScreen()->GetPrimaryDisplay()); | 262 display::Screen::GetScreen()->GetPrimaryDisplay()); |
| 263 | 263 |
| 264 // The point is on the 1st host. | 264 // The point is on the 1st host. |
| 265 EXPECT_EQ("45,45", ConvertHostPointToScreen(60, 60)); | 265 EXPECT_EQ("45,45", ConvertHostPointToScreen(60, 60)); |
| 266 // The point is out of the host windows. | 266 // The point is out of the host windows. |
| 267 EXPECT_EQ("45,225", ConvertHostPointToScreen(60, 300)); | 267 EXPECT_EQ("45,225", ConvertHostPointToScreen(60, 300)); |
| 268 // The point is on the 2nd host. Point on 2nd host (60,150) - | 268 // The point is on the 2nd host. Point on 2nd host (60,150) - |
| 269 // - screen [+(150,0)] | 269 // - screen [+(150,0)] |
| 270 EXPECT_EQ("210,49", ConvertHostPointToScreen(60, 450)); | 270 EXPECT_EQ("210,49", ConvertHostPointToScreen(60, 450)); |
| 271 | 271 |
| 272 // Move |window_| to the 2nd. | 272 // Move |window_| to the 2nd. |
| (...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 358 // destroyed. | 358 // destroyed. |
| 359 EXPECT_FALSE(tracker.Contains(root_windows[1])); | 359 EXPECT_FALSE(tracker.Contains(root_windows[1])); |
| 360 | 360 |
| 361 // Check that we could convert all of the mouse events we got to screen | 361 // Check that we could convert all of the mouse events we got to screen |
| 362 // coordinates. | 362 // coordinates. |
| 363 EXPECT_TRUE(event_handler->could_convert_to_screen()); | 363 EXPECT_TRUE(event_handler->could_convert_to_screen()); |
| 364 } | 364 } |
| 365 | 365 |
| 366 } // namespace test | 366 } // namespace test |
| 367 } // namespace ash | 367 } // namespace ash |
| OLD | NEW |