 Chromium Code Reviews
 Chromium Code Reviews Issue 10544171:
  Add OptionsUI and its handler for multiple displays.  (Closed) 
  Base URL: svn://svn.chromium.org/chrome/trunk/src
    
  
    Issue 10544171:
  Add OptionsUI and its handler for multiple displays.  (Closed) 
  Base URL: svn://svn.chromium.org/chrome/trunk/src| OLD | NEW | 
|---|---|
| (Empty) | |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "chrome/browser/ui/webui/options2/chromeos/display_options_handler.h" | |
| 6 | |
| 7 #include <string> | |
| 8 | |
| 9 #include "ash/monitor/monitor_controller.h" | |
| 10 #include "ash/shell.h" | |
| 11 #include "base/logging.h" | |
| 12 #include "base/json/json_value_converter.h" | |
| 13 #include "base/values.h" | |
| 14 #include "chromeos/monitor/output_configurator.h" | |
| 15 #include "content/public/browser/web_ui.h" | |
| 16 #include "grit/generated_resources.h" | |
| 17 #include "ui/aura/env.h" | |
| 18 #include "ui/aura/monitor_manager.h" | |
| 19 #include "ui/base/l10n/l10n_util.h" | |
| 20 #include "ui/gfx/display.h" | |
| 21 #include "ui/gfx/rect.h" | |
| 22 | |
| 23 using ash::internal::MonitorController; | |
| 
oshima
2012/06/21 16:51:56
nit: move this inside namespace
 
Jun Mukai
2012/06/22 01:36:03
Done.
 | |
