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
old mode 100755 (executable)
new mode 100644 (file)
index 088e76d..470da01
@@ -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);
 
@@ -172,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());
@@ -185,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();
     }
 }
 
@@ -350,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();
 }
 
@@ -402,7 +415,10 @@ void TextSelection::handleMouseMove(TextSelectionHandle* handle, const IntPoint&
 
 void TextSelection::handleMouseUp(TextSelectionHandle* /* handle */, const IntPoint& /* position */)
 {
+    m_handleMovingDirection = HandleMovingDirectionNormal;
+
     hideMagnifier();
+    updateHandlers();
     showContextMenu();
 }