Molybden
Loading...
Searching...
No Matches
context_menu.hpp
1// Copyright (c) 2000-2023 TeamDev Ltd. All rights reserved.
2// TeamDev PROPRIETARY and CONFIDENTIAL.
3// Use is subject to license terms.
4
5#ifndef MOLYBDEN_CONTEXT_MENU_HPP
6#define MOLYBDEN_CONTEXT_MENU_HPP
7
8#include <functional>
9#include <memory>
10#include <string>
11#include <vector>
12
13namespace molybden {
14
15class Browser;
16
18 bool is_page = false;
19 bool is_frame = false;
20 bool is_link = false;
21 bool is_image = false;
22 bool is_video = false;
23 bool is_audio = false;
24 bool is_canvas = false;
25 bool is_editable = false;
26};
27
28enum class ContextMenuItemType {
29 kStandardContextMenuItem,
30 kCustomContextMenu,
31 kCustomContextMenuItem,
32 kSeparator
33};
34
36 public:
37 ContextMenuItemType type() const;
38
39 protected:
40 explicit ContextMenuItem(ContextMenuItemType type);
41
42 private:
43 ContextMenuItemType type_;
44};
45
47 public:
48 static std::shared_ptr<SeparatorContextMenuItem> create();
49 static std::shared_ptr<SeparatorContextMenuItem> cast(
50 std::shared_ptr<ContextMenuItem> item);
51
52 explicit SeparatorContextMenuItem();
53};
54
55using ContextMenuItems = std::vector<std::shared_ptr<ContextMenuItem>>;
56
58 public:
59 ContextMenuItems items() const;
60
61 protected:
62 ContextMenu(ContextMenuItemType type, ContextMenuItems items);
63
64 private:
65 ContextMenuItems items_;
66};
67
69 public:
70 static std::shared_ptr<CustomContextMenu> create(ContextMenuItems items);
71 static std::shared_ptr<CustomContextMenu> create(std::string title,
72 ContextMenuItems items);
73 static std::shared_ptr<CustomContextMenu> cast(
74 std::shared_ptr<ContextMenuItem> item);
75
76 CustomContextMenu(std::string title, ContextMenuItems items);
77 std::string title() const;
78
79 private:
80 std::string title_;
81};
82
84
85using CustomContextMenuItemAction =
86 std::function<void(std::shared_ptr<Browser>,
87 // ContextMenuItemParams?
88 std::shared_ptr<CustomContextMenuItem>)>;
89
91 public:
92 static std::shared_ptr<CustomContextMenuItem> create(
93 std::string title,
94 CustomContextMenuItemAction action,
95 bool enabled = true);
96 static std::shared_ptr<CustomContextMenuItem> cast(
97 std::shared_ptr<ContextMenuItem> item);
98 static std::shared_ptr<CustomContextMenuItem> fromId(int32_t id);
99
100 CustomContextMenuItem(std::string title,
101 CustomContextMenuItemAction action,
102 bool enabled = true);
103
104 int32_t id() const;
105 std::string title() const;
106 bool isEnabled() const;
107 CustomContextMenuItemAction action() const;
108
109 protected:
110 CustomContextMenuItem(ContextMenuItemType type,
111 std::string title,
112 CustomContextMenuItemAction action,
113 bool enabled = true);
114
115 private:
116 int32_t id_ = 0;
117 std::string title_;
118 bool enabled_ = true;
119 CustomContextMenuItemAction action_ = nullptr;
120};
121
122enum class StandardContextMenuItemCommandId {
123 // Page context menu items.
124 kGoBack,
125 kGoForward,
126 kReload,
127 kSavePageAs,
128 kPrint,
129 kExitFullScreen,
130 kInspectElement,
131
132 // Link context menu items.
133 kSaveLinkAs,
134 kCopyLinkAddress,
135 kCopyEmailAddress,
136
137 // Image context menu items.
138 kSaveImageAs,
139 kCopyImageAddress,
140 kCopyImage,
141
142 // Audio context menu items.
143 kSaveAudioAs,
144 kCopyAudioLocation,
145
146 // Video context menu items.
147 kSaveVideoAs,
148 kCopyVideoLocation,
149 kPictureInPicture,
150
151 // Media context menu items.
152 kLoop,
153 kControls,
154 kRotateCW,
155 kRotateCCW,
156
157 // Frame context menu items.
158 kReloadFrame,
159 kViewFrameSource,
160
161 // Editable context menu items.
162 kUndo,
163 kRedo,
164 kCut,
165 kCopy,
166 kPaste,
167 kPasteAndMatchStyle,
168 kSelectAll
169};
170
172 public:
173 static std::shared_ptr<StandardContextMenuItem> create(
174 StandardContextMenuItemCommandId id);
175 static std::shared_ptr<StandardContextMenuItem> cast(
176 std::shared_ptr<ContextMenuItem> item);
177
178 explicit StandardContextMenuItem(StandardContextMenuItemCommandId command_id);
179
180 StandardContextMenuItemCommandId commandId() const;
181
182 private:
183 StandardContextMenuItemCommandId command_id_;
184};
185
186namespace context_menu {
187
188std::shared_ptr<SeparatorContextMenuItem> Separator();
189std::shared_ptr<CustomContextMenu> Menu(std::string title,
190 ContextMenuItems items);
191std::shared_ptr<CustomContextMenu> Menu(ContextMenuItems items);
192std::shared_ptr<CustomContextMenuItem> Item(std::string title,
193 CustomContextMenuItemAction action,
194 bool enabled = true);
195
196std::shared_ptr<StandardContextMenuItem> GoBack();
197std::shared_ptr<StandardContextMenuItem> GoForward();
198std::shared_ptr<StandardContextMenuItem> Reload();
199std::shared_ptr<StandardContextMenuItem> SavePageAs();
200std::shared_ptr<StandardContextMenuItem> Print();
201std::shared_ptr<StandardContextMenuItem> ExitFullScreen();
202std::shared_ptr<StandardContextMenuItem> InspectElement();
203
204std::shared_ptr<StandardContextMenuItem> SaveLinkAs();
205std::shared_ptr<StandardContextMenuItem> CopyLinkAddress();
206std::shared_ptr<StandardContextMenuItem> CopyEmailAddress();
207
208std::shared_ptr<StandardContextMenuItem> SaveImageAs();
209std::shared_ptr<StandardContextMenuItem> CopyImageAddress();
210std::shared_ptr<StandardContextMenuItem> CopyImage();
211
212std::shared_ptr<StandardContextMenuItem> SaveAudioAs();
213std::shared_ptr<StandardContextMenuItem> CopyAudioLocation();
214
215std::shared_ptr<StandardContextMenuItem> SaveVideoAs();
216std::shared_ptr<StandardContextMenuItem> CopyVideoLocation();
217std::shared_ptr<StandardContextMenuItem> PictureInPicture();
218
219std::shared_ptr<StandardContextMenuItem> Loop();
220std::shared_ptr<StandardContextMenuItem> Controls();
221std::shared_ptr<StandardContextMenuItem> RotateCW();
222std::shared_ptr<StandardContextMenuItem> RotateCCW();
223
224std::shared_ptr<StandardContextMenuItem> ReloadFrame();
225std::shared_ptr<StandardContextMenuItem> ViewFrameSource();
226
227std::shared_ptr<StandardContextMenuItem> Undo();
228std::shared_ptr<StandardContextMenuItem> Redo();
229std::shared_ptr<StandardContextMenuItem> Cut();
230std::shared_ptr<StandardContextMenuItem> Copy();
231std::shared_ptr<StandardContextMenuItem> Paste();
232std::shared_ptr<StandardContextMenuItem> PasteAndMatchStyle();
233std::shared_ptr<StandardContextMenuItem> SelectAll();
234} // namespace context_menu
235} // namespace molybden
236
237#endif // MOLYBDEN_CONTEXT_MENU_HPP
Definition context_menu.hpp:57
Definition context_menu.hpp:35
Definition context_menu.hpp:68
Definition context_menu.hpp:90
Definition menu.hpp:47
Definition context_menu.hpp:46
Definition context_menu.hpp:171
Definition context_menu.hpp:17