| 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 "chrome/browser/ui/webui/options/chromeos/display_options_handler.h" | 5 #include "chrome/browser/ui/webui/options/chromeos/display_options_handler.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 #include <stdint.h> | 8 #include <stdint.h> |
| 9 | 9 |
| 10 #include <memory> | 10 #include <memory> |
| (...skipping 16 matching lines...) Expand all Loading... |
| 27 #include "chrome/grit/generated_resources.h" | 27 #include "chrome/grit/generated_resources.h" |
| 28 #include "chromeos/chromeos_switches.h" | 28 #include "chromeos/chromeos_switches.h" |
| 29 #include "content/public/browser/user_metrics.h" | 29 #include "content/public/browser/user_metrics.h" |
| 30 #include "content/public/browser/web_ui.h" | 30 #include "content/public/browser/web_ui.h" |
| 31 #include "ui/base/l10n/l10n_util.h" | 31 #include "ui/base/l10n/l10n_util.h" |
| 32 #include "ui/display/display.h" | 32 #include "ui/display/display.h" |
| 33 #include "ui/display/manager/display_layout.h" | 33 #include "ui/display/manager/display_layout.h" |
| 34 #include "ui/display/manager/display_layout_builder.h" | 34 #include "ui/display/manager/display_layout_builder.h" |
| 35 #include "ui/display/manager/display_manager.h" | 35 #include "ui/display/manager/display_manager.h" |
| 36 #include "ui/display/screen.h" | 36 #include "ui/display/screen.h" |
| 37 #include "ui/display/types/display_constants.h" |
| 37 #include "ui/gfx/geometry/rect.h" | 38 #include "ui/gfx/geometry/rect.h" |
| 38 #include "ui/gfx/geometry/size_conversions.h" | 39 #include "ui/gfx/geometry/size_conversions.h" |
| 39 | 40 |
| 40 namespace chromeos { | 41 namespace chromeos { |
| 41 namespace options { | 42 namespace options { |
| 42 namespace { | 43 namespace { |
| 43 | 44 |
| 44 display::DisplayManager* GetDisplayManager() { | 45 display::DisplayManager* GetDisplayManager() { |
| 45 return ash::Shell::GetInstance()->display_manager(); | 46 return ash::Shell::GetInstance()->display_manager(); |
| 46 } | 47 } |
| 47 | 48 |
| 48 ash::DisplayConfigurationController* GetDisplayConfigurationController() { | 49 ash::DisplayConfigurationController* GetDisplayConfigurationController() { |
| 49 return ash::Shell::GetInstance()->display_configuration_controller(); | 50 return ash::Shell::GetInstance()->display_configuration_controller(); |
| 50 } | 51 } |
| 51 | 52 |
| 52 int64_t GetDisplayIdFromValue(const base::Value* arg) { | 53 int64_t GetDisplayIdFromValue(const base::Value* arg) { |
| 53 std::string id_value; | 54 std::string id_value; |
| 54 if (!arg->GetAsString(&id_value)) | 55 if (!arg->GetAsString(&id_value)) |
| 55 return display::Display::kInvalidDisplayID; | 56 return display::kInvalidDisplayId; |
| 56 int64_t display_id = display::Display::kInvalidDisplayID; | 57 int64_t display_id = display::kInvalidDisplayId; |
| 57 if (!base::StringToInt64(id_value, &display_id)) | 58 if (!base::StringToInt64(id_value, &display_id)) |
| 58 return display::Display::kInvalidDisplayID; | 59 return display::kInvalidDisplayId; |
| 59 return display_id; | 60 return display_id; |
| 60 } | 61 } |
| 61 | 62 |
| 62 int64_t GetDisplayIdFromArgs(const base::ListValue* args) { | 63 int64_t GetDisplayIdFromArgs(const base::ListValue* args) { |
| 63 const base::Value* arg; | 64 const base::Value* arg; |
| 64 if (!args->Get(0, &arg)) { | 65 if (!args->Get(0, &arg)) { |
| 65 LOG(ERROR) << "No display id arg"; | 66 LOG(ERROR) << "No display id arg"; |
| 66 return display::Display::kInvalidDisplayID; | 67 return display::kInvalidDisplayId; |
| 67 } | 68 } |
| 68 int64_t display_id = GetDisplayIdFromValue(arg); | 69 int64_t display_id = GetDisplayIdFromValue(arg); |
| 69 if (display_id == display::Display::kInvalidDisplayID) | 70 if (display_id == display::kInvalidDisplayId) |
| 70 LOG(ERROR) << "Invalid display id: " << *arg; | 71 LOG(ERROR) << "Invalid display id: " << *arg; |
| 71 return display_id; | 72 return display_id; |
| 72 } | 73 } |
| 73 | 74 |
| 74 int64_t GetDisplayIdFromDictionary(const base::DictionaryValue* dictionary, | 75 int64_t GetDisplayIdFromDictionary(const base::DictionaryValue* dictionary, |
| 75 const std::string& key) { | 76 const std::string& key) { |
| 76 const base::Value* arg; | 77 const base::Value* arg; |
| 77 if (!dictionary->Get(key, &arg)) | 78 if (!dictionary->Get(key, &arg)) |
| 78 return display::Display::kInvalidDisplayID; | 79 return display::kInvalidDisplayId; |
| 79 return GetDisplayIdFromValue(arg); | 80 return GetDisplayIdFromValue(arg); |
| 80 } | 81 } |
| 81 | 82 |
| 82 base::string16 GetColorProfileName(ui::ColorCalibrationProfile profile) { | 83 base::string16 GetColorProfileName(ui::ColorCalibrationProfile profile) { |
| 83 switch (profile) { | 84 switch (profile) { |
| 84 case ui::COLOR_PROFILE_STANDARD: | 85 case ui::COLOR_PROFILE_STANDARD: |
| 85 return l10n_util::GetStringUTF16( | 86 return l10n_util::GetStringUTF16( |
| 86 IDS_OPTIONS_SETTINGS_DISPLAY_OPTIONS_COLOR_PROFILE_STANDARD); | 87 IDS_OPTIONS_SETTINGS_DISPLAY_OPTIONS_COLOR_PROFILE_STANDARD); |
| 87 case ui::COLOR_PROFILE_DYNAMIC: | 88 case ui::COLOR_PROFILE_DYNAMIC: |
| 88 return l10n_util::GetStringUTF16( | 89 return l10n_util::GetStringUTF16( |
| (...skipping 264 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 353 color_profile_dict->SetInteger("profileId", color_profile); | 354 color_profile_dict->SetInteger("profileId", color_profile); |
| 354 color_profile_dict->SetString("name", profile_name); | 355 color_profile_dict->SetString("name", profile_name); |
| 355 available_color_profiles->Append(std::move(color_profile_dict)); | 356 available_color_profiles->Append(std::move(color_profile_dict)); |
| 356 } | 357 } |
| 357 js_display->Set("availableColorProfiles", available_color_profiles); | 358 js_display->Set("availableColorProfiles", available_color_profiles); |
| 358 | 359 |
| 359 if (display_manager->GetNumDisplays() > 1) { | 360 if (display_manager->GetNumDisplays() > 1) { |
| 360 const display::DisplayPlacement placement = | 361 const display::DisplayPlacement placement = |
| 361 display_manager->GetCurrentDisplayLayout().FindPlacementById( | 362 display_manager->GetCurrentDisplayLayout().FindPlacementById( |
| 362 display.id()); | 363 display.id()); |
| 363 if (placement.display_id != display::Display::kInvalidDisplayID) { | 364 if (placement.display_id != display::kInvalidDisplayId) { |
| 364 js_display->SetString( | 365 js_display->SetString( |
| 365 "parentId", base::Int64ToString(placement.parent_display_id)); | 366 "parentId", base::Int64ToString(placement.parent_display_id)); |
| 366 js_display->SetInteger("layoutType", placement.position); | 367 js_display->SetInteger("layoutType", placement.position); |
| 367 js_display->SetInteger("offset", placement.offset); | 368 js_display->SetInteger("offset", placement.offset); |
| 368 } | 369 } |
| 369 } | 370 } |
| 370 | 371 |
| 371 js_displays->Append(std::move(js_display)); | 372 js_displays->Append(std::move(js_display)); |
| 372 } | 373 } |
| 373 | 374 |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 408 NOTREACHED(); | 409 NOTREACHED(); |
| 409 content::RecordAction( | 410 content::RecordAction( |
| 410 base::UserMetricsAction("Options_DisplayToggleMirroring")); | 411 base::UserMetricsAction("Options_DisplayToggleMirroring")); |
| 411 GetDisplayConfigurationController()->SetMirrorMode(is_mirroring, | 412 GetDisplayConfigurationController()->SetMirrorMode(is_mirroring, |
| 412 true /* user_action */); | 413 true /* user_action */); |
| 413 } | 414 } |
| 414 | 415 |
| 415 void DisplayOptionsHandler::HandleSetPrimary(const base::ListValue* args) { | 416 void DisplayOptionsHandler::HandleSetPrimary(const base::ListValue* args) { |
| 416 DCHECK(!args->empty()); | 417 DCHECK(!args->empty()); |
| 417 int64_t display_id = GetDisplayIdFromArgs(args); | 418 int64_t display_id = GetDisplayIdFromArgs(args); |
| 418 if (display_id == display::Display::kInvalidDisplayID) | 419 if (display_id == display::kInvalidDisplayId) |
| 419 return; | 420 return; |
| 420 | 421 |
| 421 content::RecordAction(base::UserMetricsAction("Options_DisplaySetPrimary")); | 422 content::RecordAction(base::UserMetricsAction("Options_DisplaySetPrimary")); |
| 422 GetDisplayConfigurationController()->SetPrimaryDisplayId( | 423 GetDisplayConfigurationController()->SetPrimaryDisplayId( |
| 423 display_id, true /* user_action */); | 424 display_id, true /* user_action */); |
| 424 } | 425 } |
| 425 | 426 |
| 426 void DisplayOptionsHandler::HandleSetDisplayLayout( | 427 void DisplayOptionsHandler::HandleSetDisplayLayout( |
| 427 const base::ListValue* args) { | 428 const base::ListValue* args) { |
| 428 const base::ListValue* layouts = nullptr; | 429 const base::ListValue* layouts = nullptr; |
| 429 if (!args->GetList(0, &layouts)) | 430 if (!args->GetList(0, &layouts)) |
| 430 NOTREACHED(); | 431 NOTREACHED(); |
| 431 content::RecordAction(base::UserMetricsAction("Options_DisplayRearrange")); | 432 content::RecordAction(base::UserMetricsAction("Options_DisplayRearrange")); |
| 432 | 433 |
| 433 display::DisplayManager* display_manager = GetDisplayManager(); | 434 display::DisplayManager* display_manager = GetDisplayManager(); |
| 434 display::DisplayLayoutBuilder builder( | 435 display::DisplayLayoutBuilder builder( |
| 435 display_manager->GetCurrentDisplayLayout()); | 436 display_manager->GetCurrentDisplayLayout()); |
| 436 builder.ClearPlacements(); | 437 builder.ClearPlacements(); |
| 437 for (const auto& layout : *layouts) { | 438 for (const auto& layout : *layouts) { |
| 438 const base::DictionaryValue* dictionary; | 439 const base::DictionaryValue* dictionary; |
| 439 if (!layout->GetAsDictionary(&dictionary)) { | 440 if (!layout->GetAsDictionary(&dictionary)) { |
| 440 LOG(ERROR) << "Invalid layout dictionary: " << *dictionary; | 441 LOG(ERROR) << "Invalid layout dictionary: " << *dictionary; |
| 441 continue; | 442 continue; |
| 442 } | 443 } |
| 443 | 444 |
| 444 int64_t parent_id = GetDisplayIdFromDictionary(dictionary, "parentId"); | 445 int64_t parent_id = GetDisplayIdFromDictionary(dictionary, "parentId"); |
| 445 if (parent_id == display::Display::kInvalidDisplayID) | 446 if (parent_id == display::kInvalidDisplayId) |
| 446 continue; // No placement for root (primary) display. | 447 continue; // No placement for root (primary) display. |
| 447 | 448 |
| 448 int64_t display_id = GetDisplayIdFromDictionary(dictionary, "id"); | 449 int64_t display_id = GetDisplayIdFromDictionary(dictionary, "id"); |
| 449 if (display_id == display::Display::kInvalidDisplayID) { | 450 if (display_id == display::kInvalidDisplayId) { |
| 450 LOG(ERROR) << "Invalud display id in layout dictionary: " << *dictionary; | 451 LOG(ERROR) << "Invalud display id in layout dictionary: " << *dictionary; |
| 451 continue; | 452 continue; |
| 452 } | 453 } |
| 453 | 454 |
| 454 int position = 0; | 455 int position = 0; |
| 455 dictionary->GetInteger("layoutType", &position); | 456 dictionary->GetInteger("layoutType", &position); |
| 456 int offset = 0; | 457 int offset = 0; |
| 457 dictionary->GetInteger("offset", &offset); | 458 dictionary->GetInteger("offset", &offset); |
| 458 | 459 |
| 459 builder.AddDisplayPlacement( | 460 builder.AddDisplayPlacement( |
| 460 display_id, parent_id, | 461 display_id, parent_id, |
| 461 static_cast<display::DisplayPlacement::Position>(position), offset); | 462 static_cast<display::DisplayPlacement::Position>(position), offset); |
| 462 } | 463 } |
| 463 std::unique_ptr<display::DisplayLayout> layout = builder.Build(); | 464 std::unique_ptr<display::DisplayLayout> layout = builder.Build(); |
| 464 if (!display::DisplayLayout::Validate( | 465 if (!display::DisplayLayout::Validate( |
| 465 display_manager->GetCurrentDisplayIdList(), *layout)) { | 466 display_manager->GetCurrentDisplayIdList(), *layout)) { |
| 466 LOG(ERROR) << "Invalid layout: " << layout->ToString(); | 467 LOG(ERROR) << "Invalid layout: " << layout->ToString(); |
| 467 return; | 468 return; |
| 468 } | 469 } |
| 469 | 470 |
| 470 VLOG(1) << "Updating display layout: " << layout->ToString(); | 471 VLOG(1) << "Updating display layout: " << layout->ToString(); |
| 471 GetDisplayConfigurationController()->SetDisplayLayout(std::move(layout), | 472 GetDisplayConfigurationController()->SetDisplayLayout(std::move(layout), |
| 472 true /* user_action */); | 473 true /* user_action */); |
| 473 } | 474 } |
| 474 | 475 |
| 475 void DisplayOptionsHandler::HandleSetDisplayMode(const base::ListValue* args) { | 476 void DisplayOptionsHandler::HandleSetDisplayMode(const base::ListValue* args) { |
| 476 DCHECK(!args->empty()); | 477 DCHECK(!args->empty()); |
| 477 | 478 |
| 478 int64_t display_id = GetDisplayIdFromArgs(args); | 479 int64_t display_id = GetDisplayIdFromArgs(args); |
| 479 if (display_id == display::Display::kInvalidDisplayID) | 480 if (display_id == display::kInvalidDisplayId) |
| 480 return; | 481 return; |
| 481 | 482 |
| 482 const base::DictionaryValue* mode_data = nullptr; | 483 const base::DictionaryValue* mode_data = nullptr; |
| 483 if (!args->GetDictionary(1, &mode_data)) { | 484 if (!args->GetDictionary(1, &mode_data)) { |
| 484 LOG(ERROR) << "Failed to get mode data"; | 485 LOG(ERROR) << "Failed to get mode data"; |
| 485 return; | 486 return; |
| 486 } | 487 } |
| 487 | 488 |
| 488 scoped_refptr<display::ManagedDisplayMode> mode = | 489 scoped_refptr<display::ManagedDisplayMode> mode = |
| 489 ConvertValueToManagedDisplayMode(mode_data); | 490 ConvertValueToManagedDisplayMode(mode_data); |
| (...skipping 17 matching lines...) Expand all Loading... |
| 507 ash::Shell::GetInstance() | 508 ash::Shell::GetInstance() |
| 508 ->resolution_notification_controller() | 509 ->resolution_notification_controller() |
| 509 ->PrepareNotification(display_id, current_mode, mode, | 510 ->PrepareNotification(display_id, current_mode, mode, |
| 510 base::Bind(&chromeos::StoreDisplayPrefs)); | 511 base::Bind(&chromeos::StoreDisplayPrefs)); |
| 511 } | 512 } |
| 512 | 513 |
| 513 void DisplayOptionsHandler::HandleSetRotation(const base::ListValue* args) { | 514 void DisplayOptionsHandler::HandleSetRotation(const base::ListValue* args) { |
| 514 DCHECK(!args->empty()); | 515 DCHECK(!args->empty()); |
| 515 | 516 |
| 516 int64_t display_id = GetDisplayIdFromArgs(args); | 517 int64_t display_id = GetDisplayIdFromArgs(args); |
| 517 if (display_id == display::Display::kInvalidDisplayID) | 518 if (display_id == display::kInvalidDisplayId) |
| 518 return; | 519 return; |
| 519 | 520 |
| 520 int rotation_value = 0; | 521 int rotation_value = 0; |
| 521 if (!args->GetInteger(1, &rotation_value)) { | 522 if (!args->GetInteger(1, &rotation_value)) { |
| 522 LOG(ERROR) << "Can't parse rotation: " << args; | 523 LOG(ERROR) << "Can't parse rotation: " << args; |
| 523 return; | 524 return; |
| 524 } | 525 } |
| 525 display::Display::Rotation new_rotation = display::Display::ROTATE_0; | 526 display::Display::Rotation new_rotation = display::Display::ROTATE_0; |
| 526 if (rotation_value == 90) | 527 if (rotation_value == 90) |
| 527 new_rotation = display::Display::ROTATE_90; | 528 new_rotation = display::Display::ROTATE_90; |
| 528 else if (rotation_value == 180) | 529 else if (rotation_value == 180) |
| 529 new_rotation = display::Display::ROTATE_180; | 530 new_rotation = display::Display::ROTATE_180; |
| 530 else if (rotation_value == 270) | 531 else if (rotation_value == 270) |
| 531 new_rotation = display::Display::ROTATE_270; | 532 new_rotation = display::Display::ROTATE_270; |
| 532 else if (rotation_value != 0) | 533 else if (rotation_value != 0) |
| 533 LOG(ERROR) << "Invalid rotation: " << rotation_value << " Falls back to 0"; | 534 LOG(ERROR) << "Invalid rotation: " << rotation_value << " Falls back to 0"; |
| 534 | 535 |
| 535 content::RecordAction( | 536 content::RecordAction( |
| 536 base::UserMetricsAction("Options_DisplaySetOrientation")); | 537 base::UserMetricsAction("Options_DisplaySetOrientation")); |
| 537 GetDisplayConfigurationController()->SetDisplayRotation( | 538 GetDisplayConfigurationController()->SetDisplayRotation( |
| 538 display_id, new_rotation, display::Display::ROTATION_SOURCE_USER, | 539 display_id, new_rotation, display::Display::ROTATION_SOURCE_USER, |
| 539 true /* user_action */); | 540 true /* user_action */); |
| 540 } | 541 } |
| 541 | 542 |
| 542 void DisplayOptionsHandler::HandleSetColorProfile(const base::ListValue* args) { | 543 void DisplayOptionsHandler::HandleSetColorProfile(const base::ListValue* args) { |
| 543 DCHECK(!args->empty()); | 544 DCHECK(!args->empty()); |
| 544 int64_t display_id = GetDisplayIdFromArgs(args); | 545 int64_t display_id = GetDisplayIdFromArgs(args); |
| 545 if (display_id == display::Display::kInvalidDisplayID) | 546 if (display_id == display::kInvalidDisplayId) |
| 546 return; | 547 return; |
| 547 | 548 |
| 548 std::string profile_value; | 549 std::string profile_value; |
| 549 if (!args->GetString(1, &profile_value)) { | 550 if (!args->GetString(1, &profile_value)) { |
| 550 LOG(ERROR) << "Invalid profile_value"; | 551 LOG(ERROR) << "Invalid profile_value"; |
| 551 return; | 552 return; |
| 552 } | 553 } |
| 553 | 554 |
| 554 int profile_id; | 555 int profile_id; |
| 555 if (!base::StringToInt(profile_value, &profile_id)) { | 556 if (!base::StringToInt(profile_value, &profile_id)) { |
| (...skipping 22 matching lines...) Expand all Loading... |
| 578 if (!args->GetBoolean(0, &enable)) | 579 if (!args->GetBoolean(0, &enable)) |
| 579 NOTREACHED(); | 580 NOTREACHED(); |
| 580 | 581 |
| 581 GetDisplayManager()->SetDefaultMultiDisplayModeForCurrentDisplays( | 582 GetDisplayManager()->SetDefaultMultiDisplayModeForCurrentDisplays( |
| 582 enable ? display::DisplayManager::UNIFIED | 583 enable ? display::DisplayManager::UNIFIED |
| 583 : display::DisplayManager::EXTENDED); | 584 : display::DisplayManager::EXTENDED); |
| 584 } | 585 } |
| 585 | 586 |
| 586 } // namespace options | 587 } // namespace options |
| 587 } // namespace chromeos | 588 } // namespace chromeos |
| OLD | NEW |