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> |
11 #include <string> | 11 #include <string> |
12 #include <utility> | 12 #include <utility> |
13 | 13 |
14 #include "ash/display/display_configuration_controller.h" | 14 #include "ash/display/display_configuration_controller.h" |
15 #include "ash/display/resolution_notification_controller.h" | 15 #include "ash/display/resolution_notification_controller.h" |
16 #include "ash/display/window_tree_host_manager.h" | 16 #include "ash/display/window_tree_host_manager.h" |
17 #include "ash/shell.h" | 17 #include "ash/shell.h" |
18 #include "ash/strings/grit/ash_strings.h" | 18 #include "ash/strings/grit/ash_strings.h" |
19 #include "base/bind.h" | 19 #include "base/bind.h" |
20 #include "base/command_line.h" | 20 #include "base/command_line.h" |
21 #include "base/logging.h" | 21 #include "base/logging.h" |
22 #include "base/memory/ptr_util.h" | 22 #include "base/memory/ptr_util.h" |
| 23 #include "base/metrics/user_metrics.h" |
23 #include "base/strings/string_number_conversions.h" | 24 #include "base/strings/string_number_conversions.h" |
24 #include "base/values.h" | 25 #include "base/values.h" |
25 #include "chrome/browser/chromeos/display/display_preferences.h" | 26 #include "chrome/browser/chromeos/display/display_preferences.h" |
26 #include "chrome/browser/ui/ash/ash_util.h" | 27 #include "chrome/browser/ui/ash/ash_util.h" |
27 #include "chrome/grit/generated_resources.h" | 28 #include "chrome/grit/generated_resources.h" |
28 #include "chromeos/chromeos_switches.h" | 29 #include "chromeos/chromeos_switches.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/display_layout.h" | 33 #include "ui/display/display_layout.h" |
34 #include "ui/display/display_layout_builder.h" | 34 #include "ui/display/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/display/types/display_constants.h" |
38 #include "ui/gfx/geometry/rect.h" | 38 #include "ui/gfx/geometry/rect.h" |
39 #include "ui/gfx/geometry/size_conversions.h" | 39 #include "ui/gfx/geometry/size_conversions.h" |
(...skipping 360 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
400 void DisplayOptionsHandler::HandleDisplayInfo( | 400 void DisplayOptionsHandler::HandleDisplayInfo( |
401 const base::ListValue* unused_args) { | 401 const base::ListValue* unused_args) { |
402 SendAllDisplayInfo(); | 402 SendAllDisplayInfo(); |
403 } | 403 } |
404 | 404 |
405 void DisplayOptionsHandler::HandleMirroring(const base::ListValue* args) { | 405 void DisplayOptionsHandler::HandleMirroring(const base::ListValue* args) { |
406 DCHECK(!args->empty()); | 406 DCHECK(!args->empty()); |
407 bool is_mirroring = false; | 407 bool is_mirroring = false; |
408 if (!args->GetBoolean(0, &is_mirroring)) | 408 if (!args->GetBoolean(0, &is_mirroring)) |
409 NOTREACHED(); | 409 NOTREACHED(); |
410 content::RecordAction( | 410 base::RecordAction(base::UserMetricsAction("Options_DisplayToggleMirroring")); |
411 base::UserMetricsAction("Options_DisplayToggleMirroring")); | |
412 GetDisplayConfigurationController()->SetMirrorMode(is_mirroring); | 411 GetDisplayConfigurationController()->SetMirrorMode(is_mirroring); |
413 } | 412 } |
414 | 413 |
415 void DisplayOptionsHandler::HandleSetPrimary(const base::ListValue* args) { | 414 void DisplayOptionsHandler::HandleSetPrimary(const base::ListValue* args) { |
416 DCHECK(!args->empty()); | 415 DCHECK(!args->empty()); |
417 int64_t display_id = GetDisplayIdFromArgs(args); | 416 int64_t display_id = GetDisplayIdFromArgs(args); |
418 if (display_id == display::kInvalidDisplayId) | 417 if (display_id == display::kInvalidDisplayId) |
419 return; | 418 return; |
420 | 419 |
421 content::RecordAction(base::UserMetricsAction("Options_DisplaySetPrimary")); | 420 base::RecordAction(base::UserMetricsAction("Options_DisplaySetPrimary")); |
422 GetDisplayConfigurationController()->SetPrimaryDisplayId(display_id); | 421 GetDisplayConfigurationController()->SetPrimaryDisplayId(display_id); |
423 } | 422 } |
424 | 423 |
425 void DisplayOptionsHandler::HandleSetDisplayLayout( | 424 void DisplayOptionsHandler::HandleSetDisplayLayout( |
426 const base::ListValue* args) { | 425 const base::ListValue* args) { |
427 const base::ListValue* layouts = nullptr; | 426 const base::ListValue* layouts = nullptr; |
428 if (!args->GetList(0, &layouts)) | 427 if (!args->GetList(0, &layouts)) |
429 NOTREACHED(); | 428 NOTREACHED(); |
430 content::RecordAction(base::UserMetricsAction("Options_DisplayRearrange")); | 429 base::RecordAction(base::UserMetricsAction("Options_DisplayRearrange")); |
431 | 430 |
432 display::DisplayManager* display_manager = GetDisplayManager(); | 431 display::DisplayManager* display_manager = GetDisplayManager(); |
433 display::DisplayLayoutBuilder builder( | 432 display::DisplayLayoutBuilder builder( |
434 display_manager->GetCurrentDisplayLayout()); | 433 display_manager->GetCurrentDisplayLayout()); |
435 builder.ClearPlacements(); | 434 builder.ClearPlacements(); |
436 for (const auto& layout : *layouts) { | 435 for (const auto& layout : *layouts) { |
437 const base::DictionaryValue* dictionary; | 436 const base::DictionaryValue* dictionary; |
438 if (!layout->GetAsDictionary(&dictionary)) { | 437 if (!layout->GetAsDictionary(&dictionary)) { |
439 LOG(ERROR) << "Invalid layout dictionary: " << *dictionary; | 438 LOG(ERROR) << "Invalid layout dictionary: " << *dictionary; |
440 continue; | 439 continue; |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
481 if (!args->GetDictionary(1, &mode_data)) { | 480 if (!args->GetDictionary(1, &mode_data)) { |
482 LOG(ERROR) << "Failed to get mode data"; | 481 LOG(ERROR) << "Failed to get mode data"; |
483 return; | 482 return; |
484 } | 483 } |
485 | 484 |
486 scoped_refptr<display::ManagedDisplayMode> mode = | 485 scoped_refptr<display::ManagedDisplayMode> mode = |
487 ConvertValueToManagedDisplayMode(mode_data); | 486 ConvertValueToManagedDisplayMode(mode_data); |
488 if (!mode) | 487 if (!mode) |
489 return; | 488 return; |
490 | 489 |
491 content::RecordAction( | 490 base::RecordAction(base::UserMetricsAction("Options_DisplaySetResolution")); |
492 base::UserMetricsAction("Options_DisplaySetResolution")); | |
493 display::DisplayManager* display_manager = GetDisplayManager(); | 491 display::DisplayManager* display_manager = GetDisplayManager(); |
494 scoped_refptr<display::ManagedDisplayMode> current_mode = | 492 scoped_refptr<display::ManagedDisplayMode> current_mode = |
495 display_manager->GetActiveModeForDisplayId(display_id); | 493 display_manager->GetActiveModeForDisplayId(display_id); |
496 if (!display_manager->SetDisplayMode(display_id, mode)) { | 494 if (!display_manager->SetDisplayMode(display_id, mode)) { |
497 LOG(ERROR) << "Unable to set display mode for: " << display_id | 495 LOG(ERROR) << "Unable to set display mode for: " << display_id |
498 << " Mode: " << *mode_data; | 496 << " Mode: " << *mode_data; |
499 return; | 497 return; |
500 } | 498 } |
501 if (display::Display::IsInternalDisplayId(display_id)) | 499 if (display::Display::IsInternalDisplayId(display_id)) |
502 return; | 500 return; |
(...skipping 20 matching lines...) Expand all Loading... |
523 display::Display::Rotation new_rotation = display::Display::ROTATE_0; | 521 display::Display::Rotation new_rotation = display::Display::ROTATE_0; |
524 if (rotation_value == 90) | 522 if (rotation_value == 90) |
525 new_rotation = display::Display::ROTATE_90; | 523 new_rotation = display::Display::ROTATE_90; |
526 else if (rotation_value == 180) | 524 else if (rotation_value == 180) |
527 new_rotation = display::Display::ROTATE_180; | 525 new_rotation = display::Display::ROTATE_180; |
528 else if (rotation_value == 270) | 526 else if (rotation_value == 270) |
529 new_rotation = display::Display::ROTATE_270; | 527 new_rotation = display::Display::ROTATE_270; |
530 else if (rotation_value != 0) | 528 else if (rotation_value != 0) |
531 LOG(ERROR) << "Invalid rotation: " << rotation_value << " Falls back to 0"; | 529 LOG(ERROR) << "Invalid rotation: " << rotation_value << " Falls back to 0"; |
532 | 530 |
533 content::RecordAction( | 531 base::RecordAction(base::UserMetricsAction("Options_DisplaySetOrientation")); |
534 base::UserMetricsAction("Options_DisplaySetOrientation")); | |
535 GetDisplayConfigurationController()->SetDisplayRotation( | 532 GetDisplayConfigurationController()->SetDisplayRotation( |
536 display_id, new_rotation, display::Display::ROTATION_SOURCE_USER); | 533 display_id, new_rotation, display::Display::ROTATION_SOURCE_USER); |
537 } | 534 } |
538 | 535 |
539 void DisplayOptionsHandler::HandleSetColorProfile(const base::ListValue* args) { | 536 void DisplayOptionsHandler::HandleSetColorProfile(const base::ListValue* args) { |
540 DCHECK(!args->empty()); | 537 DCHECK(!args->empty()); |
541 int64_t display_id = GetDisplayIdFromArgs(args); | 538 int64_t display_id = GetDisplayIdFromArgs(args); |
542 if (display_id == display::kInvalidDisplayId) | 539 if (display_id == display::kInvalidDisplayId) |
543 return; | 540 return; |
544 | 541 |
545 std::string profile_value; | 542 std::string profile_value; |
546 if (!args->GetString(1, &profile_value)) { | 543 if (!args->GetString(1, &profile_value)) { |
547 LOG(ERROR) << "Invalid profile_value"; | 544 LOG(ERROR) << "Invalid profile_value"; |
548 return; | 545 return; |
549 } | 546 } |
550 | 547 |
551 int profile_id; | 548 int profile_id; |
552 if (!base::StringToInt(profile_value, &profile_id)) { | 549 if (!base::StringToInt(profile_value, &profile_id)) { |
553 LOG(ERROR) << "Invalid profile: " << profile_value; | 550 LOG(ERROR) << "Invalid profile: " << profile_value; |
554 return; | 551 return; |
555 } | 552 } |
556 | 553 |
557 if (profile_id < display::COLOR_PROFILE_STANDARD || | 554 if (profile_id < display::COLOR_PROFILE_STANDARD || |
558 profile_id > display::COLOR_PROFILE_READING) { | 555 profile_id > display::COLOR_PROFILE_READING) { |
559 LOG(ERROR) << "Invalid profile_id: " << profile_id; | 556 LOG(ERROR) << "Invalid profile_id: " << profile_id; |
560 return; | 557 return; |
561 } | 558 } |
562 | 559 |
563 content::RecordAction( | 560 base::RecordAction(base::UserMetricsAction("Options_DisplaySetColorProfile")); |
564 base::UserMetricsAction("Options_DisplaySetColorProfile")); | |
565 GetDisplayManager()->SetColorCalibrationProfile( | 561 GetDisplayManager()->SetColorCalibrationProfile( |
566 display_id, static_cast<display::ColorCalibrationProfile>(profile_id)); | 562 display_id, static_cast<display::ColorCalibrationProfile>(profile_id)); |
567 | 563 |
568 SendAllDisplayInfo(); | 564 SendAllDisplayInfo(); |
569 } | 565 } |
570 | 566 |
571 void DisplayOptionsHandler::HandleSetUnifiedDesktopEnabled( | 567 void DisplayOptionsHandler::HandleSetUnifiedDesktopEnabled( |
572 const base::ListValue* args) { | 568 const base::ListValue* args) { |
573 DCHECK(GetDisplayManager()->unified_desktop_enabled()); | 569 DCHECK(GetDisplayManager()->unified_desktop_enabled()); |
574 bool enable = false; | 570 bool enable = false; |
575 if (!args->GetBoolean(0, &enable)) | 571 if (!args->GetBoolean(0, &enable)) |
576 NOTREACHED(); | 572 NOTREACHED(); |
577 | 573 |
578 GetDisplayManager()->SetDefaultMultiDisplayModeForCurrentDisplays( | 574 GetDisplayManager()->SetDefaultMultiDisplayModeForCurrentDisplays( |
579 enable ? display::DisplayManager::UNIFIED | 575 enable ? display::DisplayManager::UNIFIED |
580 : display::DisplayManager::EXTENDED); | 576 : display::DisplayManager::EXTENDED); |
581 } | 577 } |
582 | 578 |
583 } // namespace options | 579 } // namespace options |
584 } // namespace chromeos | 580 } // namespace chromeos |
OLD | NEW |