| 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/display/display_info.h" | 7 #include "ash/display/display_info.h" |
| 8 #include "ash/display/display_manager.h" | 8 #include "ash/display/display_manager.h" |
| 9 #include "ash/launcher/launcher.h" | 9 #include "ash/launcher/launcher.h" |
| 10 #include "ash/screen_ash.h" | 10 #include "ash/screen_ash.h" |
| (...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 103 TestEventHandler() : target_root_(NULL), | 103 TestEventHandler() : target_root_(NULL), |
| 104 touch_radius_x_(0.0), | 104 touch_radius_x_(0.0), |
| 105 touch_radius_y_(0.0), | 105 touch_radius_y_(0.0), |
| 106 scroll_x_offset_(0.0), | 106 scroll_x_offset_(0.0), |
| 107 scroll_y_offset_(0.0), | 107 scroll_y_offset_(0.0), |
| 108 scroll_x_offset_ordinal_(0.0), | 108 scroll_x_offset_ordinal_(0.0), |
| 109 scroll_y_offset_ordinal_(0.0) {} | 109 scroll_y_offset_ordinal_(0.0) {} |
| 110 virtual ~TestEventHandler() {} | 110 virtual ~TestEventHandler() {} |
| 111 | 111 |
| 112 virtual void OnMouseEvent(ui::MouseEvent* event) OVERRIDE { | 112 virtual void OnMouseEvent(ui::MouseEvent* event) OVERRIDE { |
| 113 if (event->flags() & ui::EF_IS_SYNTHESIZED) |
| 114 return; |
| 113 aura::Window* target = static_cast<aura::Window*>(event->target()); | 115 aura::Window* target = static_cast<aura::Window*>(event->target()); |
| 114 // Only record when the target is the background which covers | 116 mouse_location_ = event->root_location(); |
| 115 // entire root window. | |
| 116 if (target->name() != kDesktopBackgroundView) | |
| 117 return; | |
| 118 mouse_location_ = event->location(); | |
| 119 target_root_ = target->GetRootWindow(); | 117 target_root_ = target->GetRootWindow(); |
| 120 event->StopPropagation(); | 118 event->StopPropagation(); |
| 121 } | 119 } |
| 122 | 120 |
| 123 virtual void OnTouchEvent(ui::TouchEvent* event) OVERRIDE { | 121 virtual void OnTouchEvent(ui::TouchEvent* event) OVERRIDE { |
| 124 aura::Window* target = static_cast<aura::Window*>(event->target()); | 122 aura::Window* target = static_cast<aura::Window*>(event->target()); |
| 125 // Only record when the target is the background which covers | 123 // Only record when the target is the background which covers |
| 126 // entire root window. | 124 // entire root window. |
| 127 if (target->name() != kDesktopBackgroundView) | 125 if (target->name() != kDesktopBackgroundView) |
| 128 return; | 126 return; |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 176 }; | 174 }; |
| 177 | 175 |
| 178 gfx::Display::Rotation GetStoredRotation(int64 id) { | 176 gfx::Display::Rotation GetStoredRotation(int64 id) { |
| 179 return Shell::GetInstance()->display_manager()->GetDisplayInfo(id).rotation(); | 177 return Shell::GetInstance()->display_manager()->GetDisplayInfo(id).rotation(); |
| 180 } | 178 } |
| 181 | 179 |
| 182 float GetStoredUIScale(int64 id) { | 180 float GetStoredUIScale(int64 id) { |
| 183 return Shell::GetInstance()->display_manager()->GetDisplayInfo(id).ui_scale(); | 181 return Shell::GetInstance()->display_manager()->GetDisplayInfo(id).ui_scale(); |
| 184 } | 182 } |
| 185 | 183 |
| 184 void MoveMouseToInHostCoord(aura::RootWindow* root_window, |
| 185 int host_x, |
| 186 int host_y) { |
| 187 gfx::Point move_point(host_x, host_y); |
| 188 ui::MouseEvent mouseev(ui::ET_MOUSE_MOVED, move_point, move_point, 0); |
| 189 root_window->AsRootWindowHostDelegate()->OnHostMouseEvent(&mouseev); |
| 190 } |
| 191 |
| 186 } // namespace | 192 } // namespace |
| 187 | 193 |
| 188 typedef test::AshTestBase DisplayControllerTest; | 194 typedef test::AshTestBase DisplayControllerTest; |
| 189 | 195 |
| 190 TEST_F(DisplayControllerShutdownTest, Shutdown) { | 196 TEST_F(DisplayControllerShutdownTest, Shutdown) { |
| 191 UpdateDisplay("444x333, 200x200"); | 197 UpdateDisplay("444x333, 200x200"); |
| 192 } | 198 } |
| 193 | 199 |
| 194 TEST_F(DisplayControllerTest, SecondaryDisplayLayout) { | 200 TEST_F(DisplayControllerTest, SecondaryDisplayLayout) { |
| 195 TestObserver observer; | 201 TestObserver observer; |
| (...skipping 217 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 413 EXPECT_EQ("right, 50", | 419 EXPECT_EQ("right, 50", |
| 414 display_controller->GetCurrentDisplayLayout().ToString()); | 420 display_controller->GetCurrentDisplayLayout().ToString()); |
| 415 | 421 |
| 416 // Switch primary and secondary | 422 // Switch primary and secondary |
| 417 display_controller->SetPrimaryDisplay(secondary_display); | 423 display_controller->SetPrimaryDisplay(secondary_display); |
| 418 const DisplayLayout& inverted_layout = | 424 const DisplayLayout& inverted_layout = |
| 419 display_controller->GetCurrentDisplayLayout(); | 425 display_controller->GetCurrentDisplayLayout(); |
| 420 EXPECT_EQ("left, -50", inverted_layout.ToString()); | 426 EXPECT_EQ("left, -50", inverted_layout.ToString()); |
| 421 | 427 |
| 422 EXPECT_EQ(secondary_display.id(), | 428 EXPECT_EQ(secondary_display.id(), |
| 423 Shell::GetScreen()->GetPrimaryDisplay().id()); | 429 Shell::GetScreen()->GetPrimaryDisplay().id()); |
| 424 EXPECT_EQ(primary_display.id(), ScreenAsh::GetSecondaryDisplay().id()); | 430 EXPECT_EQ(primary_display.id(), ScreenAsh::GetSecondaryDisplay().id()); |
| 425 EXPECT_EQ(secondary_display.id(), | 431 EXPECT_EQ(secondary_display.id(), |
| 426 Shell::GetScreen()->GetDisplayNearestPoint( | 432 Shell::GetScreen()->GetDisplayNearestPoint( |
| 427 gfx::Point(-100, -100)).id()); | 433 gfx::Point(-100, -100)).id()); |
| 428 EXPECT_EQ(secondary_display.id(), | 434 EXPECT_EQ(secondary_display.id(), |
| 429 Shell::GetScreen()->GetDisplayNearestWindow(NULL).id()); | 435 Shell::GetScreen()->GetDisplayNearestWindow(NULL).id()); |
| 430 | 436 |
| 431 EXPECT_EQ( | 437 EXPECT_EQ( |
| 432 primary_root, | 438 primary_root, |
| 433 display_controller->GetRootWindowForDisplayId(secondary_display.id())); | 439 display_controller->GetRootWindowForDisplayId(secondary_display.id())); |
| (...skipping 285 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 719 EXPECT_EQ("30,20", event_handler.GetLocationAndReset()); | 725 EXPECT_EQ("30,20", event_handler.GetLocationAndReset()); |
| 720 | 726 |
| 721 Shell::GetInstance()->RemovePreTargetHandler(&event_handler); | 727 Shell::GetInstance()->RemovePreTargetHandler(&event_handler); |
| 722 } | 728 } |
| 723 | 729 |
| 724 #if defined(OS_WIN) | 730 #if defined(OS_WIN) |
| 725 // On Win8 bots, the host window can't be resized and | 731 // On Win8 bots, the host window can't be resized and |
| 726 // SetTransform updates the window using the orignal host window | 732 // SetTransform updates the window using the orignal host window |
| 727 // size. | 733 // size. |
| 728 #define MAYBE_Rotate DISABLED_Rotate | 734 #define MAYBE_Rotate DISABLED_Rotate |
| 735 #define MAYBE_ScaleRootWindow DISABLED_ScaleRootWindow |
| 736 #define MAYBE_TouchScale DISABLED_TouchScale |
| 737 #define MAYBE_ConvertHostToRootCoords DISABLED_ConvertHostToRootCoords |
| 729 #else | 738 #else |
| 730 #define MAYBE_Rotate Rotate | 739 #define MAYBE_Rotate Rotate |
| 740 #define MAYBE_ScaleRootWindow ScaleRootWindow |
| 741 #define MAYBE_TouchScale TouchScale |
| 742 #define MAYBE_ConvertHostToRootCoords ConvertHostToRootCoords |
| 731 #endif | 743 #endif |
| 732 | 744 |
| 733 TEST_F(DisplayControllerTest, MAYBE_Rotate) { | 745 TEST_F(DisplayControllerTest, MAYBE_Rotate) { |
| 734 DisplayController* display_controller = | 746 DisplayController* display_controller = |
| 735 Shell::GetInstance()->display_controller(); | 747 Shell::GetInstance()->display_controller(); |
| 736 internal::DisplayManager* display_manager = | 748 internal::DisplayManager* display_manager = |
| 737 Shell::GetInstance()->display_manager(); | 749 Shell::GetInstance()->display_manager(); |
| 738 TestEventHandler event_handler; | 750 TestEventHandler event_handler; |
| 739 Shell::GetInstance()->AddPreTargetHandler(&event_handler); | 751 Shell::GetInstance()->AddPreTargetHandler(&event_handler); |
| 740 | 752 |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 791 ScreenAsh::GetSecondaryDisplay().bounds().ToString()); | 803 ScreenAsh::GetSecondaryDisplay().bounds().ToString()); |
| 792 EXPECT_EQ(gfx::Display::ROTATE_180, GetStoredRotation(display1.id())); | 804 EXPECT_EQ(gfx::Display::ROTATE_180, GetStoredRotation(display1.id())); |
| 793 EXPECT_EQ(gfx::Display::ROTATE_270, GetStoredRotation(display2_id)); | 805 EXPECT_EQ(gfx::Display::ROTATE_270, GetStoredRotation(display2_id)); |
| 794 | 806 |
| 795 generator1.MoveMouseTo(50, 40); | 807 generator1.MoveMouseTo(50, 40); |
| 796 EXPECT_EQ("69,159", event_handler.GetLocationAndReset()); | 808 EXPECT_EQ("69,159", event_handler.GetLocationAndReset()); |
| 797 | 809 |
| 798 Shell::GetInstance()->RemovePreTargetHandler(&event_handler); | 810 Shell::GetInstance()->RemovePreTargetHandler(&event_handler); |
| 799 } | 811 } |
| 800 | 812 |
| 801 #if defined(OS_WIN) | |
| 802 // On Win8 bots, the host window can't be resized and | |
| 803 // SetTransform updates the window using the orignal host window | |
| 804 // size. | |
| 805 #define MAYBE_ScaleRootWindow DISABLED_ScaleRootWindow | |
| 806 #else | |
| 807 #define MAYBE_ScaleRootWindow ScaleRootWindow | |
| 808 #endif | |
| 809 | |
| 810 TEST_F(DisplayControllerTest, MAYBE_ScaleRootWindow) { | 813 TEST_F(DisplayControllerTest, MAYBE_ScaleRootWindow) { |
| 811 TestEventHandler event_handler; | 814 TestEventHandler event_handler; |
| 812 Shell::GetInstance()->AddPreTargetHandler(&event_handler); | 815 Shell::GetInstance()->AddPreTargetHandler(&event_handler); |
| 813 | 816 |
| 814 UpdateDisplay("600x400*2@1.5,500x300"); | 817 UpdateDisplay("600x400*2@1.5,500x300"); |
| 815 | 818 |
| 816 gfx::Display display1 = Shell::GetScreen()->GetPrimaryDisplay(); | 819 gfx::Display display1 = Shell::GetScreen()->GetPrimaryDisplay(); |
| 817 gfx::Display display2 = ScreenAsh::GetSecondaryDisplay(); | 820 gfx::Display display2 = ScreenAsh::GetSecondaryDisplay(); |
| 818 Shell::RootWindowList root_windows = Shell::GetAllRootWindows(); | 821 Shell::RootWindowList root_windows = Shell::GetAllRootWindows(); |
| 819 EXPECT_EQ("0,0 450x300", display1.bounds().ToString()); | 822 EXPECT_EQ("0,0 450x300", display1.bounds().ToString()); |
| (...skipping 13 matching lines...) Expand all Loading... |
| 833 display2 = ScreenAsh::GetSecondaryDisplay(); | 836 display2 = ScreenAsh::GetSecondaryDisplay(); |
| 834 EXPECT_EQ("0,0 375x250", display1.bounds().ToString()); | 837 EXPECT_EQ("0,0 375x250", display1.bounds().ToString()); |
| 835 EXPECT_EQ("0,0 375x250", root_windows[0]->bounds().ToString()); | 838 EXPECT_EQ("0,0 375x250", root_windows[0]->bounds().ToString()); |
| 836 EXPECT_EQ("375,0 500x300", display2.bounds().ToString()); | 839 EXPECT_EQ("375,0 500x300", display2.bounds().ToString()); |
| 837 EXPECT_EQ(1.25f, GetStoredUIScale(display1.id())); | 840 EXPECT_EQ(1.25f, GetStoredUIScale(display1.id())); |
| 838 EXPECT_EQ(1.0f, GetStoredUIScale(display2.id())); | 841 EXPECT_EQ(1.0f, GetStoredUIScale(display2.id())); |
| 839 | 842 |
| 840 Shell::GetInstance()->RemovePreTargetHandler(&event_handler); | 843 Shell::GetInstance()->RemovePreTargetHandler(&event_handler); |
| 841 } | 844 } |
| 842 | 845 |
| 843 | |
| 844 #if defined(OS_WIN) | |
| 845 // On Win8 bots, the host window can't be resized and | |
| 846 // SetTransform updates the window using the orignal host window | |
| 847 // size. | |
| 848 #define MAYBE_TouchScale DISABLED_TouchScale | |
| 849 #else | |
| 850 #define MAYBE_TouchScale TouchScale | |
| 851 #endif | |
| 852 | |
| 853 TEST_F(DisplayControllerTest, MAYBE_TouchScale) { | 846 TEST_F(DisplayControllerTest, MAYBE_TouchScale) { |
| 854 TestEventHandler event_handler; | 847 TestEventHandler event_handler; |
| 855 Shell::GetInstance()->AddPreTargetHandler(&event_handler); | 848 Shell::GetInstance()->AddPreTargetHandler(&event_handler); |
| 856 | 849 |
| 857 UpdateDisplay("200x200*2"); | 850 UpdateDisplay("200x200*2"); |
| 858 gfx::Display display = Shell::GetScreen()->GetPrimaryDisplay(); | 851 gfx::Display display = Shell::GetScreen()->GetPrimaryDisplay(); |
| 859 Shell::RootWindowList root_windows = Shell::GetAllRootWindows(); | 852 Shell::RootWindowList root_windows = Shell::GetAllRootWindows(); |
| 860 aura::RootWindow* root_window = root_windows[0]; | 853 aura::RootWindow* root_window = root_windows[0]; |
| 861 aura::test::EventGenerator generator(root_window); | 854 aura::test::EventGenerator generator(root_window); |
| 862 | 855 |
| 863 generator.PressMoveAndReleaseTouchTo(50, 50); | 856 generator.PressMoveAndReleaseTouchTo(50, 50); |
| 864 // Default test touches have radius_x/y = 1.0, with device scale | 857 // Default test touches have radius_x/y = 1.0, with device scale |
| 865 // factor = 2, the scaled radius_x/y should be 0.5. | 858 // factor = 2, the scaled radius_x/y should be 0.5. |
| 866 EXPECT_EQ(0.5, event_handler.touch_radius_x()); | 859 EXPECT_EQ(0.5, event_handler.touch_radius_x()); |
| 867 EXPECT_EQ(0.5, event_handler.touch_radius_y()); | 860 EXPECT_EQ(0.5, event_handler.touch_radius_y()); |
| 868 | 861 |
| 869 generator.ScrollSequence(gfx::Point(0,0), | 862 generator.ScrollSequence(gfx::Point(0,0), |
| 870 base::TimeDelta::FromMilliseconds(100), | 863 base::TimeDelta::FromMilliseconds(100), |
| 871 10.0, 1.0, 5, 1); | 864 10.0, 1.0, 5, 1); |
| 872 | 865 |
| 873 // With device scale factor = 2, ordinal_offset * 2 = offset. | 866 // With device scale factor = 2, ordinal_offset * 2 = offset. |
| 874 EXPECT_EQ(event_handler.scroll_x_offset(), | 867 EXPECT_EQ(event_handler.scroll_x_offset(), |
| 875 event_handler.scroll_x_offset_ordinal() * 2); | 868 event_handler.scroll_x_offset_ordinal() * 2); |
| 876 EXPECT_EQ(event_handler.scroll_y_offset(), | 869 EXPECT_EQ(event_handler.scroll_y_offset(), |
| 877 event_handler.scroll_y_offset_ordinal() * 2); | 870 event_handler.scroll_y_offset_ordinal() * 2); |
| 878 | 871 |
| 879 Shell::GetInstance()->RemovePreTargetHandler(&event_handler); | 872 Shell::GetInstance()->RemovePreTargetHandler(&event_handler); |
| 880 } | 873 } |
| 881 | 874 |
| 875 TEST_F(DisplayControllerTest, MAYBE_ConvertHostToRootCoords) { |
| 876 TestEventHandler event_handler; |
| 877 Shell::GetInstance()->AddPreTargetHandler(&event_handler); |
| 878 |
| 879 UpdateDisplay("600x400*2/r@1.5"); |
| 880 |
| 881 gfx::Display display1 = Shell::GetScreen()->GetPrimaryDisplay(); |
| 882 Shell::RootWindowList root_windows = Shell::GetAllRootWindows(); |
| 883 EXPECT_EQ("0,0 300x450", display1.bounds().ToString()); |
| 884 EXPECT_EQ("0,0 300x450", root_windows[0]->bounds().ToString()); |
| 885 EXPECT_EQ(1.5f, GetStoredUIScale(display1.id())); |
| 886 |
| 887 MoveMouseToInHostCoord(root_windows[0], 0, 0); |
| 888 EXPECT_EQ("0,449", event_handler.GetLocationAndReset()); |
| 889 MoveMouseToInHostCoord(root_windows[0], 599, 0); |
| 890 EXPECT_EQ("0,0", event_handler.GetLocationAndReset()); |
| 891 MoveMouseToInHostCoord(root_windows[0], 599, 399); |
| 892 EXPECT_EQ("299,0", event_handler.GetLocationAndReset()); |
| 893 MoveMouseToInHostCoord(root_windows[0], 0, 399); |
| 894 EXPECT_EQ("299,449", event_handler.GetLocationAndReset()); |
| 895 |
| 896 Shell::GetInstance()->RemovePreTargetHandler(&event_handler); |
| 897 } |
| 898 |
| 882 } // namespace test | 899 } // namespace test |
| 883 } // namespace ash | 900 } // namespace ash |
| OLD | NEW |