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

Side by Side Diff: chrome/browser/chromeos/display/display_preferences.cc

Issue 2540383002: Updates display manager and display preferences to handle touch calibration data. (Closed)
Patch Set: Merge with ToT Created 4 years 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 (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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/chromeos/display/display_preferences.h" 5 #include "chrome/browser/chromeos/display/display_preferences.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 8
9 #include "ash/display/display_pref_util.h" 9 #include "ash/display/display_pref_util.h"
10 #include "ash/display/json_converter.h" 10 #include "ash/display/json_converter.h"
(...skipping 21 matching lines...) Expand all
32 #include "url/url_util.h" 32 #include "url/url_util.h"
33 33
34 namespace chromeos { 34 namespace chromeos {
35 namespace { 35 namespace {
36 36
37 const char kInsetsTopKey[] = "insets_top"; 37 const char kInsetsTopKey[] = "insets_top";
38 const char kInsetsLeftKey[] = "insets_left"; 38 const char kInsetsLeftKey[] = "insets_left";
39 const char kInsetsBottomKey[] = "insets_bottom"; 39 const char kInsetsBottomKey[] = "insets_bottom";
40 const char kInsetsRightKey[] = "insets_right"; 40 const char kInsetsRightKey[] = "insets_right";
41 41
42 const char kTouchCalibrationWidth[] = "touch_calibration_width";
43 const char kTouchCalibrationHeight[] = "touch_calibration_height";
44 const char kTouchCalibrationPointPairs[] = "touch_calibration_point_pairs";
45
42 // This kind of boilerplates should be done by base::JSONValueConverter but it 46 // This kind of boilerplates should be done by base::JSONValueConverter but it
43 // doesn't support classes like gfx::Insets for now. 47 // doesn't support classes like gfx::Insets for now.
44 // TODO(mukai): fix base::JSONValueConverter and use it here. 48 // TODO(mukai): fix base::JSONValueConverter and use it here.
45 bool ValueToInsets(const base::DictionaryValue& value, gfx::Insets* insets) { 49 bool ValueToInsets(const base::DictionaryValue& value, gfx::Insets* insets) {
46 DCHECK(insets); 50 DCHECK(insets);
47 int top = 0; 51 int top = 0;
48 int left = 0; 52 int left = 0;
49 int bottom = 0; 53 int bottom = 0;
50 int right = 0; 54 int right = 0;
51 if (value.GetInteger(kInsetsTopKey, &top) && 55 if (value.GetInteger(kInsetsTopKey, &top) &&
52 value.GetInteger(kInsetsLeftKey, &left) && 56 value.GetInteger(kInsetsLeftKey, &left) &&
53 value.GetInteger(kInsetsBottomKey, &bottom) && 57 value.GetInteger(kInsetsBottomKey, &bottom) &&
54 value.GetInteger(kInsetsRightKey, &right)) { 58 value.GetInteger(kInsetsRightKey, &right)) {
55 insets->Set(top, left, bottom, right); 59 insets->Set(top, left, bottom, right);
56 return true; 60 return true;
57 } 61 }
58 return false; 62 return false;
59 } 63 }
60 64
61 void InsetsToValue(const gfx::Insets& insets, base::DictionaryValue* value) { 65 void InsetsToValue(const gfx::Insets& insets, base::DictionaryValue* value) {
62 DCHECK(value); 66 DCHECK(value);
63 value->SetInteger(kInsetsTopKey, insets.top()); 67 value->SetInteger(kInsetsTopKey, insets.top());
64 value->SetInteger(kInsetsLeftKey, insets.left()); 68 value->SetInteger(kInsetsLeftKey, insets.left());
65 value->SetInteger(kInsetsBottomKey, insets.bottom()); 69 value->SetInteger(kInsetsBottomKey, insets.bottom());
66 value->SetInteger(kInsetsRightKey, insets.right()); 70 value->SetInteger(kInsetsRightKey, insets.right());
67 } 71 }
68 72
73 // Unmarshalls the string containing CalibrationPointPairQuad and populates
74 // |point_pair_quad| with the unmarshalled data.
75 bool ParseTouchCalibrationStringValue(
76 const std::string& str,
77 display::TouchCalibrationData::CalibrationPointPairQuad* point_pair_quad) {
78 DCHECK(point_pair_quad);
79 int x = 0, y = 0;
80 std::vector<std::string> parts = base::SplitString(
81 str, " ", base::KEEP_WHITESPACE, base::SPLIT_WANT_NONEMPTY);
82 size_t total = point_pair_quad->size();
83 gfx::Point display_point, touch_point;
84 for (std::size_t row = 0; row < total; row++) {
85 if (!base::StringToInt(parts[row * total], &x) ||
86 !base::StringToInt(parts[row * total + 1], &y)) {
87 return false;
88 }
89 display_point.SetPoint(x, y);
90
91 if (!base::StringToInt(parts[row * total + 2], &x) ||
92 !base::StringToInt(parts[row * total + 3], &y)) {
93 return false;
94 }
95 touch_point.SetPoint(x, y);
96
97 (*point_pair_quad)[row] = std::make_pair(display_point, touch_point);
98 }
99 return true;
100 }
101
102 // Retrieves touch calibration associated data from the dictionary and stores
103 // it in an instance of TouchCalibrationData struct.
104 bool ValueToTouchData(const base::DictionaryValue& value,
105 display::TouchCalibrationData* touch_calibration_data) {
106 display::TouchCalibrationData::CalibrationPointPairQuad* point_pair_quad =
107 &(touch_calibration_data->point_pairs);
108
109 std::string str;
110 if (!value.GetString(kTouchCalibrationPointPairs, &str))
111 return false;
112
113 if (!ParseTouchCalibrationStringValue(str, point_pair_quad))
114 return false;
115
116 int width, height;
117 if (!value.GetInteger(kTouchCalibrationWidth, &width) ||
118 !value.GetInteger(kTouchCalibrationHeight, &height)) {
119 return false;
120 }
121 touch_calibration_data->bounds = gfx::Size(width, height);
122 return true;
123 }
124
125 // Stores the touch calibration data into the dictionary.
126 void TouchDataToValue(
127 const display::TouchCalibrationData& touch_calibration_data,
128 base::DictionaryValue* value) {
129 DCHECK(value);
130 std::string str;
131 for (std::size_t row = 0; row < touch_calibration_data.point_pairs.size();
132 row++) {
133 str +=
134 base::IntToString(touch_calibration_data.point_pairs[row].first.x()) +
135 " ";
136 str +=
137 base::IntToString(touch_calibration_data.point_pairs[row].first.y()) +
138 " ";
139 str +=
140 base::IntToString(touch_calibration_data.point_pairs[row].second.x()) +
141 " ";
142 str +=
143 base::IntToString(touch_calibration_data.point_pairs[row].second.y());
144 if (row != touch_calibration_data.point_pairs.size() - 1)
145 str += " ";
146 }
147 value->SetString(kTouchCalibrationPointPairs, str);
148 value->SetInteger(kTouchCalibrationWidth,
149 touch_calibration_data.bounds.width());
150 value->SetInteger(kTouchCalibrationHeight,
151 touch_calibration_data.bounds.height());
152 }
153
69 std::string ColorProfileToString(ui::ColorCalibrationProfile profile) { 154 std::string ColorProfileToString(ui::ColorCalibrationProfile profile) {
70 switch (profile) { 155 switch (profile) {
71 case ui::COLOR_PROFILE_STANDARD: 156 case ui::COLOR_PROFILE_STANDARD:
72 return "standard"; 157 return "standard";
73 case ui::COLOR_PROFILE_DYNAMIC: 158 case ui::COLOR_PROFILE_DYNAMIC:
74 return "dynamic"; 159 return "dynamic";
75 case ui::COLOR_PROFILE_MOVIE: 160 case ui::COLOR_PROFILE_MOVIE:
76 return "movie"; 161 return "movie";
77 case ui::COLOR_PROFILE_READING: 162 case ui::COLOR_PROFILE_READING:
78 return "reading"; 163 return "reading";
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after
175 260
176 float device_scale_factor = 1.0; 261 float device_scale_factor = 1.0;
177 int dsf_value = 0; 262 int dsf_value = 0;
178 if (dict_value->GetInteger("device-scale-factor", &dsf_value)) 263 if (dict_value->GetInteger("device-scale-factor", &dsf_value))
179 device_scale_factor = static_cast<float>(dsf_value) / 1000.0f; 264 device_scale_factor = static_cast<float>(dsf_value) / 1000.0f;
180 265
181 gfx::Insets insets; 266 gfx::Insets insets;
182 if (ValueToInsets(*dict_value, &insets)) 267 if (ValueToInsets(*dict_value, &insets))
183 insets_to_set = &insets; 268 insets_to_set = &insets;
184 269
270 display::TouchCalibrationData calibration_data;
271 display::TouchCalibrationData* calibration_data_to_set = nullptr;
272 if (ValueToTouchData(*dict_value, &calibration_data))
273 calibration_data_to_set = &calibration_data;
274
185 ui::ColorCalibrationProfile color_profile = ui::COLOR_PROFILE_STANDARD; 275 ui::ColorCalibrationProfile color_profile = ui::COLOR_PROFILE_STANDARD;
186 std::string color_profile_name; 276 std::string color_profile_name;
187 if (dict_value->GetString("color_profile_name", &color_profile_name)) 277 if (dict_value->GetString("color_profile_name", &color_profile_name))
188 color_profile = StringToColorProfile(color_profile_name); 278 color_profile = StringToColorProfile(color_profile_name);
189 GetDisplayManager()->RegisterDisplayProperty(id, 279 GetDisplayManager()->RegisterDisplayProperty(
190 rotation, 280 id, rotation, ui_scale, insets_to_set, resolution_in_pixels,
191 ui_scale, 281 device_scale_factor, color_profile, calibration_data_to_set);
192 insets_to_set,
193 resolution_in_pixels,
194 device_scale_factor,
195 color_profile);
196 } 282 }
197 } 283 }
198 284
199 void LoadDisplayRotationState() { 285 void LoadDisplayRotationState() {
200 PrefService* local_state = g_browser_process->local_state(); 286 PrefService* local_state = g_browser_process->local_state();
201 const base::DictionaryValue* properties = 287 const base::DictionaryValue* properties =
202 local_state->GetDictionary(prefs::kDisplayRotationLock); 288 local_state->GetDictionary(prefs::kDisplayRotationLock);
203 289
204 bool rotation_lock = false; 290 bool rotation_lock = false;
205 if (!properties->GetBoolean("lock", &rotation_lock)) 291 if (!properties->GetBoolean("lock", &rotation_lock))
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
276 property_value->SetInteger( 362 property_value->SetInteger(
277 "device-scale-factor", 363 "device-scale-factor",
278 static_cast<int>(mode->device_scale_factor() * 1000)); 364 static_cast<int>(mode->device_scale_factor() * 1000));
279 } 365 }
280 if (!info.overscan_insets_in_dip().IsEmpty()) 366 if (!info.overscan_insets_in_dip().IsEmpty())
281 InsetsToValue(info.overscan_insets_in_dip(), property_value.get()); 367 InsetsToValue(info.overscan_insets_in_dip(), property_value.get());
282 if (info.color_profile() != ui::COLOR_PROFILE_STANDARD) { 368 if (info.color_profile() != ui::COLOR_PROFILE_STANDARD) {
283 property_value->SetString( 369 property_value->SetString(
284 "color_profile_name", ColorProfileToString(info.color_profile())); 370 "color_profile_name", ColorProfileToString(info.color_profile()));
285 } 371 }
372 if (info.has_touch_calibration_data())
373 TouchDataToValue(info.GetTouchCalibrationData(), property_value.get());
286 pref_data->Set(base::Int64ToString(id), property_value.release()); 374 pref_data->Set(base::Int64ToString(id), property_value.release());
287 } 375 }
288 } 376 }
289 377
290 typedef std::map<chromeos::DisplayPowerState, std::string> 378 typedef std::map<chromeos::DisplayPowerState, std::string>
291 DisplayPowerStateToStringMap; 379 DisplayPowerStateToStringMap;
292 380
293 const DisplayPowerStateToStringMap* GetDisplayPowerStateToStringMap() { 381 const DisplayPowerStateToStringMap* GetDisplayPowerStateToStringMap() {
294 // Don't save or retore ALL_OFF state. crbug.com/318456. 382 // Don't save or retore ALL_OFF state. crbug.com/318456.
295 static const DisplayPowerStateToStringMap* map = ash::CreateToStringMap( 383 static const DisplayPowerStateToStringMap* map = ash::CreateToStringMap(
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after
394 void StoreDisplayLayoutPrefForTest(const display::DisplayIdList& list, 482 void StoreDisplayLayoutPrefForTest(const display::DisplayIdList& list,
395 const display::DisplayLayout& layout) { 483 const display::DisplayLayout& layout) {
396 StoreDisplayLayoutPref(list, layout); 484 StoreDisplayLayoutPref(list, layout);
397 } 485 }
398 486
399 // Stores the given |power_state|. 487 // Stores the given |power_state|.
400 void StoreDisplayPowerStateForTest(DisplayPowerState power_state) { 488 void StoreDisplayPowerStateForTest(DisplayPowerState power_state) {
401 StoreDisplayPowerState(power_state); 489 StoreDisplayPowerState(power_state);
402 } 490 }
403 491
492 bool ParseTouchCalibrationStringForTest(
493 const std::string& str,
494 display::TouchCalibrationData::CalibrationPointPairQuad* point_pair_quad) {
495 return ParseTouchCalibrationStringValue(str, point_pair_quad);
496 }
497
404 } // namespace chromeos 498 } // namespace chromeos
OLDNEW
« no previous file with comments | « chrome/browser/chromeos/display/display_preferences.h ('k') | chrome/browser/chromeos/display/display_preferences_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698