[Qt] Replace QWebPageAdaptor::TouchAdjuster
authorallan.jensen@digia.com <allan.jensen@digia.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 21 Feb 2013 12:39:47 +0000 (12:39 +0000)
committerallan.jensen@digia.com <allan.jensen@digia.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 21 Feb 2013 12:39:47 +0000 (12:39 +0000)
https://bugs.webkit.org/show_bug.cgi?id=110226

Reviewed by Antonio Gomes.

* WebCoreSupport/QWebPageAdapter.cpp:
(QWebPageAdapter::adjustPointForClicking):
* WebCoreSupport/QWebPageAdapter.h:

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@143588 268f45cc-cd09-0410-ab3c-d52691b4dbfc

Source/WebKit/qt/ChangeLog
Source/WebKit/qt/WebCoreSupport/QWebPageAdapter.cpp
Source/WebKit/qt/WebCoreSupport/QWebPageAdapter.h

index 51b402860d1bd75aed951c296b503b43292774cc..a842a20fb28ad95b14e786b1b582fc567a92c9fa 100644 (file)
@@ -1,3 +1,14 @@
+2013-02-21  Allan Sandfeld Jensen  <allan.jensen@digia.com>
+
+        [Qt] Replace QWebPageAdaptor::TouchAdjuster
+        https://bugs.webkit.org/show_bug.cgi?id=110226
+
+        Reviewed by Antonio Gomes.
+
+        * WebCoreSupport/QWebPageAdapter.cpp:
+        (QWebPageAdapter::adjustPointForClicking):
+        * WebCoreSupport/QWebPageAdapter.h:
+
 2013-02-15  Allan Sandfeld Jensen  <allan.jensen@digia.com>
 
         Simplify hitTestResultAtPoint and nodesFromRect APIs
