Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(38)

Side by Side Diff: ui/views/mus/screen_mus.cc

Issue 1915363002: Rename gfx::Display/Screen to display::Display/Screen in views/wm (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: more cleanups Created 4 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « ui/views/mus/screen_mus.h ('k') | ui/views/test/desktop_screen_x11_test_api.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 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 "ui/views/mus/screen_mus.h" 5 #include "ui/views/mus/screen_mus.h"
6 6
7 #include "mojo/converters/geometry/geometry_type_converters.h" 7 #include "mojo/converters/geometry/geometry_type_converters.h"
8 #include "services/shell/public/cpp/connection.h" 8 #include "services/shell/public/cpp/connection.h"
9 #include "services/shell/public/cpp/connector.h" 9 #include "services/shell/public/cpp/connector.h"
10 #include "ui/display/display_observer.h"
10 #include "ui/gfx/display_finder.h" 11 #include "ui/gfx/display_finder.h"
11 #include "ui/gfx/display_observer.h"
12 #include "ui/views/mus/screen_mus_delegate.h" 12 #include "ui/views/mus/screen_mus_delegate.h"
13 #include "ui/views/mus/window_manager_frame_values.h" 13 #include "ui/views/mus/window_manager_frame_values.h"
14 14
15 namespace mojo { 15 namespace mojo {
16 16
17 template <> 17 template <>
18 struct TypeConverter<gfx::Display, mus::mojom::DisplayPtr> { 18 struct TypeConverter<display::Display, mus::mojom::DisplayPtr> {
19 static gfx::Display Convert(const mus::mojom::DisplayPtr& input) { 19 static display::Display Convert(const mus::mojom::DisplayPtr& input) {
20 gfx::Display result(input->id); 20 display::Display result(input->id);
21 gfx::Rect pixel_bounds = input->bounds.To<gfx::Rect>(); 21 gfx::Rect pixel_bounds = input->bounds.To<gfx::Rect>();
22 gfx::Rect pixel_work_area = input->work_area.To<gfx::Rect>(); 22 gfx::Rect pixel_work_area = input->work_area.To<gfx::Rect>();
23 float pixel_ratio = input->device_pixel_ratio; 23 float pixel_ratio = input->device_pixel_ratio;
24 24
25 gfx::Rect dip_bounds = 25 gfx::Rect dip_bounds =
26 gfx::ScaleToEnclosingRect(pixel_bounds, 1.f / pixel_ratio); 26 gfx::ScaleToEnclosingRect(pixel_bounds, 1.f / pixel_ratio);
27 gfx::Rect dip_work_area = 27 gfx::Rect dip_work_area =
28 gfx::ScaleToEnclosingRect(pixel_work_area, 1.f / pixel_ratio); 28 gfx::ScaleToEnclosingRect(pixel_work_area, 1.f / pixel_ratio);
29 result.set_bounds(dip_bounds); 29 result.set_bounds(dip_bounds);
30 result.set_work_area(dip_work_area); 30 result.set_work_area(dip_work_area);
31 result.set_device_scale_factor(input->device_pixel_ratio); 31 result.set_device_scale_factor(input->device_pixel_ratio);
32 32
33 switch (input->rotation) { 33 switch (input->rotation) {
34 case mus::mojom::Rotation::VALUE_0: 34 case mus::mojom::Rotation::VALUE_0:
35 result.set_rotation(gfx::Display::ROTATE_0); 35 result.set_rotation(display::Display::ROTATE_0);
36 break; 36 break;
37 case mus::mojom::Rotation::VALUE_90: 37 case mus::mojom::Rotation::VALUE_90:
38 result.set_rotation(gfx::Display::ROTATE_90); 38 result.set_rotation(display::Display::ROTATE_90);
39 break; 39 break;
40 case mus::mojom::Rotation::VALUE_180: 40 case mus::mojom::Rotation::VALUE_180:
41 result.set_rotation(gfx::Display::ROTATE_180); 41 result.set_rotation(display::Display::ROTATE_180);
42 break; 42 break;
43 case mus::mojom::Rotation::VALUE_270: 43 case mus::mojom::Rotation::VALUE_270:
44 result.set_rotation(gfx::Display::ROTATE_270); 44 result.set_rotation(display::Display::ROTATE_270);
45 break; 45 break;
46 } 46 }
47 switch (input->touch_support) { 47 switch (input->touch_support) {
48 case mus::mojom::TouchSupport::UNKNOWN: 48 case mus::mojom::TouchSupport::UNKNOWN:
49 result.set_touch_support(gfx::Display::TOUCH_SUPPORT_UNKNOWN); 49 result.set_touch_support(display::Display::TOUCH_SUPPORT_UNKNOWN);
50 break; 50 break;
51 case mus::mojom::TouchSupport::AVAILABLE: 51 case mus::mojom::TouchSupport::AVAILABLE:
52 result.set_touch_support(gfx::Display::TOUCH_SUPPORT_AVAILABLE); 52 result.set_touch_support(display::Display::TOUCH_SUPPORT_AVAILABLE);
53 break; 53 break;
54 case mus::mojom::TouchSupport::UNAVAILABLE: 54 case mus::mojom::TouchSupport::UNAVAILABLE:
55 result.set_touch_support(gfx::Display::TOUCH_SUPPORT_UNAVAILABLE); 55 result.set_touch_support(display::Display::TOUCH_SUPPORT_UNAVAILABLE);
56 break; 56 break;
57 } 57 }
58 return result; 58 return result;
59 } 59 }
60 }; 60 };
61 61
62 template <> 62 template <>
63 struct TypeConverter<views::WindowManagerFrameValues, 63 struct TypeConverter<views::WindowManagerFrameValues,
64 mus::mojom::FrameDecorationValuesPtr> { 64 mus::mojom::FrameDecorationValuesPtr> {
65 static views::WindowManagerFrameValues Convert( 65 static views::WindowManagerFrameValues Convert(
(...skipping 12 matching lines...) Expand all
78 namespace views { 78 namespace views {
79 79
80 ScreenMus::ScreenMus(ScreenMusDelegate* delegate) 80 ScreenMus::ScreenMus(ScreenMusDelegate* delegate)
81 : delegate_(delegate), 81 : delegate_(delegate),
82 primary_display_index_(0), 82 primary_display_index_(0),
83 display_manager_observer_binding_(this) {} 83 display_manager_observer_binding_(this) {}
84 84
85 ScreenMus::~ScreenMus() {} 85 ScreenMus::~ScreenMus() {}
86 86
87 void ScreenMus::Init(shell::Connector* connector) { 87 void ScreenMus::Init(shell::Connector* connector) {
88 gfx::Screen::SetScreenInstance(this); 88 display::Screen::SetScreenInstance(this);
89 89
90 connector->ConnectToInterface("mojo:mus", &display_manager_); 90 connector->ConnectToInterface("mojo:mus", &display_manager_);
91 91
92 display_manager_->AddObserver( 92 display_manager_->AddObserver(
93 display_manager_observer_binding_.CreateInterfacePtrAndBind()); 93 display_manager_observer_binding_.CreateInterfacePtrAndBind());
94 94
95 // We need the set of displays before we can continue. Wait for it. 95 // We need the set of displays before we can continue. Wait for it.
96 // 96 //
97 // TODO(rockot): Do something better here. This should not have to block tasks 97 // TODO(rockot): Do something better here. This should not have to block tasks
98 // from running on the calling thread. http://crbug.com/594852. 98 // from running on the calling thread. http://crbug.com/594852.
(...skipping 10 matching lines...) Expand all
109 } 109 }
110 110
111 int ScreenMus::FindDisplayIndexById(int64_t id) const { 111 int ScreenMus::FindDisplayIndexById(int64_t id) const {
112 for (size_t i = 0; i < displays_.size(); ++i) { 112 for (size_t i = 0; i < displays_.size(); ++i) {
113 if (displays_[i].id() == id) 113 if (displays_[i].id() == id)
114 return static_cast<int>(i); 114 return static_cast<int>(i);
115 } 115 }
116 return -1; 116 return -1;
117 } 117 }
118 118
119 void ScreenMus::ProcessDisplayChanged(const gfx::Display& changed_display, 119 void ScreenMus::ProcessDisplayChanged(const display::Display& changed_display,
120 bool is_primary) { 120 bool is_primary) {
121 const int display_index = FindDisplayIndexById(changed_display.id()); 121 const int display_index = FindDisplayIndexById(changed_display.id());
122 if (display_index == -1) { 122 if (display_index == -1) {
123 displays_.push_back(changed_display); 123 displays_.push_back(changed_display);
124 if (is_primary) 124 if (is_primary)
125 primary_display_index_ = static_cast<int>(displays_.size()) - 1; 125 primary_display_index_ = static_cast<int>(displays_.size()) - 1;
126 FOR_EACH_OBSERVER(gfx::DisplayObserver, observers_, 126 FOR_EACH_OBSERVER(display::DisplayObserver, observers_,
127 OnDisplayAdded(changed_display)); 127 OnDisplayAdded(changed_display));
128 return; 128 return;
129 } 129 }
130 130
131 gfx::Display* local_display = &displays_[display_index]; 131 display::Display* local_display = &displays_[display_index];
132 uint32_t changed_values = 0; 132 uint32_t changed_values = 0;
133 if (is_primary && display_index != primary_display_index_) { 133 if (is_primary && display_index != primary_display_index_) {
134 primary_display_index_ = display_index; 134 primary_display_index_ = display_index;
135 // ash::DisplayManager only notifies for the Display gaining primary, not 135 // ash::DisplayManager only notifies for the Display gaining primary, not
136 // the one losing it. 136 // the one losing it.
137 changed_values |= gfx::DisplayObserver::DISPLAY_METRIC_PRIMARY; 137 changed_values |= display::DisplayObserver::DISPLAY_METRIC_PRIMARY;
138 } 138 }
139 if (local_display->bounds() != changed_display.bounds()) { 139 if (local_display->bounds() != changed_display.bounds()) {
140 local_display->set_bounds(changed_display.bounds()); 140 local_display->set_bounds(changed_display.bounds());
141 changed_values |= gfx::DisplayObserver::DISPLAY_METRIC_BOUNDS; 141 changed_values |= display::DisplayObserver::DISPLAY_METRIC_BOUNDS;
142 } 142 }
143 if (local_display->work_area() != changed_display.work_area()) { 143 if (local_display->work_area() != changed_display.work_area()) {
144 local_display->set_work_area(changed_display.work_area()); 144 local_display->set_work_area(changed_display.work_area());
145 changed_values |= gfx::DisplayObserver::DISPLAY_METRIC_WORK_AREA; 145 changed_values |= display::DisplayObserver::DISPLAY_METRIC_WORK_AREA;
146 } 146 }
147 if (local_display->rotation() != changed_display.rotation()) { 147 if (local_display->rotation() != changed_display.rotation()) {
148 local_display->set_rotation(changed_display.rotation()); 148 local_display->set_rotation(changed_display.rotation());
149 changed_values |= gfx::DisplayObserver::DISPLAY_METRIC_ROTATION; 149 changed_values |= display::DisplayObserver::DISPLAY_METRIC_ROTATION;
150 } 150 }
151 if (local_display->device_scale_factor() != 151 if (local_display->device_scale_factor() !=
152 changed_display.device_scale_factor()) { 152 changed_display.device_scale_factor()) {
153 local_display->set_device_scale_factor( 153 local_display->set_device_scale_factor(
154 changed_display.device_scale_factor()); 154 changed_display.device_scale_factor());
155 changed_values |= gfx::DisplayObserver::DISPLAY_METRIC_DEVICE_SCALE_FACTOR; 155 changed_values |=
156 display::DisplayObserver::DISPLAY_METRIC_DEVICE_SCALE_FACTOR;
156 } 157 }
157 FOR_EACH_OBSERVER(gfx::DisplayObserver, observers_, 158 FOR_EACH_OBSERVER(display::DisplayObserver, observers_,
158 OnDisplayMetricsChanged(*local_display, changed_values)); 159 OnDisplayMetricsChanged(*local_display, changed_values));
159 } 160 }
160 161
161 gfx::Point ScreenMus::GetCursorScreenPoint() { 162 gfx::Point ScreenMus::GetCursorScreenPoint() {
162 NOTIMPLEMENTED(); 163 NOTIMPLEMENTED();
163 return gfx::Point(); 164 return gfx::Point();
164 } 165 }
165 166
166 gfx::NativeWindow ScreenMus::GetWindowUnderCursor() { 167 gfx::NativeWindow ScreenMus::GetWindowUnderCursor() {
167 NOTIMPLEMENTED(); 168 NOTIMPLEMENTED();
168 return nullptr; 169 return nullptr;
169 } 170 }
170 171
171 gfx::NativeWindow ScreenMus::GetWindowAtScreenPoint(const gfx::Point& point) { 172 gfx::NativeWindow ScreenMus::GetWindowAtScreenPoint(const gfx::Point& point) {
172 NOTIMPLEMENTED(); 173 NOTIMPLEMENTED();
173 return nullptr; 174 return nullptr;
174 } 175 }
175 176
176 gfx::Display ScreenMus::GetPrimaryDisplay() const { 177 display::Display ScreenMus::GetPrimaryDisplay() const {
177 return displays_[primary_display_index_]; 178 return displays_[primary_display_index_];
178 } 179 }
179 180
180 gfx::Display ScreenMus::GetDisplayNearestWindow(gfx::NativeView view) const { 181 display::Display ScreenMus::GetDisplayNearestWindow(
182 gfx::NativeView view) const {
181 //NOTIMPLEMENTED(); 183 //NOTIMPLEMENTED();
182 return GetPrimaryDisplay(); 184 return GetPrimaryDisplay();
183 } 185 }
184 186
185 gfx::Display ScreenMus::GetDisplayNearestPoint(const gfx::Point& point) const { 187 display::Display ScreenMus::GetDisplayNearestPoint(
188 const gfx::Point& point) const {
186 return *gfx::FindDisplayNearestPoint(displays_, point); 189 return *gfx::FindDisplayNearestPoint(displays_, point);
187 } 190 }
188 191
189 int ScreenMus::GetNumDisplays() const { 192 int ScreenMus::GetNumDisplays() const {
190 return static_cast<int>(displays_.size()); 193 return static_cast<int>(displays_.size());
191 } 194 }
192 195
193 std::vector<gfx::Display> ScreenMus::GetAllDisplays() const { 196 std::vector<display::Display> ScreenMus::GetAllDisplays() const {
194 return displays_; 197 return displays_;
195 } 198 }
196 199
197 gfx::Display ScreenMus::GetDisplayMatching(const gfx::Rect& match_rect) const { 200 display::Display ScreenMus::GetDisplayMatching(
198 const gfx::Display* match = 201 const gfx::Rect& match_rect) const {
202 const display::Display* match =
199 gfx::FindDisplayWithBiggestIntersection(displays_, match_rect); 203 gfx::FindDisplayWithBiggestIntersection(displays_, match_rect);
200 return match ? *match : GetPrimaryDisplay(); 204 return match ? *match : GetPrimaryDisplay();
201 } 205 }
202 206
203 void ScreenMus::AddObserver(gfx::DisplayObserver* observer) { 207 void ScreenMus::AddObserver(display::DisplayObserver* observer) {
204 observers_.AddObserver(observer); 208 observers_.AddObserver(observer);
205 } 209 }
206 210
207 void ScreenMus::RemoveObserver(gfx::DisplayObserver* observer) { 211 void ScreenMus::RemoveObserver(display::DisplayObserver* observer) {
208 observers_.RemoveObserver(observer); 212 observers_.RemoveObserver(observer);
209 } 213 }
210 214
211 void ScreenMus::OnDisplays(mojo::Array<mus::mojom::DisplayPtr> displays) { 215 void ScreenMus::OnDisplays(mojo::Array<mus::mojom::DisplayPtr> displays) {
212 // This should only be called once from Init() before any observers have been 216 // This should only be called once from Init() before any observers have been
213 // added. 217 // added.
214 DCHECK(displays_.empty()); 218 DCHECK(displays_.empty());
215 displays_ = displays.To<std::vector<gfx::Display>>(); 219 displays_ = displays.To<std::vector<display::Display>>();
216 DCHECK(!displays_.empty()); 220 DCHECK(!displays_.empty());
217 for (size_t i = 0; i < displays.size(); ++i) { 221 for (size_t i = 0; i < displays.size(); ++i) {
218 if (displays[i]->is_primary) { 222 if (displays[i]->is_primary) {
219 primary_display_index_ = static_cast<int>(i); 223 primary_display_index_ = static_cast<int>(i);
220 // TODO(sky): Make WindowManagerFrameValues per display. 224 // TODO(sky): Make WindowManagerFrameValues per display.
221 WindowManagerFrameValues frame_values = 225 WindowManagerFrameValues frame_values =
222 displays[i]->frame_decoration_values.To<WindowManagerFrameValues>(); 226 displays[i]->frame_decoration_values.To<WindowManagerFrameValues>();
223 WindowManagerFrameValues::SetInstance(frame_values); 227 WindowManagerFrameValues::SetInstance(frame_values);
224 } 228 }
225 } 229 }
226 } 230 }
227 231
228 void ScreenMus::OnDisplaysChanged( 232 void ScreenMus::OnDisplaysChanged(
229 mojo::Array<mus::mojom::DisplayPtr> transport_displays) { 233 mojo::Array<mus::mojom::DisplayPtr> transport_displays) {
230 for (size_t i = 0; i < transport_displays.size(); ++i) { 234 for (size_t i = 0; i < transport_displays.size(); ++i) {
231 const bool is_primary = transport_displays[i]->is_primary; 235 const bool is_primary = transport_displays[i]->is_primary;
232 ProcessDisplayChanged(transport_displays[i].To<gfx::Display>(), is_primary); 236 ProcessDisplayChanged(transport_displays[i].To<display::Display>(),
237 is_primary);
233 if (is_primary) { 238 if (is_primary) {
234 WindowManagerFrameValues frame_values = 239 WindowManagerFrameValues frame_values =
235 transport_displays[i] 240 transport_displays[i]
236 ->frame_decoration_values.To<WindowManagerFrameValues>(); 241 ->frame_decoration_values.To<WindowManagerFrameValues>();
237 WindowManagerFrameValues::SetInstance(frame_values); 242 WindowManagerFrameValues::SetInstance(frame_values);
238 if (delegate_) 243 if (delegate_)
239 delegate_->OnWindowManagerFrameValuesChanged(); 244 delegate_->OnWindowManagerFrameValuesChanged();
240 } 245 }
241 } 246 }
242 } 247 }
243 248
244 void ScreenMus::OnDisplayRemoved(int64_t id) { 249 void ScreenMus::OnDisplayRemoved(int64_t id) {
245 const int index = FindDisplayIndexById(id); 250 const int index = FindDisplayIndexById(id);
246 DCHECK_NE(-1, index); 251 DCHECK_NE(-1, index);
247 // Another display must become primary before the existing primary is 252 // Another display must become primary before the existing primary is
248 // removed. 253 // removed.
249 DCHECK_NE(index, primary_display_index_); 254 DCHECK_NE(index, primary_display_index_);
250 const gfx::Display display = displays_[index]; 255 const display::Display display = displays_[index];
251 FOR_EACH_OBSERVER(gfx::DisplayObserver, observers_, 256 FOR_EACH_OBSERVER(display::DisplayObserver, observers_,
252 OnDisplayRemoved(display)); 257 OnDisplayRemoved(display));
253 } 258 }
254 259
255 } // namespace views 260 } // namespace views
OLDNEW
« no previous file with comments | « ui/views/mus/screen_mus.h ('k') | ui/views/test/desktop_screen_x11_test_api.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698