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 CompareResolution(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 width1 = 0, height1 = 0, width2 = 0, height2 = 0; |
| 62 CHECK(d1->GetInteger("width", &width1) && d1->GetInteger("height", &height1)); |
| 63 CHECK(d2->GetInteger("width", &width2) && d2->GetInteger("height", &height2)); |
| 64 double scale_factor1 = 0, scale_factor2 = 0; |
| 65 if (d1->GetDouble("scaleFactor", &scale_factor1)) { |
| 66 width1 /= scale_factor1; |
| 67 height1 /= scale_factor1; |
| 68 } |
| 69 if (d2->GetDouble("scaleFactor", &scale_factor2)) { |
| 70 width2 /= scale_factor2; |
| 71 height2 /= scale_factor2; |
| 72 } |
| 73 |
| 74 if (width1 * height1 == width2 * height2) { |
| 75 if (scale_factor1 != scale_factor2) |
| 76 return scale_factor1 < scale_factor2; |
| 77 |
| 78 int refresh_rate1 = 0, refresh_rate2 = 0; |
| 79 CHECK(d1->GetInteger("refreshRate", &refresh_rate1) == |
| 80 d2->GetInteger("refreshRate", &refresh_rate2)); |
| 81 return refresh_rate1 < refresh_rate2; |
| 82 } |
| 83 return width1 * height1 < width2 * height2; |
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); |
71 case ui::COLOR_PROFILE_MOVIE: | 94 case ui::COLOR_PROFILE_MOVIE: |
72 return l10n_util::GetStringUTF16( | 95 return l10n_util::GetStringUTF16( |
73 IDS_OPTIONS_SETTINGS_DISPLAY_OPTIONS_COLOR_PROFILE_MOVIE); | 96 IDS_OPTIONS_SETTINGS_DISPLAY_OPTIONS_COLOR_PROFILE_MOVIE); |
74 case ui::COLOR_PROFILE_READING: | 97 case ui::COLOR_PROFILE_READING: |
75 return l10n_util::GetStringUTF16( | 98 return l10n_util::GetStringUTF16( |
76 IDS_OPTIONS_SETTINGS_DISPLAY_OPTIONS_COLOR_PROFILE_READING); | 99 IDS_OPTIONS_SETTINGS_DISPLAY_OPTIONS_COLOR_PROFILE_READING); |
77 case ui::NUM_COLOR_PROFILES: | 100 case ui::NUM_COLOR_PROFILES: |
78 break; | 101 break; |
79 } | 102 } |
80 | 103 |
81 NOTREACHED(); | 104 NOTREACHED(); |
82 return base::string16(); | 105 return base::string16(); |
83 } | 106 } |
84 | 107 |
| 108 scoped_ptr<base::ListValue> GetResolutionsForInternalDisplay( |
| 109 const ash::DisplayInfo& display_info) { |
| 110 scoped_ptr<base::ListValue> js_resolutions(new base::ListValue); |
| 111 const std::vector<float> ui_scales = |
| 112 DisplayManager::GetScalesForDisplay(display_info); |
| 113 gfx::SizeF base_size = display_info.bounds_in_native().size(); |
| 114 base_size.Scale(1.0f / display_info.device_scale_factor()); |
| 115 if (display_info.rotation() == gfx::Display::ROTATE_90 || |
| 116 display_info.rotation() == gfx::Display::ROTATE_270) { |
| 117 float tmp = base_size.width(); |
| 118 base_size.set_width(base_size.height()); |
| 119 base_size.set_height(tmp); |
| 120 } |
| 121 |
| 122 for (size_t i = 0; i < ui_scales.size(); ++i) { |
| 123 base::DictionaryValue* resolution_info = new base::DictionaryValue(); |
| 124 gfx::SizeF new_size = base_size; |
| 125 new_size.Scale(ui_scales[i]); |
| 126 gfx::Size resolution = gfx::ToFlooredSize(new_size); |
| 127 resolution_info->SetDouble("scale", ui_scales[i]); |
| 128 if (ui_scales[i] == 1.0f) |
| 129 resolution_info->SetBoolean("isBest", true); |
| 130 resolution_info->SetBoolean( |
| 131 "selected", display_info.configured_ui_scale() == ui_scales[i]); |
| 132 resolution_info->SetInteger("width", resolution.width()); |
| 133 resolution_info->SetInteger("height", resolution.height()); |
| 134 js_resolutions->Append(resolution_info); |
| 135 } |
| 136 |
| 137 return js_resolutions.Pass(); |
| 138 } |
| 139 |
| 140 scoped_ptr<base::ListValue> GetResolutionsForExternalDisplay( |
| 141 const ash::DisplayInfo& display_info) { |
| 142 scoped_ptr<base::ListValue> js_resolutions(new base::ListValue); |
| 143 |
| 144 gfx::Size current_size = display_info.bounds_in_native().size(); |
| 145 gfx::Insets current_overscan = display_info.GetOverscanInsetsInPixel(); |
| 146 int largest_index = -1; |
| 147 int largest_area = -1; |
| 148 |
| 149 for (size_t i = 0; i < display_info.display_modes().size(); ++i) { |
| 150 base::DictionaryValue* resolution_info = new base::DictionaryValue(); |
| 151 const ash::DisplayMode& display_mode = display_info.display_modes()[i]; |
| 152 gfx::Size resolution = display_mode.size; |
| 153 |
| 154 if (resolution.GetArea() > largest_area) { |
| 155 resolution_info->SetBoolean("isBest", true); |
| 156 largest_area = resolution.GetArea(); |
| 157 if (largest_index >= 0) { |
| 158 base::DictionaryValue* prev_largest = NULL; |
| 159 CHECK(js_resolutions->GetDictionary(largest_index, &prev_largest)); |
| 160 prev_largest->SetBoolean("isBest", false); |
| 161 } |
| 162 largest_index = i; |
| 163 } |
| 164 |
| 165 if (resolution == current_size) { |
| 166 // Right now, the scale factor for unselected resolutions is unknown. |
| 167 // TODO(mukai): Set the scale factor for unselected ones. |
| 168 resolution_info->SetDouble( |
| 169 "scaleFactor", display_info.device_scale_factor()); |
| 170 resolution_info->SetBoolean("selected", true); |
| 171 } |
| 172 |
| 173 resolution.Enlarge( |
| 174 -current_overscan.width(), -current_overscan.height()); |
| 175 resolution_info->SetInteger("width", resolution.width()); |
| 176 resolution_info->SetInteger("height", resolution.height()); |
| 177 resolution_info->SetDouble("refreshRate", display_mode.refresh_rate); |
| 178 js_resolutions->Append(resolution_info); |
| 179 } |
| 180 |
| 181 return js_resolutions.Pass(); |
| 182 } |
| 183 |
85 } // namespace | 184 } // namespace |
86 | 185 |
87 DisplayOptionsHandler::DisplayOptionsHandler() { | 186 DisplayOptionsHandler::DisplayOptionsHandler() { |
88 ash::Shell::GetInstance()->display_controller()->AddObserver(this); | 187 ash::Shell::GetInstance()->display_controller()->AddObserver(this); |
89 } | 188 } |
90 | 189 |
91 DisplayOptionsHandler::~DisplayOptionsHandler() { | 190 DisplayOptionsHandler::~DisplayOptionsHandler() { |
92 ash::Shell::GetInstance()->display_controller()->RemoveObserver(this); | 191 ash::Shell::GetInstance()->display_controller()->RemoveObserver(this); |
93 } | 192 } |
94 | 193 |
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
210 js_display->SetInteger("x", bounds.x()); | 309 js_display->SetInteger("x", bounds.x()); |
211 js_display->SetInteger("y", bounds.y()); | 310 js_display->SetInteger("y", bounds.y()); |
212 js_display->SetInteger("width", bounds.width()); | 311 js_display->SetInteger("width", bounds.width()); |
213 js_display->SetInteger("height", bounds.height()); | 312 js_display->SetInteger("height", bounds.height()); |
214 js_display->SetString("name", | 313 js_display->SetString("name", |
215 display_manager->GetDisplayNameForId(display.id())); | 314 display_manager->GetDisplayNameForId(display.id())); |
216 js_display->SetBoolean("isPrimary", display.id() == primary_id); | 315 js_display->SetBoolean("isPrimary", display.id() == primary_id); |
217 js_display->SetBoolean("isInternal", display.IsInternal()); | 316 js_display->SetBoolean("isInternal", display.IsInternal()); |
218 js_display->SetInteger("orientation", | 317 js_display->SetInteger("orientation", |
219 static_cast<int>(display_info.rotation())); | 318 static_cast<int>(display_info.rotation())); |
220 std::vector<ash::DisplayMode> display_modes; | |
221 std::vector<float> ui_scales; | |
222 if (display.IsInternal()) { | |
223 ui_scales = DisplayManager::GetScalesForDisplay(display_info); | |
224 gfx::SizeF base_size = display_info.bounds_in_native().size(); | |
225 base_size.Scale(1.0f / display_info.device_scale_factor()); | |
226 if (display_info.rotation() == gfx::Display::ROTATE_90 || | |
227 display_info.rotation() == gfx::Display::ROTATE_270) { | |
228 float tmp = base_size.width(); | |
229 base_size.set_width(base_size.height()); | |
230 base_size.set_height(tmp); | |
231 } | |
232 for (size_t i = 0; i < ui_scales.size(); ++i) { | |
233 gfx::SizeF new_size = base_size; | |
234 new_size.Scale(ui_scales[i]); | |
235 display_modes.push_back(ash::DisplayMode( | |
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 | 319 |
244 base::ListValue* js_resolutions = new base::ListValue(); | 320 scoped_ptr<base::ListValue> js_resolutions = display.IsInternal() ? |
245 gfx::Size current_size = display_info.bounds_in_native().size(); | 321 GetResolutionsForInternalDisplay(display_info) : |
246 gfx::Insets current_overscan = display_info.GetOverscanInsetsInPixel(); | 322 GetResolutionsForExternalDisplay(display_info); |
247 for (size_t i = 0; i < display_modes.size(); ++i) { | 323 std::sort( |
248 base::DictionaryValue* resolution_info = new base::DictionaryValue(); | 324 js_resolutions->begin(), js_resolutions->end(), CompareResolution); |
249 gfx::Size resolution = display_modes[i].size; | 325 js_display->Set("resolutions", js_resolutions.release()); |
250 if (!ui_scales.empty()) { | |
251 resolution_info->SetDouble("scale", ui_scales[i]); | |
252 if (ui_scales[i] == 1.0f) | |
253 resolution_info->SetBoolean("isBest", true); | |
254 resolution_info->SetBoolean( | |
255 "selected", display_info.configured_ui_scale() == ui_scales[i]); | |
256 } else { | |
257 // Picks the largest one as the "best", which is the last element | |
258 // because |display_modes| is sorted by its area. | |
259 if (i == display_modes.size() - 1) | |
260 resolution_info->SetBoolean("isBest", true); | |
261 resolution_info->SetBoolean("selected", (resolution == current_size)); | |
262 resolution.Enlarge( | |
263 -current_overscan.width(), -current_overscan.height()); | |
264 } | |
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 } | |
273 js_display->Set("resolutions", js_resolutions); | |
274 | 326 |
275 js_display->SetInteger("colorProfile", display_info.color_profile()); | 327 js_display->SetInteger("colorProfile", display_info.color_profile()); |
276 base::ListValue* available_color_profiles = new base::ListValue(); | 328 base::ListValue* available_color_profiles = new base::ListValue(); |
277 for (size_t i = 0; | 329 for (size_t i = 0; |
278 i < display_info.available_color_profiles().size(); ++i) { | 330 i < display_info.available_color_profiles().size(); ++i) { |
279 base::DictionaryValue* color_profile_dict = new base::DictionaryValue(); | 331 base::DictionaryValue* color_profile_dict = new base::DictionaryValue(); |
280 ui::ColorCalibrationProfile color_profile = | 332 ui::ColorCalibrationProfile color_profile = |
281 display_info.available_color_profiles()[i]; | 333 display_info.available_color_profiles()[i]; |
282 color_profile_dict->SetInteger("profileId", color_profile); | 334 color_profile_dict->SetInteger("profileId", color_profile); |
283 color_profile_dict->SetString("name", GetColorProfileName(color_profile)); | 335 color_profile_dict->SetString("name", GetColorProfileName(color_profile)); |
(...skipping 196 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
480 return; | 532 return; |
481 } | 533 } |
482 | 534 |
483 GetDisplayManager()->SetColorCalibrationProfile( | 535 GetDisplayManager()->SetColorCalibrationProfile( |
484 display_id, static_cast<ui::ColorCalibrationProfile>(profile_id)); | 536 display_id, static_cast<ui::ColorCalibrationProfile>(profile_id)); |
485 SendAllDisplayInfo(); | 537 SendAllDisplayInfo(); |
486 } | 538 } |
487 | 539 |
488 } // namespace options | 540 } // namespace options |
489 } // namespace chromeos | 541 } // namespace chromeos |
OLD | NEW |