index 3c5990ef4705ea991c9ea6c82ecc205082c172fe..a4b542cccd01d5a9187f89e4a08de0d646c7b23c 100644 (file)
@@ -344,6 +344,7 @@ bool QWebPageAdapter::findText(const QString& subString, FindFlag options)
 
 void QWebPageAdapter::adjustPointForClicking(QMouseEvent* ev)
 {
+#if ENABLE(TOUCH_ADJUSTMENT)
     QtPlatformPlugin platformPlugin;
     OwnPtr<QWebTouchModifier> touchModifier = platformPlugin.createTouchModifier();
     if (!touchModifier)
@@ -359,130 +360,22 @@ void QWebPageAdapter::adjustPointForClicking(QMouseEvent* ev)
     if (!topPadding && !rightPadding && !bottomPadding && !leftPadding)
         return;
 
-    Document* startingDocument = page->mainFrame()->document();
-    if (!startingDocument)
-        return;
+    EventHandler* eventHandler = page->mainFrame()->eventHandler();
+    ASSERT(eventHandler);
 
-    IntPoint originalPoint(ev->pos());
-    TouchAdjuster touchAdjuster(topPadding, rightPadding, bottomPadding, leftPadding);
-    IntPoint adjustedPoint = touchAdjuster.findCandidatePointForTouch(originalPoint, startingDocument);
-    if (adjustedPoint == IntPoint::zero())
+    IntRect touchRect(ev->pos().x() - leftPadding, ev->pos().y() - topPadding, leftPadding + rightPadding, topPadding + bottomPadding);
+    IntPoint adjustedPoint;
+    Node* adjustedNode;
+    bool foundClickableNode = eventHandler->bestClickableNodeForTouchPoint(touchRect.center(), touchRect.size(), adjustedPoint, adjustedNode);
+    if (!foundClickableNode)
         return;
+
     QMouseEvent* ret = new QMouseEvent(ev->type(), QPoint(adjustedPoint), ev->globalPos(), ev->button(), ev->buttons(), ev->modifiers());
     delete ev;
     ev = ret;
-}
-
-static bool hasMouseListener(Element* element)
-{
-    ASSERT(element);
-    return element->hasEventListeners(eventNames().clickEvent)
-        || element->hasEventListeners(eventNames().mousedownEvent)
-        || element->hasEventListeners(eventNames().mouseupEvent);
-}
-
-static bool isClickableElement(Element* element, PassRefPtr<NodeList> prpList)
-{
-    ASSERT(element);
-    RefPtr<NodeList> list = prpList;
-    bool isClickable = hasMouseListener(element);
-    if (!isClickable && list) {
-        Element* parent = element->parentElement();
-        unsigned count = list->length();
-        for (unsigned i = 0; i < count && parent; i++) {
-            if (list->item(i) != parent)
-                continue;
-
-            isClickable = hasMouseListener(parent);
-            if (isClickable)
-                break;
-
-            parent = parent->parentElement();
-        }
-    }
-
-    ExceptionCode ec = 0;
-    return isClickable
-        || element->webkitMatchesSelector("a,*:link,*:visited,*[role=button],button,input,select,label", ec)
-        || CSSComputedStyleDeclaration::create(element)->getPropertyValue(cssPropertyID("cursor")) == "pointer";
-}
-
-static bool isValidFrameOwner(Element* element)
-{
-    ASSERT(element);
-    return element->isFrameOwnerElement() && static_cast<HTMLFrameOwnerElement*>(element)->contentFrame();
-}
-
-QWebPageAdapter::TouchAdjuster::TouchAdjuster(unsigned topPadding, unsigned rightPadding, unsigned bottomPadding, unsigned leftPadding)
-    : m_topPadding(topPadding)
-    , m_rightPadding(rightPadding)
-    , m_bottomPadding(bottomPadding)
-    , m_leftPadding(leftPadding)
-{
-}
-
-IntPoint QWebPageAdapter::TouchAdjuster::findCandidatePointForTouch(const IntPoint& touchPoint, Document* document) const
-{
-    if (!document)
-        return IntPoint();
-
-    int x = touchPoint.x();
-    int y = touchPoint.y();
-
-    RefPtr<NodeList> intersectedNodes = document->nodesFromRect(x, y, m_topPadding, m_rightPadding, m_bottomPadding, m_leftPadding);
-    if (!intersectedNodes)
-        return IntPoint();
-
-    Element* closestClickableElement = 0;
-    IntRect largestIntersectionRect;
-    FrameView* view = document->frame()->view();
-
-    // Touch rect in contents coordinates.
-    IntRect touchRect(HitTestLocation::rectForPoint(view->windowToContents(IntPoint(x, y)), m_topPadding, m_rightPadding, m_bottomPadding, m_leftPadding));
-
-    // Iterate over the list of nodes hit looking for the one whose bounding area
-    // has largest intersection with the touch area (point + padding).
-    for (unsigned i = 0; i < intersectedNodes->length(); i++) {
-        Node* currentNode = intersectedNodes->item(i);
-
-        Element* currentElement = currentNode->isElementNode() ? toElement(currentNode) : 0;
-        if (!currentElement || (!isClickableElement(currentElement, 0) && !isValidFrameOwner(currentElement)))
-            continue;
-
-        IntRect currentElementBoundingRect = currentElement->pixelSnappedBoundingBox();
-        currentElementBoundingRect.intersect(touchRect);
-
-        if (currentElementBoundingRect.isEmpty())
-            continue;
-
-        int currentIntersectionRectArea = currentElementBoundingRect.width() * currentElementBoundingRect.height();
-        int largestIntersectionRectArea = largestIntersectionRect.width() * largestIntersectionRect.height();
-        if (currentIntersectionRectArea > largestIntersectionRectArea) {
-            closestClickableElement = currentElement;
-            largestIntersectionRect = currentElementBoundingRect;
-        }
-    }
-
-    if (largestIntersectionRect.isEmpty())
-        return IntPoint();
-
-    // Handle the case when user taps a inner frame. It is done in three steps:
-    // 1) Transform the original touch point to the inner document coordinates;
-    // 1) Call nodesFromRect for the inner document in case;
-    // 3) Re-add the inner frame offset (location) before passing the new clicking
-    //    position to WebCore.
-    if (closestClickableElement->isFrameOwnerElement()) {
-        // Adjust client coordinates' origin to be top left of inner frame viewport.
-        RefPtr<ClientRect> rect = closestClickableElement->getBoundingClientRect();
-        IntPoint newTouchPoint = touchPoint;
-        IntSize offset =  IntSize(rect->left(), rect->top());
-        newTouchPoint -= offset;
-
-        HTMLFrameOwnerElement* owner = static_cast<HTMLFrameOwnerElement*>(closestClickableElement);
-        Document* childDocument = owner->contentFrame()->document();
-        return findCandidatePointForTouch(newTouchPoint, childDocument);
-    }
-    return view->contentsToWindow(largestIntersectionRect).center();
+#else
+    Q_UNUSED(ev);
+#endif
 }
 
 void QWebPageAdapter::mouseMoveEvent(QMouseEvent* ev)
index 37b3392cd6732e33a68969358b2b2c202dbf450b..7be40d6d849be0da8e49ab930b6b6f95d903250a 100644 (file)
@@ -260,19 +260,6 @@ public:
 
     bool findText(const QString& subString, FindFlag options);
 
-    class TouchAdjuster {
-    public:
-        TouchAdjuster(unsigned topPadding, unsigned rightPadding, unsigned bottomPadding, unsigned leftPadding);
-
-        WebCore::IntPoint findCandidatePointForTouch(const WebCore::IntPoint&, WebCore::Document*) const;
-
-    private:
-        unsigned m_topPadding;
-        unsigned m_rightPadding;
-        unsigned m_bottomPadding;
-        unsigned m_leftPadding;
-    };
-
     void adjustPointForClicking(QMouseEvent*);
 
     void mouseMoveEvent(QMouseEvent*);