1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122
|
// Copyright 2011 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "ui/base/models/menu_model.h"
#include "ui/base/models/image_model.h"
#include "ui/base/resource/resource_bundle.h"
namespace ui {
MenuModel::MenuModel() : menu_model_delegate_(nullptr) {}
MenuModel::~MenuModel() {
if (menu_model_delegate_)
menu_model_delegate_->OnMenuClearingDelegate();
}
bool MenuModel::IsVisibleAt(size_t index) const {
return true;
}
bool MenuModel::IsAlertedAt(size_t index) const {
return false;
}
bool MenuModel::IsNewFeatureAt(size_t index) const {
return false;
}
bool MenuModel::GetForceShowAcceleratorForItemAt(size_t index) const {
return false;
}
ElementIdentifier MenuModel::GetElementIdentifierAt(size_t index) const {
return ElementIdentifier();
}
// static
bool MenuModel::GetModelAndIndexForCommandId(int command_id,
MenuModel** model,
size_t* index) {
const size_t item_count = (*model)->GetItemCount();
for (size_t i = 0; i < item_count; ++i) {
const size_t candidate_index = i;
// Actionable submenus have commands.
if ((*model)->GetTypeAt(candidate_index) == TYPE_ACTIONABLE_SUBMENU &&
(*model)->GetCommandIdAt(candidate_index) == command_id) {
*index = candidate_index;
return true;
}
if ((*model)->GetTypeAt(candidate_index) == TYPE_SUBMENU ||
(*model)->GetTypeAt(candidate_index) == TYPE_ACTIONABLE_SUBMENU) {
MenuModel* submenu_model = (*model)->GetSubmenuModelAt(candidate_index);
if (GetModelAndIndexForCommandId(command_id, &submenu_model, index)) {
*model = submenu_model;
return true;
}
}
if ((*model)->GetCommandIdAt(candidate_index) == command_id) {
*index = candidate_index;
return true;
}
}
return false;
}
std::u16string MenuModel::GetMinorTextAt(size_t index) const {
return std::u16string();
}
std::u16string MenuModel::GetSecondaryLabelAt(size_t index) const {
return std::u16string();
}
ImageModel MenuModel::GetMinorIconAt(size_t index) const {
return ImageModel();
}
bool MenuModel::MayHaveMnemonicsAt(size_t index) const {
return true;
}
std::u16string MenuModel::GetAccessibleNameAt(size_t index) const {
return std::u16string();
}
const gfx::FontList* MenuModel::GetLabelFontListAt(size_t index) const {
return (GetTypeAt(index) == ui::MenuModel::TYPE_TITLE)
? &ui::ResourceBundle::GetSharedInstance().GetFontList(
ui::ResourceBundle::BoldFont)
: nullptr;
}
// Default implementation ignores the event flags.
void MenuModel::ActivatedAt(size_t index, int event_flags) {
ActivatedAt(index);
}
void MenuModel::SetMenuModelDelegate(MenuModelDelegate* delegate) {
// A non-null delegate overwriting our non-null delegate is not allowed.
DCHECK(!(menu_model_delegate_ && delegate));
if (menu_model_delegate_)
menu_model_delegate_->OnMenuClearingDelegate();
menu_model_delegate_ = delegate;
}
std::optional<ui::ColorId> MenuModel::GetForegroundColorId(size_t index) {
return std::nullopt;
}
std::optional<ui::ColorId> MenuModel::GetSubmenuBackgroundColorId(
size_t index) {
return std::nullopt;
}
std::optional<ui::ColorId> MenuModel::GetSelectedBackgroundColorId(
size_t index) {
return std::nullopt;
}
} // namespace ui
|