Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(107)

Side by Side Diff: ash/common/shelf/shelf_application_menu_model.cc

Issue 2734653002: chromeos: Move files in //ash/common to //ash (Closed)
Patch Set: fix a11y tests, fix docs Created 3 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
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/common/shelf/shelf_application_menu_model.h"
6
7 #include <stddef.h>
8
9 #include <limits>
10 #include <utility>
11
12 #include "ash/common/shelf/shelf_item_delegate.h"
13 #include "ash/public/cpp/shelf_application_menu_item.h"
14 #include "base/metrics/histogram_macros.h"
15
16 namespace {
17
18 const int kInvalidCommandId = std::numeric_limits<int>::max();
19
20 } // namespace
21
22 namespace ash {
23
24 ShelfApplicationMenuModel::ShelfApplicationMenuModel(
25 const base::string16& title,
26 ShelfAppMenuItemList items,
27 ShelfItemDelegate* delegate)
28 : ui::SimpleMenuModel(this), items_(std::move(items)), delegate_(delegate) {
29 AddSeparator(ui::SPACING_SEPARATOR);
30 AddItem(kInvalidCommandId, title);
31 AddSeparator(ui::SPACING_SEPARATOR);
32
33 for (size_t i = 0; i < items_.size(); i++) {
34 ShelfApplicationMenuItem* item = items_[i].get();
35 AddItem(i, item->title());
36 if (!item->icon().IsEmpty())
37 SetIcon(GetIndexOfCommandId(i), item->icon());
38 }
39
40 // SimpleMenuModel does not allow two consecutive spacing separator items.
41 // This only occurs in tests; users should not see menus with no |items_|.
42 if (!items_.empty())
43 AddSeparator(ui::SPACING_SEPARATOR);
44 }
45
46 ShelfApplicationMenuModel::~ShelfApplicationMenuModel() {}
47
48 bool ShelfApplicationMenuModel::IsCommandIdChecked(int command_id) const {
49 return false;
50 }
51
52 bool ShelfApplicationMenuModel::IsCommandIdEnabled(int command_id) const {
53 return command_id >= 0 && static_cast<size_t>(command_id) < items_.size();
54 }
55
56 void ShelfApplicationMenuModel::ExecuteCommand(int command_id,
57 int event_flags) {
58 DCHECK(delegate_);
59 DCHECK(IsCommandIdEnabled(command_id));
60 // Have the delegate execute its own custom command id for the given item.
61 delegate_->ExecuteCommand(items_[command_id]->command_id(), event_flags);
62 RecordMenuItemSelectedMetrics(command_id, items_.size());
63 }
64
65 void ShelfApplicationMenuModel::RecordMenuItemSelectedMetrics(
66 int command_id,
67 int num_menu_items_enabled) {
68 UMA_HISTOGRAM_COUNTS_100("Ash.Shelf.Menu.SelectedMenuItemIndex", command_id);
69 UMA_HISTOGRAM_COUNTS_100("Ash.Shelf.Menu.NumItemsEnabledUponSelection",
70 num_menu_items_enabled);
71 }
72
73 } // namespace ash
OLDNEW
« no previous file with comments | « ash/common/shelf/shelf_application_menu_model.h ('k') | ash/common/shelf/shelf_application_menu_model_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698