Chromium Code Reviews| Index: chrome/browser/chromeos/display/display_preferences.cc |
| diff --git a/chrome/browser/chromeos/display/display_preferences.cc b/chrome/browser/chromeos/display/display_preferences.cc |
| index 563f394e1ca0f9ad05cc9aab8483dea091502f27..673d60c2e46a8c48f8b6e12127b56932158e1140 100644 |
| --- a/chrome/browser/chromeos/display/display_preferences.cc |
| +++ b/chrome/browser/chromeos/display/display_preferences.cc |
| @@ -39,6 +39,15 @@ const char kInsetsLeftKey[] = "insets_left"; |
| const char kInsetsBottomKey[] = "insets_bottom"; |
| const char kInsetsRightKey[] = "insets_right"; |
| +const char kTouchCalibrationWidth[] = "touch_calibration_width"; |
| +const char kTouchCalibrationHeight[] = "touch_calibration_height"; |
| +const char* kTouchCalibrationDataKeys[] = { |
| + "display_1_x", "display_1_y", "touch_1_x", "touch_1_y", // Pair 1 |
| + "display_2_x", "display_2_y", "touch_2_x", "touch_2_y", // Pair 2 |
| + "display_3_x", "display_3_y", "touch_3_x", "touch_3_y", // Pair 3 |
| + "display_4_x", "display_4_y", "touch_4_x", "touch_4_y" // Pair 4 |
| +}; |
| + |
| // This kind of boilerplates should be done by base::JSONValueConverter but it |
| // doesn't support classes like gfx::Insets for now. |
| // TODO(mukai): fix base::JSONValueConverter and use it here. |
| @@ -66,6 +75,69 @@ void InsetsToValue(const gfx::Insets& insets, base::DictionaryValue* value) { |
| value->SetInteger(kInsetsRightKey, insets.right()); |
| } |
| +// Retrieves touch calibration associated data from the dictionary and stores |
| +// it in an instance of TouchCalibrationData struct. |
| +bool ValueToTouchData(const base::DictionaryValue& value, |
| + display::TouchCalibrationData* touch_calibration_data) { |
| + int x = 0, y = 0; |
| + bool got_value = true; |
| + |
| + display::TouchCalibrationData::CalibrationPointPairQuad* point_pair_quad = |
| + &(touch_calibration_data->point_pairs); |
| + |
| + gfx::Point display_point; |
| + gfx::Point touch_point; |
| + for (std::size_t row = 0; row < point_pair_quad->size(); row++) { |
| + // Get the display point |
| + if (!(value.GetInteger(kTouchCalibrationDataKeys[row * 4], &x) && |
| + value.GetInteger(kTouchCalibrationDataKeys[row * 4 + 1], &y))) { |
|
stevenjb
2016/12/02 20:16:48
nit: I find if (!a || !b) easier to read, especial
|
| + return false; |
| + } |
| + display_point.SetPoint(x, y); |
| + |
| + // Get the touch point |
| + if (!(value.GetInteger(kTouchCalibrationDataKeys[row * 4 + 2], &x) && |
| + value.GetInteger(kTouchCalibrationDataKeys[row * 4 + 3], &y))) { |
| + return false; |
| + } |
| + touch_point.SetPoint(x, y); |
| + (*point_pair_quad)[row] = std::make_pair(display_point, touch_point); |
| + } |
| + |
| + int width, height; |
| + got_value &= value.GetInteger(kTouchCalibrationWidth, &width); |
| + got_value &= value.GetInteger(kTouchCalibrationHeight, &height); |
| + if (!got_value) |
| + return false; |
|
stevenjb
2016/12/02 20:16:48
Elim got_value here also (and remove the unnecessa
|
| + touch_calibration_data->bounds = gfx::Size(width, height); |
| + |
| + return true; |
| +} |
| + |
| +// Stores the touch calibration data into the dictionary. |
| +void TouchDataToValue( |
| + const display::TouchCalibrationData& touch_calibration_data, |
| + base::DictionaryValue* value) { |
| + DCHECK(value); |
| + for (std::size_t row = 0; row < touch_calibration_data.point_pairs.size(); |
| + row++) { |
| + // Store the display points |
| + value->SetInteger(kTouchCalibrationDataKeys[row * 4], |
| + touch_calibration_data.point_pairs[row].first.x()); |
| + value->SetInteger(kTouchCalibrationDataKeys[row * 4 + 1], |
| + touch_calibration_data.point_pairs[row].first.y()); |
| + // Store the touch points. |
| + value->SetInteger(kTouchCalibrationDataKeys[row * 4 + 2], |
| + touch_calibration_data.point_pairs[row].second.x()); |
| + value->SetInteger(kTouchCalibrationDataKeys[row * 4 + 3], |
| + touch_calibration_data.point_pairs[row].second.y()); |
| + } |
| + value->SetInteger(kTouchCalibrationWidth, |
| + touch_calibration_data.bounds.width()); |
| + value->SetInteger(kTouchCalibrationHeight, |
| + touch_calibration_data.bounds.height()); |
| +} |
| + |
| std::string ColorProfileToString(ui::ColorCalibrationProfile profile) { |
| switch (profile) { |
| case ui::COLOR_PROFILE_STANDARD: |
| @@ -182,17 +254,18 @@ void LoadDisplayProperties() { |
| if (ValueToInsets(*dict_value, &insets)) |
| insets_to_set = &insets; |
| + display::TouchCalibrationData calibration_data; |
| + display::TouchCalibrationData* calibration_data_to_set = nullptr; |
| + if (ValueToTouchData(*dict_value, &calibration_data)) |
| + calibration_data_to_set = &calibration_data; |
| + |
| ui::ColorCalibrationProfile color_profile = ui::COLOR_PROFILE_STANDARD; |
| std::string color_profile_name; |
| if (dict_value->GetString("color_profile_name", &color_profile_name)) |
| color_profile = StringToColorProfile(color_profile_name); |
| - GetDisplayManager()->RegisterDisplayProperty(id, |
| - rotation, |
| - ui_scale, |
| - insets_to_set, |
| - resolution_in_pixels, |
| - device_scale_factor, |
| - color_profile); |
| + GetDisplayManager()->RegisterDisplayProperty( |
| + id, rotation, ui_scale, insets_to_set, resolution_in_pixels, |
| + device_scale_factor, color_profile, calibration_data_to_set); |
| } |
| } |
| @@ -283,6 +356,8 @@ void StoreCurrentDisplayProperties() { |
| property_value->SetString( |
| "color_profile_name", ColorProfileToString(info.color_profile())); |
| } |
| + if (info.has_touch_calibration_data()) |
| + TouchDataToValue(info.GetTouchCalibrationData(), property_value.get()); |
| pref_data->Set(base::Int64ToString(id), property_value.release()); |
| } |
| } |