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

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

Issue 2671923002: mash: Cleanup ash shelf application menu code. (Closed)
Patch Set: Add comments Created 3 years, 10 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/public/cpp/shelf_application_menu_item.h"
13 #include "base/metrics/histogram_macros.h"
14
15 namespace {
16
17 const int kInvalidCommandId = std::numeric_limits<int>::max();
18
19 } // namespace
20
21 namespace ash {
22
23 ShelfApplicationMenuModel::ShelfApplicationMenuModel(
24 const base::string16& title,
25 ShelfAppMenuItemList items)
26 : ui::SimpleMenuModel(this), items_(std::move(items)) {
27 AddSeparator(ui::SPACING_SEPARATOR);
28 AddItem(kInvalidCommandId, title);
29 AddSeparator(ui::SPACING_SEPARATOR);
30
31 for (size_t i = 0; i < items_.size(); i++) {
32 ShelfApplicationMenuItem* item = items_[i].get();
33 AddItem(i, item->title());
34 if (!item->icon().IsEmpty())
35 SetIcon(GetIndexOfCommandId(i), item->icon());
36 }
37
38 // SimpleMenuModel does not allow two consecutive spacing separator items.
39 // This only occurs in tests; users should not see menus with no |items_|.
40 if (!items_.empty())
41 AddSeparator(ui::SPACING_SEPARATOR);
42 }
43
44 ShelfApplicationMenuModel::~ShelfApplicationMenuModel() {}
45
46 bool ShelfApplicationMenuModel::IsCommandIdChecked(int command_id) const {
47 return false;
48 }
49
50 bool ShelfApplicationMenuModel::IsCommandIdEnabled(int command_id) const {
51 return command_id >= 0 && static_cast<size_t>(command_id) < items_.size();
52 }
53
54 void ShelfApplicationMenuModel::ExecuteCommand(int command_id,
55 int event_flags) {
56 DCHECK(IsCommandIdEnabled(command_id));
57 items_[command_id]->Execute(event_flags);
58 RecordMenuItemSelectedMetrics(command_id, items_.size());
59 }
60
61 void ShelfApplicationMenuModel::RecordMenuItemSelectedMetrics(
62 int command_id,
63 int num_menu_items_enabled) {
64 UMA_HISTOGRAM_COUNTS_100("Ash.Shelf.Menu.SelectedMenuItemIndex", command_id);
65 UMA_HISTOGRAM_COUNTS_100("Ash.Shelf.Menu.NumItemsEnabledUponSelection",
66 num_menu_items_enabled);
67 }
68
69 } // 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