| 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 334 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 345 float touch_radius_x_; | 345 float touch_radius_x_; |
| 346 float touch_radius_y_; | 346 float touch_radius_y_; |
| 347 float scroll_x_offset_; | 347 float scroll_x_offset_; |
| 348 float scroll_y_offset_; | 348 float scroll_y_offset_; |
| 349 float scroll_x_offset_ordinal_; | 349 float scroll_x_offset_ordinal_; |
| 350 float scroll_y_offset_ordinal_; | 350 float scroll_y_offset_ordinal_; |
| 351 | 351 |
| 352 DISALLOW_COPY_AND_ASSIGN(TestEventHandler); | 352 DISALLOW_COPY_AND_ASSIGN(TestEventHandler); |
| 353 }; | 353 }; |
| 354 | 354 |
| 355 gfx::Display::Rotation GetStoredRotation(int64 id) { | |
| 356 return Shell::GetInstance()->display_manager()->GetDisplayInfo(id).rotation(); | |
| 357 } | |
| 358 | |
| 359 float GetStoredUIScale(int64 id) { | 355 float GetStoredUIScale(int64 id) { |
| 360 return Shell::GetInstance()->display_manager()->GetDisplayInfo(id). | 356 return Shell::GetInstance()->display_manager()->GetDisplayInfo(id). |
| 361 GetEffectiveUIScale(); | 357 GetEffectiveUIScale(); |
| 362 } | 358 } |
| 363 | 359 |
| 364 #if defined(USE_X11) | 360 #if defined(USE_X11) |
| 365 void GetPrimaryAndSeconary(aura::Window** primary, | 361 void GetPrimaryAndSeconary(aura::Window** primary, |
| 366 aura::Window** secondary) { | 362 aura::Window** secondary) { |
| 367 *primary = Shell::GetPrimaryRootWindow(); | 363 *primary = Shell::GetPrimaryRootWindow(); |
| 368 aura::Window::Windows root_windows = Shell::GetAllRootWindows(); | 364 aura::Window::Windows root_windows = Shell::GetAllRootWindows(); |
| (...skipping 181 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 550 EXPECT_LE(1, observer.GetActivationChangedCountAndReset()); | 546 EXPECT_LE(1, observer.GetActivationChangedCountAndReset()); |
| 551 } | 547 } |
| 552 | 548 |
| 553 namespace { | 549 namespace { |
| 554 | 550 |
| 555 DisplayInfo CreateDisplayInfo(int64 id, | 551 DisplayInfo CreateDisplayInfo(int64 id, |
| 556 int y, | 552 int y, |
| 557 gfx::Display::Rotation rotation) { | 553 gfx::Display::Rotation rotation) { |
| 558 DisplayInfo info(id, "", false); | 554 DisplayInfo info(id, "", false); |
| 559 info.SetBounds(gfx::Rect(0, y, 500, 500)); | 555 info.SetBounds(gfx::Rect(0, y, 500, 500)); |
| 560 info.set_rotation(rotation); | 556 info.SetRotation(rotation, gfx::Display::ROTATION_SOURCE_ACTIVE); |
| 561 return info; | 557 return info; |
| 562 } | 558 } |
| 563 | 559 |
| 564 DisplayInfo CreateMirroredDisplayInfo(int64 id, | 560 DisplayInfo CreateMirroredDisplayInfo(int64 id, |
| 565 float device_scale_factor) { | 561 float device_scale_factor) { |
| 566 DisplayInfo info = CreateDisplayInfo(id, 0, gfx::Display::ROTATE_0); | 562 DisplayInfo info = CreateDisplayInfo(id, 0, gfx::Display::ROTATE_0); |
| 567 info.set_device_scale_factor(device_scale_factor); | 563 info.set_device_scale_factor(device_scale_factor); |
| 568 return info; | 564 return info; |
| 569 } | 565 } |
| 570 | 566 |
| (...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 679 // No change | 675 // No change |
| 680 UpdateDisplay("400x500*2,300x300"); | 676 UpdateDisplay("400x500*2,300x300"); |
| 681 // We still call into Pre/PostDisplayConfigurationChange(). | 677 // We still call into Pre/PostDisplayConfigurationChange(). |
| 682 EXPECT_EQ(1, observer.CountAndReset()); | 678 EXPECT_EQ(1, observer.CountAndReset()); |
| 683 EXPECT_EQ(0, observer.GetFocusChangedCountAndReset()); | 679 EXPECT_EQ(0, observer.GetFocusChangedCountAndReset()); |
| 684 EXPECT_EQ(0, observer.GetActivationChangedCountAndReset()); | 680 EXPECT_EQ(0, observer.GetActivationChangedCountAndReset()); |
| 685 | 681 |
| 686 // Rotation | 682 // Rotation |
| 687 observer.GetRotationChangedCountAndReset(); // we only want to reset. | 683 observer.GetRotationChangedCountAndReset(); // we only want to reset. |
| 688 int64 primary_id = GetPrimaryDisplay().id(); | 684 int64 primary_id = GetPrimaryDisplay().id(); |
| 689 display_manager->SetDisplayRotation(primary_id, gfx::Display::ROTATE_90); | 685 display_manager->SetDisplayRotation(primary_id, gfx::Display::ROTATE_90, |
| 686 gfx::Display::ROTATION_SOURCE_ACTIVE); |
| 690 EXPECT_EQ(1, observer.GetRotationChangedCountAndReset()); | 687 EXPECT_EQ(1, observer.GetRotationChangedCountAndReset()); |
| 691 EXPECT_EQ(1, observer.CountAndReset()); | 688 EXPECT_EQ(1, observer.CountAndReset()); |
| 692 EXPECT_EQ(0, observer.GetFocusChangedCountAndReset()); | 689 EXPECT_EQ(0, observer.GetFocusChangedCountAndReset()); |
| 693 EXPECT_EQ(0, observer.GetActivationChangedCountAndReset()); | 690 EXPECT_EQ(0, observer.GetActivationChangedCountAndReset()); |
| 694 display_manager->SetDisplayRotation(primary_id, gfx::Display::ROTATE_90); | 691 display_manager->SetDisplayRotation(primary_id, gfx::Display::ROTATE_90, |
| 692 gfx::Display::ROTATION_SOURCE_ACTIVE); |
| 695 EXPECT_EQ(0, observer.GetRotationChangedCountAndReset()); | 693 EXPECT_EQ(0, observer.GetRotationChangedCountAndReset()); |
| 696 EXPECT_EQ(0, observer.CountAndReset()); | 694 EXPECT_EQ(0, observer.CountAndReset()); |
| 697 EXPECT_EQ(0, observer.GetFocusChangedCountAndReset()); | 695 EXPECT_EQ(0, observer.GetFocusChangedCountAndReset()); |
| 698 EXPECT_EQ(0, observer.GetActivationChangedCountAndReset()); | 696 EXPECT_EQ(0, observer.GetActivationChangedCountAndReset()); |
| 699 | 697 |
| 700 // UI scale is eanbled only on internal display. | 698 // UI scale is eanbled only on internal display. |
| 701 int64 secondary_id = GetSecondaryDisplay().id(); | 699 int64 secondary_id = GetSecondaryDisplay().id(); |
| 702 test::DisplayManagerTestApi(display_manager) | 700 test::DisplayManagerTestApi(display_manager) |
| 703 .SetInternalDisplayId(secondary_id); | 701 .SetInternalDisplayId(secondary_id); |
| 704 | 702 |
| (...skipping 334 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1039 aura::Window::Windows root_windows = Shell::GetAllRootWindows(); | 1037 aura::Window::Windows root_windows = Shell::GetAllRootWindows(); |
| 1040 ui::test::EventGenerator generator1(root_windows[0]); | 1038 ui::test::EventGenerator generator1(root_windows[0]); |
| 1041 | 1039 |
| 1042 TestObserver observer; | 1040 TestObserver observer; |
| 1043 EXPECT_EQ("120x200", root_windows[0]->bounds().size().ToString()); | 1041 EXPECT_EQ("120x200", root_windows[0]->bounds().size().ToString()); |
| 1044 EXPECT_EQ("150x200", root_windows[1]->bounds().size().ToString()); | 1042 EXPECT_EQ("150x200", root_windows[1]->bounds().size().ToString()); |
| 1045 EXPECT_EQ("120,0 150x200", | 1043 EXPECT_EQ("120,0 150x200", |
| 1046 ScreenUtil::GetSecondaryDisplay().bounds().ToString()); | 1044 ScreenUtil::GetSecondaryDisplay().bounds().ToString()); |
| 1047 generator1.MoveMouseToInHost(50, 40); | 1045 generator1.MoveMouseToInHost(50, 40); |
| 1048 EXPECT_EQ("50,40", event_handler.GetLocationAndReset()); | 1046 EXPECT_EQ("50,40", event_handler.GetLocationAndReset()); |
| 1049 EXPECT_EQ(gfx::Display::ROTATE_0, GetStoredRotation(display1.id())); | 1047 EXPECT_EQ(gfx::Display::ROTATE_0, GetActiveDisplayRotation(display1.id())); |
| 1050 EXPECT_EQ(gfx::Display::ROTATE_0, GetStoredRotation(display2_id)); | 1048 EXPECT_EQ(gfx::Display::ROTATE_0, GetActiveDisplayRotation(display2_id)); |
| 1051 EXPECT_EQ(0, observer.GetRotationChangedCountAndReset()); | 1049 EXPECT_EQ(0, observer.GetRotationChangedCountAndReset()); |
| 1052 | 1050 |
| 1053 display_manager->SetDisplayRotation(display1.id(), | 1051 display_manager->SetDisplayRotation(display1.id(), gfx::Display::ROTATE_90, |
| 1054 gfx::Display::ROTATE_90); | 1052 gfx::Display::ROTATION_SOURCE_ACTIVE); |
| 1055 EXPECT_EQ("200x120", root_windows[0]->bounds().size().ToString()); | 1053 EXPECT_EQ("200x120", root_windows[0]->bounds().size().ToString()); |
| 1056 EXPECT_EQ("150x200", root_windows[1]->bounds().size().ToString()); | 1054 EXPECT_EQ("150x200", root_windows[1]->bounds().size().ToString()); |
| 1057 EXPECT_EQ("200,0 150x200", | 1055 EXPECT_EQ("200,0 150x200", |
| 1058 ScreenUtil::GetSecondaryDisplay().bounds().ToString()); | 1056 ScreenUtil::GetSecondaryDisplay().bounds().ToString()); |
| 1059 generator1.MoveMouseToInHost(50, 40); | 1057 generator1.MoveMouseToInHost(50, 40); |
| 1060 EXPECT_EQ("40,69", event_handler.GetLocationAndReset()); | 1058 EXPECT_EQ("40,69", event_handler.GetLocationAndReset()); |
| 1061 EXPECT_EQ(gfx::Display::ROTATE_90, GetStoredRotation(display1.id())); | 1059 EXPECT_EQ(gfx::Display::ROTATE_90, GetActiveDisplayRotation(display1.id())); |
| 1062 EXPECT_EQ(gfx::Display::ROTATE_0, GetStoredRotation(display2_id)); | 1060 EXPECT_EQ(gfx::Display::ROTATE_0, GetActiveDisplayRotation(display2_id)); |
| 1063 EXPECT_EQ(1, observer.GetRotationChangedCountAndReset()); | 1061 EXPECT_EQ(1, observer.GetRotationChangedCountAndReset()); |
| 1064 | 1062 |
| 1065 DisplayLayout display_layout(DisplayLayout::BOTTOM, 50); | 1063 DisplayLayout display_layout(DisplayLayout::BOTTOM, 50); |
| 1066 display_manager->SetLayoutForCurrentDisplays(display_layout); | 1064 display_manager->SetLayoutForCurrentDisplays(display_layout); |
| 1067 EXPECT_EQ("50,120 150x200", | 1065 EXPECT_EQ("50,120 150x200", |
| 1068 ScreenUtil::GetSecondaryDisplay().bounds().ToString()); | 1066 ScreenUtil::GetSecondaryDisplay().bounds().ToString()); |
| 1069 | 1067 |
| 1070 display_manager->SetDisplayRotation(display2_id, | 1068 display_manager->SetDisplayRotation(display2_id, gfx::Display::ROTATE_270, |
| 1071 gfx::Display::ROTATE_270); | 1069 gfx::Display::ROTATION_SOURCE_ACTIVE); |
| 1072 EXPECT_EQ("200x120", root_windows[0]->bounds().size().ToString()); | 1070 EXPECT_EQ("200x120", root_windows[0]->bounds().size().ToString()); |
| 1073 EXPECT_EQ("200x150", root_windows[1]->bounds().size().ToString()); | 1071 EXPECT_EQ("200x150", root_windows[1]->bounds().size().ToString()); |
| 1074 EXPECT_EQ("50,120 200x150", | 1072 EXPECT_EQ("50,120 200x150", |
| 1075 ScreenUtil::GetSecondaryDisplay().bounds().ToString()); | 1073 ScreenUtil::GetSecondaryDisplay().bounds().ToString()); |
| 1076 EXPECT_EQ(gfx::Display::ROTATE_90, GetStoredRotation(display1.id())); | 1074 EXPECT_EQ(gfx::Display::ROTATE_90, GetActiveDisplayRotation(display1.id())); |
| 1077 EXPECT_EQ(gfx::Display::ROTATE_270, GetStoredRotation(display2_id)); | 1075 EXPECT_EQ(gfx::Display::ROTATE_270, GetActiveDisplayRotation(display2_id)); |
| 1078 EXPECT_EQ(1, observer.GetRotationChangedCountAndReset()); | 1076 EXPECT_EQ(1, observer.GetRotationChangedCountAndReset()); |
| 1079 | 1077 |
| 1080 #if !defined(OS_WIN) | 1078 #if !defined(OS_WIN) |
| 1081 ui::test::EventGenerator generator2(root_windows[1]); | 1079 ui::test::EventGenerator generator2(root_windows[1]); |
| 1082 generator2.MoveMouseToInHost(50, 40); | 1080 generator2.MoveMouseToInHost(50, 40); |
| 1083 EXPECT_EQ("179,25", event_handler.GetLocationAndReset()); | 1081 EXPECT_EQ("179,25", event_handler.GetLocationAndReset()); |
| 1084 display_manager->SetDisplayRotation(display1.id(), | 1082 display_manager->SetDisplayRotation(display1.id(), gfx::Display::ROTATE_180, |
| 1085 gfx::Display::ROTATE_180); | 1083 gfx::Display::ROTATION_SOURCE_ACTIVE); |
| 1086 | 1084 |
| 1087 EXPECT_EQ("120x200", root_windows[0]->bounds().size().ToString()); | 1085 EXPECT_EQ("120x200", root_windows[0]->bounds().size().ToString()); |
| 1088 EXPECT_EQ("200x150", root_windows[1]->bounds().size().ToString()); | 1086 EXPECT_EQ("200x150", root_windows[1]->bounds().size().ToString()); |
| 1089 // Dislay must share at least 100, so the x's offset becomes 20. | 1087 // Dislay must share at least 100, so the x's offset becomes 20. |
| 1090 EXPECT_EQ("20,200 200x150", | 1088 EXPECT_EQ("20,200 200x150", |
| 1091 ScreenUtil::GetSecondaryDisplay().bounds().ToString()); | 1089 ScreenUtil::GetSecondaryDisplay().bounds().ToString()); |
| 1092 EXPECT_EQ(gfx::Display::ROTATE_180, GetStoredRotation(display1.id())); | 1090 EXPECT_EQ(gfx::Display::ROTATE_180, GetActiveDisplayRotation(display1.id())); |
| 1093 EXPECT_EQ(gfx::Display::ROTATE_270, GetStoredRotation(display2_id)); | 1091 EXPECT_EQ(gfx::Display::ROTATE_270, GetActiveDisplayRotation(display2_id)); |
| 1094 EXPECT_EQ(1, observer.GetRotationChangedCountAndReset()); | 1092 EXPECT_EQ(1, observer.GetRotationChangedCountAndReset()); |
| 1095 | 1093 |
| 1096 generator1.MoveMouseToInHost(50, 40); | 1094 generator1.MoveMouseToInHost(50, 40); |
| 1097 EXPECT_EQ("69,159", event_handler.GetLocationAndReset()); | 1095 EXPECT_EQ("69,159", event_handler.GetLocationAndReset()); |
| 1098 #endif | 1096 #endif |
| 1099 | 1097 |
| 1100 Shell::GetInstance()->RemovePreTargetHandler(&event_handler); | 1098 Shell::GetInstance()->RemovePreTargetHandler(&event_handler); |
| 1101 } | 1099 } |
| 1102 | 1100 |
| 1103 TEST_F(DisplayControllerTest, ScaleRootWindow) { | 1101 TEST_F(DisplayControllerTest, ScaleRootWindow) { |
| (...skipping 397 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1501 widget->GetNativeWindow()->GetRootWindow()); | 1499 widget->GetNativeWindow()->GetRootWindow()); |
| 1502 event_generator.MoveMouseToCenterOf(widget->GetNativeWindow()); | 1500 event_generator.MoveMouseToCenterOf(widget->GetNativeWindow()); |
| 1503 | 1501 |
| 1504 UpdateDisplay("300x300"); | 1502 UpdateDisplay("300x300"); |
| 1505 watcher.Stop(); | 1503 watcher.Stop(); |
| 1506 | 1504 |
| 1507 widget->CloseNow(); | 1505 widget->CloseNow(); |
| 1508 } | 1506 } |
| 1509 | 1507 |
| 1510 } // namespace ash | 1508 } // namespace ash |
| OLD | NEW |