Whole block area is highlighted instead of only Selected option.
[framework/web/webkit-efl.git] / Source / WebKit2 / WebProcess / WebPage / efl / WebPageEfl.cpp
index 56a46ec..f74b956 100755 (executable)
@@ -290,10 +290,12 @@ void WebPage::confirmComposition(const String& compositionString)
     if (!targetFrame)
         return;
 
+#if ENABLE(TIZEN_ISF_PORT)
     if (m_prepareKeyDownEvent) {
         m_keyPressCommands.append(adoptPtr(new ConfirmCompositionKeyPressCommand(compositionString)));
         return;
     }
+#endif
 
     targetFrame->editor()->confirmComposition(compositionString);
 
@@ -308,12 +310,15 @@ void WebPage::setComposition(const String& compositionString, const Vector<WebCo
     if (!targetFrame)
         return;
 
+#if ENABLE(TIZEN_ISF_PORT)
+    if (!targetFrame->editor()->hasComposition() && compositionString.isEmpty())
+        return;
+
     if (m_prepareKeyDownEvent) {
         m_keyPressCommands.append(adoptPtr(new SetCompositionKeyPressCommand(compositionString, underlines, cursorPosition)));
         return;
     }
 
-#if ENABLE(TIZEN_ISF_PORT)
     if (targetFrame->selection()->rootEditableElement()) {
         HTMLTextFormControlElement* textFormControl = toTextFormControl(targetFrame->selection()->rootEditableElement()->shadowAncestorNode());
         if (textFormControl && textFormControl->maxLength() >= 0) {
@@ -894,9 +899,50 @@ static IntRect getNodeRect(Node* node, Node* focusableNode, bool isImage)
 
 #if ENABLE(TIZEN_WEBKIT2_HIT_TEST)
 #if ENABLE(TIZEN_WEBKIT2_FOCUS_RING)
+#if ENABLE(TOUCH_ADJUSTMENT)
+static bool isClickableOrFocusable(Node* focusableNode)
+{
+
+   if (!focusableNode)
+       return false;
+   if (focusableNode->disabled())
+        return false;
+   if (!focusableNode->inDocument())
+        return false;
+   if (!focusableNode->renderer() || focusableNode->renderer()->style()->visibility() != VISIBLE)
+        return false;
+   if (focusableNode->isFocusable()) {
+       if (focusableNode->isLink()
+           || focusableNode->hasTagName(HTMLNames::inputTag)
+           || focusableNode->hasTagName(HTMLNames::selectTag)
+           || focusableNode->hasTagName(HTMLNames::buttonTag))
+           return true;
+   }
+   if (focusableNode->supportsFocus()
+       || focusableNode->hasEventListeners(eventNames().clickEvent)
+       || focusableNode->hasEventListeners(eventNames().mousedownEvent)
+       || focusableNode->hasEventListeners(eventNames().mouseupEvent)) {
+       return true;
+   }
+   return false;
+}
+
+static IntRect getFocusedRect(HitTestResult hitTestResult, Page* page, const IntPoint& point, const IntSize& area)
+#else
 static IntRect getFocusedRect(HitTestResult hitTestResult, Page* page)
+#endif
 {
     Node* node = hitTestResult.innerNode();
+#if ENABLE(TOUCH_ADJUSTMENT)
+    Node* adjustedNode = 0;
+    IntPoint adustedPoint;
+    Frame* mainFrame = page->mainFrame();
+    if (!isClickableOrFocusable(node))
+        mainFrame->eventHandler()->bestClickableNodeForTouchPoint(point, IntSize(area.width() / 2, area.height() / 2), adustedPoint, adjustedNode);
+
+    if (adjustedNode)
+        node = adjustedNode;
+#endif
     if (!node)
         return IntRect();
 
@@ -904,21 +950,31 @@ static IntRect getFocusedRect(HitTestResult hitTestResult, Page* page)
     Node* focusableNode = node;
     while (focusableNode) {
         RenderObject* renderer = focusableNode->renderer();
-        if (renderer && renderer->isRoot())
+        if (renderer && (renderer->isBody() || renderer->isRenderView() || renderer->isRoot()))
             break;
 
-        if (focusableNode->isFocusable()) {
-            if (focusableNode->isLink()
-                || focusableNode->hasTagName(HTMLNames::inputTag)
-                || focusableNode->hasTagName(HTMLNames::selectTag)
-                || focusableNode->hasTagName(HTMLNames::buttonTag))
-                isFocusRingDrawable = true;
+        if (isClickableOrFocusable(focusableNode)) {
+            isFocusRingDrawable = true;
             break;
         }
 
         focusableNode = focusableNode->parentNode();
     }
 
+    // Don't draw focus ring if child is focusable or has trigger
+    if (focusableNode && focusableNode->isContainerNode() && !focusableNode->isLink()) {
+        WebCore::Node *child = static_cast<const ContainerNode*>(focusableNode)->firstChild();
+        while(child) {
+            if( child->supportsFocus()
+                || child->hasEventListeners(eventNames().clickEvent)
+                || child->hasEventListeners(eventNames().mousedownEvent)
+                || child->hasEventListeners(eventNames().mouseupEvent)) {
+                return IntRect();
+            }
+            child = child->traverseNextNode(focusableNode);
+        }
+    }
+
     if (!isFocusRingDrawable) {
         if (node->hasTagName(HTMLNames::imgTag))
             return getNodeRect(node, node, !hitTestResult.absoluteImageURL().isEmpty());
@@ -930,7 +986,11 @@ static IntRect getFocusedRect(HitTestResult hitTestResult, Page* page)
 }
 #endif
 
+#if ENABLE(TOUCH_ADJUSTMENT)
+void WebPage::hitTestResultAtPoint(const IntPoint& point, int hitTestMode, const IntSize& area, WebHitTestResult::Data& hitTestResultData)
+#else
 void WebPage::hitTestResultAtPoint(const IntPoint& point, int hitTestMode, WebHitTestResult::Data& hitTestResultData)
+#endif
 {
     Frame* frame = m_page->mainFrame();
     FrameView* frameView = frame->view();
@@ -967,7 +1027,19 @@ void WebPage::hitTestResultAtPoint(const IntPoint& point, int hitTestMode, WebHi
     hitTestResultData.hitTestMode = hitTestMode;
 
 #if ENABLE(TIZEN_WEBKIT2_FOCUS_RING)
+#if ENABLE(TOUCH_ADJUSTMENT)
+    hitTestResultData.focusedRect = getFocusedRect(hitTestResult, m_page.get(), point, area);
+#else
     hitTestResultData.focusedRect = getFocusedRect(hitTestResult, m_page.get());
+#endif
+
+    // Don't display FocusRect if the size is too big..
+    IntRect framerect = frameView->visibleContentRect(true);
+    if (hitTestResultData.focusedRect.width() > (0.8 * framerect.width())
+        && hitTestResultData.focusedRect.height() > (0.8 * framerect.height())) {
+        hitTestResultData.focusedRect = IntRect();
+    }
+
     if (hitTestResult.innerNode() && hitTestResult.innerNode()->renderer() && hitTestResult.innerNode()->renderer()->style()) {
         hitTestResultData.focusedColor = hitTestResult.innerNode()->renderer()->style()->tapHighlightColor();
         if (!hitTestResultData.focusedColor.hasAlpha())
@@ -1327,9 +1399,9 @@ void WebPage::selectClosestWord(const IntPoint& point, bool& result)
     result = true;
 }
 
-void WebPage::setLeftSelection(const IntPoint& point, bool& result)
+void WebPage::setLeftSelection(const IntPoint& point, const int direction, int& result)
 {
-    result = false;
+    result = HandleMovingDirectionNone;
 
     Frame* focusedFrame = m_page->focusController()->focusedOrMainFrame();
     FrameSelection* frameSelection = focusedFrame->selection();
@@ -1347,8 +1419,6 @@ void WebPage::setLeftSelection(const IntPoint& point, bool& result)
     IntPoint pos = frameView->windowToContents(point);
     IntRect leftRect, rightRect;
     getSelectionHandlers(leftRect, rightRect);
-    if ((rightRect.y() + rightRect.height()) < pos.y())
-        pos.setY(rightRect.y() + (rightRect.height()/2));
 
     if (selectionEndNode->rendererIsEditable() && !selectionEndNode->rendererIsRichlyEditable()) {
         const int boundariesWidth = 2;
@@ -1362,6 +1432,7 @@ void WebPage::setLeftSelection(const IntPoint& point, bool& result)
     }
 
     OwnPtr<VisiblePosition> position = adoptPtr(new VisiblePosition(focusedFrame->visiblePositionForPoint(pos)));
+    Position base = frameSelection->base();
     Position extent = frameSelection->extent();
 
     Node* newSelectionStartNode = position->deepEquivalent().deprecatedNode();
@@ -1369,8 +1440,7 @@ void WebPage::setLeftSelection(const IntPoint& point, bool& result)
     // both start and end nodes should be in the same area type: both should be editable or both should be not editable
     // Check if the new position is before the extent's position
     if (newSelectionStartNode
-        && selectionEndNode->isContentEditable() == newSelectionStartNode->isContentEditable()
-        && comparePositions(position->deepEquivalent(), extent) < 0) {
+        && selectionEndNode->isContentEditable() == newSelectionStartNode->isContentEditable()) {
         // Change the 'base' and 'extent' positions to 'start' and 'end' positions.
         // We do it, because without this, the other modification of the selection
         // would destroy the 'start' and/or 'end' positions and set them to
@@ -1381,20 +1451,35 @@ void WebPage::setLeftSelection(const IntPoint& point, bool& result)
         bool oldProhibitsScrolling = focusedFrame->view()->prohibitsScrolling();
         focusedFrame->view()->setProhibitsScrolling(true);
 
-        frameSelection->setBase(*position);
+        if (direction == HandleMovingDirectionNormal) {
+            if (comparePositions(position->deepEquivalent(), extent) < 0) {
+                frameSelection->setBase(*position);
+                result = HandleMovingDirectionNormal;
+            } else if (comparePositions(position->deepEquivalent(), extent) > 0) {
+                frameSelection->setExtent(*position);
+                frameSelection->setBase(extent);
+                result = HandleMovingDirectionReverse;
+            }
+        } else if (direction == HandleMovingDirectionReverse) {
+            if (comparePositions(position->deepEquivalent(), base) > 0) {
+                frameSelection->setExtent(*position);
+                result = HandleMovingDirectionReverse;
+            } else if (comparePositions(position->deepEquivalent(), base) < 0) {
+                frameSelection->setBase(*position);
+                frameSelection->setExtent(base);
+                result = HandleMovingDirectionNormal;
+            }
+        }
 
         focusedFrame->view()->setProhibitsScrolling(oldProhibitsScrolling);
         // This forces webkit to show selection
         // m_coreFrame->invalidateSelection();
-
-        result = true;
     }
 }
 
-
-void WebPage::setRightSelection(const IntPoint& point, bool& result)
+void WebPage::setRightSelection(const IntPoint& point, const int direction, int& result)
 {
-    result = false;
+    result = HandleMovingDirectionNone;
 
     Frame* focusedFrame = m_page->focusController()->focusedOrMainFrame();
     FrameSelection* frameSelection = focusedFrame->selection();
@@ -1424,14 +1509,14 @@ void WebPage::setRightSelection(const IntPoint& point, bool& result)
 
     OwnPtr<VisiblePosition> position = adoptPtr(new VisiblePosition(focusedFrame->visiblePositionForPoint(pos)));
     Position base = frameSelection->base();
+    Position extent = frameSelection->extent();
 
     Node* newSelectionEndNode = position->deepEquivalent().deprecatedNode();
 
     // both start and end nodes should be in the same area type: both should be editable or both should be not editable
     // Check if the new position is after the base's position
     if (newSelectionEndNode
-        && selectionStartNode->isContentEditable() == newSelectionEndNode->isContentEditable()
-        && comparePositions(position->deepEquivalent(), base) > 0) {
+        && selectionStartNode->isContentEditable() == newSelectionEndNode->isContentEditable()) {
         // Change the 'base' and 'extent' positions to 'start' and 'end' positions.
         // We do it, because without this, the other modifications of the selection
         // would destroy the 'start' and/or 'end' positions and set them to
@@ -1443,11 +1528,27 @@ void WebPage::setRightSelection(const IntPoint& point, bool& result)
         bool oldProhibitsScrolling = focusedFrame->view()->prohibitsScrolling();
         focusedFrame->view()->setProhibitsScrolling(true);
 
-        frameSelection->setExtent(*position);
+        if (direction == HandleMovingDirectionNormal) {
+            if (comparePositions(position->deepEquivalent(), base) > 0) {
+                frameSelection->setExtent(*position);
+                result = HandleMovingDirectionNormal;
+            } else if (comparePositions(position->deepEquivalent(), base) < 0) {
+                frameSelection->setBase(*position);
+                frameSelection->setExtent(base);
+                result = HandleMovingDirectionReverse;
+            }
+        } else if (direction == HandleMovingDirectionReverse) {
+            if (comparePositions(position->deepEquivalent(), extent) < 0) {
+                frameSelection->setBase(*position);
+                result = HandleMovingDirectionReverse;
+            } else if (comparePositions(position->deepEquivalent(), extent) > 0) {
+                frameSelection->setExtent(*position);
+                frameSelection->setBase(extent);
+                result = HandleMovingDirectionNormal;
+            }
+        }
 
         focusedFrame->view()->setProhibitsScrolling(oldProhibitsScrolling);
-
-        result = true;
     }
 }
 
@@ -1842,6 +1943,9 @@ void WebPage::useSettingsFont()
 
 void WebPage::didChangeContents(const IntRect& rect)
 {
+    if (!m_page)
+        return;
+
     Frame* frame = m_page->focusController()->focusedOrMainFrame();
     if (!frame || !frame->view() || frame->view()->needsLayout())
         return;