// 'region' is in contents coordinates relative to the frame containing 'node' // 'remainingFingerRegion' and 'intersectingRegions' will always be in main frame contents // coordinates. // Thus, before comparing, we need to map the former to main frame contents coordinates. bool FatFingers::checkFingerIntersection(const IntRectRegion& region, const IntRectRegion& remainingFingerRegion, Node* node, Vector<IntersectingRegion>& intersectingRegions) { ASSERT(node); IntRectRegion regionCopy(region); WebCore::IntPoint framePos(m_webPage->frameOffset(node->document()->frame())); regionCopy.move(framePos.x(), framePos.y()); IntRectRegion intersection = intersectRegions(regionCopy, remainingFingerRegion); if (intersection.isEmpty()) return false; #if DEBUG_FAT_FINGERS String nodeName; if (node->isTextNode()) nodeName = "text node"; else if (node->isElementNode()) nodeName = String::format("%s node", toElement(node)->tagName().latin1().data()); else nodeName = "unknown node"; if (node->isInShadowTree()) { nodeName = nodeName + "(in shadow tree"; if (node->isElementNode() && !toElement(node)->shadowPseudoId().isEmpty()) nodeName = nodeName + ", pseudo id " + toElement(node)->shadowPseudoId(); nodeName = nodeName + ")"; } Platform::logAlways(Platform::LogLevelInfo, "%s has region %s, intersecting at %s (area %d)", nodeName.latin1().data(), regionCopy.toString().c_str(), intersection.toString().c_str(), intersection.area()); #endif intersectingRegions.append(std::make_pair(node, intersection)); return true; }
const FatFingersResult FatFingers::findBestPoint() { ASSERT(m_webPage); ASSERT(m_webPage->m_mainFrame); m_cachedRectHitTestResults.clear(); FatFingersResult result(m_contentPos); // Lets set nodeUnderFatFinger to the result of a point based hit test here. If something // targable is actually found by ::findIntersectingRegions, then we might replace what we just set below later on. Element* elementUnderPoint; Element* clickableElementUnderPoint; getRelevantInfoFromCachedHitTest(elementUnderPoint, clickableElementUnderPoint); if (elementUnderPoint) { result.m_nodeUnderFatFinger = elementUnderPoint; // If we are looking for a Clickable Element and we found one, we can quit early. if (m_targetType == ClickableElement) { if (clickableElementUnderPoint) { setSuccessfulFatFingersResult(result, clickableElementUnderPoint, m_contentPos /*adjustedPosition*/); return result; } if (isElementClickable(elementUnderPoint)) { setSuccessfulFatFingersResult(result, elementUnderPoint, m_contentPos /*adjustedPosition*/); return result; } } } #if DEBUG_FAT_FINGERS // Force blit to make the fat fingers rects show up. if (!m_debugFatFingerRect.isEmpty()) m_webPage->m_backingStore->repaint(0, 0, m_webPage->transformedViewportSize().width(), m_webPage->transformedViewportSize().height(), true, true); #endif Vector<IntersectingRegion> intersectingRegions; IntRectRegion remainingFingerRegion = IntRectRegion(fingerRectForPoint(m_contentPos)); bool foundOne = findIntersectingRegions(m_webPage->m_mainFrame->document(), intersectingRegions, remainingFingerRegion); m_cachedRectHitTestResults.clear(); if (!foundOne) return result; Node* bestNode = 0; IntRectRegion largestIntersectionRegion; int largestIntersectionRegionArea = 0; Vector<IntersectingRegion>::const_iterator endIt = intersectingRegions.end(); for (Vector<IntersectingRegion>::const_iterator it = intersectingRegions.begin(); it != endIt; ++it) { Node* currentNode = it->first; IntRectRegion currentIntersectionRegion = it->second; int currentIntersectionRegionArea = currentIntersectionRegion.area(); if (currentIntersectionRegionArea > largestIntersectionRegionArea || (currentIntersectionRegionArea == largestIntersectionRegionArea && compareDistanceBetweenPoints(m_contentPos, currentIntersectionRegion, largestIntersectionRegion))) { bestNode = currentNode; largestIntersectionRegion = currentIntersectionRegion; largestIntersectionRegionArea = currentIntersectionRegionArea; } } if (!bestNode || largestIntersectionRegion.isEmpty()) return result; #if DEBUG_FAT_FINGERS m_debugFatFingerAdjustedPosition = m_webPage->mapToTransformed(m_webPage->mapFromContentsToViewport(largestIntersectionRegion.rects()[0].center())); #endif setSuccessfulFatFingersResult(result, bestNode, largestIntersectionRegion.rects()[0].center() /*adjustedPosition*/); return result; }
const FatFingersResult FatFingers::findBestPoint() { ASSERT(m_webPage); ASSERT(m_webPage->m_mainFrame); // Even though we have clamped the point in libwebview to viewport, but there might be a rounding difference for viewport rect. // Clamp position to viewport to ensure we are inside viewport. IntRect viewportRect = m_webPage->mainFrame()->view()->visibleContentRect(); m_contentPos = Platform::pointClampedToRect(m_contentPos, viewportRect); m_cachedRectHitTestResults.clear(); FatFingersResult result(m_contentPos); // Lets set nodeUnderFatFinger to the result of a point based hit test here. If something // targable is actually found by ::findIntersectingRegions, then we might replace what we just set below later on. const HitTestResult& hitResult = m_webPage->hitTestResult(m_contentPos); Node* node = hitResult.innerNode(); while (node && !node->isElementNode()) node = node->parentNode(); Element* elementUnderPoint = static_cast<Element*>(node); if (elementUnderPoint) { result.m_nodeUnderFatFinger = elementUnderPoint; // If we are looking for a Clickable Element and we found one, we can quit early. if (m_targetType == ClickableElement) { if (isElementClickable(elementUnderPoint)) { setSuccessfulFatFingersResult(result, elementUnderPoint, m_contentPos /*adjustedPosition*/); return result; } if (hitResult.URLElement()) { setSuccessfulFatFingersResult(result, hitResult.URLElement(), m_contentPos /*adjustedPosition*/); return result; } } } #if DEBUG_FAT_FINGERS // Force blit to make the fat fingers rects show up. if (!m_debugFatFingerRect.isEmpty()) m_webPage->m_backingStore->repaint(0, 0, m_webPage->transformedViewportSize().width(), m_webPage->transformedViewportSize().height(), true, true); #endif Vector<IntersectingRegion> intersectingRegions; IntRectRegion remainingFingerRegion = IntRectRegion(fingerRectForPoint(m_contentPos)); bool foundOne = findIntersectingRegions(m_webPage->m_mainFrame->document(), intersectingRegions, remainingFingerRegion); m_cachedRectHitTestResults.clear(); if (!foundOne) return result; Node* bestNode = 0; IntRectRegion largestIntersectionRegion; int largestIntersectionRegionArea = 0; Vector<IntersectingRegion>::const_iterator endIt = intersectingRegions.end(); for (Vector<IntersectingRegion>::const_iterator it = intersectingRegions.begin(); it != endIt; ++it) { Node* currentNode = it->first; IntRectRegion currentIntersectionRegion = it->second; int currentIntersectionRegionArea = currentIntersectionRegion.area(); if (currentIntersectionRegionArea > largestIntersectionRegionArea || (currentIntersectionRegionArea == largestIntersectionRegionArea && compareDistanceBetweenPoints(m_contentPos, currentIntersectionRegion, largestIntersectionRegion))) { bestNode = currentNode; largestIntersectionRegion = currentIntersectionRegion; largestIntersectionRegionArea = currentIntersectionRegionArea; } } if (!bestNode || largestIntersectionRegion.isEmpty()) return result; #if DEBUG_FAT_FINGERS const Platform::ViewportAccessor* viewportAccessor = m_webPage->m_webkitThreadViewportAccessor; m_debugFatFingerAdjustedPosition = viewportAccessor->pixelViewportFromContents( viewportAccessor->roundToPixelFromDocumentContents(largestIntersectionRegion.rects()[0].center())); #endif setSuccessfulFatFingersResult(result, bestNode, largestIntersectionRegion.rects()[0].center() /*adjustedPosition*/); return result; }