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" |
11 #include "ash/shelf/shelf_widget.h" | 11 #include "ash/shelf/shelf_widget.h" |
12 #include "ash/shell.h" | 12 #include "ash/shell.h" |
13 #include "ash/test/ash_test_base.h" | 13 #include "ash/test/ash_test_base.h" |
14 #include "ash/test/cursor_manager_test_api.h" | 14 #include "ash/test/cursor_manager_test_api.h" |
15 #include "ui/aura/env.h" | 15 #include "ui/aura/env.h" |
16 #include "ui/aura/root_window.h" | 16 #include "ui/aura/root_window.h" |
17 #include "ui/aura/test/event_generator.h" | 17 #include "ui/aura/test/event_generator.h" |
18 #include "ui/aura/window_tracker.h" | 18 #include "ui/aura/window_tracker.h" |
19 #include "ui/base/events/event_handler.h" | 19 #include "ui/base/events/event_handler.h" |
20 #include "ui/gfx/display.h" | 20 #include "ui/gfx/display.h" |
21 #include "ui/gfx/screen.h" | 21 #include "ui/gfx/screen.h" |
22 #include "ui/views/widget/widget.h" | 22 #include "ui/views/widget/widget.h" |
23 | 23 |
24 namespace ash { | 24 namespace ash { |
25 namespace test { | 25 namespace test { |
26 namespace { | 26 namespace { |
27 | 27 |
| 28 const char kDesktopBackgroundView[] = "DesktopBackgroundView"; |
| 29 |
28 class TestObserver : public DisplayController::Observer { | 30 class TestObserver : public DisplayController::Observer { |
29 public: | 31 public: |
30 TestObserver() : changing_count_(0), changed_count_(0) { | 32 TestObserver() : changing_count_(0), changed_count_(0) { |
31 Shell::GetInstance()->display_controller()->AddObserver(this); | 33 Shell::GetInstance()->display_controller()->AddObserver(this); |
32 } | 34 } |
33 | 35 |
34 virtual ~TestObserver() { | 36 virtual ~TestObserver() { |
35 Shell::GetInstance()->display_controller()->RemoveObserver(this); | 37 Shell::GetInstance()->display_controller()->RemoveObserver(this); |
36 } | 38 } |
37 | 39 |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
91 test::AshTestBase::TearDown(); | 93 test::AshTestBase::TearDown(); |
92 // Make sure that primary display is accessible after shutdown. | 94 // Make sure that primary display is accessible after shutdown. |
93 gfx::Display primary = Shell::GetScreen()->GetPrimaryDisplay(); | 95 gfx::Display primary = Shell::GetScreen()->GetPrimaryDisplay(); |
94 EXPECT_EQ("0,0 444x333", primary.bounds().ToString()); | 96 EXPECT_EQ("0,0 444x333", primary.bounds().ToString()); |
95 EXPECT_EQ(2, Shell::GetScreen()->GetNumDisplays()); | 97 EXPECT_EQ(2, Shell::GetScreen()->GetNumDisplays()); |
96 } | 98 } |
97 }; | 99 }; |
98 | 100 |
99 class TestEventHandler : public ui::EventHandler { | 101 class TestEventHandler : public ui::EventHandler { |
100 public: | 102 public: |
101 TestEventHandler() : target_root_(NULL) {} | 103 TestEventHandler() : target_root_(NULL), |
| 104 touch_radius_x_(0.0), |
| 105 touch_radius_y_(0.0), |
| 106 scroll_x_offset_(0.0), |
| 107 scroll_y_offset_(0.0), |
| 108 scroll_x_offset_ordinal_(0.0), |
| 109 scroll_y_offset_ordinal_(0.0) {} |
102 virtual ~TestEventHandler() {} | 110 virtual ~TestEventHandler() {} |
103 | 111 |
104 virtual void OnMouseEvent(ui::MouseEvent* event) OVERRIDE { | 112 virtual void OnMouseEvent(ui::MouseEvent* event) OVERRIDE { |
105 aura::Window* target = static_cast<aura::Window*>(event->target()); | 113 aura::Window* target = static_cast<aura::Window*>(event->target()); |
106 // Only record when the target is the background which covers | 114 // Only record when the target is the background which covers |
107 // entire root window. | 115 // entire root window. |
108 if (target->name() != "DesktopBackgroundView") | 116 if (target->name() != kDesktopBackgroundView) |
109 return; | 117 return; |
110 mouse_location_ = event->location(); | 118 mouse_location_ = event->location(); |
111 target_root_ = target->GetRootWindow(); | 119 target_root_ = target->GetRootWindow(); |
112 event->StopPropagation(); | 120 event->StopPropagation(); |
113 } | 121 } |
114 | 122 |
| 123 virtual void OnTouchEvent(ui::TouchEvent* event) OVERRIDE { |
| 124 aura::Window* target = static_cast<aura::Window*>(event->target()); |
| 125 // Only record when the target is the background which covers |
| 126 // entire root window. |
| 127 if (target->name() != kDesktopBackgroundView) |
| 128 return; |
| 129 touch_radius_x_ = event->radius_x(); |
| 130 touch_radius_y_ = event->radius_y(); |
| 131 event->StopPropagation(); |
| 132 } |
| 133 |
| 134 virtual void OnScrollEvent(ui::ScrollEvent* event) OVERRIDE { |
| 135 aura::Window* target = static_cast<aura::Window*>(event->target()); |
| 136 // Only record when the target is the background which covers |
| 137 // entire root window. |
| 138 if (target->name() != kDesktopBackgroundView) |
| 139 return; |
| 140 |
| 141 if (event->type() == ui::ET_SCROLL) { |
| 142 scroll_x_offset_ = event->x_offset(); |
| 143 scroll_y_offset_ = event->y_offset(); |
| 144 scroll_x_offset_ordinal_ = event->x_offset_ordinal(); |
| 145 scroll_y_offset_ordinal_ = event->y_offset_ordinal(); |
| 146 } |
| 147 event->StopPropagation(); |
| 148 } |
| 149 |
115 std::string GetLocationAndReset() { | 150 std::string GetLocationAndReset() { |
116 std::string result = mouse_location_.ToString(); | 151 std::string result = mouse_location_.ToString(); |
117 mouse_location_.SetPoint(0, 0); | 152 mouse_location_.SetPoint(0, 0); |
118 target_root_ = NULL; | 153 target_root_ = NULL; |
119 return result; | 154 return result; |
120 } | 155 } |
121 | 156 |
| 157 float touch_radius_x() { return touch_radius_x_; } |
| 158 float touch_radius_y() { return touch_radius_y_; } |
| 159 float scroll_x_offset() { return scroll_x_offset_; } |
| 160 float scroll_y_offset() { return scroll_y_offset_; } |
| 161 float scroll_x_offset_ordinal() { return scroll_x_offset_ordinal_; } |
| 162 float scroll_y_offset_ordinal() { return scroll_y_offset_ordinal_; } |
| 163 |
122 private: | 164 private: |
123 gfx::Point mouse_location_; | 165 gfx::Point mouse_location_; |
124 aura::RootWindow* target_root_; | 166 aura::RootWindow* target_root_; |
125 | 167 |
| 168 float touch_radius_x_; |
| 169 float touch_radius_y_; |
| 170 float scroll_x_offset_; |
| 171 float scroll_y_offset_; |
| 172 float scroll_x_offset_ordinal_; |
| 173 float scroll_y_offset_ordinal_; |
| 174 |
126 DISALLOW_COPY_AND_ASSIGN(TestEventHandler); | 175 DISALLOW_COPY_AND_ASSIGN(TestEventHandler); |
127 }; | 176 }; |
128 | 177 |
129 gfx::Display::Rotation GetStoredRotation(int64 id) { | 178 gfx::Display::Rotation GetStoredRotation(int64 id) { |
130 return Shell::GetInstance()->display_manager()->GetDisplayInfo(id).rotation(); | 179 return Shell::GetInstance()->display_manager()->GetDisplayInfo(id).rotation(); |
131 } | 180 } |
132 | 181 |
133 float GetStoredUIScale(int64 id) { | 182 float GetStoredUIScale(int64 id) { |
134 return Shell::GetInstance()->display_manager()->GetDisplayInfo(id).ui_scale(); | 183 return Shell::GetInstance()->display_manager()->GetDisplayInfo(id).ui_scale(); |
135 } | 184 } |
(...skipping 648 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
784 display2 = ScreenAsh::GetSecondaryDisplay(); | 833 display2 = ScreenAsh::GetSecondaryDisplay(); |
785 EXPECT_EQ("0,0 375x250", display1.bounds().ToString()); | 834 EXPECT_EQ("0,0 375x250", display1.bounds().ToString()); |
786 EXPECT_EQ("0,0 375x250", root_windows[0]->bounds().ToString()); | 835 EXPECT_EQ("0,0 375x250", root_windows[0]->bounds().ToString()); |
787 EXPECT_EQ("375,0 500x300", display2.bounds().ToString()); | 836 EXPECT_EQ("375,0 500x300", display2.bounds().ToString()); |
788 EXPECT_EQ(1.25f, GetStoredUIScale(display1.id())); | 837 EXPECT_EQ(1.25f, GetStoredUIScale(display1.id())); |
789 EXPECT_EQ(1.0f, GetStoredUIScale(display2.id())); | 838 EXPECT_EQ(1.0f, GetStoredUIScale(display2.id())); |
790 | 839 |
791 Shell::GetInstance()->RemovePreTargetHandler(&event_handler); | 840 Shell::GetInstance()->RemovePreTargetHandler(&event_handler); |
792 } | 841 } |
793 | 842 |
| 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) { |
| 854 TestEventHandler event_handler; |
| 855 Shell::GetInstance()->AddPreTargetHandler(&event_handler); |
| 856 |
| 857 UpdateDisplay("200x200*2"); |
| 858 gfx::Display display = Shell::GetScreen()->GetPrimaryDisplay(); |
| 859 Shell::RootWindowList root_windows = Shell::GetAllRootWindows(); |
| 860 aura::RootWindow* root_window = root_windows[0]; |
| 861 aura::test::EventGenerator generator(root_window); |
| 862 |
| 863 generator.PressMoveAndReleaseTouchTo(50, 50); |
| 864 // Default test touches have radius_x/y = 1.0, with device scale |
| 865 // factor = 2, the scaled radius_x/y should be 0.5. |
| 866 EXPECT_EQ(0.5, event_handler.touch_radius_x()); |
| 867 EXPECT_EQ(0.5, event_handler.touch_radius_y()); |
| 868 |
| 869 generator.ScrollSequence(gfx::Point(0,0), |
| 870 base::TimeDelta::FromMilliseconds(100), |
| 871 10.0, 1.0, 5, 1); |
| 872 |
| 873 // With device scale factor = 2, ordinal_offset * 2 = offset. |
| 874 EXPECT_EQ(event_handler.scroll_x_offset(), |
| 875 event_handler.scroll_x_offset_ordinal() * 2); |
| 876 EXPECT_EQ(event_handler.scroll_y_offset(), |
| 877 event_handler.scroll_y_offset_ordinal() * 2); |
| 878 |
| 879 Shell::GetInstance()->RemovePreTargetHandler(&event_handler); |
| 880 } |
| 881 |
794 } // namespace test | 882 } // namespace test |
795 } // namespace ash | 883 } // namespace ash |
OLD | NEW |