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/output_configurator_animation.h" | 10 #include "ash/display/output_configurator_animation.h" |
11 #include "ash/shell.h" | 11 #include "ash/shell.h" |
12 #include "base/bind.h" | 12 #include "base/bind.h" |
13 #include "base/json/json_value_converter.h" | 13 #include "base/json/json_value_converter.h" |
14 #include "base/logging.h" | 14 #include "base/logging.h" |
15 #include "base/stringprintf.h" | 15 #include "base/stringprintf.h" |
16 #include "base/values.h" | 16 #include "base/values.h" |
17 #include "chrome/browser/prefs/pref_service.h" | 17 #include "chrome/browser/chromeos/display/display_preferences.h" |
18 #include "chrome/browser/profiles/profile.h" | 18 #include "chrome/browser/profiles/profile.h" |
19 #include "chrome/common/pref_names.h" | 19 #include "chrome/common/pref_names.h" |
20 #include "chromeos/display/output_configurator.h" | 20 #include "chromeos/display/output_configurator.h" |
21 #include "content/public/browser/web_ui.h" | 21 #include "content/public/browser/web_ui.h" |
22 #include "grit/generated_resources.h" | 22 #include "grit/generated_resources.h" |
23 #include "ui/aura/env.h" | 23 #include "ui/aura/env.h" |
24 #include "ui/aura/display_manager.h" | 24 #include "ui/aura/display_manager.h" |
25 #include "ui/base/l10n/l10n_util.h" | 25 #include "ui/base/l10n/l10n_util.h" |
26 #include "ui/gfx/display.h" | 26 #include "ui/gfx/display.h" |
27 #include "ui/gfx/rect.h" | 27 #include "ui/gfx/rect.h" |
28 | 28 |
29 namespace chromeos { | 29 namespace chromeos { |
30 namespace options { | 30 namespace options { |
31 | 31 |
32 using ash::internal::DisplayController; | |
33 | |
34 DisplayOptionsHandler::DisplayOptionsHandler() { | 32 DisplayOptionsHandler::DisplayOptionsHandler() { |
35 aura::Env::GetInstance()->display_manager()->AddObserver(this); | 33 aura::Env::GetInstance()->display_manager()->AddObserver(this); |
36 } | 34 } |
37 | 35 |
38 DisplayOptionsHandler::~DisplayOptionsHandler() { | 36 DisplayOptionsHandler::~DisplayOptionsHandler() { |
39 aura::Env::GetInstance()->display_manager()->RemoveObserver(this); | 37 aura::Env::GetInstance()->display_manager()->RemoveObserver(this); |
40 } | 38 } |
41 | 39 |
42 void DisplayOptionsHandler::GetLocalizedValues( | 40 void DisplayOptionsHandler::GetLocalizedValues( |
43 DictionaryValue* localized_strings) { | 41 DictionaryValue* localized_strings) { |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
96 output_state != chromeos::STATE_INVALID && | 94 output_state != chromeos::STATE_INVALID && |
97 output_state != chromeos::STATE_HEADLESS && | 95 output_state != chromeos::STATE_HEADLESS && |
98 output_state != chromeos::STATE_SINGLE); | 96 output_state != chromeos::STATE_SINGLE); |
99 web_ui()->CallJavascriptFunction( | 97 web_ui()->CallJavascriptFunction( |
100 "options.BrowserOptions.showDisplayOptions", show_options); | 98 "options.BrowserOptions.showDisplayOptions", show_options); |
101 } | 99 } |
102 | 100 |
103 void DisplayOptionsHandler::SendDisplayInfo() { | 101 void DisplayOptionsHandler::SendDisplayInfo() { |
104 aura::DisplayManager* display_manager = | 102 aura::DisplayManager* display_manager = |
105 aura::Env::GetInstance()->display_manager(); | 103 aura::Env::GetInstance()->display_manager(); |
| 104 ash::DisplayController* display_controller = |
| 105 ash::Shell::GetInstance()->display_controller(); |
106 chromeos::OutputConfigurator* output_configurator = | 106 chromeos::OutputConfigurator* output_configurator = |
107 ash::Shell::GetInstance()->output_configurator(); | 107 ash::Shell::GetInstance()->output_configurator(); |
108 base::FundamentalValue mirroring( | 108 base::FundamentalValue mirroring( |
109 output_configurator->output_state() == chromeos::STATE_DUAL_MIRROR); | 109 output_configurator->output_state() == chromeos::STATE_DUAL_MIRROR); |
110 | 110 |
111 base::ListValue displays; | 111 base::ListValue displays; |
112 for (size_t i = 0; i < display_manager->GetNumDisplays(); ++i) { | 112 for (size_t i = 0; i < display_manager->GetNumDisplays(); ++i) { |
113 const gfx::Display* display = display_manager->GetDisplayAt(i); | 113 const gfx::Display* display = display_manager->GetDisplayAt(i); |
114 const gfx::Rect& bounds = display->bounds(); | 114 const gfx::Rect& bounds = display->bounds(); |
115 base::DictionaryValue* js_display = new base::DictionaryValue(); | 115 base::DictionaryValue* js_display = new base::DictionaryValue(); |
116 js_display->SetDouble("id", display->id()); | 116 js_display->SetDouble("id", display->id()); |
117 js_display->SetDouble("x", bounds.x()); | 117 js_display->SetDouble("x", bounds.x()); |
118 js_display->SetDouble("y", bounds.y()); | 118 js_display->SetDouble("y", bounds.y()); |
119 js_display->SetDouble("width", bounds.width()); | 119 js_display->SetDouble("width", bounds.width()); |
120 js_display->SetDouble("height", bounds.height()); | 120 js_display->SetDouble("height", bounds.height()); |
121 js_display->SetString("name", display_manager->GetDisplayNameAt(i)); | 121 js_display->SetString("name", display_manager->GetDisplayNameAt(i)); |
122 displays.Set(i, js_display); | 122 displays.Set(i, js_display); |
123 } | 123 } |
124 | 124 |
125 PrefService* pref_service = Profile::FromWebUI(web_ui())->GetPrefs(); | 125 scoped_ptr<base::Value> layout_value(base::Value::CreateNullValue()); |
126 base::FundamentalValue layout( | 126 scoped_ptr<base::Value> offset_value(base::Value::CreateNullValue()); |
127 pref_service->GetInteger(prefs::kSecondaryDisplayLayout)); | 127 if (display_manager->GetNumDisplays() > 1) { |
128 base::FundamentalValue offset( | 128 const std::string& secondary_display_name = |
129 pref_service->GetInteger(prefs::kSecondaryDisplayOffset)); | 129 display_manager->GetDisplayNameAt(1); |
| 130 const ash::DisplayLayout& layout = |
| 131 display_controller->GetLayoutForDisplayName(secondary_display_name); |
| 132 layout_value.reset(new base::FundamentalValue(layout.position)); |
| 133 offset_value.reset(new base::FundamentalValue(layout.offset)); |
| 134 } |
130 | 135 |
131 web_ui()->CallJavascriptFunction( | 136 web_ui()->CallJavascriptFunction( |
132 "options.DisplayOptions.setDisplayInfo", | 137 "options.DisplayOptions.setDisplayInfo", |
133 mirroring, displays, layout, offset); | 138 mirroring, displays, *layout_value.get(), *offset_value.get()); |
134 } | 139 } |
135 | 140 |
136 void DisplayOptionsHandler::FadeOutForMirroringFinished(bool is_mirroring) { | 141 void DisplayOptionsHandler::FadeOutForMirroringFinished(bool is_mirroring) { |
137 // We use 'PRIMARY_ONLY' for non-mirroring state for now. | 142 // We use 'PRIMARY_ONLY' for non-mirroring state for now. |
138 // TODO(mukai): fix this and support multiple display modes. | 143 // TODO(mukai): fix this and support multiple display modes. |
139 chromeos::OutputState new_state = | 144 chromeos::OutputState new_state = |
140 is_mirroring ? STATE_DUAL_MIRROR : STATE_DUAL_PRIMARY_ONLY; | 145 is_mirroring ? STATE_DUAL_MIRROR : STATE_DUAL_PRIMARY_ONLY; |
141 ash::Shell::GetInstance()->output_configurator()->SetDisplayMode(new_state); | 146 ash::Shell::GetInstance()->output_configurator()->SetDisplayMode(new_state); |
142 SendDisplayInfo(); | 147 SendDisplayInfo(); |
143 // Not necessary to start fade-in animation. OutputConfigurator will do that. | 148 // Not necessary to start fade-in animation. OutputConfigurator will do that. |
144 } | 149 } |
145 | 150 |
146 void DisplayOptionsHandler::FadeOutForDisplayLayoutFinished( | 151 void DisplayOptionsHandler::FadeOutForDisplayLayoutFinished( |
147 int layout, int offset) { | 152 int layout, int offset) { |
148 PrefService* pref_service = Profile::FromWebUI(web_ui())->GetPrefs(); | 153 PrefService* pref_service = Profile::FromWebUI(web_ui())->GetPrefs(); |
149 pref_service->SetInteger(prefs::kSecondaryDisplayLayout, layout); | 154 aura::DisplayManager* display_manager = |
150 pref_service->SetInteger(prefs::kSecondaryDisplayOffset, offset); | 155 aura::Env::GetInstance()->display_manager(); |
| 156 // Assumes that there are two displays at most and the second item is the |
| 157 // secondary display. |
| 158 if (display_manager->GetNumDisplays() > 1) { |
| 159 gfx::Display* display = display_manager->GetDisplayAt(1); |
| 160 SetDisplayLayoutPref(pref_service, *display, layout, offset); |
| 161 } |
| 162 |
151 SendDisplayInfo(); | 163 SendDisplayInfo(); |
152 ash::Shell::GetInstance()->output_configurator_animation()-> | 164 ash::Shell::GetInstance()->output_configurator_animation()-> |
153 StartFadeInAnimation(); | 165 StartFadeInAnimation(); |
154 } | 166 } |
155 | 167 |
156 void DisplayOptionsHandler::HandleDisplayInfo( | 168 void DisplayOptionsHandler::HandleDisplayInfo( |
157 const base::ListValue* unused_args) { | 169 const base::ListValue* unused_args) { |
158 SendDisplayInfo(); | 170 SendDisplayInfo(); |
159 } | 171 } |
160 | 172 |
161 void DisplayOptionsHandler::HandleMirroring(const base::ListValue* args) { | 173 void DisplayOptionsHandler::HandleMirroring(const base::ListValue* args) { |
162 DCHECK(!args->empty()); | 174 DCHECK(!args->empty()); |
163 bool is_mirroring = false; | 175 bool is_mirroring = false; |
164 args->GetBoolean(0, &is_mirroring); | 176 args->GetBoolean(0, &is_mirroring); |
165 ash::Shell::GetInstance()->output_configurator_animation()-> | 177 ash::Shell::GetInstance()->output_configurator_animation()-> |
166 StartFadeOutAnimation(base::Bind( | 178 StartFadeOutAnimation(base::Bind( |
167 &DisplayOptionsHandler::FadeOutForMirroringFinished, | 179 &DisplayOptionsHandler::FadeOutForMirroringFinished, |
168 base::Unretained(this), | 180 base::Unretained(this), |
169 is_mirroring)); | 181 is_mirroring)); |
170 } | 182 } |
171 | 183 |
172 void DisplayOptionsHandler::HandleDisplayLayout(const base::ListValue* args) { | 184 void DisplayOptionsHandler::HandleDisplayLayout(const base::ListValue* args) { |
173 double layout = -1; | 185 double layout = -1; |
174 double offset = -1; | 186 double offset = -1; |
175 if (!args->GetDouble(0, &layout) || !args->GetDouble(1, &offset)) { | 187 if (!args->GetDouble(0, &layout) || !args->GetDouble(1, &offset)) { |
176 LOG(ERROR) << "Invalid parameter"; | 188 LOG(ERROR) << "Invalid parameter"; |
177 SendDisplayInfo(); | 189 SendDisplayInfo(); |
178 return; | 190 return; |
179 } | 191 } |
180 DCHECK_LE(DisplayController::TOP, layout); | 192 DCHECK_LE(ash::DisplayLayout::TOP, layout); |
181 DCHECK_GE(DisplayController::LEFT, layout); | 193 DCHECK_GE(ash::DisplayLayout::LEFT, layout); |
182 ash::Shell::GetInstance()->output_configurator_animation()-> | 194 ash::Shell::GetInstance()->output_configurator_animation()-> |
183 StartFadeOutAnimation(base::Bind( | 195 StartFadeOutAnimation(base::Bind( |
184 &DisplayOptionsHandler::FadeOutForDisplayLayoutFinished, | 196 &DisplayOptionsHandler::FadeOutForDisplayLayoutFinished, |
185 base::Unretained(this), | 197 base::Unretained(this), |
186 static_cast<int>(layout), | 198 static_cast<int>(layout), |
187 static_cast<int>(offset))); | 199 static_cast<int>(offset))); |
188 } | 200 } |
189 | 201 |
190 } // namespace options | 202 } // namespace options |
191 } // namespace chromeos | 203 } // namespace chromeos |
OLD | NEW |