| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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/app_list_shelf_item_delegate.h" | 5 #include "ash/shelf/app_list_shelf_item_delegate.h" |
| 6 | 6 |
| 7 #include "ash/shelf/shelf_model.h" | 7 #include "ash/shelf/shelf_model.h" |
| 8 #include "ash/shell.h" | 8 #include "ash/shell.h" |
| 9 #include "ash/strings/grit/ash_strings.h" | 9 #include "ash/strings/grit/ash_strings.h" |
| 10 #include "base/memory/ptr_util.h" | 10 #include "base/memory/ptr_util.h" |
| 11 #include "ui/app_list/app_list_switches.h" | 11 #include "ui/app_list/app_list_switches.h" |
| 12 #include "ui/base/l10n/l10n_util.h" | 12 #include "ui/base/l10n/l10n_util.h" |
| 13 | 13 |
| 14 namespace ash { | 14 namespace ash { |
| 15 | 15 |
| 16 namespace { |
| 17 |
| 18 // An app id for the app list, used to identify the shelf item. |
| 19 static constexpr char kAppListId[] = "AppListId"; |
| 20 |
| 21 } // namespace |
| 22 |
| 16 // static | 23 // static |
| 17 void AppListShelfItemDelegate::CreateAppListItemAndDelegate(ShelfModel* model) { | 24 void AppListShelfItemDelegate::CreateAppListItemAndDelegate(ShelfModel* model) { |
| 18 // Add the app list item to the shelf model. | 25 // Add the app list item to the shelf model. |
| 19 ShelfItem item; | 26 ShelfItem item; |
| 20 item.type = TYPE_APP_LIST; | 27 item.type = TYPE_APP_LIST; |
| 28 item.id = ShelfID(kAppListId); |
| 21 item.title = l10n_util::GetStringUTF16(IDS_ASH_SHELF_APP_LIST_LAUNCHER_TITLE); | 29 item.title = l10n_util::GetStringUTF16(IDS_ASH_SHELF_APP_LIST_LAUNCHER_TITLE); |
| 22 int index = model->Add(item); | 30 int index = model->Add(item); |
| 23 DCHECK_GE(index, 0); | 31 DCHECK_GE(index, 0); |
| 24 | 32 |
| 25 // Create an AppListShelfItemDelegate for that item. | 33 // Create an AppListShelfItemDelegate for that item. |
| 26 ShelfID id = model->items()[index].id; | 34 model->SetShelfItemDelegate(item.id, |
| 27 DCHECK_NE(id, kInvalidShelfID); | 35 base::MakeUnique<AppListShelfItemDelegate>()); |
| 28 model->SetShelfItemDelegate(id, base::MakeUnique<AppListShelfItemDelegate>()); | |
| 29 } | 36 } |
| 30 | 37 |
| 31 AppListShelfItemDelegate::AppListShelfItemDelegate() | 38 AppListShelfItemDelegate::AppListShelfItemDelegate() |
| 32 : ShelfItemDelegate(AppLaunchId()) {} | 39 : ShelfItemDelegate(ShelfID(kAppListId)) {} |
| 33 | 40 |
| 34 AppListShelfItemDelegate::~AppListShelfItemDelegate() {} | 41 AppListShelfItemDelegate::~AppListShelfItemDelegate() {} |
| 35 | 42 |
| 36 void AppListShelfItemDelegate::ItemSelected( | 43 void AppListShelfItemDelegate::ItemSelected( |
| 37 std::unique_ptr<ui::Event> event, | 44 std::unique_ptr<ui::Event> event, |
| 38 int64_t display_id, | 45 int64_t display_id, |
| 39 ShelfLaunchSource source, | 46 ShelfLaunchSource source, |
| 40 const ItemSelectedCallback& callback) { | 47 const ItemSelectedCallback& callback) { |
| 41 Shell::Get()->ToggleAppList(); | 48 Shell::Get()->ToggleAppList(); |
| 42 callback.Run(SHELF_ACTION_APP_LIST_SHOWN, base::nullopt); | 49 callback.Run(SHELF_ACTION_APP_LIST_SHOWN, base::nullopt); |
| 43 } | 50 } |
| 44 | 51 |
| 45 void AppListShelfItemDelegate::ExecuteCommand(uint32_t command_id, | 52 void AppListShelfItemDelegate::ExecuteCommand(uint32_t command_id, |
| 46 int32_t event_flags) { | 53 int32_t event_flags) { |
| 47 // This delegate does not support showing an application menu. | 54 // This delegate does not support showing an application menu. |
| 48 NOTIMPLEMENTED(); | 55 NOTIMPLEMENTED(); |
| 49 } | 56 } |
| 50 | 57 |
| 51 void AppListShelfItemDelegate::Close() {} | 58 void AppListShelfItemDelegate::Close() {} |
| 52 | 59 |
| 53 } // namespace ash | 60 } // namespace ash |
| OLD | NEW |