Skip to content

Add an opt-in framework hit-test region pass for platform views - #195607

Open
harryterkelsen wants to merge 25 commits into
flutter:masterfrom
harryterkelsen:automatic-pointerinterceptors-on-the-web-via-a
Open

harryterkelsen wants to merge 25 commits into
flutter:masterfrom
harryterkelsen:automatic-pointerinterceptors-on-the-web-via-a

Conversation

@harryterkelsen

@harryterkelsen harryterkelsen commented Oct 29, 2026 •

Copy link
Copy Markdown
Contributor

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 a PointerInterceptor.

Behind the new RendererBinding.automaticPointerInterceptorsEnabled flag (off by default; it only has an effect on the web unless debugEnableHitTestRegionsOnAllPlatforms is set), PipelineOwner.flushHitTestRegions() runs after compositing each frame:

  • PlatformViewRenderBox reports attach/detach to its PipelineOwner, so the walk is skipped entirely when an owner has no platform views attached.
  • A walk (in child order; paint-order overrides follow in a later PR) tracks the global transform and ancestor paint clips. It groups the physical-pixel rects of hit-testable boxes painted after each platform view, and keeps only rects that overlap an earlier platform view. Offstage subtrees are skipped. Translucent targets don't claim a rect.
  • Render objects describe whether pointer events can reach their children through a new protected getter, RenderObject.hitTestsChildren (default true). RenderIgnorePointer returns !ignoring and RenderAbsorbPointer returns !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 absorbing AbsorbPointer still claims its own bounds.
  • The result is sent as a flat Float64List ([viewId, n, l, t, r, b * n, ...]) to a new PipelineOwner.onHitTestRegionsUpdate callback. It's also exposed through debugLastHitTestRegions for tests. When the last platform view goes away or the flag is turned off, an empty payload is sent once.
  • The pass recurses through child pipeline owners, so it works with multiple views.

Part of #179806

Behavioral Changes

  • With automaticPointerInterceptorsEnabled off (the default), nothing changes at runtime. The only always-on addition is the attach/detach counter on PipelineOwner for platform views.
  • New API: RendererBinding.automaticPointerInterceptorsEnabled, PipelineOwner.flushHitTestRegions, PipelineOwner.onHitTestRegionsUpdate, PipelineOwner.debugLastHitTestRegions, debugEnableHitTestRegionsOnAllPlatforms, and the protected RenderObject.hitTestsChildren getter (overridden by RenderIgnorePointer and RenderAbsorbPointer). The getter doesn't change hit testing. Only the new pass reads it.

Where to focus

  • RenderObject.hitTestsChildren. It's a new protected member on RenderObject. It sits on RenderObject rather than RenderBox so that sliver render objects (for example RenderSliverIgnorePointer, in the follow-up paint-order PR) can override it too. Its contract is that it must agree with the render object's own hitTest/hitTestChildren.
  • Remaining type checks. The walk still has two is checks: RenderOffstage (skips the subtree) and an absorbing RenderAbsorbPointer claiming its own bounds. Follow-up PRs replace them with visitChildrenInPaintOrder and a region override point.
  • Child order, not paint order. The walk follows visitChildren and 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 for IndexedStack. Those cases are left for the follow-up paint-order PR.
  • Frame hook. The pass runs from its own persistent frame callback registered in RendererBinding.initInstances, not from drawFrame, because the test bindings override drawFrame without calling super.
  • Empty-payload teardown. One empty payload is sent when the last platform view detaches or the flag is turned off, and only on platforms where the pass runs.
  • Primary files: packages/flutter/lib/src/rendering/hit_test_regions.dart (the walk and encoding), then object.dart (PipelineOwner bookkeeping and hitTestsChildren), proxy_box.dart (the IgnorePointer/AbsorbPointer overrides) and binding.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-assist bot 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.

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.
@github-actions github-actions Bot added the framework flutter/packages/flutter repository. See also f: labels. label Oct 29, 2026
@harryterkelsen
harryterkelsen marked this pull request as ready for review November 4, 2026 22:19
@harryterkelsen harryterkelsen added the CICD Run CI/CD label Nov 4, 2026

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@github-actions github-actions Bot added the a: tests "flutter test", flutter_test, or one of our tests label Nov 12, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

a: tests "flutter test", flutter_test, or one of our tests CICD Run CI/CD framework flutter/packages/flutter repository. See also f: labels.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant