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_CONTEXT_MENU_TEXT_SELECTION_MODE)
68 , m_positionForSelection()
73 WebContextMenuProxyTizen::~WebContextMenuProxyTizen()
75 #if ENABLE(TIZEN_CONTEXT_MENU_WEBKIT_2)
77 evas_object_del(m_popup);
81 #if ENABLE(TIZEN_CONTEXT_MENU_WEBKIT_2)
82 void WebContextMenuProxyTizen::contextMenuItemSelectedCallback(void* data, Evas_Object* obj, void* eventInfo)
84 WebContextMenuItemData itemData = *(static_cast<WebContextMenuItemData*>(data));
85 WebContextMenuProxyTizen* menuProxy = static_cast<WebContextMenuProxyTizen*>(evas_object_data_get(obj, "WebContextMenuProxyTizen"));
87 #if ENABLE(TIZEN_WEBKIT2_FOCUS_RING)
88 menuProxy->m_pageClientImpl->hideFocusRing();
91 #if ENABLE(TIZEN_WEBKIT2_TEXT_SELECTION)
92 menuProxy->m_pageClientImpl->initTextSelectionHandlesMouseDownedStatus();
95 menuProxy->m_page->contextMenuItemSelected(itemData);
96 menuProxy->hideContextMenu();
98 evas_object_del(menuProxy->m_popup);
99 menuProxy->m_popup = 0;
102 #if ENABLE(TIZEN_HW_MORE_BACK_KEY)
103 static void contextMenuHwBackKeyCallback(void* data, Evas_Object* obj, void* eventInfo)
105 elm_ctxpopup_dismiss(obj);
109 void WebContextMenuProxyTizen::createEflMenu(const Vector<WebContextMenuItemData>& items)
112 evas_object_del(m_popup);
114 Evas_Object* topWidget = elm_object_top_widget_get(elm_object_parent_widget_get(m_webView));
116 topWidget = m_webView;
118 m_popup = elm_ctxpopup_add(topWidget);
122 #if ENABLE(TIZEN_HW_MORE_BACK_KEY)
123 if (EflAssistHandle) {
124 void (*webkit_ea_object_event_callback_add)(Evas_Object *, Ea_Callback_Type , Ea_Event_Cb func, void *);
125 webkit_ea_object_event_callback_add = (void (*)(Evas_Object *, Ea_Callback_Type , Ea_Event_Cb func, void *))dlsym(EflAssistHandle, "ea_object_event_callback_add");
126 (*webkit_ea_object_event_callback_add)(m_popup, EA_CALLBACK_BACK, contextMenuHwBackKeyCallback, 0);
131 evas_object_data_set(m_popup, "WebContextMenuProxyTizen", this);
132 elm_object_tree_focus_allow_set(m_popup, false);
134 size_t size = m_items.size();
135 #if ENABLE(TIZEN_WEBKIT2_CLIPBOARD_HELPER)
136 int clipboardItemSize = ClipboardHelper::numberOfItems();
137 TIZEN_LOGI("clipboardItemSize : %d", clipboardItemSize);
140 #if ENABLE(TIZEN_WEBKIT2_TEXT_SELECTION)
141 m_isContextMenuForTextSelection = false;
144 for (size_t i = 0; i < size; i++) {
145 #if ENABLE(TIZEN_WEBKIT2_CLIPBOARD_HELPER)
146 if ((m_items.at(i).action() == ContextMenuItemTagPaste || m_items.at(i).action() == ContextMenuItemTagClipboard) && !clipboardItemSize)
150 #if ENABLE(TIZEN_WEBKIT2_TEXT_SELECTION)
151 if (m_items.at(i).action() == ContextMenuItemTagCopy || m_items.at(i).action() == ContextMenuItemTagSelectAll
152 || m_items.at(i).action() == ContextMenuItemTagSelectWord || m_items.at(i).action() == ContextMenuItemTagPaste)
153 m_isContextMenuForTextSelection = true;
156 #if ENABLE(TIZEN_WEBKIT2_CONTEXT_MENU_ICON_TYPE_SUPPORT)
157 if (!m_items.at(i).title().isEmpty() || !m_items.at(i).iconFile().isEmpty()) {
158 Evas_Object* icon = 0;
159 if (!m_items.at(i).iconFile().isEmpty()) {
160 icon = elm_icon_add(m_popup);
161 TIZEN_LOGI("icon file path : %s", m_items.at(i).iconFile().utf8().data());
162 if (!elm_image_file_set(icon, m_items.at(i).iconFile().utf8().data(), NULL)) {
163 TIZEN_LOGE("elm_image_file_set is failed");
168 if (!m_items.at(i).title().isEmpty())
169 elm_ctxpopup_item_append(m_popup, m_items.at(i).title().utf8().data(), icon,
170 contextMenuItemSelectedCallback, &(m_items.at(i)));
172 elm_ctxpopup_item_append(m_popup, 0, icon,
173 contextMenuItemSelectedCallback, &(m_items.at(i)));
176 if (!m_items.at(i).title().isEmpty())
177 elm_ctxpopup_item_append(m_popup, m_items.at(i).title().utf8().data(), 0,
178 contextMenuItemSelectedCallback, &(m_items.at(i)));
183 static void contextMenuPopupDismissedCallback(void* data, Evas_Object* obj, void* eventInfo)
185 #if ENABLE(TIZEN_WEBKIT2_FOCUS_RING)
186 static_cast<PageClientImpl*>(data)->hideFocusRing();
188 static_cast<PageClientImpl*>(data)->setIsContextMenuVisible(false);
191 void WebContextMenuProxyTizen::createEflMenu()
197 void WebContextMenuProxyTizen::showContextMenu(const WebCore::IntPoint& position, const Vector<WebContextMenuItemData>& items)
199 #if ENABLE(TIZEN_WEBKIT2_CONTEXT_MENU_TEXT_SELECTION_MODE)
200 m_positionForSelection = position;
203 #if ENABLE(TIZEN_CONTEXT_MENU_WEBKIT_2)
204 if (items.isEmpty()) {
205 #if ENABLE(TIZEN_WEBKIT2_TEXT_SELECTION)
206 if (m_pageClientImpl->isTextSelectionMode())
207 m_pageClientImpl->setIsTextSelectionMode(false);
212 createEflMenu(items);
214 #if ENABLE(TIZEN_WEBKIT2_TEXT_SELECTION)
215 if (m_isContextMenuForTextSelection && !evas_object_focus_get(m_webView))
220 int webViewX, webViewY;
221 evas_object_geometry_get(m_webView, &webViewX, &webViewY, 0, 0);
222 IntPoint popupPosition = position;
223 #if ENABLE(TIZEN_WEBKIT2_TILED_BACKING_STORE)
224 if (m_pageClientImpl) {
225 popupPosition.scale(m_pageClientImpl->scaleFactor(), m_pageClientImpl->scaleFactor());
226 IntPoint scrollPosition = m_pageClientImpl->scrollPosition();
227 popupPosition.move(-scrollPosition.x(), -scrollPosition.y());
230 popupPosition.setX(popupPosition.x() + webViewX);
231 popupPosition.setY(popupPosition.y() + webViewY);
233 #if ENABLE(TIZEN_WEBKIT2_TEXT_SELECTION)
234 if (m_isContextMenuForTextSelection) {
235 if (!m_pageClientImpl->isTextSelectionMode())
236 m_pageClientImpl->setIsTextSelectionMode(true);
237 elm_object_style_set(m_popup,"copypaste");
238 elm_ctxpopup_horizontal_set(m_popup, EINA_TRUE);
239 elm_ctxpopup_direction_priority_set(m_popup, ELM_CTXPOPUP_DIRECTION_UP, ELM_CTXPOPUP_DIRECTION_UP, ELM_CTXPOPUP_DIRECTION_UP, ELM_CTXPOPUP_DIRECTION_UP);
243 evas_object_move(m_popup, popupPosition.x(), popupPosition.y());
244 evas_object_show(m_popup);
246 evas_object_smart_callback_add(m_popup, "dismissed", contextMenuPopupDismissedCallback, m_pageClientImpl);
248 m_pageClientImpl->setIsContextMenuVisible(true);
249 #if ENABLE(TOUCH_EVENTS) && ENABLE(TIZEN_GESTURE)
250 // Cancel touch event when ContextMenu is shown.
251 EwkViewImpl::fromEvasObject(m_webView)->feedTouchEventsByType(EWK_TOUCH_CANCEL);
260 void WebContextMenuProxyTizen::hideContextMenu()
262 #if ENABLE(TIZEN_CONTEXT_MENU_WEBKIT_2)
264 evas_object_hide(m_popup);
265 m_pageClientImpl->setIsContextMenuVisible(false);
271 #if ENABLE(TIZEN_WEBKIT2_CONTEXT_MENU_TEXT_SELECTION_MODE)
272 WebCore::IntPoint& WebContextMenuProxyTizen::positionForSelection()
274 return m_positionForSelection;
278 } // namespace WebKit