Skip to content

Commit

Permalink
Overlay regions do not correctly handle sticky positioned scrolling n…
Browse files Browse the repository at this point in the history
…odes

https://bugs.webkit.org/show_bug.cgi?id=243973
<rdar://98640826>

Reviewed by Tim Horton.

Sticky node regions should be added to the overlay regions but their rectangles
can move during scrolling. Also fixed or sticky rectangles can change
during page zoom.

To support this, instead of storing a list of rectangles, store a list of
layer IDs with event regions and then compute the rectangles.

* Source/WebKit/UIProcess/API/ios/WKWebViewIOS.mm:
(addOverlayEventRegions):
Store only the layer ID.

(-[WKWebView _updateOverlayRegions:destroyedLayers:]):
Recompute the rectangles from the current frames of the nodes whenever the layer
properties change. Scrolling and page zoom where this would be impacted both
trigger a change in layer properties.

* Source/WebKit/UIProcess/RemoteLayerTree/RemoteLayerTreeDrawingAreaProxy.h:
Renamed function.

* Source/WebKit/UIProcess/RemoteLayerTree/RemoteLayerTreeHost.h:
(WebKit::RemoteLayerTreeHost::overlayRegionIDs const):
(WebKit::RemoteLayerTreeHost::updateOverlayRegionIDs):
Renamed.

* Source/WebKit/UIProcess/RemoteLayerTree/ios/RemoteScrollingCoordinatorProxyIOS.mm:
(WebKit::RemoteScrollingCoordinatorProxy::connectStateNodeLayers):
Call renamed function.

Canonical link: https://commits.webkit.org/253603@main
  • Loading branch information
mwyrzykowski authored and hortont424 committed Aug 19, 2022
1 parent 7199d38 commit 649ae3d
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 17 deletions.
24 changes: 12 additions & 12 deletions Source/WebKit/UIProcess/API/ios/WKWebViewIOS.mm
Original file line number Diff line number Diff line change
Expand Up @@ -1054,7 +1054,7 @@ - (void)_didCommitLayerTree:(const WebKit::RemoteLayerTreeTransaction&)layerTree
}

