Skip to content

Implement describeApproximatePaintClip in clipping render objects - #196888

Open
YannVanneth wants to merge 5 commits into
flutter:masterfrom
YannVanneth:fix/describe-approximate-paint-clip
Open

YannVanneth wants to merge 5 commits into
flutter:masterfrom
YannVanneth:fix/describe-approximate-paint-clip

Conversation

@YannVanneth

Copy link
Copy Markdown

Fixes #196646

Description

Implements describeApproximatePaintClip on render objects that clip their children during paint so that clipped child semantics rects are clipped accordingly:

  • RenderWrap (packages/flutter/lib/src/rendering/wrap.dart): returns Offset.zero & size when clipBehavior != Clip.none and _hasVisualOverflow is true.
  • RenderFittedBox (packages/flutter/lib/src/rendering/proxy_box.dart): when clipBehavior != Clip.none and paintsChild(child), updates paint data if needed and returns _hasVisualOverflow! ? Offset.zero & size : null.
  • RenderFlow (packages/flutter/lib/src/rendering/flow.dart): returns Offset.zero & size when clipBehavior != Clip.none.
  • RenderParagraph (packages/flutter/lib/src/rendering/paragraph.dart): returns _needsClipping ? Offset.zero & size : null.
  • RenderAnimatedSize (packages/flutter/lib/src/rendering/animated_size.dart): initializes _hasVisualOverflow = false and returns Offset.zero & size when clipBehavior != Clip.none and _hasVisualOverflow is true.
  • RenderTwoDimensionalViewport (packages/flutter/lib/src/widgets/two_dimensional_viewport.dart): returns Offset.zero & viewportDimension when clipBehavior != Clip.none and _hasVisualOverflow is true.

Tests

Added widget tests verifying that each widget clips the semantics rect of an overflowing child when clipping is enabled and preserves the full rect when clipping is disabled:

  • packages/flutter/test/widgets/wrap_test.dart
  • packages/flutter/test/widgets/fitted_box_test.dart
  • packages/flutter/test/widgets/flow_test.dart
  • packages/flutter/test/widgets/text_test.dart
  • packages/flutter/test/widgets/animated_size_test.dart
  • packages/flutter/test/widgets/two_dimensional_viewport_test.dart

Pre-launch Checklist

@github-actions github-actions Bot added a: text input Entering text in a text field or keyboard related problems framework flutter/packages/flutter repository. See also f: labels. f: scrolling Viewports, list views, slivers, etc. labels Nov 18, 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 implements the describeApproximatePaintClip method across several render objects, including RenderAnimatedSize, RenderFlow, RenderParagraph, RenderFittedBox, RenderWrap, and RenderTwoDimensionalViewport, to correctly describe their paint clips. It also adds corresponding tests to verify that the semantics rects of overflowing children are clipped. Feedback on the changes suggests performing a safe type check (child is! RenderBox) instead of a direct cast (child as RenderBox) in RenderFittedBox.describeApproximatePaintClip to avoid potential runtime type errors.

Keep cached TwoDimensionalViewport children in the semantics tree, fix its
overflow detection, and update semantics when RenderFittedBox or RenderFlow
repaint without relayout.
@chunhtai

Copy link
Copy Markdown
Contributor

LGTM

@chunhtai chunhtai added the CICD Run CI/CD label Nov 25, 2026
@flutter-dashboard flutter-dashboard Bot removed the CICD Run CI/CD label Nov 29, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

a: text input Entering text in a text field or keyboard related problems f: scrolling Viewports, list views, slivers, etc. framework flutter/packages/flutter repository. See also f: labels.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Several clipping render objects don't implement describeApproximatePaintClip

2 participants