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 using namespace WebCore;
52 WebContextMenuProxyTizen::WebContextMenuProxyTizen(Evas_Object* webView, WebPageProxy* page, PageClientImpl* pageClientImpl)
54 , m_pageClientImpl(pageClientImpl)
56 #if ENABLE(TIZEN_CONTEXT_MENU_WEBKIT_2)
61 #if ENABLE(TIZEN_WEBKIT2_CONTEXT_MENU_TEXT_SELECTION_MODE)
62 , m_positionForSelection()
67 WebContextMenuProxyTizen::~WebContextMenuProxyTizen()
69 #if ENABLE(TIZEN_CONTEXT_MENU_WEBKIT_2)
71 evas_object_del(m_popup);
75 #if ENABLE(TIZEN_CONTEXT_MENU_WEBKIT_2)
76 void WebContextMenuProxyTizen::contextMenuItemSelectedCallback(void* data, Evas_Object* obj, void* eventInfo)
78 WebContextMenuItemData itemData = *(static_cast<WebContextMenuItemData*>(data));
79 WebContextMenuProxyTizen* menuProxy = static_cast<WebContextMenuProxyTizen*>(evas_object_data_get(obj, "WebContextMenuProxyTizen"));
81 #if ENABLE(TIZEN_WEBKIT2_FOCUS_RING)
82 menuProxy->m_pageClientImpl->hideFocusRing();
85 menuProxy->m_page->contextMenuItemSelected(itemData);
86 menuProxy->hideContextMenu();
88 evas_object_del(menuProxy->m_popup);
89 menuProxy->m_popup = 0;
92 void WebContextMenuProxyTizen::createEflMenu(const Vector<WebContextMenuItemData>& items)
95 evas_object_del(m_popup);
97 Evas_Object* topWidget = elm_object_top_widget_get(elm_object_parent_widget_get(m_webView));
99 topWidget = m_webView;
101 m_popup = elm_ctxpopup_add(topWidget);
106 evas_object_data_set(m_popup, "WebContextMenuProxyTizen", this);
107 elm_object_tree_focus_allow_set(m_popup, false);
109 size_t size = m_items.size();
110 #if ENABLE(TIZEN_WEBKIT2_CLIPBOARD_HELPER)
111 int clipboardItemSize = ClipboardHelper::numberOfItems();
112 TIZEN_LOGI("clipboardItemSize : %d", clipboardItemSize);
114 for (size_t i = 0; i < size; i++) {
115 #if ENABLE(TIZEN_WEBKIT2_CLIPBOARD_HELPER)
116 if ((m_items.at(i).action() == ContextMenuItemTagPaste || m_items.at(i).action() == ContextMenuItemTagClipboard) && !clipboardItemSize)
120 #if ENABLE(TIZEN_WEBKIT2_CONTEXT_MENU_ICON_TYPE_SUPPORT)
121 if (!m_items.at(i).title().isEmpty() || !m_items.at(i).iconFile().isEmpty()) {
122 Evas_Object* icon = 0;
123 if (!m_items.at(i).iconFile().isEmpty()) {
124 icon = elm_icon_add(m_popup);
125 TIZEN_LOGI("icon file path : %s", m_items.at(i).iconFile().utf8().data());
126 if (!elm_image_file_set(icon, m_items.at(i).iconFile().utf8().data(), NULL)) {
127 TIZEN_LOGE("elm_image_file_set is failed");
132 if (!m_items.at(i).title().isEmpty())
133 elm_ctxpopup_item_append(m_popup, m_items.at(i).title().utf8().data(), icon,
134 contextMenuItemSelectedCallback, &(m_items.at(i)));
136 elm_ctxpopup_item_append(m_popup, 0, icon,
137 contextMenuItemSelectedCallback, &(m_items.at(i)));
140 if (!m_items.at(i).title().isEmpty())
141 elm_ctxpopup_item_append(m_popup, m_items.at(i).title().utf8().data(), 0,
142 contextMenuItemSelectedCallback, &(m_items.at(i)));
147 static void contextMenuPopupDismissedCallback(void* data, Evas_Object* obj, void* eventInfo)
149 #if ENABLE(TIZEN_WEBKIT2_FOCUS_RING)
150 static_cast<PageClientImpl*>(data)->hideFocusRing();
152 static_cast<PageClientImpl*>(data)->setIsContextMenuVisible(false);
155 void WebContextMenuProxyTizen::createEflMenu()
161 void WebContextMenuProxyTizen::showContextMenu(const WebCore::IntPoint& position, const Vector<WebContextMenuItemData>& items)
163 #if ENABLE(TIZEN_WEBKIT2_CONTEXT_MENU_TEXT_SELECTION_MODE)
164 m_positionForSelection = position;
167 #if ENABLE(TIZEN_CONTEXT_MENU_WEBKIT_2)
171 createEflMenu(items);
174 int webViewX, webViewY;
175 evas_object_geometry_get(m_webView, &webViewX, &webViewY, 0, 0);
176 IntPoint popupPosition = position;
177 #if ENABLE(TIZEN_WEBKIT2_TILED_BACKING_STORE)
178 if (m_pageClientImpl) {
179 popupPosition.scale(m_pageClientImpl->scaleFactor(), m_pageClientImpl->scaleFactor());
180 IntPoint scrollPosition = m_pageClientImpl->scrollPosition();
181 popupPosition.move(-scrollPosition.x(), -scrollPosition.y());
185 #if ENABLE(TIZEN_WEBKIT2_TEXT_SELECTION)
186 if ( m_pageClientImpl->isTextSelectionMode()) {
187 elm_ctxpopup_horizontal_set(m_popup, EINA_TRUE);
188 elm_ctxpopup_direction_priority_set(m_popup, ELM_CTXPOPUP_DIRECTION_UP, ELM_CTXPOPUP_DIRECTION_UP, ELM_CTXPOPUP_DIRECTION_UP, ELM_CTXPOPUP_DIRECTION_UP);
192 evas_object_move(m_popup, popupPosition.x() + webViewX, popupPosition.y() + webViewY);
193 evas_object_show(m_popup);
195 evas_object_smart_callback_add(m_popup, "dismissed", contextMenuPopupDismissedCallback, m_pageClientImpl);
197 m_pageClientImpl->setIsContextMenuVisible(true);
198 #if ENABLE(TOUCH_EVENTS) && ENABLE(TIZEN_GESTURE)
199 // Cancel touch event when ContextMenu is shown.
200 EwkViewImpl::fromEvasObject(m_webView)->feedTouchEventsByType(EWK_TOUCH_CANCEL);
209 void WebContextMenuProxyTizen::hideContextMenu()
211 #if ENABLE(TIZEN_CONTEXT_MENU_WEBKIT_2)
213 evas_object_hide(m_popup);
214 m_pageClientImpl->setIsContextMenuVisible(false);
220 #if ENABLE(TIZEN_WEBKIT2_CONTEXT_MENU_TEXT_SELECTION_MODE)
221 WebCore::IntPoint& WebContextMenuProxyTizen::positionForSelection()
223 return m_positionForSelection;
227 } // namespace WebKit