#if ENABLE(OVERLAY_REGIONS_IN_EVENT_REGION)
static void addOverlayEventRegions(WebCore::GraphicsLayer::PlatformLayerID layerID, const WebKit::RemoteLayerTreeTransaction::LayerPropertiesMap& changedLayerPropertiesMap, HashMap<WebCore::GraphicsLayer::PlatformLayerID, CGRect>& overlayRegionsWithIDs, const WebKit::RemoteLayerTreeHost& layerTreeHost, UIView *rootView)
static void addOverlayEventRegions(WebCore::GraphicsLayer::PlatformLayerID layerID, const WebKit::RemoteLayerTreeTransaction::LayerPropertiesMap& changedLayerPropertiesMap, HashSet<WebCore::GraphicsLayer::PlatformLayerID>& overlayRegionIDs, const WebKit::RemoteLayerTreeHost& layerTreeHost)
{
using WebKit::RemoteLayerTreeTransaction;
const auto& it = changedLayerPropertiesMap.find(layerID);
Expand All @@ -1063,13 +1063,11 @@ static void addOverlayEventRegions(WebCore::GraphicsLayer::PlatformLayerID layer

const auto& layerProperties = *it->value;
CGRect rect = layerProperties.eventRegion.region().bounds();
if ((layerProperties.changedProperties & RemoteLayerTreeTransaction::EventRegionChanged) && !CGRectIsEmpty(rect)) {
if (const auto* node = layerTreeHost.nodeForID(layerID))
overlayRegionsWithIDs.set(layerID, [node->uiView() convertRect:rect toView:rootView]);
}
if ((layerProperties.changedProperties & RemoteLayerTreeTransaction::EventRegionChanged) && !CGRectIsEmpty(rect))
overlayRegionIDs.add(layerID);

for (auto childLayerID : layerProperties.children)
addOverlayEventRegions(childLayerID, changedLayerPropertiesMap, overlayRegionsWithIDs, layerTreeHost, rootView);
addOverlayEventRegions(childLayerID, changedLayerPropertiesMap, overlayRegionIDs, layerTreeHost);
}

- (void)_updateOverlayRegions:(const WebKit::RemoteLayerTreeTransaction::LayerPropertiesMap&)changedLayerPropertiesMap destroyedLayers:(const Vector<WebCore::GraphicsLayer::PlatformLayerID>&)destroyedLayers
Expand All @@ -1086,19 +1084,21 @@ - (void)_updateOverlayRegions:(const WebKit::RemoteLayerTreeTransaction::LayerPr
scrollingCoordinatorProxy->removeFixedScrollingNodeLayerIDs(destroyedLayers);
const auto& fixedIDs = scrollingCoordinatorProxy->fixedScrollingNodeLayerIDs();

auto overlayRegionsWithIDs = layerTreeHost.overlayRegionsWithIDs();
auto overlayRegionIDs = layerTreeHost.overlayRegionIDs();
for (auto layerID : destroyedLayers)
overlayRegionsWithIDs.remove(layerID);
overlayRegionIDs.remove(layerID);

for (auto layerID : fixedIDs)
addOverlayEventRegions(layerID, changedLayerPropertiesMap, overlayRegionsWithIDs, layerTreeHost, self);
addOverlayEventRegions(layerID, changedLayerPropertiesMap, overlayRegionIDs, layerTreeHost);

Vector<CGRect> overlayRegions;
for (const auto& [layerID, rect] : overlayRegionsWithIDs)
overlayRegions.append(rect);
for (const auto layerID : overlayRegionIDs) {
if (const auto* node = layerTreeHost.nodeForID(layerID))
overlayRegions.append([node->uiView() convertRect:node->eventRegion().region().bounds() toView:self]);
}

if ([_scrollView _updateOverlayRegions:overlayRegions])
layerTreeProxy.updateOverlayRegionsWithIDs(overlayRegionsWithIDs);
layerTreeProxy.updateOverlayRegionIDs(overlayRegionIDs);
}
#endif // ENABLE(OVERLAY_REGIONS_IN_EVENT_REGION)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ class RemoteLayerTreeDrawingAreaProxy final : public DrawingAreaProxy {
CALayer *layerWithIDForTesting(uint64_t) const;

#if ENABLE(OVERLAY_REGIONS_IN_EVENT_REGION)
void updateOverlayRegionsWithIDs(const HashMap<WebCore::GraphicsLayer::PlatformLayerID, CGRect> &overlayRegions) { m_remoteLayerTreeHost->updateOverlayRegionsWithIDs(overlayRegions); }
void updateOverlayRegionIDs(const HashSet<WebCore::GraphicsLayer::PlatformLayerID> &overlayRegionIDs) { m_remoteLayerTreeHost->updateOverlayRegionIDs(overlayRegionIDs); }
#endif

private:
Expand Down
6 changes: 3 additions & 3 deletions Source/WebKit/UIProcess/RemoteLayerTree/RemoteLayerTreeHost.h
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,8 @@ class RemoteLayerTreeHost {

bool replayCGDisplayListsIntoBackingStore() const;
#if ENABLE(OVERLAY_REGIONS_IN_EVENT_REGION)
const HashMap<WebCore::GraphicsLayer::PlatformLayerID, CGRect>& overlayRegionsWithIDs() const { return m_overlayRegionsWithIDs; }
void updateOverlayRegionsWithIDs(const HashMap<WebCore::GraphicsLayer::PlatformLayerID, CGRect> &overlayRegions) { m_overlayRegionsWithIDs = overlayRegions; }
const HashSet<WebCore::GraphicsLayer::PlatformLayerID>& overlayRegionIDs() const { return m_overlayRegionIDs; }
void updateOverlayRegionIDs(const HashSet<WebCore::GraphicsLayer::PlatformLayerID> &overlayRegionNodes) { m_overlayRegionIDs = overlayRegionNodes; }
#endif

private:
Expand All @@ -94,7 +94,7 @@ class RemoteLayerTreeHost {
HashMap<WebCore::GraphicsLayer::PlatformLayerID, std::unique_ptr<RemoteLayerTreeNode>> m_nodes;
HashMap<WebCore::GraphicsLayer::PlatformLayerID, RetainPtr<WKAnimationDelegate>> m_animationDelegates;
#if ENABLE(OVERLAY_REGIONS_IN_EVENT_REGION)
HashMap<WebCore::GraphicsLayer::PlatformLayerID, CGRect> m_overlayRegionsWithIDs;
HashSet<WebCore::GraphicsLayer::PlatformLayerID> m_overlayRegionIDs;
#endif
bool m_isDebugLayerTreeHost { false };
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@
auto platformLayerID = PlatformLayerID { currNode->layer() };
currNode->setLayer(layerTreeHost.layerForID(platformLayerID));
#if ENABLE(OVERLAY_REGIONS_IN_EVENT_REGION)
if (platformLayerID && currNode->isFixedNode())
if (platformLayerID && (currNode->isFixedNode() || currNode->isStickyNode()))
m_fixedScrollingNodeLayerIDs.add(platformLayerID);
#endif
}
Expand Down

0 comments on commit 649ae3d

Please sign in to comment.