[EFL][WK2] Add an API for getting context menu item's parent menu
[WebKit-https.git] / Source / WebKit2 / UIProcess / API / efl / ewk_context_menu_item.cpp
1 /*
2  * Copyright (C) 2012 Samsung Electronics. All rights reserved.
3  *
4  * Redistribution and use in source and binary forms, with or without
5  * modification, are permitted provided that the following conditions
6  * are met:
7  * 1. Redistributions of source code must retain the above copyright
8  *    notice, this list of conditions and the following disclaimer.
9  * 2. Redistributions in binary form must reproduce the above copyright
10  *    notice, this list of conditions and the following disclaimer in the
11  *    documentation and/or other materials provided with the distribution.
12  *
13  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
14  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
15  * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
16  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
17  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
18  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
19  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
20  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
21  * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
22  * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
23  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
24  */
25
26 #include "config.h"
27 #include "ewk_context_menu_item.h"
28
29 #include "ewk_context_menu_item_private.h"
30 #include "ewk_private.h"
31 #include <WebKit2/WKContextMenuItemTypes.h>
32 #include <wtf/text/CString.h>
33
34 using namespace WebKit;
35
36 static Ewk_Context_Menu_Item_Action getEwkActionFromWKTag(WKContextMenuItemTag action);
37
38 EwkContextMenuItem::EwkContextMenuItem(WKContextMenuItemRef item, Ewk_Context_Menu* parentMenu)
39     : m_type(static_cast<Ewk_Context_Menu_Item_Type>(WKContextMenuItemGetType(item)))
40     , m_action(getEwkActionFromWKTag((WKContextMenuItemGetTag(item))))
41     , m_title(WKEinaSharedString(AdoptWK, WKContextMenuItemCopyTitle(item)))
42     , m_isChecked(WKContextMenuItemGetChecked(item))
43     , m_isEnabled(WKContextMenuItemGetEnabled(item))
44     , m_parentMenu(parentMenu)
45     , m_subMenu(0)
46 {
47 }
48
49 EwkContextMenuItem::EwkContextMenuItem(Ewk_Context_Menu_Item_Type type, Ewk_Context_Menu_Item_Action action, const char* title, Eina_Bool checked, Eina_Bool enabled, Ewk_Context_Menu* subMenu, Ewk_Context_Menu* parentMenu)
50     : m_type(type)
51     , m_action(action)
52     , m_title(title)
53     , m_isChecked(checked)
54     , m_isEnabled(enabled)
55     , m_parentMenu(parentMenu)
56     , m_subMenu(subMenu)
57 {
58 }
59
60 Ewk_Context_Menu_Item* ewk_context_menu_item_new(Ewk_Context_Menu_Item_Type type, Ewk_Context_Menu_Item_Action action, const char* title, Eina_Bool checked, Eina_Bool enabled)
61 {
62     return Ewk_Context_Menu_Item::create(type, action, title, checked, enabled, 0).leakPtr();
63 }
64
65 Ewk_Context_Menu_Item* ewk_context_menu_item_new_with_submenu(Ewk_Context_Menu_Item_Type type, Ewk_Context_Menu_Item_Action action, const char* title, Eina_Bool checked, Eina_Bool enabled, Ewk_Context_Menu* subMenu)
66 {
67     return Ewk_Context_Menu_Item::create(type, action, title, checked, enabled, subMenu).leakPtr();
68 }
69
70 Ewk_Context_Menu_Item_Type ewk_context_menu_item_type_get(const Ewk_Context_Menu_Item* item)
71 {
72     EINA_SAFETY_ON_NULL_RETURN_VAL(item, EWK_ACTION_TYPE);
73
74     return item->type();
75 }
76
77 Eina_Bool ewk_context_menu_item_type_set(Ewk_Context_Menu_Item* item, Ewk_Context_Menu_Item_Type type)
78 {
79     EINA_SAFETY_ON_NULL_RETURN_VAL(item, false);
80
81     item->setType(type);
82
83     return true;
84 }
85
86 Ewk_Context_Menu_Item_Action ewk_context_menu_item_action_get(const Ewk_Context_Menu_Item* item)
87 {
88     EINA_SAFETY_ON_NULL_RETURN_VAL(item, EWK_CONTEXT_MENU_ITEM_TAG_NO_ACTION);
89
90     return item->action();
91 }
92
93 Eina_Bool ewk_context_menu_item_action_set(Ewk_Context_Menu_Item* item, Ewk_Context_Menu_Item_Action action)
94 {
95     EINA_SAFETY_ON_NULL_RETURN_VAL(item, false);
96
97     item->setAction(action);
98
99     return true;
100 }
101
102 const char* ewk_context_menu_item_title_get(const Ewk_Context_Menu_Item* item)
103 {
104     EINA_SAFETY_ON_NULL_RETURN_VAL(item, 0);
105
106     return item->title();
107 }
108
109 Eina_Bool ewk_context_menu_item_title_set(Ewk_Context_Menu_Item* item, const char* title)
110 {
111     EINA_SAFETY_ON_NULL_RETURN_VAL(item, false);
112
113     item->setTitle(title);
114
115     return true;
116 }
117
118 Eina_Bool ewk_context_menu_item_checked_get(const Ewk_Context_Menu_Item* item)
119 {
120     EINA_SAFETY_ON_NULL_RETURN_VAL(item, false);
121
122     return item->checked();
123 }
124
125 Eina_Bool ewk_context_menu_item_checked_set(Ewk_Context_Menu_Item* item, Eina_Bool checked)
126 {
127     EINA_SAFETY_ON_NULL_RETURN_VAL(item, false);
128
129     item->setChecked(checked);
130
131     return true;
132 }
133
134 Eina_Bool ewk_context_menu_item_enabled_get(const Ewk_Context_Menu_Item* item)
135 {
136     EINA_SAFETY_ON_NULL_RETURN_VAL(item, false);
137     
138     return item->enabled();
139 }
140
141 Eina_Bool ewk_context_menu_item_enabled_set(Ewk_Context_Menu_Item* item, Eina_Bool enabled)
142 {
143     EINA_SAFETY_ON_NULL_RETURN_VAL(item, false);
144
145     item->setEnabled(enabled);
146
147     return true;
148 }
149
150 Ewk_Context_Menu* ewk_context_menu_item_parent_menu_get(const Ewk_Context_Menu_Item* item)
151 {
152     EINA_SAFETY_ON_NULL_RETURN_VAL(item, 0);
153
154     return const_cast<Ewk_Context_Menu_Item*>(item)->parentMenu();
155 }
156
157 static Ewk_Context_Menu_Item_Action getEwkActionFromWKTag(WKContextMenuItemTag action)
158 {
159     switch (action) {
160     case kWKContextMenuItemTagNoAction:
161         return EWK_CONTEXT_MENU_ITEM_TAG_NO_ACTION;
162     case kWKContextMenuItemTagOpenLinkInNewWindow:
163         return EWK_CONTEXT_MENU_ITEM_TAG_OPEN_LINK_IN_NEW_WINDOW;
164     case kWKContextMenuItemTagDownloadLinkToDisk:
165         return EWK_CONTEXT_MENU_ITEM_TAG_DOWNLOAD_LINK_TO_DISK;
166     case kWKContextMenuItemTagCopyLinkToClipboard:
167         return EWK_CONTEXT_MENU_ITEM_TAG_COPY_LINK_TO_CLIPBOARD;
168     case kWKContextMenuItemTagOpenImageInNewWindow:
169         return EWK_CONTEXT_MENU_ITEM_TAG_OPEN_IMAGE_IN_NEW_WINDOW;
170     case kWKContextMenuItemTagDownloadImageToDisk:
171         return EWK_CONTEXT_MENU_ITEM_TAG_DOWNLOAD_IMAGE_TO_DISK;
172     case kWKContextMenuItemTagCopyImageToClipboard:
173         return EWK_CONTEXT_MENU_ITEM_TAG_COPY_IMAGE_TO_CLIPBOARD;
174     case kWKContextMenuItemTagCopyImageUrlToClipboard:
175         return EWK_CONTEXT_MENU_ITEM_TAG_COPY_IMAGE_URL_TO_CLIPBOARD;
176     case kWKContextMenuItemTagOpenFrameInNewWindow:
177         return EWK_CONTEXT_MENU_ITEM_TAG_OPEN_FRAME_IN_NEW_WINDOW;
178     case kWKContextMenuItemTagCopy:
179         return EWK_CONTEXT_MENU_ITEM_TAG_COPY;
180     case kWKContextMenuItemTagGoBack:
181         return EWK_CONTEXT_MENU_ITEM_TAG_GO_BACK;
182     case kWKContextMenuItemTagGoForward:
183         return EWK_CONTEXT_MENU_ITEM_TAG_GO_FORWARD;
184     case kWKContextMenuItemTagStop:
185         return EWK_CONTEXT_MENU_ITEM_TAG_STOP;
186     case kWKContextMenuItemTagReload:
187         return EWK_CONTEXT_MENU_ITEM_TAG_RELOAD;
188     case kWKContextMenuItemTagCut:
189         return EWK_CONTEXT_MENU_ITEM_TAG_CUT;
190     case kWKContextMenuItemTagPaste:
191         return EWK_CONTEXT_MENU_ITEM_TAG_PASTE;
192     case kWKContextMenuItemTagSelectAll:
193         return EWK_CONTEXT_MENU_ITEM_TAG_SELECT_ALL;
194     case kWKContextMenuItemTagSpellingGuess:
195         return EWK_CONTEXT_MENU_ITEM_TAG_SPELLING_GUESS;
196     case kWKContextMenuItemTagNoGuessesFound:
197         return EWK_CONTEXT_MENU_ITEM_TAG_NO_GUESSES_FOUND;
198     case kWKContextMenuItemTagIgnoreSpelling:
199         return EWK_CONTEXT_MENU_ITEM_TAG_IGNORE_SPELLING;
200     case kWKContextMenuItemTagLearnSpelling:
201         return EWK_CONTEXT_MENU_ITEM_TAG_LEARN_SPELLING;
202     case kWKContextMenuItemTagOther:
203         return EWK_CONTEXT_MENU_ITEM_TAG_OTHER;
204     case kWKContextMenuItemTagSearchInSpotlight:
205         return EWK_CONTEXT_MENU_ITEM_TAG_SEARCH_IN_SPOTLIGHT;
206     case kWKContextMenuItemTagSearchWeb:
207         return EWK_CONTEXT_MENU_ITEM_TAG_SEARCH_WEB;
208     case kWKContextMenuItemTagLookUpInDictionary:
209         return EWK_CONTEXT_MENU_ITEM_TAG_LOOK_UP_IN_DICTIONARY;
210     case kWKContextMenuItemTagOpenWithDefaultApplication:
211         return EWK_CONTEXT_MENU_ITEM_TAG_OPEN_WITH_DEFAULT_APPLICATION;
212     case kWKContextMenuItemTagPDFActualSize:
213         return EWK_CONTEXT_MENU_ITEM_PDFACTUAL_SIZE;
214     case kWKContextMenuItemTagPDFZoomIn:
215         return EWK_CONTEXT_MENU_ITEM_PDFZOOM_IN;
216     case kWKContextMenuItemTagPDFZoomOut:
217         return EWK_CONTEXT_MENU_ITEM_PDFZOOM_OUT;
218     case kWKContextMenuItemTagPDFAutoSize:
219         return EWK_CONTEXT_MENU_ITEM_PDFAUTO_SIZE;
220     case kWKContextMenuItemTagPDFSinglePage:
221         return EWK_CONTEXT_MENU_ITEM_PDFSINGLE_PAGE;
222     case kWKContextMenuItemTagPDFFacingPages:
223         return EWK_CONTEXT_MENU_ITEM_PDFFACING_PAGES;
224     case kWKContextMenuItemTagPDFContinuous:
225         return EWK_CONTEXT_MENU_ITEM_PDFCONTINUOUS;
226     case kWKContextMenuItemTagPDFNextPage:
227         return EWK_CONTEXT_MENU_ITEM_PDFNEXT_PAGE;
228     case kWKContextMenuItemTagPDFPreviousPage:
229         return EWK_CONTEXT_MENU_ITEM_PDFPREVIOUS_PAGE;
230     case kWKContextMenuItemTagOpenLink:
231         return EWK_CONTEXT_MENU_ITEM_TAG_OPEN_LINK;
232     case kWKContextMenuItemTagIgnoreGrammar:
233         return EWK_CONTEXT_MENU_ITEM_TAG_IGNORE_GRAMMAR;
234     case kWKContextMenuItemTagSpellingMenu:
235         return EWK_CONTEXT_MENU_ITEM_TAG_SPELLING_MENU;
236     case kWKContextMenuItemTagShowSpellingPanel:
237         return EWK_CONTEXT_MENU_ITEM_TAG_SHOW_SPELLING_PANEL;
238     case kWKContextMenuItemTagCheckSpelling:
239         return EWK_CONTEXT_MENU_ITEM_TAG_CHECK_SPELLING;
240     case kWKContextMenuItemTagCheckSpellingWhileTyping:
241         return EWK_CONTEXT_MENU_ITEM_TAG_CHECK_SPELLING_WHILE_TYPING;
242     case kWKContextMenuItemTagCheckGrammarWithSpelling:
243         return EWK_CONTEXT_MENU_ITEM_TAG_CHECK_GRAMMAR_WITH_SPELLING;
244     case kWKContextMenuItemTagFontMenu:
245         return EWK_CONTEXT_MENU_ITEM_TAG_FONT_MENU;
246     case kWKContextMenuItemTagShowFonts:
247         return EWK_CONTEXT_MENU_ITEM_TAG_SHOW_FONTS;
248     case kWKContextMenuItemTagBold:
249         return EWK_CONTEXT_MENU_ITEM_TAG_BOLD;
250     case kWKContextMenuItemTagItalic:
251         return EWK_CONTEXT_MENU_ITEM_TAG_ITALIC;
252     case kWKContextMenuItemTagUnderline:
253         return EWK_CONTEXT_MENU_ITEM_TAG_UNDERLINE;
254     case kWKContextMenuItemTagOutline:
255         return EWK_CONTEXT_MENU_ITEM_TAG_OUTLINE;
256     case kWKContextMenuItemTagStyles:
257         return EWK_CONTEXT_MENU_ITEM_TAG_STYLES;
258     case kWKContextMenuItemTagShowColors:
259         return EWK_CONTEXT_MENU_ITEM_TAG_SHOW_COLORS;
260     case kWKContextMenuItemTagSpeechMenu:
261         return EWK_CONTEXT_MENU_ITEM_TAG_SPEECH_MENU;
262     case kWKContextMenuItemTagStartSpeaking:
263         return EWK_CONTEXT_MENU_ITEM_TAG_START_SPEAKING;
264     case kWKContextMenuItemTagStopSpeaking:
265         return EWK_CONTEXT_MENU_ITEM_TAG_STOP_SPEAKING;
266     case kWKContextMenuItemTagWritingDirectionMenu:
267         return EWK_CONTEXT_MENU_ITEM_TAG_WRITING_DIRECTION_MENU;
268     case kWKContextMenuItemTagDefaultDirection:
269         return EWK_CONTEXT_MENU_ITEM_TAG_DEFAULT_DIRECTION;
270     case kWKContextMenuItemTagLeftToRight:
271         return EWK_CONTEXT_MENU_ITEM_TAG_LEFT_TO_RIGHT;
272     case kWKContextMenuItemTagRightToLeft:
273         return EWK_CONTEXT_MENU_ITEM_TAG_RIGHT_TO_LEFT;
274     case kWKContextMenuItemTagPDFSinglePageScrolling:
275         return EWK_CONTEXT_MENU_ITEM_TAG_PDFSINGLE_PAGE_SCROLLING;
276     case kWKContextMenuItemTagPDFFacingPagesScrolling:
277         return EWK_CONTEXT_MENU_ITEM_TAG_PDFFACING_PAGES_SCROLLING;
278     case kWKContextMenuItemTagInspectElement:
279         return EWK_CONTEXT_MENU_ITEM_TAG_INSPECT_ELEMENT;
280     case kWKContextMenuItemTagTextDirectionMenu:
281         return EWK_CONTEXT_MENU_ITEM_TAG_TEXT_DIRECTION_MENU;
282     case kWKContextMenuItemTagTextDirectionDefault:
283         return EWK_CONTEXT_MENU_ITEM_TAG_TEXT_DIRECTION_DEFAULT;
284     case kWKContextMenuItemTagTextDirectionLeftToRight:
285         return EWK_CONTEXT_MENU_ITEM_TAG_TEXT_DIRECTION_LEFT_TO_RIGHT;
286     case kWKContextMenuItemTagTextDirectionRightToLeft:
287         return EWK_CONTEXT_MENU_ITEM_TAG_TEXT_DIRECTION_RIGHT_TO_LEFT;
288     case kWKContextMenuItemTagOpenMediaInNewWindow:
289         return EWK_CONTEXT_MENU_ITEM_OPEN_MEDIA_IN_NEW_WINDOW;
290     case kWKContextMenuItemTagCopyMediaLinkToClipboard:
291         return EWK_CONTEXT_MENU_ITEM_TAG_COPY_MEDIA_LINK_TO_CLIPBOARD;
292     case kWKContextMenuItemTagToggleMediaControls:
293         return EWK_CONTEXT_MENU_ITEM_TAG_TOGGLE_MEDIA_CONTROLS;
294     case kWKContextMenuItemTagToggleMediaLoop:
295         return EWK_CONTEXT_MENU_ITEM_TAG_TOGGLE_MEDIA_LOOP;
296     case kWKContextMenuItemTagEnterVideoFullscreen:
297         return EWK_CONTEXT_MENU_ITEM_TAG_ENTER_VIDEO_FULLSCREEN;
298     case kWKContextMenuItemTagMediaPlayPause:
299         return EWK_CONTEXT_MENU_ITEM_TAG_MEDIA_PLAY_PAUSE;
300     case kWKContextMenuItemTagMediaMute:
301         return EWK_CONTEXT_MENU_ITEM_TAG_MEDIA_MUTE;
302     case kWKContextMenuItemBaseApplicationTag:
303         return EWK_CONTEXT_MENU_ITEM_BASE_APPLICATION_TAG;
304     default:
305         return static_cast<Ewk_Context_Menu_Item_Action>(action);
306     }
307 }