1/*
2 * Copyright (C) 2012 Igalia S.L.
3 *
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Library General Public
6 * License as published by the Free Software Foundation; either
7 * version 2 of the License, or (at your option) any later version.
8 *
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Library General Public License for more details.
13 *
14 * You should have received a copy of the GNU Library General Public License
15 * along with this library; see the file COPYING.LIB. If not, write to
16 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17 * Boston, MA 02110-1301, USA.
18 */
19
20#include "config.h"
21#include "WebKitContextMenuActions.h"
22
23#include "WebKitContextMenuActionsPrivate.h"
24#include <WebCore/LocalizedStrings.h>
25
26using namespace WebCore;
27
28bool webkitContextMenuActionIsCheckable(WebKitContextMenuAction action)
29{
30 switch (action) {
31 case WEBKIT_CONTEXT_MENU_ACTION_BOLD:
32 case WEBKIT_CONTEXT_MENU_ACTION_ITALIC:
33 case WEBKIT_CONTEXT_MENU_ACTION_UNDERLINE:
34 case WEBKIT_CONTEXT_MENU_ACTION_TOGGLE_MEDIA_CONTROLS:
35 case WEBKIT_CONTEXT_MENU_ACTION_TOGGLE_MEDIA_LOOP:
36 return true;
37 default:
38 return false;
39 }
40}
41
42ContextMenuAction webkitContextMenuActionGetActionTag(WebKitContextMenuAction action)
43{
44 switch (action) {
45 case WEBKIT_CONTEXT_MENU_ACTION_NO_ACTION:
46 return ContextMenuItemTagNoAction;
47 case WEBKIT_CONTEXT_MENU_ACTION_OPEN_LINK:
48 return ContextMenuItemTagOpenLink;
49 case WEBKIT_CONTEXT_MENU_ACTION_OPEN_LINK_IN_NEW_WINDOW:
50 return ContextMenuItemTagOpenLinkInNewWindow;
51 case WEBKIT_CONTEXT_MENU_ACTION_DOWNLOAD_LINK_TO_DISK:
52 return ContextMenuItemTagDownloadLinkToDisk;
53 case WEBKIT_CONTEXT_MENU_ACTION_COPY_LINK_TO_CLIPBOARD:
54 return ContextMenuItemTagCopyLinkToClipboard;
55 case WEBKIT_CONTEXT_MENU_ACTION_OPEN_IMAGE_IN_NEW_WINDOW:
56 return ContextMenuItemTagOpenImageInNewWindow;
57 case WEBKIT_CONTEXT_MENU_ACTION_DOWNLOAD_IMAGE_TO_DISK:
58 return ContextMenuItemTagDownloadImageToDisk;
59 case WEBKIT_CONTEXT_MENU_ACTION_COPY_IMAGE_TO_CLIPBOARD:
60 return ContextMenuItemTagCopyImageToClipboard;
61#if PLATFORM(GTK)
62 case WEBKIT_CONTEXT_MENU_ACTION_COPY_IMAGE_URL_TO_CLIPBOARD:
63 return ContextMenuItemTagCopyImageUrlToClipboard;
64#endif
65 case WEBKIT_CONTEXT_MENU_ACTION_OPEN_FRAME_IN_NEW_WINDOW:
66 return ContextMenuItemTagOpenFrameInNewWindow;
67 case WEBKIT_CONTEXT_MENU_ACTION_GO_BACK:
68 return ContextMenuItemTagGoBack;
69 case WEBKIT_CONTEXT_MENU_ACTION_GO_FORWARD:
70 return ContextMenuItemTagGoForward;
71 case WEBKIT_CONTEXT_MENU_ACTION_STOP:
72 return ContextMenuItemTagStop;
73 case WEBKIT_CONTEXT_MENU_ACTION_RELOAD:
74 return ContextMenuItemTagReload;
75 case WEBKIT_CONTEXT_MENU_ACTION_COPY:
76 return ContextMenuItemTagCopy;
77 case WEBKIT_CONTEXT_MENU_ACTION_CUT:
78 return ContextMenuItemTagCut;
79 case WEBKIT_CONTEXT_MENU_ACTION_PASTE:
80 return ContextMenuItemTagPaste;
81#if PLATFORM(GTK)
82 case WEBKIT_CONTEXT_MENU_ACTION_DELETE:
83 return ContextMenuItemTagDelete;
84 case WEBKIT_CONTEXT_MENU_ACTION_SELECT_ALL:
85 return ContextMenuItemTagSelectAll;
86 case WEBKIT_CONTEXT_MENU_ACTION_INSERT_EMOJI:
87 return ContextMenuItemTagInsertEmoji;
88 case WEBKIT_CONTEXT_MENU_ACTION_INPUT_METHODS:
89 return ContextMenuItemTagInputMethods;
90 case WEBKIT_CONTEXT_MENU_ACTION_UNICODE:
91 return ContextMenuItemTagUnicode;
92#endif
93 case WEBKIT_CONTEXT_MENU_ACTION_SPELLING_GUESS:
94 return ContextMenuItemTagSpellingGuess;
95 case WEBKIT_CONTEXT_MENU_ACTION_NO_GUESSES_FOUND:
96 return ContextMenuItemTagNoGuessesFound;
97 case WEBKIT_CONTEXT_MENU_ACTION_IGNORE_SPELLING:
98 return ContextMenuItemTagIgnoreSpelling;
99 case WEBKIT_CONTEXT_MENU_ACTION_LEARN_SPELLING:
100 return ContextMenuItemTagLearnSpelling;
101 case WEBKIT_CONTEXT_MENU_ACTION_IGNORE_GRAMMAR:
102 return ContextMenuItemTagIgnoreGrammar;
103 case WEBKIT_CONTEXT_MENU_ACTION_FONT_MENU:
104 return ContextMenuItemTagFontMenu;
105 case WEBKIT_CONTEXT_MENU_ACTION_BOLD:
106 return ContextMenuItemTagBold;
107 case WEBKIT_CONTEXT_MENU_ACTION_ITALIC:
108 return ContextMenuItemTagItalic;
109 case WEBKIT_CONTEXT_MENU_ACTION_UNDERLINE:
110 return ContextMenuItemTagUnderline;
111 case WEBKIT_CONTEXT_MENU_ACTION_OUTLINE:
112 return ContextMenuItemTagOutline;
113 case WEBKIT_CONTEXT_MENU_ACTION_INSPECT_ELEMENT:
114 return ContextMenuItemTagInspectElement;
115 case WEBKIT_CONTEXT_MENU_ACTION_OPEN_VIDEO_IN_NEW_WINDOW:
116 case WEBKIT_CONTEXT_MENU_ACTION_OPEN_AUDIO_IN_NEW_WINDOW:
117 return ContextMenuItemTagOpenMediaInNewWindow;
118 case WEBKIT_CONTEXT_MENU_ACTION_COPY_VIDEO_LINK_TO_CLIPBOARD:
119 case WEBKIT_CONTEXT_MENU_ACTION_COPY_AUDIO_LINK_TO_CLIPBOARD:
120 return ContextMenuItemTagCopyMediaLinkToClipboard;
121 case WEBKIT_CONTEXT_MENU_ACTION_TOGGLE_MEDIA_CONTROLS:
122 return ContextMenuItemTagToggleMediaControls;
123 case WEBKIT_CONTEXT_MENU_ACTION_TOGGLE_MEDIA_LOOP:
124 return ContextMenuItemTagToggleMediaLoop;
125 case WEBKIT_CONTEXT_MENU_ACTION_ENTER_VIDEO_FULLSCREEN:
126 return ContextMenuItemTagEnterVideoFullscreen;
127 case WEBKIT_CONTEXT_MENU_ACTION_MEDIA_PLAY:
128 case WEBKIT_CONTEXT_MENU_ACTION_MEDIA_PAUSE:
129 return ContextMenuItemTagMediaPlayPause;
130 case WEBKIT_CONTEXT_MENU_ACTION_MEDIA_MUTE:
131 return ContextMenuItemTagMediaMute;
132 case WEBKIT_CONTEXT_MENU_ACTION_DOWNLOAD_VIDEO_TO_DISK:
133 case WEBKIT_CONTEXT_MENU_ACTION_DOWNLOAD_AUDIO_TO_DISK:
134 return ContextMenuItemTagDownloadMediaToDisk;
135 case WEBKIT_CONTEXT_MENU_ACTION_CUSTOM:
136 return ContextMenuItemBaseApplicationTag;
137 default:
138 ASSERT_NOT_REACHED();
139 }
140
141 return ContextMenuItemBaseApplicationTag;
142}
143
144WebKitContextMenuAction webkitContextMenuActionGetForContextMenuItem(const WebKit::WebContextMenuItemGlib& menuItem)
145{
146 switch (menuItem.action()) {
147 case ContextMenuItemTagNoAction:
148 return WEBKIT_CONTEXT_MENU_ACTION_NO_ACTION;
149 case ContextMenuItemTagOpenLink:
150 return WEBKIT_CONTEXT_MENU_ACTION_OPEN_LINK;
151 case ContextMenuItemTagOpenLinkInNewWindow:
152 return WEBKIT_CONTEXT_MENU_ACTION_OPEN_LINK_IN_NEW_WINDOW;
153 case ContextMenuItemTagDownloadLinkToDisk:
154 return WEBKIT_CONTEXT_MENU_ACTION_DOWNLOAD_LINK_TO_DISK;
155 case ContextMenuItemTagCopyLinkToClipboard:
156 return WEBKIT_CONTEXT_MENU_ACTION_COPY_LINK_TO_CLIPBOARD;
157 case ContextMenuItemTagOpenImageInNewWindow:
158 return WEBKIT_CONTEXT_MENU_ACTION_OPEN_IMAGE_IN_NEW_WINDOW;
159 case ContextMenuItemTagDownloadImageToDisk:
160 return WEBKIT_CONTEXT_MENU_ACTION_DOWNLOAD_IMAGE_TO_DISK;
161 case ContextMenuItemTagCopyImageToClipboard:
162 return WEBKIT_CONTEXT_MENU_ACTION_COPY_IMAGE_TO_CLIPBOARD;
163#if PLATFORM(GTK)
164 case ContextMenuItemTagCopyImageUrlToClipboard:
165 return WEBKIT_CONTEXT_MENU_ACTION_COPY_IMAGE_URL_TO_CLIPBOARD;
166#endif
167 case ContextMenuItemTagOpenFrameInNewWindow:
168 return WEBKIT_CONTEXT_MENU_ACTION_OPEN_FRAME_IN_NEW_WINDOW;
169 case ContextMenuItemTagGoBack:
170 return WEBKIT_CONTEXT_MENU_ACTION_GO_BACK;
171 case ContextMenuItemTagGoForward:
172 return WEBKIT_CONTEXT_MENU_ACTION_GO_FORWARD;
173 case ContextMenuItemTagStop:
174 return WEBKIT_CONTEXT_MENU_ACTION_STOP;
175 case ContextMenuItemTagReload:
176 return WEBKIT_CONTEXT_MENU_ACTION_RELOAD;
177 case ContextMenuItemTagCopy:
178 return WEBKIT_CONTEXT_MENU_ACTION_COPY;
179 case ContextMenuItemTagCut:
180 return WEBKIT_CONTEXT_MENU_ACTION_CUT;
181 case ContextMenuItemTagPaste:
182 return WEBKIT_CONTEXT_MENU_ACTION_PASTE;
183#if PLATFORM(GTK)
184 case ContextMenuItemTagDelete:
185 return WEBKIT_CONTEXT_MENU_ACTION_DELETE;
186 case ContextMenuItemTagSelectAll:
187 return WEBKIT_CONTEXT_MENU_ACTION_SELECT_ALL;
188 case ContextMenuItemTagInsertEmoji:
189 return WEBKIT_CONTEXT_MENU_ACTION_INSERT_EMOJI;
190 case ContextMenuItemTagInputMethods:
191 return WEBKIT_CONTEXT_MENU_ACTION_INPUT_METHODS;
192 case ContextMenuItemTagUnicode:
193 return WEBKIT_CONTEXT_MENU_ACTION_UNICODE;
194#endif
195 case ContextMenuItemTagSpellingGuess:
196 return WEBKIT_CONTEXT_MENU_ACTION_SPELLING_GUESS;
197 case ContextMenuItemTagNoGuessesFound:
198 return WEBKIT_CONTEXT_MENU_ACTION_NO_GUESSES_FOUND;
199 case ContextMenuItemTagIgnoreSpelling:
200 return WEBKIT_CONTEXT_MENU_ACTION_IGNORE_SPELLING;
201 case ContextMenuItemTagLearnSpelling:
202 return WEBKIT_CONTEXT_MENU_ACTION_LEARN_SPELLING;
203 case ContextMenuItemTagIgnoreGrammar:
204 return WEBKIT_CONTEXT_MENU_ACTION_IGNORE_GRAMMAR;
205 case ContextMenuItemTagFontMenu:
206 return WEBKIT_CONTEXT_MENU_ACTION_FONT_MENU;
207 case ContextMenuItemTagBold:
208 return WEBKIT_CONTEXT_MENU_ACTION_BOLD;
209 case ContextMenuItemTagItalic:
210 return WEBKIT_CONTEXT_MENU_ACTION_ITALIC;
211 case ContextMenuItemTagUnderline:
212 return WEBKIT_CONTEXT_MENU_ACTION_UNDERLINE;
213 case ContextMenuItemTagOutline:
214 return WEBKIT_CONTEXT_MENU_ACTION_OUTLINE;
215 case ContextMenuItemTagInspectElement:
216 return WEBKIT_CONTEXT_MENU_ACTION_INSPECT_ELEMENT;
217 case ContextMenuItemTagOpenMediaInNewWindow:
218 return menuItem.title() == contextMenuItemTagOpenVideoInNewWindow() ?
219 WEBKIT_CONTEXT_MENU_ACTION_OPEN_VIDEO_IN_NEW_WINDOW : WEBKIT_CONTEXT_MENU_ACTION_OPEN_AUDIO_IN_NEW_WINDOW;
220 case ContextMenuItemTagCopyMediaLinkToClipboard:
221 return menuItem.title() == contextMenuItemTagCopyVideoLinkToClipboard() ?
222 WEBKIT_CONTEXT_MENU_ACTION_COPY_VIDEO_LINK_TO_CLIPBOARD : WEBKIT_CONTEXT_MENU_ACTION_COPY_AUDIO_LINK_TO_CLIPBOARD;
223 case ContextMenuItemTagToggleMediaControls:
224 return WEBKIT_CONTEXT_MENU_ACTION_TOGGLE_MEDIA_CONTROLS;
225 case ContextMenuItemTagToggleMediaLoop:
226 return WEBKIT_CONTEXT_MENU_ACTION_TOGGLE_MEDIA_LOOP;
227 case ContextMenuItemTagEnterVideoFullscreen:
228 return WEBKIT_CONTEXT_MENU_ACTION_ENTER_VIDEO_FULLSCREEN;
229 case ContextMenuItemTagMediaPlayPause:
230 return menuItem.title() == contextMenuItemTagMediaPlay() ?
231 WEBKIT_CONTEXT_MENU_ACTION_MEDIA_PLAY : WEBKIT_CONTEXT_MENU_ACTION_MEDIA_PAUSE;
232 case ContextMenuItemTagMediaMute:
233 return WEBKIT_CONTEXT_MENU_ACTION_MEDIA_MUTE;
234 case ContextMenuItemTagDownloadMediaToDisk:
235 return menuItem.title() == contextMenuItemTagDownloadVideoToDisk() ?
236 WEBKIT_CONTEXT_MENU_ACTION_DOWNLOAD_VIDEO_TO_DISK : WEBKIT_CONTEXT_MENU_ACTION_DOWNLOAD_AUDIO_TO_DISK;
237 case ContextMenuItemBaseApplicationTag:
238 return WEBKIT_CONTEXT_MENU_ACTION_CUSTOM;
239 default:
240 ASSERT_NOT_REACHED();
241 }
242
243 return WEBKIT_CONTEXT_MENU_ACTION_CUSTOM;
244}
245
246String webkitContextMenuActionGetLabel(WebKitContextMenuAction action)
247{
248 switch (action) {
249 case WEBKIT_CONTEXT_MENU_ACTION_OPEN_LINK:
250 return contextMenuItemTagOpenLink();
251 case WEBKIT_CONTEXT_MENU_ACTION_OPEN_LINK_IN_NEW_WINDOW:
252 return contextMenuItemTagOpenLinkInNewWindow();
253 case WEBKIT_CONTEXT_MENU_ACTION_DOWNLOAD_LINK_TO_DISK:
254 return contextMenuItemTagDownloadLinkToDisk();
255 case WEBKIT_CONTEXT_MENU_ACTION_COPY_LINK_TO_CLIPBOARD:
256 return contextMenuItemTagCopyLinkToClipboard();
257 case WEBKIT_CONTEXT_MENU_ACTION_OPEN_IMAGE_IN_NEW_WINDOW:
258 return contextMenuItemTagOpenImageInNewWindow();
259 case WEBKIT_CONTEXT_MENU_ACTION_DOWNLOAD_IMAGE_TO_DISK:
260 return contextMenuItemTagDownloadImageToDisk();
261 case WEBKIT_CONTEXT_MENU_ACTION_COPY_IMAGE_TO_CLIPBOARD:
262 return contextMenuItemTagCopyImageToClipboard();
263#if PLATFORM(GTK)
264 case WEBKIT_CONTEXT_MENU_ACTION_COPY_IMAGE_URL_TO_CLIPBOARD:
265 return contextMenuItemTagCopyImageUrlToClipboard();
266#endif
267 case WEBKIT_CONTEXT_MENU_ACTION_OPEN_FRAME_IN_NEW_WINDOW:
268 return contextMenuItemTagOpenFrameInNewWindow();
269 case WEBKIT_CONTEXT_MENU_ACTION_GO_BACK:
270 return contextMenuItemTagGoBack();
271 case WEBKIT_CONTEXT_MENU_ACTION_GO_FORWARD:
272 return contextMenuItemTagGoForward();
273 case WEBKIT_CONTEXT_MENU_ACTION_STOP:
274 return contextMenuItemTagStop();
275 case WEBKIT_CONTEXT_MENU_ACTION_RELOAD:
276 return contextMenuItemTagReload();
277 case WEBKIT_CONTEXT_MENU_ACTION_COPY:
278 return contextMenuItemTagCopy();
279 case WEBKIT_CONTEXT_MENU_ACTION_CUT:
280 return contextMenuItemTagCut();
281 case WEBKIT_CONTEXT_MENU_ACTION_PASTE:
282 return contextMenuItemTagPaste();
283#if PLATFORM(GTK)
284 case WEBKIT_CONTEXT_MENU_ACTION_DELETE:
285 return contextMenuItemTagDelete();
286 case WEBKIT_CONTEXT_MENU_ACTION_SELECT_ALL:
287 return contextMenuItemTagSelectAll();
288 case WEBKIT_CONTEXT_MENU_ACTION_INSERT_EMOJI:
289 return contextMenuItemTagInsertEmoji();
290 case WEBKIT_CONTEXT_MENU_ACTION_INPUT_METHODS:
291 return contextMenuItemTagInputMethods();
292 case WEBKIT_CONTEXT_MENU_ACTION_UNICODE:
293 return contextMenuItemTagUnicode();
294#endif
295 case WEBKIT_CONTEXT_MENU_ACTION_NO_GUESSES_FOUND:
296 return contextMenuItemTagNoGuessesFound();
297 case WEBKIT_CONTEXT_MENU_ACTION_IGNORE_SPELLING:
298 return contextMenuItemTagIgnoreSpelling();
299 case WEBKIT_CONTEXT_MENU_ACTION_LEARN_SPELLING:
300 return contextMenuItemTagLearnSpelling();
301 case WEBKIT_CONTEXT_MENU_ACTION_IGNORE_GRAMMAR:
302 return contextMenuItemTagIgnoreGrammar();
303 case WEBKIT_CONTEXT_MENU_ACTION_FONT_MENU:
304 return contextMenuItemTagFontMenu();
305 case WEBKIT_CONTEXT_MENU_ACTION_BOLD:
306 return contextMenuItemTagBold();
307 case WEBKIT_CONTEXT_MENU_ACTION_ITALIC:
308 return contextMenuItemTagItalic();
309 case WEBKIT_CONTEXT_MENU_ACTION_UNDERLINE:
310 return contextMenuItemTagUnderline();
311 case WEBKIT_CONTEXT_MENU_ACTION_OUTLINE:
312 return contextMenuItemTagOutline();
313 case WEBKIT_CONTEXT_MENU_ACTION_INSPECT_ELEMENT:
314 return contextMenuItemTagInspectElement();
315 case WEBKIT_CONTEXT_MENU_ACTION_OPEN_VIDEO_IN_NEW_WINDOW:
316 return contextMenuItemTagOpenVideoInNewWindow();
317 case WEBKIT_CONTEXT_MENU_ACTION_OPEN_AUDIO_IN_NEW_WINDOW:
318 return contextMenuItemTagOpenAudioInNewWindow();
319 case WEBKIT_CONTEXT_MENU_ACTION_COPY_VIDEO_LINK_TO_CLIPBOARD:
320 return contextMenuItemTagCopyVideoLinkToClipboard();
321 case WEBKIT_CONTEXT_MENU_ACTION_COPY_AUDIO_LINK_TO_CLIPBOARD:
322 return contextMenuItemTagCopyAudioLinkToClipboard();
323 case WEBKIT_CONTEXT_MENU_ACTION_TOGGLE_MEDIA_CONTROLS:
324 return contextMenuItemTagToggleMediaControls();
325 case WEBKIT_CONTEXT_MENU_ACTION_TOGGLE_MEDIA_LOOP:
326 return contextMenuItemTagToggleMediaLoop();
327 case WEBKIT_CONTEXT_MENU_ACTION_ENTER_VIDEO_FULLSCREEN:
328 return contextMenuItemTagEnterVideoFullscreen();
329 case WEBKIT_CONTEXT_MENU_ACTION_MEDIA_PLAY:
330 return contextMenuItemTagMediaPlay();
331 case WEBKIT_CONTEXT_MENU_ACTION_MEDIA_PAUSE:
332 return contextMenuItemTagMediaPause();
333 case WEBKIT_CONTEXT_MENU_ACTION_MEDIA_MUTE:
334 return contextMenuItemTagMediaMute();
335 case WEBKIT_CONTEXT_MENU_ACTION_DOWNLOAD_VIDEO_TO_DISK:
336 return contextMenuItemTagDownloadVideoToDisk();
337 case WEBKIT_CONTEXT_MENU_ACTION_DOWNLOAD_AUDIO_TO_DISK:
338 return contextMenuItemTagDownloadAudioToDisk();
339 case WEBKIT_CONTEXT_MENU_ACTION_NO_ACTION:
340 case WEBKIT_CONTEXT_MENU_ACTION_CUSTOM:
341 case WEBKIT_CONTEXT_MENU_ACTION_SPELLING_GUESS:
342 return String();
343 default:
344 ASSERT_NOT_REACHED();
345 }
346
347 return String();
348}
349