| 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 130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 141 result->SetDouble("refreshRate", mode.refresh_rate); | 141 result->SetDouble("refreshRate", mode.refresh_rate); |
| 142 result->SetBoolean( | 142 result->SetBoolean( |
| 143 "isBest", is_internal ? (mode.ui_scale == 1.0f) : mode.native); | 143 "isBest", is_internal ? (mode.ui_scale == 1.0f) : mode.native); |
| 144 result->SetBoolean("isNative", mode.native); | 144 result->SetBoolean("isNative", mode.native); |
| 145 result->SetBoolean( | 145 result->SetBoolean( |
| 146 "selected", mode.IsEquivalent( | 146 "selected", mode.IsEquivalent( |
| 147 GetDisplayManager()->GetActiveModeForDisplayId(display_id))); | 147 GetDisplayManager()->GetActiveModeForDisplayId(display_id))); |
| 148 return result; | 148 return result; |
| 149 } | 149 } |
| 150 | 150 |
| 151 base::DictionaryValue* ConvertBoundsToValue(const gfx::Rect& bounds) { |
| 152 base::DictionaryValue* result = new base::DictionaryValue(); |
| 153 result->SetInteger("left", bounds.x()); |
| 154 result->SetInteger("top", bounds.y()); |
| 155 result->SetInteger("width", bounds.width()); |
| 156 result->SetInteger("height", bounds.height()); |
| 157 return result; |
| 158 } |
| 159 |
| 151 } // namespace | 160 } // namespace |
| 152 | 161 |
| 153 DisplayOptionsHandler::DisplayOptionsHandler() { | 162 DisplayOptionsHandler::DisplayOptionsHandler() { |
| 154 // ash::Shell doesn't exist in Athena. | 163 // ash::Shell doesn't exist in Athena. |
| 155 // See: http://crbug.com/416961 | 164 // See: http://crbug.com/416961 |
| 156 ash::Shell::GetInstance()->window_tree_host_manager()->AddObserver(this); | 165 ash::Shell::GetInstance()->window_tree_host_manager()->AddObserver(this); |
| 157 } | 166 } |
| 158 | 167 |
| 159 DisplayOptionsHandler::~DisplayOptionsHandler() { | 168 DisplayOptionsHandler::~DisplayOptionsHandler() { |
| 160 // ash::Shell doesn't exist in Athena. | 169 // ash::Shell doesn't exist in Athena. |
| (...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 232 base::Unretained(this))); | 241 base::Unretained(this))); |
| 233 web_ui()->RegisterMessageCallback( | 242 web_ui()->RegisterMessageCallback( |
| 234 "setDisplayLayout", | 243 "setDisplayLayout", |
| 235 base::Bind(&DisplayOptionsHandler::HandleSetDisplayLayout, | 244 base::Bind(&DisplayOptionsHandler::HandleSetDisplayLayout, |
| 236 base::Unretained(this))); | 245 base::Unretained(this))); |
| 237 web_ui()->RegisterMessageCallback( | 246 web_ui()->RegisterMessageCallback( |
| 238 "setDisplayMode", | 247 "setDisplayMode", |
| 239 base::Bind(&DisplayOptionsHandler::HandleSetDisplayMode, | 248 base::Bind(&DisplayOptionsHandler::HandleSetDisplayMode, |
| 240 base::Unretained(this))); | 249 base::Unretained(this))); |
| 241 web_ui()->RegisterMessageCallback( | 250 web_ui()->RegisterMessageCallback( |
| 242 "setOrientation", | 251 "setRotation", |
| 243 base::Bind(&DisplayOptionsHandler::HandleSetOrientation, | 252 base::Bind(&DisplayOptionsHandler::HandleSetRotation, |
| 244 base::Unretained(this))); | 253 base::Unretained(this))); |
| 245 web_ui()->RegisterMessageCallback( | 254 web_ui()->RegisterMessageCallback( |
| 246 "setColorProfile", | 255 "setColorProfile", |
| 247 base::Bind(&DisplayOptionsHandler::HandleSetColorProfile, | 256 base::Bind(&DisplayOptionsHandler::HandleSetColorProfile, |
| 248 base::Unretained(this))); | 257 base::Unretained(this))); |
| 249 web_ui()->RegisterMessageCallback( | 258 web_ui()->RegisterMessageCallback( |
| 250 "setUnifiedDesktopEnabled", | 259 "setUnifiedDesktopEnabled", |
| 251 base::Bind(&DisplayOptionsHandler::HandleSetUnifiedDesktopEnabled, | 260 base::Bind(&DisplayOptionsHandler::HandleSetUnifiedDesktopEnabled, |
| 252 base::Unretained(this))); | 261 base::Unretained(this))); |
| 253 } | 262 } |
| (...skipping 24 matching lines...) Expand all Loading... |
| 278 else if (display_manager->IsInUnifiedMode()) | 287 else if (display_manager->IsInUnifiedMode()) |
| 279 display_mode = ash::DisplayManager::UNIFIED; | 288 display_mode = ash::DisplayManager::UNIFIED; |
| 280 else | 289 else |
| 281 display_mode = ash::DisplayManager::EXTENDED; | 290 display_mode = ash::DisplayManager::EXTENDED; |
| 282 base::FundamentalValue mode(static_cast<int>(display_mode)); | 291 base::FundamentalValue mode(static_cast<int>(display_mode)); |
| 283 int64_t primary_id = ash::Shell::GetScreen()->GetPrimaryDisplay().id(); | 292 int64_t primary_id = ash::Shell::GetScreen()->GetPrimaryDisplay().id(); |
| 284 base::ListValue js_displays; | 293 base::ListValue js_displays; |
| 285 for (const gfx::Display& display : displays) { | 294 for (const gfx::Display& display : displays) { |
| 286 const ash::DisplayInfo& display_info = | 295 const ash::DisplayInfo& display_info = |
| 287 display_manager->GetDisplayInfo(display.id()); | 296 display_manager->GetDisplayInfo(display.id()); |
| 288 const gfx::Rect& bounds = display.bounds(); | |
| 289 base::DictionaryValue* js_display = new base::DictionaryValue(); | 297 base::DictionaryValue* js_display = new base::DictionaryValue(); |
| 290 js_display->SetString("id", base::Int64ToString(display.id())); | 298 js_display->SetString("id", base::Int64ToString(display.id())); |
| 291 js_display->SetInteger("x", bounds.x()); | |
| 292 js_display->SetInteger("y", bounds.y()); | |
| 293 js_display->SetInteger("width", bounds.width()); | |
| 294 js_display->SetInteger("height", bounds.height()); | |
| 295 js_display->SetString("name", | 299 js_display->SetString("name", |
| 296 display_manager->GetDisplayNameForId(display.id())); | 300 display_manager->GetDisplayNameForId(display.id())); |
| 301 base::DictionaryValue* display_bounds = |
| 302 ConvertBoundsToValue(display.bounds()); |
| 303 js_display->Set("bounds", display_bounds); |
| 297 js_display->SetBoolean("isPrimary", display.id() == primary_id); | 304 js_display->SetBoolean("isPrimary", display.id() == primary_id); |
| 298 js_display->SetBoolean("isInternal", display.IsInternal()); | 305 js_display->SetBoolean("isInternal", display.IsInternal()); |
| 299 js_display->SetInteger("orientation", | 306 js_display->SetInteger("rotation", display.RotationAsDegree()); |
| 300 static_cast<int>(display_info.GetActiveRotation())); | |
| 301 | 307 |
| 302 base::ListValue* js_resolutions = new base::ListValue(); | 308 base::ListValue* js_resolutions = new base::ListValue(); |
| 303 for (const ash::DisplayMode& display_mode : display_info.display_modes()) { | 309 for (const ash::DisplayMode& display_mode : display_info.display_modes()) { |
| 304 js_resolutions->Append( | 310 js_resolutions->Append( |
| 305 ConvertDisplayModeToValue(display.id(), display_mode)); | 311 ConvertDisplayModeToValue(display.id(), display_mode)); |
| 306 } | 312 } |
| 307 js_display->Set("resolutions", js_resolutions); | 313 js_display->Set("resolutions", js_resolutions); |
| 308 | 314 |
| 309 js_display->SetInteger("colorProfile", display_info.color_profile()); | 315 js_display->SetInteger("colorProfileId", display_info.color_profile()); |
| 310 base::ListValue* available_color_profiles = new base::ListValue(); | 316 base::ListValue* available_color_profiles = new base::ListValue(); |
| 311 for (const auto& color_profile : display_info.available_color_profiles()) { | 317 for (const auto& color_profile : display_info.available_color_profiles()) { |
| 312 const base::string16 profile_name = GetColorProfileName(color_profile); | 318 const base::string16 profile_name = GetColorProfileName(color_profile); |
| 313 if (profile_name.empty()) | 319 if (profile_name.empty()) |
| 314 continue; | 320 continue; |
| 315 base::DictionaryValue* color_profile_dict = new base::DictionaryValue(); | 321 base::DictionaryValue* color_profile_dict = new base::DictionaryValue(); |
| 316 color_profile_dict->SetInteger("profileId", color_profile); | 322 color_profile_dict->SetInteger("profileId", color_profile); |
| 317 color_profile_dict->SetString("name", profile_name); | 323 color_profile_dict->SetString("name", profile_name); |
| 318 available_color_profiles->Append(color_profile_dict); | 324 available_color_profiles->Append(color_profile_dict); |
| 319 } | 325 } |
| (...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 418 if (gfx::Display::IsInternalDisplayId(display_id)) | 424 if (gfx::Display::IsInternalDisplayId(display_id)) |
| 419 return; | 425 return; |
| 420 // For external displays, show a notification confirming the resolution | 426 // For external displays, show a notification confirming the resolution |
| 421 // change. | 427 // change. |
| 422 ash::Shell::GetInstance() | 428 ash::Shell::GetInstance() |
| 423 ->resolution_notification_controller() | 429 ->resolution_notification_controller() |
| 424 ->PrepareNotification(display_id, current_mode, mode, | 430 ->PrepareNotification(display_id, current_mode, mode, |
| 425 base::Bind(&chromeos::StoreDisplayPrefs)); | 431 base::Bind(&chromeos::StoreDisplayPrefs)); |
| 426 } | 432 } |
| 427 | 433 |
| 428 void DisplayOptionsHandler::HandleSetOrientation(const base::ListValue* args) { | 434 void DisplayOptionsHandler::HandleSetRotation(const base::ListValue* args) { |
| 429 DCHECK(!args->empty()); | 435 DCHECK(!args->empty()); |
| 430 | 436 |
| 431 int64_t display_id = GetDisplayId(args); | 437 int64_t display_id = GetDisplayId(args); |
| 432 if (display_id == gfx::Display::kInvalidDisplayID) | 438 if (display_id == gfx::Display::kInvalidDisplayID) |
| 433 return; | 439 return; |
| 434 | 440 |
| 435 std::string rotation_value; | 441 int rotation_value = 0; |
| 436 gfx::Display::Rotation new_rotation = gfx::Display::ROTATE_0; | 442 if (!args->GetInteger(1, &rotation_value)) { |
| 437 if (!args->GetString(1, &rotation_value)) { | 443 LOG(ERROR) << "Can't parse rotation: " << args; |
| 438 LOG(ERROR) << "Can't find new orientation"; | |
| 439 return; | 444 return; |
| 440 } | 445 } |
| 441 if (rotation_value == "90") | 446 gfx::Display::Rotation new_rotation = gfx::Display::ROTATE_0; |
| 447 if (rotation_value == 90) |
| 442 new_rotation = gfx::Display::ROTATE_90; | 448 new_rotation = gfx::Display::ROTATE_90; |
| 443 else if (rotation_value == "180") | 449 else if (rotation_value == 180) |
| 444 new_rotation = gfx::Display::ROTATE_180; | 450 new_rotation = gfx::Display::ROTATE_180; |
| 445 else if (rotation_value == "270") | 451 else if (rotation_value == 270) |
| 446 new_rotation = gfx::Display::ROTATE_270; | 452 new_rotation = gfx::Display::ROTATE_270; |
| 447 else if (rotation_value != "0") | 453 else if (rotation_value != 0) |
| 448 LOG(ERROR) << "Invalid rotation: " << rotation_value << " Falls back to 0"; | 454 LOG(ERROR) << "Invalid rotation: " << rotation_value << " Falls back to 0"; |
| 449 | 455 |
| 450 content::RecordAction( | 456 content::RecordAction( |
| 451 base::UserMetricsAction("Options_DisplaySetOrientation")); | 457 base::UserMetricsAction("Options_DisplaySetOrientation")); |
| 452 GetDisplayConfigurationController()->SetDisplayRotation( | 458 GetDisplayConfigurationController()->SetDisplayRotation( |
| 453 display_id, new_rotation, gfx::Display::ROTATION_SOURCE_USER, | 459 display_id, new_rotation, gfx::Display::ROTATION_SOURCE_USER, |
| 454 true /* user_action */); | 460 true /* user_action */); |
| 455 } | 461 } |
| 456 | 462 |
| 457 void DisplayOptionsHandler::HandleSetColorProfile(const base::ListValue* args) { | 463 void DisplayOptionsHandler::HandleSetColorProfile(const base::ListValue* args) { |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 492 bool enable = false; | 498 bool enable = false; |
| 493 if (!args->GetBoolean(0, &enable)) | 499 if (!args->GetBoolean(0, &enable)) |
| 494 NOTREACHED(); | 500 NOTREACHED(); |
| 495 | 501 |
| 496 GetDisplayManager()->SetDefaultMultiDisplayModeForCurrentDisplays( | 502 GetDisplayManager()->SetDefaultMultiDisplayModeForCurrentDisplays( |
| 497 enable ? ash::DisplayManager::UNIFIED : ash::DisplayManager::EXTENDED); | 503 enable ? ash::DisplayManager::UNIFIED : ash::DisplayManager::EXTENDED); |
| 498 } | 504 } |
| 499 | 505 |
| 500 } // namespace options | 506 } // namespace options |
| 501 } // namespace chromeos | 507 } // namespace chromeos |
| OLD | NEW |