Chromium Code Reviews| 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..ecaed6b4cc738f2c6d8f6c2209a0e11721bb6478 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,40 @@ 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 = std::string("Display Id(" + id + ") is an invalid display ID"); |
|
stevenjb
2016/12/27 19:37:26
nit: std::string() not needed.
malaykeshav
2016/12/27 20:07:00
Done
|
| + 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; |
| + } |
| + |
| + if (touch_calibrator_controller->is_calibrating()) { |
| + *error = "Another calibration is already under progress"; |
| + return false; |
| + } |
| + return true; |
| +} |
| + |
| } // namespace |
| DisplayInfoProviderChromeOS::DisplayInfoProviderChromeOS() {} |
| @@ -599,7 +634,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 +646,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 +656,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 +664,85 @@ 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); |
| + gfx::Size display_size(bounds.width, bounds.height); |
| + |
| + // The display bounds cannot have negative values. |
| + if (bounds.width < 0 || bounds.height < 0) { |
| + *error = "Bounds cannot have negative values."; |
| + return false; |
| + } |
| + |
| + // The display points must be withing the display bounds while the touch |
|
stevenjb
2016/12/27 19:37:26
within
malaykeshav
2016/12/27 20:07:00
done
|
| + // points must be non negative. |
| + for (size_t row = 0; row < calibration_points.size(); row++) { |
| + 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 = std::string("Display points and touch points cannot have") + |
| + " negative coordinates"; |
| + return false; |
| + } |
| + if (calibration_points[row].first.x() > bounds.width || |
| + calibration_points[row].first.y() > bounds.height) { |
| + *error = std::string("Display point coordinates cannot be more than") + |
| + " size of the display."; |
| + return false; |
| + } |
|
stevenjb
2016/12/27 19:37:26
Nit: invert comment above or logic order to match.
malaykeshav
2016/12/27 20:07:00
Done
|
| + } |
| + |
| + 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; |
| +} |
| + |
| +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(); |