| Index: ash/common/shelf/shelf_application_menu_model.cc
|
| diff --git a/ash/common/shelf/shelf_application_menu_model.cc b/ash/common/shelf/shelf_application_menu_model.cc
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..331f0d5e3737ebaf03fe3a461473692a06f0f427
|
| --- /dev/null
|
| +++ b/ash/common/shelf/shelf_application_menu_model.cc
|
| @@ -0,0 +1,69 @@
|
| +// Copyright 2017 The Chromium Authors. All rights reserved.
|
| +// Use of this source code is governed by a BSD-style license that can be
|
| +// found in the LICENSE file.
|
| +
|
| +#include "ash/common/shelf/shelf_application_menu_model.h"
|
| +
|
| +#include <stddef.h>
|
| +
|
| +#include <limits>
|
| +#include <utility>
|
| +
|
| +#include "ash/public/cpp/shelf_application_menu_item.h"
|
| +#include "base/metrics/histogram_macros.h"
|
| +
|
| +namespace {
|
| +
|
| +const int kInvalidCommandId = std::numeric_limits<int>::max();
|
| +
|
| +} // namespace
|
| +
|
| +namespace ash {
|
| +
|
| +ShelfApplicationMenuModel::ShelfApplicationMenuModel(
|
| + const base::string16& title,
|
| + ShelfAppMenuItemList items)
|
| + : ui::SimpleMenuModel(this), items_(std::move(items)) {
|
| + AddSeparator(ui::SPACING_SEPARATOR);
|
| + AddItem(kInvalidCommandId, title);
|
| + AddSeparator(ui::SPACING_SEPARATOR);
|
| +
|
| + for (size_t i = 0; i < items_.size(); i++) {
|
| + ShelfApplicationMenuItem* item = items_[i].get();
|
| + AddItem(i, item->title());
|
| + if (!item->icon().IsEmpty())
|
| + SetIcon(GetIndexOfCommandId(i), item->icon());
|
| + }
|
| +
|
| + // SimpleMenuModel does not allow two consecutive spacing separator items.
|
| + // This only occurs in tests; users should not see menus with no |items_|.
|
| + if (!items_.empty())
|
| + AddSeparator(ui::SPACING_SEPARATOR);
|
| +}
|
| +
|
| +ShelfApplicationMenuModel::~ShelfApplicationMenuModel() {}
|
| +
|
| +bool ShelfApplicationMenuModel::IsCommandIdChecked(int command_id) const {
|
| + return false;
|
| +}
|
| +
|
| +bool ShelfApplicationMenuModel::IsCommandIdEnabled(int command_id) const {
|
| + return command_id >= 0 && static_cast<size_t>(command_id) < items_.size();
|
| +}
|
| +
|
| +void ShelfApplicationMenuModel::ExecuteCommand(int command_id,
|
| + int event_flags) {
|
| + DCHECK(IsCommandIdEnabled(command_id));
|
| + items_[command_id]->Execute(event_flags);
|
| + RecordMenuItemSelectedMetrics(command_id, items_.size());
|
| +}
|
| +
|
| +void ShelfApplicationMenuModel::RecordMenuItemSelectedMetrics(
|
| + int command_id,
|
| + int num_menu_items_enabled) {
|
| + UMA_HISTOGRAM_COUNTS_100("Ash.Shelf.Menu.SelectedMenuItemIndex", command_id);
|
| + UMA_HISTOGRAM_COUNTS_100("Ash.Shelf.Menu.NumItemsEnabledUponSelection",
|
| + num_menu_items_enabled);
|
| +}
|
| +
|
| +} // namespace ash
|
|
|