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