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 EditorState editorState = contextMenuProxy->m_page->editorState();
223 if (!editorState.selectionIsRange && editorState.isContentEditable)
224 contextMenuProxy->m_pageClientImpl->setIsTextSelectionMode(false);
225 #if ENABLE(TIZEN_WEBKIT2_FOCUS_RING)
226 contextMenuProxy->m_pageClientImpl->hideFocusRing();
229 return ECORE_CALLBACK_CANCEL;
232 void WebContextMenuProxyTizen::startContextMenuTimer()
234 double contextMenuDispTime = 3.0;
235 if (m_contextShowTimer) {
236 ecore_timer_del(m_contextShowTimer);
237 m_contextShowTimer = 0;
239 m_contextShowTimer = ecore_timer_add(contextMenuDispTime, contextMenuTimerCallback, this);
241 #endif // TIZEN_WEBKIT2_TEXT_SELECTION
243 void WebContextMenuProxyTizen::showContextMenu(const WebCore::IntPoint& position, const Vector<WebContextMenuItemData>& items)
245 #if ENABLE(TIZEN_WEBKIT2_CONTEXT_MENU_TEXT_SELECTION_MODE)
246 m_positionForSelection = position;
249 #if ENABLE(TIZEN_CONTEXT_MENU_WEBKIT_2)
250 if (items.isEmpty()) {
251 #if ENABLE(TIZEN_WEBKIT2_TEXT_SELECTION)
252 if (m_pageClientImpl->isTextSelectionMode())
253 m_pageClientImpl->setIsTextSelectionMode(false);
258 createEflMenu(items);
260 #if ENABLE(TIZEN_WEBKIT2_TEXT_SELECTION)
261 if (m_isContextMenuForTextSelection && !evas_object_focus_get(m_webView))
266 int webViewX, webViewY;
267 evas_object_geometry_get(m_webView, &webViewX, &webViewY, 0, 0);
268 IntPoint popupPosition = position;
269 #if ENABLE(TIZEN_WEBKIT2_TILED_BACKING_STORE)
270 if (m_pageClientImpl) {
271 popupPosition.scale(m_pageClientImpl->scaleFactor(), m_pageClientImpl->scaleFactor());
272 IntPoint scrollPosition = m_pageClientImpl->scrollPosition();
273 popupPosition.move(-scrollPosition.x(), -scrollPosition.y());
276 popupPosition.setX(popupPosition.x() + webViewX);
277 popupPosition.setY(popupPosition.y() + webViewY);
279 #if ENABLE(TIZEN_WEBKIT2_TEXT_SELECTION)
280 if (m_isContextMenuForTextSelection) {
281 if (!m_pageClientImpl->isTextSelectionMode())
282 m_pageClientImpl->setIsTextSelectionMode(true);
284 elm_object_style_set(m_popup,"copypaste");
285 elm_ctxpopup_horizontal_set(m_popup, EINA_TRUE);
286 elm_ctxpopup_direction_priority_set(m_popup, ELM_CTXPOPUP_DIRECTION_UP, ELM_CTXPOPUP_DIRECTION_LEFT, ELM_CTXPOPUP_DIRECTION_RIGHT, ELM_CTXPOPUP_DIRECTION_DOWN);
288 m_pageClientImpl->changeContextMenuPosition(popupPosition);
292 evas_object_move(m_popup, popupPosition.x(), popupPosition.y());
293 evas_object_show(m_popup);
295 evas_object_smart_callback_add(m_popup, "dismissed", contextMenuPopupDismissedCallback, this);
298 m_pageClientImpl->setIsContextMenuVisible(true);
299 #if ENABLE(TOUCH_EVENTS) && ENABLE(TIZEN_GESTURE)
300 // Cancel touch event when ContextMenu is shown.
301 EwkViewImpl::fromEvasObject(m_webView)->feedTouchEventsByType(EWK_TOUCH_CANCEL);
304 #if ENABLE(TIZEN_WEBKIT2_TEXT_SELECTION)
305 // Start the timer at the end
306 if (m_isContextMenuForTextSelection)
307 startContextMenuTimer();
316 void WebContextMenuProxyTizen::hideContextMenu()
318 #if ENABLE(TIZEN_CONTEXT_MENU_WEBKIT_2)
320 evas_object_hide(m_popup);
321 m_pageClientImpl->setIsContextMenuVisible(false);
322 #if ENABLE(TIZEN_WEBKIT2_TEXT_SELECTION)
323 if (m_contextShowTimer) {
324 ecore_timer_del(m_contextShowTimer);
325 m_contextShowTimer = 0;
333 #if ENABLE(TIZEN_WEBKIT2_CONTEXT_MENU_TEXT_SELECTION_MODE)
334 WebCore::IntPoint& WebContextMenuProxyTizen::positionForSelection()
336 return m_positionForSelection;
340 } // namespace WebKit