Implemented selection by doubleTap in WebKit.
authorYuni Jeong <yhnet.jung@samsung.com>
Thu, 4 Jul 2013 14:32:38 +0000 (23:32 +0900)
committerGerrit Code Review <gerrit@gerrit.vlan144.tizendev.org>
Thu, 10 Oct 2013 05:50:26 +0000 (05:50 +0000)
[Title] Implemented selection by doubleTap in WebKit.
[Issue#] N/A
[Problem] When doubleTap on any text of email composor, sometimes selection is not working properly.
[Cause] Current, selection by doubleTap is implemented in Email.
        So, when doubleTap on any text of email composor,
        selection routine from email is called and tap is performed twice from WebKit.
        Tap should not be performed in case of doubleTap from email.
[Solution] Moved selection by doubleTap to WebKit.

Change-Id: I4440325118c302b2473a9b1f23734cf060f71eb3

13 files changed:
Source/WebKit2/UIProcess/API/efl/PageClientImpl.cpp
Source/WebKit2/UIProcess/API/efl/PageClientImpl.h
Source/WebKit2/UIProcess/API/efl/ewk_settings.cpp
Source/WebKit2/UIProcess/API/efl/ewk_settings.h
Source/WebKit2/UIProcess/API/efl/ewk_settings_private.h
Source/WebKit2/UIProcess/API/efl/tizen/GestureClient.cpp
Source/WebKit2/UIProcess/API/efl/tizen/TextSelection.cpp
Source/WebKit2/UIProcess/API/efl/tizen/TextSelection.h
Source/WebKit2/UIProcess/WebPageProxy.h
Source/WebKit2/UIProcess/efl/WebPageProxyEfl.cpp
Source/WebKit2/WebProcess/WebPage/WebPage.h
Source/WebKit2/WebProcess/WebPage/WebPage.messages.in
Source/WebKit2/WebProcess/WebPage/efl/WebPageEfl.cpp

index 74cb953..2407650 100755 (executable)
@@ -394,6 +394,14 @@ void PageClientImpl::didChangeViewportProperties(const WebCore::ViewportAttribut
     double scaleRatioBeforeRotation = m_scaleFactor / m_viewportConstraints.minimumScale;
     m_viewportConstraints = computeViewportConstraints(attributes);
 
+#if ENABLE(TIZEN_GESTURE)
+    bool doubleTapEnabled = userScalable();
+#if ENABLE(TIZEN_WEBKIT2_TEXT_SELECTION)
+    doubleTapEnabled |= ewk_settings_select_word_automatically_get(ewk_view_settings_get(m_viewImpl->view()));
+#endif
+    m_viewImpl->setDoubleTapEnabled(doubleTapEnabled);
+#endif
+
     // Initially, m_scaleFactor is not decided yet.
     // So, we should update visible content rect at here.
     if (!m_scaleFactor) {
@@ -1200,6 +1208,11 @@ void PageClientImpl::changeContextMenuPosition(IntPoint& point)
 {
     m_textSelection->changeContextMenuPosition(point);
 }
+
+void PageClientImpl::selectWordAutomatically(const IntPoint& point)
+{
+    m_textSelection->selectWordAutomatically(point);
+}
 #endif
 
 #if ENABLE(TIZEN_OFFLINE_PAGE_SAVE)
index 5c58d30..8ce4e06 100755 (executable)
@@ -187,6 +187,7 @@ public:
     void requestToShowTextSelectionHandlesAndContextMenu();
     void initTextSelectionHandlesMouseDownedStatus();
     void changeContextMenuPosition(WebCore::IntPoint& point);
+    void selectWordAutomatically(const WebCore::IntPoint& point);
 #endif
 
 #if ENABLE(TIZEN_OFFLINE_PAGE_SAVE)
index 4517da5..92b4a10 100755 (executable)
@@ -666,3 +666,26 @@ Eina_Bool ewk_settings_text_style_state_enabled_get(const Ewk_Settings* settings
     return false;
 #endif
 }
+
+Eina_Bool ewk_settings_select_word_automatically_set(Ewk_Settings* settings, Eina_Bool enable)
+{
+    EINA_SAFETY_ON_NULL_RETURN_VAL(settings, false);
+
+#if ENABLE(TIZEN_WEBKIT2_TEXT_SELECTION)
+    settings->setAutoSelectWord(enable);
+    return true;
+#else
+    return false;
+#endif
+}
+
+Eina_Bool ewk_settings_select_word_automatically_get(const Ewk_Settings* settings)
+{
+    EINA_SAFETY_ON_NULL_RETURN_VAL(settings, false);
+
+#if ENABLE(TIZEN_WEBKIT2_TEXT_SELECTION)
+    return settings->autoSelectWord();
+#else
+    return false;
+#endif
+}
index 712d467..2b516b4 100755 (executable)
@@ -701,6 +701,28 @@ EAPI void ewk_settings_text_style_state_enabled_set(Ewk_Settings *settings, Eina
 EAPI Eina_Bool ewk_settings_text_style_state_enabled_get(const Ewk_Settings *settings);
 // #endif
 
+// #if ENABLE(TIZEN_WEBKIT2_TEXT_SELECTION)
+/**
+ * Requests to enable/disable to select word by double tap
+ *
+ * @param settings settings object to enable/disable to select word by double tap
+ * @param enable @c EINA_TRUE to select word by double tap
+ *        @c EINA_FALSE to disable
+ *
+ * @return @c EINA_TRUE on success or @c EINA_FALSE on failure
+ */
+EAPI Eina_Bool ewk_settings_select_word_automatically_set(Ewk_Settings *settings, Eina_Bool enabled);
+
+/**
+ * Returns enable/disable text selection by double tap
+ *
+ * @param settings settings object to get whether word by double tap is selected
+ *
+ * @return @c EINA_TRUE on enable or @c EINA_FALSE on disable
+ */
+EAPI Eina_Bool ewk_settings_select_word_automatically_get(const Ewk_Settings *settings);
+// #endif
+
 #ifdef __cplusplus
 }
 #endif
index 82169e0..8a74f37 100755 (executable)
@@ -66,6 +66,8 @@ public:
     void setTextSelectionEnabled(bool enable) { m_textSelectionEnabled = enable; }
     bool autoClearTextSelection() const { return m_autoClearTextSelection; }
     void setAutoClearTextSelection(bool enable) { m_autoClearTextSelection = enable; }
+    bool autoSelectWord() const { return m_autoSelectWord; }
+    void setAutoSelectWord(bool enable) { m_autoSelectWord = enable; }
 #endif
 #endif
 
@@ -80,6 +82,7 @@ private:
 #if ENABLE(TIZEN_WEBKIT2_TEXT_SELECTION)
         , m_textSelectionEnabled(true)
         , m_autoClearTextSelection(true)
+        , m_autoSelectWord(false)
 #endif
 #endif
     {
@@ -97,6 +100,7 @@ private:
 #if ENABLE(TIZEN_WEBKIT2_TEXT_SELECTION)
     bool m_textSelectionEnabled;
     bool m_autoClearTextSelection;
+    bool m_autoSelectWord;
 #endif
 #endif
 };
index 729bc25..26abfac 100755 (executable)
@@ -304,17 +304,24 @@ void GestureClient::movePinch(const IntPoint& position, double scale)
 
 void GestureClient::endDoubleTap(const IntPoint& position)
 {
+    if (!m_isGestureEnabled) {
+        setDoubleTapScheduled(true, position);
+        return;
+    }
+
     PageClientImpl* pageClientImpl = ewkViewGetPageClient(m_viewImpl->view());
 
-#if ENABLE(TIZEN_WEBKIT2_TEXT_ZOOM)
-    if (!pageClientImpl || m_viewImpl->page()->pageGroup()->preferences()->textZoomEnabled())
+#if ENABLE(TIZEN_WEBKIT2_TEXT_SELECTION)
+    if (ewk_settings_select_word_automatically_get(ewk_view_settings_get(m_viewImpl->view()))) {
+        pageClientImpl->selectWordAutomatically(position);
         return;
+    }
 #endif
 
-    if (!m_isTapEnabled) {
-        setDoubleTapScheduled(true, position);
+#if ENABLE(TIZEN_WEBKIT2_TEXT_ZOOM)
+    if (!pageClientImpl || m_viewImpl->page()->pageGroup()->preferences()->textZoomEnabled())
         return;
-    }
+#endif
 
     if (pageClientImpl->userScalable())
         m_smartZoom->start(position.x(), position.y());
index 71dd024..5dc183d 100755 (executable)
@@ -49,6 +49,7 @@ TextSelection::TextSelection(EwkViewImpl* viewImpl)
 #endif
       , m_handleMovingDirection(HandleMovingDirectionNormal)
       , m_isSelectionInScrollingMode(false)
+      , m_isAutoWordSelectionScheduled(false)
 {
     ASSERT(viewWidget);
 
@@ -106,6 +107,9 @@ void TextSelection::update()
         informTextStyleState();
 #endif
 
+    if (!editorState.shouldIgnoreCompositionSelectionChange && !editorState.hasComposition && m_isAutoWordSelectionScheduled)
+        setAutoWordSelection(m_scheduledAutoWordSelectionPosition);
+
     if (isTextSelectionMode()) {
         if (!editorState.selectionIsRange) {
             if (editorState.isContentEditable && !evas_object_focus_get(m_viewImpl->view())) {
@@ -573,7 +577,7 @@ bool TextSelection::textSelectionDown(const IntPoint& point)
     setIsTextSelectionMode(false);
 
     IntPoint contentsPoint = m_viewImpl->transformFromScene().mapPoint(point);
-    bool result = m_viewImpl->page()->selectClosestWord(contentsPoint);
+    bool result = m_viewImpl->page()->selectClosestWord(contentsPoint, false);
     if (!result)
         return false;
 
@@ -656,12 +660,12 @@ void TextSelection::textSelectionMove(const IntPoint& point)
 
         if (!scrolledX && !scrolledY) {
             viewPoint = m_viewImpl->transformFromScene().mapPoint(updatedPoint);
-            m_viewImpl->page()->selectClosestWord(viewPoint);
+            m_viewImpl->page()->selectClosestWord(viewPoint, false);
             updateMagnifier(updatedPoint);
         }
     } else {
         viewPoint = m_viewImpl->transformFromScene().mapPoint(point);
-        m_viewImpl->page()->selectClosestWord(viewPoint);
+        m_viewImpl->page()->selectClosestWord(viewPoint, false);
         updateMagnifier(point);
     }
     showMagnifier();
@@ -821,6 +825,41 @@ void TextSelection::informTextStyleState()
     ewkViewTextStyleState(m_viewImpl->view(), startEvasPoint, endEvasPoint);
 }
 #endif
+
+void TextSelection::selectWordAutomatically(const IntPoint& point)
+{
+    EditorState editorState = m_viewImpl->page()->editorState();
+    if (editorState.hasComposition) {
+        setAutoWordSelectionScheduled(true, point);
+        m_viewImpl->inputMethodContext()->resetIMFContext();
+        return;
+    }
+
+    setAutoWordSelection(point);
+}
+
+void TextSelection::setAutoWordSelectionScheduled(bool scheduled, const IntPoint& position)
+{
+    m_isAutoWordSelectionScheduled = scheduled;
+    m_scheduledAutoWordSelectionPosition = position;
+}
+
+void TextSelection::setAutoWordSelection(const IntPoint& point)
+{
+    IntPoint contentsPoint = m_viewImpl->transformFromScene().mapPoint(point);
+
+    setAutoWordSelectionScheduled(false, IntPoint(0, 0));
+    setIsTextSelectionMode(false);
+
+    bool result = m_viewImpl->page()->selectClosestWord(contentsPoint, true);
+    if (!result)
+        return;
+
+    setIsTextSelectionMode(true);
+
+    updateHandlers();
+    showContextMenu();
+}
 } // namespace WebKit
 
 #endif // TIZEN_WEBKIT2_TEXT_SELECTION
index 3cce5ba..bea2df5 100755 (executable)
@@ -94,6 +94,7 @@ public:
     void initHandlesMouseDownedStatus();
 
     void changeContextMenuPosition(WebCore::IntPoint& position);
+    void selectWordAutomatically(const WebCore::IntPoint& point);
 
     friend class PageClientImpl; // to allow hideHandlers() call while zooming
 private:
@@ -129,6 +130,8 @@ private:
 #if ENABLE(TIZEN_WEBKIT2_GET_TEXT_STYLE_FOR_SELECTION)
     void informTextStyleState();
 #endif
+    void setAutoWordSelectionScheduled(bool scheduled, const WebCore::IntPoint& position);
+    void setAutoWordSelection(const WebCore::IntPoint& point);
 
 private:
     EwkViewImpl* m_viewImpl;
@@ -146,6 +149,8 @@ private:
 #endif
     int m_handleMovingDirection;
     bool m_isSelectionInScrollingMode;
+    bool m_isAutoWordSelectionScheduled;
+    WebCore::IntPoint  m_scheduledAutoWordSelectionPosition;
 };
 
 } // namespace WebKit
index 6991f2c..8bc5cb2 100755 (executable)
@@ -1002,7 +1002,7 @@ public:
 #endif
 
 #if ENABLE(TIZEN_WEBKIT2_TEXT_SELECTION)
-    bool selectClosestWord(const WebCore::IntPoint&);
+    bool selectClosestWord(const WebCore::IntPoint&, bool isAutoWordSelection);
     int setLeftSelection(const WebCore::IntPoint&, const int direction);
     int setRightSelection(const WebCore::IntPoint&, const int direction);
     bool getSelectionHandlers(WebCore::IntRect& leftRect, WebCore::IntRect& rightRect, int& selectionDirection);
index aad72a2..822a8ab 100755 (executable)
@@ -895,13 +895,13 @@ void WebPageProxy::startOfflinePageSave(String subresourceFolderName)
 #endif
 
 #if ENABLE(TIZEN_WEBKIT2_TEXT_SELECTION)
-bool WebPageProxy::selectClosestWord(const IntPoint& point)
+bool WebPageProxy::selectClosestWord(const IntPoint& point, bool isAutoWordSelection)
 {
     if (!isValid())
         return false;
 
     bool result = false;
-    process()->sendSync(Messages::WebPage::SelectClosestWord(point), Messages::WebPage::SelectClosestWord::Reply(result), m_pageID);
+    process()->sendSync(Messages::WebPage::SelectClosestWord(point, isAutoWordSelection), Messages::WebPage::SelectClosestWord::Reply(result), m_pageID);
     return result;
 }
 
index d8424b2..b8dd229 100755 (executable)
@@ -341,7 +341,7 @@ public:
         HandleMovingDirectionNormal,
         HandleMovingDirectionReverse,
     };
-    void selectClosestWord(const WebCore::IntPoint&, bool& result);
+    void selectClosestWord(const WebCore::IntPoint&, bool isAutoWordSelection, bool& result);
     void setLeftSelection(const WebCore::IntPoint&, const int direction, int& result);
     void setRightSelection(const WebCore::IntPoint&, const int direction, int& result);
     bool isSelectionOnlyImage() const;
index ebad1ed..965949a 100755 (executable)
@@ -379,7 +379,7 @@ messages -> WebPage {
 #endif
 
 #if ENABLE(TIZEN_WEBKIT2_TEXT_SELECTION)
-    SelectClosestWord(WebCore::IntPoint point) -> (bool result)
+    SelectClosestWord(WebCore::IntPoint point, bool isAutoWordSelection) -> (bool result)
     SetLeftSelection(WebCore::IntPoint point, int direction) -> (int result)
     SetRightSelection(WebCore::IntPoint point, int direction) -> (int result)
     GetSelectionHandlers() -> (WebCore::IntRect leftRect, WebCore::IntRect rightRect, int selectionDirection, WebCore::IntRect updateEditorRect)
index 94b4ee4..776fbbe 100644 (file)
@@ -1264,7 +1264,7 @@ void WebPage::startOfflinePageSave(String subresourceFolderName)
 #endif
 
 #if ENABLE(TIZEN_WEBKIT2_TEXT_SELECTION)
-void WebPage::selectClosestWord(const IntPoint& point, bool& result)
+void WebPage::selectClosestWord(const IntPoint& point, bool isAutoWordSelection, bool& result)
 {
     result = false;
 
@@ -1289,8 +1289,19 @@ void WebPage::selectClosestWord(const IntPoint& point, bool& result)
     HTMLInputElement* inputElement = node->toInputElement();
 
     if (hitTestResult.isContentEditable()) {
+#if ENABLE(TIZEN_INPUT_TAG_EXTENSION)
+        if (!inputElement || (inputElement
+            && !inputElement->isDateField() && !inputElement->isDateTimeField() && !inputElement->isDateTimeLocalField()
+            && !inputElement->isMonthField() && !inputElement->isTimeField() && !inputElement->isWeekField())) {
+            result = setCaretPosition(point);
+            if (!isAutoWordSelection)
+                return;
+        }
+#else
         result = setCaretPosition(point);
-        return;
+        if (!isAutoWordSelection)
+            return;
+#endif
     }
 
 #if ENABLE(TIZEN_INPUT_TAG_EXTENSION)