WK: Cannot select text inside clickable containers.
https://bugs.webkit.org/show_bug.cgi?id=128197
<rdar://problem/15970890>

Reviewed by Simon Fraser.

When retrieving position information, we first try to
find the node responding to click events because we want
to know whether we are on a link or an image to show
the appropriate action sheet.
We could still have a node responding to click events if
for example we have a DIV with a click handler but that
doesn't require any special handling and we still need to
perform regular hit testing.

* WebProcess/WebPage/ios/WebPageIOS.mm:
(WebKit::WebPage::getPositionInformation):



git-svn-id: http://svn.webkit.org/repository/webkit/trunk@163400 268f45cc-cd09-0410-ab3c-d52691b4dbfc
diff --git a/Source/WebKit2/ChangeLog b/Source/WebKit2/ChangeLog
index eb522e3..09ee806 100644
--- a/Source/WebKit2/ChangeLog
+++ b/Source/WebKit2/ChangeLog
@@ -1,5 +1,25 @@
 2014-02-04  Enrica Casucci  <enrica@apple.com>
 
+        WK: Cannot select text inside clickable containers.
+        https://bugs.webkit.org/show_bug.cgi?id=128197
+        <rdar://problem/15970890>
+
+        Reviewed by Simon Fraser.
+
+        When retrieving position information, we first try to
+        find the node responding to click events because we want
+        to know whether we are on a link or an image to show
+        the appropriate action sheet.
+        We could still have a node responding to click events if
+        for example we have a DIV with a click handler but that
+        doesn't require any special handling and we still need to
+        perform regular hit testing.
+
+        * WebProcess/WebPage/ios/WebPageIOS.mm:
+        (WebKit::WebPage::getPositionInformation):
+
+2014-02-04  Enrica Casucci  <enrica@apple.com>
+
         WK2: Selection callout bar does not scroll with the selection.
         https://bugs.webkit.org/show_bug.cgi?id=128142
         <rdar://problem/15970812>
diff --git a/Source/WebKit2/WebProcess/WebPage/ios/WebPageIOS.mm b/Source/WebKit2/WebProcess/WebPage/ios/WebPageIOS.mm
index e5bc453..5ef7471 100644
--- a/Source/WebKit2/WebProcess/WebPage/ios/WebPageIOS.mm
+++ b/Source/WebKit2/WebProcess/WebPage/ios/WebPageIOS.mm
@@ -827,6 +827,7 @@
 
     info.point = point;
     info.nodeAtPositionIsAssistedNode = (hitNode == m_assistedNode);
+    bool elementIsLinkOrImage = false;
     if (hitNode) {
         info.clickableElementName = hitNode->nodeName();
 
@@ -834,17 +835,23 @@
         if (!element)
             return;
 
+        Element* linkElement = nullptr;
         if (element->renderer() && element->renderer()->isRenderImage()) {
-            Element* linkElement = containingLinkElement(element);
+            elementIsLinkOrImage = true;
+            linkElement = containingLinkElement(element);
 
-            if (linkElement)
-                info.url = linkElement->document().completeURL(stripLeadingAndTrailingHTMLSpaces(linkElement->getAttribute(HTMLNames::hrefAttr)));;
-        } else if (element->isLink())
-            info.url = element->document().completeURL(stripLeadingAndTrailingHTMLSpaces(element->getAttribute(HTMLNames::hrefAttr)));
+        } else if (element->isLink()) {
+            linkElement = element;
+            elementIsLinkOrImage = true;
+        }
+        if (linkElement)
+            info.url = linkElement->document().completeURL(stripLeadingAndTrailingHTMLSpaces(linkElement->getAttribute(HTMLNames::hrefAttr)));
         info.title = element->getAttribute(HTMLNames::titleAttr).string();
         if (element->renderer())
             info.bounds = element->renderer()->absoluteBoundingBoxRect(true);
-    } else {
+    }
+
+    if (!elementIsLinkOrImage) {
         Frame& frame = m_page->mainFrame();
         hitNode = frame.eventHandler().hitTestResultAtPoint((point), HitTestRequest::ReadOnly | HitTestRequest::Active | HitTestRequest::DisallowShadowContent).innerNode();
         if (hitNode->isTextNode()) {