Whole block area is highlighted instead of only Selected option.
authorManish R Gurnaney <m.gurnaney@samsung.com>
Tue, 25 Jun 2013 14:30:27 +0000 (20:00 +0530)
committerGerrit Code Review <gerrit@gerrit.vlan144.tizendev.org>
Wed, 10 Jul 2013 03:08:27 +0000 (03:08 +0000)
[Title] Whole block area is highlighted instead of only Selected option.
[Issue#] P130612-3611, P130612-3538, P130615-1146, WEB-3182
[Problem] Header element is shown as Focused element
[Cause] Header element has been regisetered with click-event listener in the page content.
[Solution] We will be checking two conditions here If the FocusRect is too big then we don't show focus ring.
Second to see focused parent should not have any child which is focusable.

Change-Id: I8e690bb817c160698ecd498d094b810591aec3f3

Source/WebKit2/WebProcess/WebPage/efl/WebPageEfl.cpp

index 37b51cd..f74b956 100755 (executable)
@@ -900,6 +900,33 @@ 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)
@@ -910,7 +937,8 @@ static IntRect getFocusedRect(HitTestResult hitTestResult, Page* page)
     Node* adjustedNode = 0;
     IntPoint adustedPoint;
     Frame* mainFrame = page->mainFrame();
-    mainFrame->eventHandler()->bestClickableNodeForTouchPoint(point, IntSize(area.width() / 2, area.height() / 2), adustedPoint, adjustedNode);
+    if (!isClickableOrFocusable(node))
+        mainFrame->eventHandler()->bestClickableNodeForTouchPoint(point, IntSize(area.width() / 2, area.height() / 2), adustedPoint, adjustedNode);
 
     if (adjustedNode)
         node = adjustedNode;
@@ -925,19 +953,7 @@ static IntRect getFocusedRect(HitTestResult hitTestResult, Page* page)
         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;
-            break;
-        }
-
-        if (focusableNode->supportsFocus()
-            || focusableNode->hasEventListeners(eventNames().clickEvent)
-            || focusableNode->hasEventListeners(eventNames().mousedownEvent)
-            || focusableNode->hasEventListeners(eventNames().mouseupEvent)) {
+        if (isClickableOrFocusable(focusableNode)) {
             isFocusRingDrawable = true;
             break;
         }
@@ -945,6 +961,20 @@ static IntRect getFocusedRect(HitTestResult hitTestResult, Page* page)
         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());
@@ -1002,6 +1032,14 @@ void WebPage::hitTestResultAtPoint(const IntPoint& point, int hitTestMode, WebHi
 #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())