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/display_controller.h" | 5 #include "ash/display/display_controller.h" |
6 | 6 |
7 #include "ash/ash_switches.h" | 7 #include "ash/ash_switches.h" |
8 #include "ash/display/display_info.h" | 8 #include "ash/display/display_info.h" |
9 #include "ash/display/display_layout_store.h" | 9 #include "ash/display/display_layout_store.h" |
10 #include "ash/display/display_manager.h" | 10 #include "ash/display/display_manager.h" |
(...skipping 943 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
954 EXPECT_EQ(third_display_info.id(), ScreenUtil::GetSecondaryDisplay().id()); | 954 EXPECT_EQ(third_display_info.id(), ScreenUtil::GetSecondaryDisplay().id()); |
955 EXPECT_EQ( | 955 EXPECT_EQ( |
956 primary_root, | 956 primary_root, |
957 display_controller->GetRootWindowForDisplayId(primary_display.id())); | 957 display_controller->GetRootWindowForDisplayId(primary_display.id())); |
958 EXPECT_NE( | 958 EXPECT_NE( |
959 primary_root, | 959 primary_root, |
960 display_controller->GetRootWindowForDisplayId(third_display_info.id())); | 960 display_controller->GetRootWindowForDisplayId(third_display_info.id())); |
961 EXPECT_TRUE(primary_root->Contains(shelf_window)); | 961 EXPECT_TRUE(primary_root->Contains(shelf_window)); |
962 } | 962 } |
963 | 963 |
964 TEST_F(DisplayControllerTest, CursorDeviceScaleFactorSwapPrimary) { | |
965 if (!SupportsMultipleDisplays()) | |
966 return; | |
967 | |
968 DisplayController* display_controller = | |
969 Shell::GetInstance()->display_controller(); | |
970 | |
971 UpdateDisplay("200x200,200x200*2"); | |
972 gfx::Display primary_display = Shell::GetScreen()->GetPrimaryDisplay(); | |
973 gfx::Display secondary_display = ScreenUtil::GetSecondaryDisplay(); | |
974 | |
975 aura::Window* primary_root = | |
976 display_controller->GetRootWindowForDisplayId(primary_display.id()); | |
977 aura::Window* secondary_root = | |
978 display_controller->GetRootWindowForDisplayId(secondary_display.id()); | |
979 EXPECT_NE(primary_root, secondary_root); | |
980 | |
981 test::CursorManagerTestApi test_api(Shell::GetInstance()->cursor_manager()); | |
982 | |
983 EXPECT_EQ(1.0f, primary_root->GetHost()->compositor()-> | |
984 device_scale_factor()); | |
985 primary_root->MoveCursorTo(gfx::Point(50, 50)); | |
986 EXPECT_EQ(1.0f, test_api.GetCurrentCursor().device_scale_factor()); | |
987 EXPECT_EQ(2.0f, secondary_root->GetHost()->compositor()-> | |
988 device_scale_factor()); | |
989 secondary_root->MoveCursorTo(gfx::Point(50, 50)); | |
990 EXPECT_EQ(2.0f, test_api.GetCurrentCursor().device_scale_factor()); | |
991 | |
992 // Switch primary and secondary | |
993 display_controller->SetPrimaryDisplay(secondary_display); | |
994 | |
995 // Cursor's device scale factor should be updated accroding to the swap of | |
996 // primary and secondary. | |
997 EXPECT_EQ(1.0f, secondary_root->GetHost()->compositor()-> | |
998 device_scale_factor()); | |
999 secondary_root->MoveCursorTo(gfx::Point(50, 50)); | |
1000 EXPECT_EQ(1.0f, test_api.GetCurrentCursor().device_scale_factor()); | |
1001 primary_root->MoveCursorTo(gfx::Point(50, 50)); | |
1002 EXPECT_EQ(2.0f, primary_root->GetHost()->compositor()-> | |
1003 device_scale_factor()); | |
1004 EXPECT_EQ(2.0f, test_api.GetCurrentCursor().device_scale_factor()); | |
1005 | |
1006 // Deleting 2nd display. | |
1007 UpdateDisplay("200x200"); | |
1008 RunAllPendingInMessageLoop(); // RootWindow is deleted in a posted task. | |
1009 | |
1010 // Cursor's device scale factor should be updated even without moving cursor. | |
1011 EXPECT_EQ(1.0f, test_api.GetCurrentCursor().device_scale_factor()); | |
1012 | |
1013 primary_root->MoveCursorTo(gfx::Point(50, 50)); | |
1014 EXPECT_EQ(1.0f, primary_root->GetHost()->compositor()-> | |
1015 device_scale_factor()); | |
1016 EXPECT_EQ(1.0f, test_api.GetCurrentCursor().device_scale_factor()); | |
1017 } | |
1018 | |
1019 TEST_F(DisplayControllerTest, OverscanInsets) { | 964 TEST_F(DisplayControllerTest, OverscanInsets) { |
1020 if (!SupportsMultipleDisplays()) | 965 if (!SupportsMultipleDisplays()) |
1021 return; | 966 return; |
1022 | 967 |
1023 DisplayController* display_controller = | 968 DisplayController* display_controller = |
1024 Shell::GetInstance()->display_controller(); | 969 Shell::GetInstance()->display_controller(); |
1025 TestEventHandler event_handler; | 970 TestEventHandler event_handler; |
1026 Shell::GetInstance()->AddPreTargetHandler(&event_handler); | 971 Shell::GetInstance()->AddPreTargetHandler(&event_handler); |
1027 | 972 |
1028 UpdateDisplay("120x200,300x400*2"); | 973 UpdateDisplay("120x200,300x400*2"); |
(...skipping 338 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1367 EXPECT_EQ("aura_root_0", GetXWindowName(primary->GetHost())); | 1312 EXPECT_EQ("aura_root_0", GetXWindowName(primary->GetHost())); |
1368 EXPECT_EQ("aura_root_x", GetXWindowName(secondary->GetHost())); | 1313 EXPECT_EQ("aura_root_x", GetXWindowName(secondary->GetHost())); |
1369 | 1314 |
1370 // Switching back to single display. | 1315 // Switching back to single display. |
1371 UpdateDisplay("300x400"); | 1316 UpdateDisplay("300x400"); |
1372 EXPECT_EQ("aura_root_0", GetXWindowName( | 1317 EXPECT_EQ("aura_root_0", GetXWindowName( |
1373 Shell::GetPrimaryRootWindow()->GetHost())); | 1318 Shell::GetPrimaryRootWindow()->GetHost())); |
1374 } | 1319 } |
1375 #endif | 1320 #endif |
1376 | 1321 |
| 1322 TEST_F(DisplayControllerTest, UpdateMouseLocationAfterDisplayChange) { |
| 1323 if (!SupportsMultipleDisplays()) |
| 1324 return; |
| 1325 |
| 1326 UpdateDisplay("200x200,300x300"); |
| 1327 aura::Window::Windows root_windows = Shell::GetAllRootWindows(); |
| 1328 |
| 1329 aura::Env* env = aura::Env::GetInstance(); |
| 1330 |
| 1331 ui::test::EventGenerator generator(root_windows[0]); |
| 1332 |
| 1333 // Set the initial position. |
| 1334 generator.MoveMouseToInHost(350, 150); |
| 1335 EXPECT_EQ("350,150", env->last_mouse_location().ToString()); |
| 1336 |
| 1337 // A mouse pointer will stay in the 2nd display. |
| 1338 UpdateDisplay("300x300,200x200"); |
| 1339 EXPECT_EQ("450,50", env->last_mouse_location().ToString()); |
| 1340 |
| 1341 // A mouse pointer will be outside of displays and move to the |
| 1342 // center of 2nd display. |
| 1343 UpdateDisplay("300x300,100x100"); |
| 1344 EXPECT_EQ("350,50", env->last_mouse_location().ToString()); |
| 1345 |
| 1346 // 2nd display was disconnected, and the cursor is |
| 1347 // now in the 1st display. |
| 1348 UpdateDisplay("400x400"); |
| 1349 EXPECT_EQ("50,350", env->last_mouse_location().ToString()); |
| 1350 |
| 1351 // 1st display's resolution has changed, and the mouse pointer is |
| 1352 // now outside. Move the mouse pointer to the center of 1st display. |
| 1353 UpdateDisplay("300x300"); |
| 1354 EXPECT_EQ("150,150", env->last_mouse_location().ToString()); |
| 1355 |
| 1356 // Move the mouse pointer to the bottom of 1st display. |
| 1357 generator.MoveMouseToInHost(150, 290); |
| 1358 EXPECT_EQ("150,290", env->last_mouse_location().ToString()); |
| 1359 |
| 1360 // The mouse pointer is now on 2nd display. |
| 1361 UpdateDisplay("300x280,200x200"); |
| 1362 EXPECT_EQ("450,10", env->last_mouse_location().ToString()); |
| 1363 } |
| 1364 |
| 1365 TEST_F(DisplayControllerTest, UpdateMouseLocationAfterDisplayChange_2ndOnLeft) { |
| 1366 if (!SupportsMultipleDisplays()) |
| 1367 return; |
| 1368 |
| 1369 // Set the 2nd display on the left. |
| 1370 DisplayLayoutStore* layout_store = |
| 1371 Shell::GetInstance()->display_manager()->layout_store(); |
| 1372 DisplayLayout layout = layout_store->default_display_layout(); |
| 1373 layout.position = DisplayLayout::LEFT; |
| 1374 layout_store->SetDefaultDisplayLayout(layout); |
| 1375 |
| 1376 UpdateDisplay("200x200,300x300"); |
| 1377 aura::Window::Windows root_windows = Shell::GetAllRootWindows(); |
| 1378 |
| 1379 EXPECT_EQ("-300,0 300x300", |
| 1380 ScreenUtil::GetSecondaryDisplay().bounds().ToString()); |
| 1381 |
| 1382 aura::Env* env = aura::Env::GetInstance(); |
| 1383 |
| 1384 // Set the initial position. |
| 1385 root_windows[0]->MoveCursorTo(gfx::Point(-150, 250)); |
| 1386 EXPECT_EQ("-150,250", env->last_mouse_location().ToString()); |
| 1387 |
| 1388 // A mouse pointer will stay in 2nd display. |
| 1389 UpdateDisplay("300x300,200x300"); |
| 1390 EXPECT_EQ("-50,150", env->last_mouse_location().ToString()); |
| 1391 |
| 1392 // A mouse pointer will be outside of displays and move to the |
| 1393 // center of 2nd display. |
| 1394 UpdateDisplay("300x300,200x100"); |
| 1395 EXPECT_EQ("-100,50", env->last_mouse_location().ToString()); |
| 1396 |
| 1397 // 2nd display was disconnected. Mouse pointer should move to |
| 1398 // 1st display. |
| 1399 UpdateDisplay("300x300"); |
| 1400 EXPECT_EQ("150,150", env->last_mouse_location().ToString()); |
| 1401 } |
| 1402 |
| 1403 // Test that the cursor swaps displays and that its scale factor and rotation |
| 1404 // are updated when the primary display is swapped. |
| 1405 TEST_F(DisplayControllerTest, |
| 1406 UpdateMouseLocationAfterDisplayChange_SwapPrimary) { |
| 1407 if (!SupportsMultipleDisplays()) |
| 1408 return; |
| 1409 |
| 1410 UpdateDisplay("200x200,200x200*2/r"); |
| 1411 |
| 1412 aura::Env* env = aura::Env::GetInstance(); |
| 1413 Shell* shell = Shell::GetInstance(); |
| 1414 DisplayController* display_controller = shell->display_controller(); |
| 1415 test::CursorManagerTestApi test_api(shell->cursor_manager()); |
| 1416 |
| 1417 display_controller->GetPrimaryRootWindow()->MoveCursorTo(gfx::Point(20, 50)); |
| 1418 |
| 1419 EXPECT_EQ("20,50", env->last_mouse_location().ToString()); |
| 1420 EXPECT_EQ(1.0f, test_api.GetCurrentCursor().device_scale_factor()); |
| 1421 EXPECT_EQ(gfx::Display::ROTATE_0, test_api.GetCurrentCursorRotation()); |
| 1422 |
| 1423 display_controller->SwapPrimaryDisplay(); |
| 1424 |
| 1425 EXPECT_EQ("20,50", env->last_mouse_location().ToString()); |
| 1426 EXPECT_EQ(2.0f, test_api.GetCurrentCursor().device_scale_factor()); |
| 1427 EXPECT_EQ(gfx::Display::ROTATE_90, test_api.GetCurrentCursorRotation()); |
| 1428 } |
| 1429 |
| 1430 // Test that the cursor moves to the other display and that its scale factor |
| 1431 // and rotation are updated when the primary display is disconnected. |
| 1432 TEST_F(DisplayControllerTest, |
| 1433 UpdateMouseLocationAfterDisplayChange_PrimaryDisconnected) { |
| 1434 if (!SupportsMultipleDisplays()) |
| 1435 return; |
| 1436 |
| 1437 aura::Env* env = aura::Env::GetInstance(); |
| 1438 Shell* shell = Shell::GetInstance(); |
| 1439 DisplayController* display_controller = shell->display_controller(); |
| 1440 test::CursorManagerTestApi test_api(shell->cursor_manager()); |
| 1441 |
| 1442 UpdateDisplay("300x300*2/r,200x200"); |
| 1443 // Swap the primary display to make it possible to remove the primary display |
| 1444 // via UpdateDisplay(). |
| 1445 display_controller->SwapPrimaryDisplay(); |
| 1446 int primary_display_id = display_controller->GetPrimaryDisplayId(); |
| 1447 |
| 1448 display_controller->GetPrimaryRootWindow()->MoveCursorTo(gfx::Point(20, 50)); |
| 1449 |
| 1450 EXPECT_EQ("20,50", env->last_mouse_location().ToString()); |
| 1451 EXPECT_EQ(1.0f, test_api.GetCurrentCursor().device_scale_factor()); |
| 1452 EXPECT_EQ(gfx::Display::ROTATE_0, test_api.GetCurrentCursorRotation()); |
| 1453 |
| 1454 UpdateDisplay("300x300*2/r"); |
| 1455 ASSERT_NE(primary_display_id, display_controller->GetPrimaryDisplayId()); |
| 1456 |
| 1457 // Cursor should be centered on the remaining display. |
| 1458 EXPECT_EQ("75,75", env->last_mouse_location().ToString()); |
| 1459 EXPECT_EQ(2.0f, test_api.GetCurrentCursor().device_scale_factor()); |
| 1460 EXPECT_EQ(gfx::Display::ROTATE_90, test_api.GetCurrentCursorRotation()); |
| 1461 } |
| 1462 |
1377 } // namespace ash | 1463 } // namespace ash |
OLD | NEW |