File: menu_delegate.cc

package info (click to toggle)
chromium 138.0.7204.183-1
  • links: PTS, VCS
  • area: main
  • in suites: trixie
  • size: 6,071,908 kB
  • sloc: cpp: 34,937,088; ansic: 7,176,967; javascript: 4,110,704; python: 1,419,953; asm: 946,768; xml: 739,971; pascal: 187,324; sh: 89,623; perl: 88,663; objc: 79,944; sql: 50,304; cs: 41,786; fortran: 24,137; makefile: 21,806; php: 13,980; tcl: 13,166; yacc: 8,925; ruby: 7,485; awk: 3,720; lisp: 3,096; lex: 1,327; ada: 727; jsp: 228; sed: 36
file content (167 lines) | stat: -rw-r--r-- 4,601 bytes parent folder | download | duplicates (6)
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
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
// Copyright 2012 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/views/controls/menu/menu_delegate.h"

#include "base/functional/callback_helpers.h"
#include "base/notreached.h"
#include "ui/base/dragdrop/mojom/drag_drop_types.mojom.h"
#include "ui/base/mojom/menu_source_type.mojom-forward.h"
#include "ui/events/event.h"
#include "ui/views/controls/menu/menu_config.h"
#include "ui/views/controls/menu/menu_item_view.h"

namespace views {

MenuDelegate::~MenuDelegate() = default;

bool MenuDelegate::IsItemChecked(int id) const {
  return false;
}

std::u16string MenuDelegate::GetLabel(int id) const {
  return std::u16string();
}

const gfx::FontList* MenuDelegate::GetLabelFontList(int id) const {
  return nullptr;
}

std::optional<SkColor> MenuDelegate::GetLabelColor(int id) const {
  return std::nullopt;
}

std::u16string MenuDelegate::GetTooltipText(
    int id,
    const gfx::Point& screen_loc) const {
  return std::u16string();
}

bool MenuDelegate::GetAccelerator(int id, ui::Accelerator* accelerator) const {
  return false;
}

bool MenuDelegate::ShowContextMenu(MenuItemView* source,
                                   int id,
                                   const gfx::Point& p,
                                   ui::mojom::MenuSourceType source_type) {
  return false;
}

bool MenuDelegate::SupportsCommand(int id) const {
  return true;
}

bool MenuDelegate::IsCommandEnabled(int id) const {
  return true;
}

bool MenuDelegate::IsCommandVisible(int id) const {
  return true;
}

bool MenuDelegate::GetContextualLabel(int id, std::u16string* out) const {
  return false;
}

bool MenuDelegate::ShouldCloseAllMenusOnExecute(int id) {
  return true;
}

void MenuDelegate::ExecuteCommand(int id, int mouse_event_flags) {
  ExecuteCommand(id);
}

bool MenuDelegate::ShouldExecuteCommandWithoutClosingMenu(int id,
                                                          const ui::Event& e) {
  return false;
}

bool MenuDelegate::IsTriggerableEvent(MenuItemView* source,
                                      const ui::Event& e) {
  // By default, a sub-menu is not triggerable.
  // Subclass can override this behavior.
  if (source->GetType() == MenuItemView::Type::kSubMenu) {
    return false;
  }

  // Trigger the action by click or click-like event.
  return e.type() == ui::EventType::kGestureTap ||
         e.type() == ui::EventType::kGestureTapDown ||
         (e.IsMouseEvent() &&
          (e.flags() & (ui::EF_LEFT_MOUSE_BUTTON | ui::EF_RIGHT_MOUSE_BUTTON)));
}

bool MenuDelegate::CanDrop(MenuItemView* menu, const OSExchangeData& data) {
  return false;
}

bool MenuDelegate::GetDropFormats(
    MenuItemView* menu,
    int* formats,
    std::set<ui::ClipboardFormatType>* format_types) {
  return false;
}

bool MenuDelegate::AreDropTypesRequired(MenuItemView* menu) {
  return false;
}

ui::mojom::DragOperation MenuDelegate::GetDropOperation(
    MenuItemView* item,
    const ui::DropTargetEvent& event,
    DropPosition* position) {
  NOTREACHED() << "If you override CanDrop, you must override this too";
}

views::View::DropCallback MenuDelegate::GetDropCallback(
    MenuItemView* menu,
    DropPosition position,
    const ui::DropTargetEvent& event) {
  NOTREACHED() << "If you override CanDrop, you must override this too";
}

bool MenuDelegate::CanDrag(MenuItemView* menu) {
  return false;
}

void MenuDelegate::WriteDragData(MenuItemView* sender, OSExchangeData* data) {
  NOTREACHED() << "If you override CanDrag, you must override this too.";
}

int MenuDelegate::GetDragOperations(MenuItemView* sender) {
  NOTREACHED() << "If you override CanDrag, you must override this too.";
}

bool MenuDelegate::ShouldCloseOnDragComplete() {
  return true;
}

MenuItemView* MenuDelegate::GetSiblingMenu(MenuItemView* menu,
                                           const gfx::Point& screen_point,
                                           MenuAnchorPosition* anchor,
                                           bool* has_mnemonics,
                                           MenuButton** button) {
  return nullptr;
}

int MenuDelegate::GetMaxWidthForMenu(MenuItemView* menu) {
  // NOTE: this needs to be large enough to accommodate the wrench menu with
  // big fonts.
  return 800;
}

void MenuDelegate::WillShowMenu(MenuItemView* menu) {}

void MenuDelegate::WillHideMenu(MenuItemView* menu) {}

bool MenuDelegate::ShouldTryPositioningBesideAnchor() const {
  return true;
}

bool MenuDelegate::IsTearingDown() const {
  return false;
}

}  // namespace views