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