Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[UI-side compositing] Ensure that wheel events got to the web process for JS event handlers #7234

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,9 @@ class RemoteScrollingTreeMac final : public RemoteScrollingTree {
private:
void handleWheelEventPhase(WebCore::ScrollingNodeID, WebCore::PlatformWheelEventPhase) final;
RefPtr<WebCore::ScrollingTreeNode> scrollingNodeForPoint(WebCore::FloatPoint) final;
#if ENABLE(WHEEL_EVENT_REGIONS)
OptionSet<WebCore::EventListenerRegionType> eventListenerRegionTypesForPoint(WebCore::FloatPoint) const final;
#endif

void hasNodeWithAnimatedScrollChanged(bool) final;
void displayDidRefresh(WebCore::PlatformDisplayID) final;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -130,17 +130,25 @@ static bool isScrolledBy(const ScrollingTree& tree, ScrollingNodeID scrollingNod
return false;
}

static bool layerEventRegionContainsPoint(CALayer *layer, CGPoint localPoint)
static const EventRegion* eventRegionForLayer(CALayer *layer)
{
auto* layerTreeNode = RemoteLayerTreeNode::forCALayer(layer);
if (!layerTreeNode)
return nullptr;

return &layerTreeNode->eventRegion();
}

static bool layerEventRegionContainsPoint(CALayer *layer, CGPoint localPoint)
{
auto* eventRegion = eventRegionForLayer(layer);
if (!eventRegion)
return false;

// Scrolling changes boundsOrigin on the scroll container layer, but we computed its event region ignoring scroll position, so factor out bounds origin.
FloatPoint boundsOrigin = layer.bounds.origin;
FloatPoint originRelativePoint = localPoint - toFloatSize(boundsOrigin);
auto& eventRegion = layerTreeNode->eventRegion();
return eventRegion.contains(roundedIntPoint(originRelativePoint));
return eventRegion->contains(roundedIntPoint(originRelativePoint));
}

RefPtr<ScrollingTreeNode> RemoteScrollingTreeMac::scrollingNodeForPoint(FloatPoint point)
Expand Down Expand Up @@ -183,6 +191,33 @@ static bool layerEventRegionContainsPoint(CALayer *layer, CGPoint localPoint)
return rootScrollingNode;
}

#if ENABLE(WHEEL_EVENT_REGIONS)
OptionSet<EventListenerRegionType> RemoteScrollingTreeMac::eventListenerRegionTypesForPoint(FloatPoint point) const
{
auto* rootScrollingNode = rootNode();
if (!rootScrollingNode)
return { };

auto rootContentsLayer = static_cast<ScrollingTreeFrameScrollingNodeMac*>(rootScrollingNode)->rootContentsLayer();

Vector<LayerAndPoint, 16> layersAtPoint;
collectDescendantLayersAtPoint(layersAtPoint, rootContentsLayer.get(), point, layerEventRegionContainsPoint);

if (layersAtPoint.isEmpty())
return { };

auto [hitLayer, localPoint] = layersAtPoint.last();
if (!hitLayer)
return { };

auto* eventRegion = eventRegionForLayer(hitLayer);
if (!eventRegion)
return { };

return eventRegion->eventListenerRegionTypesForPoint(roundedIntPoint(localPoint));
}
#endif

} // namespace WebKit

#endif // PLATFORM(MAC) && ENABLE(UI_SIDE_COMPOSITING)