| 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" |
| (...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 127 std::vector<std::string> ids = base::SplitString( | 127 std::vector<std::string> ids = base::SplitString( |
| 128 it.key(), ",", base::TRIM_WHITESPACE, base::SPLIT_WANT_ALL); | 128 it.key(), ",", base::TRIM_WHITESPACE, base::SPLIT_WANT_ALL); |
| 129 int64_t id1 = gfx::Display::kInvalidDisplayID; | 129 int64_t id1 = gfx::Display::kInvalidDisplayID; |
| 130 int64_t id2 = gfx::Display::kInvalidDisplayID; | 130 int64_t id2 = gfx::Display::kInvalidDisplayID; |
| 131 if (!base::StringToInt64(ids[0], &id1) || | 131 if (!base::StringToInt64(ids[0], &id1) || |
| 132 !base::StringToInt64(ids[1], &id2) || | 132 !base::StringToInt64(ids[1], &id2) || |
| 133 id1 == gfx::Display::kInvalidDisplayID || | 133 id1 == gfx::Display::kInvalidDisplayID || |
| 134 id2 == gfx::Display::kInvalidDisplayID) { | 134 id2 == gfx::Display::kInvalidDisplayID) { |
| 135 continue; | 135 continue; |
| 136 } | 136 } |
| 137 layout_store->RegisterLayoutForDisplayIdPair(id1, id2, layout); | 137 layout_store->RegisterLayoutForDisplayIdList(id1, id2, layout); |
| 138 } | 138 } |
| 139 } | 139 } |
| 140 } | 140 } |
| 141 | 141 |
| 142 void LoadDisplayProperties() { | 142 void LoadDisplayProperties() { |
| 143 PrefService* local_state = g_browser_process->local_state(); | 143 PrefService* local_state = g_browser_process->local_state(); |
| 144 const base::DictionaryValue* properties = local_state->GetDictionary( | 144 const base::DictionaryValue* properties = local_state->GetDictionary( |
| 145 prefs::kDisplayProperties); | 145 prefs::kDisplayProperties); |
| 146 for (base::DictionaryValue::Iterator it(*properties); | 146 for (base::DictionaryValue::Iterator it(*properties); |
| 147 !it.IsAtEnd(); it.Advance()) { | 147 !it.IsAtEnd(); it.Advance()) { |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 203 return; | 203 return; |
| 204 | 204 |
| 205 int rotation = gfx::Display::ROTATE_0; | 205 int rotation = gfx::Display::ROTATE_0; |
| 206 if (!properties->GetInteger("orientation", &rotation)) | 206 if (!properties->GetInteger("orientation", &rotation)) |
| 207 return; | 207 return; |
| 208 | 208 |
| 209 GetDisplayManager()->RegisterDisplayRotationProperties(rotation_lock, | 209 GetDisplayManager()->RegisterDisplayRotationProperties(rotation_lock, |
| 210 static_cast<gfx::Display::Rotation>(rotation)); | 210 static_cast<gfx::Display::Rotation>(rotation)); |
| 211 } | 211 } |
| 212 | 212 |
| 213 void StoreDisplayLayoutPref(const ash::DisplayIdPair& pair, | 213 void StoreDisplayLayoutPref(const ash::DisplayIdList& list, |
| 214 const ash::DisplayLayout& display_layout) { | 214 const ash::DisplayLayout& display_layout) { |
| 215 std::string name = | 215 std::string name = ash::DisplayIdListToString(list); |
| 216 base::Int64ToString(pair.first) + "," + base::Int64ToString(pair.second); | |
| 217 | 216 |
| 218 PrefService* local_state = g_browser_process->local_state(); | 217 PrefService* local_state = g_browser_process->local_state(); |
| 219 DictionaryPrefUpdate update(local_state, prefs::kSecondaryDisplays); | 218 DictionaryPrefUpdate update(local_state, prefs::kSecondaryDisplays); |
| 220 base::DictionaryValue* pref_data = update.Get(); | 219 base::DictionaryValue* pref_data = update.Get(); |
| 221 scoped_ptr<base::Value> layout_value(new base::DictionaryValue()); | 220 scoped_ptr<base::Value> layout_value(new base::DictionaryValue()); |
| 222 if (pref_data->HasKey(name)) { | 221 if (pref_data->HasKey(name)) { |
| 223 base::Value* value = NULL; | 222 base::Value* value = NULL; |
| 224 if (pref_data->Get(name, &value) && value != NULL) | 223 if (pref_data->Get(name, &value) && value != NULL) |
| 225 layout_value.reset(value->DeepCopy()); | 224 layout_value.reset(value->DeepCopy()); |
| 226 } | 225 } |
| 227 if (ash::DisplayLayout::ConvertToValue(display_layout, layout_value.get())) | 226 if (ash::DisplayLayout::ConvertToValue(display_layout, layout_value.get())) |
| 228 pref_data->Set(name, layout_value.release()); | 227 pref_data->Set(name, layout_value.release()); |
| 229 } | 228 } |
| 230 | 229 |
| 231 void StoreCurrentDisplayLayoutPrefs() { | 230 void StoreCurrentDisplayLayoutPrefs() { |
| 232 ash::DisplayManager* display_manager = GetDisplayManager(); | 231 ash::DisplayManager* display_manager = GetDisplayManager(); |
| 233 if (!UserCanSaveDisplayPreference() || | 232 if (!UserCanSaveDisplayPreference() || |
| 234 display_manager->num_connected_displays() < 2) { | 233 display_manager->num_connected_displays() < 2) { |
| 235 return; | 234 return; |
| 236 } | 235 } |
| 237 | 236 |
| 238 ash::DisplayIdPair pair = display_manager->GetCurrentDisplayIdPair(); | 237 ash::DisplayIdList pair = display_manager->GetCurrentDisplayIdList(); |
| 239 ash::DisplayLayout display_layout = | 238 ash::DisplayLayout display_layout = |
| 240 display_manager->layout_store()->GetRegisteredDisplayLayout(pair); | 239 display_manager->layout_store()->GetRegisteredDisplayLayout(pair); |
| 241 StoreDisplayLayoutPref(pair, display_layout); | 240 StoreDisplayLayoutPref(pair, display_layout); |
| 242 } | 241 } |
| 243 | 242 |
| 244 void StoreCurrentDisplayProperties() { | 243 void StoreCurrentDisplayProperties() { |
| 245 ash::DisplayManager* display_manager = GetDisplayManager(); | 244 ash::DisplayManager* display_manager = GetDisplayManager(); |
| 246 PrefService* local_state = g_browser_process->local_state(); | 245 PrefService* local_state = g_browser_process->local_state(); |
| 247 | 246 |
| 248 DictionaryPrefUpdate update(local_state, prefs::kDisplayProperties); | 247 DictionaryPrefUpdate update(local_state, prefs::kDisplayProperties); |
| (...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 386 ash::Shell::GetInstance()->display_configurator()->SetInitialDisplayPower( | 385 ash::Shell::GetInstance()->display_configurator()->SetInitialDisplayPower( |
| 387 power_state); | 386 power_state); |
| 388 } | 387 } |
| 389 } | 388 } |
| 390 } | 389 } |
| 391 | 390 |
| 392 // Stores the display layout for given display pairs. | 391 // Stores the display layout for given display pairs. |
| 393 void StoreDisplayLayoutPrefForTest(int64_t id1, | 392 void StoreDisplayLayoutPrefForTest(int64_t id1, |
| 394 int64_t id2, | 393 int64_t id2, |
| 395 const ash::DisplayLayout& layout) { | 394 const ash::DisplayLayout& layout) { |
| 396 StoreDisplayLayoutPref(ash::CreateDisplayIdPair(id1, id2), layout); | 395 StoreDisplayLayoutPref(ash::CreateDisplayIdList(id1, id2), 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 |