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 240 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
251 | 251 |
252 float touch_radius_x() { return touch_radius_x_; } | 252 float touch_radius_x() { return touch_radius_x_; } |
253 float touch_radius_y() { return touch_radius_y_; } | 253 float touch_radius_y() { return touch_radius_y_; } |
254 float scroll_x_offset() { return scroll_x_offset_; } | 254 float scroll_x_offset() { return scroll_x_offset_; } |
255 float scroll_y_offset() { return scroll_y_offset_; } | 255 float scroll_y_offset() { return scroll_y_offset_; } |
256 float scroll_x_offset_ordinal() { return scroll_x_offset_ordinal_; } | 256 float scroll_x_offset_ordinal() { return scroll_x_offset_ordinal_; } |
257 float scroll_y_offset_ordinal() { return scroll_y_offset_ordinal_; } | 257 float scroll_y_offset_ordinal() { return scroll_y_offset_ordinal_; } |
258 | 258 |
259 private: | 259 private: |
260 gfx::Point mouse_location_; | 260 gfx::Point mouse_location_; |
261 aura::RootWindow* target_root_; | 261 aura::Window* target_root_; |
262 | 262 |
263 float touch_radius_x_; | 263 float touch_radius_x_; |
264 float touch_radius_y_; | 264 float touch_radius_y_; |
265 float scroll_x_offset_; | 265 float scroll_x_offset_; |
266 float scroll_y_offset_; | 266 float scroll_y_offset_; |
267 float scroll_x_offset_ordinal_; | 267 float scroll_x_offset_ordinal_; |
268 float scroll_y_offset_ordinal_; | 268 float scroll_y_offset_ordinal_; |
269 | 269 |
270 DISALLOW_COPY_AND_ASSIGN(TestEventHandler); | 270 DISALLOW_COPY_AND_ASSIGN(TestEventHandler); |
271 }; | 271 }; |
272 | 272 |
273 gfx::Display::Rotation GetStoredRotation(int64 id) { | 273 gfx::Display::Rotation GetStoredRotation(int64 id) { |
274 return Shell::GetInstance()->display_manager()->GetDisplayInfo(id).rotation(); | 274 return Shell::GetInstance()->display_manager()->GetDisplayInfo(id).rotation(); |
275 } | 275 } |
276 | 276 |
277 float GetStoredUIScale(int64 id) { | 277 float GetStoredUIScale(int64 id) { |
278 return Shell::GetInstance()->display_manager()->GetDisplayInfo(id).ui_scale(); | 278 return Shell::GetInstance()->display_manager()->GetDisplayInfo(id).ui_scale(); |
279 } | 279 } |
280 | 280 |
281 #if defined(USE_X11) | 281 #if defined(USE_X11) |
282 void GetPrimaryAndSeconary(aura::RootWindow** primary, | 282 void GetPrimaryAndSeconary(aura::Window** primary, |
283 aura::RootWindow** secondary) { | 283 aura::Window** secondary) { |
284 *primary = Shell::GetPrimaryRootWindow(); | 284 *primary = Shell::GetPrimaryRootWindow(); |
285 Shell::RootWindowList root_windows = Shell::GetAllRootWindows(); | 285 Shell::RootWindowList root_windows = Shell::GetAllRootWindows(); |
286 *secondary = root_windows[0] == *primary ? root_windows[1] : root_windows[0]; | 286 *secondary = root_windows[0] == *primary ? root_windows[1] : root_windows[0]; |
287 } | 287 } |
288 | 288 |
289 std::string GetXWindowName(aura::RootWindow* window) { | 289 std::string GetXWindowName(aura::RootWindow* window) { |
290 char* name = NULL; | 290 char* name = NULL; |
291 XFetchName(gfx::GetXDisplay(), window->GetAcceleratedWidget(), &name); | 291 XFetchName(gfx::GetXDisplay(), window->GetAcceleratedWidget(), &name); |
292 std::string ret(name); | 292 std::string ret(name); |
293 XFree(name); | 293 XFree(name); |
(...skipping 246 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
540 Shell::GetInstance()->display_manager(); | 540 Shell::GetInstance()->display_manager(); |
541 | 541 |
542 UpdateDisplay("200x200,300x300"); | 542 UpdateDisplay("200x200,300x300"); |
543 gfx::Display primary_display = Shell::GetScreen()->GetPrimaryDisplay(); | 543 gfx::Display primary_display = Shell::GetScreen()->GetPrimaryDisplay(); |
544 gfx::Display secondary_display = ScreenAsh::GetSecondaryDisplay(); | 544 gfx::Display secondary_display = ScreenAsh::GetSecondaryDisplay(); |
545 | 545 |
546 DisplayLayout display_layout(DisplayLayout::RIGHT, 50); | 546 DisplayLayout display_layout(DisplayLayout::RIGHT, 50); |
547 display_manager->SetLayoutForCurrentDisplays(display_layout); | 547 display_manager->SetLayoutForCurrentDisplays(display_layout); |
548 | 548 |
549 EXPECT_NE(primary_display.id(), secondary_display.id()); | 549 EXPECT_NE(primary_display.id(), secondary_display.id()); |
550 aura::RootWindow* primary_root = | 550 aura::Window* primary_root = |
551 display_controller->GetRootWindowForDisplayId(primary_display.id()); | 551 display_controller->GetRootWindowForDisplayId(primary_display.id()); |
552 aura::RootWindow* secondary_root = | 552 aura::Window* secondary_root = |
553 display_controller->GetRootWindowForDisplayId(secondary_display.id()); | 553 display_controller->GetRootWindowForDisplayId(secondary_display.id()); |
554 EXPECT_NE(primary_root, secondary_root); | 554 EXPECT_NE(primary_root, secondary_root); |
555 aura::Window* launcher_window = | 555 aura::Window* launcher_window = |
556 Launcher::ForPrimaryDisplay()->shelf_widget()->GetNativeView(); | 556 Launcher::ForPrimaryDisplay()->shelf_widget()->GetNativeView(); |
557 EXPECT_TRUE(primary_root->Contains(launcher_window)); | 557 EXPECT_TRUE(primary_root->Contains(launcher_window)); |
558 EXPECT_FALSE(secondary_root->Contains(launcher_window)); | 558 EXPECT_FALSE(secondary_root->Contains(launcher_window)); |
559 EXPECT_EQ(primary_display.id(), | 559 EXPECT_EQ(primary_display.id(), |
560 Shell::GetScreen()->GetDisplayNearestPoint( | 560 Shell::GetScreen()->GetDisplayNearestPoint( |
561 gfx::Point(-100, -100)).id()); | 561 gfx::Point(-100, -100)).id()); |
562 EXPECT_EQ(primary_display.id(), | 562 EXPECT_EQ(primary_display.id(), |
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
634 Shell::GetInstance()->display_manager(); | 634 Shell::GetInstance()->display_manager(); |
635 | 635 |
636 UpdateDisplay("200x200,300x300"); | 636 UpdateDisplay("200x200,300x300"); |
637 gfx::Display primary_display = Shell::GetScreen()->GetPrimaryDisplay(); | 637 gfx::Display primary_display = Shell::GetScreen()->GetPrimaryDisplay(); |
638 gfx::Display secondary_display = ScreenAsh::GetSecondaryDisplay(); | 638 gfx::Display secondary_display = ScreenAsh::GetSecondaryDisplay(); |
639 | 639 |
640 DisplayLayout display_layout(DisplayLayout::RIGHT, 50); | 640 DisplayLayout display_layout(DisplayLayout::RIGHT, 50); |
641 display_manager->SetLayoutForCurrentDisplays(display_layout); | 641 display_manager->SetLayoutForCurrentDisplays(display_layout); |
642 | 642 |
643 EXPECT_NE(primary_display.id(), secondary_display.id()); | 643 EXPECT_NE(primary_display.id(), secondary_display.id()); |
644 aura::RootWindow* primary_root = | 644 aura::Window* primary_root = |
645 display_controller->GetRootWindowForDisplayId(primary_display.id()); | 645 display_controller->GetRootWindowForDisplayId(primary_display.id()); |
646 aura::RootWindow* secondary_root = | 646 aura::Window* secondary_root = |
647 display_controller->GetRootWindowForDisplayId(secondary_display.id()); | 647 display_controller->GetRootWindowForDisplayId(secondary_display.id()); |
648 EXPECT_NE(primary_root, secondary_root); | 648 EXPECT_NE(primary_root, secondary_root); |
649 aura::Window* launcher_window = | 649 aura::Window* launcher_window = |
650 Launcher::ForPrimaryDisplay()->shelf_widget()->GetNativeView(); | 650 Launcher::ForPrimaryDisplay()->shelf_widget()->GetNativeView(); |
651 EXPECT_TRUE(primary_root->Contains(launcher_window)); | 651 EXPECT_TRUE(primary_root->Contains(launcher_window)); |
652 EXPECT_FALSE(secondary_root->Contains(launcher_window)); | 652 EXPECT_FALSE(secondary_root->Contains(launcher_window)); |
653 EXPECT_EQ(primary_display.id(), | 653 EXPECT_EQ(primary_display.id(), |
654 Shell::GetScreen()->GetDisplayNearestPoint( | 654 Shell::GetScreen()->GetDisplayNearestPoint( |
655 gfx::Point(-100, -100)).id()); | 655 gfx::Point(-100, -100)).id()); |
656 EXPECT_EQ(primary_display.id(), | 656 EXPECT_EQ(primary_display.id(), |
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
725 Shell::GetInstance()->display_manager(); | 725 Shell::GetInstance()->display_manager(); |
726 | 726 |
727 UpdateDisplay("200x200,300x300"); | 727 UpdateDisplay("200x200,300x300"); |
728 gfx::Display primary_display = Shell::GetScreen()->GetPrimaryDisplay(); | 728 gfx::Display primary_display = Shell::GetScreen()->GetPrimaryDisplay(); |
729 gfx::Display secondary_display = ScreenAsh::GetSecondaryDisplay(); | 729 gfx::Display secondary_display = ScreenAsh::GetSecondaryDisplay(); |
730 | 730 |
731 DisplayLayout display_layout(DisplayLayout::RIGHT, 50); | 731 DisplayLayout display_layout(DisplayLayout::RIGHT, 50); |
732 display_manager->SetLayoutForCurrentDisplays(display_layout); | 732 display_manager->SetLayoutForCurrentDisplays(display_layout); |
733 | 733 |
734 EXPECT_NE(primary_display.id(), secondary_display.id()); | 734 EXPECT_NE(primary_display.id(), secondary_display.id()); |
735 aura::RootWindow* primary_root = | 735 aura::Window* primary_root = |
736 display_controller->GetRootWindowForDisplayId(primary_display.id()); | 736 display_controller->GetRootWindowForDisplayId(primary_display.id()); |
737 aura::RootWindow* secondary_root = | 737 aura::Window* secondary_root = |
738 display_controller->GetRootWindowForDisplayId(secondary_display.id()); | 738 display_controller->GetRootWindowForDisplayId(secondary_display.id()); |
739 aura::Window* launcher_window = | 739 aura::Window* launcher_window = |
740 Launcher::ForPrimaryDisplay()->shelf_widget()->GetNativeView(); | 740 Launcher::ForPrimaryDisplay()->shelf_widget()->GetNativeView(); |
741 EXPECT_TRUE(primary_root->Contains(launcher_window)); | 741 EXPECT_TRUE(primary_root->Contains(launcher_window)); |
742 EXPECT_FALSE(secondary_root->Contains(launcher_window)); | 742 EXPECT_FALSE(secondary_root->Contains(launcher_window)); |
743 EXPECT_NE(primary_root, secondary_root); | 743 EXPECT_NE(primary_root, secondary_root); |
744 EXPECT_EQ(primary_display.id(), | 744 EXPECT_EQ(primary_display.id(), |
745 Shell::GetScreen()->GetDisplayNearestPoint( | 745 Shell::GetScreen()->GetDisplayNearestPoint( |
746 gfx::Point(-100, -100)).id()); | 746 gfx::Point(-100, -100)).id()); |
747 EXPECT_EQ(primary_display.id(), | 747 EXPECT_EQ(primary_display.id(), |
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
843 if (!SupportsMultipleDisplays()) | 843 if (!SupportsMultipleDisplays()) |
844 return; | 844 return; |
845 | 845 |
846 DisplayController* display_controller = | 846 DisplayController* display_controller = |
847 Shell::GetInstance()->display_controller(); | 847 Shell::GetInstance()->display_controller(); |
848 | 848 |
849 UpdateDisplay("200x200,200x200*2"); | 849 UpdateDisplay("200x200,200x200*2"); |
850 gfx::Display primary_display = Shell::GetScreen()->GetPrimaryDisplay(); | 850 gfx::Display primary_display = Shell::GetScreen()->GetPrimaryDisplay(); |
851 gfx::Display secondary_display = ScreenAsh::GetSecondaryDisplay(); | 851 gfx::Display secondary_display = ScreenAsh::GetSecondaryDisplay(); |
852 | 852 |
853 aura::RootWindow* primary_root = | 853 aura::Window* primary_root = |
854 display_controller->GetRootWindowForDisplayId(primary_display.id()); | 854 display_controller->GetRootWindowForDisplayId(primary_display.id()); |
855 aura::RootWindow* secondary_root = | 855 aura::Window* secondary_root = |
856 display_controller->GetRootWindowForDisplayId(secondary_display.id()); | 856 display_controller->GetRootWindowForDisplayId(secondary_display.id()); |
857 EXPECT_NE(primary_root, secondary_root); | 857 EXPECT_NE(primary_root, secondary_root); |
858 | 858 |
859 test::CursorManagerTestApi test_api(Shell::GetInstance()->cursor_manager()); | 859 test::CursorManagerTestApi test_api(Shell::GetInstance()->cursor_manager()); |
860 | 860 |
861 EXPECT_EQ(1.0f, | 861 EXPECT_EQ(1.0f, primary_root->GetDispatcher()->AsRootWindowHostDelegate()-> |
862 primary_root->AsRootWindowHostDelegate()->GetDeviceScaleFactor()); | 862 GetDeviceScaleFactor()); |
863 primary_root->MoveCursorTo(gfx::Point(50, 50)); | 863 primary_root->MoveCursorTo(gfx::Point(50, 50)); |
864 EXPECT_EQ(1.0f, test_api.GetDisplay().device_scale_factor()); | 864 EXPECT_EQ(1.0f, test_api.GetDisplay().device_scale_factor()); |
865 EXPECT_EQ(2.0f, | 865 EXPECT_EQ(2.0f, secondary_root->GetDispatcher()->AsRootWindowHostDelegate()-> |
866 secondary_root->AsRootWindowHostDelegate()->GetDeviceScaleFactor()); | 866 GetDeviceScaleFactor()); |
867 secondary_root->MoveCursorTo(gfx::Point(50, 50)); | 867 secondary_root->MoveCursorTo(gfx::Point(50, 50)); |
868 EXPECT_EQ(2.0f, test_api.GetDisplay().device_scale_factor()); | 868 EXPECT_EQ(2.0f, test_api.GetDisplay().device_scale_factor()); |
869 | 869 |
870 // Switch primary and secondary | 870 // Switch primary and secondary |
871 display_controller->SetPrimaryDisplay(secondary_display); | 871 display_controller->SetPrimaryDisplay(secondary_display); |
872 | 872 |
873 // Cursor's device scale factor should be updated accroding to the swap of | 873 // Cursor's device scale factor should be updated accroding to the swap of |
874 // primary and secondary. | 874 // primary and secondary. |
875 EXPECT_EQ(1.0f, | 875 EXPECT_EQ(1.0f, secondary_root->GetDispatcher()->AsRootWindowHostDelegate()-> |
876 secondary_root->AsRootWindowHostDelegate()->GetDeviceScaleFactor()); | 876 GetDeviceScaleFactor()); |
877 secondary_root->MoveCursorTo(gfx::Point(50, 50)); | 877 secondary_root->MoveCursorTo(gfx::Point(50, 50)); |
878 EXPECT_EQ(1.0f, test_api.GetDisplay().device_scale_factor()); | 878 EXPECT_EQ(1.0f, test_api.GetDisplay().device_scale_factor()); |
879 primary_root->MoveCursorTo(gfx::Point(50, 50)); | 879 primary_root->MoveCursorTo(gfx::Point(50, 50)); |
880 EXPECT_EQ(2.0f, | 880 EXPECT_EQ(2.0f, primary_root->GetDispatcher()->AsRootWindowHostDelegate()-> |
881 primary_root->AsRootWindowHostDelegate()->GetDeviceScaleFactor()); | 881 GetDeviceScaleFactor()); |
882 EXPECT_EQ(2.0f, test_api.GetDisplay().device_scale_factor()); | 882 EXPECT_EQ(2.0f, test_api.GetDisplay().device_scale_factor()); |
883 | 883 |
884 // Deleting 2nd display. | 884 // Deleting 2nd display. |
885 UpdateDisplay("200x200"); | 885 UpdateDisplay("200x200"); |
886 RunAllPendingInMessageLoop(); // RootWindow is deleted in a posted task. | 886 RunAllPendingInMessageLoop(); // RootWindow is deleted in a posted task. |
887 | 887 |
888 // Cursor's device scale factor should be updated even without moving cursor. | 888 // Cursor's device scale factor should be updated even without moving cursor. |
889 EXPECT_EQ(1.0f, test_api.GetDisplay().device_scale_factor()); | 889 EXPECT_EQ(1.0f, test_api.GetDisplay().device_scale_factor()); |
890 | 890 |
891 primary_root->MoveCursorTo(gfx::Point(50, 50)); | 891 primary_root->MoveCursorTo(gfx::Point(50, 50)); |
892 EXPECT_EQ(1.0f, | 892 EXPECT_EQ(1.0f, primary_root->GetDispatcher()->AsRootWindowHostDelegate()-> |
893 primary_root->AsRootWindowHostDelegate()->GetDeviceScaleFactor()); | 893 GetDeviceScaleFactor()); |
894 EXPECT_EQ(1.0f, test_api.GetDisplay().device_scale_factor()); | 894 EXPECT_EQ(1.0f, test_api.GetDisplay().device_scale_factor()); |
895 } | 895 } |
896 | 896 |
897 TEST_F(DisplayControllerTest, OverscanInsets) { | 897 TEST_F(DisplayControllerTest, OverscanInsets) { |
898 if (!SupportsMultipleDisplays()) | 898 if (!SupportsMultipleDisplays()) |
899 return; | 899 return; |
900 | 900 |
901 DisplayController* display_controller = | 901 DisplayController* display_controller = |
902 Shell::GetInstance()->display_controller(); | 902 Shell::GetInstance()->display_controller(); |
903 TestEventHandler event_handler; | 903 TestEventHandler event_handler; |
(...skipping 234 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1138 generator.MoveMouseToInHost(599, 399); | 1138 generator.MoveMouseToInHost(599, 399); |
1139 EXPECT_EQ("0,449", event_handler.GetLocationAndReset()); | 1139 EXPECT_EQ("0,449", event_handler.GetLocationAndReset()); |
1140 generator.MoveMouseToInHost(0, 399); | 1140 generator.MoveMouseToInHost(0, 399); |
1141 EXPECT_EQ("0,0", event_handler.GetLocationAndReset()); | 1141 EXPECT_EQ("0,0", event_handler.GetLocationAndReset()); |
1142 | 1142 |
1143 Shell::GetInstance()->RemovePreTargetHandler(&event_handler); | 1143 Shell::GetInstance()->RemovePreTargetHandler(&event_handler); |
1144 } | 1144 } |
1145 | 1145 |
1146 #if defined(USE_X11) | 1146 #if defined(USE_X11) |
1147 TEST_F(DisplayControllerTest, XWidowNameForRootWindow) { | 1147 TEST_F(DisplayControllerTest, XWidowNameForRootWindow) { |
1148 EXPECT_EQ("aura_root_0", GetXWindowName(Shell::GetPrimaryRootWindow())); | 1148 EXPECT_EQ("aura_root_0", GetXWindowName( |
| 1149 Shell::GetPrimaryRootWindow()->GetDispatcher())); |
1149 | 1150 |
1150 // Multiple display. | 1151 // Multiple display. |
1151 UpdateDisplay("200x200,300x300"); | 1152 UpdateDisplay("200x200,300x300"); |
1152 aura::RootWindow* primary, *secondary; | 1153 aura::Window* primary, *secondary; |
1153 GetPrimaryAndSeconary(&primary, &secondary); | 1154 GetPrimaryAndSeconary(&primary, &secondary); |
1154 EXPECT_EQ("aura_root_0", GetXWindowName(primary)); | 1155 EXPECT_EQ("aura_root_0", GetXWindowName(primary->GetDispatcher())); |
1155 EXPECT_EQ("aura_root_x", GetXWindowName(secondary)); | 1156 EXPECT_EQ("aura_root_x", GetXWindowName(secondary->GetDispatcher())); |
1156 | 1157 |
1157 // Swap primary. | 1158 // Swap primary. |
1158 primary = secondary = NULL; | 1159 primary = secondary = NULL; |
1159 Shell::GetInstance()->display_controller()->SwapPrimaryDisplay(); | 1160 Shell::GetInstance()->display_controller()->SwapPrimaryDisplay(); |
1160 GetPrimaryAndSeconary(&primary, &secondary); | 1161 GetPrimaryAndSeconary(&primary, &secondary); |
1161 EXPECT_EQ("aura_root_0", GetXWindowName(primary)); | 1162 EXPECT_EQ("aura_root_0", GetXWindowName(primary->GetDispatcher())); |
1162 EXPECT_EQ("aura_root_x", GetXWindowName(secondary)); | 1163 EXPECT_EQ("aura_root_x", GetXWindowName(secondary->GetDispatcher())); |
1163 | 1164 |
1164 // Switching back to single display. | 1165 // Switching back to single display. |
1165 UpdateDisplay("300x400"); | 1166 UpdateDisplay("300x400"); |
1166 EXPECT_EQ("aura_root_0", GetXWindowName(Shell::GetPrimaryRootWindow())); | 1167 EXPECT_EQ("aura_root_0", GetXWindowName( |
| 1168 Shell::GetPrimaryRootWindow()->GetDispatcher())); |
1167 } | 1169 } |
1168 #endif | 1170 #endif |
1169 | 1171 |
1170 } // namespace ash | 1172 } // namespace ash |
OLD | NEW |