Sometimes selection handler is not moving any direction.
authordeepak <deepak.m1@samsung.com>
Tue, 2 Jul 2013 19:02:32 +0000 (00:32 +0530)
committerGerrit Code Review <gerrit@gerrit.vlan144.tizendev.org>
Thu, 10 Oct 2013 05:48:14 +0000 (05:48 +0000)
[Version]    N/A
[Project]    Redwood
[Title]      Sometimes selection handler is not moving any direction.
[BinType]    N/A
[Customer]   HQ
[Issue#]     WEB-3432
[Problem]    setBasePositionForMove is setting wrong in handleMouseDown in TextSelection.cpp file
[Cause]      setVisibleContent() from initializeVisibleContentRect() in PageClientImpl.cpp is setting m_visibleContectRect to 0,0
[Solution]   for Image height should not be set half as is happening for the text.
[Team]       WebCoreSupport
[Developer]  deepak.m1@samsung.com
[Request]    N/A
[Horizontal expansion] N/A
[SCMRequest] NA

Change-Id: I602e51d36d69518e5bc75b05fe1bdea01ceb7fba

Source/WebKit2/Shared/EditorState.cpp
Source/WebKit2/Shared/EditorState.h
Source/WebKit2/UIProcess/API/efl/tizen/TextSelection.cpp
Source/WebKit2/WebProcess/WebPage/WebPage.cpp
Source/WebKit2/WebProcess/WebPage/WebPage.h
Source/WebKit2/WebProcess/WebPage/efl/WebPageEfl.cpp

index 2a0185c..0cde2a9 100755 (executable)
@@ -52,6 +52,7 @@ void EditorState::encode(CoreIPC::ArgumentEncoder* encoder) const
 #if ENABLE(TIZEN_WEBKIT2_TEXT_SELECTION)
     encoder->encode(editorRect);
     encoder->encode(updateEditorRectOnly);
+    encoder->encode(isOnlyImageSelection);
 #if ENABLE(TIZEN_WEBKIT2_GET_TEXT_STYLE_FOR_SELECTION)
     encoder->encode(underlineState);
     encoder->encode(italicState);
@@ -121,6 +122,9 @@ bool EditorState::decode(CoreIPC::ArgumentDecoder* decoder, EditorState& result)
     if (!decoder->decode(result.updateEditorRectOnly))
         return false;
 
+    if (!decoder->decode(result.isOnlyImageSelection))
+        return false;
+
 #if ENABLE(TIZEN_WEBKIT2_GET_TEXT_STYLE_FOR_SELECTION)
     if (!decoder->decode(result.underlineState))
         return false;
index 32c84ef..3099769 100755 (executable)
@@ -47,6 +47,7 @@ struct EditorState {
         , cursorPosition(0)
 #endif
 #if ENABLE(TIZEN_WEBKIT2_TEXT_SELECTION)
+        , isOnlyImageSelection(false)
         , updateEditorRectOnly(false)
         , underlineState(0)
         , italicState(0)
@@ -78,6 +79,7 @@ struct EditorState {
 #if ENABLE(TIZEN_WEBKIT2_TEXT_SELECTION)
     WebCore::IntRect editorRect;
     bool updateEditorRectOnly;
+    bool isOnlyImageSelection;
 #if ENABLE(TIZEN_WEBKIT2_GET_TEXT_STYLE_FOR_SELECTION)
     int underlineState;
     int italicState;
index 5eb3b36..560235c 100755 (executable)
@@ -429,10 +429,16 @@ void TextSelection::handleMouseDown(TextSelectionHandle* handle, const IntPoint&
 
         if (handle->isLeft()) {
             basePosition.setX(leftRect.x());
-            basePosition.setY(leftRect.y() + (leftRect.height()/2));
+            if(editorState.isOnlyImageSelection)
+                basePosition.setY(leftRect.y() + (leftRect.height()));
+            else
+                basePosition.setY(leftRect.y() + (leftRect.height()/2));
         } else {
             basePosition.setX(rightRect.x() + rightRect.width());
-            basePosition.setY(rightRect.y() + (rightRect.height()/2));
+            if(editorState.isOnlyImageSelection)
+                basePosition.setY(leftRect.y() + (leftRect.height()));
+            else
+                basePosition.setY(rightRect.y() + (rightRect.height()/2));
         }
 
         handle->setBasePositionForMove(m_viewImpl->transformToScene().mapPoint(basePosition));
index cc1d724..848ea1f 100755 (executable)
@@ -569,6 +569,7 @@ EditorState WebPage::editorState() const
 #endif
 
 #if ENABLE(TIZEN_ISF_PORT)
+    result.isOnlyImageSelection = isSelectionOnlyImage();
     Element* rootEditableElement = frame->selection()->rootEditableElement();
     if (!rootEditableElement)
         return result;
index 16afee0..4f036eb 100755 (executable)
@@ -344,6 +344,7 @@ public:
     void selectClosestWord(const WebCore::IntPoint&, 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;
     void getSelectionHandlers(WebCore::IntRect& leftRect, WebCore::IntRect& rightRect, WebCore::IntRect& updateEditorRect);
     void getSelectionText(String& result);
     void selectionRangeClear(bool& result);
index 33dc00c..5b345f6 100644 (file)
@@ -1507,6 +1507,40 @@ void WebPage::setRightSelection(const IntPoint& point, const int direction, int&
     }
 }
 
+bool WebPage::isSelectionOnlyImage() const
+{
+    bool isImage = false;
+    Frame* focusedFrame = m_page->focusController()->focusedOrMainFrame();
+    if (!focusedFrame->selection()->isRange())
+        return  isImage;
+
+    RefPtr<Range> selectedRange = focusedFrame->selection()->toNormalizedRange();
+    Vector<IntRect> rects;
+    selectedRange->boundingBoxEx(rects, true);
+    unsigned size = rects.size();
+    if(size == 1) {
+        Node* startNode = selectedRange->startContainer();
+        Node* endNode = selectedRange->endContainer();
+        if(startNode == endNode) {
+            if(endNode && endNode->isContainerNode() && !(endNode->hasTagName(HTMLNames::imgTag))) {
+                WebCore::Node *child = static_cast<const ContainerNode*>(endNode)->firstChild();
+                while(child) {
+                    if(child->hasTagName(HTMLNames::imgTag)) {
+                        isImage = true;
+                        break;
+                    }
+                    child = child->traverseNextNode(endNode);
+                }
+            }
+            else {
+                if(endNode->hasTagName(HTMLNames::imgTag))
+                    isImage = true;
+            }
+        }
+    }
+    return isImage;
+}
+
 void WebPage::getSelectionHandlers(IntRect& leftRect, IntRect& rightRect, WebCore::IntRect& updatedEditorRect)
 {
     Frame* focusedFrame = m_page->focusController()->focusedOrMainFrame();