Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(702)

Side by Side Diff: chrome/browser/chromeos/display/display_preferences.cc

Issue 1838833002: Move DisplayLayout and DisplayLayoutBuilder From ash To ui/display (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@screenwinmove
Patch Set: Fix comment Created 4 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 100 matching lines...) Expand 10 before | Expand all | Expand 10 after
111 } 111 }
112 112
113 void LoadDisplayLayouts() { 113 void LoadDisplayLayouts() {
114 PrefService* local_state = g_browser_process->local_state(); 114 PrefService* local_state = g_browser_process->local_state();
115 ash::DisplayLayoutStore* layout_store = GetDisplayManager()->layout_store(); 115 ash::DisplayLayoutStore* layout_store = GetDisplayManager()->layout_store();
116 116
117 const base::DictionaryValue* layouts = local_state->GetDictionary( 117 const base::DictionaryValue* layouts = local_state->GetDictionary(
118 prefs::kSecondaryDisplays); 118 prefs::kSecondaryDisplays);
119 for (base::DictionaryValue::Iterator it(*layouts); 119 for (base::DictionaryValue::Iterator it(*layouts);
120 !it.IsAtEnd(); it.Advance()) { 120 !it.IsAtEnd(); it.Advance()) {
121 scoped_ptr<ash::DisplayLayout> layout(new ash::DisplayLayout); 121 scoped_ptr<display::DisplayLayout> layout(new display::DisplayLayout);
122 if (!ash::JsonToDisplayLayout(it.value(), layout.get())) { 122 if (!ash::JsonToDisplayLayout(it.value(), layout.get())) {
123 LOG(WARNING) << "Invalid preference value for " << it.key(); 123 LOG(WARNING) << "Invalid preference value for " << it.key();
124 continue; 124 continue;
125 } 125 }
126 126
127 if (it.key().find(",") != std::string::npos) { 127 if (it.key().find(",") != std::string::npos) {
128 std::vector<std::string> ids_str = base::SplitString( 128 std::vector<std::string> ids_str = base::SplitString(
129 it.key(), ",", base::TRIM_WHITESPACE, base::SPLIT_WANT_ALL); 129 it.key(), ",", base::TRIM_WHITESPACE, base::SPLIT_WANT_ALL);
130 std::vector<int64_t> ids; 130 std::vector<int64_t> ids;
131 for (std::string id_str : ids_str) { 131 for (std::string id_str : ids_str) {
132 int64_t id; 132 int64_t id;
133 if (!base::StringToInt64(id_str, &id)) 133 if (!base::StringToInt64(id_str, &id))
134 continue; 134 continue;
135 ids.push_back(id); 135 ids.push_back(id);
136 } 136 }
137 ash::DisplayIdList list = 137 display::DisplayIdList list =
138 ash::GenerateDisplayIdList(ids.begin(), ids.end()); 138 ash::GenerateDisplayIdList(ids.begin(), ids.end());
139 layout_store->RegisterLayoutForDisplayIdList(list, std::move(layout)); 139 layout_store->RegisterLayoutForDisplayIdList(list, std::move(layout));
140 } 140 }
141 } 141 }
142 } 142 }
143 143
144 void LoadDisplayProperties() { 144 void LoadDisplayProperties() {
145 PrefService* local_state = g_browser_process->local_state(); 145 PrefService* local_state = g_browser_process->local_state();
146 const base::DictionaryValue* properties = local_state->GetDictionary( 146 const base::DictionaryValue* properties = local_state->GetDictionary(
147 prefs::kDisplayProperties); 147 prefs::kDisplayProperties);
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
205 return; 205 return;
206 206
207 int rotation = gfx::Display::ROTATE_0; 207 int rotation = gfx::Display::ROTATE_0;
208 if (!properties->GetInteger("orientation", &rotation)) 208 if (!properties->GetInteger("orientation", &rotation))
209 return; 209 return;
210 210
211 GetDisplayManager()->RegisterDisplayRotationProperties(rotation_lock, 211 GetDisplayManager()->RegisterDisplayRotationProperties(rotation_lock,
212 static_cast<gfx::Display::Rotation>(rotation)); 212 static_cast<gfx::Display::Rotation>(rotation));
213 } 213 }
214 214
215 void StoreDisplayLayoutPref(const ash::DisplayIdList& list, 215 void StoreDisplayLayoutPref(const display::DisplayIdList& list,
216 const ash::DisplayLayout& display_layout) { 216 const display::DisplayLayout& display_layout) {
217 std::string name = ash::DisplayIdListToString(list); 217 std::string name = ash::DisplayIdListToString(list);
218 218
219 PrefService* local_state = g_browser_process->local_state(); 219 PrefService* local_state = g_browser_process->local_state();
220 DictionaryPrefUpdate update(local_state, prefs::kSecondaryDisplays); 220 DictionaryPrefUpdate update(local_state, prefs::kSecondaryDisplays);
221 base::DictionaryValue* pref_data = update.Get(); 221 base::DictionaryValue* pref_data = update.Get();
222 scoped_ptr<base::Value> layout_value(new base::DictionaryValue()); 222 scoped_ptr<base::Value> layout_value(new base::DictionaryValue());
223 if (pref_data->HasKey(name)) { 223 if (pref_data->HasKey(name)) {
224 base::Value* value = nullptr; 224 base::Value* value = nullptr;
225 if (pref_data->Get(name, &value) && value != nullptr) 225 if (pref_data->Get(name, &value) && value != nullptr)
226 layout_value.reset(value->DeepCopy()); 226 layout_value.reset(value->DeepCopy());
227 } 227 }
228 if (ash::DisplayLayoutToJson(display_layout, layout_value.get())) 228 if (ash::DisplayLayoutToJson(display_layout, layout_value.get()))
229 pref_data->Set(name, layout_value.release()); 229 pref_data->Set(name, layout_value.release());
230 } 230 }
231 231
232 void StoreCurrentDisplayLayoutPrefs() { 232 void StoreCurrentDisplayLayoutPrefs() {
233 ash::DisplayManager* display_manager = GetDisplayManager(); 233 ash::DisplayManager* display_manager = GetDisplayManager();
234 if (!UserCanSaveDisplayPreference() || 234 if (!UserCanSaveDisplayPreference() ||
235 display_manager->num_connected_displays() < 2) { 235 display_manager->num_connected_displays() < 2) {
236 return; 236 return;
237 } 237 }
238 238
239 ash::DisplayIdList list = display_manager->GetCurrentDisplayIdList(); 239 display::DisplayIdList list = display_manager->GetCurrentDisplayIdList();
240 const ash::DisplayLayout& display_layout = 240 const display::DisplayLayout& display_layout =
241 display_manager->layout_store()->GetRegisteredDisplayLayout(list); 241 display_manager->layout_store()->GetRegisteredDisplayLayout(list);
242 StoreDisplayLayoutPref(list, display_layout); 242 StoreDisplayLayoutPref(list, display_layout);
243 } 243 }
244 244
245 void StoreCurrentDisplayProperties() { 245 void StoreCurrentDisplayProperties() {
246 ash::DisplayManager* display_manager = GetDisplayManager(); 246 ash::DisplayManager* display_manager = GetDisplayManager();
247 PrefService* local_state = g_browser_process->local_state(); 247 PrefService* local_state = g_browser_process->local_state();
248 248
249 DictionaryPrefUpdate update(local_state, prefs::kDisplayProperties); 249 DictionaryPrefUpdate update(local_state, prefs::kDisplayProperties);
250 base::DictionaryValue* pref_data = update.Get(); 250 base::DictionaryValue* pref_data = update.Get();
(...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after
384 std::string value = local_state->GetString(prefs::kDisplayPowerState); 384 std::string value = local_state->GetString(prefs::kDisplayPowerState);
385 chromeos::DisplayPowerState power_state; 385 chromeos::DisplayPowerState power_state;
386 if (GetDisplayPowerStateFromString(value, &power_state)) { 386 if (GetDisplayPowerStateFromString(value, &power_state)) {
387 ash::Shell::GetInstance()->display_configurator()->SetInitialDisplayPower( 387 ash::Shell::GetInstance()->display_configurator()->SetInitialDisplayPower(
388 power_state); 388 power_state);
389 } 389 }
390 } 390 }
391 } 391 }
392 392
393 // Stores the display layout for given display pairs. 393 // Stores the display layout for given display pairs.
394 void StoreDisplayLayoutPrefForTest(const ash::DisplayIdList& list, 394 void StoreDisplayLayoutPrefForTest(const display::DisplayIdList& list,
395 const ash::DisplayLayout& layout) { 395 const display::DisplayLayout& layout) {
396 StoreDisplayLayoutPref(list, layout); 396 StoreDisplayLayoutPref(list, layout);
397 } 397 }
398 398
399 // Stores the given |power_state|. 399 // Stores the given |power_state|.
400 void StoreDisplayPowerStateForTest(DisplayPowerState power_state) { 400 void StoreDisplayPowerStateForTest(DisplayPowerState power_state) {
401 StoreDisplayPowerState(power_state); 401 StoreDisplayPowerState(power_state);
402 } 402 }
403 403
404 } // namespace chromeos 404 } // namespace chromeos
OLDNEW
« no previous file with comments | « chrome/browser/chromeos/display/display_preferences.h ('k') | chrome/browser/chromeos/display/display_preferences_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698