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/multi_display_manager.h" | |
10 #include "ash/display/output_configurator_animation.h" | 11 #include "ash/display/output_configurator_animation.h" |
11 #include "ash/screen_ash.h" | 12 #include "ash/screen_ash.h" |
12 #include "ash/shell.h" | 13 #include "ash/shell.h" |
13 #include "base/bind.h" | 14 #include "base/bind.h" |
14 #include "base/json/json_value_converter.h" | |
15 #include "base/logging.h" | 15 #include "base/logging.h" |
16 #include "base/string_number_conversions.h" | 16 #include "base/string_number_conversions.h" |
17 #include "base/stringprintf.h" | 17 #include "base/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 "chrome/browser/chromeos/display/overscan_calibrator.h" | |
20 #include "chrome/browser/profiles/profile.h" | 21 #include "chrome/browser/profiles/profile.h" |
21 #include "chrome/common/pref_names.h" | 22 #include "chrome/common/pref_names.h" |
22 #include "chromeos/display/output_configurator.h" | 23 #include "chromeos/display/output_configurator.h" |
23 #include "content/public/browser/web_ui.h" | 24 #include "content/public/browser/web_ui.h" |
24 #include "grit/generated_resources.h" | 25 #include "grit/generated_resources.h" |
25 #include "ui/aura/env.h" | 26 #include "ui/aura/env.h" |
26 #include "ui/aura/display_manager.h" | 27 #include "ui/aura/display_manager.h" |
27 #include "ui/base/l10n/l10n_util.h" | 28 #include "ui/base/l10n/l10n_util.h" |
28 #include "ui/gfx/display.h" | 29 #include "ui/gfx/display.h" |
29 #include "ui/gfx/rect.h" | 30 #include "ui/gfx/rect.h" |
(...skipping 18 matching lines...) Expand all Loading... | |
48 localized_strings->SetString("startMirroring", l10n_util::GetStringUTF16( | 49 localized_strings->SetString("startMirroring", l10n_util::GetStringUTF16( |
49 IDS_OPTIONS_SETTINGS_DISPLAY_OPTIONS_START_MIRRORING)); | 50 IDS_OPTIONS_SETTINGS_DISPLAY_OPTIONS_START_MIRRORING)); |
50 localized_strings->SetString("stopMirroring", l10n_util::GetStringUTF16( | 51 localized_strings->SetString("stopMirroring", l10n_util::GetStringUTF16( |
51 IDS_OPTIONS_SETTINGS_DISPLAY_OPTIONS_STOP_MIRRORING)); | 52 IDS_OPTIONS_SETTINGS_DISPLAY_OPTIONS_STOP_MIRRORING)); |
52 localized_strings->SetString("setPrimary", l10n_util::GetStringUTF16( | 53 localized_strings->SetString("setPrimary", l10n_util::GetStringUTF16( |
53 IDS_OPTIONS_SETTINGS_DISPLAY_OPTIONS_SET_PRIMARY)); | 54 IDS_OPTIONS_SETTINGS_DISPLAY_OPTIONS_SET_PRIMARY)); |
54 localized_strings->SetString("applyResult", l10n_util::GetStringUTF16( | 55 localized_strings->SetString("applyResult", l10n_util::GetStringUTF16( |
55 IDS_OPTIONS_SETTINGS_DISPLAY_OPTIONS_APPLY_RESULT)); | 56 IDS_OPTIONS_SETTINGS_DISPLAY_OPTIONS_APPLY_RESULT)); |
56 localized_strings->SetString("resolution", l10n_util::GetStringUTF16( | 57 localized_strings->SetString("resolution", l10n_util::GetStringUTF16( |
57 IDS_OPTIONS_SETTINGS_DISPLAY_OPTIONS_RESOLUTION)); | 58 IDS_OPTIONS_SETTINGS_DISPLAY_OPTIONS_RESOLUTION)); |
59 localized_strings->SetString( | |
60 "startCalibratingOverscan", l10n_util::GetStringUTF16( | |
61 IDS_OPTIONS_SETTINGS_DISPLAY_OPTIONS_START_CALIBRATING_OVERSCAN)); | |
62 localized_strings->SetString( | |
63 "finishCalibratingOverscan", l10n_util::GetStringUTF16( | |
64 IDS_OPTIONS_SETTINGS_DISPLAY_OPTIONS_FINISH_CALIBRATING_OVERSCAN)); | |
65 localized_strings->SetString( | |
66 "clearCalibratingOverscan", l10n_util::GetStringUTF16( | |
67 IDS_OPTIONS_SETTINGS_DISPLAY_OPTIONS_CLEAR_CALIBRATING_OVERSCAN)); | |
58 } | 68 } |
59 | 69 |
60 void DisplayOptionsHandler::InitializePage() { | 70 void DisplayOptionsHandler::InitializePage() { |
61 DCHECK(web_ui()); | 71 DCHECK(web_ui()); |
62 UpdateDisplaySectionVisibility(); | 72 UpdateDisplaySectionVisibility(); |
63 } | 73 } |
64 | 74 |
65 void DisplayOptionsHandler::RegisterMessages() { | 75 void DisplayOptionsHandler::RegisterMessages() { |
66 web_ui()->RegisterMessageCallback( | 76 web_ui()->RegisterMessageCallback( |
67 "getDisplayInfo", | 77 "getDisplayInfo", |
68 base::Bind(&DisplayOptionsHandler::HandleDisplayInfo, | 78 base::Bind(&DisplayOptionsHandler::HandleDisplayInfo, |
69 base::Unretained(this))); | 79 base::Unretained(this))); |
70 web_ui()->RegisterMessageCallback( | 80 web_ui()->RegisterMessageCallback( |
71 "setMirroring", | 81 "setMirroring", |
72 base::Bind(&DisplayOptionsHandler::HandleMirroring, | 82 base::Bind(&DisplayOptionsHandler::HandleMirroring, |
73 base::Unretained(this))); | 83 base::Unretained(this))); |
74 web_ui()->RegisterMessageCallback( | 84 web_ui()->RegisterMessageCallback( |
75 "setPrimary", | 85 "setPrimary", |
76 base::Bind(&DisplayOptionsHandler::HandleSetPrimary, | 86 base::Bind(&DisplayOptionsHandler::HandleSetPrimary, |
77 base::Unretained(this))); | 87 base::Unretained(this))); |
78 web_ui()->RegisterMessageCallback( | 88 web_ui()->RegisterMessageCallback( |
79 "setDisplayLayout", | 89 "setDisplayLayout", |
80 base::Bind(&DisplayOptionsHandler::HandleDisplayLayout, | 90 base::Bind(&DisplayOptionsHandler::HandleDisplayLayout, |
81 base::Unretained(this))); | 91 base::Unretained(this))); |
92 web_ui()->RegisterMessageCallback( | |
93 "startOverscanCalibration", | |
94 base::Bind(&DisplayOptionsHandler::HandleStartOverscanCalibration, | |
95 base::Unretained(this))); | |
96 web_ui()->RegisterMessageCallback( | |
97 "finishOverscanCalibration", | |
98 base::Bind(&DisplayOptionsHandler::HandleFinishOverscanCalibration, | |
99 base::Unretained(this))); | |
100 web_ui()->RegisterMessageCallback( | |
101 "clearOverscanCalibration", | |
102 base::Bind(&DisplayOptionsHandler::HandleClearOverscanCalibration, | |
103 base::Unretained(this))); | |
104 web_ui()->RegisterMessageCallback( | |
105 "updateOverscanCalibration", | |
106 base::Bind(&DisplayOptionsHandler::HandleUpdateOverscanCalibration, | |
107 base::Unretained(this))); | |
82 } | 108 } |
83 | 109 |
84 void DisplayOptionsHandler::OnDisplayBoundsChanged( | 110 void DisplayOptionsHandler::OnDisplayBoundsChanged( |
85 const gfx::Display& display) { | 111 const gfx::Display& display) { |
86 SendDisplayInfo(); | 112 SendDisplayInfo(); |
87 } | 113 } |
88 | 114 |
89 void DisplayOptionsHandler::OnDisplayAdded(const gfx::Display& new_display) { | 115 void DisplayOptionsHandler::OnDisplayAdded(const gfx::Display& new_display) { |
90 UpdateDisplaySectionVisibility(); | 116 UpdateDisplaySectionVisibility(); |
91 SendDisplayInfo(); | 117 SendDisplayInfo(); |
92 } | 118 } |
93 | 119 |
94 void DisplayOptionsHandler::OnDisplayRemoved(const gfx::Display& old_display) { | 120 void DisplayOptionsHandler::OnDisplayRemoved(const gfx::Display& old_display) { |
95 UpdateDisplaySectionVisibility(); | 121 UpdateDisplaySectionVisibility(); |
96 SendDisplayInfo(); | 122 SendDisplayInfo(); |
97 } | 123 } |
98 | 124 |
99 void DisplayOptionsHandler::UpdateDisplaySectionVisibility() { | 125 void DisplayOptionsHandler::UpdateDisplaySectionVisibility() { |
100 chromeos::OutputState output_state = | 126 chromeos::OutputState output_state = |
101 ash::Shell::GetInstance()->output_configurator()->output_state(); | 127 ash::Shell::GetInstance()->output_configurator()->output_state(); |
102 base::FundamentalValue show_options( | 128 base::FundamentalValue show_options( |
103 output_state != chromeos::STATE_INVALID && | 129 output_state != chromeos::STATE_INVALID && |
104 output_state != chromeos::STATE_HEADLESS && | 130 output_state != chromeos::STATE_HEADLESS && |
105 output_state != chromeos::STATE_SINGLE); | 131 output_state != chromeos::STATE_SINGLE); |
106 web_ui()->CallJavascriptFunction( | 132 web_ui()->CallJavascriptFunction( |
107 "options.BrowserOptions.showDisplayOptions", show_options); | 133 "options.BrowserOptions.showDisplayOptions", show_options); |
108 } | 134 } |
109 | 135 |
110 void DisplayOptionsHandler::SendDisplayInfo() { | 136 void DisplayOptionsHandler::SendDisplayInfo() { |
111 aura::DisplayManager* display_manager = | 137 ash::internal::MultiDisplayManager* display_manager = |
oshima
2012/10/19 19:36:11
internal class shouldn't be used by non ash code.
Jun Mukai
2012/10/19 21:39:34
Done. Also I am using GetDisplayForId() below, so
| |
112 aura::Env::GetInstance()->display_manager(); | 138 static_cast<ash::internal::MultiDisplayManager*>( |
139 aura::Env::GetInstance()->display_manager()); | |
113 ash::DisplayController* display_controller = | 140 ash::DisplayController* display_controller = |
114 ash::Shell::GetInstance()->display_controller(); | 141 ash::Shell::GetInstance()->display_controller(); |
115 chromeos::OutputConfigurator* output_configurator = | 142 chromeos::OutputConfigurator* output_configurator = |
116 ash::Shell::GetInstance()->output_configurator(); | 143 ash::Shell::GetInstance()->output_configurator(); |
117 base::FundamentalValue mirroring( | 144 base::FundamentalValue mirroring( |
118 output_configurator->output_state() == chromeos::STATE_DUAL_MIRROR); | 145 output_configurator->output_state() == chromeos::STATE_DUAL_MIRROR); |
119 | 146 |
120 int64 primary_id = ash::Shell::GetScreen()->GetPrimaryDisplay().id(); | 147 int64 primary_id = ash::Shell::GetScreen()->GetPrimaryDisplay().id(); |
121 base::ListValue displays; | 148 base::ListValue displays; |
122 for (size_t i = 0; i < display_manager->GetNumDisplays(); ++i) { | 149 for (size_t i = 0; i < display_manager->GetNumDisplays(); ++i) { |
123 const gfx::Display* display = display_manager->GetDisplayAt(i); | 150 const gfx::Display* display = display_manager->GetDisplayAt(i); |
124 const gfx::Rect& bounds = display->bounds(); | 151 const gfx::Rect& bounds = display->bounds(); |
125 base::DictionaryValue* js_display = new base::DictionaryValue(); | 152 base::DictionaryValue* js_display = new base::DictionaryValue(); |
126 js_display->SetString("id", base::Int64ToString(display->id())); | 153 js_display->SetString("id", base::Int64ToString(display->id())); |
127 js_display->SetDouble("x", bounds.x()); | 154 js_display->SetDouble("x", bounds.x()); |
128 js_display->SetDouble("y", bounds.y()); | 155 js_display->SetDouble("y", bounds.y()); |
129 js_display->SetDouble("width", bounds.width()); | 156 js_display->SetDouble("width", bounds.width()); |
130 js_display->SetDouble("height", bounds.height()); | 157 js_display->SetDouble("height", bounds.height()); |
131 js_display->SetString("name", | 158 js_display->SetString("name", |
132 display_manager->GetDisplayNameFor(*display)); | 159 display_manager->GetDisplayNameFor(*display)); |
133 js_display->SetBoolean("isPrimary", display->id() == primary_id); | 160 js_display->SetBoolean("isPrimary", display->id() == primary_id); |
161 base::DictionaryValue* js_insets = new base::DictionaryValue(); | |
162 const gfx::Insets& insets = | |
163 display_manager->GetOverscanInsets(display->id()); | |
164 js_insets->SetInteger("top", insets.top()); | |
165 js_insets->SetInteger("left", insets.left()); | |
166 js_insets->SetInteger("bottom", insets.bottom()); | |
167 js_insets->SetInteger("right", insets.right()); | |
168 js_display->Set("overscan", js_insets); | |
134 displays.Set(i, js_display); | 169 displays.Set(i, js_display); |
135 } | 170 } |
136 | 171 |
137 scoped_ptr<base::Value> layout_value(base::Value::CreateNullValue()); | 172 scoped_ptr<base::Value> layout_value(base::Value::CreateNullValue()); |
138 scoped_ptr<base::Value> offset_value(base::Value::CreateNullValue()); | 173 scoped_ptr<base::Value> offset_value(base::Value::CreateNullValue()); |
139 if (display_manager->GetNumDisplays() > 1) { | 174 if (display_manager->GetNumDisplays() > 1) { |
140 const gfx::Display secondary_display = | 175 const gfx::Display secondary_display = |
141 ash::ScreenAsh::GetSecondaryDisplay(); | 176 ash::ScreenAsh::GetSecondaryDisplay(); |
142 const ash::DisplayLayout& layout = | 177 const ash::DisplayLayout& layout = |
143 display_controller->GetLayoutForDisplay(secondary_display); | 178 display_controller->GetLayoutForDisplay(secondary_display); |
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
224 DCHECK_LE(ash::DisplayLayout::TOP, layout); | 259 DCHECK_LE(ash::DisplayLayout::TOP, layout); |
225 DCHECK_GE(ash::DisplayLayout::LEFT, layout); | 260 DCHECK_GE(ash::DisplayLayout::LEFT, layout); |
226 ash::Shell::GetInstance()->output_configurator_animation()-> | 261 ash::Shell::GetInstance()->output_configurator_animation()-> |
227 StartFadeOutAnimation(base::Bind( | 262 StartFadeOutAnimation(base::Bind( |
228 &DisplayOptionsHandler::OnFadeOutForDisplayLayoutFinished, | 263 &DisplayOptionsHandler::OnFadeOutForDisplayLayoutFinished, |
229 base::Unretained(this), | 264 base::Unretained(this), |
230 static_cast<int>(layout), | 265 static_cast<int>(layout), |
231 static_cast<int>(offset))); | 266 static_cast<int>(offset))); |
232 } | 267 } |
233 | 268 |
269 void DisplayOptionsHandler::HandleStartOverscanCalibration( | |
270 const base::ListValue* args) { | |
271 int64 display_id = gfx::Display::kInvalidDisplayID; | |
272 std::string id_value; | |
273 if (!args->GetString(0, &id_value)) { | |
274 LOG(ERROR) << "Can't find ID"; | |
275 return; | |
276 } | |
277 if (!base::StringToInt64(id_value, &display_id) || | |
278 display_id == gfx::Display::kInvalidDisplayID) { | |
279 LOG(ERROR) << "Invalid parameter: " << id_value; | |
280 return; | |
281 } | |
282 | |
283 ash::internal::MultiDisplayManager* display_manager = | |
284 static_cast<ash::internal::MultiDisplayManager*>( | |
285 aura::Env::GetInstance()->display_manager()); | |
286 const gfx::Display& display = display_manager->GetDisplayForId(display_id); | |
oshima
2012/10/19 19:36:11
DCHECK(display.is_valid());
Jun Mukai
2012/10/19 21:39:34
Done.
| |
287 gfx::Insets insets = display_manager->GetOverscanInsets(display_id); | |
288 overscan_calibrator_.reset(new OverscanCalibrator(display, insets)); | |
289 } | |
290 | |
291 void DisplayOptionsHandler::HandleFinishOverscanCalibration( | |
292 const base::ListValue* args) { | |
293 DCHECK(overscan_calibrator_.get()); | |
294 overscan_calibrator_->Commit(); | |
295 overscan_calibrator_.reset(); | |
296 SendDisplayInfo(); | |
297 } | |
298 | |
299 void DisplayOptionsHandler::HandleClearOverscanCalibration( | |
300 const base::ListValue* args) { | |
301 DCHECK(overscan_calibrator_.get()); | |
302 overscan_calibrator_->UpdateInsets(gfx::Insets()); | |
303 overscan_calibrator_->Commit(); | |
304 SendDisplayInfo(); | |
305 } | |
306 | |
307 void DisplayOptionsHandler::HandleUpdateOverscanCalibration( | |
308 const base::ListValue* args) { | |
309 DCHECK(overscan_calibrator_.get()); | |
310 double top = 0, left = 0, bottom = 0, right = 0; | |
311 if (!args->GetDouble(0, &top) || !args->GetDouble(1, &left) || | |
312 !args->GetDouble(2, &bottom) || !args->GetDouble(3, &right)) { | |
313 LOG(ERROR) << "Can't find overscan insets data."; | |
314 return; | |
315 } | |
316 | |
317 overscan_calibrator_->UpdateInsets(gfx::Insets(top, left, bottom, right)); | |
318 } | |
319 | |
234 } // namespace options | 320 } // namespace options |
235 } // namespace chromeos | 321 } // namespace chromeos |
OLD | NEW |