Modified: trunk/Source/WebCore/page/Frame.h (250641 => 250642)
--- trunk/Source/WebCore/page/Frame.h 2019-10-03 02:47:00 UTC (rev 250641)
+++ trunk/Source/WebCore/page/Frame.h 2019-10-03 04:53:53 UTC (rev 250642)
@@ -221,6 +221,7 @@
WEBCORE_EXPORT Node* deepestNodeAtLocation(const FloatPoint& viewportLocation);
WEBCORE_EXPORT Node* nodeRespondingToClickEvents(const FloatPoint& viewportLocation, FloatPoint& adjustedViewportLocation, SecurityOrigin* = nullptr);
WEBCORE_EXPORT Node* nodeRespondingToDoubleClickEvent(const FloatPoint& viewportLocation, FloatPoint& adjustedViewportLocation);
+ WEBCORE_EXPORT Node* nodeRespondingToInteraction(const FloatPoint& viewportLocation, FloatPoint& adjustedViewportLocation);
WEBCORE_EXPORT Node* nodeRespondingToScrollWheelEvents(const FloatPoint& viewportLocation);
WEBCORE_EXPORT Node* approximateNodeAtViewportLocationLegacy(const FloatPoint& viewportLocation, FloatPoint& adjustedViewportLocation);
@@ -333,7 +334,10 @@
#if PLATFORM(IOS_FAMILY)
void betterApproximateNode(const IntPoint& testPoint, const NodeQualifier&, Node*& best, Node* failedNode, IntPoint& bestPoint, IntRect& bestRect, const IntRect& testRect);
bool hitTestResultAtViewportLocation(const FloatPoint& viewportLocation, HitTestResult&, IntPoint& center);
- Node* qualifyingNodeAtViewportLocation(const FloatPoint& viewportLocation, FloatPoint& adjustedViewportLocation, const NodeQualifier&, bool shouldApproximate);
+
+ enum class ShouldApproximate : bool { No, Yes };
+ enum class ShouldFindRootEditableElement : bool { No, Yes };
+ Node* qualifyingNodeAtViewportLocation(const FloatPoint& viewportLocation, FloatPoint& adjustedViewportLocation, const NodeQualifier&, ShouldApproximate, ShouldFindRootEditableElement = ShouldFindRootEditableElement::Yes);
void setTimersPausedInternal(bool);
Modified: trunk/Source/WebCore/page/ios/FrameIOS.mm (250641 => 250642)
--- trunk/Source/WebCore/page/ios/FrameIOS.mm 2019-10-03 02:47:00 UTC (rev 250641)
+++ trunk/Source/WebCore/page/ios/FrameIOS.mm 2019-10-03 04:53:53 UTC (rev 250642)
@@ -266,8 +266,12 @@
return true;
}
-Node* Frame::qualifyingNodeAtViewportLocation(const FloatPoint& viewportLocation, FloatPoint& adjustedViewportLocation, const NodeQualifier& nodeQualifierFunction, bool shouldApproximate)
+Node* Frame::qualifyingNodeAtViewportLocation(const FloatPoint& viewportLocation, FloatPoint& adjustedViewportLocation, const NodeQualifier& nodeQualifierFunction, ShouldApproximate shouldApproximate, ShouldFindRootEditableElement shouldFindRootEditableElement)
{
+#if !USE(UIKIT_EDITING)
+ UNUSED_PARAM(shouldFindRootEditableElement);
+#endif
+
adjustedViewportLocation = viewportLocation;
IntPoint testCenter;
@@ -282,12 +286,12 @@
Node* approximateNode = nodeQualifierFunction(candidateInfo, 0, 0);
#if USE(UIKIT_EDITING)
- if (approximateNode && approximateNode->isContentEditable()) {
+ if (shouldFindRootEditableElement == ShouldFindRootEditableElement::Yes && approximateNode && approximateNode->isContentEditable()) {
// If we are in editable content, we look for the root editable element.
approximateNode = approximateNode->rootEditableElement();
// If we have a focusable node, there is no need to approximate.
if (approximateNode)
- shouldApproximate = false;
+ shouldApproximate = ShouldApproximate::No;
}
#endif
@@ -298,7 +302,7 @@
static const float unscaledSearchRadius = 15;
int searchRadius = static_cast<int>(unscaledSearchRadius * ppiFactor / scale);
- if (approximateNode && shouldApproximate) {
+ if (approximateNode && shouldApproximate == ShouldApproximate::Yes) {
const float testOffsets[] = {
-.3f, -.3f,
-.6f, -.6f,
@@ -319,7 +323,7 @@
break;
}
}
- } else if (!approximateNode && shouldApproximate) {
+ } else if (!approximateNode && shouldApproximate == ShouldApproximate::Yes) {
// Grab the closest parent element of our failed candidate node.
Node* candidate = candidateInfo.innerNode();
Node* failedNode = candidate;
@@ -367,7 +371,7 @@
IntPoint p = m_view->contentsToWindow(bestPoint);
adjustedViewportLocation = p;
#if USE(UIKIT_EDITING)
- if (approximateNode->isContentEditable()) {
+ if (shouldFindRootEditableElement == ShouldFindRootEditableElement::Yes && approximateNode->isContentEditable()) {
// When in editable content, look for the root editable node again,
// since this could be the node found with the approximation.
approximateNode = approximateNode->rootEditableElement();
@@ -448,12 +452,12 @@
return nullptr;
};
- return qualifyingNodeAtViewportLocation(viewportLocation, adjustedViewportLocation, WTFMove(ancestorRespondingToClickEvents), true);
+ return qualifyingNodeAtViewportLocation(viewportLocation, adjustedViewportLocation, WTFMove(ancestorRespondingToClickEvents), ShouldApproximate::Yes);
}
-Node* Frame::nodeRespondingToClickEvents(const FloatPoint& viewportLocation, FloatPoint& adjustedViewportLocation, SecurityOrigin* securityOrigin)
+static inline NodeQualifier ancestorRespondingToClickEventsNodeQualifier(SecurityOrigin* securityOrigin = nullptr)
{
- auto&& ancestorRespondingToClickEvents = [securityOrigin](const HitTestResult& hitTestResult, Node* terminationNode, IntRect* nodeBounds) -> Node* {
+ return [securityOrigin](const HitTestResult& hitTestResult, Node* terminationNode, IntRect* nodeBounds) -> Node* {
if (nodeBounds)
*nodeBounds = IntRect();
@@ -478,8 +482,11 @@
return nullptr;
};
+}
- return qualifyingNodeAtViewportLocation(viewportLocation, adjustedViewportLocation, WTFMove(ancestorRespondingToClickEvents), true);
+Node* Frame::nodeRespondingToClickEvents(const FloatPoint& viewportLocation, FloatPoint& adjustedViewportLocation, SecurityOrigin* securityOrigin)
+{
+ return qualifyingNodeAtViewportLocation(viewportLocation, adjustedViewportLocation, ancestorRespondingToClickEventsNodeQualifier(securityOrigin), ShouldApproximate::Yes);
}
Node* Frame::nodeRespondingToDoubleClickEvent(const FloatPoint& viewportLocation, FloatPoint& adjustedViewportLocation)
@@ -506,9 +513,14 @@
return nullptr;
};
- return qualifyingNodeAtViewportLocation(viewportLocation, adjustedViewportLocation, WTFMove(ancestorRespondingToDoubleClickEvent), true);
+ return qualifyingNodeAtViewportLocation(viewportLocation, adjustedViewportLocation, WTFMove(ancestorRespondingToDoubleClickEvent), ShouldApproximate::Yes);
}
+Node* Frame::nodeRespondingToInteraction(const FloatPoint& viewportLocation, FloatPoint& adjustedViewportLocation)
+{
+ return qualifyingNodeAtViewportLocation(viewportLocation, adjustedViewportLocation, ancestorRespondingToClickEventsNodeQualifier(), ShouldApproximate::Yes, ShouldFindRootEditableElement::No);
+}
+
Node* Frame::nodeRespondingToScrollWheelEvents(const FloatPoint& viewportLocation)
{
auto&& ancestorRespondingToScrollWheelEvents = [](const HitTestResult& hitTestResult, Node* terminationNode, IntRect* nodeBounds) -> Node* {
@@ -539,7 +551,7 @@
};
FloatPoint adjustedViewportLocation;
- return qualifyingNodeAtViewportLocation(viewportLocation, adjustedViewportLocation, WTFMove(ancestorRespondingToScrollWheelEvents), false);
+ return qualifyingNodeAtViewportLocation(viewportLocation, adjustedViewportLocation, WTFMove(ancestorRespondingToScrollWheelEvents), ShouldApproximate::No);
}
int Frame::preferredHeight() const
Modified: trunk/Source/WebKit/WebProcess/WebPage/ios/WebPageIOS.mm (250641 => 250642)
--- trunk/Source/WebKit/WebProcess/WebPage/ios/WebPageIOS.mm 2019-10-03 02:47:00 UTC (rev 250641)
+++ trunk/Source/WebKit/WebProcess/WebPage/ios/WebPageIOS.mm 2019-10-03 04:53:53 UTC (rev 250642)
@@ -2813,8 +2813,14 @@
void WebPage::startInteractionWithElementAtPosition(const WebCore::IntPoint& point)
{
+ // FIXME: We've already performed a hit test when the long-press gesture was recognized and we
+ // used that result to generate the targeted preview, but now we are hit testing again in order
+ // to perform the selected action. Since an arbitrary amount of time can elapse between
+ // generating the targeted preview and the user selecting an action, it's possible that this
+ // second hit test will find a different element than the first one, leading to bugs like
+ // <rdar://problem/54723131>. We should re-use the results of the first hit test instead.
FloatPoint adjustedPoint;
- m_interactionNode = m_page->mainFrame().nodeRespondingToClickEvents(point, adjustedPoint);
+ m_interactionNode = m_page->mainFrame().nodeRespondingToInteraction(point, adjustedPoint);
}
void WebPage::stopInteraction()