Repository navigation
Add an opt-in framework hit-test region pass for platform views - #195607
Open
harryterkelsen wants to merge 25 commits into
Open
harryterkelsen wants to merge 25 commits into
harryterkelsen wants to merge 25 commits into
Conversation
Rename the hit-test region library to hit_test_regions.dart, document how regions are collected and encoded, document the PipelineOwner bookkeeping fields, and run the pass from its own persistent frame callback instead of special-casing it in the main frame callback.
Document that the walk follows child order and its known exceptions, describe the onHitTestRegionsUpdate payload and clear contract, share a single empty payload, and remove the duplicated clear logic.
An absorbing AbsorbPointer painted after a platform view used to claim its own bounds and then skip its subtree, so a platform view inside it never started its own group. Content painted later over that inner platform view was then attributed to the earlier platform view's group. Treat an absorbing AbsorbPointer like an ignoring IgnorePointer for its subtree: it still claims its own bounds, but the walk keeps descending with pointers ignored, so descendant platform views start their own groups and nothing else in the subtree claims a region.
Keep geometry, claim rules and PipelineOwner bookkeeping in the rendering tests, and only the real-widget dialog scenarios in the widget tests, removing widget tests that re-tested the same render objects. Express expected payloads as named rects instead of raw float lists, and make the clip test actually clip: its box was sized to the clip, so the clip had no effect before. Fold the overlay-after-a-second-platform-view attribution case into the grouping test, and run the widget tests at a device pixel ratio of 2 so they check physical-pixel output.
7 tasks done
harryterkelsen
marked this pull request as ready for review
November 4, 2026 22:19
Contributor
There was a problem hiding this comment.
Code Review
This pull request introduces a mechanism to automatically compute hit-test regions overlapping platform views and report them to the engine each frame. It adds tracking of platform views in PipelineOwner, implements a render tree walk in computeHitTestRegions to collect overlapping bounding boxes, and exposes configuration flags in RendererBinding. Feedback on the implementation highlights two critical issues: first, calling applyPaintTransform on un-laid-out children during the tree walk can trigger assertion crashes in debug mode; second, attributing overlapping rectangles only to the most recently painted platform view can cause pointer event leakage when a widget overlaps multiple platform views.
…interceptors-on-the-web-via-a
…interceptors-on-the-web-via-a
This was referenced Nov 12, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This adds an experimental, opt-in framework pass that computes the regions where Flutter content painted on top of a platform view would claim pointer events. A later change will have the web engine use these regions to place hit-test proxies, so content drawn over
HtmlElementViews gets pointer events without wrapping it in aPointerInterceptor.Behind the new
RendererBinding.automaticPointerInterceptorsEnabledflag (off by default; it only has an effect on the web unlessdebugEnableHitTestRegionsOnAllPlatformsis set),PipelineOwner.flushHitTestRegions()runs after compositing each frame:PlatformViewRenderBoxreports attach/detach to itsPipelineOwner, so the walk is skipped entirely when an owner has no platform views attached.Offstagesubtrees are skipped. Translucent targets don't claim a rect.RenderObject.hitTestsChildren(defaulttrue).RenderIgnorePointerreturns!ignoringandRenderAbsorbPointerreturns!absorbing. The walk reads the getter instead of checking for specific render object types, so third-party render objects that block hit testing of their children can take part by overriding it. When it is false, no descendant claims a rect, but platform views in the subtree are still found and start their own groups (the browser still sends them pointer events). The render object's own claim isn't affected, so an absorbingAbsorbPointerstill claims its own bounds.Float64List([viewId, n, l, t, r, b * n, ...]) to a newPipelineOwner.onHitTestRegionsUpdatecallback. It's also exposed throughdebugLastHitTestRegionsfor tests. When the last platform view goes away or the flag is turned off, an empty payload is sent once.Part of #179806
Behavioral Changes
automaticPointerInterceptorsEnabledoff (the default), nothing changes at runtime. The only always-on addition is the attach/detach counter onPipelineOwnerfor platform views.RendererBinding.automaticPointerInterceptorsEnabled,PipelineOwner.flushHitTestRegions,PipelineOwner.onHitTestRegionsUpdate,PipelineOwner.debugLastHitTestRegions,debugEnableHitTestRegionsOnAllPlatforms, and the protectedRenderObject.hitTestsChildrengetter (overridden byRenderIgnorePointerandRenderAbsorbPointer). The getter doesn't change hit testing. Only the new pass reads it.Where to focus
RenderObject.hitTestsChildren. It's a new protected member onRenderObject. It sits onRenderObjectrather thanRenderBoxso that sliver render objects (for exampleRenderSliverIgnorePointer, in the follow-up paint-order PR) can override it too. Its contract is that it must agree with the render object's ownhitTest/hitTestChildren.ischecks:RenderOffstage(skips the subtree) and an absorbingRenderAbsorbPointerclaiming its own bounds. Follow-up PRs replace them withvisitChildrenInPaintOrderand a region override point.visitChildrenand treats anything visited after a platform view as painting over it. That matches paint order for most render objects, but not for viewports that paint slivers in reverse, or forIndexedStack. Those cases are left for the follow-up paint-order PR.RendererBinding.initInstances, not fromdrawFrame, because the test bindings overridedrawFramewithout calling super.packages/flutter/lib/src/rendering/hit_test_regions.dart(the walk and encoding), thenobject.dart(PipelineOwnerbookkeeping andhitTestsChildren),proxy_box.dart(theIgnorePointer/AbsorbPointeroverrides) andbinding.dart(flag and frame callback).Pre-launch Checklist
///).If you need help, consider asking for advice on the #hackers-new channel on Discord.
If this change needs to override an active code freeze, provide a comment explaining why. The code freeze workflow can be overridden by code reviewers. See pinned issues for any active code freezes with guidance.
Note: The Flutter team is currently trialing the use of Gemini Code Assist for GitHub. Comments from the
gemini-code-assistbot should not be taken as authoritative feedback from the Flutter team. If you find its comments useful you can update your code accordingly, but if you are unsure or disagree with the feedback, please feel free to wait for a Flutter team member's review for guidance on which automated comments should be addressed.