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

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

Issue 2802603005: MD Settings: Display: Add unified desktop control and modify api (Closed)
Patch Set: Fix closure and tests Created 3 years, 8 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/resolution_notification_controller.h" 10 #include "ash/display/resolution_notification_controller.h"
(...skipping 221 matching lines...) Expand 10 before | Expand all | Expand 10 after
232 // error message. 232 // error message.
233 bool ValidateParamsForDisplay(const system_display::DisplayProperties& info, 233 bool ValidateParamsForDisplay(const system_display::DisplayProperties& info,
234 const display::Display& display, 234 const display::Display& display,
235 display::DisplayManager* display_manager, 235 display::DisplayManager* display_manager,
236 int64_t primary_display_id, 236 int64_t primary_display_id,
237 std::string* error) { 237 std::string* error) {
238 int64_t id = display.id(); 238 int64_t id = display.id();
239 bool is_primary = 239 bool is_primary =
240 id == primary_display_id || (info.is_primary && *info.is_primary); 240 id == primary_display_id || (info.is_primary && *info.is_primary);
241 241
242 if (info.is_unified) {
243 if (!is_primary) {
244 *error = "Unified desktop mode can only be set for the primary display.";
245 return false;
246 }
247 if (info.mirroring_source_id) {
248 *error = "Unified desktop mode can not be set with mirroringSourceId.";
249 return false;
250 }
251 return true;
252 }
253
242 // If mirroring source id is set, a display with the given id should exist, 254 // If mirroring source id is set, a display with the given id should exist,
243 // and if should not be the same as the target display's id. 255 // and if should not be the same as the target display's id.
244 if (info.mirroring_source_id && !info.mirroring_source_id->empty()) { 256 if (info.mirroring_source_id && !info.mirroring_source_id->empty()) {
245 int64_t mirroring_id = GetDisplay(*info.mirroring_source_id).id(); 257 int64_t mirroring_id = GetDisplay(*info.mirroring_source_id).id();
246 if (mirroring_id == display::kInvalidDisplayId) { 258 if (mirroring_id == display::kInvalidDisplayId) {
247 *error = "Display " + *info.mirroring_source_id + " not found."; 259 *error = "Display " + *info.mirroring_source_id + " not found.";
248 return false; 260 return false;
249 } 261 }
250 262
251 if (*info.mirroring_source_id == base::Int64ToString(id)) { 263 if (*info.mirroring_source_id == base::Int64ToString(id)) {
(...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after
410 422
411 bool IsMaximizeModeWindowManagerEnabled() { 423 bool IsMaximizeModeWindowManagerEnabled() {
412 return ash::Shell::Get() 424 return ash::Shell::Get()
413 ->maximize_mode_controller() 425 ->maximize_mode_controller()
414 ->IsMaximizeModeWindowManagerEnabled(); 426 ->IsMaximizeModeWindowManagerEnabled();
415 } 427 }
416 428
417 } // namespace 429 } // namespace
418 430
419 // static 431 // static
420 const char DisplayInfoProviderChromeOS:: 432 const char
421 kCustomTouchCalibrationInProgressError[] = 433 DisplayInfoProviderChromeOS::kCustomTouchCalibrationInProgressError[] =
422 "Another custom touch calibration already under progress."; 434 "Another custom touch calibration already under progress.";
423 435
424 // static 436 // static
425 const char DisplayInfoProviderChromeOS:: 437 const char
426 kCompleteCalibrationCalledBeforeStartError[] = 438 DisplayInfoProviderChromeOS::kCompleteCalibrationCalledBeforeStartError[] =
427 "system.display.completeCustomTouchCalibration called before " 439 "system.display.completeCustomTouchCalibration called before "
428 "system.display.startCustomTouchCalibration before."; 440 "system.display.startCustomTouchCalibration before.";
429 441
430 // static 442 // static
431 const char DisplayInfoProviderChromeOS::kTouchBoundsNegativeError[] = 443 const char DisplayInfoProviderChromeOS::kTouchBoundsNegativeError[] =
432 "Bounds cannot have negative values."; 444 "Bounds cannot have negative values.";
433 445
434 // static 446 // static
435 const char DisplayInfoProviderChromeOS::kTouchCalibrationPointsNegativeError[] = 447 const char DisplayInfoProviderChromeOS::kTouchCalibrationPointsNegativeError[] =
436 "Display points and touch points cannot have negative coordinates"; 448 "Display points and touch points cannot have negative coordinates";
437 449
438 // static 450 // static
(...skipping 11 matching lines...) Expand all
450 bool DisplayInfoProviderChromeOS::SetInfo( 462 bool DisplayInfoProviderChromeOS::SetInfo(
451 const std::string& display_id_str, 463 const std::string& display_id_str,
452 const system_display::DisplayProperties& info, 464 const system_display::DisplayProperties& info,
453 std::string* error) { 465 std::string* error) {
454 if (ash_util::IsRunningInMash()) { 466 if (ash_util::IsRunningInMash()) {
455 // TODO(crbug.com/682402): Mash support. 467 // TODO(crbug.com/682402): Mash support.
456 NOTIMPLEMENTED(); 468 NOTIMPLEMENTED();
457 *error = "Not implemented for mash."; 469 *error = "Not implemented for mash.";
458 return false; 470 return false;
459 } 471 }
472
460 display::DisplayManager* display_manager = 473 display::DisplayManager* display_manager =
461 ash::Shell::Get()->display_manager(); 474 ash::Shell::Get()->display_manager();
462 ash::DisplayConfigurationController* display_configuration_controller = 475 ash::DisplayConfigurationController* display_configuration_controller =
463 ash::Shell::Get()->display_configuration_controller(); 476 ash::Shell::Get()->display_configuration_controller();
464 477
465 const display::Display target = GetDisplay(display_id_str); 478 const display::Display target = GetDisplay(display_id_str);
466 479
467 if (target.id() == display::kInvalidDisplayId) { 480 if (target.id() == display::kInvalidDisplayId) {
468 *error = "Display not found:" + display_id_str; 481 *error = "Display not found:" + display_id_str;
469 return false; 482 return false;
470 } 483 }
471 484
472 int64_t display_id = target.id(); 485 int64_t display_id = target.id();
473 const display::Display& primary = 486 const display::Display& primary =
474 display::Screen::GetScreen()->GetPrimaryDisplay(); 487 display::Screen::GetScreen()->GetPrimaryDisplay();
475 488
476 if (!ValidateParamsForDisplay(info, target, display_manager, primary.id(), 489 if (!ValidateParamsForDisplay(info, target, display_manager, primary.id(),
477 error)) { 490 error)) {
478 return false; 491 return false;
479 } 492 }
480 493
494 // Process 'isUnified' parameter if set.
495 if (info.is_unified) {
496 display_manager->SetDefaultMultiDisplayModeForCurrentDisplays(
497 *info.is_unified ? display::DisplayManager::UNIFIED
498 : display::DisplayManager::EXTENDED);
499 }
500
481 // Process 'isPrimary' parameter. 501 // Process 'isPrimary' parameter.
482 if (info.is_primary && *info.is_primary && target.id() != primary.id()) 502 if (info.is_primary && *info.is_primary && target.id() != primary.id())
483 display_configuration_controller->SetPrimaryDisplayId(display_id); 503 display_configuration_controller->SetPrimaryDisplayId(display_id);
484 504
485 // Process 'mirroringSourceId' parameter. 505 // Process 'mirroringSourceId' parameter.
486 if (info.mirroring_source_id) { 506 if (info.mirroring_source_id) {
487 bool mirror = !info.mirroring_source_id->empty(); 507 bool mirror = !info.mirroring_source_id->empty();
488 display_configuration_controller->SetMirrorMode(mirror); 508 display_configuration_controller->SetMirrorMode(mirror);
489 } 509 }
490 510
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after
612 void DisplayInfoProviderChromeOS::EnableUnifiedDesktop(bool enable) { 632 void DisplayInfoProviderChromeOS::EnableUnifiedDesktop(bool enable) {
613 if (ash_util::IsRunningInMash()) { 633 if (ash_util::IsRunningInMash()) {
614 // TODO(crbug.com/682402): Mash support. 634 // TODO(crbug.com/682402): Mash support.
615 NOTIMPLEMENTED(); 635 NOTIMPLEMENTED();
616 return; 636 return;
617 } 637 }
618 ash::Shell::Get()->display_manager()->SetUnifiedDesktopEnabled(enable); 638 ash::Shell::Get()->display_manager()->SetUnifiedDesktopEnabled(enable);
619 } 639 }
620 640
621 DisplayInfoProvider::DisplayUnitInfoList 641 DisplayInfoProvider::DisplayUnitInfoList
622 DisplayInfoProviderChromeOS::GetAllDisplaysInfo() { 642 DisplayInfoProviderChromeOS::GetAllDisplaysInfo(bool single_unified) {
623 if (ash_util::IsRunningInMash()) { 643 if (ash_util::IsRunningInMash()) {
624 // TODO(crbug.com/682402): Mash support. 644 // TODO(crbug.com/682402): Mash support.
625 NOTIMPLEMENTED(); 645 NOTIMPLEMENTED();
626 return DisplayInfoProvider::DisplayUnitInfoList(); 646 return DisplayInfoProvider::DisplayUnitInfoList();
627 } 647 }
628 display::DisplayManager* display_manager = 648 display::DisplayManager* display_manager =
629 ash::Shell::Get()->display_manager(); 649 ash::Shell::Get()->display_manager();
650
630 if (!display_manager->IsInUnifiedMode()) 651 if (!display_manager->IsInUnifiedMode())
631 return DisplayInfoProvider::GetAllDisplaysInfo(); 652 return DisplayInfoProvider::GetAllDisplaysInfo(single_unified);
632 653
633 std::vector<display::Display> displays = 654 // Chrome OS specific: get displays for unified mode.
634 display_manager->software_mirroring_display_list(); 655 std::vector<display::Display> displays;
635 CHECK_GT(displays.size(), 0u); 656 int64_t primary_id;
657 if (single_unified) {
658 for (size_t i = 0; i < display_manager->GetNumDisplays(); ++i)
659 displays.push_back(display_manager->GetDisplayAt(i));
660 primary_id = display::Screen::GetScreen()->GetPrimaryDisplay().id();
661 } else {
662 displays = display_manager->software_mirroring_display_list();
663 CHECK_GT(displays.size(), 0u);
664 // Use first display as primary.
665 primary_id = displays[0].id();
666 }
636 667
637 // Use first display as primary.
638 int64_t primary_id = displays[0].id();
639 DisplayUnitInfoList all_displays; 668 DisplayUnitInfoList all_displays;
640 for (const display::Display& display : displays) { 669 for (const display::Display& display : displays) {
641 system_display::DisplayUnitInfo unit = 670 system_display::DisplayUnitInfo unit_info =
642 CreateDisplayUnitInfo(display, primary_id); 671 CreateDisplayUnitInfo(display, primary_id);
643 UpdateDisplayUnitInfoForPlatform(display, &unit); 672 UpdateDisplayUnitInfoForPlatform(display, &unit_info);
644 all_displays.push_back(std::move(unit)); 673 unit_info.is_unified = true;
674 all_displays.push_back(std::move(unit_info));
645 } 675 }
646 return all_displays; 676 return all_displays;
647 } 677 }
648 678
649 DisplayInfoProvider::DisplayLayoutList 679 DisplayInfoProvider::DisplayLayoutList
650 DisplayInfoProviderChromeOS::GetDisplayLayout() { 680 DisplayInfoProviderChromeOS::GetDisplayLayout() {
651 if (ash_util::IsRunningInMash()) { 681 if (ash_util::IsRunningInMash()) {
652 // TODO(crbug.com/682402): Mash support. 682 // TODO(crbug.com/682402): Mash support.
653 NOTIMPLEMENTED(); 683 NOTIMPLEMENTED();
654 return DisplayInfoProvider::DisplayLayoutList(); 684 return DisplayInfoProvider::DisplayLayoutList();
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
726 VLOG(1) << "OverscanCalibrationComplete: " << id; 756 VLOG(1) << "OverscanCalibrationComplete: " << id;
727 chromeos::OverscanCalibrator* calibrator = GetOverscanCalibrator(id); 757 chromeos::OverscanCalibrator* calibrator = GetOverscanCalibrator(id);
728 if (!calibrator) 758 if (!calibrator)
729 return false; 759 return false;
730 calibrator->Commit(); 760 calibrator->Commit();
731 overscan_calibrators_[id].reset(); 761 overscan_calibrators_[id].reset();
732 return true; 762 return true;
733 } 763 }
734 764
735 bool DisplayInfoProviderChromeOS::ShowNativeTouchCalibration( 765 bool DisplayInfoProviderChromeOS::ShowNativeTouchCalibration(
736 const std::string& id, std::string* error, 766 const std::string& id,
767 std::string* error,
737 const DisplayInfoProvider::TouchCalibrationCallback& callback) { 768 const DisplayInfoProvider::TouchCalibrationCallback& callback) {
738 if (ash_util::IsRunningInMash()) { 769 if (ash_util::IsRunningInMash()) {
739 // TODO(crbug.com/682402): Mash support. 770 // TODO(crbug.com/682402): Mash support.
740 NOTIMPLEMENTED(); 771 NOTIMPLEMENTED();
741 return false; 772 return false;
742 } 773 }
743 VLOG(1) << "StartNativeTouchCalibration: " << id; 774 VLOG(1) << "StartNativeTouchCalibration: " << id;
744 775
745 // If a custom calibration is already running, then throw an error. 776 // If a custom calibration is already running, then throw an error.
746 if (custom_touch_calibration_active_) { 777 if (custom_touch_calibration_active_) {
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
798 touch_calibration_target_id_.clear(); 829 touch_calibration_target_id_.clear();
799 830
800 // If Complete() is called before calling Start(), throw an error. 831 // If Complete() is called before calling Start(), throw an error.
801 if (!custom_touch_calibration_active_) { 832 if (!custom_touch_calibration_active_) {
802 *error = kCompleteCalibrationCalledBeforeStartError; 833 *error = kCompleteCalibrationCalledBeforeStartError;
803 return false; 834 return false;
804 } 835 }
805 836
806 custom_touch_calibration_active_ = false; 837 custom_touch_calibration_active_ = false;
807 838
808 if (!ValidateParamsForTouchCalibration( 839 if (!ValidateParamsForTouchCalibration(touch_calibration_target_id_, display,
809 touch_calibration_target_id_, display, GetTouchCalibrator(), error)) { 840 GetTouchCalibrator(), error)) {
810 return false; 841 return false;
811 } 842 }
812 843
813 display::TouchCalibrationData::CalibrationPointPairQuad calibration_points; 844 display::TouchCalibrationData::CalibrationPointPairQuad calibration_points;
814 calibration_points[0] = GetCalibrationPair(pairs.pair1); 845 calibration_points[0] = GetCalibrationPair(pairs.pair1);
815 calibration_points[1] = GetCalibrationPair(pairs.pair2); 846 calibration_points[1] = GetCalibrationPair(pairs.pair2);
816 calibration_points[2] = GetCalibrationPair(pairs.pair3); 847 calibration_points[2] = GetCalibrationPair(pairs.pair3);
817 calibration_points[3] = GetCalibrationPair(pairs.pair4); 848 calibration_points[3] = GetCalibrationPair(pairs.pair4);
818 849
819 // The display bounds cannot have negative values. 850 // The display bounds cannot have negative values.
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
888 touch_calibrator_.reset(new chromeos::TouchCalibratorController); 919 touch_calibrator_.reset(new chromeos::TouchCalibratorController);
889 return touch_calibrator_.get(); 920 return touch_calibrator_.get();
890 } 921 }
891 922
892 // static 923 // static
893 DisplayInfoProvider* DisplayInfoProvider::Create() { 924 DisplayInfoProvider* DisplayInfoProvider::Create() {
894 return new DisplayInfoProviderChromeOS(); 925 return new DisplayInfoProviderChromeOS();
895 } 926 }
896 927
897 } // namespace extensions 928 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698