edb9f468678c33b46630aa944c23265317c87b49
[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)
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(0)
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)
50     : m_type(type)
51     , m_action(action)
52     , m_title(title)
53     , m_isChecked(checked)
54     , m_isEnabled(enabled)
55     , m_parentMenu(0)
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 static Ewk_Context_Menu_Item_Action getEwkActionFromWKTag(WKContextMenuItemTag action)
151 {
152     switch (action) {
153     case kWKContextMenuItemTagNoAction:
154         return EWK_CONTEXT_MENU_ITEM_TAG_NO_ACTION;
155     case kWKContextMenuItemTagOpenLinkInNewWindow:
156         return EWK_CONTEXT_MENU_ITEM_TAG_OPEN_LINK_IN_NEW_WINDOW;
157     case kWKContextMenuItemTagDownloadLinkToDisk:
158         return EWK_CONTEXT_MENU_ITEM_TAG_DOWNLOAD_LINK_TO_DISK;
159     case kWKContextMenuItemTagCopyLinkToClipboard:
160         return EWK_CONTEXT_MENU_ITEM_TAG_COPY_LINK_TO_CLIPBOARD;
161     case kWKContextMenuItemTagOpenImageInNewWindow:
162         return EWK_CONTEXT_MENU_ITEM_TAG_OPEN_IMAGE_IN_NEW_WINDOW;
163     case kWKContextMenuItemTagDownloadImageToDisk:
164         return EWK_CONTEXT_MENU_ITEM_TAG_DOWNLOAD_IMAGE_TO_DISK;
165     case kWKContextMenuItemTagCopyImageToClipboard:
166         return EWK_CONTEXT_MENU_ITEM_TAG_COPY_IMAGE_TO_CLIPBOARD;
167     case kWKContextMenuItemTagCopyImageUrlToClipboard:
168         return EWK_CONTEXT_MENU_ITEM_TAG_COPY_IMAGE_URL_TO_CLIPBOARD;
169     case kWKContextMenuItemTagOpenFrameInNewWindow:
170         return EWK_CONTEXT_MENU_ITEM_TAG_OPEN_FRAME_IN_NEW_WINDOW;
171     case kWKContextMenuItemTagCopy:
172         return EWK_CONTEXT_MENU_ITEM_TAG_COPY;
173     case kWKContextMenuItemTagGoBack:
174         return EWK_CONTEXT_MENU_ITEM_TAG_GO_BACK;
175     case kWKContextMenuItemTagGoForward:
176         return EWK_CONTEXT_MENU_ITEM_TAG_GO_FORWARD;
177     case kWKContextMenuItemTagStop:
178         return EWK_CONTEXT_MENU_ITEM_TAG_STOP;
179     case kWKContextMenuItemTagReload:
180         return EWK_CONTEXT_MENU_ITEM_TAG_RELOAD;
181     case kWKContextMenuItemTagCut:
182         return EWK_CONTEXT_MENU_ITEM_TAG_CUT;
183     case kWKContextMenuItemTagPaste:
184         return EWK_CONTEXT_MENU_ITEM_TAG_PASTE;
185     case kWKContextMenuItemTagSelectAll:
186         return EWK_CONTEXT_MENU_ITEM_TAG_SELECT_ALL;
187     case kWKContextMenuItemTagSpellingGuess:
188         return EWK_CONTEXT_MENU_ITEM_TAG_SPELLING_GUESS;
189     case kWKContextMenuItemTagNoGuessesFound:
190         return EWK_CONTEXT_MENU_ITEM_TAG_NO_GUESSES_FOUND;
191     case kWKContextMenuItemTagIgnoreSpelling:
192         return EWK_CONTEXT_MENU_ITEM_TAG_IGNORE_SPELLING;
193     case kWKContextMenuItemTagLearnSpelling:
194         return EWK_CONTEXT_MENU_ITEM_TAG_LEARN_SPELLING;
195     case kWKContextMenuItemTagOther:
196         return EWK_CONTEXT_MENU_ITEM_TAG_OTHER;
197     case kWKContextMenuItemTagSearchInSpotlight:
198         return EWK_CONTEXT_MENU_ITEM_TAG_SEARCH_IN_SPOTLIGHT;
199     case kWKContextMenuItemTagSearchWeb:
200         return EWK_CONTEXT_MENU_ITEM_TAG_SEARCH_WEB;
201     case kWKContextMenuItemTagLookUpInDictionary:
202         return EWK_CONTEXT_MENU_ITEM_TAG_LOOK_UP_IN_DICTIONARY;
203     case kWKContextMenuItemTagOpenWithDefaultApplication:
204         return EWK_CONTEXT_MENU_ITEM_TAG_OPEN_WITH_DEFAULT_APPLICATION;
205     case kWKContextMenuItemTagPDFActualSize:
206         return EWK_CONTEXT_MENU_ITEM_PDFACTUAL_SIZE;
207     case kWKContextMenuItemTagPDFZoomIn:
208         return EWK_CONTEXT_MENU_ITEM_PDFZOOM_IN;
209     case kWKContextMenuItemTagPDFZoomOut:
210         return EWK_CONTEXT_MENU_ITEM_PDFZOOM_OUT;
211     case kWKContextMenuItemTagPDFAutoSize:
212         return EWK_CONTEXT_MENU_ITEM_PDFAUTO_SIZE;
213     case kWKContextMenuItemTagPDFSinglePage:
214         return EWK_CONTEXT_MENU_ITEM_PDFSINGLE_PAGE;
215     case kWKContextMenuItemTagPDFFacingPages:
216         return EWK_CONTEXT_MENU_ITEM_PDFFACING_PAGES;
217     case kWKContextMenuItemTagPDFContinuous:
218         return EWK_CONTEXT_MENU_ITEM_PDFCONTINUOUS;
219     case kWKContextMenuItemTagPDFNextPage:
220         return EWK_CONTEXT_MENU_ITEM_PDFNEXT_PAGE;
221     case kWKContextMenuItemTagPDFPreviousPage:
222         return EWK_CONTEXT_MENU_ITEM_PDFPREVIOUS_PAGE;
223     case kWKContextMenuItemTagOpenLink:
224         return EWK_CONTEXT_MENU_ITEM_TAG_OPEN_LINK;
225     case kWKContextMenuItemTagIgnoreGrammar:
226         return EWK_CONTEXT_MENU_ITEM_TAG_IGNORE_GRAMMAR;
227     case kWKContextMenuItemTagSpellingMenu:
228         return EWK_CONTEXT_MENU_ITEM_TAG_SPELLING_MENU;
229     case kWKContextMenuItemTagShowSpellingPanel:
230         return EWK_CONTEXT_MENU_ITEM_TAG_SHOW_SPELLING_PANEL;
231     case kWKContextMenuItemTagCheckSpelling:
232         return EWK_CONTEXT_MENU_ITEM_TAG_CHECK_SPELLING;
233     case kWKContextMenuItemTagCheckSpellingWhileTyping:
234         return EWK_CONTEXT_MENU_ITEM_TAG_CHECK_SPELLING_WHILE_TYPING;
235     case kWKContextMenuItemTagCheckGrammarWithSpelling:
236         return EWK_CONTEXT_MENU_ITEM_TAG_CHECK_GRAMMAR_WITH_SPELLING;
237     case kWKContextMenuItemTagFontMenu:
238         return EWK_CONTEXT_MENU_ITEM_TAG_FONT_MENU;
239     case kWKContextMenuItemTagShowFonts:
240         return EWK_CONTEXT_MENU_ITEM_TAG_SHOW_FONTS;
241     case kWKContextMenuItemTagBold:
242         return EWK_CONTEXT_MENU_ITEM_TAG_BOLD;
243     case kWKContextMenuItemTagItalic:
244         return EWK_CONTEXT_MENU_ITEM_TAG_ITALIC;
245     case kWKContextMenuItemTagUnderline:
246         return EWK_CONTEXT_MENU_ITEM_TAG_UNDERLINE;
247     case kWKContextMenuItemTagOutline:
248         return EWK_CONTEXT_MENU_ITEM_TAG_OUTLINE;
249     case kWKContextMenuItemTagStyles:
250         return EWK_CONTEXT_MENU_ITEM_TAG_STYLES;
251     case kWKContextMenuItemTagShowColors:
252         return EWK_CONTEXT_MENU_ITEM_TAG_SHOW_COLORS;
253     case kWKContextMenuItemTagSpeechMenu:
254         return EWK_CONTEXT_MENU_ITEM_TAG_SPEECH_MENU;
255     case kWKContextMenuItemTagStartSpeaking:
256         return EWK_CONTEXT_MENU_ITEM_TAG_START_SPEAKING;
257     case kWKContextMenuItemTagStopSpeaking:
258         return EWK_CONTEXT_MENU_ITEM_TAG_STOP_SPEAKING;
259     case kWKContextMenuItemTagWritingDirectionMenu:
260         return EWK_CONTEXT_MENU_ITEM_TAG_WRITING_DIRECTION_MENU;
261     case kWKContextMenuItemTagDefaultDirection:
262         return EWK_CONTEXT_MENU_ITEM_TAG_DEFAULT_DIRECTION;
263     case kWKContextMenuItemTagLeftToRight:
264         return EWK_CONTEXT_MENU_ITEM_TAG_LEFT_TO_RIGHT;
265     case kWKContextMenuItemTagRightToLeft:
266         return EWK_CONTEXT_MENU_ITEM_TAG_RIGHT_TO_LEFT;
267     case kWKContextMenuItemTagPDFSinglePageScrolling:
268         return EWK_CONTEXT_MENU_ITEM_TAG_PDFSINGLE_PAGE_SCROLLING;
269     case kWKContextMenuItemTagPDFFacingPagesScrolling:
270         return EWK_CONTEXT_MENU_ITEM_TAG_PDFFACING_PAGES_SCROLLING;
271     case kWKContextMenuItemTagInspectElement:
272         return EWK_CONTEXT_MENU_ITEM_TAG_INSPECT_ELEMENT;
273     case kWKContextMenuItemTagTextDirectionMenu:
274         return EWK_CONTEXT_MENU_ITEM_TAG_TEXT_DIRECTION_MENU;
275     case kWKContextMenuItemTagTextDirectionDefault:
276         return EWK_CONTEXT_MENU_ITEM_TAG_TEXT_DIRECTION_DEFAULT;
277     case kWKContextMenuItemTagTextDirectionLeftToRight:
278         return EWK_CONTEXT_MENU_ITEM_TAG_TEXT_DIRECTION_LEFT_TO_RIGHT;
279     case kWKContextMenuItemTagTextDirectionRightToLeft:
280         return EWK_CONTEXT_MENU_ITEM_TAG_TEXT_DIRECTION_RIGHT_TO_LEFT;
281     case kWKContextMenuItemTagOpenMediaInNewWindow:
282         return EWK_CONTEXT_MENU_ITEM_OPEN_MEDIA_IN_NEW_WINDOW;
283     case kWKContextMenuItemTagCopyMediaLinkToClipboard:
284         return EWK_CONTEXT_MENU_ITEM_TAG_COPY_MEDIA_LINK_TO_CLIPBOARD;
285     case kWKContextMenuItemTagToggleMediaControls:
286         return EWK_CONTEXT_MENU_ITEM_TAG_TOGGLE_MEDIA_CONTROLS;
287     case kWKContextMenuItemTagToggleMediaLoop:
288         return EWK_CONTEXT_MENU_ITEM_TAG_TOGGLE_MEDIA_LOOP;
289     case kWKContextMenuItemTagEnterVideoFullscreen:
290         return EWK_CONTEXT_MENU_ITEM_TAG_ENTER_VIDEO_FULLSCREEN;
291     case kWKContextMenuItemTagMediaPlayPause:
292         return EWK_CONTEXT_MENU_ITEM_TAG_MEDIA_PLAY_PAUSE;
293     case kWKContextMenuItemTagMediaMute:
294         return EWK_CONTEXT_MENU_ITEM_TAG_MEDIA_MUTE;
295     case kWKContextMenuItemBaseApplicationTag:
296         return EWK_CONTEXT_MENU_ITEM_BASE_APPLICATION_TAG;
297     default:
298         return static_cast<Ewk_Context_Menu_Item_Action>(action);
299     }
300 }