Modified: trunk/Source/WebKit/qt/WebCoreSupport/QWebPageAdapter.cpp (143587 => 143588)
--- trunk/Source/WebKit/qt/WebCoreSupport/QWebPageAdapter.cpp 2013-02-21 12:38:50 UTC (rev 143587)
+++ trunk/Source/WebKit/qt/WebCoreSupport/QWebPageAdapter.cpp 2013-02-21 12:39:47 UTC (rev 143588)
@@ -344,6 +344,7 @@
void QWebPageAdapter::adjustPointForClicking(QMouseEvent* ev)
{
+#if ENABLE(TOUCH_ADJUSTMENT)
QtPlatformPlugin platformPlugin;
OwnPtr<QWebTouchModifier> touchModifier = platformPlugin.createTouchModifier();
if (!touchModifier)
@@ -359,132 +360,24 @@
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;
+#else
+ Q_UNUSED(ev);
+#endif
}
-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();
-}
-
void QWebPageAdapter::mouseMoveEvent(QMouseEvent* ev)
{
WebCore::Frame* frame = mainFrameAdapter()->frame;
Modified: trunk/Source/WebKit/qt/WebCoreSupport/QWebPageAdapter.h (143587 => 143588)
--- trunk/Source/WebKit/qt/WebCoreSupport/QWebPageAdapter.h 2013-02-21 12:38:50 UTC (rev 143587)
+++ trunk/Source/WebKit/qt/WebCoreSupport/QWebPageAdapter.h 2013-02-21 12:39:47 UTC (rev 143588)
@@ -260,19 +260,6 @@
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*);