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/common/shell_window_ids.h" | 9 #include "ash/common/shell_window_ids.h" |
10 #include "ash/display/display_manager.h" | 10 #include "ash/display/display_manager.h" |
(...skipping 29 matching lines...) Expand all Loading... |
40 #define MAYBE_ConvertHostPointToScreenUIScale ConvertHostPointToScreenUIScale | 40 #define MAYBE_ConvertHostPointToScreenUIScale ConvertHostPointToScreenUIScale |
41 #define MAYBE_ConvertToScreenWhileRemovingSecondaryDisplay \ | 41 #define MAYBE_ConvertToScreenWhileRemovingSecondaryDisplay \ |
42 ConvertToScreenWhileRemovingSecondaryDisplay | 42 ConvertToScreenWhileRemovingSecondaryDisplay |
43 #endif | 43 #endif |
44 | 44 |
45 namespace ash { | 45 namespace ash { |
46 namespace test { | 46 namespace test { |
47 | 47 |
48 namespace { | 48 namespace { |
49 | 49 |
50 void SetSecondaryDisplayLayout(display::DisplayPlacement::Position position) { | |
51 std::unique_ptr<display::DisplayLayout> layout(Shell::GetInstance() | |
52 ->display_manager() | |
53 ->GetCurrentDisplayLayout() | |
54 .Copy()); | |
55 layout->placement_list[0].position = position; | |
56 Shell::GetInstance()->display_manager()->SetLayoutForCurrentDisplays( | |
57 std::move(layout)); | |
58 } | |
59 | |
60 ScreenPositionController* GetScreenPositionController() { | 50 ScreenPositionController* GetScreenPositionController() { |
61 ShellTestApi test_api(Shell::GetInstance()); | 51 ShellTestApi test_api(Shell::GetInstance()); |
62 return test_api.screen_position_controller(); | 52 return test_api.screen_position_controller(); |
63 } | 53 } |
64 | 54 |
65 class ScreenPositionControllerTest : public test::AshTestBase { | 55 class ScreenPositionControllerTest : public test::AshTestBase { |
66 public: | 56 public: |
67 ScreenPositionControllerTest() {} | 57 ScreenPositionControllerTest() {} |
68 ~ScreenPositionControllerTest() override {} | 58 ~ScreenPositionControllerTest() override {} |
69 | 59 |
(...skipping 13 matching lines...) Expand all Loading... |
83 | 73 |
84 // Converts a point (x, y) in host window's coordinate to screen and | 74 // Converts a point (x, y) in host window's coordinate to screen and |
85 // returns its string representation. | 75 // returns its string representation. |
86 std::string ConvertHostPointToScreen(int x, int y) const { | 76 std::string ConvertHostPointToScreen(int x, int y) const { |
87 gfx::Point point(x, y); | 77 gfx::Point point(x, y); |
88 GetScreenPositionController()->ConvertHostPointToScreen( | 78 GetScreenPositionController()->ConvertHostPointToScreen( |
89 window_->GetRootWindow(), &point); | 79 window_->GetRootWindow(), &point); |
90 return point.ToString(); | 80 return point.ToString(); |
91 } | 81 } |
92 | 82 |
| 83 void SetSecondaryDisplayLayout(display::DisplayPlacement::Position position) { |
| 84 std::unique_ptr<display::DisplayLayout> layout( |
| 85 display_manager()->GetCurrentDisplayLayout().Copy()); |
| 86 layout->placement_list[0].position = position; |
| 87 display_manager()->SetLayoutForCurrentDisplays(std::move(layout)); |
| 88 } |
| 89 |
93 protected: | 90 protected: |
94 std::unique_ptr<aura::Window> window_; | 91 std::unique_ptr<aura::Window> window_; |
95 aura::test::TestWindowDelegate window_delegate_; | 92 aura::test::TestWindowDelegate window_delegate_; |
96 | 93 |
97 private: | 94 private: |
98 DISALLOW_COPY_AND_ASSIGN(ScreenPositionControllerTest); | 95 DISALLOW_COPY_AND_ASSIGN(ScreenPositionControllerTest); |
99 }; | 96 }; |
100 | 97 |
101 } // namespace | 98 } // namespace |
102 | 99 |
(...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
235 // The point is on the 1st host. | 232 // The point is on the 1st host. |
236 EXPECT_EQ("70,149", ConvertHostPointToScreen(50, 70)); | 233 EXPECT_EQ("70,149", ConvertHostPointToScreen(50, 70)); |
237 // The point is out of the host windows. | 234 // The point is out of the host windows. |
238 EXPECT_EQ("250,-51", ConvertHostPointToScreen(250, 250)); | 235 EXPECT_EQ("250,-51", ConvertHostPointToScreen(250, 250)); |
239 // 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) - |
240 // rotate 270 clockwise -> (149, 30) - layout [+(200,0)] -> (349,30). | 237 // rotate 270 clockwise -> (149, 30) - layout [+(200,0)] -> (349,30). |
241 EXPECT_EQ("349,30", ConvertHostPointToScreen(30, 450)); | 238 EXPECT_EQ("349,30", ConvertHostPointToScreen(30, 450)); |
242 | 239 |
243 // Move |window_| to the 2nd. | 240 // Move |window_| to the 2nd. |
244 window_->SetBoundsInScreen(gfx::Rect(300, 20, 50, 50), | 241 window_->SetBoundsInScreen(gfx::Rect(300, 20, 50, 50), |
245 ScreenUtil::GetSecondaryDisplay()); | 242 display_manager()->GetSecondaryDisplay()); |
246 aura::Window::Windows root_windows = | 243 aura::Window::Windows root_windows = |
247 Shell::GetInstance()->GetAllRootWindows(); | 244 Shell::GetInstance()->GetAllRootWindows(); |
248 EXPECT_EQ(root_windows[1], window_->GetRootWindow()); | 245 EXPECT_EQ(root_windows[1], window_->GetRootWindow()); |
249 | 246 |
250 // The point is on the 2nd host. (50,70) on 2n host - | 247 // The point is on the 2nd host. (50,70) on 2n host - |
251 // roatate 270 clockwise -> (129,50) -layout [+(200,0)] -> (329,50) | 248 // roatate 270 clockwise -> (129,50) -layout [+(200,0)] -> (329,50) |
252 EXPECT_EQ("329,50", ConvertHostPointToScreen(50, 70)); | 249 EXPECT_EQ("329,50", ConvertHostPointToScreen(50, 70)); |
253 // The point is out of the host windows. | 250 // The point is out of the host windows. |
254 EXPECT_EQ("449,50", ConvertHostPointToScreen(50, -50)); | 251 EXPECT_EQ("449,50", ConvertHostPointToScreen(50, -50)); |
255 // 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) - |
(...skipping 11 matching lines...) Expand all Loading... |
267 // The point is on the 1st host. | 264 // The point is on the 1st host. |
268 EXPECT_EQ("45,45", ConvertHostPointToScreen(60, 60)); | 265 EXPECT_EQ("45,45", ConvertHostPointToScreen(60, 60)); |
269 // The point is out of the host windows. | 266 // The point is out of the host windows. |
270 EXPECT_EQ("45,225", ConvertHostPointToScreen(60, 300)); | 267 EXPECT_EQ("45,225", ConvertHostPointToScreen(60, 300)); |
271 // 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) - |
272 // - screen [+(150,0)] | 269 // - screen [+(150,0)] |
273 EXPECT_EQ("210,49", ConvertHostPointToScreen(60, 450)); | 270 EXPECT_EQ("210,49", ConvertHostPointToScreen(60, 450)); |
274 | 271 |
275 // Move |window_| to the 2nd. | 272 // Move |window_| to the 2nd. |
276 window_->SetBoundsInScreen(gfx::Rect(300, 20, 50, 50), | 273 window_->SetBoundsInScreen(gfx::Rect(300, 20, 50, 50), |
277 ScreenUtil::GetSecondaryDisplay()); | 274 display_manager()->GetSecondaryDisplay()); |
278 aura::Window::Windows root_windows = | 275 aura::Window::Windows root_windows = |
279 Shell::GetInstance()->GetAllRootWindows(); | 276 Shell::GetInstance()->GetAllRootWindows(); |
280 EXPECT_EQ(root_windows[1], window_->GetRootWindow()); | 277 EXPECT_EQ(root_windows[1], window_->GetRootWindow()); |
281 | 278 |
282 // The point is on the 2nd host. (50,70) - ro | 279 // The point is on the 2nd host. (50,70) - ro |
283 EXPECT_EQ("210,70", ConvertHostPointToScreen(60, 70)); | 280 EXPECT_EQ("210,70", ConvertHostPointToScreen(60, 70)); |
284 // The point is out of the host windows. | 281 // The point is out of the host windows. |
285 EXPECT_EQ("210,-50", ConvertHostPointToScreen(60, -50)); | 282 EXPECT_EQ("210,-50", ConvertHostPointToScreen(60, -50)); |
286 // The point is on the 2nd host. Point on 1nd host (60, 60) | 283 // The point is on the 2nd host. Point on 1nd host (60, 60) |
287 // 1/2 * 1.5 = (45,45) | 284 // 1/2 * 1.5 = (45,45) |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
325 // to convert the event to screen coordinates. The ScreenPositionClient is | 322 // to convert the event to screen coordinates. The ScreenPositionClient is |
326 // detached from the root window prior to the root window being destroyed. Test | 323 // detached from the root window prior to the root window being destroyed. Test |
327 // that no events are dispatched at this time. | 324 // that no events are dispatched at this time. |
328 TEST_F(ScreenPositionControllerTest, | 325 TEST_F(ScreenPositionControllerTest, |
329 MAYBE_ConvertToScreenWhileRemovingSecondaryDisplay) { | 326 MAYBE_ConvertToScreenWhileRemovingSecondaryDisplay) { |
330 UpdateDisplay("600x600,600x600"); | 327 UpdateDisplay("600x600,600x600"); |
331 RunAllPendingInMessageLoop(); | 328 RunAllPendingInMessageLoop(); |
332 | 329 |
333 // Create a window on the secondary display. | 330 // Create a window on the secondary display. |
334 window_->SetBoundsInScreen(gfx::Rect(600, 0, 400, 400), | 331 window_->SetBoundsInScreen(gfx::Rect(600, 0, 400, 400), |
335 ScreenUtil::GetSecondaryDisplay()); | 332 display_manager()->GetSecondaryDisplay()); |
336 | 333 |
337 // Move the mouse cursor over |window_|. Synthetic mouse moves are dispatched | 334 // Move the mouse cursor over |window_|. Synthetic mouse moves are dispatched |
338 // asynchronously when a window which contains the mouse cursor is destroyed. | 335 // asynchronously when a window which contains the mouse cursor is destroyed. |
339 // We want to check that none of these synthetic events are dispatched after | 336 // We want to check that none of these synthetic events are dispatched after |
340 // ScreenPositionClient has been detached from the root window. | 337 // ScreenPositionClient has been detached from the root window. |
341 GetEventGenerator().MoveMouseTo(800, 200); | 338 GetEventGenerator().MoveMouseTo(800, 200); |
342 EXPECT_TRUE(window_->GetBoundsInScreen().Contains( | 339 EXPECT_TRUE(window_->GetBoundsInScreen().Contains( |
343 aura::Env::GetInstance()->last_mouse_location())); | 340 aura::Env::GetInstance()->last_mouse_location())); |
344 | 341 |
345 aura::Window::Windows root_windows = | 342 aura::Window::Windows root_windows = |
(...skipping 15 matching lines...) Expand all Loading... |
361 // destroyed. | 358 // destroyed. |
362 EXPECT_FALSE(tracker.Contains(root_windows[1])); | 359 EXPECT_FALSE(tracker.Contains(root_windows[1])); |
363 | 360 |
364 // 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 |
365 // coordinates. | 362 // coordinates. |
366 EXPECT_TRUE(event_handler->could_convert_to_screen()); | 363 EXPECT_TRUE(event_handler->could_convert_to_screen()); |
367 } | 364 } |
368 | 365 |
369 } // namespace test | 366 } // namespace test |
370 } // namespace ash | 367 } // namespace ash |
OLD | NEW |