| 24 | |
| 25 namespace chromeos { | |
| 26 namespace options2 { | |
| 27 | |
| 28 DisplayOptionsHandler::DisplayOptionsHandler() { | |
| 29 aura::Env::GetInstance()->monitor_manager()->AddObserver(this); | |
| 30 } | |
| 31 | |
| 32 DisplayOptionsHandler::~DisplayOptionsHandler() { | |
| 33 aura::Env::GetInstance()->monitor_manager()->RemoveObserver(this); | |
| 34 } | |
| 35 | |
| 36 void DisplayOptionsHandler::GetLocalizedValues( | |
| 37 DictionaryValue* localized_strings) { | |
| 38 DCHECK(localized_strings); | |
| 39 RegisterTitle(localized_strings, "displayOptionsPage", | |
| 40 IDS_OPTIONS_SETTINGS_DISPLAY_OPTIONS_TAB_TITLE); | |
| 41 localized_strings->SetString("startMirroring", l10n_util::GetStringUTF16( | |
| 42 IDS_OPTIONS_SETTINGS_DISPLAY_OPTIONS_START_MIRRORING)); | |
| 43 localized_strings->SetString("stopMirroring", l10n_util::GetStringUTF16( | |
| 44 IDS_OPTIONS_SETTINGS_DISPLAY_OPTIONS_STOP_MIRRORING)); | |
| 45 } | |
| 46 | |
| 47 void DisplayOptionsHandler::InitializeHandler() { | |
| 48 DCHECK(web_ui()); | |
| 49 UpdateDisplaySectionVisibility(); | |
| 50 } | |
| 51 | |
| 52 void DisplayOptionsHandler::RegisterMessages() { | |
| 53 web_ui()->RegisterMessageCallback( | |
| 54 "getDisplayInfo", | |
| 55 base::Bind(&DisplayOptionsHandler::HandleDisplayInfo, | |
| 56 base::Unretained(this))); | |
| 57 web_ui()->RegisterMessageCallback( | |
| 58 "setMirroring", | |
| 59 base::Bind(&DisplayOptionsHandler::HandleMirroring, | |
| 60 base::Unretained(this))); | |
| 61 web_ui()->RegisterMessageCallback( | |
| 62 "setDisplayLayout", | |
| 63 base::Bind(&DisplayOptionsHandler::HandleDisplayLayout, | |
| 64 base::Unretained(this))); | |
| 65 } | |
| 66 | |
| 67 void DisplayOptionsHandler::OnDisplayBoundsChanged( | |
| 68 const gfx::Display& display) { | |
| 69 SendDisplayInfo(); | |
| 70 } | |
| 71 | |
| 72 void DisplayOptionsHandler::OnDisplayAdded(const gfx::Display& new_display) { | |
| 73 UpdateDisplaySectionVisibility(); | |
| 74 SendDisplayInfo(); | |
| 75 } | |
| 76 | |
| 77 void DisplayOptionsHandler::OnDisplayRemoved(const gfx::Display& old_display) { | |
| 78 UpdateDisplaySectionVisibility(); | |
| 79 SendDisplayInfo(); | |
| 80 } | |
| 81 | |
| 82 void DisplayOptionsHandler::UpdateDisplaySectionVisibility() { | |
| 83 MonitorController* monitor_controller = | |
| 84 ash::Shell::GetInstance()->monitor_controller(); | |
| 
oshima
2012/06/21 16:51:56
you don't need this (see below)
 
Jun Mukai
2012/06/22 01:36:03
Done.
 | |
| 85 aura::MonitorManager* monitor_manager = | |
| 86 aura::Env::GetInstance()->monitor_manager(); | |
| 87 chromeos::State output_state = | |
| 88 ash::Shell::GetInstance()->output_configurator()->output_state(); | |
| 89 base::FundamentalValue show_options( | |
| 90 monitor_controller->IsExtendedDesktopEnabled() && | |
| 
oshima
2012/06/21 16:51:56
MonitorController::IsExtendedDesktopEnalbed()
(it'
 
Jun Mukai
2012/06/22 01:36:03
Done.
 | |
| 91 monitor_manager->GetNumDisplays() > 1 && | |
| 92 output_state != chromeos::STATE_INVALID && | |
| 93 output_state != chromeos::STATE_HEADLESS && | |
| 94 output_state != chromeos::STATE_SINGLE); | |
| 95 web_ui()->CallJavascriptFunction( | |
| 96 "options.BrowserOptions.showDisplayOptions", show_options); | |
| 97 } | |
| 98 | |
| 99 void DisplayOptionsHandler::SendDisplayInfo() { | |
| 100 aura::MonitorManager* monitor_manager = | |
| 101 aura::Env::GetInstance()->monitor_manager(); | |
| 102 chromeos::OutputConfigurator* output_configurator = | |
| 103 ash::Shell::GetInstance()->output_configurator(); | |
| 104 base::FundamentalValue mirroring( | |
| 105 output_configurator->output_state() == chromeos::STATE_DUAL_MIRROR); | |
| 106 | |
| 107 base::ListValue displays; | |
| 108 for (size_t i = 0; i < monitor_manager->GetNumDisplays(); ++i) { | |
| 109 const gfx::Display& display = monitor_manager->GetDisplayAt(i); | |
| 110 const gfx::Rect& bounds = display.bounds(); | |
| 111 base::DictionaryValue* js_display = new base::DictionaryValue(); | |
| 112 js_display->SetDouble("id", display.id()); | |
| 113 js_display->SetDouble("x", bounds.x()); | |
| 114 js_display->SetDouble("y", bounds.y()); | |
| 115 js_display->SetDouble("width", bounds.width()); | |
| 116 js_display->SetDouble("height", bounds.height()); | |
| 117 displays.Set(i, js_display); | |
| 118 } | |
| 119 | |
| 120 MonitorController* monitor_controller = | |
| 121 ash::Shell::GetInstance()->monitor_controller(); | |
| 122 base::FundamentalValue layout(static_cast<int>( | |
| 123 monitor_controller->secondary_display_layout())); | |
| 124 | |
| 125 web_ui()->CallJavascriptFunction( | |
| 126 "options.DisplayOptions.setDisplayInfo", | |
| 127 mirroring, displays, layout); | |
| 128 } | |
| 129 | |
| 130 void DisplayOptionsHandler::HandleDisplayInfo( | |
| 131 const base::ListValue* unused_args) { | |
| 132 SendDisplayInfo(); | |
| 133 } | |
| 134 | |
| 135 void DisplayOptionsHandler::HandleMirroring(const base::ListValue* args) { | |
| 136 DCHECK(!args->empty()); | |
| 137 bool is_mirroring = false; | |
| 138 args->GetBoolean(0, &is_mirroring); | |
| 139 // We use 'PRIMARY_ONLY' for non-mirroring state for now. | |
| 140 // TODO(mukai): fix this and support multiple display modes. | |
| 141 chromeos::State new_state = | |
| 142 is_mirroring ? STATE_DUAL_MIRROR : STATE_DUAL_PRIMARY_ONLY; | |
| 143 ash::Shell::GetInstance()->output_configurator()->SetDisplayMode(new_state); | |
| 144 SendDisplayInfo(); | |
| 145 } | |
| 146 | |
| 147 void DisplayOptionsHandler::HandleDisplayLayout(const base::ListValue* args) { | |
| 148 double layout = -1; | |
| 149 if (!args->GetDouble(0, &layout)) { | |
| 150 LOG(ERROR) << "Invalid parameter"; | |
| 151 return; | |
| 152 } | |
| 153 | |
| 
oshima
2012/06/21 16:51:56
does DCHECK_NE(-1, layout) make sense?
 
Jun Mukai
2012/06/22 01:36:03
Then probably nicer to check if the |layout| is va
 | |
| 154 ash::Shell::GetInstance()->monitor_controller()->SetSecondaryDisplayLayout( | |
| 155 static_cast<MonitorController::SecondaryDisplayLayout>(layout)); | |
| 156 SendDisplayInfo(); | |
| 157 } | |
| 158 | |
| 159 } // namespace options2 | |
| 160 } // namespace chromeos | |
| OLD | NEW |