| 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/shelf/shelf_controller.h" | 5 #include "ash/shelf/shelf_controller.h" |
| 6 | 6 |
| 7 #include "ash/public/cpp/config.h" | 7 #include "ash/public/cpp/config.h" |
| 8 #include "ash/public/cpp/remote_shelf_item_delegate.h" | 8 #include "ash/public/cpp/remote_shelf_item_delegate.h" |
| 9 #include "ash/root_window_controller.h" | 9 #include "ash/root_window_controller.h" |
| 10 #include "ash/session/session_controller.h" | 10 #include "ash/session/session_controller.h" |
| 11 #include "ash/shelf/app_list_shelf_item_delegate.h" | 11 #include "ash/shelf/app_list_shelf_item_delegate.h" |
| 12 #include "ash/shelf/shelf.h" | 12 #include "ash/shelf/shelf.h" |
| 13 #include "ash/shell.h" | 13 #include "ash/shell.h" |
| 14 #include "ash/strings/grit/ash_strings.h" |
| 14 #include "base/auto_reset.h" | 15 #include "base/auto_reset.h" |
| 15 #include "base/strings/utf_string_conversions.h" | 16 #include "base/strings/utf_string_conversions.h" |
| 17 #include "ui/base/l10n/l10n_util.h" |
| 16 #include "ui/base/models/simple_menu_model.h" | 18 #include "ui/base/models/simple_menu_model.h" |
| 17 #include "ui/display/display.h" | 19 #include "ui/display/display.h" |
| 18 #include "ui/display/screen.h" | 20 #include "ui/display/screen.h" |
| 19 | 21 |
| 20 namespace ash { | 22 namespace ash { |
| 21 | 23 |
| 22 namespace { | 24 namespace { |
| 23 | 25 |
| 24 // Returns the Shelf instance for the display with the given |display_id|. | 26 // Returns the Shelf instance for the display with the given |display_id|. |
| 25 Shelf* GetShelfForDisplay(int64_t display_id) { | 27 Shelf* GetShelfForDisplay(int64_t display_id) { |
| 26 // The controller may be null for invalid ids or for displays being removed. | 28 // The controller may be null for invalid ids or for displays being removed. |
| 27 RootWindowController* root_window_controller = | 29 RootWindowController* root_window_controller = |
| 28 Shell::GetRootWindowControllerWithDisplayId(display_id); | 30 Shell::GetRootWindowControllerWithDisplayId(display_id); |
| 29 return root_window_controller ? root_window_controller->shelf() : nullptr; | 31 return root_window_controller ? root_window_controller->shelf() : nullptr; |
| 30 } | 32 } |
| 31 | 33 |
| 32 } // namespace | 34 } // namespace |
| 33 | 35 |
| 34 ShelfController::ShelfController() { | 36 ShelfController::ShelfController() { |
| 35 // Create an AppListShelfItemDelegate for the app list item. | 37 // Set the delegate and title string for the app list item. |
| 36 model_.SetShelfItemDelegate(ShelfID(kAppListId), | 38 model_.SetShelfItemDelegate(ShelfID(kAppListId), |
| 37 base::MakeUnique<AppListShelfItemDelegate>()); | 39 base::MakeUnique<AppListShelfItemDelegate>()); |
| 40 DCHECK_EQ(0, model_.ItemIndexByID(ShelfID(kAppListId))); |
| 41 ShelfItem item = model_.items()[0]; |
| 42 item.title = l10n_util::GetStringUTF16(IDS_ASH_SHELF_APP_LIST_LAUNCHER_TITLE); |
| 43 model_.Set(0, item); |
| 44 |
| 38 model_.AddObserver(this); | 45 model_.AddObserver(this); |
| 39 } | 46 } |
| 40 | 47 |
| 41 ShelfController::~ShelfController() { | 48 ShelfController::~ShelfController() { |
| 42 model_.RemoveObserver(this); | 49 model_.RemoveObserver(this); |
| 43 } | 50 } |
| 44 | 51 |
| 45 void ShelfController::BindRequest(mojom::ShelfControllerRequest request) { | 52 void ShelfController::BindRequest(mojom::ShelfControllerRequest request) { |
| 46 bindings_.AddBinding(this, std::move(request)); | 53 bindings_.AddBinding(this, std::move(request)); |
| 47 } | 54 } |
| (...skipping 192 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 240 } | 247 } |
| 241 | 248 |
| 242 observers_.ForAllPtrs([id, delegate](mojom::ShelfObserver* observer) { | 249 observers_.ForAllPtrs([id, delegate](mojom::ShelfObserver* observer) { |
| 243 observer->OnShelfItemDelegateChanged( | 250 observer->OnShelfItemDelegateChanged( |
| 244 id, delegate ? delegate->CreateInterfacePtrAndBind() | 251 id, delegate ? delegate->CreateInterfacePtrAndBind() |
| 245 : mojom::ShelfItemDelegatePtr()); | 252 : mojom::ShelfItemDelegatePtr()); |
| 246 }); | 253 }); |
| 247 } | 254 } |
| 248 | 255 |
| 249 } // namespace ash | 256 } // namespace ash |
| OLD | NEW |