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

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

Issue 2716403005: mash: Remove shelf app menu item objects. (Closed)
Patch Set: Fix ash_shell compile 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
1 // Copyright 2017 The Chromium Authors. All rights reserved. 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 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/shelf_application_menu_model.h" 5 #include "ash/common/shelf/shelf_application_menu_model.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 8
9 #include <limits> 9 #include <limits>
10 #include <utility> 10 #include <utility>
11 11
12 #include "ash/common/shelf/shelf_item_delegate.h"
12 #include "ash/public/cpp/shelf_application_menu_item.h" 13 #include "ash/public/cpp/shelf_application_menu_item.h"
13 #include "base/metrics/histogram_macros.h" 14 #include "base/metrics/histogram_macros.h"
14 15
15 namespace { 16 namespace {
16 17
17 const int kInvalidCommandId = std::numeric_limits<int>::max(); 18 const int kInvalidCommandId = std::numeric_limits<int>::max();
18 19
19 } // namespace 20 } // namespace
20 21
21 namespace ash { 22 namespace ash {
22 23
23 ShelfApplicationMenuModel::ShelfApplicationMenuModel( 24 ShelfApplicationMenuModel::ShelfApplicationMenuModel(
24 const base::string16& title, 25 const base::string16& title,
25 ShelfAppMenuItemList items) 26 ShelfAppMenuItemList items,
26 : ui::SimpleMenuModel(this), items_(std::move(items)) { 27 ShelfItemDelegate* delegate)
28 : ui::SimpleMenuModel(this), items_(std::move(items)), delegate_(delegate) {
27 AddSeparator(ui::SPACING_SEPARATOR); 29 AddSeparator(ui::SPACING_SEPARATOR);
James Cook 2017/03/01 19:50:48 DCHECK(delegate_)? Or early exit for null delegat
msw 2017/03/02 02:59:20 I added a DCHECK in ExecuteCommand; tests use null
28 AddItem(kInvalidCommandId, title); 30 AddItem(kInvalidCommandId, title);
29 AddSeparator(ui::SPACING_SEPARATOR); 31 AddSeparator(ui::SPACING_SEPARATOR);
30 32
31 for (size_t i = 0; i < items_.size(); i++) { 33 for (size_t i = 0; i < items_.size(); i++) {
32 ShelfApplicationMenuItem* item = items_[i].get(); 34 ShelfApplicationMenuItem* item = items_[i].get();
33 AddItem(i, item->title()); 35 AddItem(i, item->title());
34 if (!item->icon().IsEmpty()) 36 if (!item->icon().IsEmpty())
35 SetIcon(GetIndexOfCommandId(i), item->icon()); 37 SetIcon(GetIndexOfCommandId(i), item->icon());
36 } 38 }
37 39
38 // SimpleMenuModel does not allow two consecutive spacing separator items. 40 // SimpleMenuModel does not allow two consecutive spacing separator items.
39 // This only occurs in tests; users should not see menus with no |items_|. 41 // This only occurs in tests; users should not see menus with no |items_|.
40 if (!items_.empty()) 42 if (!items_.empty())
41 AddSeparator(ui::SPACING_SEPARATOR); 43 AddSeparator(ui::SPACING_SEPARATOR);
42 } 44 }
43 45
44 ShelfApplicationMenuModel::~ShelfApplicationMenuModel() {} 46 ShelfApplicationMenuModel::~ShelfApplicationMenuModel() {}
45 47
46 bool ShelfApplicationMenuModel::IsCommandIdChecked(int command_id) const { 48 bool ShelfApplicationMenuModel::IsCommandIdChecked(int command_id) const {
47 return false; 49 return false;
48 } 50 }
49 51
50 bool ShelfApplicationMenuModel::IsCommandIdEnabled(int command_id) const { 52 bool ShelfApplicationMenuModel::IsCommandIdEnabled(int command_id) const {
51 return command_id >= 0 && static_cast<size_t>(command_id) < items_.size(); 53 return command_id >= 0 && static_cast<size_t>(command_id) < items_.size();
52 } 54 }
53 55
54 void ShelfApplicationMenuModel::ExecuteCommand(int command_id, 56 void ShelfApplicationMenuModel::ExecuteCommand(int command_id,
55 int event_flags) { 57 int event_flags) {
56 DCHECK(IsCommandIdEnabled(command_id)); 58 DCHECK(IsCommandIdEnabled(command_id));
57 items_[command_id]->Execute(event_flags); 59 // Have the delegate execute its own custom command id for the given item.
60 delegate_->ExecuteCommand(items_[command_id]->command_id(), event_flags);
58 RecordMenuItemSelectedMetrics(command_id, items_.size()); 61 RecordMenuItemSelectedMetrics(command_id, items_.size());
59 } 62 }
60 63
61 void ShelfApplicationMenuModel::RecordMenuItemSelectedMetrics( 64 void ShelfApplicationMenuModel::RecordMenuItemSelectedMetrics(
62 int command_id, 65 int command_id,
63 int num_menu_items_enabled) { 66 int num_menu_items_enabled) {
64 UMA_HISTOGRAM_COUNTS_100("Ash.Shelf.Menu.SelectedMenuItemIndex", command_id); 67 UMA_HISTOGRAM_COUNTS_100("Ash.Shelf.Menu.SelectedMenuItemIndex", command_id);
65 UMA_HISTOGRAM_COUNTS_100("Ash.Shelf.Menu.NumItemsEnabledUponSelection", 68 UMA_HISTOGRAM_COUNTS_100("Ash.Shelf.Menu.NumItemsEnabledUponSelection",
66 num_menu_items_enabled); 69 num_menu_items_enabled);
67 } 70 }
68 71
69 } // namespace ash 72 } // namespace ash
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698