1 // Copyright (c) 2012 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 "ui/views/controls/menu/menu_delegate.h"
6
7 #include "ui/events/event.h"
8 #include "ui/views/controls/menu/menu_config.h"
9
10 namespace views {
11
12 MenuDelegate::~MenuDelegate() = default;
13
IsItemChecked(int id) const14 bool MenuDelegate::IsItemChecked(int id) const {
15 return false;
16 }
17
GetLabel(int id) const18 base::string16 MenuDelegate::GetLabel(int id) const {
19 return base::string16();
20 }
21
GetLabelStyle(int id,LabelStyle * style) const22 void MenuDelegate::GetLabelStyle(int id, LabelStyle* style) const {}
23
GetTooltipText(int id,const gfx::Point & screen_loc) const24 base::string16 MenuDelegate::GetTooltipText(
25 int id,
26 const gfx::Point& screen_loc) const {
27 return base::string16();
28 }
29
GetAccelerator(int id,ui::Accelerator * accelerator) const30 bool MenuDelegate::GetAccelerator(int id, ui::Accelerator* accelerator) const {
31 return false;
32 }
33
ShowContextMenu(MenuItemView * source,int id,const gfx::Point & p,ui::MenuSourceType source_type)34 bool MenuDelegate::ShowContextMenu(MenuItemView* source,
35 int id,
36 const gfx::Point& p,
37 ui::MenuSourceType source_type) {
38 return false;
39 }
40
SupportsCommand(int id) const41 bool MenuDelegate::SupportsCommand(int id) const {
42 return true;
43 }
44
IsCommandEnabled(int id) const45 bool MenuDelegate::IsCommandEnabled(int id) const {
46 return true;
47 }
48
IsCommandVisible(int id) const49 bool MenuDelegate::IsCommandVisible(int id) const {
50 return true;
51 }
52
GetContextualLabel(int id,base::string16 * out) const53 bool MenuDelegate::GetContextualLabel(int id, base::string16* out) const {
54 return false;
55 }
56
ShouldCloseAllMenusOnExecute(int id)57 bool MenuDelegate::ShouldCloseAllMenusOnExecute(int id) {
58 return true;
59 }
60
ExecuteCommand(int id,int mouse_event_flags)61 void MenuDelegate::ExecuteCommand(int id, int mouse_event_flags) {
62 ExecuteCommand(id);
63 }
64
ShouldExecuteCommandWithoutClosingMenu(int id,const ui::Event & e)65 bool MenuDelegate::ShouldExecuteCommandWithoutClosingMenu(int id,
66 const ui::Event& e) {
67 return false;
68 }
69
IsTriggerableEvent(MenuItemView * source,const ui::Event & e)70 bool MenuDelegate::IsTriggerableEvent(MenuItemView* source,
71 const ui::Event& e) {
72 return e.type() == ui::ET_GESTURE_TAP ||
73 e.type() == ui::ET_GESTURE_TAP_DOWN ||
74 (e.IsMouseEvent() &&
75 (e.flags() & (ui::EF_LEFT_MOUSE_BUTTON | ui::EF_RIGHT_MOUSE_BUTTON)));
76 }
77
CanDrop(MenuItemView * menu,const OSExchangeData & data)78 bool MenuDelegate::CanDrop(MenuItemView* menu, const OSExchangeData& data) {
79 return false;
80 }
81
GetDropFormats(MenuItemView * menu,int * formats,std::set<ui::ClipboardFormatType> * format_types)82 bool MenuDelegate::GetDropFormats(
83 MenuItemView* menu,
84 int* formats,
85 std::set<ui::ClipboardFormatType>* format_types) {
86 return false;
87 }
88
AreDropTypesRequired(MenuItemView * menu)89 bool MenuDelegate::AreDropTypesRequired(MenuItemView* menu) {
90 return false;
91 }
92
GetDropOperation(MenuItemView * item,const ui::DropTargetEvent & event,DropPosition * position)93 int MenuDelegate::GetDropOperation(MenuItemView* item,
94 const ui::DropTargetEvent& event,
95 DropPosition* position) {
96 NOTREACHED() << "If you override CanDrop, you need to override this too";
97 return ui::DragDropTypes::DRAG_NONE;
98 }
99
OnPerformDrop(MenuItemView * menu,DropPosition position,const ui::DropTargetEvent & event)100 int MenuDelegate::OnPerformDrop(MenuItemView* menu,
101 DropPosition position,
102 const ui::DropTargetEvent& event) {
103 NOTREACHED() << "If you override CanDrop, you need to override this too";
104 return ui::DragDropTypes::DRAG_NONE;
105 }
106
CanDrag(MenuItemView * menu)107 bool MenuDelegate::CanDrag(MenuItemView* menu) {
108 return false;
109 }
110
WriteDragData(MenuItemView * sender,OSExchangeData * data)111 void MenuDelegate::WriteDragData(MenuItemView* sender, OSExchangeData* data) {
112 NOTREACHED() << "If you override CanDrag, you must override this too.";
113 }
114
GetDragOperations(MenuItemView * sender)115 int MenuDelegate::GetDragOperations(MenuItemView* sender) {
116 NOTREACHED() << "If you override CanDrag, you must override this too.";
117 return 0;
118 }
119
ShouldCloseOnDragComplete()120 bool MenuDelegate::ShouldCloseOnDragComplete() {
121 return true;
122 }
123
GetSiblingMenu(MenuItemView * menu,const gfx::Point & screen_point,MenuAnchorPosition * anchor,bool * has_mnemonics,MenuButton ** button)124 MenuItemView* MenuDelegate::GetSiblingMenu(MenuItemView* menu,
125 const gfx::Point& screen_point,
126 MenuAnchorPosition* anchor,
127 bool* has_mnemonics,
128 MenuButton** button) {
129 return nullptr;
130 }
131
GetMaxWidthForMenu(MenuItemView * menu)132 int MenuDelegate::GetMaxWidthForMenu(MenuItemView* menu) {
133 // NOTE: this needs to be large enough to accommodate the wrench menu with
134 // big fonts.
135 return 800;
136 }
137
WillShowMenu(MenuItemView * menu)138 void MenuDelegate::WillShowMenu(MenuItemView* menu) {}
139
WillHideMenu(MenuItemView * menu)140 void MenuDelegate::WillHideMenu(MenuItemView* menu) {}
141
GetHorizontalIconMargins(int command_id,int icon_size,int * left_margin,int * right_margin) const142 void MenuDelegate::GetHorizontalIconMargins(int command_id,
143 int icon_size,
144 int* left_margin,
145 int* right_margin) const {
146 *left_margin = 0;
147 *right_margin = 0;
148 }
149
ShouldReserveSpaceForSubmenuIndicator() const150 bool MenuDelegate::ShouldReserveSpaceForSubmenuIndicator() const {
151 return true;
152 }
153
ShouldTryPositioningBesideAnchor() const154 bool MenuDelegate::ShouldTryPositioningBesideAnchor() const {
155 return true;
156 }
157
158 } // namespace views
159