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/display_manager.h" | 10 #include "ash/display/display_manager.h" |
11 #include "ash/display/output_configurator_animation.h" | 11 #include "ash/display/output_configurator_animation.h" |
12 #include "ash/screen_ash.h" | 12 #include "ash/screen_ash.h" |
13 #include "ash/shell.h" | 13 #include "ash/shell.h" |
14 #include "base/bind.h" | 14 #include "base/bind.h" |
15 #include "base/logging.h" | 15 #include "base/logging.h" |
16 #include "base/stringprintf.h" | 16 #include "base/stringprintf.h" |
17 #include "base/strings/string_number_conversions.h" | 17 #include "base/strings/string_number_conversions.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 "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/base/l10n/l10n_util.h" | 23 #include "ui/base/l10n/l10n_util.h" |
24 #include "ui/gfx/display.h" | 24 #include "ui/gfx/display.h" |
25 #include "ui/gfx/rect.h" | 25 #include "ui/gfx/rect.h" |
| 26 #include "ui/gfx/safe_integer_conversions.h" |
26 #include "ui/gfx/screen.h" | 27 #include "ui/gfx/screen.h" |
27 | 28 |
28 using ash::internal::DisplayManager; | 29 using ash::internal::DisplayManager; |
29 | 30 |
30 namespace chromeos { | 31 namespace chromeos { |
31 namespace options { | 32 namespace options { |
32 namespace { | 33 namespace { |
33 | 34 |
34 DisplayManager* GetDisplayManager() { | 35 DisplayManager* GetDisplayManager() { |
35 return ash::Shell::GetInstance()->display_manager(); | 36 return ash::Shell::GetInstance()->display_manager(); |
36 } | 37 } |
37 | 38 |
| 39 int64 GetDisplayId(const base::ListValue* args) { |
| 40 // Assumes the display id is specified as the first argument. |
| 41 std::string id_value; |
| 42 if (!args->GetString(0, &id_value)) { |
| 43 LOG(ERROR) << "Can't find ID"; |
| 44 return gfx::Display::kInvalidDisplayID; |
| 45 } |
| 46 |
| 47 int64 display_id = gfx::Display::kInvalidDisplayID; |
| 48 if (!base::StringToInt64(id_value, &display_id)) { |
| 49 LOG(ERROR) << "Invalid display id: " << id_value; |
| 50 return gfx::Display::kInvalidDisplayID; |
| 51 } |
| 52 |
| 53 return display_id; |
| 54 } |
| 55 |
38 } // namespace | 56 } // namespace |
39 | 57 |
40 DisplayOptionsHandler::DisplayOptionsHandler() { | 58 DisplayOptionsHandler::DisplayOptionsHandler() { |
41 ash::Shell::GetInstance()->display_controller()->AddObserver(this); | 59 ash::Shell::GetInstance()->display_controller()->AddObserver(this); |
42 } | 60 } |
43 | 61 |
44 DisplayOptionsHandler::~DisplayOptionsHandler() { | 62 DisplayOptionsHandler::~DisplayOptionsHandler() { |
45 ash::Shell::GetInstance()->display_controller()->RemoveObserver(this); | 63 ash::Shell::GetInstance()->display_controller()->RemoveObserver(this); |
46 } | 64 } |
47 | 65 |
48 void DisplayOptionsHandler::GetLocalizedValues( | 66 void DisplayOptionsHandler::GetLocalizedValues( |
49 DictionaryValue* localized_strings) { | 67 DictionaryValue* localized_strings) { |
50 DCHECK(localized_strings); | 68 DCHECK(localized_strings); |
51 RegisterTitle(localized_strings, "displayOptionsPage", | 69 RegisterTitle(localized_strings, "displayOptionsPage", |
52 IDS_OPTIONS_SETTINGS_DISPLAY_OPTIONS_TAB_TITLE); | 70 IDS_OPTIONS_SETTINGS_DISPLAY_OPTIONS_TAB_TITLE); |
| 71 |
| 72 localized_strings->SetString( |
| 73 "selectedDisplayTitleOptions", l10n_util::GetStringUTF16( |
| 74 IDS_OPTIONS_SETTINGS_DISPLAY_OPTIONS_OPTIONS)); |
| 75 localized_strings->SetString( |
| 76 "selectedDisplayTitleResolution", l10n_util::GetStringUTF16( |
| 77 IDS_OPTIONS_SETTINGS_DISPLAY_OPTIONS_RESOLUTION)); |
| 78 localized_strings->SetString( |
| 79 "selectedDisplayTitleOrientation", l10n_util::GetStringUTF16( |
| 80 IDS_OPTIONS_SETTINGS_DISPLAY_OPTIONS_ORIENTATION)); |
| 81 localized_strings->SetString( |
| 82 "selectedDisplayTitleOverscan", l10n_util::GetStringUTF16( |
| 83 IDS_OPTIONS_SETTINGS_DISPLAY_OPTIONS_OVERSCAN)); |
| 84 |
53 localized_strings->SetString("startMirroring", l10n_util::GetStringUTF16( | 85 localized_strings->SetString("startMirroring", l10n_util::GetStringUTF16( |
54 IDS_OPTIONS_SETTINGS_DISPLAY_OPTIONS_START_MIRRORING)); | 86 IDS_OPTIONS_SETTINGS_DISPLAY_OPTIONS_START_MIRRORING)); |
55 localized_strings->SetString("stopMirroring", l10n_util::GetStringUTF16( | 87 localized_strings->SetString("stopMirroring", l10n_util::GetStringUTF16( |
56 IDS_OPTIONS_SETTINGS_DISPLAY_OPTIONS_STOP_MIRRORING)); | 88 IDS_OPTIONS_SETTINGS_DISPLAY_OPTIONS_STOP_MIRRORING)); |
| 89 localized_strings->SetString("mirroringDisplay", l10n_util::GetStringUTF16( |
| 90 IDS_OPTIONS_SETTINGS_DISPLAY_OPTIONS_MIRRORING_DISPLAY_NAME)); |
57 localized_strings->SetString("setPrimary", l10n_util::GetStringUTF16( | 91 localized_strings->SetString("setPrimary", l10n_util::GetStringUTF16( |
58 IDS_OPTIONS_SETTINGS_DISPLAY_OPTIONS_SET_PRIMARY)); | 92 IDS_OPTIONS_SETTINGS_DISPLAY_OPTIONS_SET_PRIMARY)); |
59 localized_strings->SetString("applyResult", l10n_util::GetStringUTF16( | 93 localized_strings->SetString("annotateBest", l10n_util::GetStringUTF16( |
60 IDS_OPTIONS_SETTINGS_DISPLAY_OPTIONS_APPLY_RESULT)); | 94 IDS_OPTIONS_SETTINGS_DISPLAY_OPTIONS_RESOLUTION_ANNOTATION_BEST)); |
61 localized_strings->SetString("resolution", l10n_util::GetStringUTF16( | 95 localized_strings->SetString("orientation0", l10n_util::GetStringUTF16( |
62 IDS_OPTIONS_SETTINGS_DISPLAY_OPTIONS_RESOLUTION)); | 96 IDS_OPTIONS_SETTINGS_DISPLAY_OPTIONS_STANDARD_ORIENTATION)); |
63 localized_strings->SetString( | 97 localized_strings->SetString("orientation90", l10n_util::GetStringUTF16( |
64 "startCalibratingOverscan", l10n_util::GetStringUTF16( | 98 IDS_OPTIONS_SETTINGS_DISPLAY_OPTIONS_ORIENTATION_90)); |
65 IDS_OPTIONS_SETTINGS_DISPLAY_OPTIONS_START_CALIBRATING_OVERSCAN)); | 99 localized_strings->SetString("orientation180", l10n_util::GetStringUTF16( |
| 100 IDS_OPTIONS_SETTINGS_DISPLAY_OPTIONS_ORIENTATION_180)); |
| 101 localized_strings->SetString("orientation270", l10n_util::GetStringUTF16( |
| 102 IDS_OPTIONS_SETTINGS_DISPLAY_OPTIONS_ORIENTATION_270)); |
| 103 localized_strings->SetString( |
| 104 "startCalibratingOverscan", l10n_util::GetStringUTF16( |
| 105 IDS_OPTIONS_SETTINGS_DISPLAY_OPTIONS_START_CALIBRATING_OVERSCAN)); |
66 } | 106 } |
67 | 107 |
68 void DisplayOptionsHandler::InitializePage() { | 108 void DisplayOptionsHandler::InitializePage() { |
69 DCHECK(web_ui()); | 109 DCHECK(web_ui()); |
70 UpdateDisplaySectionVisibility(); | |
71 } | 110 } |
72 | 111 |
73 void DisplayOptionsHandler::RegisterMessages() { | 112 void DisplayOptionsHandler::RegisterMessages() { |
74 web_ui()->RegisterMessageCallback( | 113 web_ui()->RegisterMessageCallback( |
75 "getDisplayInfo", | 114 "getDisplayInfo", |
76 base::Bind(&DisplayOptionsHandler::HandleDisplayInfo, | 115 base::Bind(&DisplayOptionsHandler::HandleDisplayInfo, |
77 base::Unretained(this))); | 116 base::Unretained(this))); |
78 web_ui()->RegisterMessageCallback( | 117 web_ui()->RegisterMessageCallback( |
79 "setMirroring", | 118 "setMirroring", |
80 base::Bind(&DisplayOptionsHandler::HandleMirroring, | 119 base::Bind(&DisplayOptionsHandler::HandleMirroring, |
81 base::Unretained(this))); | 120 base::Unretained(this))); |
82 web_ui()->RegisterMessageCallback( | 121 web_ui()->RegisterMessageCallback( |
83 "setPrimary", | 122 "setPrimary", |
84 base::Bind(&DisplayOptionsHandler::HandleSetPrimary, | 123 base::Bind(&DisplayOptionsHandler::HandleSetPrimary, |
85 base::Unretained(this))); | 124 base::Unretained(this))); |
86 web_ui()->RegisterMessageCallback( | 125 web_ui()->RegisterMessageCallback( |
87 "setDisplayLayout", | 126 "setDisplayLayout", |
88 base::Bind(&DisplayOptionsHandler::HandleDisplayLayout, | 127 base::Bind(&DisplayOptionsHandler::HandleDisplayLayout, |
89 base::Unretained(this))); | 128 base::Unretained(this))); |
| 129 web_ui()->RegisterMessageCallback( |
| 130 "setUIScale", |
| 131 base::Bind(&DisplayOptionsHandler::HandleSetUIScale, |
| 132 base::Unretained(this))); |
| 133 web_ui()->RegisterMessageCallback( |
| 134 "setOrientation", |
| 135 base::Bind(&DisplayOptionsHandler::HandleSetOrientation, |
| 136 base::Unretained(this))); |
90 } | 137 } |
91 | 138 |
92 void DisplayOptionsHandler::OnDisplayConfigurationChanging() { | 139 void DisplayOptionsHandler::OnDisplayConfigurationChanging() { |
93 } | 140 } |
94 | 141 |
95 void DisplayOptionsHandler::OnDisplayConfigurationChanged() { | 142 void DisplayOptionsHandler::OnDisplayConfigurationChanged() { |
96 UpdateDisplaySectionVisibility(); | |
97 SendAllDisplayInfo(); | 143 SendAllDisplayInfo(); |
98 } | 144 } |
99 | 145 |
100 void DisplayOptionsHandler::UpdateDisplaySectionVisibility() { | |
101 DisplayManager* display_manager = GetDisplayManager(); | |
102 size_t num_displays = display_manager->num_connected_displays(); | |
103 base::FundamentalValue show_options( | |
104 num_displays > 1 || !display_manager->HasInternalDisplay()); | |
105 web_ui()->CallJavascriptFunction( | |
106 "options.BrowserOptions.showDisplayOptions", show_options); | |
107 } | |
108 | |
109 void DisplayOptionsHandler::SendAllDisplayInfo() { | 146 void DisplayOptionsHandler::SendAllDisplayInfo() { |
110 DisplayManager* display_manager = GetDisplayManager(); | 147 DisplayManager* display_manager = GetDisplayManager(); |
111 | 148 |
112 std::vector<const gfx::Display*> displays; | 149 std::vector<const gfx::Display*> displays; |
113 for (size_t i = 0; i < display_manager->GetNumDisplays(); ++i) { | 150 for (size_t i = 0; i < display_manager->GetNumDisplays(); ++i) { |
114 displays.push_back(display_manager->GetDisplayAt(i)); | 151 displays.push_back(display_manager->GetDisplayAt(i)); |
115 } | 152 } |
116 SendDisplayInfo(displays); | 153 SendDisplayInfo(displays); |
117 } | 154 } |
118 | 155 |
119 void DisplayOptionsHandler::SendDisplayInfo( | 156 void DisplayOptionsHandler::SendDisplayInfo( |
120 const std::vector<const gfx::Display*> displays) { | 157 const std::vector<const gfx::Display*> displays) { |
121 DisplayManager* display_manager = GetDisplayManager(); | 158 DisplayManager* display_manager = GetDisplayManager(); |
122 ash::DisplayController* display_controller = | 159 ash::DisplayController* display_controller = |
123 ash::Shell::GetInstance()->display_controller(); | 160 ash::Shell::GetInstance()->display_controller(); |
124 chromeos::OutputConfigurator* output_configurator = | 161 chromeos::OutputConfigurator* output_configurator = |
125 ash::Shell::GetInstance()->output_configurator(); | 162 ash::Shell::GetInstance()->output_configurator(); |
126 base::FundamentalValue mirroring( | 163 base::FundamentalValue mirroring( |
127 output_configurator->output_state() == chromeos::STATE_DUAL_MIRROR); | 164 output_configurator->output_state() == chromeos::STATE_DUAL_MIRROR); |
128 | 165 |
129 int64 primary_id = ash::Shell::GetScreen()->GetPrimaryDisplay().id(); | 166 int64 primary_id = ash::Shell::GetScreen()->GetPrimaryDisplay().id(); |
130 base::ListValue display_info; | 167 base::ListValue js_displays; |
131 for (size_t i = 0; i < displays.size(); ++i) { | 168 for (size_t i = 0; i < displays.size(); ++i) { |
132 const gfx::Display* display = displays[i]; | 169 const gfx::Display* display = displays[i]; |
| 170 const ash::internal::DisplayInfo& display_info = |
| 171 display_manager->GetDisplayInfo(display->id()); |
133 const gfx::Rect& bounds = display->bounds(); | 172 const gfx::Rect& bounds = display->bounds(); |
134 base::DictionaryValue* js_display = new base::DictionaryValue(); | 173 base::DictionaryValue* js_display = new base::DictionaryValue(); |
135 js_display->SetString("id", base::Int64ToString(display->id())); | 174 js_display->SetString("id", base::Int64ToString(display->id())); |
136 js_display->SetDouble("x", bounds.x()); | 175 js_display->SetInteger("x", bounds.x()); |
137 js_display->SetDouble("y", bounds.y()); | 176 js_display->SetInteger("y", bounds.y()); |
138 js_display->SetDouble("width", bounds.width()); | 177 js_display->SetInteger("width", bounds.width()); |
139 js_display->SetDouble("height", bounds.height()); | 178 js_display->SetInteger("height", bounds.height()); |
140 js_display->SetString("name", | 179 js_display->SetString("name", |
141 display_manager->GetDisplayNameForId(display->id())); | 180 display_manager->GetDisplayNameForId(display->id())); |
142 js_display->SetBoolean("isPrimary", display->id() == primary_id); | 181 js_display->SetBoolean("isPrimary", display->id() == primary_id); |
143 js_display->SetBoolean("isInternal", display->IsInternal()); | 182 js_display->SetBoolean("isInternal", display->IsInternal()); |
144 display_info.Set(i, js_display); | 183 js_display->SetInteger("orientation", |
| 184 static_cast<int>(display_info.rotation())); |
| 185 std::vector<float> ui_scales = DisplayManager::GetScalesForDisplay( |
| 186 display_info); |
| 187 base::ListValue* js_scales = new base::ListValue(); |
| 188 gfx::SizeF base_size = display_info.bounds_in_pixel().size(); |
| 189 base_size.Scale(1.0f / display->device_scale_factor()); |
| 190 if (display_info.rotation() == gfx::Display::ROTATE_90 || |
| 191 display_info.rotation() == gfx::Display::ROTATE_270) { |
| 192 float tmp = base_size.width(); |
| 193 base_size.set_width(base_size.height()); |
| 194 base_size.set_height(tmp); |
| 195 } |
| 196 |
| 197 for (size_t i = 0; i < ui_scales.size(); ++i) { |
| 198 base::DictionaryValue* scale_info = new base::DictionaryValue(); |
| 199 scale_info->SetDouble("scale", ui_scales[i]); |
| 200 scale_info->SetInteger( |
| 201 "width", gfx::ToFlooredInt(base_size.width() * ui_scales[i])); |
| 202 scale_info->SetInteger( |
| 203 "height", gfx::ToFlooredInt(base_size.height() * ui_scales[i])); |
| 204 scale_info->SetBoolean("selected", |
| 205 display_info.ui_scale() == ui_scales[i]); |
| 206 js_scales->Append(scale_info); |
| 207 } |
| 208 js_display->Set("uiScales", js_scales); |
| 209 js_displays.Append(js_display); |
145 } | 210 } |
146 | 211 |
147 scoped_ptr<base::Value> layout_value(base::Value::CreateNullValue()); | 212 scoped_ptr<base::Value> layout_value(base::Value::CreateNullValue()); |
148 scoped_ptr<base::Value> offset_value(base::Value::CreateNullValue()); | 213 scoped_ptr<base::Value> offset_value(base::Value::CreateNullValue()); |
149 if (display_manager->GetNumDisplays() > 1) { | 214 if (display_manager->GetNumDisplays() > 1) { |
150 const ash::DisplayLayout layout = | 215 const ash::DisplayLayout layout = |
151 display_controller->GetCurrentDisplayLayout(); | 216 display_controller->GetCurrentDisplayLayout(); |
152 layout_value.reset(new base::FundamentalValue(layout.position)); | 217 layout_value.reset(new base::FundamentalValue(layout.position)); |
153 offset_value.reset(new base::FundamentalValue(layout.offset)); | 218 offset_value.reset(new base::FundamentalValue(layout.offset)); |
154 } | 219 } |
155 | 220 |
156 web_ui()->CallJavascriptFunction( | 221 web_ui()->CallJavascriptFunction( |
157 "options.DisplayOptions.setDisplayInfo", | 222 "options.DisplayOptions.setDisplayInfo", |
158 mirroring, display_info, *layout_value.get(), *offset_value.get()); | 223 mirroring, js_displays, *layout_value.get(), *offset_value.get()); |
159 } | 224 } |
160 | 225 |
161 void DisplayOptionsHandler::OnFadeOutForMirroringFinished(bool is_mirroring) { | 226 void DisplayOptionsHandler::OnFadeOutForMirroringFinished(bool is_mirroring) { |
162 chromeos::OutputState new_state = | 227 chromeos::OutputState new_state = |
163 is_mirroring ? STATE_DUAL_MIRROR : STATE_DUAL_EXTENDED; | 228 is_mirroring ? STATE_DUAL_MIRROR : STATE_DUAL_EXTENDED; |
164 ash::Shell::GetInstance()->output_configurator()->SetDisplayMode(new_state); | 229 ash::Shell::GetInstance()->output_configurator()->SetDisplayMode(new_state); |
165 // Not necessary to start fade-in animation. OutputConfigurator will do that. | 230 // Not necessary to start fade-in animation. OutputConfigurator will do that. |
166 } | 231 } |
167 | 232 |
168 void DisplayOptionsHandler::OnFadeOutForDisplayLayoutFinished( | 233 void DisplayOptionsHandler::OnFadeOutForDisplayLayoutFinished( |
(...skipping 15 matching lines...) Expand all Loading... |
184 args->GetBoolean(0, &is_mirroring); | 249 args->GetBoolean(0, &is_mirroring); |
185 ash::Shell::GetInstance()->output_configurator_animation()-> | 250 ash::Shell::GetInstance()->output_configurator_animation()-> |
186 StartFadeOutAnimation(base::Bind( | 251 StartFadeOutAnimation(base::Bind( |
187 &DisplayOptionsHandler::OnFadeOutForMirroringFinished, | 252 &DisplayOptionsHandler::OnFadeOutForMirroringFinished, |
188 base::Unretained(this), | 253 base::Unretained(this), |
189 is_mirroring)); | 254 is_mirroring)); |
190 } | 255 } |
191 | 256 |
192 void DisplayOptionsHandler::HandleSetPrimary(const base::ListValue* args) { | 257 void DisplayOptionsHandler::HandleSetPrimary(const base::ListValue* args) { |
193 DCHECK(!args->empty()); | 258 DCHECK(!args->empty()); |
| 259 int display_id = GetDisplayId(args); |
| 260 if (display_id == gfx::Display::kInvalidDisplayID) |
| 261 return; |
194 | 262 |
195 int64 display_id = gfx::Display::kInvalidDisplayID; | |
196 std::string id_value; | |
197 if (!args->GetString(0, &id_value)) { | |
198 LOG(ERROR) << "Can't find ID"; | |
199 return; | |
200 } | |
201 | |
202 if (!base::StringToInt64(id_value, &display_id) || | |
203 display_id == gfx::Display::kInvalidDisplayID) { | |
204 LOG(ERROR) << "Invalid parameter: " << id_value; | |
205 return; | |
206 } | |
207 ash::Shell::GetInstance()->display_controller()-> | 263 ash::Shell::GetInstance()->display_controller()-> |
208 SetPrimaryDisplayId(display_id); | 264 SetPrimaryDisplayId(display_id); |
209 } | 265 } |
210 | 266 |
211 void DisplayOptionsHandler::HandleDisplayLayout(const base::ListValue* args) { | 267 void DisplayOptionsHandler::HandleDisplayLayout(const base::ListValue* args) { |
212 double layout = -1; | 268 double layout = -1; |
213 double offset = -1; | 269 double offset = -1; |
214 if (!args->GetDouble(0, &layout) || !args->GetDouble(1, &offset)) { | 270 if (!args->GetDouble(0, &layout) || !args->GetDouble(1, &offset)) { |
215 LOG(ERROR) << "Invalid parameter"; | 271 LOG(ERROR) << "Invalid parameter"; |
216 SendAllDisplayInfo(); | 272 SendAllDisplayInfo(); |
217 return; | 273 return; |
218 } | 274 } |
219 DCHECK_LE(ash::DisplayLayout::TOP, layout); | 275 DCHECK_LE(ash::DisplayLayout::TOP, layout); |
220 DCHECK_GE(ash::DisplayLayout::LEFT, layout); | 276 DCHECK_GE(ash::DisplayLayout::LEFT, layout); |
221 ash::Shell::GetInstance()->output_configurator_animation()-> | 277 ash::Shell::GetInstance()->output_configurator_animation()-> |
222 StartFadeOutAnimation(base::Bind( | 278 StartFadeOutAnimation(base::Bind( |
223 &DisplayOptionsHandler::OnFadeOutForDisplayLayoutFinished, | 279 &DisplayOptionsHandler::OnFadeOutForDisplayLayoutFinished, |
224 base::Unretained(this), | 280 base::Unretained(this), |
225 static_cast<int>(layout), | 281 static_cast<int>(layout), |
226 static_cast<int>(offset))); | 282 static_cast<int>(offset))); |
227 } | 283 } |
228 | 284 |
| 285 void DisplayOptionsHandler::HandleSetUIScale(const base::ListValue* args) { |
| 286 DCHECK(!args->empty()); |
| 287 |
| 288 int64 display_id = GetDisplayId(args); |
| 289 if (display_id == gfx::Display::kInvalidDisplayID) |
| 290 return; |
| 291 |
| 292 std::string ui_scale_value; |
| 293 double ui_scale = 0.0f; |
| 294 if (!args->GetString(1, &ui_scale_value)) { |
| 295 LOG(ERROR) << "Ca't find new ui_scale"; |
| 296 return; |
| 297 } |
| 298 if (!base::StringToDouble(ui_scale_value, &ui_scale)) { |
| 299 LOG(ERROR) << "Invalid ui_scale: " << ui_scale_value; |
| 300 return; |
| 301 } |
| 302 |
| 303 GetDisplayManager()->SetDisplayUIScale(display_id, ui_scale); |
| 304 } |
| 305 |
| 306 void DisplayOptionsHandler::HandleSetOrientation(const base::ListValue* args) { |
| 307 DCHECK(!args->empty()); |
| 308 |
| 309 int64 display_id = GetDisplayId(args); |
| 310 if (display_id == gfx::Display::kInvalidDisplayID) |
| 311 return; |
| 312 |
| 313 std::string rotation_value; |
| 314 gfx::Display::Rotation new_rotation = gfx::Display::ROTATE_0; |
| 315 if (!args->GetString(1, &rotation_value)) { |
| 316 LOG(ERROR) << "Can't find new orientation"; |
| 317 return; |
| 318 } |
| 319 if (rotation_value == "90") |
| 320 new_rotation = gfx::Display::ROTATE_90; |
| 321 else if (rotation_value == "180") |
| 322 new_rotation = gfx::Display::ROTATE_180; |
| 323 else if (rotation_value == "270") |
| 324 new_rotation = gfx::Display::ROTATE_270; |
| 325 else if (rotation_value != "0") |
| 326 LOG(ERROR) << "Invalid rotation: " << rotation_value << " Falls back to 0"; |
| 327 |
| 328 GetDisplayManager()->SetDisplayRotation(display_id, new_rotation); |
| 329 } |
| 330 |
229 } // namespace options | 331 } // namespace options |
230 } // namespace chromeos | 332 } // namespace chromeos |
OLD | NEW |