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/common/shelf/app_list_shelf_item_delegate.h" | 5 #include "ash/common/shelf/app_list_shelf_item_delegate.h" |
6 | 6 |
7 #include "ash/common/shelf/shelf_model.h" | 7 #include "ash/common/shelf/shelf_model.h" |
8 #include "ash/common/wm_shell.h" | 8 #include "ash/common/wm_shell.h" |
9 #include "base/memory/ptr_util.h" | 9 #include "base/memory/ptr_util.h" |
10 #include "grit/ash_strings.h" | 10 #include "grit/ash_strings.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 // static | 16 // static |
17 void AppListShelfItemDelegate::CreateAppListItemAndDelegate( | 17 void AppListShelfItemDelegate::CreateAppListItemAndDelegate(ShelfModel* model) { |
18 ShelfModel* shelf_model) { | |
19 // Add the app list item to the shelf model. | 18 // Add the app list item to the shelf model. |
20 ShelfItem app_list; | 19 ShelfItem item; |
21 app_list.type = TYPE_APP_LIST; | 20 item.type = TYPE_APP_LIST; |
22 int app_list_index = shelf_model->Add(app_list); | 21 item.title = l10n_util::GetStringUTF16(IDS_ASH_SHELF_APP_LIST_LAUNCHER_TITLE); |
23 DCHECK_GE(app_list_index, 0); | 22 int index = model->Add(item); |
| 23 DCHECK_GE(index, 0); |
24 | 24 |
25 // Create an AppListShelfItemDelegate for that item. | 25 // Create an AppListShelfItemDelegate for that item. |
26 ShelfID app_list_id = shelf_model->items()[app_list_index].id; | 26 ShelfID id = model->items()[index].id; |
27 DCHECK_GE(app_list_id, 0); | 27 DCHECK_GE(id, 0); |
28 shelf_model->SetShelfItemDelegate( | 28 model->SetShelfItemDelegate(id, base::MakeUnique<AppListShelfItemDelegate>()); |
29 app_list_id, base::MakeUnique<AppListShelfItemDelegate>()); | |
30 } | 29 } |
31 | 30 |
32 AppListShelfItemDelegate::AppListShelfItemDelegate() {} | 31 AppListShelfItemDelegate::AppListShelfItemDelegate() {} |
33 | 32 |
34 AppListShelfItemDelegate::~AppListShelfItemDelegate() {} | 33 AppListShelfItemDelegate::~AppListShelfItemDelegate() {} |
35 | 34 |
36 ShelfItemDelegate::PerformedAction AppListShelfItemDelegate::ItemSelected( | 35 ShelfItemDelegate::PerformedAction AppListShelfItemDelegate::ItemSelected( |
37 const ui::Event& event) { | 36 const ui::Event& event) { |
38 WmShell::Get()->ToggleAppList(); | 37 WmShell::Get()->ToggleAppList(); |
39 return ShelfItemDelegate::kAppListMenuShown; | 38 return ShelfItemDelegate::kAppListMenuShown; |
40 } | 39 } |
41 | 40 |
42 base::string16 AppListShelfItemDelegate::GetTitle() { | |
43 ShelfModel* model = WmShell::Get()->shelf_model(); | |
44 DCHECK(model); | |
45 int title_id; | |
46 title_id = model->status() == ShelfModel::STATUS_LOADING | |
47 ? IDS_ASH_SHELF_APP_LIST_LAUNCHER_SYNCING_TITLE | |
48 : IDS_ASH_SHELF_APP_LIST_LAUNCHER_TITLE; | |
49 return l10n_util::GetStringUTF16(title_id); | |
50 } | |
51 | |
52 ShelfMenuModel* AppListShelfItemDelegate::CreateApplicationMenu( | 41 ShelfMenuModel* AppListShelfItemDelegate::CreateApplicationMenu( |
53 int event_flags) { | 42 int event_flags) { |
54 // AppList does not show an application menu. | 43 // AppList does not show an application menu. |
55 return NULL; | 44 return NULL; |
56 } | 45 } |
57 | 46 |
58 void AppListShelfItemDelegate::Close() {} | 47 void AppListShelfItemDelegate::Close() {} |
59 | 48 |
60 } // namespace ash | 49 } // namespace ash |
OLD | NEW |