Adjusted magnifier position properly in case that touched position is outside of...
[framework/web/webkit-efl.git] / Source / WebKit2 / UIProcess / API / efl / tizen / TextSelection.cpp
index 33dae6a..75f80ba 100755 (executable)
@@ -503,6 +503,8 @@ bool TextSelection::textSelectionDown(const IntPoint& point, bool isStartedTextS
     return true;
 }
 
+static int s_textSelectionMargin = 5;
+
 void TextSelection::textSelectionMove(const IntPoint& point, bool isStartedTextSelectionFromOutside)
 {
     // text selection should be ignored when longtap on handle from osp
@@ -519,18 +521,37 @@ void TextSelection::textSelectionMove(const IntPoint& point, bool isStartedTextS
     if (editorState.isContentEditable) {
         IntRect mapRect = m_viewImpl->transformToScene().mapRect(editorState.editorRect);
         IntPoint updatedPoint = point;
-        if ((point.y() < mapRect.y()) || (point.y() > ((mapRect.y()) + (mapRect.height()))))
-            updatedPoint.setY((mapRect.y()) + ((mapRect.height())/2) );
+        bool scrolledY = false;
+        if (point.y() < mapRect.y()) {
+            updatedPoint.setY(mapRect.y() + s_textSelectionMargin);
+            if (m_viewImpl->page()->scrollContentByLine(point,WebCore::DirectionBackward)) {
+                scrolledY = true;
+                updateMagnifier(updatedPoint);
+            }
+        } else if (point.y() > mapRect.maxY()) {
+            updatedPoint.setY(mapRect.maxY() - s_textSelectionMargin);
+            if (m_viewImpl->page()->scrollContentByLine(point,WebCore::DirectionForward)) {
+                scrolledY = true;
+                updateMagnifier(updatedPoint);
+            }
+        }
 
+        bool scrolledX = false;
         if (point.x() < mapRect.x()) {
-            updatedPoint.setX(mapRect.x());
-            if (m_viewImpl->page()->scrollContentByCharacter(point,WebCore::DirectionBackward))
+            updatedPoint.setX(mapRect.x() + s_textSelectionMargin);
+            if (m_viewImpl->page()->scrollContentByCharacter(point,WebCore::DirectionBackward)) {
+                scrolledX = true;
                 updateMagnifier(updatedPoint);
-        } else if (point.x() > ((mapRect.x()) + (mapRect.width()))) {
-            updatedPoint.setX((mapRect.x()) + (mapRect.width()));
-            if (m_viewImpl->page()->scrollContentByCharacter(point,WebCore::DirectionForward))
+            }
+        } else if (point.x() > mapRect.maxX()) {
+            updatedPoint.setX(mapRect.maxX() - s_textSelectionMargin);
+            if (m_viewImpl->page()->scrollContentByCharacter(point,WebCore::DirectionForward)) {
+                scrolledX = true;
                 updateMagnifier(updatedPoint);
-        } else {
+            }
+        }
+
+        if (!scrolledX && !scrolledY) {
             viewPoint = m_viewImpl->transformFromScene().mapPoint(updatedPoint);
             m_viewImpl->page()->selectClosestWord(viewPoint, isStartedTextSelectionFromOutside);
             updateMagnifier(updatedPoint);