| OLD | NEW |
| 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" |
| 11 #include "ash/shell.h" | 11 #include "ash/shell.h" |
| 12 #include "ash/touch/ash_touch_transform_controller.h" |
| 12 #include "base/strings/string_number_conversions.h" | 13 #include "base/strings/string_number_conversions.h" |
| 13 #include "chrome/browser/chromeos/display/display_preferences.h" | 14 #include "chrome/browser/chromeos/display/display_preferences.h" |
| 14 #include "chrome/browser/chromeos/display/overscan_calibrator.h" | 15 #include "chrome/browser/chromeos/display/overscan_calibrator.h" |
| 15 #include "chrome/browser/chromeos/display/touch_calibrator/touch_calibrator_cont
roller.h" | 16 #include "chrome/browser/chromeos/display/touch_calibrator/touch_calibrator_cont
roller.h" |
| 16 #include "extensions/common/api/system_display.h" | 17 #include "extensions/common/api/system_display.h" |
| 17 #include "ui/display/display.h" | 18 #include "ui/display/display.h" |
| 18 #include "ui/display/display_layout.h" | 19 #include "ui/display/display_layout.h" |
| 19 #include "ui/display/display_layout_builder.h" | 20 #include "ui/display/display_layout_builder.h" |
| 20 #include "ui/display/manager/display_manager.h" | 21 #include "ui/display/manager/display_manager.h" |
| 21 #include "ui/display/types/display_constants.h" | 22 #include "ui/display/types/display_constants.h" |
| (...skipping 631 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 653 const std::string& id) { | 654 const std::string& id) { |
| 654 VLOG(1) << "OverscanCalibrationComplete: " << id; | 655 VLOG(1) << "OverscanCalibrationComplete: " << id; |
| 655 chromeos::OverscanCalibrator* calibrator = GetOverscanCalibrator(id); | 656 chromeos::OverscanCalibrator* calibrator = GetOverscanCalibrator(id); |
| 656 if (!calibrator) | 657 if (!calibrator) |
| 657 return false; | 658 return false; |
| 658 calibrator->Commit(); | 659 calibrator->Commit(); |
| 659 overscan_calibrators_[id].reset(); | 660 overscan_calibrators_[id].reset(); |
| 660 return true; | 661 return true; |
| 661 } | 662 } |
| 662 | 663 |
| 663 bool DisplayInfoProviderChromeOS::TouchCalibrationSet( | 664 bool DisplayInfoProviderChromeOS::ShowNativeTouchCalibration( |
| 664 const std::string& id, | 665 const std::string& id, std::string* error, |
| 665 const api::system_display::TouchCalibrationPairQuad& pairs, | 666 const DisplayInfoProvider::TouchCalibrationCallback& callback) { |
| 666 const api::system_display::Bounds& bounds, | 667 VLOG(1) << "StartNativeTouchCalibration: " << id; |
| 667 std::string* error) { | 668 |
| 668 VLOG(1) << "TouchCalibrationSet: " << id; | 669 if (custom_touch_calibration_active_) { |
| 670 *error = "Please complete the custom touch calibration that is under " |
| 671 "progress for id - " + touch_calibration_target_id_ + " before " |
| 672 "calling this method."; |
| 673 return false; |
| 674 } |
| 669 | 675 |
| 670 const display::Display display = GetDisplay(id); | 676 const display::Display display = GetDisplay(id); |
| 671 if (!ValidateParamsForTouchCalibration(id, display, GetTouchCalibrator(), | 677 if (!ValidateParamsForTouchCalibration(id, display, GetTouchCalibrator(), |
| 672 error)) { | 678 error)) { |
| 673 return false; | 679 return false; |
| 674 } | 680 } |
| 675 | 681 |
| 682 GetTouchCalibrator()->AddCallback(callback); |
| 683 GetTouchCalibrator()->StartCalibration(display); |
| 684 return true; |
| 685 } |
| 686 |
| 687 bool DisplayInfoProviderChromeOS::StartCustomTouchCalibration( |
| 688 const std::string& id, |
| 689 std::string* error) { |
| 690 VLOG(1) << "StartCustomTouchCalibration: " << id; |
| 691 const display::Display display = GetDisplay(id); |
| 692 if (!ValidateParamsForTouchCalibration(id, display, GetTouchCalibrator(), |
| 693 error)) { |
| 694 return false; |
| 695 } |
| 696 |
| 697 touch_calibration_target_id_ = id; |
| 698 custom_touch_calibration_active_ = true; |
| 699 |
| 700 // Enable un-transformed touch input. |
| 701 ash::Shell::GetInstance()->touch_transformer_controller()->SetForCalibration( |
| 702 true); |
| 703 return true; |
| 704 } |
| 705 |
| 706 bool DisplayInfoProviderChromeOS::CompleteCustomTouchCalibration( |
| 707 const api::system_display::TouchCalibrationPairQuad& pairs, |
| 708 const api::system_display::Bounds& bounds, |
| 709 std::string* error) { |
| 710 VLOG(1) << "CompleteCustomTouchCalibration: " << touch_calibration_target_id_; |
| 711 |
| 712 ash::Shell::GetInstance()->touch_transformer_controller()->SetForCalibration( |
| 713 false); |
| 714 |
| 715 const display::Display display = GetDisplay(touch_calibration_target_id_); |
| 716 touch_calibration_target_id_ = ""; |
| 717 |
| 718 if (!custom_touch_calibration_active_) { |
| 719 *error = "Please call system.display.startCustomTouchCalibration before " |
| 720 "calling this method."; |
| 721 return false; |
| 722 } |
| 723 |
| 724 custom_touch_calibration_active_ = false; |
| 725 |
| 726 if (!ValidateParamsForTouchCalibration( |
| 727 touch_calibration_target_id_, display, GetTouchCalibrator(), error)) { |
| 728 return false; |
| 729 } |
| 730 |
| 676 display::TouchCalibrationData::CalibrationPointPairQuad calibration_points; | 731 display::TouchCalibrationData::CalibrationPointPairQuad calibration_points; |
| 677 calibration_points[0] = GetCalibrationPair(pairs.pair1); | 732 calibration_points[0] = GetCalibrationPair(pairs.pair1); |
| 678 calibration_points[1] = GetCalibrationPair(pairs.pair2); | 733 calibration_points[1] = GetCalibrationPair(pairs.pair2); |
| 679 calibration_points[2] = GetCalibrationPair(pairs.pair3); | 734 calibration_points[2] = GetCalibrationPair(pairs.pair3); |
| 680 calibration_points[3] = GetCalibrationPair(pairs.pair4); | 735 calibration_points[3] = GetCalibrationPair(pairs.pair4); |
| 681 | 736 |
| 682 // The display bounds cannot have negative values. | 737 // The display bounds cannot have negative values. |
| 683 if (bounds.width < 0 || bounds.height < 0) { | 738 if (bounds.width < 0 || bounds.height < 0) { |
| 684 *error = "Bounds cannot have negative values."; | 739 *error = "Bounds cannot have negative values."; |
| 685 return false; | 740 return false; |
| (...skipping 17 matching lines...) Expand all Loading... |
| 703 return false; | 758 return false; |
| 704 } | 759 } |
| 705 } | 760 } |
| 706 | 761 |
| 707 gfx::Size display_size(bounds.width, bounds.height); | 762 gfx::Size display_size(bounds.width, bounds.height); |
| 708 ash::Shell::GetInstance()->display_manager()->SetTouchCalibrationData( | 763 ash::Shell::GetInstance()->display_manager()->SetTouchCalibrationData( |
| 709 display.id(), calibration_points, display_size); | 764 display.id(), calibration_points, display_size); |
| 710 return true; | 765 return true; |
| 711 } | 766 } |
| 712 | 767 |
| 713 bool DisplayInfoProviderChromeOS::TouchCalibrationReset(const std::string& id, | 768 bool DisplayInfoProviderChromeOS::ResetTouchCalibration(const std::string& id, |
| 714 std::string* error) { | 769 std::string* error) { |
| 715 const display::Display display = GetDisplay(id); | 770 const display::Display display = GetDisplay(id); |
| 716 | 771 |
| 717 if (!ValidateParamsForTouchCalibration(id, display, GetTouchCalibrator(), | 772 if (!ValidateParamsForTouchCalibration(id, display, GetTouchCalibrator(), |
| 718 error)) { | 773 error)) { |
| 719 return false; | 774 return false; |
| 720 } | 775 } |
| 721 | 776 |
| 722 ash::Shell::GetInstance()->display_manager()->ClearTouchCalibrationData( | 777 ash::Shell::GetInstance()->display_manager()->ClearTouchCalibrationData( |
| 723 display.id()); | 778 display.id()); |
| 724 return true; | 779 return true; |
| 725 } | 780 } |
| 726 | 781 |
| 727 bool DisplayInfoProviderChromeOS::IsTouchCalibrationActive(std::string* error) { | 782 bool DisplayInfoProviderChromeOS::IsNativeTouchCalibrationActive( |
| 783 std::string* error) { |
| 728 if (GetTouchCalibrator()->is_calibrating()) { | 784 if (GetTouchCalibrator()->is_calibrating()) { |
| 729 *error = "Another touch calibration is already active."; | 785 *error = "Another touch calibration is already active."; |
| 730 return true; | 786 return true; |
| 731 } | 787 } |
| 732 return false; | 788 return false; |
| 733 } | 789 } |
| 734 | 790 |
| 735 chromeos::OverscanCalibrator* | 791 chromeos::OverscanCalibrator* |
| 736 DisplayInfoProviderChromeOS::GetOverscanCalibrator(const std::string& id) { | 792 DisplayInfoProviderChromeOS::GetOverscanCalibrator(const std::string& id) { |
| 737 auto iter = overscan_calibrators_.find(id); | 793 auto iter = overscan_calibrators_.find(id); |
| 738 if (iter == overscan_calibrators_.end()) | 794 if (iter == overscan_calibrators_.end()) |
| 739 return nullptr; | 795 return nullptr; |
| 740 return iter->second.get(); | 796 return iter->second.get(); |
| 741 } | 797 } |
| 742 | 798 |
| 743 chromeos::TouchCalibratorController* | 799 chromeos::TouchCalibratorController* |
| 744 DisplayInfoProviderChromeOS::GetTouchCalibrator() { | 800 DisplayInfoProviderChromeOS::GetTouchCalibrator() { |
| 745 if (!touch_calibrator_) | 801 if (!touch_calibrator_) |
| 746 touch_calibrator_.reset(new chromeos::TouchCalibratorController); | 802 touch_calibrator_.reset(new chromeos::TouchCalibratorController); |
| 747 return touch_calibrator_.get(); | 803 return touch_calibrator_.get(); |
| 748 } | 804 } |
| 749 | 805 |
| 750 // static | 806 // static |
| 751 DisplayInfoProvider* DisplayInfoProvider::Create() { | 807 DisplayInfoProvider* DisplayInfoProvider::Create() { |
| 752 return new DisplayInfoProviderChromeOS(); | 808 return new DisplayInfoProviderChromeOS(); |
| 753 } | 809 } |
| 754 | 810 |
| 755 } // namespace extensions | 811 } // namespace extensions |
| OLD | NEW |