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/test/display_manager_test_api.h" | 5 #include "ash/test/display_manager_test_api.h" |
6 | 6 |
7 #include <cstdarg> | 7 #include <cstdarg> |
8 #include <vector> | 8 #include <vector> |
9 | 9 |
10 #include "ash/display/display_manager.h" | 10 #include "ash/display/display_manager.h" |
11 #include "ash/display/extended_mouse_warp_controller.h" | |
12 #include "ash/display/mouse_cursor_event_filter.h" | |
13 #include "ash/display/unified_mouse_warp_controller.h" | |
14 #include "ash/screen_util.h" | |
15 #include "ash/shell.h" | |
16 #include "base/command_line.h" | 11 #include "base/command_line.h" |
17 #include "base/strings/string_split.h" | 12 #include "base/strings/string_split.h" |
18 #include "ui/aura/env.h" | |
19 #include "ui/aura/window_event_dispatcher.h" | |
20 #include "ui/display/display.h" | 13 #include "ui/display/display.h" |
21 #include "ui/display/manager/display_layout_builder.h" | 14 #include "ui/display/manager/display_layout_builder.h" |
22 #include "ui/display/manager/display_manager_utilities.h" | 15 #include "ui/display/manager/display_manager_utilities.h" |
23 #include "ui/display/manager/managed_display_info.h" | 16 #include "ui/display/manager/managed_display_info.h" |
| 17 #include "ui/display/screen.h" |
24 #include "ui/events/test/event_generator.h" | 18 #include "ui/events/test/event_generator.h" |
25 | 19 |
26 namespace ash { | 20 namespace ash { |
27 namespace test { | 21 namespace test { |
28 namespace { | 22 namespace { |
29 | 23 |
30 DisplayInfoList CreateDisplayInfoListFromString( | 24 DisplayInfoList CreateDisplayInfoListFromString( |
31 const std::string specs, | 25 const std::string specs, |
32 DisplayManager* display_manager) { | 26 DisplayManager* display_manager) { |
33 DisplayInfoList display_info_list; | 27 DisplayInfoList display_info_list; |
(...skipping 11 matching lines...) Expand all Loading... |
45 int64_t id = (index < list.size()) ? list[index].id() | 39 int64_t id = (index < list.size()) ? list[index].id() |
46 : display::Display::kInvalidDisplayID; | 40 : display::Display::kInvalidDisplayID; |
47 display_info_list.push_back( | 41 display_info_list.push_back( |
48 display::ManagedDisplayInfo::CreateFromSpecWithID(*iter, id)); | 42 display::ManagedDisplayInfo::CreateFromSpecWithID(*iter, id)); |
49 } | 43 } |
50 return display_info_list; | 44 return display_info_list; |
51 } | 45 } |
52 | 46 |
53 } // namespace | 47 } // namespace |
54 | 48 |
55 // static | 49 DisplayManagerTestApi::DisplayManagerTestApi(DisplayManager* display_manager) |
56 bool DisplayManagerTestApi::TestIfMouseWarpsAt( | 50 : display_manager_(display_manager) {} |
57 ui::test::EventGenerator& event_generator, | |
58 const gfx::Point& point_in_screen) { | |
59 DCHECK(!Shell::GetInstance()->display_manager()->IsInUnifiedMode()); | |
60 static_cast<ExtendedMouseWarpController*>( | |
61 Shell::GetInstance() | |
62 ->mouse_cursor_filter() | |
63 ->mouse_warp_controller_for_test()) | |
64 ->allow_non_native_event_for_test(); | |
65 display::Screen* screen = display::Screen::GetScreen(); | |
66 display::Display original_display = | |
67 screen->GetDisplayNearestPoint(point_in_screen); | |
68 event_generator.MoveMouseTo(point_in_screen); | |
69 return original_display.id() != | |
70 screen | |
71 ->GetDisplayNearestPoint( | |
72 aura::Env::GetInstance()->last_mouse_location()) | |
73 .id(); | |
74 } | |
75 | |
76 DisplayManagerTestApi::DisplayManagerTestApi() | |
77 : display_manager_(Shell::GetInstance()->display_manager()) {} | |
78 | 51 |
79 DisplayManagerTestApi::~DisplayManagerTestApi() {} | 52 DisplayManagerTestApi::~DisplayManagerTestApi() {} |
80 | 53 |
81 void DisplayManagerTestApi::UpdateDisplay(const std::string& display_specs) { | 54 void DisplayManagerTestApi::UpdateDisplay(const std::string& display_specs) { |
82 DisplayInfoList display_info_list = | 55 DisplayInfoList display_info_list = |
83 CreateDisplayInfoListFromString(display_specs, display_manager_); | 56 CreateDisplayInfoListFromString(display_specs, display_manager_); |
84 bool is_host_origin_set = false; | 57 bool is_host_origin_set = false; |
85 for (size_t i = 0; i < display_info_list.size(); ++i) { | 58 for (size_t i = 0; i < display_info_list.size(); ++i) { |
86 const display::ManagedDisplayInfo& display_info = display_info_list[i]; | 59 const display::ManagedDisplayInfo& display_info = display_info_list[i]; |
87 if (display_info.bounds_in_native().origin() != gfx::Point(0, 0)) { | 60 if (display_info.bounds_in_native().origin() != gfx::Point(0, 0)) { |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
128 display_manager_->set_change_display_upon_host_resize(false); | 101 display_manager_->set_change_display_upon_host_resize(false); |
129 } | 102 } |
130 | 103 |
131 void DisplayManagerTestApi::SetAvailableColorProfiles( | 104 void DisplayManagerTestApi::SetAvailableColorProfiles( |
132 int64_t display_id, | 105 int64_t display_id, |
133 const std::vector<ui::ColorCalibrationProfile>& profiles) { | 106 const std::vector<ui::ColorCalibrationProfile>& profiles) { |
134 display_manager_->display_info_[display_id].set_available_color_profiles( | 107 display_manager_->display_info_[display_id].set_available_color_profiles( |
135 profiles); | 108 profiles); |
136 } | 109 } |
137 | 110 |
| 111 const display::ManagedDisplayInfo& |
| 112 DisplayManagerTestApi::GetInternalManagedDisplayInfo(int64_t display_id) { |
| 113 return display_manager_->display_info_[display_id]; |
| 114 } |
| 115 |
138 ScopedDisable125DSFForUIScaling::ScopedDisable125DSFForUIScaling() { | 116 ScopedDisable125DSFForUIScaling::ScopedDisable125DSFForUIScaling() { |
139 display::ManagedDisplayInfo::SetUse125DSFForUIScalingForTest(false); | 117 display::ManagedDisplayInfo::SetUse125DSFForUIScalingForTest(false); |
140 } | 118 } |
141 | 119 |
142 ScopedDisable125DSFForUIScaling::~ScopedDisable125DSFForUIScaling() { | 120 ScopedDisable125DSFForUIScaling::~ScopedDisable125DSFForUIScaling() { |
143 display::ManagedDisplayInfo::SetUse125DSFForUIScalingForTest(true); | 121 display::ManagedDisplayInfo::SetUse125DSFForUIScalingForTest(true); |
144 } | 122 } |
145 | 123 |
146 ScopedSetInternalDisplayId::ScopedSetInternalDisplayId(int64_t id) { | 124 ScopedSetInternalDisplayId::ScopedSetInternalDisplayId( |
147 DisplayManagerTestApi().SetInternalDisplayId(id); | 125 DisplayManager* display_manager, |
| 126 int64_t id) { |
| 127 DisplayManagerTestApi(display_manager).SetInternalDisplayId(id); |
148 } | 128 } |
149 | 129 |
150 ScopedSetInternalDisplayId::~ScopedSetInternalDisplayId() { | 130 ScopedSetInternalDisplayId::~ScopedSetInternalDisplayId() { |
151 display::Display::SetInternalDisplayId(display::Display::kInvalidDisplayID); | 131 display::Display::SetInternalDisplayId(display::Display::kInvalidDisplayID); |
152 } | 132 } |
153 | 133 |
154 bool SetDisplayResolution(int64_t display_id, const gfx::Size& resolution) { | 134 bool SetDisplayResolution(DisplayManager* display_manager, |
155 DisplayManager* display_manager = Shell::GetInstance()->display_manager(); | 135 int64_t display_id, |
| 136 const gfx::Size& resolution) { |
156 const display::ManagedDisplayInfo& info = | 137 const display::ManagedDisplayInfo& info = |
157 display_manager->GetDisplayInfo(display_id); | 138 display_manager->GetDisplayInfo(display_id); |
158 scoped_refptr<display::ManagedDisplayMode> mode = | 139 scoped_refptr<display::ManagedDisplayMode> mode = |
159 GetDisplayModeForResolution(info, resolution); | 140 GetDisplayModeForResolution(info, resolution); |
160 if (!mode) | 141 if (!mode) |
161 return false; | 142 return false; |
162 return display_manager->SetDisplayMode(display_id, mode); | 143 return display_manager->SetDisplayMode(display_id, mode); |
163 } | 144 } |
164 | 145 |
165 void SwapPrimaryDisplay() { | |
166 if (display::Screen::GetScreen()->GetNumDisplays() <= 1) | |
167 return; | |
168 Shell::GetInstance()->window_tree_host_manager()->SetPrimaryDisplayId( | |
169 ScreenUtil::GetSecondaryDisplay().id()); | |
170 } | |
171 | |
172 std::unique_ptr<display::DisplayLayout> CreateDisplayLayout( | 146 std::unique_ptr<display::DisplayLayout> CreateDisplayLayout( |
| 147 DisplayManager* display_manager, |
173 display::DisplayPlacement::Position position, | 148 display::DisplayPlacement::Position position, |
174 int offset) { | 149 int offset) { |
175 DisplayManager* display_manager = Shell::GetInstance()->display_manager(); | |
176 display::DisplayIdList list = display_manager->GetCurrentDisplayIdList(); | |
177 | |
178 display::DisplayLayoutBuilder builder( | 150 display::DisplayLayoutBuilder builder( |
179 display::Screen::GetScreen()->GetPrimaryDisplay().id()); | 151 display::Screen::GetScreen()->GetPrimaryDisplay().id()); |
180 builder.SetSecondaryPlacement(ScreenUtil::GetSecondaryDisplay().id(), | 152 builder.SetSecondaryPlacement(display_manager->GetSecondaryDisplay().id(), |
181 position, offset); | 153 position, offset); |
182 return builder.Build(); | 154 return builder.Build(); |
183 } | 155 } |
184 | 156 |
185 display::DisplayIdList CreateDisplayIdList2(int64_t id1, int64_t id2) { | 157 display::DisplayIdList CreateDisplayIdList2(int64_t id1, int64_t id2) { |
186 display::DisplayIdList list; | 158 display::DisplayIdList list; |
187 list.push_back(id1); | 159 list.push_back(id1); |
188 list.push_back(id2); | 160 list.push_back(id2); |
189 display::SortDisplayIdList(&list); | 161 display::SortDisplayIdList(&list); |
190 return list; | 162 return list; |
191 } | 163 } |
192 | 164 |
193 display::DisplayIdList CreateDisplayIdListN(size_t count, ...) { | 165 display::DisplayIdList CreateDisplayIdListN(size_t count, ...) { |
194 display::DisplayIdList list; | 166 display::DisplayIdList list; |
195 va_list args; | 167 va_list args; |
196 va_start(args, count); | 168 va_start(args, count); |
197 for (size_t i = 0; i < count; i++) { | 169 for (size_t i = 0; i < count; i++) { |
198 int64_t id = va_arg(args, int64_t); | 170 int64_t id = va_arg(args, int64_t); |
199 list.push_back(id); | 171 list.push_back(id); |
200 } | 172 } |
201 display::SortDisplayIdList(&list); | 173 display::SortDisplayIdList(&list); |
202 return list; | 174 return list; |
203 } | 175 } |
204 | 176 |
205 } // namespace test | 177 } // namespace test |
206 } // namespace ash | 178 } // namespace ash |
OLD | NEW |