| OLD | NEW |
| (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 if (!items_.empty()) |
| 39 AddSeparator(ui::SPACING_SEPARATOR); |
| 40 } |
| 41 |
| 42 ShelfApplicationMenuModel::~ShelfApplicationMenuModel() {} |
| 43 |
| 44 bool ShelfApplicationMenuModel::IsCommandIdChecked(int command_id) const { |
| 45 return false; |
| 46 } |
| 47 |
| 48 bool ShelfApplicationMenuModel::IsCommandIdEnabled(int command_id) const { |
| 49 return command_id >= 0 && static_cast<size_t>(command_id) < items_.size(); |
| 50 } |
| 51 |
| 52 void ShelfApplicationMenuModel::ExecuteCommand(int command_id, |
| 53 int event_flags) { |
| 54 DCHECK(IsCommandIdEnabled(command_id)); |
| 55 items_[command_id]->Execute(event_flags); |
| 56 RecordMenuItemSelectedMetrics(command_id, items_.size()); |
| 57 } |
| 58 |
| 59 void ShelfApplicationMenuModel::RecordMenuItemSelectedMetrics( |
| 60 int command_id, |
| 61 int num_menu_items_enabled) { |
| 62 UMA_HISTOGRAM_COUNTS_100("Ash.Shelf.Menu.SelectedMenuItemIndex", command_id); |
| 63 UMA_HISTOGRAM_COUNTS_100("Ash.Shelf.Menu.NumItemsEnabledUponSelection", |
| 64 num_menu_items_enabled); |
| 65 } |
| 66 |
| 67 } // namespace ash |
| OLD | NEW |