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" |
11 #include "ash/display/output_configurator_animation.h" | 11 #include "ash/display/output_configurator_animation.h" |
12 #include "ash/display/resolution_notification_controller.h" | 12 #include "ash/display/resolution_notification_controller.h" |
13 #include "ash/shell.h" | 13 #include "ash/shell.h" |
14 #include "base/bind.h" | 14 #include "base/bind.h" |
15 #include "base/logging.h" | 15 #include "base/logging.h" |
16 #include "base/strings/string_number_conversions.h" | 16 #include "base/strings/string_number_conversions.h" |
17 #include "base/strings/stringprintf.h" | 17 #include "base/strings/stringprintf.h" |
18 #include "base/values.h" | 18 #include "base/values.h" |
19 #include "chrome/browser/chromeos/display/display_preferences.h" | 19 #include "chrome/browser/chromeos/display/display_preferences.h" |
20 #include "content/public/browser/web_ui.h" | 20 #include "content/public/browser/web_ui.h" |
21 #include "grit/ash_strings.h" | 21 #include "grit/ash_strings.h" |
22 #include "grit/generated_resources.h" | 22 #include "grit/generated_resources.h" |
23 #include "ui/base/l10n/l10n_util.h" | 23 #include "ui/base/l10n/l10n_util.h" |
24 #include "ui/gfx/display.h" | 24 #include "ui/gfx/display.h" |
25 #include "ui/gfx/rect.h" | 25 #include "ui/gfx/rect.h" |
26 #include "ui/gfx/screen.h" | 26 #include "ui/gfx/screen.h" |
27 #include "ui/gfx/size_conversions.h" | 27 #include "ui/gfx/size_conversions.h" |
28 | 28 |
29 using ash::internal::DisplayManager; | 29 using ash::DisplayManager; |
30 | 30 |
31 namespace chromeos { | 31 namespace chromeos { |
32 namespace options { | 32 namespace options { |
33 namespace { | 33 namespace { |
34 | 34 |
35 DisplayManager* GetDisplayManager() { | 35 DisplayManager* GetDisplayManager() { |
36 return ash::Shell::GetInstance()->display_manager(); | 36 return ash::Shell::GetInstance()->display_manager(); |
37 } | 37 } |
38 | 38 |
39 int64 GetDisplayId(const base::ListValue* args) { | 39 int64 GetDisplayId(const base::ListValue* args) { |
40 // Assumes the display ID is specified as the first argument. | 40 // Assumes the display ID is specified as the first argument. |
41 std::string id_value; | 41 std::string id_value; |
42 if (!args->GetString(0, &id_value)) { | 42 if (!args->GetString(0, &id_value)) { |
43 LOG(ERROR) << "Can't find ID"; | 43 LOG(ERROR) << "Can't find ID"; |
44 return gfx::Display::kInvalidDisplayID; | 44 return gfx::Display::kInvalidDisplayID; |
45 } | 45 } |
46 | 46 |
47 int64 display_id = gfx::Display::kInvalidDisplayID; | 47 int64 display_id = gfx::Display::kInvalidDisplayID; |
48 if (!base::StringToInt64(id_value, &display_id)) { | 48 if (!base::StringToInt64(id_value, &display_id)) { |
49 LOG(ERROR) << "Invalid display id: " << id_value; | 49 LOG(ERROR) << "Invalid display id: " << id_value; |
50 return gfx::Display::kInvalidDisplayID; | 50 return gfx::Display::kInvalidDisplayID; |
51 } | 51 } |
52 | 52 |
53 return display_id; | 53 return display_id; |
54 } | 54 } |
55 | 55 |
56 bool CompareDisplayMode(ash::internal::DisplayMode d1, | 56 bool CompareDisplayMode(ash::DisplayMode d1, ash::DisplayMode d2) { |
57 ash::internal::DisplayMode d2) { | |
58 if (d1.size.GetArea() == d2.size.GetArea()) | 57 if (d1.size.GetArea() == d2.size.GetArea()) |
59 return d1.refresh_rate < d2.refresh_rate; | 58 return d1.refresh_rate < d2.refresh_rate; |
60 return d1.size.GetArea() < d2.size.GetArea(); | 59 return d1.size.GetArea() < d2.size.GetArea(); |
61 } | 60 } |
62 | 61 |
63 base::string16 GetColorProfileName(ui::ColorCalibrationProfile profile) { | 62 base::string16 GetColorProfileName(ui::ColorCalibrationProfile profile) { |
64 switch (profile) { | 63 switch (profile) { |
65 case ui::COLOR_PROFILE_STANDARD: | 64 case ui::COLOR_PROFILE_STANDARD: |
66 return l10n_util::GetStringUTF16( | 65 return l10n_util::GetStringUTF16( |
67 IDS_OPTIONS_SETTINGS_DISPLAY_OPTIONS_COLOR_PROFILE_STANDARD); | 66 IDS_OPTIONS_SETTINGS_DISPLAY_OPTIONS_COLOR_PROFILE_STANDARD); |
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
195 | 194 |
196 void DisplayOptionsHandler::SendDisplayInfo( | 195 void DisplayOptionsHandler::SendDisplayInfo( |
197 const std::vector<gfx::Display>& displays) { | 196 const std::vector<gfx::Display>& displays) { |
198 DisplayManager* display_manager = GetDisplayManager(); | 197 DisplayManager* display_manager = GetDisplayManager(); |
199 base::FundamentalValue mirroring(display_manager->IsMirrored()); | 198 base::FundamentalValue mirroring(display_manager->IsMirrored()); |
200 | 199 |
201 int64 primary_id = ash::Shell::GetScreen()->GetPrimaryDisplay().id(); | 200 int64 primary_id = ash::Shell::GetScreen()->GetPrimaryDisplay().id(); |
202 base::ListValue js_displays; | 201 base::ListValue js_displays; |
203 for (size_t i = 0; i < displays.size(); ++i) { | 202 for (size_t i = 0; i < displays.size(); ++i) { |
204 const gfx::Display& display = displays[i]; | 203 const gfx::Display& display = displays[i]; |
205 const ash::internal::DisplayInfo& display_info = | 204 const ash::DisplayInfo& display_info = |
206 display_manager->GetDisplayInfo(display.id()); | 205 display_manager->GetDisplayInfo(display.id()); |
207 const gfx::Rect& bounds = display.bounds(); | 206 const gfx::Rect& bounds = display.bounds(); |
208 base::DictionaryValue* js_display = new base::DictionaryValue(); | 207 base::DictionaryValue* js_display = new base::DictionaryValue(); |
209 js_display->SetString("id", base::Int64ToString(display.id())); | 208 js_display->SetString("id", base::Int64ToString(display.id())); |
210 js_display->SetInteger("x", bounds.x()); | 209 js_display->SetInteger("x", bounds.x()); |
211 js_display->SetInteger("y", bounds.y()); | 210 js_display->SetInteger("y", bounds.y()); |
212 js_display->SetInteger("width", bounds.width()); | 211 js_display->SetInteger("width", bounds.width()); |
213 js_display->SetInteger("height", bounds.height()); | 212 js_display->SetInteger("height", bounds.height()); |
214 js_display->SetString("name", | 213 js_display->SetString("name", |
215 display_manager->GetDisplayNameForId(display.id())); | 214 display_manager->GetDisplayNameForId(display.id())); |
216 js_display->SetBoolean("isPrimary", display.id() == primary_id); | 215 js_display->SetBoolean("isPrimary", display.id() == primary_id); |
217 js_display->SetBoolean("isInternal", display.IsInternal()); | 216 js_display->SetBoolean("isInternal", display.IsInternal()); |
218 js_display->SetInteger("orientation", | 217 js_display->SetInteger("orientation", |
219 static_cast<int>(display_info.rotation())); | 218 static_cast<int>(display_info.rotation())); |
220 std::vector<ash::internal::DisplayMode> display_modes; | 219 std::vector<ash::DisplayMode> display_modes; |
221 std::vector<float> ui_scales; | 220 std::vector<float> ui_scales; |
222 if (display.IsInternal()) { | 221 if (display.IsInternal()) { |
223 ui_scales = DisplayManager::GetScalesForDisplay(display_info); | 222 ui_scales = DisplayManager::GetScalesForDisplay(display_info); |
224 gfx::SizeF base_size = display_info.bounds_in_native().size(); | 223 gfx::SizeF base_size = display_info.bounds_in_native().size(); |
225 base_size.Scale(1.0f / display_info.device_scale_factor()); | 224 base_size.Scale(1.0f / display_info.device_scale_factor()); |
226 if (display_info.rotation() == gfx::Display::ROTATE_90 || | 225 if (display_info.rotation() == gfx::Display::ROTATE_90 || |
227 display_info.rotation() == gfx::Display::ROTATE_270) { | 226 display_info.rotation() == gfx::Display::ROTATE_270) { |
228 float tmp = base_size.width(); | 227 float tmp = base_size.width(); |
229 base_size.set_width(base_size.height()); | 228 base_size.set_width(base_size.height()); |
230 base_size.set_height(tmp); | 229 base_size.set_height(tmp); |
231 } | 230 } |
232 for (size_t i = 0; i < ui_scales.size(); ++i) { | 231 for (size_t i = 0; i < ui_scales.size(); ++i) { |
233 gfx::SizeF new_size = base_size; | 232 gfx::SizeF new_size = base_size; |
234 new_size.Scale(ui_scales[i]); | 233 new_size.Scale(ui_scales[i]); |
235 display_modes.push_back(ash::internal::DisplayMode( | 234 display_modes.push_back(ash::DisplayMode( |
236 gfx::ToFlooredSize(new_size), -1.0f, false, false)); | 235 gfx::ToFlooredSize(new_size), -1.0f, false, false)); |
237 } | 236 } |
238 } else { | 237 } else { |
239 for (size_t i = 0; i < display_info.display_modes().size(); ++i) | 238 for (size_t i = 0; i < display_info.display_modes().size(); ++i) |
240 display_modes.push_back(display_info.display_modes()[i]); | 239 display_modes.push_back(display_info.display_modes()[i]); |
241 } | 240 } |
242 std::sort(display_modes.begin(), display_modes.end(), CompareDisplayMode); | 241 std::sort(display_modes.begin(), display_modes.end(), CompareDisplayMode); |
243 | 242 |
244 base::ListValue* js_resolutions = new base::ListValue(); | 243 base::ListValue* js_resolutions = new base::ListValue(); |
245 gfx::Size current_size = display_info.bounds_in_native().size(); | 244 gfx::Size current_size = display_info.bounds_in_native().size(); |
(...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
384 double height = 0.0f; | 383 double height = 0.0f; |
385 if (!args->GetDouble(1, &width) || width == 0.0f) { | 384 if (!args->GetDouble(1, &width) || width == 0.0f) { |
386 LOG(ERROR) << "Can't find new width"; | 385 LOG(ERROR) << "Can't find new width"; |
387 return; | 386 return; |
388 } | 387 } |
389 if (!args->GetDouble(2, &height) || height == 0.0f) { | 388 if (!args->GetDouble(2, &height) || height == 0.0f) { |
390 LOG(ERROR) << "Can't find new height"; | 389 LOG(ERROR) << "Can't find new height"; |
391 return; | 390 return; |
392 } | 391 } |
393 | 392 |
394 const ash::internal::DisplayInfo& display_info = | 393 const ash::DisplayInfo& display_info = |
395 GetDisplayManager()->GetDisplayInfo(display_id); | 394 GetDisplayManager()->GetDisplayInfo(display_id); |
396 gfx::Insets current_overscan = display_info.GetOverscanInsetsInPixel(); | 395 gfx::Insets current_overscan = display_info.GetOverscanInsetsInPixel(); |
397 gfx::Size new_resolution = gfx::ToFlooredSize(gfx::SizeF(width, height)); | 396 gfx::Size new_resolution = gfx::ToFlooredSize(gfx::SizeF(width, height)); |
398 new_resolution.Enlarge(current_overscan.width(), current_overscan.height()); | 397 new_resolution.Enlarge(current_overscan.width(), current_overscan.height()); |
399 gfx::Size old_resolution = display_info.bounds_in_native().size(); | 398 gfx::Size old_resolution = display_info.bounds_in_native().size(); |
400 bool has_new_resolution = false; | 399 bool has_new_resolution = false; |
401 bool has_old_resolution = false; | 400 bool has_old_resolution = false; |
402 for (size_t i = 0; i < display_info.display_modes().size(); ++i) { | 401 for (size_t i = 0; i < display_info.display_modes().size(); ++i) { |
403 ash::internal::DisplayMode display_mode = display_info.display_modes()[i]; | 402 ash::DisplayMode display_mode = display_info.display_modes()[i]; |
404 if (display_mode.size == new_resolution) | 403 if (display_mode.size == new_resolution) |
405 has_new_resolution = true; | 404 has_new_resolution = true; |
406 if (display_mode.size == old_resolution) | 405 if (display_mode.size == old_resolution) |
407 has_old_resolution = true; | 406 has_old_resolution = true; |
408 } | 407 } |
409 if (!has_new_resolution) { | 408 if (!has_new_resolution) { |
410 LOG(ERROR) << "No new resolution " << new_resolution.ToString() | 409 LOG(ERROR) << "No new resolution " << new_resolution.ToString() |
411 << " is found in the display info " << display_info.ToString(); | 410 << " is found in the display info " << display_info.ToString(); |
412 return; | 411 return; |
413 } | 412 } |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
472 return; | 471 return; |
473 } | 472 } |
474 | 473 |
475 GetDisplayManager()->SetColorCalibrationProfile( | 474 GetDisplayManager()->SetColorCalibrationProfile( |
476 display_id, static_cast<ui::ColorCalibrationProfile>(profile_id)); | 475 display_id, static_cast<ui::ColorCalibrationProfile>(profile_id)); |
477 SendAllDisplayInfo(); | 476 SendAllDisplayInfo(); |
478 } | 477 } |
479 | 478 |
480 } // namespace options | 479 } // namespace options |
481 } // namespace chromeos | 480 } // namespace chromeos |
OLD | NEW |