Implement that a text selection handle can be moved over another text selection handle.
[framework/web/webkit-efl.git] / Source / WebKit2 / UIProcess / API / efl / tizen / TextSelection.cpp
index 3bbe3d3..470da01 100644 (file)
@@ -47,6 +47,7 @@ TextSelection::TextSelection(EwkViewImpl* viewImpl)
 #if ENABLE(TIZEN_WEBKIT2_FOR_MOVING_TEXT_SELECTION_HANDLE_FROM_OSP)
       , m_selectedHandle(0)
 #endif
+      , m_handleMovingDirection(HandleMovingDirectionNormal)
 {
     ASSERT(viewWidget);
 
@@ -137,6 +138,7 @@ void TextSelection::setIsTextSelectionMode(bool isTextSelectionMode)
         hide();
         clear();
         initHandlesMouseDownedStatus();
+        setIsTextSelectionDowned(false);
     }
 
     m_isTextSelectionMode = isTextSelectionMode;
@@ -171,10 +173,18 @@ void TextSelection::updateHandlers()
     WebCore::IntPoint leftEvasPoint = toEvasTransform.mapPoint(leftRect.minXMaxYCorner());
     WebCore::IntPoint rightEvasPoint = toEvasTransform.mapPoint(rightRect.maxXMaxYCorner());
 
+    TextSelectionHandle* shownLeftHandle = m_leftHandle;
+    TextSelectionHandle* shownRightHandle = m_rightHandle;
+
+    if (m_handleMovingDirection == HandleMovingDirectionReverse) {
+        shownLeftHandle = m_rightHandle;
+        shownRightHandle = m_leftHandle;
+    }
+
     EditorState editorState = m_viewImpl->page()->editorState();
     if (editorState.isContentEditable) {
-        m_leftHandle->hide();
-        m_rightHandle->hide();
+        shownLeftHandle->hide();
+        shownRightHandle->hide();
 
         WebCore::IntRect editorRect = editorState.editorRect;
         WebCore::IntPoint editorLeftEvasPoint = toEvasTransform.mapPoint(editorRect.location());
@@ -184,21 +194,21 @@ void TextSelection::updateHandlers()
         evas_object_geometry_get(m_viewImpl->view(), &webViewX, &webViewY, &webViewWidth, &webViewHeight);
         if ((editorLeftEvasPoint.x() <= leftEvasPoint.x() && editorLeftEvasPoint.y() <= leftEvasPoint.y())
             && (webViewX <= leftEvasPoint.x() && webViewY <= leftEvasPoint.y())) {
-            m_leftHandle->move(leftEvasPoint, m_viewImpl->transformToScene().mapRect(leftRect));
-            m_leftHandle->show();
+            shownLeftHandle->move(leftEvasPoint, m_viewImpl->transformToScene().mapRect(leftRect));
+            shownLeftHandle->show();
         }
 
         if ((editorRightEvasPoint.x() >= rightEvasPoint.x() && editorRightEvasPoint.y() >= rightEvasPoint.y())
             && ((webViewX + webViewWidth) >= rightEvasPoint.x() && (webViewY <= rightEvasPoint.y() && (webViewY + webViewHeight) >= rightEvasPoint.y()))) {
-            m_rightHandle->move(rightEvasPoint, m_viewImpl->transformToScene().mapRect(rightRect));
-            m_rightHandle->show();
+            shownRightHandle->move(rightEvasPoint, m_viewImpl->transformToScene().mapRect(rightRect));
+            shownRightHandle->show();
         }
     } else {
-        m_leftHandle->move(leftEvasPoint, m_viewImpl->transformToScene().mapRect(leftRect));
-        m_leftHandle->show();
+        shownLeftHandle->move(leftEvasPoint, m_viewImpl->transformToScene().mapRect(leftRect));
+        shownLeftHandle->show();
 
-        m_rightHandle->move(rightEvasPoint, m_viewImpl->transformToScene().mapRect(rightRect));
-        m_rightHandle->show();
+        shownRightHandle->move(rightEvasPoint, m_viewImpl->transformToScene().mapRect(rightRect));
+        shownRightHandle->show();
     }
 }
 
