OLD | NEW |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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 "ash/common/shelf/shelf_controller.h" | 5 #include "ash/common/shelf/shelf_controller.h" |
6 | 6 |
7 #include "ash/common/shelf/shelf_item_delegate.h" | 7 #include "ash/common/shelf/shelf_item_delegate.h" |
8 #include "ash/common/shelf/shelf_menu_model.h" | 8 #include "ash/common/shelf/shelf_menu_model.h" |
9 #include "ash/common/shelf/wm_shelf.h" | 9 #include "ash/common/shelf/wm_shelf.h" |
| 10 #include "ash/common/shell_delegate.h" |
10 #include "ash/common/wm_lookup.h" | 11 #include "ash/common/wm_lookup.h" |
11 #include "ash/common/wm_root_window_controller.h" | 12 #include "ash/common/wm_root_window_controller.h" |
12 #include "ash/common/wm_shell.h" | 13 #include "ash/common/wm_shell.h" |
13 #include "ash/common/wm_window.h" | 14 #include "ash/common/wm_window.h" |
14 #include "base/strings/utf_string_conversions.h" | 15 #include "base/strings/utf_string_conversions.h" |
| 16 #include "services/preferences/public/cpp/pref_observer_store.h" |
15 #include "ui/base/resource/resource_bundle.h" | 17 #include "ui/base/resource/resource_bundle.h" |
16 #include "ui/display/display.h" | 18 #include "ui/display/display.h" |
17 #include "ui/display/screen.h" | 19 #include "ui/display/screen.h" |
18 #include "ui/gfx/image/image_skia.h" | 20 #include "ui/gfx/image/image_skia.h" |
19 #include "ui/resources/grit/ui_resources.h" | 21 #include "ui/resources/grit/ui_resources.h" |
20 | 22 |
21 namespace ash { | 23 namespace ash { |
22 | 24 |
23 namespace { | 25 namespace { |
24 | 26 |
(...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
157 // The controller may be null for invalid ids or for displays being removed. | 159 // The controller may be null for invalid ids or for displays being removed. |
158 WmRootWindowController* root_window_controller = | 160 WmRootWindowController* root_window_controller = |
159 WmLookup::Get()->GetRootWindowControllerWithDisplayId(display_id); | 161 WmLookup::Get()->GetRootWindowControllerWithDisplayId(display_id); |
160 return root_window_controller ? root_window_controller->GetShelf() : nullptr; | 162 return root_window_controller ? root_window_controller->GetShelf() : nullptr; |
161 } | 163 } |
162 | 164 |
163 } // namespace | 165 } // namespace |
164 | 166 |
165 ShelfController::ShelfController() {} | 167 ShelfController::ShelfController() {} |
166 | 168 |
167 ShelfController::~ShelfController() {} | 169 ShelfController::~ShelfController() { |
| 170 preferences::PrefObserverStore* store = WmShell::Get()->pref_store(); |
| 171 if (store) |
| 172 store->RemoveObserver(this); |
| 173 } |
168 | 174 |
169 void ShelfController::BindRequest(mojom::ShelfControllerRequest request) { | 175 void ShelfController::BindRequest(mojom::ShelfControllerRequest request) { |
170 bindings_.AddBinding(this, std::move(request)); | 176 bindings_.AddBinding(this, std::move(request)); |
| 177 |
| 178 // Sample of connecting to the PreferencesManager |
| 179 preferences::PrefObserverStore* store = WmShell::Get()->pref_store(); |
| 180 std::set<std::string> keys; |
| 181 // chrome::common::pref_names::kShelfAutoHideBehavior |
| 182 const std::string key("auto_hide_behavior"); |
| 183 keys.insert(key); |
| 184 store->AddObserver(this); |
| 185 store->Subscribe(keys); |
171 } | 186 } |
172 | 187 |
173 void ShelfController::NotifyShelfCreated(WmShelf* shelf) { | 188 void ShelfController::NotifyShelfCreated(WmShelf* shelf) { |
174 // Notify observers, Chrome will set alignment and auto-hide from prefs. | 189 // Notify observers, Chrome will set alignment and auto-hide from prefs. |
175 int64_t display_id = shelf->GetWindow()->GetDisplayNearestWindow().id(); | 190 int64_t display_id = shelf->GetWindow()->GetDisplayNearestWindow().id(); |
176 observers_.ForAllPtrs([display_id](mojom::ShelfObserver* observer) { | 191 observers_.ForAllPtrs([display_id](mojom::ShelfObserver* observer) { |
177 observer->OnShelfCreated(display_id); | 192 observer->OnShelfCreated(display_id); |
178 }); | 193 }); |
179 } | 194 } |
180 | 195 |
181 void ShelfController::NotifyShelfAlignmentChanged(WmShelf* shelf) { | 196 void ShelfController::NotifyShelfAlignmentChanged(WmShelf* shelf) { |
182 ShelfAlignment alignment = shelf->alignment(); | 197 ShelfAlignment alignment = shelf->alignment(); |
183 int64_t display_id = shelf->GetWindow()->GetDisplayNearestWindow().id(); | 198 int64_t display_id = shelf->GetWindow()->GetDisplayNearestWindow().id(); |
184 observers_.ForAllPtrs( | 199 observers_.ForAllPtrs( |
185 [alignment, display_id](mojom::ShelfObserver* observer) { | 200 [alignment, display_id](mojom::ShelfObserver* observer) { |
186 observer->OnAlignmentChanged(alignment, display_id); | 201 observer->OnAlignmentChanged(alignment, display_id); |
187 }); | 202 }); |
188 } | 203 } |
189 | 204 |
190 void ShelfController::NotifyShelfAutoHideBehaviorChanged(WmShelf* shelf) { | 205 void ShelfController::NotifyShelfAutoHideBehaviorChanged(WmShelf* shelf) { |
191 ShelfAutoHideBehavior behavior = shelf->auto_hide_behavior(); | 206 ShelfAutoHideBehavior behavior = shelf->auto_hide_behavior(); |
192 int64_t display_id = shelf->GetWindow()->GetDisplayNearestWindow().id(); | 207 int64_t display_id = shelf->GetWindow()->GetDisplayNearestWindow().id(); |
193 observers_.ForAllPtrs([behavior, display_id](mojom::ShelfObserver* observer) { | 208 observers_.ForAllPtrs([behavior, display_id](mojom::ShelfObserver* observer) { |
194 observer->OnAutoHideBehaviorChanged(behavior, display_id); | 209 observer->OnAutoHideBehaviorChanged(behavior, display_id); |
195 }); | 210 }); |
| 211 |
| 212 // This was acutally a race-conditiony place to put this example code. You |
| 213 // can't call it until init has completed. |
| 214 /* |
| 215 // Using Preferences to set the value. the chrome ShelfObserver can |
| 216 seprately |
| 217 // listen to preference changes to make any according UI state changes. |
| 218 std::string behaviour_pref; |
| 219 switch (behavior) { |
| 220 case SHELF_AUTO_HIDE_BEHAVIOR_ALWAYS: |
| 221 behaviour_pref = "Always"; |
| 222 break; |
| 223 case SHELF_AUTO_HIDE_BEHAVIOR_NEVER: |
| 224 behaviour_pref = "Never"; |
| 225 break; |
| 226 default: |
| 227 behaviour_pref = "ooops"; |
| 228 } |
| 229 std::unique_ptr<base::Value> value(new base::StringValue(behaviour_pref)); |
| 230 if (store_) |
| 231 store_->SetValue("auto_hide_behavior", std::move(value), 0); |
| 232 */ |
196 } | 233 } |
197 | 234 |
198 void ShelfController::AddObserver( | 235 void ShelfController::AddObserver( |
199 mojom::ShelfObserverAssociatedPtrInfo observer) { | 236 mojom::ShelfObserverAssociatedPtrInfo observer) { |
200 mojom::ShelfObserverAssociatedPtr observer_ptr; | 237 mojom::ShelfObserverAssociatedPtr observer_ptr; |
201 observer_ptr.Bind(std::move(observer)); | 238 observer_ptr.Bind(std::move(observer)); |
202 observers_.AddPtr(std::move(observer_ptr)); | 239 observers_.AddPtr(std::move(observer_ptr)); |
203 } | 240 } |
204 | 241 |
205 void ShelfController::SetAlignment(ShelfAlignment alignment, | 242 void ShelfController::SetAlignment(ShelfAlignment alignment, |
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
274 if (!app_id_to_shelf_id_.count(app_id)) | 311 if (!app_id_to_shelf_id_.count(app_id)) |
275 return; | 312 return; |
276 ShelfID shelf_id = app_id_to_shelf_id_[app_id]; | 313 ShelfID shelf_id = app_id_to_shelf_id_[app_id]; |
277 int index = model_.ItemIndexByID(shelf_id); | 314 int index = model_.ItemIndexByID(shelf_id); |
278 DCHECK_GE(index, 0); | 315 DCHECK_GE(index, 0); |
279 ShelfItem item = *model_.ItemByID(shelf_id); | 316 ShelfItem item = *model_.ItemByID(shelf_id); |
280 item.image = GetShelfIconFromBitmap(image); | 317 item.image = GetShelfIconFromBitmap(image); |
281 model_.Set(index, item); | 318 model_.Set(index, item); |
282 } | 319 } |
283 | 320 |
| 321 void ShelfController::OnPrefValueChanged(const std::string& key) { |
| 322 const base::Value* value = nullptr; |
| 323 WmShell::Get()->pref_store()->GetValue("auto_hide_behavior", &value); |
| 324 if (!value) |
| 325 return; |
| 326 std::string actual_value; |
| 327 value->GetAsString(&actual_value); |
| 328 LOG(ERROR) << "JR OnPrefValueChanged " << key << " : " << actual_value |
| 329 << "\n"; |
| 330 |
| 331 // Call a method that needs the pref here |
| 332 } |
| 333 |
| 334 void ShelfController::OnInitializationCompleted(bool succeeded) { |
| 335 LOG(ERROR) << "JR OnInitializationCompleted\n"; |
| 336 } |
| 337 |
284 } // namespace ash | 338 } // namespace ash |
OLD | NEW |