2 * Copyright (C) 2011 Samsung Electronics
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
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.
13 * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS AS IS''
14 * 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 APPLE INC. OR ITS CONTRIBUTORS
17 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
18 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
19 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
20 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
21 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
22 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
23 * THE POSSIBILITY OF SUCH DAMAGE.
27 #include "WebContextMenuProxyTizen.h"
29 #include "WebContextMenuItemData.h"
30 #include "WebPageProxy.h"
31 #include "ewk_view_private.h"
33 #if ENABLE(TIZEN_CONTEXT_MENU_WEBKIT_2)
34 #include <Elementary.h>
38 #if ENABLE(TIZEN_WEBKIT2_CLIPBOARD_HELPER)
39 #include "ClipboardHelper.h"
42 #include <WebCore/ContextMenu.h>
43 #include <WebCore/NotImplemented.h>
44 #include <wtf/text/CString.h>
48 #if ENABLE(TIZEN_HW_MORE_BACK_KEY)
50 #include <efl_assist.h>
51 extern void* EflAssistHandle;
54 using namespace WebCore;
58 WebContextMenuProxyTizen::WebContextMenuProxyTizen(Evas_Object* webView, WebPageProxy* page, PageClientImpl* pageClientImpl)
60 , m_pageClientImpl(pageClientImpl)
62 #if ENABLE(TIZEN_CONTEXT_MENU_WEBKIT_2)
67 #if ENABLE(TIZEN_WEBKIT2_TEXT_SELECTION)
68 , m_contextShowTimer(0)
70 #if ENABLE(TIZEN_WEBKIT2_CONTEXT_MENU_TEXT_SELECTION_MODE)
71 , m_positionForSelection()
76 WebContextMenuProxyTizen::~WebContextMenuProxyTizen()
78 #if ENABLE(TIZEN_CONTEXT_MENU_WEBKIT_2)
80 evas_object_del(m_popup);
84 #if ENABLE(TIZEN_CONTEXT_MENU_WEBKIT_2)
85 void WebContextMenuProxyTizen::contextMenuItemSelectedCallback(void* data, Evas_Object* obj, void* eventInfo)
87 WebContextMenuItemData itemData = *(static_cast<WebContextMenuItemData*>(data));
88 WebContextMenuProxyTizen* menuProxy = static_cast<WebContextMenuProxyTizen*>(evas_object_data_get(obj, "WebContextMenuProxyTizen"));
90 #if ENABLE(TIZEN_WEBKIT2_FOCUS_RING)
91 menuProxy->m_pageClientImpl->hideFocusRing();
94 #if ENABLE(TIZEN_WEBKIT2_TEXT_SELECTION)
95 menuProxy->m_pageClientImpl->initTextSelectionHandlesMouseDownedStatus();
98 menuProxy->m_page->contextMenuItemSelected(itemData);
99 menuProxy->hideContextMenu();
101 evas_object_del(menuProxy->m_popup);
102 menuProxy->m_popup = 0;
105 #if ENABLE(TIZEN_HW_MORE_BACK_KEY)
106 static void contextMenuHwBackKeyCallback(void* data, Evas_Object* obj, void* eventInfo)
108 elm_ctxpopup_dismiss(obj);
112 void WebContextMenuProxyTizen::createEflMenu(const Vector<WebContextMenuItemData>& items)
115 evas_object_del(m_popup);
117 Evas_Object* topWidget = elm_object_top_widget_get(elm_object_parent_widget_get(m_webView));
119 topWidget = m_webView;
121 m_popup = elm_ctxpopup_add(topWidget);
125 #if ENABLE(TIZEN_HW_MORE_BACK_KEY)
126 if (EflAssistHandle) {
127 void (*webkit_ea_object_event_callback_add)(Evas_Object *, Ea_Callback_Type , Ea_Event_Cb func, void *);
128 webkit_ea_object_event_callback_add = (void (*)(Evas_Object *, Ea_Callback_Type , Ea_Event_Cb func, void *))dlsym(EflAssistHandle, "ea_object_event_callback_add");
129 (*webkit_ea_object_event_callback_add)(m_popup, EA_CALLBACK_BACK, contextMenuHwBackKeyCallback, 0);
134 evas_object_data_set(m_popup, "WebContextMenuProxyTizen", this);
135 elm_object_tree_focus_allow_set(m_popup, false);
137 size_t size = m_items.size();
138 #if ENABLE(TIZEN_WEBKIT2_CLIPBOARD_HELPER)
139 int clipboardItemSize = ClipboardHelper::numberOfItems();
140 TIZEN_LOGI("clipboardItemSize : %d", clipboardItemSize);
143 #if ENABLE(TIZEN_WEBKIT2_TEXT_SELECTION)
144 m_isContextMenuForTextSelection = false;
147 for (size_t i = 0; i < size; i++) {
148 #if ENABLE(TIZEN_WEBKIT2_CLIPBOARD_HELPER)
149 if ((m_items.at(i).action() == ContextMenuItemTagPaste || m_items.at(i).action() == ContextMenuItemTagClipboard) && !clipboardItemSize)
153 #if ENABLE(TIZEN_WEBKIT2_TEXT_SELECTION)
154 if (m_items.at(i).action() == ContextMenuItemTagCopy || m_items.at(i).action() == ContextMenuItemTagSelectAll
155 || m_items.at(i).action() == ContextMenuItemTagSelectWord || m_items.at(i).action() == ContextMenuItemTagPaste)
156 m_isContextMenuForTextSelection = true;
159 #if ENABLE(TIZEN_WEBKIT2_CONTEXT_MENU_ICON_TYPE_SUPPORT)
160 if (!m_items.at(i).title().isEmpty() || !m_items.at(i).iconFile().isEmpty()) {
161 Evas_Object* icon = 0;
162 if (!m_items.at(i).iconFile().isEmpty()) {
163 icon = elm_icon_add(m_popup);
164 TIZEN_LOGI("icon file path : %s", m_items.at(i).iconFile().utf8().data());
165 if (!elm_image_file_set(icon, m_items.at(i).iconFile().utf8().data(), NULL)) {
166 TIZEN_LOGE("elm_image_file_set is failed");
171 if (!m_items.at(i).title().isEmpty())
172 elm_ctxpopup_item_append(m_popup, m_items.at(i).title().utf8().data(), icon,
173 contextMenuItemSelectedCallback, &(m_items.at(i)));
175 elm_ctxpopup_item_append(m_popup, 0, icon,
176 contextMenuItemSelectedCallback, &(m_items.at(i)));
179 if (!m_items.at(i).title().isEmpty())
180 elm_ctxpopup_item_append(m_popup, m_items.at(i).title().utf8().data(), 0,
181 contextMenuItemSelectedCallback, &(m_items.at(i)));
186 #if ENABLE(TIZEN_CONTEXT_MENU_WEBKIT_2)
187 void WebContextMenuProxyTizen::contextMenuPopupDismissedCallback(void* data, Evas_Object* obj, void* eventInfo)
189 WebContextMenuProxyTizen* menuProxy = static_cast<WebContextMenuProxyTizen*>(data);
191 #if ENABLE(TIZEN_WEBKIT2_FOCUS_RING)
192 menuProxy->m_pageClientImpl->hideFocusRing();
194 menuProxy->m_pageClientImpl->setIsContextMenuVisible(false);
196 #if ENABLE(TIZEN_WEBKIT2_TEXT_SELECTION)
197 if (menuProxy->m_contextShowTimer) {
198 ecore_timer_del(menuProxy->m_contextShowTimer);
199 menuProxy->m_contextShowTimer = 0;
207 void WebContextMenuProxyTizen::createEflMenu()
213 #if ENABLE(TIZEN_WEBKIT2_TEXT_SELECTION)
214 Eina_Bool WebContextMenuProxyTizen::contextMenuTimerCallback(void* data)
216 WebContextMenuProxyTizen *contextMenuProxy = static_cast<WebContextMenuProxyTizen*>(data);
217 if (contextMenuProxy) {
218 if (contextMenuProxy->m_popup)
219 evas_object_hide(contextMenuProxy->m_popup);
221 contextMenuProxy->m_pageClientImpl->setIsContextMenuVisible(false);
222 #if ENABLE(TIZEN_WEBKIT2_FOCUS_RING)
223 contextMenuProxy->m_pageClientImpl->hideFocusRing();
226 return ECORE_CALLBACK_CANCEL;
229 void WebContextMenuProxyTizen::startContextMenuTimer()
231 double contextMenuDispTime = 3.0;
232 if (m_contextShowTimer) {
233 ecore_timer_del(m_contextShowTimer);
234 m_contextShowTimer = 0;
236 m_contextShowTimer = ecore_timer_add(contextMenuDispTime, contextMenuTimerCallback, this);
238 #endif // TIZEN_WEBKIT2_TEXT_SELECTION
240 void WebContextMenuProxyTizen::showContextMenu(const WebCore::IntPoint& position, const Vector<WebContextMenuItemData>& items)
242 #if ENABLE(TIZEN_WEBKIT2_CONTEXT_MENU_TEXT_SELECTION_MODE)
243 m_positionForSelection = position;
246 #if ENABLE(TIZEN_CONTEXT_MENU_WEBKIT_2)
247 if (items.isEmpty()) {
248 #if ENABLE(TIZEN_WEBKIT2_TEXT_SELECTION)
249 if (m_pageClientImpl->isTextSelectionMode())
250 m_pageClientImpl->setIsTextSelectionMode(false);
255 createEflMenu(items);
257 #if ENABLE(TIZEN_WEBKIT2_TEXT_SELECTION)
258 if (m_isContextMenuForTextSelection && !evas_object_focus_get(m_webView))
263 int webViewX, webViewY;
264 evas_object_geometry_get(m_webView, &webViewX, &webViewY, 0, 0);
265 IntPoint popupPosition = position;
266 #if ENABLE(TIZEN_WEBKIT2_TILED_BACKING_STORE)
267 if (m_pageClientImpl) {
268 popupPosition.scale(m_pageClientImpl->scaleFactor(), m_pageClientImpl->scaleFactor());
269 IntPoint scrollPosition = m_pageClientImpl->scrollPosition();
270 popupPosition.move(-scrollPosition.x(), -scrollPosition.y());
273 popupPosition.setX(popupPosition.x() + webViewX);
274 popupPosition.setY(popupPosition.y() + webViewY);
276 #if ENABLE(TIZEN_WEBKIT2_TEXT_SELECTION)
277 if (m_isContextMenuForTextSelection) {
278 if (!m_pageClientImpl->isTextSelectionMode())
279 m_pageClientImpl->setIsTextSelectionMode(true);
280 elm_object_style_set(m_popup,"copypaste");
281 elm_ctxpopup_horizontal_set(m_popup, EINA_TRUE);
282 elm_ctxpopup_direction_priority_set(m_popup, ELM_CTXPOPUP_DIRECTION_UP, ELM_CTXPOPUP_DIRECTION_UP, ELM_CTXPOPUP_DIRECTION_UP, ELM_CTXPOPUP_DIRECTION_UP);
286 evas_object_move(m_popup, popupPosition.x(), popupPosition.y());
287 evas_object_show(m_popup);
289 evas_object_smart_callback_add(m_popup, "dismissed", contextMenuPopupDismissedCallback, this);
292 m_pageClientImpl->setIsContextMenuVisible(true);
293 #if ENABLE(TOUCH_EVENTS) && ENABLE(TIZEN_GESTURE)
294 // Cancel touch event when ContextMenu is shown.
295 EwkViewImpl::fromEvasObject(m_webView)->feedTouchEventsByType(EWK_TOUCH_CANCEL);
298 #if ENABLE(TIZEN_WEBKIT2_TEXT_SELECTION)
299 // Start the timer at the end
300 if (m_isContextMenuForTextSelection)
301 startContextMenuTimer();
310 void WebContextMenuProxyTizen::hideContextMenu()
312 #if ENABLE(TIZEN_CONTEXT_MENU_WEBKIT_2)
314 evas_object_hide(m_popup);
315 m_pageClientImpl->setIsContextMenuVisible(false);
316 #if ENABLE(TIZEN_WEBKIT2_TEXT_SELECTION)
317 if (m_contextShowTimer) {
318 ecore_timer_del(m_contextShowTimer);
319 m_contextShowTimer = 0;
327 #if ENABLE(TIZEN_WEBKIT2_CONTEXT_MENU_TEXT_SELECTION_MODE)
328 WebCore::IntPoint& WebContextMenuProxyTizen::positionForSelection()
330 return m_positionForSelection;
334 } // namespace WebKit