@@ -349,13 +359,17 @@ void TextSelection::hideContextMenu()
 
 void TextSelection::setLeftSelectionToEvasPoint(const IntPoint& evasPoint)
 {
-    m_viewImpl->page()->setLeftSelection(m_viewImpl->transformFromScene().mapPoint(evasPoint));
+    int result = m_viewImpl->page()->setLeftSelection(m_viewImpl->transformFromScene().mapPoint(evasPoint), m_handleMovingDirection);
+    if (result)
+        m_handleMovingDirection = result;
     updateHandlers();
 }
 
 void TextSelection::setRightSelectionToEvasPoint(const IntPoint& evasPoint)
 {
-    m_viewImpl->page()->setRightSelection(m_viewImpl->transformFromScene().mapPoint(evasPoint));
+    int result = m_viewImpl->page()->setRightSelection(m_viewImpl->transformFromScene().mapPoint(evasPoint), m_handleMovingDirection);
+    if (result)
+        m_handleMovingDirection = result;
     updateHandlers();
 }
 
@@ -401,7 +415,10 @@ void TextSelection::handleMouseMove(TextSelectionHandle* handle, const IntPoint&
 
 void TextSelection::handleMouseUp(TextSelectionHandle* /* handle */, const IntPoint& /* position */)
 {
+    m_handleMovingDirection = HandleMovingDirectionNormal;
+
     hideMagnifier();
+    updateHandlers();
     showContextMenu();
 }
 
@@ -475,7 +492,7 @@ Eina_Bool TextSelection::moveAnimatorCallback(void* data)
 
 // 'return false' means text selection is not possible for point.
 // 'return true' means text selection is possible.
-bool TextSelection::textSelectionDown(const IntPoint& point, bool isStartedTextSelectionFromOutside)
+bool TextSelection::textSelectionDown(const IntPoint& point)
 {
     // text selection should be ignored when longtap on handle from osp
     if (!isEnabled() && isTextSelectionHandleDowned())
@@ -487,7 +504,7 @@ bool TextSelection::textSelectionDown(const IntPoint& point, bool isStartedTextS
     setIsTextSelectionMode(false);
 
     IntPoint contentsPoint = m_viewImpl->transformFromScene().mapPoint(point);
-    bool result = m_viewImpl->page()->selectClosestWord(contentsPoint, isStartedTextSelectionFromOutside);
+    bool result = m_viewImpl->page()->selectClosestWord(contentsPoint);
     if (!result)
         return false;
 
@@ -508,7 +525,7 @@ bool TextSelection::textSelectionDown(const IntPoint& point, bool isStartedTextS
 
 static int s_textSelectionMargin = 5;
 
-void TextSelection::textSelectionMove(const IntPoint& point, bool isStartedTextSelectionFromOutside)
+void TextSelection::textSelectionMove(const IntPoint& point)
 {
     // text selection should be ignored when longtap on handle from osp
     if (!isEnabled() && isTextSelectionHandleDowned())
@@ -521,7 +538,21 @@ void TextSelection::textSelectionMove(const IntPoint& point, bool isStartedTextS
 
     WebCore::IntPoint viewPoint;
     EditorState editorState = m_viewImpl->page()->editorState();
+    bool isInEditablePicker = false;
+
+#if ENABLE(TIZEN_INPUT_TAG_EXTENSION)
     if (editorState.isContentEditable) {
+        if (editorState.inputMethodHints == "date"
+            || editorState.inputMethodHints == "datetime"
+            || editorState.inputMethodHints == "datetime-local"
+            || editorState.inputMethodHints == "month"
+            || editorState.inputMethodHints == "time"
+            || editorState.inputMethodHints == "week")
+            isInEditablePicker = true;
+    }
+#endif
+
+    if (editorState.isContentEditable && !isInEditablePicker) {
         IntRect mapRect = m_viewImpl->transformToScene().mapRect(editorState.editorRect);
         IntPoint updatedPoint = point;
         bool scrolledY = false;
@@ -556,12 +587,12 @@ void TextSelection::textSelectionMove(const IntPoint& point, bool isStartedTextS
 
         if (!scrolledX && !scrolledY) {
             viewPoint = m_viewImpl->transformFromScene().mapPoint(updatedPoint);
-            m_viewImpl->page()->selectClosestWord(viewPoint, isStartedTextSelectionFromOutside);
+            m_viewImpl->page()->selectClosestWord(viewPoint);
             updateMagnifier(updatedPoint);
         }
     } else {
         viewPoint = m_viewImpl->transformFromScene().mapPoint(point);
-        m_viewImpl->page()->selectClosestWord(viewPoint, isStartedTextSelectionFromOutside);
+        m_viewImpl->page()->selectClosestWord(viewPoint);
         updateMagnifier(point);
     }
     showMagnifier();