| Index: chrome/browser/extensions/display_info_provider_chromeos.cc
|
| diff --git a/chrome/browser/extensions/display_info_provider_chromeos.cc b/chrome/browser/extensions/display_info_provider_chromeos.cc
|
| index 584f3f19bad474828098bd18be6cbbc64b3af5ba..b358bfa40a62dd140eccce3ce689f5bb29913683 100644
|
| --- a/chrome/browser/extensions/display_info_provider_chromeos.cc
|
| +++ b/chrome/browser/extensions/display_info_provider_chromeos.cc
|
| @@ -12,6 +12,7 @@
|
| #include "base/strings/string_number_conversions.h"
|
| #include "chrome/browser/chromeos/display/display_preferences.h"
|
| #include "chrome/browser/chromeos/display/overscan_calibrator.h"
|
| +#include "chrome/browser/chromeos/display/touch_calibrator/touch_calibrator_controller.h"
|
| #include "extensions/common/api/system_display.h"
|
| #include "ui/display/display.h"
|
| #include "ui/display/display_layout.h"
|
| @@ -375,6 +376,36 @@ system_display::DisplayMode GetDisplayMode(
|
| return result;
|
| }
|
|
|
| +display::TouchCalibrationData::CalibrationPointPair GetCalibrationPair(
|
| + const system_display::TouchCalibrationPair& pair) {
|
| + return std::make_pair(gfx::Point(pair.display_point.x, pair.display_point.y),
|
| + gfx::Point(pair.touch_point.x, pair.touch_point.y));
|
| +}
|
| +
|
| +bool ValidateParamsForTouchCalibration(
|
| + const std::string& id,
|
| + const display::Display& display,
|
| + chromeos::TouchCalibratorController* const touch_calibrator_controller,
|
| + std::string* error) {
|
| + if (display.id() == display::kInvalidDisplayId) {
|
| + *error = "Display Id(" + id + ") is an invalid display ID";
|
| + return false;
|
| + }
|
| +
|
| + if (display.IsInternal()) {
|
| + *error = "Display Id(" + id + ") is an internal display. Internal " +
|
| + "displays cannot be calibrated for touch.";
|
| + return false;
|
| + }
|
| +
|
| + if (display.touch_support() != display::Display::TOUCH_SUPPORT_AVAILABLE) {
|
| + *error = "Display Id(" + id + ") does not support touch.";
|
| + return false;
|
| + }
|
| +
|
| + return true;
|
| +}
|
| +
|
| } // namespace
|
|
|
| DisplayInfoProviderChromeOS::DisplayInfoProviderChromeOS() {}
|
| @@ -599,7 +630,7 @@ bool DisplayInfoProviderChromeOS::OverscanCalibrationAdjust(
|
| const std::string& id,
|
| const system_display::Insets& delta) {
|
| VLOG(1) << "OverscanCalibrationAdjust: " << id;
|
| - chromeos::OverscanCalibrator* calibrator = GetCalibrator(id);
|
| + chromeos::OverscanCalibrator* calibrator = GetOverscanCalibrator(id);
|
| if (!calibrator)
|
| return false;
|
| gfx::Insets insets = calibrator->insets();
|
| @@ -611,7 +642,7 @@ bool DisplayInfoProviderChromeOS::OverscanCalibrationAdjust(
|
| bool DisplayInfoProviderChromeOS::OverscanCalibrationReset(
|
| const std::string& id) {
|
| VLOG(1) << "OverscanCalibrationReset: " << id;
|
| - chromeos::OverscanCalibrator* calibrator = GetCalibrator(id);
|
| + chromeos::OverscanCalibrator* calibrator = GetOverscanCalibrator(id);
|
| if (!calibrator)
|
| return false;
|
| calibrator->Reset();
|
| @@ -621,7 +652,7 @@ bool DisplayInfoProviderChromeOS::OverscanCalibrationReset(
|
| bool DisplayInfoProviderChromeOS::OverscanCalibrationComplete(
|
| const std::string& id) {
|
| VLOG(1) << "OverscanCalibrationComplete: " << id;
|
| - chromeos::OverscanCalibrator* calibrator = GetCalibrator(id);
|
| + chromeos::OverscanCalibrator* calibrator = GetOverscanCalibrator(id);
|
| if (!calibrator)
|
| return false;
|
| calibrator->Commit();
|
| @@ -629,14 +660,93 @@ bool DisplayInfoProviderChromeOS::OverscanCalibrationComplete(
|
| return true;
|
| }
|
|
|
| -chromeos::OverscanCalibrator* DisplayInfoProviderChromeOS::GetCalibrator(
|
| - const std::string& id) {
|
| +bool DisplayInfoProviderChromeOS::TouchCalibrationSet(
|
| + const std::string& id,
|
| + const api::system_display::TouchCalibrationPairQuad& pairs,
|
| + const api::system_display::Bounds& bounds,
|
| + std::string* error) {
|
| + VLOG(1) << "TouchCalibrationSet: " << id;
|
| +
|
| + const display::Display display = GetDisplay(id);
|
| + if (!ValidateParamsForTouchCalibration(id, display, GetTouchCalibrator(),
|
| + error)) {
|
| + return false;
|
| + }
|
| +
|
| + display::TouchCalibrationData::CalibrationPointPairQuad calibration_points;
|
| + calibration_points[0] = GetCalibrationPair(pairs.pair1);
|
| + calibration_points[1] = GetCalibrationPair(pairs.pair2);
|
| + calibration_points[2] = GetCalibrationPair(pairs.pair3);
|
| + calibration_points[3] = GetCalibrationPair(pairs.pair4);
|
| +
|
| + // The display bounds cannot have negative values.
|
| + if (bounds.width < 0 || bounds.height < 0) {
|
| + *error = "Bounds cannot have negative values.";
|
| + return false;
|
| + }
|
| +
|
| + for (size_t row = 0; row < calibration_points.size(); row++) {
|
| + // Coordinates for display and touch point cannot be negative.
|
| + if (calibration_points[row].first.x() < 0 ||
|
| + calibration_points[row].first.y() < 0 ||
|
| + calibration_points[row].second.x() < 0 ||
|
| + calibration_points[row].second.y() < 0) {
|
| + *error = "Display points and touch points cannot have negative "
|
| + "coordinates";
|
| + return false;
|
| + }
|
| + // Coordinates for display points cannot be greater than the screen bounds.
|
| + if (calibration_points[row].first.x() > bounds.width ||
|
| + calibration_points[row].first.y() > bounds.height) {
|
| + *error = "Display point coordinates cannot be more than size of the "
|
| + "display.";
|
| + return false;
|
| + }
|
| + }
|
| +
|
| + gfx::Size display_size(bounds.width, bounds.height);
|
| + ash::Shell::GetInstance()->display_manager()->SetTouchCalibrationData(
|
| + display.id(), calibration_points, display_size);
|
| + return true;
|
| +}
|
| +
|
| +bool DisplayInfoProviderChromeOS::TouchCalibrationReset(const std::string& id,
|
| + std::string* error) {
|
| + const display::Display display = GetDisplay(id);
|
| +
|
| + if (!ValidateParamsForTouchCalibration(id, display, GetTouchCalibrator(),
|
| + error)) {
|
| + return false;
|
| + }
|
| +
|
| + ash::Shell::GetInstance()->display_manager()->ClearTouchCalibrationData(
|
| + display.id());
|
| + return true;
|
| +}
|
| +
|
| +bool DisplayInfoProviderChromeOS::IsTouchCalibrationActive(std::string* error) {
|
| + if (GetTouchCalibrator()->is_calibrating()) {
|
| + *error = "Another touch calibration is already active.";
|
| + return true;
|
| + }
|
| + return false;
|
| +}
|
| +
|
| +chromeos::OverscanCalibrator*
|
| +DisplayInfoProviderChromeOS::GetOverscanCalibrator(const std::string& id) {
|
| auto iter = overscan_calibrators_.find(id);
|
| if (iter == overscan_calibrators_.end())
|
| return nullptr;
|
| return iter->second.get();
|
| }
|
|
|
| +chromeos::TouchCalibratorController*
|
| +DisplayInfoProviderChromeOS::GetTouchCalibrator() {
|
| + if (!touch_calibrator_)
|
| + touch_calibrator_.reset(new chromeos::TouchCalibratorController);
|
| + return touch_calibrator_.get();
|
| +}
|
| +
|
| // static
|
| DisplayInfoProvider* DisplayInfoProvider::Create() {
|
| return new DisplayInfoProviderChromeOS();
|
|
|