1 // Copyright 2017 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "ash/public/cpp/shelf_item_delegate.h"
6
7 #include "base/bind.h"
8 #include "ui/base/models/simple_menu_model.h"
9
10 namespace ash {
11
ShelfItemDelegate(const ShelfID & shelf_id)12 ShelfItemDelegate::ShelfItemDelegate(const ShelfID& shelf_id)
13 : shelf_id_(shelf_id) {}
14
15 ShelfItemDelegate::~ShelfItemDelegate() = default;
16
ItemSelected(std::unique_ptr<ui::Event> event,int64_t display_id,ShelfLaunchSource source,ItemSelectedCallback callback,const ItemFilterPredicate & filter_predicate)17 void ShelfItemDelegate::ItemSelected(
18 std::unique_ptr<ui::Event> event,
19 int64_t display_id,
20 ShelfLaunchSource source,
21 ItemSelectedCallback callback,
22 const ItemFilterPredicate& filter_predicate) {
23 std::move(callback).Run(SHELF_ACTION_NONE, {});
24 }
25
GetAppMenuItems(int event_flags,const ItemFilterPredicate & filter_predicate)26 ShelfItemDelegate::AppMenuItems ShelfItemDelegate::GetAppMenuItems(
27 int event_flags,
28 const ItemFilterPredicate& filter_predicate) {
29 return {};
30 }
31
GetContextMenu(int64_t display_id,GetContextMenuCallback callback)32 void ShelfItemDelegate::GetContextMenu(int64_t display_id,
33 GetContextMenuCallback callback) {
34 // Supplying null will cause ShelfView to show a default context menu.
35 std::move(callback).Run(nullptr);
36 }
37
38 AppWindowLauncherItemController*
AsAppWindowLauncherItemController()39 ShelfItemDelegate::AsAppWindowLauncherItemController() {
40 return nullptr;
41 }
42
ExecuteContextMenuCommand(int64_t command_id,int32_t event_flags)43 bool ShelfItemDelegate::ExecuteContextMenuCommand(int64_t command_id,
44 int32_t event_flags) {
45 DCHECK(context_menu_);
46 // Help subclasses execute context menu items, which may be on a sub-menu.
47 ui::MenuModel* model = context_menu_.get();
48 int index = -1;
49 if (!ui::MenuModel::GetModelAndIndexForCommandId(command_id, &model, &index))
50 return false;
51
52 model->ActivatedAt(index, event_flags);
53 return true;
54 }
55
56 } // namespace ash
57