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

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

Issue 1920263003: Rename gfx::Display/Screen to display::Display/Screen in chrome (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: 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
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_configuration_controller.h"
10 #include "ash/display/display_manager.h" 10 #include "ash/display/display_manager.h"
11 #include "ash/display/resolution_notification_controller.h" 11 #include "ash/display/resolution_notification_controller.h"
12 #include "ash/shell.h" 12 #include "ash/shell.h"
13 #include "base/strings/string_number_conversions.h" 13 #include "base/strings/string_number_conversions.h"
14 #include "chrome/browser/chromeos/display/display_preferences.h" 14 #include "chrome/browser/chromeos/display/display_preferences.h"
15 #include "extensions/common/api/system_display.h" 15 #include "extensions/common/api/system_display.h"
16 #include "ui/display/display.h"
16 #include "ui/display/manager/display_layout.h" 17 #include "ui/display/manager/display_layout.h"
17 #include "ui/gfx/display.h"
18 #include "ui/gfx/geometry/point.h" 18 #include "ui/gfx/geometry/point.h"
19 #include "ui/gfx/geometry/rect.h" 19 #include "ui/gfx/geometry/rect.h"
20 20
21 namespace extensions { 21 namespace extensions {
22 22
23 using api::system_display::Bounds; 23 using api::system_display::Bounds;
24 using api::system_display::DisplayUnitInfo; 24 using api::system_display::DisplayUnitInfo;
25 using api::system_display::DisplayProperties; 25 using api::system_display::DisplayProperties;
26 using api::system_display::Insets; 26 using api::system_display::Insets;
27 27
28 namespace { 28 namespace {
29 29
30 // Maximum allowed bounds origin absolute value. 30 // Maximum allowed bounds origin absolute value.
31 const int kMaxBoundsOrigin = 200 * 1000; 31 const int kMaxBoundsOrigin = 200 * 1000;
32 32
33 // Checks if the given integer value is valid display rotation in degrees. 33 // Checks if the given integer value is valid display rotation in degrees.
34 bool IsValidRotationValue(int rotation) { 34 bool IsValidRotationValue(int rotation) {
35 return rotation == 0 || rotation == 90 || rotation == 180 || rotation == 270; 35 return rotation == 0 || rotation == 90 || rotation == 180 || rotation == 270;
36 } 36 }
37 37
38 // Converts integer integer value in degrees to Rotation enum value. 38 // Converts integer integer value in degrees to Rotation enum value.
39 gfx::Display::Rotation DegreesToRotation(int degrees) { 39 display::Display::Rotation DegreesToRotation(int degrees) {
40 DCHECK(IsValidRotationValue(degrees)); 40 DCHECK(IsValidRotationValue(degrees));
41 switch (degrees) { 41 switch (degrees) {
42 case 0: 42 case 0:
43 return gfx::Display::ROTATE_0; 43 return display::Display::ROTATE_0;
44 case 90: 44 case 90:
45 return gfx::Display::ROTATE_90; 45 return display::Display::ROTATE_90;
46 case 180: 46 case 180:
47 return gfx::Display::ROTATE_180; 47 return display::Display::ROTATE_180;
48 case 270: 48 case 270:
49 return gfx::Display::ROTATE_270; 49 return display::Display::ROTATE_270;
50 default: 50 default:
51 return gfx::Display::ROTATE_0; 51 return display::Display::ROTATE_0;
52 } 52 }
53 } 53 }
54 54
55 // Checks if the given point is over the radius vector described by it's end 55 // Checks if the given point is over the radius vector described by it's end
56 // point |vector|. The point is over a vector if it's on its positive (left) 56 // point |vector|. The point is over a vector if it's on its positive (left)
57 // side. The method sees a point on the same line as the vector as being over 57 // side. The method sees a point on the same line as the vector as being over
58 // the vector. 58 // the vector.
59 bool PointIsOverRadiusVector(const gfx::Point& point, 59 bool PointIsOverRadiusVector(const gfx::Point& point,
60 const gfx::Point& vector) { 60 const gfx::Point& vector) {
61 // |point| is left of |vector| if its radius vector's scalar product with a 61 // |point| is left of |vector| if its radius vector's scalar product with a
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after
177 ash::Shell::GetInstance() 177 ash::Shell::GetInstance()
178 ->display_configuration_controller() 178 ->display_configuration_controller()
179 ->SetDisplayLayout(std::move(layout), true /* user_action */); 179 ->SetDisplayLayout(std::move(layout), true /* user_action */);
180 } 180 }
181 181
182 // Validates that parameters passed to the SetInfo function are valid for the 182 // Validates that parameters passed to the SetInfo function are valid for the
183 // desired display and the current display manager state. 183 // desired display and the current display manager state.
184 // Returns whether the parameters are valid. On failure |error| is set to the 184 // Returns whether the parameters are valid. On failure |error| is set to the
185 // error message. 185 // error message.
186 bool ValidateParamsForDisplay(const DisplayProperties& info, 186 bool ValidateParamsForDisplay(const DisplayProperties& info,
187 const gfx::Display& display, 187 const display::Display& display,
188 ash::DisplayManager* display_manager, 188 ash::DisplayManager* display_manager,
189 int64_t primary_display_id, 189 int64_t primary_display_id,
190 std::string* error) { 190 std::string* error) {
191 int64_t id = display.id(); 191 int64_t id = display.id();
192 bool is_primary = 192 bool is_primary =
193 id == primary_display_id || (info.is_primary && *info.is_primary); 193 id == primary_display_id || (info.is_primary && *info.is_primary);
194 194
195 // If mirroring source id is set, a display with the given id should exist, 195 // If mirroring source id is set, a display with the given id should exist,
196 // and if should not be the same as the target display's id. 196 // and if should not be the same as the target display's id.
197 if (info.mirroring_source_id && !info.mirroring_source_id->empty()) { 197 if (info.mirroring_source_id && !info.mirroring_source_id->empty()) {
198 int64_t mirroring_id; 198 int64_t mirroring_id;
199 if (!base::StringToInt64(*info.mirroring_source_id, &mirroring_id) || 199 if (!base::StringToInt64(*info.mirroring_source_id, &mirroring_id) ||
200 display_manager->GetDisplayForId(mirroring_id).id() == 200 display_manager->GetDisplayForId(mirroring_id).id() ==
201 gfx::Display::kInvalidDisplayID) { 201 display::Display::kInvalidDisplayID) {
202 *error = "Display " + *info.mirroring_source_id + " not found."; 202 *error = "Display " + *info.mirroring_source_id + " not found.";
203 return false; 203 return false;
204 } 204 }
205 205
206 if (*info.mirroring_source_id == base::Int64ToString(id)) { 206 if (*info.mirroring_source_id == base::Int64ToString(id)) {
207 *error = "Not allowed to mirror self."; 207 *error = "Not allowed to mirror self.";
208 return false; 208 return false;
209 } 209 }
210 } 210 }
211 211
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after
292 if (new_mode.IsEquivalent(current_mode)) { 292 if (new_mode.IsEquivalent(current_mode)) {
293 *error = "Display mode mataches crrent mode."; 293 *error = "Display mode mataches crrent mode.";
294 return false; 294 return false;
295 } 295 }
296 296
297 if (!display_manager->SetDisplayMode(id, new_mode)) { 297 if (!display_manager->SetDisplayMode(id, new_mode)) {
298 *error = "Unable to set the display mode."; 298 *error = "Unable to set the display mode.";
299 return false; 299 return false;
300 } 300 }
301 301
302 if (!gfx::Display::IsInternalDisplayId(id)) { 302 if (!display::Display::IsInternalDisplayId(id)) {
303 // For external displays, show a notification confirming the resolution 303 // For external displays, show a notification confirming the resolution
304 // change. 304 // change.
305 ash::Shell::GetInstance() 305 ash::Shell::GetInstance()
306 ->resolution_notification_controller() 306 ->resolution_notification_controller()
307 ->PrepareNotification(id, current_mode, new_mode, 307 ->PrepareNotification(id, current_mode, new_mode,
308 base::Bind(&chromeos::StoreDisplayPrefs)); 308 base::Bind(&chromeos::StoreDisplayPrefs));
309 } 309 }
310 } 310 }
311 return true; 311 return true;
312 } 312 }
313 313
314 // Gets the display with the provided string id. 314 // Gets the display with the provided string id.
315 gfx::Display GetTargetDisplay(const std::string& display_id_str, 315 display::Display GetTargetDisplay(const std::string& display_id_str,
316 ash::DisplayManager* manager) { 316 ash::DisplayManager* manager) {
317 int64_t display_id; 317 int64_t display_id;
318 if (!base::StringToInt64(display_id_str, &display_id)) { 318 if (!base::StringToInt64(display_id_str, &display_id)) {
319 // This should return invalid display. 319 // This should return invalid display.
320 return gfx::Display(); 320 return display::Display();
321 } 321 }
322 return manager->GetDisplayForId(display_id); 322 return manager->GetDisplayForId(display_id);
323 } 323 }
324 324
325 extensions::api::system_display::DisplayMode GetDisplayMode( 325 extensions::api::system_display::DisplayMode GetDisplayMode(
326 ash::DisplayManager* display_manager, 326 ash::DisplayManager* display_manager,
327 const ash::DisplayInfo& display_info, 327 const ash::DisplayInfo& display_info,
328 const ash::DisplayMode& display_mode) { 328 const ash::DisplayMode& display_mode) {
329 extensions::api::system_display::DisplayMode result; 329 extensions::api::system_display::DisplayMode result;
330 330
331 bool is_internal = gfx::Display::HasInternalDisplay() && 331 bool is_internal = display::Display::HasInternalDisplay() &&
332 gfx::Display::InternalDisplayId() == display_info.id(); 332 display::Display::InternalDisplayId() == display_info.id();
333 gfx::Size size_dip = display_mode.GetSizeInDIP(is_internal); 333 gfx::Size size_dip = display_mode.GetSizeInDIP(is_internal);
334 result.width = size_dip.width(); 334 result.width = size_dip.width();
335 result.height = size_dip.height(); 335 result.height = size_dip.height();
336 result.width_in_native_pixels = display_mode.size.width(); 336 result.width_in_native_pixels = display_mode.size.width();
337 result.height_in_native_pixels = display_mode.size.height(); 337 result.height_in_native_pixels = display_mode.size.height();
338 result.ui_scale = display_mode.ui_scale; 338 result.ui_scale = display_mode.ui_scale;
339 result.device_scale_factor = display_mode.device_scale_factor; 339 result.device_scale_factor = display_mode.device_scale_factor;
340 result.is_native = display_mode.native; 340 result.is_native = display_mode.native;
341 result.is_selected = display_mode.IsEquivalent( 341 result.is_selected = display_mode.IsEquivalent(
342 display_manager->GetActiveModeForDisplayId(display_info.id())); 342 display_manager->GetActiveModeForDisplayId(display_info.id()));
343 return result; 343 return result;
344 } 344 }
345 345
346 } // namespace 346 } // namespace
347 347
348 DisplayInfoProviderChromeOS::DisplayInfoProviderChromeOS() { 348 DisplayInfoProviderChromeOS::DisplayInfoProviderChromeOS() {
349 } 349 }
350 350
351 DisplayInfoProviderChromeOS::~DisplayInfoProviderChromeOS() { 351 DisplayInfoProviderChromeOS::~DisplayInfoProviderChromeOS() {
352 } 352 }
353 353
354 bool DisplayInfoProviderChromeOS::SetInfo(const std::string& display_id_str, 354 bool DisplayInfoProviderChromeOS::SetInfo(const std::string& display_id_str,
355 const DisplayProperties& info, 355 const DisplayProperties& info,
356 std::string* error) { 356 std::string* error) {
357 ash::DisplayManager* display_manager = 357 ash::DisplayManager* display_manager =
358 ash::Shell::GetInstance()->display_manager(); 358 ash::Shell::GetInstance()->display_manager();
359 ash::DisplayConfigurationController* display_configuration_controller = 359 ash::DisplayConfigurationController* display_configuration_controller =
360 ash::Shell::GetInstance()->display_configuration_controller(); 360 ash::Shell::GetInstance()->display_configuration_controller();
361 361
362 const gfx::Display target = GetTargetDisplay(display_id_str, display_manager); 362 const display::Display target =
363 GetTargetDisplay(display_id_str, display_manager);
363 364
364 if (target.id() == gfx::Display::kInvalidDisplayID) { 365 if (target.id() == display::Display::kInvalidDisplayID) {
365 *error = "Display not found."; 366 *error = "Display not found.";
366 return false; 367 return false;
367 } 368 }
368 369
369 int64_t display_id = target.id(); 370 int64_t display_id = target.id();
370 const gfx::Display& primary = gfx::Screen::GetScreen()->GetPrimaryDisplay(); 371 const display::Display& primary =
372 display::Screen::GetScreen()->GetPrimaryDisplay();
371 373
372 if (!ValidateParamsForDisplay( 374 if (!ValidateParamsForDisplay(
373 info, target, display_manager, primary.id(), error)) { 375 info, target, display_manager, primary.id(), error)) {
374 return false; 376 return false;
375 } 377 }
376 378
377 // Process 'isPrimary' parameter. 379 // Process 'isPrimary' parameter.
378 if (info.is_primary && *info.is_primary && target.id() != primary.id()) { 380 if (info.is_primary && *info.is_primary && target.id() != primary.id()) {
379 display_configuration_controller->SetPrimaryDisplayId( 381 display_configuration_controller->SetPrimaryDisplayId(
380 display_id, true /* user_action */); 382 display_id, true /* user_action */);
(...skipping 12 matching lines...) Expand all
393 gfx::Insets(info.overscan->top, 395 gfx::Insets(info.overscan->top,
394 info.overscan->left, 396 info.overscan->left,
395 info.overscan->bottom, 397 info.overscan->bottom,
396 info.overscan->right)); 398 info.overscan->right));
397 } 399 }
398 400
399 // Process 'rotation' parameter. 401 // Process 'rotation' parameter.
400 if (info.rotation) { 402 if (info.rotation) {
401 display_configuration_controller->SetDisplayRotation( 403 display_configuration_controller->SetDisplayRotation(
402 display_id, DegreesToRotation(*info.rotation), 404 display_id, DegreesToRotation(*info.rotation),
403 gfx::Display::ROTATION_SOURCE_ACTIVE, true /* user_action */); 405 display::Display::ROTATION_SOURCE_ACTIVE, true /* user_action */);
404 } 406 }
405 407
406 // Process new display origin parameters. 408 // Process new display origin parameters.
407 gfx::Point new_bounds_origin = target.bounds().origin(); 409 gfx::Point new_bounds_origin = target.bounds().origin();
408 if (info.bounds_origin_x) 410 if (info.bounds_origin_x)
409 new_bounds_origin.set_x(*info.bounds_origin_x); 411 new_bounds_origin.set_x(*info.bounds_origin_x);
410 if (info.bounds_origin_y) 412 if (info.bounds_origin_y)
411 new_bounds_origin.set_y(*info.bounds_origin_y); 413 new_bounds_origin.set_y(*info.bounds_origin_y);
412 414
413 if (new_bounds_origin != target.bounds().origin()) { 415 if (new_bounds_origin != target.bounds().origin()) {
414 gfx::Rect target_bounds = target.bounds(); 416 gfx::Rect target_bounds = target.bounds();
415 target_bounds.Offset(new_bounds_origin.x() - target.bounds().x(), 417 target_bounds.Offset(new_bounds_origin.x() - target.bounds().x(),
416 new_bounds_origin.y() - target.bounds().y()); 418 new_bounds_origin.y() - target.bounds().y());
417 UpdateDisplayLayout( 419 UpdateDisplayLayout(
418 primary.bounds(), primary.id(), target_bounds, target.id()); 420 primary.bounds(), primary.id(), target_bounds, target.id());
419 } 421 }
420 422
421 return true; 423 return true;
422 } 424 }
423 425
424 void DisplayInfoProviderChromeOS::UpdateDisplayUnitInfoForPlatform( 426 void DisplayInfoProviderChromeOS::UpdateDisplayUnitInfoForPlatform(
425 const gfx::Display& display, 427 const display::Display& display,
426 extensions::api::system_display::DisplayUnitInfo* unit) { 428 extensions::api::system_display::DisplayUnitInfo* unit) {
427 ash::DisplayManager* display_manager = 429 ash::DisplayManager* display_manager =
428 ash::Shell::GetInstance()->display_manager(); 430 ash::Shell::GetInstance()->display_manager();
429 unit->name = display_manager->GetDisplayNameForId(display.id()); 431 unit->name = display_manager->GetDisplayNameForId(display.id());
430 if (display_manager->IsInMirrorMode()) { 432 if (display_manager->IsInMirrorMode()) {
431 unit->mirroring_source_id = 433 unit->mirroring_source_id =
432 base::Int64ToString(display_manager->mirroring_display_id()); 434 base::Int64ToString(display_manager->mirroring_display_id());
433 } 435 }
434 436
435 const ash::DisplayInfo& display_info = 437 const ash::DisplayInfo& display_info =
(...skipping 21 matching lines...) Expand all
457 ash::Shell::GetInstance()->display_manager()->SetUnifiedDesktopEnabled( 459 ash::Shell::GetInstance()->display_manager()->SetUnifiedDesktopEnabled(
458 enable); 460 enable);
459 } 461 }
460 462
461 DisplayUnitInfoList DisplayInfoProviderChromeOS::GetAllDisplaysInfo() { 463 DisplayUnitInfoList DisplayInfoProviderChromeOS::GetAllDisplaysInfo() {
462 ash::DisplayManager* display_manager = 464 ash::DisplayManager* display_manager =
463 ash::Shell::GetInstance()->display_manager(); 465 ash::Shell::GetInstance()->display_manager();
464 if (!display_manager->IsInUnifiedMode()) 466 if (!display_manager->IsInUnifiedMode())
465 return DisplayInfoProvider::GetAllDisplaysInfo(); 467 return DisplayInfoProvider::GetAllDisplaysInfo();
466 468
467 std::vector<gfx::Display> displays = 469 std::vector<display::Display> displays =
468 display_manager->software_mirroring_display_list(); 470 display_manager->software_mirroring_display_list();
469 CHECK_GT(displays.size(), 0u); 471 CHECK_GT(displays.size(), 0u);
470 472
471 // Use first display as primary. 473 // Use first display as primary.
472 int64_t primary_id = displays[0].id(); 474 int64_t primary_id = displays[0].id();
473 DisplayUnitInfoList all_displays; 475 DisplayUnitInfoList all_displays;
474 for (const gfx::Display& display : displays) { 476 for (const display::Display& display : displays) {
475 api::system_display::DisplayUnitInfo unit = 477 api::system_display::DisplayUnitInfo unit =
476 CreateDisplayUnitInfo(display, primary_id); 478 CreateDisplayUnitInfo(display, primary_id);
477 UpdateDisplayUnitInfoForPlatform(display, &unit); 479 UpdateDisplayUnitInfoForPlatform(display, &unit);
478 all_displays.push_back(std::move(unit)); 480 all_displays.push_back(std::move(unit));
479 } 481 }
480 return all_displays; 482 return all_displays;
481 } 483 }
482 484
483 // static 485 // static
484 DisplayInfoProvider* DisplayInfoProvider::Create() { 486 DisplayInfoProvider* DisplayInfoProvider::Create() {
485 return new DisplayInfoProviderChromeOS(); 487 return new DisplayInfoProviderChromeOS();
486 } 488 }
487 489
488 } // namespace extensions 490 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698