Fixed invalid display of handlers for R2L languages
authorprathmesh.m <prathmesh.m@samsung.com>
Mon, 1 Jul 2013 09:20:30 +0000 (14:50 +0530)
committerGerrit Code Review <gerrit@gerrit.vlan144.tizendev.org>
Thu, 10 Oct 2013 05:49:04 +0000 (05:49 +0000)
[Title] Fixed invalid display of handlers for R2L languages
[Issue#] WEB-3433, WEB-3434
[Problem] Long press and extend the selection to multiple lines
    then the first selected lies getting cleared
[Cause] Handles were drawn according to the selection rects. In all
    cases the bottom left of 1st rect and bottom right of last rect
    was used for drawing handlers. This is correct in case of L2R
    languages as the base of selection will be at start of 1st rect
    and extent at the end of last rect, but in case of R2L languages
    the base is at the end of 1st rect and the extent is at the start
    of the last rect
[Solution] Obtained the direction of selected text from
    frameselection and depending on the selection direction if the
    language is R2L draw the handlers at end of 1st rect and start
    of the last rect.

Change-Id: I4528b7b5744e3db30cdae42d90f2201f326271d4

12 files changed:
Source/WebCore/editing/FrameSelection.h [changed mode: 0644->0755]
Source/WebKit2/Platform/CoreIPC/HandleMessage.h
Source/WebKit2/UIProcess/API/efl/ewk_view.cpp
Source/WebKit2/UIProcess/API/efl/tizen/TextSelection.cpp
Source/WebKit2/UIProcess/API/efl/tizen/TextSelection.h
Source/WebKit2/UIProcess/API/efl/tizen/TextSelectionHandle.cpp [changed mode: 0644->0755]
Source/WebKit2/UIProcess/API/efl/tizen/TextSelectionHandle.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

old mode 100644 (file)
new mode 100755 (executable)
index 94e2fb0..3d661c6
@@ -262,6 +262,9 @@ public:
 #if ENABLE(TIZEN_CONTEXT_MENU_SELECT)
     bool canEditableSelectRange() const;
 #endif
+#if ENABLE(TIZEN_WEBKIT2_TEXT_SELECTION)
+    TextDirection getSelectionTextDirection() { return directionOfSelection(); }
+#endif
 
 private:
     enum EPositionType { START, END, BASE, EXTENT };
index 3083105..fd06fd1 100755 (executable)
@@ -93,6 +93,12 @@ void callMemberFunction(const Arguments0&, Arguments3<R1, R2, R3>& replyArgs, C*
     (object->*function)(replyArgs.argument1, replyArgs.argument2, replyArgs.argument3);
 }
 
+template<typename C, typename MF, typename R1, typename R2, typename R3, typename R4>
+void callMemberFunction(const Arguments0&, Arguments4<R1, R2, R3, R4>& replyArgs, C* object, MF function)
+{
+    (object->*function)(replyArgs.argument1, replyArgs.argument2, replyArgs.argument3, replyArgs.argument4);
+}
+
 template<typename C, typename MF, typename P1>
 void callMemberFunction(const Arguments1<P1>& args, Arguments0&, C* object, MF function)
 {
index f10ceae..7198e61 100755 (executable)
@@ -3981,7 +3981,8 @@ Eina_Bool ewk_view_text_selection_range_get(Evas_Object* ewkView, Eina_Rectangle
 
     IntRect leftSelectionRect;
     IntRect rightSelectionRect;
-    if (!impl->pageProxy->getSelectionHandlers(leftSelectionRect, rightSelectionRect)) {
+    int selectionDirection = 1;
+    if (!impl->pageProxy->getSelectionHandlers(leftSelectionRect, rightSelectionRect, selectionDirection)) {
         leftRect->x = 0;
         leftRect->y = 0;
         leftRect->w = 0;
index 560235c..71dd024 100755 (executable)
@@ -121,7 +121,8 @@ void TextSelection::update()
             } else {
                 WebCore::IntRect leftRect;
                 WebCore::IntRect rightRect;
-                if (isTextSelectionDowned() || m_viewImpl->page()->getSelectionHandlers(leftRect, rightRect))
+                int selectionDirection = LToR;
+                if (isTextSelectionDowned() || m_viewImpl->page()->getSelectionHandlers(leftRect, rightRect, selectionDirection))
                     return;
 
                 setIsTextSelectionMode(false);
@@ -176,16 +177,27 @@ void TextSelection::hide()
 void TextSelection::updateHandlers()
 {
     WebCore::IntRect leftRect, rightRect;
-    if (!m_viewImpl->page()->getSelectionHandlers(leftRect, rightRect))
+    int selectionDirection = LToR;
+    if (!m_viewImpl->page()->getSelectionHandlers(leftRect, rightRect, selectionDirection))
         return;
 
     m_lastLeftHandleRect = leftRect;
     m_lastRightHandleRect = rightRect;
 
     AffineTransform toEvasTransform = m_viewImpl->transformToScene();
-    WebCore::IntPoint leftEvasPoint = toEvasTransform.mapPoint(leftRect.minXMaxYCorner());
-    WebCore::IntPoint rightEvasPoint = toEvasTransform.mapPoint(rightRect.maxXMaxYCorner());
+    WebCore::IntPoint leftEvasPoint ;
+    WebCore::IntPoint rightEvasPoint ;
 
+    // Selection Direction 1 -> L2R, Selection is Left to Right
+    if (selectionDirection == LToR) {
+        leftEvasPoint = toEvasTransform.mapPoint(leftRect.minXMaxYCorner());
+        rightEvasPoint = toEvasTransform.mapPoint(rightRect.maxXMaxYCorner());
+    }
+    // Selection Direction 0 -> R2L, Selection is Right to Left
+    else {
+        leftEvasPoint = toEvasTransform.mapPoint(leftRect.maxXMaxYCorner());
+        rightEvasPoint = toEvasTransform.mapPoint(rightRect.minXMaxYCorner());
+    }
     TextSelectionHandle* shownLeftHandle = m_leftHandle;
     TextSelectionHandle* shownRightHandle = m_rightHandle;
 
@@ -207,20 +219,20 @@ 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())) {
-            shownLeftHandle->move(leftEvasPoint, m_viewImpl->transformToScene().mapRect(leftRect));
+            shownLeftHandle->move(leftEvasPoint, m_viewImpl->transformToScene().mapRect(leftRect), (selectionDirection == LToR?true:false));
             shownLeftHandle->show();
         }
 
         if ((editorRightEvasPoint.x() >= rightEvasPoint.x() && editorRightEvasPoint.y() >= rightEvasPoint.y())
             && ((webViewX + webViewWidth) >= rightEvasPoint.x() && (webViewY <= rightEvasPoint.y() && (webViewY + webViewHeight) >= rightEvasPoint.y()))) {
-            shownRightHandle->move(rightEvasPoint, m_viewImpl->transformToScene().mapRect(rightRect));
+            shownRightHandle->move(rightEvasPoint, m_viewImpl->transformToScene().mapRect(rightRect), (selectionDirection == LToR?true:false));
             shownRightHandle->show();
         }
     } else {
-        shownLeftHandle->move(leftEvasPoint, m_viewImpl->transformToScene().mapRect(leftRect));
+        shownLeftHandle->move(leftEvasPoint, m_viewImpl->transformToScene().mapRect(leftRect), (selectionDirection == LToR?true:false));
         shownLeftHandle->show();
 
-        shownRightHandle->move(rightEvasPoint, m_viewImpl->transformToScene().mapRect(rightRect));
+        shownRightHandle->move(rightEvasPoint, m_viewImpl->transformToScene().mapRect(rightRect), (selectionDirection == LToR?true:false));
         shownRightHandle->show();
     }
 }
@@ -262,7 +274,8 @@ void TextSelection::showContextMenu()
 #endif
     if (editorState.selectionIsRange) {
         WebCore::IntRect leftRect, rightRect;
-        if (!m_viewImpl->page()->getSelectionHandlers(leftRect, rightRect))
+        int selectionDirection = LToR;
+        if (!m_viewImpl->page()->getSelectionHandlers(leftRect, rightRect, selectionDirection))
             return;
 
 #if ENABLE(TIZEN_WEBKIT2_TILED_BACKING_STORE)
@@ -422,25 +435,29 @@ void TextSelection::handleMouseDown(TextSelectionHandle* handle, const IntPoint&
 
     if (editorState.selectionIsRange) {
         WebCore::IntRect leftRect, rightRect;
-        if (!m_viewImpl->page()->getSelectionHandlers(leftRect, rightRect)) {
+        int selectionDirection = LToR, adjustValue = 2;
+        if (!m_viewImpl->page()->getSelectionHandlers(leftRect, rightRect, selectionDirection)) {
             clear();
             return;
         }
-
+        (editorState.isOnlyImageSelection == true)?adjustValue = 1:adjustValue = 2;
         if (handle->isLeft()) {
-            basePosition.setX(leftRect.x());
-            if(editorState.isOnlyImageSelection)
-                basePosition.setY(leftRect.y() + (leftRect.height()));
-            else
-                basePosition.setY(leftRect.y() + (leftRect.height()/2));
+            if (selectionDirection == LToR) {
+                basePosition.setX(leftRect.x());
+                basePosition.setY(leftRect.y() + (leftRect.height()/adjustValue));
+            } else {
+                basePosition.setX(leftRect.x() + leftRect.width());
+                basePosition.setY(leftRect.y() + (leftRect.height()/adjustValue));
+            }
         } else {
-            basePosition.setX(rightRect.x() + rightRect.width());
-            if(editorState.isOnlyImageSelection)
-                basePosition.setY(leftRect.y() + (leftRect.height()));
-            else
-                basePosition.setY(rightRect.y() + (rightRect.height()/2));
+            if (selectionDirection == LToR) {
+                basePosition.setX(rightRect.x() + rightRect.width());
+                basePosition.setY(rightRect.y() + (rightRect.height()/adjustValue));
+            } else {
+                basePosition.setX(rightRect.x());
+                basePosition.setY(rightRect.y() + (rightRect.height()/adjustValue));
+            }
         }
-
         handle->setBasePositionForMove(m_viewImpl->transformToScene().mapPoint(basePosition));
     } else
         return;
@@ -740,7 +757,8 @@ Eina_Bool TextSelection::showTimerCallback(void* data)
 void TextSelection::showHandlesAndContextMenu()
 {
     WebCore::IntRect leftRect, rightRect;
-    if (m_viewImpl->page()->getSelectionHandlers(leftRect, rightRect)) {
+    int selectionDirection = LToR;
+    if (m_viewImpl->page()->getSelectionHandlers(leftRect, rightRect, selectionDirection)) {
         if ((leftRect == m_lastLeftHandleRect) && (rightRect == m_lastRightHandleRect)) {
             if (m_showTimer) {
                 ecore_timer_del(m_showTimer);
@@ -774,6 +792,7 @@ void TextSelection::informTextStyleState()
 {
     WebCore::IntPoint startPoint, endPoint;
     WebCore::IntRect leftRect, rightRect;
+    int selectionDirection = LToR;
 
     const EditorState& editor = m_viewImpl->page()->editorState();
     IntRect caretRect;
@@ -787,7 +806,7 @@ void TextSelection::informTextStyleState()
         endPoint.setX(caretRect.x() + caretRect.width());
         endPoint.setY(caretRect.y() + caretRect.height());
     }
-    else if (m_viewImpl->page()->getSelectionHandlers(leftRect, rightRect)) {
+    else if (m_viewImpl->page()->getSelectionHandlers(leftRect, rightRect, selectionDirection)) {
         startPoint.setX(leftRect.x());
         startPoint.setY(leftRect.y() + leftRect.height());
 
index d937298..3cce5ba 100755 (executable)
@@ -60,6 +60,11 @@ public:
         HandleMovingDirectionReverse,
     };
 
+    enum TextSelectionDirection {
+        RToL = 0,
+        LToR,
+    };
+
     void update();
     bool isTextSelectionDowned() { return m_isTextSelectionDowned; }
     void setIsTextSelectionDowned(bool isTextSelectionDowned) { m_isTextSelectionDowned = isTextSelectionDowned; }
old mode 100644 (file)
new mode 100755 (executable)
index 47a35ae..832271f
@@ -75,7 +75,7 @@ TextSelectionHandle::~TextSelectionHandle()
     }
 }
 
-void TextSelectionHandle::move(const IntPoint& point, const IntRect& selectionRect)
+void TextSelectionHandle::move(const IntPoint& point, const IntRect& selectionRect, bool selectionDirection)
 {
     IntPoint movePoint = point;
     const int reverseMargin = 32;
@@ -98,10 +98,16 @@ void TextSelectionHandle::move(const IntPoint& point, const IntRect& selectionRe
     else {
         if ((movePoint.y() + handleHeight) > (y + deviceHeight)) {
             movePoint.setY(movePoint.y() - selectionRect.height());
-            edje_object_signal_emit(m_icon, "elm,state,top", "elm");
+            if (selectionDirection)
+                edje_object_signal_emit(m_icon, "elm,state,top", "elm");
+            else
+                edje_object_signal_emit(m_icon, "elm,state,top,reversed", "elm");
             m_isTop = true;
         } else {
-            edje_object_signal_emit(m_icon, "elm,state,bottom", "elm");
+            if (selectionDirection)
+                edje_object_signal_emit(m_icon, "elm,state,bottom", "elm");
+            else
+                edje_object_signal_emit(m_icon, "elm,state,bottom,reversed", "elm");
             m_isTop = false;
         }
     }
index 8499a89..39a5897 100755 (executable)
@@ -44,7 +44,7 @@ public:
     TextSelectionHandle(Evas_Object* object, const char* path, const char* part, bool isLeft, TextSelection* textSelection);
     ~TextSelectionHandle();
 
-    void move(const WebCore::IntPoint& point, const WebCore::IntRect& selectionRect);
+    void move(const WebCore::IntPoint& point, const WebCore::IntRect& selectionRect, bool selectionDirection);
     void show();
     void hide();
     bool isLeft() const { return m_isLeft; }
index 50eb437..6991f2c 100755 (executable)
@@ -1005,7 +1005,7 @@ public:
     bool selectClosestWord(const WebCore::IntPoint&);
     int setLeftSelection(const WebCore::IntPoint&, const int direction);
     int setRightSelection(const WebCore::IntPoint&, const int direction);
-    bool getSelectionHandlers(WebCore::IntRect& leftRect, WebCore::IntRect& rightRect);
+    bool getSelectionHandlers(WebCore::IntRect& leftRect, WebCore::IntRect& rightRect, int& selectionDirection);
     String getSelectionText();
     bool selectionRangeClear();
     bool scrollContentByCharacter(const WebCore::IntPoint&, WebCore::SelectionDirection direction);
index c198f2c..aad72a2 100755 (executable)
@@ -925,14 +925,14 @@ int WebPageProxy::setRightSelection(const IntPoint& point, const int direction)
     return result;
 }
 
-bool WebPageProxy::getSelectionHandlers(IntRect& leftRect, IntRect& rightRect)
+bool WebPageProxy::getSelectionHandlers(IntRect& leftRect, IntRect& rightRect, int& selectionDirection)
 {
     if (!isValid())
         return false;
 
     bool result = false;
     IntRect updateEditorRect(0, 0, 0, 0);
-    process()->sendSync(Messages::WebPage::GetSelectionHandlers(), Messages::WebPage::GetSelectionHandlers::Reply(leftRect, rightRect, updateEditorRect), m_pageID);
+    process()->sendSync(Messages::WebPage::GetSelectionHandlers(), Messages::WebPage::GetSelectionHandlers::Reply(leftRect, rightRect, selectionDirection, updateEditorRect), m_pageID);
     if (!leftRect.size().isZero() || !rightRect.size().isZero())
         result = true;
     if(m_editorState.editorRect != updateEditorRect) {
index 4f036eb..d8424b2 100755 (executable)
@@ -345,7 +345,7 @@ public:
     void setLeftSelection(const WebCore::IntPoint&, const int direction, int& result);
     void setRightSelection(const WebCore::IntPoint&, const int direction, int& result);
     bool isSelectionOnlyImage() const;
-    void getSelectionHandlers(WebCore::IntRect& leftRect, WebCore::IntRect& rightRect, WebCore::IntRect& updateEditorRect);
+    void getSelectionHandlers(WebCore::IntRect& leftRect, WebCore::IntRect& rightRect, int& selectionDirection, WebCore::IntRect& updateEditorRect);
     void getSelectionText(String& result);
     void selectionRangeClear(bool& result);
     void selectionClearAllSelection(WebCore::Frame* frame);
index 107b796..ebad1ed 100755 (executable)
@@ -382,7 +382,7 @@ messages -> WebPage {
     SelectClosestWord(WebCore::IntPoint point) -> (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, WebCore::IntRect updateEditorRect)
+    GetSelectionHandlers() -> (WebCore::IntRect leftRect, WebCore::IntRect rightRect, int selectionDirection, WebCore::IntRect updateEditorRect)
     GetSelectionText() -> (String result)
     SelectionRangeClear() -> (bool result)
     ScrollContentByCharacter(WebCore::IntPoint point, int direction) -> (bool result)
index 5b345f6..94b4ee4 100644 (file)
@@ -1339,7 +1339,8 @@ void WebPage::selectClosestWord(const IntPoint& point, bool& result)
     // This changes just the 'start' and 'end' positions of the VisibleSelection
     // Find handlers positions
     IntRect leftRect, rightRect, updatedEditorRect;
-    getSelectionHandlers(leftRect, rightRect, updatedEditorRect);
+    int selectionDirection = 0;
+    getSelectionHandlers(leftRect, rightRect, selectionDirection, updatedEditorRect);
     if (leftRect.size().isZero() && rightRect.size().isZero()) {
         // Sometimes there is no selected text, but isNone() returns TRUE
         // in this case ewk_frame_selection_handlers_get() returns FALSE and handlers are invalid
@@ -1373,7 +1374,8 @@ void WebPage::setLeftSelection(const IntPoint& point, const int direction, int&
 
     IntPoint pos = frameView->windowToContents(point);
     IntRect leftRect, rightRect, updatedEditorRect;
-    getSelectionHandlers(leftRect, rightRect, updatedEditorRect);
+    int selectionDirection = 0;
+    getSelectionHandlers(leftRect, rightRect, selectionDirection, updatedEditorRect);
 
     if (selectionEndNode->rendererIsEditable() && !selectionEndNode->rendererIsRichlyEditable()) {
         const int boundariesWidth = 2;
@@ -1541,7 +1543,7 @@ bool WebPage::isSelectionOnlyImage() const
     return isImage;
 }
 
-void WebPage::getSelectionHandlers(IntRect& leftRect, IntRect& rightRect, WebCore::IntRect& updatedEditorRect)
+void WebPage::getSelectionHandlers(IntRect& leftRect, IntRect& rightRect, int& selectionDirection, WebCore::IntRect& updatedEditorRect)
 {
     Frame* focusedFrame = m_page->focusController()->focusedOrMainFrame();
     updatedEditorRect = m_editorState.editorRect;
@@ -1596,6 +1598,7 @@ void WebPage::getSelectionHandlers(IntRect& leftRect, IntRect& rightRect, WebCor
 
         leftRect = frameView->contentsToWindow(leftRect);
         rightRect = frameView->contentsToWindow(rightRect);
+        selectionDirection = focusedFrame->selection()->getSelectionTextDirection();
      }
 }