OLD | NEW |
---|---|
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/ui/webui/options/chromeos/display_options_handler.h" | 5 #include "chrome/browser/ui/webui/options/chromeos/display_options_handler.h" |
6 | 6 |
7 #include <string> | 7 #include <string> |
8 | 8 |
9 #include "ash/display/display_controller.h" | 9 #include "ash/display/display_controller.h" |
10 #include "ash/display/display_manager.h" | 10 #include "ash/display/display_manager.h" |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
47 | 47 |
48 int64 display_id = gfx::Display::kInvalidDisplayID; | 48 int64 display_id = gfx::Display::kInvalidDisplayID; |
49 if (!base::StringToInt64(id_value, &display_id)) { | 49 if (!base::StringToInt64(id_value, &display_id)) { |
50 LOG(ERROR) << "Invalid display id: " << id_value; | 50 LOG(ERROR) << "Invalid display id: " << id_value; |
51 return gfx::Display::kInvalidDisplayID; | 51 return gfx::Display::kInvalidDisplayID; |
52 } | 52 } |
53 | 53 |
54 return display_id; | 54 return display_id; |
55 } | 55 } |
56 | 56 |
57 bool CompareDisplayMode(ash::DisplayMode d1, ash::DisplayMode d2) { | 57 bool CompareDisplayMode(base::Value* display1, base::Value* display2) { |
58 if (d1.size.GetArea() == d2.size.GetArea()) | 58 base::DictionaryValue* d1 = NULL; |
59 return d1.refresh_rate < d2.refresh_rate; | 59 base::DictionaryValue* d2 = NULL; |
60 return d1.size.GetArea() < d2.size.GetArea(); | 60 CHECK(display1->GetAsDictionary(&d1) && display2->GetAsDictionary(&d2)); |
61 int w1 = 0, h1 = 0, w2 = 0, h2 = 0; | |
62 CHECK(d1->GetInteger("width", &w1) && d1->GetInteger("height", &h1)); | |
63 CHECK(d2->GetInteger("width", &w2) && d2->GetInteger("height", &h2)); | |
64 double sf1 = 0, sf2 = 0; | |
65 if (d1->GetDouble("scaleFactor", &sf1)) { | |
66 w1 /= sf1; | |
67 h1 /= sf1; | |
68 } | |
69 if (d2->GetDouble("scaleFactor", &sf2)) { | |
70 w2 /= sf2; | |
71 h2 /= sf2; | |
72 } | |
73 | |
74 if (w1 * h1 == w2 * h2) { | |
75 if (sf1 != sf2) | |
76 return sf1 < sf2; | |
77 | |
78 int r1 = 0, r2 = 0; | |
79 CHECK(d1->GetInteger("refreshRate", &r1) == | |
80 d2->GetInteger("refreshRate", &r2)); | |
81 return r1 < r2; | |
82 } | |
83 return w1 * h1 < w2 * h2; | |
61 } | 84 } |
62 | 85 |
63 base::string16 GetColorProfileName(ui::ColorCalibrationProfile profile) { | 86 base::string16 GetColorProfileName(ui::ColorCalibrationProfile profile) { |
64 switch (profile) { | 87 switch (profile) { |
65 case ui::COLOR_PROFILE_STANDARD: | 88 case ui::COLOR_PROFILE_STANDARD: |
66 return l10n_util::GetStringUTF16( | 89 return l10n_util::GetStringUTF16( |
67 IDS_OPTIONS_SETTINGS_DISPLAY_OPTIONS_COLOR_PROFILE_STANDARD); | 90 IDS_OPTIONS_SETTINGS_DISPLAY_OPTIONS_COLOR_PROFILE_STANDARD); |
68 case ui::COLOR_PROFILE_DYNAMIC: | 91 case ui::COLOR_PROFILE_DYNAMIC: |
69 return l10n_util::GetStringUTF16( | 92 return l10n_util::GetStringUTF16( |
70 IDS_OPTIONS_SETTINGS_DISPLAY_OPTIONS_COLOR_PROFILE_DYNAMIC); | 93 IDS_OPTIONS_SETTINGS_DISPLAY_OPTIONS_COLOR_PROFILE_DYNAMIC); |
(...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
210 js_display->SetInteger("x", bounds.x()); | 233 js_display->SetInteger("x", bounds.x()); |
211 js_display->SetInteger("y", bounds.y()); | 234 js_display->SetInteger("y", bounds.y()); |
212 js_display->SetInteger("width", bounds.width()); | 235 js_display->SetInteger("width", bounds.width()); |
213 js_display->SetInteger("height", bounds.height()); | 236 js_display->SetInteger("height", bounds.height()); |
214 js_display->SetString("name", | 237 js_display->SetString("name", |
215 display_manager->GetDisplayNameForId(display.id())); | 238 display_manager->GetDisplayNameForId(display.id())); |
216 js_display->SetBoolean("isPrimary", display.id() == primary_id); | 239 js_display->SetBoolean("isPrimary", display.id() == primary_id); |
217 js_display->SetBoolean("isInternal", display.IsInternal()); | 240 js_display->SetBoolean("isInternal", display.IsInternal()); |
218 js_display->SetInteger("orientation", | 241 js_display->SetInteger("orientation", |
219 static_cast<int>(display_info.rotation())); | 242 static_cast<int>(display_info.rotation())); |
220 std::vector<ash::DisplayMode> display_modes; | 243 |
221 std::vector<float> ui_scales; | 244 base::ListValue* js_resolutions = new base::ListValue(); |
222 if (display.IsInternal()) { | 245 if (display.IsInternal()) { |
223 ui_scales = DisplayManager::GetScalesForDisplay(display_info); | 246 const std::vector<float> ui_scales = |
247 DisplayManager::GetScalesForDisplay(display_info); | |
224 gfx::SizeF base_size = display_info.bounds_in_native().size(); | 248 gfx::SizeF base_size = display_info.bounds_in_native().size(); |
225 base_size.Scale(1.0f / display_info.device_scale_factor()); | 249 base_size.Scale(1.0f / display_info.device_scale_factor()); |
226 if (display_info.rotation() == gfx::Display::ROTATE_90 || | 250 if (display_info.rotation() == gfx::Display::ROTATE_90 || |
227 display_info.rotation() == gfx::Display::ROTATE_270) { | 251 display_info.rotation() == gfx::Display::ROTATE_270) { |
228 float tmp = base_size.width(); | 252 float tmp = base_size.width(); |
229 base_size.set_width(base_size.height()); | 253 base_size.set_width(base_size.height()); |
230 base_size.set_height(tmp); | 254 base_size.set_height(tmp); |
231 } | 255 } |
232 for (size_t i = 0; i < ui_scales.size(); ++i) { | 256 for (size_t i = 0; i < ui_scales.size(); ++i) { |
257 base::DictionaryValue* resolution_info = new base::DictionaryValue(); | |
233 gfx::SizeF new_size = base_size; | 258 gfx::SizeF new_size = base_size; |
234 new_size.Scale(ui_scales[i]); | 259 new_size.Scale(ui_scales[i]); |
235 display_modes.push_back(ash::DisplayMode( | 260 gfx::Size resolution = gfx::ToFlooredSize(new_size); |
236 gfx::ToFlooredSize(new_size), -1.0f, false, false)); | |
237 } | |
238 } else { | |
239 for (size_t i = 0; i < display_info.display_modes().size(); ++i) | |
240 display_modes.push_back(display_info.display_modes()[i]); | |
241 } | |
242 std::sort(display_modes.begin(), display_modes.end(), CompareDisplayMode); | |
243 | |
244 base::ListValue* js_resolutions = new base::ListValue(); | |
245 gfx::Size current_size = display_info.bounds_in_native().size(); | |
246 gfx::Insets current_overscan = display_info.GetOverscanInsetsInPixel(); | |
247 for (size_t i = 0; i < display_modes.size(); ++i) { | |
248 base::DictionaryValue* resolution_info = new base::DictionaryValue(); | |
249 gfx::Size resolution = display_modes[i].size; | |
250 if (!ui_scales.empty()) { | |
251 resolution_info->SetDouble("scale", ui_scales[i]); | 261 resolution_info->SetDouble("scale", ui_scales[i]); |
252 if (ui_scales[i] == 1.0f) | 262 if (ui_scales[i] == 1.0f) |
253 resolution_info->SetBoolean("isBest", true); | 263 resolution_info->SetBoolean("isBest", true); |
254 resolution_info->SetBoolean( | 264 resolution_info->SetBoolean( |
255 "selected", display_info.configured_ui_scale() == ui_scales[i]); | 265 "selected", display_info.configured_ui_scale() == ui_scales[i]); |
256 } else { | 266 resolution_info->SetInteger("width", resolution.width()); |
257 // Picks the largest one as the "best", which is the last element | 267 resolution_info->SetInteger("height", resolution.height()); |
258 // because |display_modes| is sorted by its area. | 268 js_resolutions->Append(resolution_info); |
259 if (i == display_modes.size() - 1) | 269 } |
270 } else { | |
271 gfx::Size current_size = display_info.bounds_in_native().size(); | |
oshima
2014/04/08 23:07:43
would you mind refacotring this define a method th
Jun Mukai
2014/04/09 20:20:07
Done.
| |
272 gfx::Insets current_overscan = display_info.GetOverscanInsetsInPixel(); | |
273 int largest_index = -1; | |
274 int largest_area = -1; | |
275 for (size_t i = 0; i < display_info.display_modes().size(); ++i) { | |
276 base::DictionaryValue* resolution_info = new base::DictionaryValue(); | |
277 const ash::DisplayMode& display_mode = display_info.display_modes()[i]; | |
278 gfx::Size resolution = display_mode.size; | |
279 | |
280 if (resolution.GetArea() > largest_area) { | |
260 resolution_info->SetBoolean("isBest", true); | 281 resolution_info->SetBoolean("isBest", true); |
261 resolution_info->SetBoolean("selected", (resolution == current_size)); | 282 largest_area = resolution.GetArea(); |
283 if (largest_index >= 0) { | |
284 base::DictionaryValue* prev_largest = NULL; | |
285 CHECK(js_resolutions->GetDictionary(largest_index, &prev_largest)); | |
286 prev_largest->SetBoolean("isBest", false); | |
287 } | |
288 largest_index = i; | |
289 } | |
290 if (resolution == current_size) { | |
291 // Right now, the scale factor for unselected resolutions is unknown. | |
292 // TODO(mukai): Set the scale factor for unselected ones. | |
293 resolution_info->SetDouble( | |
294 "scaleFactor", display_info.device_scale_factor()); | |
295 resolution_info->SetBoolean("selected", true); | |
296 } else { | |
297 resolution_info->SetBoolean("selected", false); | |
298 } | |
262 resolution.Enlarge( | 299 resolution.Enlarge( |
263 -current_overscan.width(), -current_overscan.height()); | 300 -current_overscan.width(), -current_overscan.height()); |
301 resolution_info->SetInteger("width", resolution.width()); | |
302 resolution_info->SetInteger("height", resolution.height()); | |
303 resolution_info->SetDouble("refreshRate", display_mode.refresh_rate); | |
304 js_resolutions->Append(resolution_info); | |
264 } | 305 } |
265 resolution_info->SetInteger("width", resolution.width()); | |
266 resolution_info->SetInteger("height", resolution.height()); | |
267 if (display_modes[i].refresh_rate > 0.0f) { | |
268 resolution_info->SetDouble("refreshRate", | |
269 display_modes[i].refresh_rate); | |
270 } | |
271 js_resolutions->Append(resolution_info); | |
272 } | 306 } |
307 std::sort( | |
308 js_resolutions->begin(), js_resolutions->end(), CompareDisplayMode); | |
273 js_display->Set("resolutions", js_resolutions); | 309 js_display->Set("resolutions", js_resolutions); |
274 | 310 |
275 js_display->SetInteger("colorProfile", display_info.color_profile()); | 311 js_display->SetInteger("colorProfile", display_info.color_profile()); |
276 base::ListValue* available_color_profiles = new base::ListValue(); | 312 base::ListValue* available_color_profiles = new base::ListValue(); |
277 for (size_t i = 0; | 313 for (size_t i = 0; |
278 i < display_info.available_color_profiles().size(); ++i) { | 314 i < display_info.available_color_profiles().size(); ++i) { |
279 base::DictionaryValue* color_profile_dict = new base::DictionaryValue(); | 315 base::DictionaryValue* color_profile_dict = new base::DictionaryValue(); |
280 ui::ColorCalibrationProfile color_profile = | 316 ui::ColorCalibrationProfile color_profile = |
281 display_info.available_color_profiles()[i]; | 317 display_info.available_color_profiles()[i]; |
282 color_profile_dict->SetInteger("profileId", color_profile); | 318 color_profile_dict->SetInteger("profileId", color_profile); |
(...skipping 197 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
480 return; | 516 return; |
481 } | 517 } |
482 | 518 |
483 GetDisplayManager()->SetColorCalibrationProfile( | 519 GetDisplayManager()->SetColorCalibrationProfile( |
484 display_id, static_cast<ui::ColorCalibrationProfile>(profile_id)); | 520 display_id, static_cast<ui::ColorCalibrationProfile>(profile_id)); |
485 SendAllDisplayInfo(); | 521 SendAllDisplayInfo(); |
486 } | 522 } |
487 | 523 |
488 } // namespace options | 524 } // namespace options |
489 } // namespace chromeos | 525 } // namespace chromeos |
OLD | NEW |