Changed the postion of context menu to avaliable space
[framework/web/webkit-efl.git] / Source / WebKit2 / UIProcess / tizen / WebContextMenuProxyTizen.cpp
index 3c90bab..11cac6f 100755 (executable)
 
 #include <stdio.h>
 
+#if ENABLE(TIZEN_HW_MORE_BACK_KEY)
+#include <dlfcn.h>
+#include <efl_assist.h>
+extern void* EflAssistHandle;
+#endif
+
 using namespace WebCore;
 
 namespace WebKit {
@@ -58,6 +64,9 @@ WebContextMenuProxyTizen::WebContextMenuProxyTizen(Evas_Object* webView, WebPage
     , m_webView(webView)
     , m_items()
 #endif
+#if ENABLE(TIZEN_WEBKIT2_TEXT_SELECTION)
+    , m_contextShowTimer(0)
+#endif
 #if ENABLE(TIZEN_WEBKIT2_CONTEXT_MENU_TEXT_SELECTION_MODE)
     , m_positionForSelection()
 #endif
@@ -93,6 +102,13 @@ void WebContextMenuProxyTizen::contextMenuItemSelectedCallback(void* data, Evas_
     menuProxy->m_popup = 0;
 }
 
+#if ENABLE(TIZEN_HW_MORE_BACK_KEY)
+static void contextMenuHwBackKeyCallback(void* data, Evas_Object* obj, void* eventInfo)
+{
+    elm_ctxpopup_dismiss(obj);
+}
+#endif
+
 void WebContextMenuProxyTizen::createEflMenu(const Vector<WebContextMenuItemData>& items)
 {
     if (m_popup)
@@ -106,6 +122,14 @@ void WebContextMenuProxyTizen::createEflMenu(const Vector<WebContextMenuItemData
     if (!m_popup)
         return;
 
+#if ENABLE(TIZEN_HW_MORE_BACK_KEY)
+    if (EflAssistHandle) {
+        void (*webkit_ea_object_event_callback_add)(Evas_Object *, Ea_Callback_Type , Ea_Event_Cb func, void *);
+        webkit_ea_object_event_callback_add = (void (*)(Evas_Object *, Ea_Callback_Type , Ea_Event_Cb func, void *))dlsym(EflAssistHandle, "ea_object_event_callback_add");
+        (*webkit_ea_object_event_callback_add)(m_popup, EA_CALLBACK_BACK, contextMenuHwBackKeyCallback, 0);
+    }
+#endif
+
     m_items = items;
     evas_object_data_set(m_popup, "WebContextMenuProxyTizen", this);
     elm_object_tree_focus_allow_set(m_popup, false);
@@ -115,12 +139,23 @@ void WebContextMenuProxyTizen::createEflMenu(const Vector<WebContextMenuItemData
     int clipboardItemSize = ClipboardHelper::numberOfItems();
     TIZEN_LOGI("clipboardItemSize : %d", clipboardItemSize);
 #endif
+
+#if ENABLE(TIZEN_WEBKIT2_TEXT_SELECTION)
+    m_isContextMenuForTextSelection = false;
+#endif
+
     for (size_t i = 0; i < size; i++) {
 #if ENABLE(TIZEN_WEBKIT2_CLIPBOARD_HELPER)
         if ((m_items.at(i).action() == ContextMenuItemTagPaste || m_items.at(i).action() == ContextMenuItemTagClipboard) && !clipboardItemSize)
             continue;
 #endif
 
+#if ENABLE(TIZEN_WEBKIT2_TEXT_SELECTION)
+        if (m_items.at(i).action() == ContextMenuItemTagCopy || m_items.at(i).action() == ContextMenuItemTagSelectAll
+            || m_items.at(i).action() == ContextMenuItemTagSelectWord || m_items.at(i).action() == ContextMenuItemTagPaste)
+            m_isContextMenuForTextSelection = true;
+#endif
+
 #if ENABLE(TIZEN_WEBKIT2_CONTEXT_MENU_ICON_TYPE_SUPPORT)
         if (!m_items.at(i).title().isEmpty() || !m_items.at(i).iconFile().isEmpty()) {
             Evas_Object* icon = 0;
@@ -148,13 +183,26 @@ void WebContextMenuProxyTizen::createEflMenu(const Vector<WebContextMenuItemData
     }
 }
 
-static void contextMenuPopupDismissedCallback(void* data, Evas_Object* obj, void* eventInfo)
+#if ENABLE(TIZEN_CONTEXT_MENU_WEBKIT_2)
+void WebContextMenuProxyTizen::contextMenuPopupDismissedCallback(void* data, Evas_Object* obj, void* eventInfo)
 {
+    WebContextMenuProxyTizen* menuProxy = static_cast<WebContextMenuProxyTizen*>(data);
+    if (menuProxy) {
 #if ENABLE(TIZEN_WEBKIT2_FOCUS_RING)
-    static_cast<PageClientImpl*>(data)->hideFocusRing();
+        menuProxy->m_pageClientImpl->hideFocusRing();
 #endif
-    static_cast<PageClientImpl*>(data)->setIsContextMenuVisible(false);
+        menuProxy->m_pageClientImpl->setIsContextMenuVisible(false);
+
+#if ENABLE(TIZEN_WEBKIT2_TEXT_SELECTION)
+        if (menuProxy->m_contextShowTimer) {
+            ecore_timer_del(menuProxy->m_contextShowTimer);
+            menuProxy->m_contextShowTimer = 0;
+        }
+#endif
+    }
 }
+#endif
+
 #else
 void WebContextMenuProxyTizen::createEflMenu()
 {
@@ -162,6 +210,36 @@ void WebContextMenuProxyTizen::createEflMenu()
 }
 #endif
 
+#if ENABLE(TIZEN_WEBKIT2_TEXT_SELECTION)
+Eina_Bool WebContextMenuProxyTizen::contextMenuTimerCallback(void* data)
+{
+    WebContextMenuProxyTizen *contextMenuProxy = static_cast<WebContextMenuProxyTizen*>(data);
+    if (contextMenuProxy) {
+        if (contextMenuProxy->m_popup)
+            evas_object_hide(contextMenuProxy->m_popup);
+
+        contextMenuProxy->m_pageClientImpl->setIsContextMenuVisible(false);
+        EditorState editorState = contextMenuProxy->m_page->editorState();
+        if (!editorState.selectionIsRange && editorState.isContentEditable)
+            contextMenuProxy->m_pageClientImpl->setIsTextSelectionMode(false);
+#if ENABLE(TIZEN_WEBKIT2_FOCUS_RING)
+        contextMenuProxy->m_pageClientImpl->hideFocusRing();
+#endif
+    }
+     return ECORE_CALLBACK_CANCEL;
+}
+
+void WebContextMenuProxyTizen::startContextMenuTimer()
+{
+    double contextMenuDispTime = 3.0;
+    if (m_contextShowTimer) {
+        ecore_timer_del(m_contextShowTimer);
+        m_contextShowTimer = 0;
+    }
+    m_contextShowTimer = ecore_timer_add(contextMenuDispTime, contextMenuTimerCallback, this);
+}
+#endif // TIZEN_WEBKIT2_TEXT_SELECTION
+
 void WebContextMenuProxyTizen::showContextMenu(const WebCore::IntPoint& position, const Vector<WebContextMenuItemData>& items)
 {
 #if ENABLE(TIZEN_WEBKIT2_CONTEXT_MENU_TEXT_SELECTION_MODE)
@@ -179,6 +257,11 @@ void WebContextMenuProxyTizen::showContextMenu(const WebCore::IntPoint& position
 
     createEflMenu(items);
 
+#if ENABLE(TIZEN_WEBKIT2_TEXT_SELECTION)
+    if (m_isContextMenuForTextSelection && !evas_object_focus_get(m_webView))
+        return;
+#endif
+
     if (m_popup) {
         int webViewX, webViewY;
         evas_object_geometry_get(m_webView, &webViewX, &webViewY, 0, 0);
@@ -194,10 +277,13 @@ void WebContextMenuProxyTizen::showContextMenu(const WebCore::IntPoint& position
         popupPosition.setY(popupPosition.y() + webViewY);
 
 #if ENABLE(TIZEN_WEBKIT2_TEXT_SELECTION)
-        if (m_pageClientImpl->isTextSelectionMode()) {
+        if (m_isContextMenuForTextSelection) {
+            if (!m_pageClientImpl->isTextSelectionMode())
+                m_pageClientImpl->setIsTextSelectionMode(true);
+
             elm_object_style_set(m_popup,"copypaste");
             elm_ctxpopup_horizontal_set(m_popup, EINA_TRUE);
-            elm_ctxpopup_direction_priority_set(m_popup, ELM_CTXPOPUP_DIRECTION_UP, ELM_CTXPOPUP_DIRECTION_UP, ELM_CTXPOPUP_DIRECTION_UP, ELM_CTXPOPUP_DIRECTION_UP);
+            elm_ctxpopup_direction_priority_set(m_popup, ELM_CTXPOPUP_DIRECTION_UP, ELM_CTXPOPUP_DIRECTION_LEFT, ELM_CTXPOPUP_DIRECTION_RIGHT, ELM_CTXPOPUP_DIRECTION_DOWN);
 
             m_pageClientImpl->changeContextMenuPosition(popupPosition);
         }
@@ -206,13 +292,20 @@ void WebContextMenuProxyTizen::showContextMenu(const WebCore::IntPoint& position
         evas_object_move(m_popup, popupPosition.x(), popupPosition.y());
         evas_object_show(m_popup);
 
-        evas_object_smart_callback_add(m_popup, "dismissed", contextMenuPopupDismissedCallback, m_pageClientImpl);
+        evas_object_smart_callback_add(m_popup, "dismissed", contextMenuPopupDismissedCallback, this);
+
 
         m_pageClientImpl->setIsContextMenuVisible(true);
 #if ENABLE(TOUCH_EVENTS) && ENABLE(TIZEN_GESTURE)
         // Cancel touch event when ContextMenu is shown.
         EwkViewImpl::fromEvasObject(m_webView)->feedTouchEventsByType(EWK_TOUCH_CANCEL);
 #endif
+
+#if ENABLE(TIZEN_WEBKIT2_TEXT_SELECTION)
+        // Start the timer at the end
+        if (m_isContextMenuForTextSelection)
+            startContextMenuTimer();
+#endif
     }
 #else
     createEflMenu();
@@ -226,6 +319,12 @@ void WebContextMenuProxyTizen::hideContextMenu()
     if (m_popup)
         evas_object_hide(m_popup);
     m_pageClientImpl->setIsContextMenuVisible(false);
+#if ENABLE(TIZEN_WEBKIT2_TEXT_SELECTION)
+    if (m_contextShowTimer) {
+        ecore_timer_del(m_contextShowTimer);
+        m_contextShowTimer = 0;
+    }
+#endif
 #else
     notImplemented();
 #endif