| 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 <memory> | 10 #include <memory> |
| 11 #include <string> | 11 #include <string> |
| 12 #include <utility> | 12 #include <utility> |
| 13 | 13 |
| 14 #include "ash/common/strings/grit/ash_strings.h" | 14 #include "ash/common/strings/grit/ash_strings.h" |
| 15 #include "ash/display/display_configuration_controller.h" | 15 #include "ash/display/display_configuration_controller.h" |
| 16 #include "ash/display/display_manager.h" | |
| 17 #include "ash/display/resolution_notification_controller.h" | 16 #include "ash/display/resolution_notification_controller.h" |
| 18 #include "ash/display/window_tree_host_manager.h" | 17 #include "ash/display/window_tree_host_manager.h" |
| 19 #include "ash/shell.h" | 18 #include "ash/shell.h" |
| 20 #include "base/bind.h" | 19 #include "base/bind.h" |
| 21 #include "base/command_line.h" | 20 #include "base/command_line.h" |
| 22 #include "base/logging.h" | 21 #include "base/logging.h" |
| 23 #include "base/memory/ptr_util.h" | 22 #include "base/memory/ptr_util.h" |
| 24 #include "base/strings/string_number_conversions.h" | 23 #include "base/strings/string_number_conversions.h" |
| 25 #include "base/strings/stringprintf.h" | 24 #include "base/strings/stringprintf.h" |
| 26 #include "base/values.h" | 25 #include "base/values.h" |
| 27 #include "chrome/browser/chromeos/display/display_preferences.h" | 26 #include "chrome/browser/chromeos/display/display_preferences.h" |
| 28 #include "chrome/browser/ui/ash/ash_util.h" | 27 #include "chrome/browser/ui/ash/ash_util.h" |
| 29 #include "chrome/grit/generated_resources.h" | 28 #include "chrome/grit/generated_resources.h" |
| 30 #include "chromeos/chromeos_switches.h" | 29 #include "chromeos/chromeos_switches.h" |
| 31 #include "content/public/browser/user_metrics.h" | 30 #include "content/public/browser/user_metrics.h" |
| 32 #include "content/public/browser/web_ui.h" | 31 #include "content/public/browser/web_ui.h" |
| 33 #include "ui/base/l10n/l10n_util.h" | 32 #include "ui/base/l10n/l10n_util.h" |
| 34 #include "ui/display/display.h" | 33 #include "ui/display/display.h" |
| 35 #include "ui/display/manager/display_layout.h" | 34 #include "ui/display/manager/display_layout.h" |
| 36 #include "ui/display/manager/display_layout_builder.h" | 35 #include "ui/display/manager/display_layout_builder.h" |
| 36 #include "ui/display/manager/display_manager.h" |
| 37 #include "ui/display/screen.h" | 37 #include "ui/display/screen.h" |
| 38 #include "ui/gfx/geometry/rect.h" | 38 #include "ui/gfx/geometry/rect.h" |
| 39 #include "ui/gfx/geometry/size_conversions.h" | 39 #include "ui/gfx/geometry/size_conversions.h" |
| 40 | 40 |
| 41 namespace chromeos { | 41 namespace chromeos { |
| 42 namespace options { | 42 namespace options { |
| 43 namespace { | 43 namespace { |
| 44 | 44 |
| 45 ash::DisplayManager* GetDisplayManager() { | 45 display::DisplayManager* GetDisplayManager() { |
| 46 return ash::Shell::GetInstance()->display_manager(); | 46 return ash::Shell::GetInstance()->display_manager(); |
| 47 } | 47 } |
| 48 | 48 |
| 49 ash::DisplayConfigurationController* GetDisplayConfigurationController() { | 49 ash::DisplayConfigurationController* GetDisplayConfigurationController() { |
| 50 return ash::Shell::GetInstance()->display_configuration_controller(); | 50 return ash::Shell::GetInstance()->display_configuration_controller(); |
| 51 } | 51 } |
| 52 | 52 |
| 53 int64_t GetDisplayIdFromValue(const base::Value* arg) { | 53 int64_t GetDisplayIdFromValue(const base::Value* arg) { |
| 54 std::string id_value; | 54 std::string id_value; |
| 55 if (!arg->GetAsString(&id_value)) | 55 if (!arg->GetAsString(&id_value)) |
| (...skipping 242 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 298 | 298 |
| 299 void DisplayOptionsHandler::OnDisplayConfigurationChanging() { | 299 void DisplayOptionsHandler::OnDisplayConfigurationChanging() { |
| 300 } | 300 } |
| 301 | 301 |
| 302 void DisplayOptionsHandler::OnDisplayConfigurationChanged() { | 302 void DisplayOptionsHandler::OnDisplayConfigurationChanged() { |
| 303 UpdateDisplaySettingsEnabled(); | 303 UpdateDisplaySettingsEnabled(); |
| 304 SendAllDisplayInfo(); | 304 SendAllDisplayInfo(); |
| 305 } | 305 } |
| 306 | 306 |
| 307 void DisplayOptionsHandler::SendAllDisplayInfo() { | 307 void DisplayOptionsHandler::SendAllDisplayInfo() { |
| 308 ash::DisplayManager* display_manager = GetDisplayManager(); | 308 display::DisplayManager* display_manager = GetDisplayManager(); |
| 309 | 309 |
| 310 std::vector<display::Display> displays; | 310 std::vector<display::Display> displays; |
| 311 for (size_t i = 0; i < display_manager->GetNumDisplays(); ++i) | 311 for (size_t i = 0; i < display_manager->GetNumDisplays(); ++i) |
| 312 displays.push_back(display_manager->GetDisplayAt(i)); | 312 displays.push_back(display_manager->GetDisplayAt(i)); |
| 313 | 313 |
| 314 ash::DisplayManager::MultiDisplayMode display_mode; | 314 display::DisplayManager::MultiDisplayMode display_mode; |
| 315 if (display_manager->IsInMirrorMode()) | 315 if (display_manager->IsInMirrorMode()) |
| 316 display_mode = ash::DisplayManager::MIRRORING; | 316 display_mode = display::DisplayManager::MIRRORING; |
| 317 else if (display_manager->IsInUnifiedMode()) | 317 else if (display_manager->IsInUnifiedMode()) |
| 318 display_mode = ash::DisplayManager::UNIFIED; | 318 display_mode = display::DisplayManager::UNIFIED; |
| 319 else | 319 else |
| 320 display_mode = ash::DisplayManager::EXTENDED; | 320 display_mode = display::DisplayManager::EXTENDED; |
| 321 base::FundamentalValue mode(static_cast<int>(display_mode)); | 321 base::FundamentalValue mode(static_cast<int>(display_mode)); |
| 322 | 322 |
| 323 int64_t primary_id = display::Screen::GetScreen()->GetPrimaryDisplay().id(); | 323 int64_t primary_id = display::Screen::GetScreen()->GetPrimaryDisplay().id(); |
| 324 std::unique_ptr<base::ListValue> js_displays(new base::ListValue); | 324 std::unique_ptr<base::ListValue> js_displays(new base::ListValue); |
| 325 for (const display::Display& display : displays) { | 325 for (const display::Display& display : displays) { |
| 326 const display::ManagedDisplayInfo& display_info = | 326 const display::ManagedDisplayInfo& display_info = |
| 327 display_manager->GetDisplayInfo(display.id()); | 327 display_manager->GetDisplayInfo(display.id()); |
| 328 auto js_display = base::MakeUnique<base::DictionaryValue>(); | 328 auto js_display = base::MakeUnique<base::DictionaryValue>(); |
| 329 js_display->SetString("id", base::Int64ToString(display.id())); | 329 js_display->SetString("id", base::Int64ToString(display.id())); |
| 330 js_display->SetString("name", | 330 js_display->SetString("name", |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 374 | 374 |
| 375 web_ui()->CallJavascriptFunctionUnsafe( | 375 web_ui()->CallJavascriptFunctionUnsafe( |
| 376 "options.DisplayOptions.setDisplayInfo", mode, *js_displays); | 376 "options.DisplayOptions.setDisplayInfo", mode, *js_displays); |
| 377 } | 377 } |
| 378 | 378 |
| 379 void DisplayOptionsHandler::UpdateDisplaySettingsEnabled() { | 379 void DisplayOptionsHandler::UpdateDisplaySettingsEnabled() { |
| 380 // TODO(mash) Support Chrome display settings in Mash. crbug.com/548429 | 380 // TODO(mash) Support Chrome display settings in Mash. crbug.com/548429 |
| 381 if (chrome::IsRunningInMash()) | 381 if (chrome::IsRunningInMash()) |
| 382 return; | 382 return; |
| 383 | 383 |
| 384 ash::DisplayManager* display_manager = GetDisplayManager(); | 384 display::DisplayManager* display_manager = GetDisplayManager(); |
| 385 bool disable_multi_display_layout = | 385 bool disable_multi_display_layout = |
| 386 base::CommandLine::ForCurrentProcess()->HasSwitch( | 386 base::CommandLine::ForCurrentProcess()->HasSwitch( |
| 387 chromeos::switches::kDisableMultiDisplayLayout); | 387 chromeos::switches::kDisableMultiDisplayLayout); |
| 388 bool ui_enabled = display_manager->num_connected_displays() <= 2 || | 388 bool ui_enabled = display_manager->num_connected_displays() <= 2 || |
| 389 !disable_multi_display_layout; | 389 !disable_multi_display_layout; |
| 390 bool unified_enabled = display_manager->unified_desktop_enabled(); | 390 bool unified_enabled = display_manager->unified_desktop_enabled(); |
| 391 bool mirrored_enabled = display_manager->num_connected_displays() == 2; | 391 bool mirrored_enabled = display_manager->num_connected_displays() == 2; |
| 392 | 392 |
| 393 web_ui()->CallJavascriptFunctionUnsafe( | 393 web_ui()->CallJavascriptFunctionUnsafe( |
| 394 "options.BrowserOptions.enableDisplaySettings", | 394 "options.BrowserOptions.enableDisplaySettings", |
| (...skipping 29 matching lines...) Expand all Loading... |
| 424 display_id, true /* user_action */); | 424 display_id, true /* user_action */); |
| 425 } | 425 } |
| 426 | 426 |
| 427 void DisplayOptionsHandler::HandleSetDisplayLayout( | 427 void DisplayOptionsHandler::HandleSetDisplayLayout( |
| 428 const base::ListValue* args) { | 428 const base::ListValue* args) { |
| 429 const base::ListValue* layouts = nullptr; | 429 const base::ListValue* layouts = nullptr; |
| 430 if (!args->GetList(0, &layouts)) | 430 if (!args->GetList(0, &layouts)) |
| 431 NOTREACHED(); | 431 NOTREACHED(); |
| 432 content::RecordAction(base::UserMetricsAction("Options_DisplayRearrange")); | 432 content::RecordAction(base::UserMetricsAction("Options_DisplayRearrange")); |
| 433 | 433 |
| 434 ash::DisplayManager* display_manager = GetDisplayManager(); | 434 display::DisplayManager* display_manager = GetDisplayManager(); |
| 435 display::DisplayLayoutBuilder builder( | 435 display::DisplayLayoutBuilder builder( |
| 436 display_manager->GetCurrentDisplayLayout()); | 436 display_manager->GetCurrentDisplayLayout()); |
| 437 builder.ClearPlacements(); | 437 builder.ClearPlacements(); |
| 438 for (const auto& layout : *layouts) { | 438 for (const auto& layout : *layouts) { |
| 439 const base::DictionaryValue* dictionary; | 439 const base::DictionaryValue* dictionary; |
| 440 if (!layout->GetAsDictionary(&dictionary)) { | 440 if (!layout->GetAsDictionary(&dictionary)) { |
| 441 LOG(ERROR) << "Invalid layout dictionary: " << *dictionary; | 441 LOG(ERROR) << "Invalid layout dictionary: " << *dictionary; |
| 442 continue; | 442 continue; |
| 443 } | 443 } |
| 444 | 444 |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 486 return; | 486 return; |
| 487 } | 487 } |
| 488 | 488 |
| 489 scoped_refptr<display::ManagedDisplayMode> mode = | 489 scoped_refptr<display::ManagedDisplayMode> mode = |
| 490 ConvertValueToManagedDisplayMode(mode_data); | 490 ConvertValueToManagedDisplayMode(mode_data); |
| 491 if (!mode) | 491 if (!mode) |
| 492 return; | 492 return; |
| 493 | 493 |
| 494 content::RecordAction( | 494 content::RecordAction( |
| 495 base::UserMetricsAction("Options_DisplaySetResolution")); | 495 base::UserMetricsAction("Options_DisplaySetResolution")); |
| 496 ash::DisplayManager* display_manager = GetDisplayManager(); | 496 display::DisplayManager* display_manager = GetDisplayManager(); |
| 497 scoped_refptr<display::ManagedDisplayMode> current_mode = | 497 scoped_refptr<display::ManagedDisplayMode> current_mode = |
| 498 display_manager->GetActiveModeForDisplayId(display_id); | 498 display_manager->GetActiveModeForDisplayId(display_id); |
| 499 if (!display_manager->SetDisplayMode(display_id, mode)) { | 499 if (!display_manager->SetDisplayMode(display_id, mode)) { |
| 500 LOG(ERROR) << "Unable to set display mode for: " << display_id | 500 LOG(ERROR) << "Unable to set display mode for: " << display_id |
| 501 << " Mode: " << *mode_data; | 501 << " Mode: " << *mode_data; |
| 502 return; | 502 return; |
| 503 } | 503 } |
| 504 if (display::Display::IsInternalDisplayId(display_id)) | 504 if (display::Display::IsInternalDisplayId(display_id)) |
| 505 return; | 505 return; |
| 506 // For external displays, show a notification confirming the resolution | 506 // For external displays, show a notification confirming the resolution |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 573 } | 573 } |
| 574 | 574 |
| 575 void DisplayOptionsHandler::HandleSetUnifiedDesktopEnabled( | 575 void DisplayOptionsHandler::HandleSetUnifiedDesktopEnabled( |
| 576 const base::ListValue* args) { | 576 const base::ListValue* args) { |
| 577 DCHECK(GetDisplayManager()->unified_desktop_enabled()); | 577 DCHECK(GetDisplayManager()->unified_desktop_enabled()); |
| 578 bool enable = false; | 578 bool enable = false; |
| 579 if (!args->GetBoolean(0, &enable)) | 579 if (!args->GetBoolean(0, &enable)) |
| 580 NOTREACHED(); | 580 NOTREACHED(); |
| 581 | 581 |
| 582 GetDisplayManager()->SetDefaultMultiDisplayModeForCurrentDisplays( | 582 GetDisplayManager()->SetDefaultMultiDisplayModeForCurrentDisplays( |
| 583 enable ? ash::DisplayManager::UNIFIED : ash::DisplayManager::EXTENDED); | 583 enable ? display::DisplayManager::UNIFIED |
| 584 : display::DisplayManager::EXTENDED); |
| 584 } | 585 } |
| 585 | 586 |
| 586 } // namespace options | 587 } // namespace options |
| 587 } // namespace chromeos | 588 } // namespace chromeos |
| OLD | NEW |