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::internal::DisplayMode d1, | 57 bool CompareResolution(ash::internal::Resolution r1, |
58 ash::internal::DisplayMode d2) { | 58 ash::internal::Resolution r2) { |
59 if (d1.size.GetArea() == d2.size.GetArea()) | 59 return r1.size.GetArea() < r2.size.GetArea(); |
60 return d1.refresh_rate < d2.refresh_rate; | |
61 return d1.size.GetArea() < d2.size.GetArea(); | |
62 } | 60 } |
63 | 61 |
64 } // namespace | 62 } // namespace |
65 | 63 |
66 DisplayOptionsHandler::DisplayOptionsHandler() { | 64 DisplayOptionsHandler::DisplayOptionsHandler() { |
67 ash::Shell::GetInstance()->display_controller()->AddObserver(this); | 65 ash::Shell::GetInstance()->display_controller()->AddObserver(this); |
68 } | 66 } |
69 | 67 |
70 DisplayOptionsHandler::~DisplayOptionsHandler() { | 68 DisplayOptionsHandler::~DisplayOptionsHandler() { |
71 ash::Shell::GetInstance()->display_controller()->RemoveObserver(this); | 69 ash::Shell::GetInstance()->display_controller()->RemoveObserver(this); |
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
182 js_display->SetInteger("x", bounds.x()); | 180 js_display->SetInteger("x", bounds.x()); |
183 js_display->SetInteger("y", bounds.y()); | 181 js_display->SetInteger("y", bounds.y()); |
184 js_display->SetInteger("width", bounds.width()); | 182 js_display->SetInteger("width", bounds.width()); |
185 js_display->SetInteger("height", bounds.height()); | 183 js_display->SetInteger("height", bounds.height()); |
186 js_display->SetString("name", | 184 js_display->SetString("name", |
187 display_manager->GetDisplayNameForId(display.id())); | 185 display_manager->GetDisplayNameForId(display.id())); |
188 js_display->SetBoolean("isPrimary", display.id() == primary_id); | 186 js_display->SetBoolean("isPrimary", display.id() == primary_id); |
189 js_display->SetBoolean("isInternal", display.IsInternal()); | 187 js_display->SetBoolean("isInternal", display.IsInternal()); |
190 js_display->SetInteger("orientation", | 188 js_display->SetInteger("orientation", |
191 static_cast<int>(display_info.rotation())); | 189 static_cast<int>(display_info.rotation())); |
192 std::vector<ash::internal::DisplayMode> display_modes; | 190 std::vector<ash::internal::Resolution> resolutions; |
193 std::vector<float> ui_scales; | 191 std::vector<float> ui_scales; |
194 if (display.IsInternal()) { | 192 if (display.IsInternal()) { |
195 ui_scales = DisplayManager::GetScalesForDisplay(display_info); | 193 ui_scales = DisplayManager::GetScalesForDisplay(display_info); |
196 gfx::SizeF base_size = display_info.bounds_in_native().size(); | 194 gfx::SizeF base_size = display_info.bounds_in_native().size(); |
197 base_size.Scale(1.0f / display_info.device_scale_factor()); | 195 base_size.Scale(1.0f / display_info.device_scale_factor()); |
198 if (display_info.rotation() == gfx::Display::ROTATE_90 || | 196 if (display_info.rotation() == gfx::Display::ROTATE_90 || |
199 display_info.rotation() == gfx::Display::ROTATE_270) { | 197 display_info.rotation() == gfx::Display::ROTATE_270) { |
200 float tmp = base_size.width(); | 198 float tmp = base_size.width(); |
201 base_size.set_width(base_size.height()); | 199 base_size.set_width(base_size.height()); |
202 base_size.set_height(tmp); | 200 base_size.set_height(tmp); |
203 } | 201 } |
204 for (size_t i = 0; i < ui_scales.size(); ++i) { | 202 for (size_t i = 0; i < ui_scales.size(); ++i) { |
205 gfx::SizeF new_size = base_size; | 203 gfx::SizeF new_size = base_size; |
206 new_size.Scale(ui_scales[i]); | 204 new_size.Scale(ui_scales[i]); |
207 display_modes.push_back(ash::internal::DisplayMode( | 205 resolutions.push_back(ash::internal::Resolution( |
208 gfx::ToFlooredSize(new_size), -1.0f, false, false)); | 206 gfx::ToFlooredSize(new_size), false /* interlaced */)); |
209 } | 207 } |
210 } else { | 208 } else { |
211 for (size_t i = 0; i < display_info.display_modes().size(); ++i) | 209 for (size_t i = 0; i < display_info.resolutions().size(); ++i) |
212 display_modes.push_back(display_info.display_modes()[i]); | 210 resolutions.push_back(display_info.resolutions()[i]); |
213 } | 211 } |
214 std::sort(display_modes.begin(), display_modes.end(), CompareDisplayMode); | 212 std::sort(resolutions.begin(), resolutions.end(), CompareResolution); |
215 | 213 |
216 base::ListValue* js_resolutions = new base::ListValue(); | 214 base::ListValue* js_resolutions = new base::ListValue(); |
217 gfx::Size current_size = display_info.bounds_in_native().size(); | 215 gfx::Size current_size = display_info.bounds_in_native().size(); |
218 gfx::Insets current_overscan = display_info.GetOverscanInsetsInPixel(); | 216 gfx::Insets current_overscan = display_info.GetOverscanInsetsInPixel(); |
219 for (size_t i = 0; i < display_modes.size(); ++i) { | 217 for (size_t i = 0; i < resolutions.size(); ++i) { |
220 base::DictionaryValue* resolution_info = new base::DictionaryValue(); | 218 base::DictionaryValue* resolution_info = new base::DictionaryValue(); |
221 gfx::Size resolution = display_modes[i].size; | 219 gfx::Size resolution = resolutions[i].size; |
222 if (!ui_scales.empty()) { | 220 if (!ui_scales.empty()) { |
223 resolution_info->SetDouble("scale", ui_scales[i]); | 221 resolution_info->SetDouble("scale", ui_scales[i]); |
224 if (ui_scales[i] == 1.0f) | 222 if (ui_scales[i] == 1.0f) |
225 resolution_info->SetBoolean("isBest", true); | 223 resolution_info->SetBoolean("isBest", true); |
226 resolution_info->SetBoolean( | 224 resolution_info->SetBoolean( |
227 "selected", display_info.configured_ui_scale() == ui_scales[i]); | 225 "selected", display_info.configured_ui_scale() == ui_scales[i]); |
228 } else { | 226 } else { |
229 // Picks the largest one as the "best", which is the last element | 227 // Picks the largest one as the "best", which is the last element |
230 // because |display_modes| is sorted by its area. | 228 // because |resolutions| is sorted by its area. |
231 if (i == display_modes.size() - 1) | 229 if (i == resolutions.size() - 1) |
232 resolution_info->SetBoolean("isBest", true); | 230 resolution_info->SetBoolean("isBest", true); |
233 resolution_info->SetBoolean("selected", (resolution == current_size)); | 231 resolution_info->SetBoolean("selected", (resolution == current_size)); |
234 resolution.Enlarge( | 232 resolution.Enlarge( |
235 -current_overscan.width(), -current_overscan.height()); | 233 -current_overscan.width(), -current_overscan.height()); |
236 } | 234 } |
237 resolution_info->SetInteger("width", resolution.width()); | 235 resolution_info->SetInteger("width", resolution.width()); |
238 resolution_info->SetInteger("height", resolution.height()); | 236 resolution_info->SetInteger("height", resolution.height()); |
239 if (display_modes[i].refresh_rate > 0.0f) { | |
240 resolution_info->SetDouble("refreshRate", | |
241 display_modes[i].refresh_rate); | |
242 } | |
243 js_resolutions->Append(resolution_info); | 237 js_resolutions->Append(resolution_info); |
244 } | 238 } |
245 js_display->Set("resolutions", js_resolutions); | 239 js_display->Set("resolutions", js_resolutions); |
246 js_displays.Append(js_display); | 240 js_displays.Append(js_display); |
247 } | 241 } |
248 | 242 |
249 scoped_ptr<base::Value> layout_value(base::Value::CreateNullValue()); | 243 scoped_ptr<base::Value> layout_value(base::Value::CreateNullValue()); |
250 scoped_ptr<base::Value> offset_value(base::Value::CreateNullValue()); | 244 scoped_ptr<base::Value> offset_value(base::Value::CreateNullValue()); |
251 if (display_manager->GetNumDisplays() > 1) { | 245 if (display_manager->GetNumDisplays() > 1) { |
252 const ash::DisplayLayout layout = | 246 const ash::DisplayLayout layout = |
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
351 } | 345 } |
352 | 346 |
353 const ash::internal::DisplayInfo& display_info = | 347 const ash::internal::DisplayInfo& display_info = |
354 GetDisplayManager()->GetDisplayInfo(display_id); | 348 GetDisplayManager()->GetDisplayInfo(display_id); |
355 gfx::Insets current_overscan = display_info.GetOverscanInsetsInPixel(); | 349 gfx::Insets current_overscan = display_info.GetOverscanInsetsInPixel(); |
356 gfx::Size new_resolution = gfx::ToFlooredSize(gfx::SizeF(width, height)); | 350 gfx::Size new_resolution = gfx::ToFlooredSize(gfx::SizeF(width, height)); |
357 new_resolution.Enlarge(current_overscan.width(), current_overscan.height()); | 351 new_resolution.Enlarge(current_overscan.width(), current_overscan.height()); |
358 gfx::Size old_resolution = display_info.bounds_in_native().size(); | 352 gfx::Size old_resolution = display_info.bounds_in_native().size(); |
359 bool has_new_resolution = false; | 353 bool has_new_resolution = false; |
360 bool has_old_resolution = false; | 354 bool has_old_resolution = false; |
361 for (size_t i = 0; i < display_info.display_modes().size(); ++i) { | 355 for (size_t i = 0; i < display_info.resolutions().size(); ++i) { |
362 ash::internal::DisplayMode display_mode = display_info.display_modes()[i]; | 356 ash::internal::Resolution resolution = display_info.resolutions()[i]; |
363 if (display_mode.size == new_resolution) | 357 if (resolution.size == new_resolution) |
364 has_new_resolution = true; | 358 has_new_resolution = true; |
365 if (display_mode.size == old_resolution) | 359 if (resolution.size == old_resolution) |
366 has_old_resolution = true; | 360 has_old_resolution = true; |
367 } | 361 } |
368 if (!has_new_resolution) { | 362 if (!has_new_resolution) { |
369 LOG(ERROR) << "No new resolution " << new_resolution.ToString() | 363 LOG(ERROR) << "No new resolution " << new_resolution.ToString() |
370 << " is found in the display info " << display_info.ToString(); | 364 << " is found in the display info " << display_info.ToString(); |
371 return; | 365 return; |
372 } | 366 } |
373 if (!has_old_resolution) { | 367 if (!has_old_resolution) { |
374 LOG(ERROR) << "No old resolution " << old_resolution.ToString() | 368 LOG(ERROR) << "No old resolution " << old_resolution.ToString() |
375 << " is found in the display info " << display_info.ToString(); | 369 << " is found in the display info " << display_info.ToString(); |
(...skipping 26 matching lines...) Expand all Loading... |
402 else if (rotation_value == "270") | 396 else if (rotation_value == "270") |
403 new_rotation = gfx::Display::ROTATE_270; | 397 new_rotation = gfx::Display::ROTATE_270; |
404 else if (rotation_value != "0") | 398 else if (rotation_value != "0") |
405 LOG(ERROR) << "Invalid rotation: " << rotation_value << " Falls back to 0"; | 399 LOG(ERROR) << "Invalid rotation: " << rotation_value << " Falls back to 0"; |
406 | 400 |
407 GetDisplayManager()->SetDisplayRotation(display_id, new_rotation); | 401 GetDisplayManager()->SetDisplayRotation(display_id, new_rotation); |
408 } | 402 } |
409 | 403 |
410 } // namespace options | 404 } // namespace options |
411 } // namespace chromeos | 405 } // namespace chromeos |
OLD | NEW |