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

Side by Side Diff: chrome/browser/extensions/display_info_provider_chromeos.cc

Issue 1594683002: Introduce DisplayConfigurationController (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@issue_576375_display1b1
Patch Set: Rebase Created 4 years, 11 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
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 "chrome/browser/extensions/display_info_provider_chromeos.h" 5 #include "chrome/browser/extensions/display_info_provider_chromeos.h"
6 6
7 #include <stdint.h> 7 #include <stdint.h>
8 8
9 #include "ash/display/display_configuration_controller.h"
9 #include "ash/display/display_manager.h" 10 #include "ash/display/display_manager.h"
10 #include "ash/display/window_tree_host_manager.h"
11 #include "ash/shell.h" 11 #include "ash/shell.h"
12 #include "base/strings/string_number_conversions.h" 12 #include "base/strings/string_number_conversions.h"
13 #include "extensions/common/api/system_display.h" 13 #include "extensions/common/api/system_display.h"
14 #include "ui/gfx/display.h" 14 #include "ui/gfx/display.h"
15 #include "ui/gfx/geometry/point.h" 15 #include "ui/gfx/geometry/point.h"
16 #include "ui/gfx/geometry/rect.h" 16 #include "ui/gfx/geometry/rect.h"
17 17
18 using ash::DisplayManager;
19
20 namespace extensions { 18 namespace extensions {
21 19
22 using api::system_display::Bounds; 20 using api::system_display::Bounds;
23 using api::system_display::DisplayUnitInfo; 21 using api::system_display::DisplayUnitInfo;
24 using api::system_display::DisplayProperties; 22 using api::system_display::DisplayProperties;
25 using api::system_display::Insets; 23 using api::system_display::Insets;
26 24
27 namespace { 25 namespace {
28 26
29 // Maximum allowed bounds origin absolute value. 27 // Maximum allowed bounds origin absolute value.
(...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after
159 } 157 }
160 158
161 // Updates the display layout for the target display in reference to the primary 159 // Updates the display layout for the target display in reference to the primary
162 // display. 160 // display.
163 void UpdateDisplayLayout(const gfx::Rect& primary_display_bounds, 161 void UpdateDisplayLayout(const gfx::Rect& primary_display_bounds,
164 int primary_display_id, 162 int primary_display_id,
165 const gfx::Rect& target_display_bounds, 163 const gfx::Rect& target_display_bounds,
166 int target_display_id) { 164 int target_display_id) {
167 ash::DisplayLayout layout = 165 ash::DisplayLayout layout =
168 GetLayoutForRectangles(primary_display_bounds, target_display_bounds); 166 GetLayoutForRectangles(primary_display_bounds, target_display_bounds);
169 ash::Shell::GetInstance()->display_manager()->SetLayoutForCurrentDisplays( 167 layout.primary_id = primary_display_id;
170 layout); 168 ash::Shell::GetInstance()
169 ->display_configuration_controller()
170 ->SetDisplayLayout(target_display_id, layout, false /* user_action */);
171 } 171 }
172 172
173 // Validates that parameters passed to the SetInfo function are valid for the 173 // Validates that parameters passed to the SetInfo function are valid for the
174 // desired display and the current display manager state. 174 // desired display and the current display manager state.
175 // Returns whether the parameters are valid. On failure |error| is set to the 175 // Returns whether the parameters are valid. On failure |error| is set to the
176 // error message. 176 // error message.
177 bool ValidateParamsForDisplay(const DisplayProperties& info, 177 bool ValidateParamsForDisplay(const DisplayProperties& info,
178 const gfx::Display& display, 178 const gfx::Display& display,
179 DisplayManager* display_manager, 179 ash::DisplayManager* display_manager,
180 int64_t primary_display_id, 180 int64_t primary_display_id,
181 std::string* error) { 181 std::string* error) {
182 bool is_primary = display.id() == primary_display_id || 182 bool is_primary = display.id() == primary_display_id ||
183 (info.is_primary && *info.is_primary); 183 (info.is_primary && *info.is_primary);
184 184
185 // If mirroring source id is set, a display with the given id should exist, 185 // If mirroring source id is set, a display with the given id should exist,
186 // and if should not be the same as the target display's id. 186 // and if should not be the same as the target display's id.
187 if (info.mirroring_source_id && !info.mirroring_source_id->empty()) { 187 if (info.mirroring_source_id && !info.mirroring_source_id->empty()) {
188 int64_t mirroring_id; 188 int64_t mirroring_id;
189 if (!base::StringToInt64(*info.mirroring_source_id, &mirroring_id) || 189 if (!base::StringToInt64(*info.mirroring_source_id, &mirroring_id) ||
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
262 if ((info.overscan->top + info.overscan->bottom) * 2 > screen_height) { 262 if ((info.overscan->top + info.overscan->bottom) * 2 > screen_height) {
263 *error = "Vertical overscan is more than half of the screen height."; 263 *error = "Vertical overscan is more than half of the screen height.";
264 return false; 264 return false;
265 } 265 }
266 } 266 }
267 return true; 267 return true;
268 } 268 }
269 269
270 // Gets the display with the provided string id. 270 // Gets the display with the provided string id.
271 gfx::Display GetTargetDisplay(const std::string& display_id_str, 271 gfx::Display GetTargetDisplay(const std::string& display_id_str,
272 DisplayManager* manager) { 272 ash::DisplayManager* manager) {
273 int64_t display_id; 273 int64_t display_id;
274 if (!base::StringToInt64(display_id_str, &display_id)) { 274 if (!base::StringToInt64(display_id_str, &display_id)) {
275 // This should return invalid display. 275 // This should return invalid display.
276 return gfx::Display(); 276 return gfx::Display();
277 } 277 }
278 return manager->GetDisplayForId(display_id); 278 return manager->GetDisplayForId(display_id);
279 } 279 }
280 280
281 } // namespace 281 } // namespace
282 282
283 DisplayInfoProviderChromeOS::DisplayInfoProviderChromeOS() { 283 DisplayInfoProviderChromeOS::DisplayInfoProviderChromeOS() {
284 } 284 }
285 285
286 DisplayInfoProviderChromeOS::~DisplayInfoProviderChromeOS() { 286 DisplayInfoProviderChromeOS::~DisplayInfoProviderChromeOS() {
287 } 287 }
288 288
289 bool DisplayInfoProviderChromeOS::SetInfo(const std::string& display_id_str, 289 bool DisplayInfoProviderChromeOS::SetInfo(const std::string& display_id_str,
290 const DisplayProperties& info, 290 const DisplayProperties& info,
291 std::string* error) { 291 std::string* error) {
292 DisplayManager* display_manager = 292 ash::DisplayManager* display_manager =
293 ash::Shell::GetInstance()->display_manager(); 293 ash::Shell::GetInstance()->display_manager();
294 DCHECK(display_manager); 294 ash::DisplayConfigurationController* display_configuration_controller =
295 ash::WindowTreeHostManager* window_tree_host_manager = 295 ash::Shell::GetInstance()->display_configuration_controller();
296 ash::Shell::GetInstance()->window_tree_host_manager();
297 DCHECK(window_tree_host_manager);
298 296
299 const gfx::Display target = GetTargetDisplay(display_id_str, display_manager); 297 const gfx::Display target = GetTargetDisplay(display_id_str, display_manager);
300 298
301 if (target.id() == gfx::Display::kInvalidDisplayID) { 299 if (target.id() == gfx::Display::kInvalidDisplayID) {
302 *error = "Display not found."; 300 *error = "Display not found.";
303 return false; 301 return false;
304 } 302 }
305 303
306 int64_t display_id = target.id(); 304 int64_t display_id = target.id();
307 // TODO(scottmg): Native is wrong http://crbug.com/133312 305 // TODO(scottmg): Native is wrong http://crbug.com/133312
308 const gfx::Display& primary = 306 const gfx::Display& primary =
309 gfx::Screen::GetNativeScreen()->GetPrimaryDisplay(); 307 gfx::Screen::GetNativeScreen()->GetPrimaryDisplay();
310 308
311 if (!ValidateParamsForDisplay( 309 if (!ValidateParamsForDisplay(
312 info, target, display_manager, primary.id(), error)) { 310 info, target, display_manager, primary.id(), error)) {
313 return false; 311 return false;
314 } 312 }
315 313
316 // Process 'isPrimary' parameter. 314 // Process 'isPrimary' parameter.
317 if (info.is_primary && *info.is_primary && target.id() != primary.id()) 315 if (info.is_primary && *info.is_primary && target.id() != primary.id()) {
318 window_tree_host_manager->SetPrimaryDisplayId(display_id); 316 display_configuration_controller->SetPrimaryDisplayId(
317 display_id, false /* user_action */);
318 }
319 319
320 // Process 'mirroringSourceId' parameter. 320 // Process 'mirroringSourceId' parameter.
321 if (info.mirroring_source_id && 321 if (info.mirroring_source_id) {
322 info.mirroring_source_id->empty() == display_manager->IsInMirrorMode()) { 322 bool mirror = !info.mirroring_source_id->empty();
323 window_tree_host_manager->ToggleMirrorMode(); 323 display_configuration_controller->SetMirrorMode(mirror,
324 false /* user_action */);
324 } 325 }
325 326
326 // Process 'overscan' parameter. 327 // Process 'overscan' parameter.
327 if (info.overscan) { 328 if (info.overscan) {
328 display_manager->SetOverscanInsets(display_id, 329 display_manager->SetOverscanInsets(display_id,
329 gfx::Insets(info.overscan->top, 330 gfx::Insets(info.overscan->top,
330 info.overscan->left, 331 info.overscan->left,
331 info.overscan->bottom, 332 info.overscan->bottom,
332 info.overscan->right)); 333 info.overscan->right));
333 } 334 }
334 335
335 // Process 'rotation' parameter. 336 // Process 'rotation' parameter.
336 if (info.rotation) { 337 if (info.rotation) {
337 display_manager->SetDisplayRotation(display_id, 338 display_configuration_controller->SetDisplayRotation(
338 DegreesToRotation(*info.rotation), 339 display_id, DegreesToRotation(*info.rotation),
339 gfx::Display::ROTATION_SOURCE_ACTIVE); 340 gfx::Display::ROTATION_SOURCE_ACTIVE, false /* user_action */);
340 } 341 }
341 342
342 // Process new display origin parameters. 343 // Process new display origin parameters.
343 gfx::Point new_bounds_origin = target.bounds().origin(); 344 gfx::Point new_bounds_origin = target.bounds().origin();
344 if (info.bounds_origin_x) 345 if (info.bounds_origin_x)
345 new_bounds_origin.set_x(*info.bounds_origin_x); 346 new_bounds_origin.set_x(*info.bounds_origin_x);
346 if (info.bounds_origin_y) 347 if (info.bounds_origin_y)
347 new_bounds_origin.set_y(*info.bounds_origin_y); 348 new_bounds_origin.set_y(*info.bounds_origin_y);
348 349
349 if (new_bounds_origin != target.bounds().origin()) { 350 if (new_bounds_origin != target.bounds().origin()) {
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
414 } 415 }
415 return all_displays; 416 return all_displays;
416 } 417 }
417 418
418 // static 419 // static
419 DisplayInfoProvider* DisplayInfoProvider::Create() { 420 DisplayInfoProvider* DisplayInfoProvider::Create() {
420 return new DisplayInfoProviderChromeOS(); 421 return new DisplayInfoProviderChromeOS();
421 } 422 }
422 423
423 } // namespace extensions 424 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698