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/chromeos/display/display_preferences.h" | 5 #include "chrome/browser/chromeos/display/display_preferences.h" |
6 | 6 |
7 #include <stddef.h> | 7 #include <stddef.h> |
8 | 8 |
9 #include "ash/display/display_layout_store.h" | 9 #include "ash/display/display_layout_store.h" |
10 #include "ash/display/display_manager.h" | 10 #include "ash/display/display_manager.h" |
11 #include "ash/display/display_pref_util.h" | 11 #include "ash/display/display_pref_util.h" |
12 #include "ash/display/display_util.h" | 12 #include "ash/display/display_util.h" |
13 #include "ash/display/json_converter.h" | 13 #include "ash/display/json_converter.h" |
14 #include "ash/shell.h" | 14 #include "ash/shell.h" |
15 #include "base/strings/string16.h" | 15 #include "base/strings/string16.h" |
16 #include "base/strings/string_number_conversions.h" | 16 #include "base/strings/string_number_conversions.h" |
17 #include "base/strings/string_split.h" | 17 #include "base/strings/string_split.h" |
18 #include "base/strings/string_util.h" | 18 #include "base/strings/string_util.h" |
19 #include "base/sys_info.h" | 19 #include "base/sys_info.h" |
20 #include "base/values.h" | 20 #include "base/values.h" |
21 #include "chrome/browser/browser_process.h" | 21 #include "chrome/browser/browser_process.h" |
22 #include "chrome/common/pref_names.h" | 22 #include "chrome/common/pref_names.h" |
23 #include "components/prefs/pref_registry_simple.h" | 23 #include "components/prefs/pref_registry_simple.h" |
24 #include "components/prefs/pref_service.h" | 24 #include "components/prefs/pref_service.h" |
25 #include "components/prefs/scoped_user_pref_update.h" | 25 #include "components/prefs/scoped_user_pref_update.h" |
26 #include "components/user_manager/user_manager.h" | 26 #include "components/user_manager/user_manager.h" |
27 #include "third_party/cros_system_api/dbus/service_constants.h" | 27 #include "third_party/cros_system_api/dbus/service_constants.h" |
28 #include "ui/gfx/display.h" | 28 #include "ui/display/display.h" |
29 #include "ui/gfx/geometry/insets.h" | 29 #include "ui/gfx/geometry/insets.h" |
30 #include "ui/gfx/screen.h" | |
31 #include "url/url_canon.h" | 30 #include "url/url_canon.h" |
32 #include "url/url_util.h" | 31 #include "url/url_util.h" |
33 | 32 |
34 namespace chromeos { | 33 namespace chromeos { |
35 namespace { | 34 namespace { |
36 | 35 |
37 const char kInsetsTopKey[] = "insets_top"; | 36 const char kInsetsTopKey[] = "insets_top"; |
38 const char kInsetsLeftKey[] = "insets_left"; | 37 const char kInsetsLeftKey[] = "insets_left"; |
39 const char kInsetsBottomKey[] = "insets_bottom"; | 38 const char kInsetsBottomKey[] = "insets_bottom"; |
40 const char kInsetsRightKey[] = "insets_right"; | 39 const char kInsetsRightKey[] = "insets_right"; |
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
143 | 142 |
144 void LoadDisplayProperties() { | 143 void LoadDisplayProperties() { |
145 PrefService* local_state = g_browser_process->local_state(); | 144 PrefService* local_state = g_browser_process->local_state(); |
146 const base::DictionaryValue* properties = local_state->GetDictionary( | 145 const base::DictionaryValue* properties = local_state->GetDictionary( |
147 prefs::kDisplayProperties); | 146 prefs::kDisplayProperties); |
148 for (base::DictionaryValue::Iterator it(*properties); | 147 for (base::DictionaryValue::Iterator it(*properties); |
149 !it.IsAtEnd(); it.Advance()) { | 148 !it.IsAtEnd(); it.Advance()) { |
150 const base::DictionaryValue* dict_value = nullptr; | 149 const base::DictionaryValue* dict_value = nullptr; |
151 if (!it.value().GetAsDictionary(&dict_value) || dict_value == nullptr) | 150 if (!it.value().GetAsDictionary(&dict_value) || dict_value == nullptr) |
152 continue; | 151 continue; |
153 int64_t id = gfx::Display::kInvalidDisplayID; | 152 int64_t id = display::Display::kInvalidDisplayID; |
154 if (!base::StringToInt64(it.key(), &id) || | 153 if (!base::StringToInt64(it.key(), &id) || |
155 id == gfx::Display::kInvalidDisplayID) { | 154 id == display::Display::kInvalidDisplayID) { |
156 continue; | 155 continue; |
157 } | 156 } |
158 gfx::Display::Rotation rotation = gfx::Display::ROTATE_0; | 157 display::Display::Rotation rotation = display::Display::ROTATE_0; |
159 float ui_scale = 1.0f; | 158 float ui_scale = 1.0f; |
160 const gfx::Insets* insets_to_set = nullptr; | 159 const gfx::Insets* insets_to_set = nullptr; |
161 | 160 |
162 int rotation_value = 0; | 161 int rotation_value = 0; |
163 if (dict_value->GetInteger("rotation", &rotation_value)) { | 162 if (dict_value->GetInteger("rotation", &rotation_value)) { |
164 rotation = static_cast<gfx::Display::Rotation>(rotation_value); | 163 rotation = static_cast<display::Display::Rotation>(rotation_value); |
165 } | 164 } |
166 int ui_scale_value = 0; | 165 int ui_scale_value = 0; |
167 if (dict_value->GetInteger("ui-scale", &ui_scale_value)) | 166 if (dict_value->GetInteger("ui-scale", &ui_scale_value)) |
168 ui_scale = static_cast<float>(ui_scale_value) / 1000.0f; | 167 ui_scale = static_cast<float>(ui_scale_value) / 1000.0f; |
169 | 168 |
170 int width = 0, height = 0; | 169 int width = 0, height = 0; |
171 dict_value->GetInteger("width", &width); | 170 dict_value->GetInteger("width", &width); |
172 dict_value->GetInteger("height", &height); | 171 dict_value->GetInteger("height", &height); |
173 gfx::Size resolution_in_pixels(width, height); | 172 gfx::Size resolution_in_pixels(width, height); |
174 | 173 |
(...skipping 22 matching lines...) Expand all Loading... |
197 | 196 |
198 void LoadDisplayRotationState() { | 197 void LoadDisplayRotationState() { |
199 PrefService* local_state = g_browser_process->local_state(); | 198 PrefService* local_state = g_browser_process->local_state(); |
200 const base::DictionaryValue* properties = | 199 const base::DictionaryValue* properties = |
201 local_state->GetDictionary(prefs::kDisplayRotationLock); | 200 local_state->GetDictionary(prefs::kDisplayRotationLock); |
202 | 201 |
203 bool rotation_lock = false; | 202 bool rotation_lock = false; |
204 if (!properties->GetBoolean("lock", &rotation_lock)) | 203 if (!properties->GetBoolean("lock", &rotation_lock)) |
205 return; | 204 return; |
206 | 205 |
207 int rotation = gfx::Display::ROTATE_0; | 206 int rotation = display::Display::ROTATE_0; |
208 if (!properties->GetInteger("orientation", &rotation)) | 207 if (!properties->GetInteger("orientation", &rotation)) |
209 return; | 208 return; |
210 | 209 |
211 GetDisplayManager()->RegisterDisplayRotationProperties(rotation_lock, | 210 GetDisplayManager()->RegisterDisplayRotationProperties( |
212 static_cast<gfx::Display::Rotation>(rotation)); | 211 rotation_lock, static_cast<display::Display::Rotation>(rotation)); |
213 } | 212 } |
214 | 213 |
215 void StoreDisplayLayoutPref(const display::DisplayIdList& list, | 214 void StoreDisplayLayoutPref(const display::DisplayIdList& list, |
216 const display::DisplayLayout& display_layout) { | 215 const display::DisplayLayout& display_layout) { |
217 std::string name = ash::DisplayIdListToString(list); | 216 std::string name = ash::DisplayIdListToString(list); |
218 | 217 |
219 PrefService* local_state = g_browser_process->local_state(); | 218 PrefService* local_state = g_browser_process->local_state(); |
220 DictionaryPrefUpdate update(local_state, prefs::kSecondaryDisplays); | 219 DictionaryPrefUpdate update(local_state, prefs::kSecondaryDisplays); |
221 base::DictionaryValue* pref_data = update.Get(); | 220 base::DictionaryValue* pref_data = update.Get(); |
222 std::unique_ptr<base::Value> layout_value(new base::DictionaryValue()); | 221 std::unique_ptr<base::Value> layout_value(new base::DictionaryValue()); |
(...skipping 21 matching lines...) Expand all Loading... |
244 | 243 |
245 void StoreCurrentDisplayProperties() { | 244 void StoreCurrentDisplayProperties() { |
246 ash::DisplayManager* display_manager = GetDisplayManager(); | 245 ash::DisplayManager* display_manager = GetDisplayManager(); |
247 PrefService* local_state = g_browser_process->local_state(); | 246 PrefService* local_state = g_browser_process->local_state(); |
248 | 247 |
249 DictionaryPrefUpdate update(local_state, prefs::kDisplayProperties); | 248 DictionaryPrefUpdate update(local_state, prefs::kDisplayProperties); |
250 base::DictionaryValue* pref_data = update.Get(); | 249 base::DictionaryValue* pref_data = update.Get(); |
251 | 250 |
252 size_t num = display_manager->GetNumDisplays(); | 251 size_t num = display_manager->GetNumDisplays(); |
253 for (size_t i = 0; i < num; ++i) { | 252 for (size_t i = 0; i < num; ++i) { |
254 const gfx::Display& display = display_manager->GetDisplayAt(i); | 253 const display::Display& display = display_manager->GetDisplayAt(i); |
255 int64_t id = display.id(); | 254 int64_t id = display.id(); |
256 ash::DisplayInfo info = display_manager->GetDisplayInfo(id); | 255 ash::DisplayInfo info = display_manager->GetDisplayInfo(id); |
257 | 256 |
258 std::unique_ptr<base::DictionaryValue> property_value( | 257 std::unique_ptr<base::DictionaryValue> property_value( |
259 new base::DictionaryValue()); | 258 new base::DictionaryValue()); |
260 // Don't save the display preference in unified mode because its | 259 // Don't save the display preference in unified mode because its |
261 // size and modes can change depending on the combination of displays. | 260 // size and modes can change depending on the combination of displays. |
262 if (display_manager->IsInUnifiedMode()) | 261 if (display_manager->IsInUnifiedMode()) |
263 continue; | 262 continue; |
264 property_value->SetInteger( | 263 property_value->SetInteger("rotation", |
265 "rotation", | 264 static_cast<int>(info.GetRotation( |
266 static_cast<int>(info.GetRotation(gfx::Display::ROTATION_SOURCE_USER))); | 265 display::Display::ROTATION_SOURCE_USER))); |
267 property_value->SetInteger( | 266 property_value->SetInteger( |
268 "ui-scale", static_cast<int>(info.configured_ui_scale() * 1000)); | 267 "ui-scale", static_cast<int>(info.configured_ui_scale() * 1000)); |
269 | 268 |
270 ash::DisplayMode mode; | 269 ash::DisplayMode mode; |
271 if (!display.IsInternal() && | 270 if (!display.IsInternal() && |
272 display_manager->GetSelectedModeForDisplayId(id, &mode) && | 271 display_manager->GetSelectedModeForDisplayId(id, &mode) && |
273 !mode.native) { | 272 !mode.native) { |
274 property_value->SetInteger("width", mode.size.width()); | 273 property_value->SetInteger("width", mode.size.width()); |
275 property_value->SetInteger("height", mode.size.height()); | 274 property_value->SetInteger("height", mode.size.height()); |
276 property_value->SetInteger( | 275 property_value->SetInteger( |
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
353 if (!UserCanSaveDisplayPreference() || | 352 if (!UserCanSaveDisplayPreference() || |
354 !ash::Shell::GetInstance()->ShouldSaveDisplaySettings()) { | 353 !ash::Shell::GetInstance()->ShouldSaveDisplaySettings()) { |
355 return; | 354 return; |
356 } | 355 } |
357 | 356 |
358 StoreCurrentDisplayLayoutPrefs(); | 357 StoreCurrentDisplayLayoutPrefs(); |
359 StoreCurrentDisplayProperties(); | 358 StoreCurrentDisplayProperties(); |
360 } | 359 } |
361 | 360 |
362 void StoreDisplayRotationPrefs(bool rotation_lock) { | 361 void StoreDisplayRotationPrefs(bool rotation_lock) { |
363 if (!gfx::Display::HasInternalDisplay()) | 362 if (!display::Display::HasInternalDisplay()) |
364 return; | 363 return; |
365 | 364 |
366 PrefService* local_state = g_browser_process->local_state(); | 365 PrefService* local_state = g_browser_process->local_state(); |
367 DictionaryPrefUpdate update(local_state, prefs::kDisplayRotationLock); | 366 DictionaryPrefUpdate update(local_state, prefs::kDisplayRotationLock); |
368 base::DictionaryValue* pref_data = update.Get(); | 367 base::DictionaryValue* pref_data = update.Get(); |
369 pref_data->SetBoolean("lock", rotation_lock); | 368 pref_data->SetBoolean("lock", rotation_lock); |
370 gfx::Display::Rotation rotation = | 369 display::Display::Rotation rotation = |
371 GetDisplayManager() | 370 GetDisplayManager() |
372 ->GetDisplayInfo(gfx::Display::InternalDisplayId()) | 371 ->GetDisplayInfo(display::Display::InternalDisplayId()) |
373 .GetRotation(gfx::Display::ROTATION_SOURCE_ACCELEROMETER); | 372 .GetRotation(display::Display::ROTATION_SOURCE_ACCELEROMETER); |
374 pref_data->SetInteger("orientation", static_cast<int>(rotation)); | 373 pref_data->SetInteger("orientation", static_cast<int>(rotation)); |
375 } | 374 } |
376 | 375 |
377 void LoadDisplayPreferences(bool first_run_after_boot) { | 376 void LoadDisplayPreferences(bool first_run_after_boot) { |
378 LoadDisplayLayouts(); | 377 LoadDisplayLayouts(); |
379 LoadDisplayProperties(); | 378 LoadDisplayProperties(); |
380 LoadDisplayRotationState(); | 379 LoadDisplayRotationState(); |
381 if (!first_run_after_boot) { | 380 if (!first_run_after_boot) { |
382 PrefService* local_state = g_browser_process->local_state(); | 381 PrefService* local_state = g_browser_process->local_state(); |
383 // Restore DisplayPowerState: | 382 // Restore DisplayPowerState: |
(...skipping 11 matching lines...) Expand all Loading... |
395 const display::DisplayLayout& layout) { | 394 const display::DisplayLayout& layout) { |
396 StoreDisplayLayoutPref(list, layout); | 395 StoreDisplayLayoutPref(list, layout); |
397 } | 396 } |
398 | 397 |
399 // Stores the given |power_state|. | 398 // Stores the given |power_state|. |
400 void StoreDisplayPowerStateForTest(DisplayPowerState power_state) { | 399 void StoreDisplayPowerStateForTest(DisplayPowerState power_state) { |
401 StoreDisplayPowerState(power_state); | 400 StoreDisplayPowerState(power_state); |
402 } | 401 } |
403 | 402 |
404 } // namespace chromeos | 403 } // namespace chromeos |
OLD | NEW |