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 <stddef.h> | 7 #include <stddef.h> |
8 #include <stdint.h> | 8 #include <stdint.h> |
9 | 9 |
10 #include <string> | 10 #include <string> |
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
114 const std::string& field, | 114 const std::string& field, |
115 float* result) { | 115 float* result) { |
116 double double_result = 0; | 116 double double_result = 0; |
117 if (dict->GetDouble(field, &double_result)) { | 117 if (dict->GetDouble(field, &double_result)) { |
118 *result = static_cast<float>(double_result); | 118 *result = static_cast<float>(double_result); |
119 return true; | 119 return true; |
120 } | 120 } |
121 return false; | 121 return false; |
122 } | 122 } |
123 | 123 |
124 scoped_refptr<ash::ManagedDisplayMode> ConvertValueToManagedDisplayMode( | 124 scoped_refptr<display::ManagedDisplayMode> ConvertValueToManagedDisplayMode( |
125 const base::DictionaryValue* dict) { | 125 const base::DictionaryValue* dict) { |
126 scoped_refptr<ash::ManagedDisplayMode> mode; | 126 scoped_refptr<display::ManagedDisplayMode> mode; |
127 | 127 |
128 gfx::Size size; | 128 gfx::Size size; |
129 size.set_width(GetIntOrDouble(dict, "originalWidth")); | 129 size.set_width(GetIntOrDouble(dict, "originalWidth")); |
130 size.set_height(GetIntOrDouble(dict, "originalHeight")); | 130 size.set_height(GetIntOrDouble(dict, "originalHeight")); |
131 | 131 |
132 if (size.IsEmpty()) { | 132 if (size.IsEmpty()) { |
133 LOG(ERROR) << "missing width or height."; | 133 LOG(ERROR) << "missing width or height."; |
134 return mode; | 134 return mode; |
135 } | 135 } |
136 | 136 |
137 float refresh_rate, ui_scale, device_scale_factor; | 137 float refresh_rate, ui_scale, device_scale_factor; |
138 if (!GetFloat(dict, "refreshRate", &refresh_rate)) { | 138 if (!GetFloat(dict, "refreshRate", &refresh_rate)) { |
139 LOG(ERROR) << "missing refreshRate."; | 139 LOG(ERROR) << "missing refreshRate."; |
140 return mode; | 140 return mode; |
141 } | 141 } |
142 if (!GetFloat(dict, "scale", &ui_scale)) { | 142 if (!GetFloat(dict, "scale", &ui_scale)) { |
143 LOG(ERROR) << "missing ui-scale."; | 143 LOG(ERROR) << "missing ui-scale."; |
144 return mode; | 144 return mode; |
145 } | 145 } |
146 if (!GetFloat(dict, "deviceScaleFactor", &device_scale_factor)) { | 146 if (!GetFloat(dict, "deviceScaleFactor", &device_scale_factor)) { |
147 LOG(ERROR) << "missing deviceScaleFactor."; | 147 LOG(ERROR) << "missing deviceScaleFactor."; |
148 return mode; | 148 return mode; |
149 } | 149 } |
150 | 150 |
151 // Used to select the actual mode. | 151 // Used to select the actual mode. |
152 mode = new ash::ManagedDisplayMode(size, refresh_rate, false /* interlaced */, | 152 mode = new display::ManagedDisplayMode( |
153 false /* native */, ui_scale, | 153 size, refresh_rate, false /* interlaced */, false /* native */, ui_scale, |
154 device_scale_factor); | 154 device_scale_factor); |
155 return mode; | 155 return mode; |
156 } | 156 } |
157 | 157 |
158 base::DictionaryValue* ConvertDisplayModeToValue( | 158 base::DictionaryValue* ConvertDisplayModeToValue( |
159 int64_t display_id, | 159 int64_t display_id, |
160 const scoped_refptr<ash::ManagedDisplayMode>& mode) { | 160 const scoped_refptr<display::ManagedDisplayMode>& mode) { |
161 bool is_internal = display::Display::HasInternalDisplay() && | 161 bool is_internal = display::Display::HasInternalDisplay() && |
162 display::Display::InternalDisplayId() == display_id; | 162 display::Display::InternalDisplayId() == display_id; |
163 base::DictionaryValue* result = new base::DictionaryValue(); | 163 base::DictionaryValue* result = new base::DictionaryValue(); |
164 gfx::Size size_dip = mode->GetSizeInDIP(is_internal); | 164 gfx::Size size_dip = mode->GetSizeInDIP(is_internal); |
165 result->SetInteger("width", size_dip.width()); | 165 result->SetInteger("width", size_dip.width()); |
166 result->SetInteger("height", size_dip.height()); | 166 result->SetInteger("height", size_dip.height()); |
167 result->SetInteger("originalWidth", mode->size().width()); | 167 result->SetInteger("originalWidth", mode->size().width()); |
168 result->SetInteger("originalHeight", mode->size().height()); | 168 result->SetInteger("originalHeight", mode->size().height()); |
169 result->SetDouble("deviceScaleFactor", mode->device_scale_factor()); | 169 result->SetDouble("deviceScaleFactor", mode->device_scale_factor()); |
170 result->SetDouble("scale", mode->ui_scale()); | 170 result->SetDouble("scale", mode->ui_scale()); |
(...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
312 display_mode = ash::DisplayManager::MIRRORING; | 312 display_mode = ash::DisplayManager::MIRRORING; |
313 else if (display_manager->IsInUnifiedMode()) | 313 else if (display_manager->IsInUnifiedMode()) |
314 display_mode = ash::DisplayManager::UNIFIED; | 314 display_mode = ash::DisplayManager::UNIFIED; |
315 else | 315 else |
316 display_mode = ash::DisplayManager::EXTENDED; | 316 display_mode = ash::DisplayManager::EXTENDED; |
317 base::FundamentalValue mode(static_cast<int>(display_mode)); | 317 base::FundamentalValue mode(static_cast<int>(display_mode)); |
318 | 318 |
319 int64_t primary_id = display::Screen::GetScreen()->GetPrimaryDisplay().id(); | 319 int64_t primary_id = display::Screen::GetScreen()->GetPrimaryDisplay().id(); |
320 std::unique_ptr<base::ListValue> js_displays(new base::ListValue); | 320 std::unique_ptr<base::ListValue> js_displays(new base::ListValue); |
321 for (const display::Display& display : displays) { | 321 for (const display::Display& display : displays) { |
322 const ash::DisplayInfo& display_info = | 322 const display::ManagedDisplayInfo& display_info = |
323 display_manager->GetDisplayInfo(display.id()); | 323 display_manager->GetDisplayInfo(display.id()); |
324 base::DictionaryValue* js_display = new base::DictionaryValue(); | 324 base::DictionaryValue* js_display = new base::DictionaryValue(); |
325 js_display->SetString("id", base::Int64ToString(display.id())); | 325 js_display->SetString("id", base::Int64ToString(display.id())); |
326 js_display->SetString("name", | 326 js_display->SetString("name", |
327 display_manager->GetDisplayNameForId(display.id())); | 327 display_manager->GetDisplayNameForId(display.id())); |
328 base::DictionaryValue* display_bounds = | 328 base::DictionaryValue* display_bounds = |
329 ConvertBoundsToValue(display.bounds()); | 329 ConvertBoundsToValue(display.bounds()); |
330 js_display->Set("bounds", display_bounds); | 330 js_display->Set("bounds", display_bounds); |
331 js_display->SetBoolean("isPrimary", display.id() == primary_id); | 331 js_display->SetBoolean("isPrimary", display.id() == primary_id); |
332 js_display->SetBoolean("isInternal", display.IsInternal()); | 332 js_display->SetBoolean("isInternal", display.IsInternal()); |
333 js_display->SetInteger("rotation", display.RotationAsDegree()); | 333 js_display->SetInteger("rotation", display.RotationAsDegree()); |
334 | 334 |
335 base::ListValue* js_resolutions = new base::ListValue(); | 335 base::ListValue* js_resolutions = new base::ListValue(); |
336 for (const scoped_refptr<ash::ManagedDisplayMode>& display_mode : | 336 for (const scoped_refptr<display::ManagedDisplayMode>& display_mode : |
337 display_info.display_modes()) { | 337 display_info.display_modes()) { |
338 js_resolutions->Append( | 338 js_resolutions->Append( |
339 ConvertDisplayModeToValue(display.id(), display_mode)); | 339 ConvertDisplayModeToValue(display.id(), display_mode)); |
340 } | 340 } |
341 js_display->Set("resolutions", js_resolutions); | 341 js_display->Set("resolutions", js_resolutions); |
342 | 342 |
343 js_display->SetInteger("colorProfileId", display_info.color_profile()); | 343 js_display->SetInteger("colorProfileId", display_info.color_profile()); |
344 base::ListValue* available_color_profiles = new base::ListValue(); | 344 base::ListValue* available_color_profiles = new base::ListValue(); |
345 for (const auto& color_profile : display_info.available_color_profiles()) { | 345 for (const auto& color_profile : display_info.available_color_profiles()) { |
346 const base::string16 profile_name = GetColorProfileName(color_profile); | 346 const base::string16 profile_name = GetColorProfileName(color_profile); |
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
471 int64_t display_id = GetDisplayIdFromArgs(args); | 471 int64_t display_id = GetDisplayIdFromArgs(args); |
472 if (display_id == display::Display::kInvalidDisplayID) | 472 if (display_id == display::Display::kInvalidDisplayID) |
473 return; | 473 return; |
474 | 474 |
475 const base::DictionaryValue* mode_data = nullptr; | 475 const base::DictionaryValue* mode_data = nullptr; |
476 if (!args->GetDictionary(1, &mode_data)) { | 476 if (!args->GetDictionary(1, &mode_data)) { |
477 LOG(ERROR) << "Failed to get mode data"; | 477 LOG(ERROR) << "Failed to get mode data"; |
478 return; | 478 return; |
479 } | 479 } |
480 | 480 |
481 scoped_refptr<ash::ManagedDisplayMode> mode = | 481 scoped_refptr<display::ManagedDisplayMode> mode = |
482 ConvertValueToManagedDisplayMode(mode_data); | 482 ConvertValueToManagedDisplayMode(mode_data); |
483 if (!mode) | 483 if (!mode) |
484 return; | 484 return; |
485 | 485 |
486 content::RecordAction( | 486 content::RecordAction( |
487 base::UserMetricsAction("Options_DisplaySetResolution")); | 487 base::UserMetricsAction("Options_DisplaySetResolution")); |
488 ash::DisplayManager* display_manager = GetDisplayManager(); | 488 ash::DisplayManager* display_manager = GetDisplayManager(); |
489 scoped_refptr<ash::ManagedDisplayMode> current_mode = | 489 scoped_refptr<display::ManagedDisplayMode> current_mode = |
490 display_manager->GetActiveModeForDisplayId(display_id); | 490 display_manager->GetActiveModeForDisplayId(display_id); |
491 if (!display_manager->SetDisplayMode(display_id, mode)) { | 491 if (!display_manager->SetDisplayMode(display_id, mode)) { |
492 LOG(ERROR) << "Unable to set display mode for: " << display_id | 492 LOG(ERROR) << "Unable to set display mode for: " << display_id |
493 << " Mode: " << *mode_data; | 493 << " Mode: " << *mode_data; |
494 return; | 494 return; |
495 } | 495 } |
496 if (display::Display::IsInternalDisplayId(display_id)) | 496 if (display::Display::IsInternalDisplayId(display_id)) |
497 return; | 497 return; |
498 // For external displays, show a notification confirming the resolution | 498 // For external displays, show a notification confirming the resolution |
499 // change. | 499 // change. |
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
570 bool enable = false; | 570 bool enable = false; |
571 if (!args->GetBoolean(0, &enable)) | 571 if (!args->GetBoolean(0, &enable)) |
572 NOTREACHED(); | 572 NOTREACHED(); |
573 | 573 |
574 GetDisplayManager()->SetDefaultMultiDisplayModeForCurrentDisplays( | 574 GetDisplayManager()->SetDefaultMultiDisplayModeForCurrentDisplays( |
575 enable ? ash::DisplayManager::UNIFIED : ash::DisplayManager::EXTENDED); | 575 enable ? ash::DisplayManager::UNIFIED : ash::DisplayManager::EXTENDED); |
576 } | 576 } |
577 | 577 |
578 } // namespace options | 578 } // namespace options |
579 } // namespace chromeos | 579 } // namespace chromeos |
OLD | NEW |