Unverified Commit 13f106b0 authored by Kate Lovett's avatar Kate Lovett Committed by GitHub

Allow Clip.none as a valid clipBehavior (#95593)

parent f82c0200
...@@ -1429,13 +1429,13 @@ class RenderClipRect extends _RenderCustomClip<Rect> { ...@@ -1429,13 +1429,13 @@ class RenderClipRect extends _RenderCustomClip<Rect> {
/// If [clipper] is null, the clip will match the layout size and position of /// If [clipper] is null, the clip will match the layout size and position of
/// the child. /// the child.
/// ///
/// The [clipBehavior] must not be null or [Clip.none]. /// The [clipBehavior] must not be null. If [clipBehavior] is
/// [Clip.none], no clipping will be applied.
RenderClipRect({ RenderClipRect({
RenderBox? child, RenderBox? child,
CustomClipper<Rect>? clipper, CustomClipper<Rect>? clipper,
Clip clipBehavior = Clip.antiAlias, Clip clipBehavior = Clip.antiAlias,
}) : assert(clipBehavior != null), }) : assert(clipBehavior != null),
assert(clipBehavior != Clip.none),
super(child: child, clipper: clipper, clipBehavior: clipBehavior); super(child: child, clipper: clipper, clipBehavior: clipBehavior);
@override @override
...@@ -1455,15 +1455,20 @@ class RenderClipRect extends _RenderCustomClip<Rect> { ...@@ -1455,15 +1455,20 @@ class RenderClipRect extends _RenderCustomClip<Rect> {
@override @override
void paint(PaintingContext context, Offset offset) { void paint(PaintingContext context, Offset offset) {
if (child != null) { if (child != null) {
_updateClip(); if (clipBehavior != Clip.none) {
layer = context.pushClipRect( _updateClip();
needsCompositing, layer = context.pushClipRect(
offset, needsCompositing,
_clip!, offset,
super.paint, _clip!,
clipBehavior: clipBehavior, super.paint,
oldLayer: layer as ClipRectLayer?, clipBehavior: clipBehavior,
); oldLayer: layer as ClipRectLayer?,
);
} else {
context.paintChild(child!, offset);
layer = null;
}
} else { } else {
layer = null; layer = null;
} }
...@@ -1495,14 +1500,14 @@ class RenderClipRRect extends _RenderCustomClip<RRect> { ...@@ -1495,14 +1500,14 @@ class RenderClipRRect extends _RenderCustomClip<RRect> {
/// ///
/// If [clipper] is non-null, then [borderRadius] is ignored. /// If [clipper] is non-null, then [borderRadius] is ignored.
/// ///
/// The [clipBehavior] argument must not be null or [Clip.none]. /// The [clipBehavior] argument must not be null. If [clipBehavior] is
/// [Clip.none], no clipping will be applied.
RenderClipRRect({ RenderClipRRect({
RenderBox? child, RenderBox? child,
BorderRadius borderRadius = BorderRadius.zero, BorderRadius borderRadius = BorderRadius.zero,
CustomClipper<RRect>? clipper, CustomClipper<RRect>? clipper,
Clip clipBehavior = Clip.antiAlias, Clip clipBehavior = Clip.antiAlias,
}) : assert(clipBehavior != null), }) : assert(clipBehavior != null),
assert(clipBehavior != Clip.none),
_borderRadius = borderRadius, _borderRadius = borderRadius,
super(child: child, clipper: clipper, clipBehavior: clipBehavior) { super(child: child, clipper: clipper, clipBehavior: clipBehavior) {
assert(_borderRadius != null || clipper != null); assert(_borderRadius != null || clipper != null);
...@@ -1541,14 +1546,21 @@ class RenderClipRRect extends _RenderCustomClip<RRect> { ...@@ -1541,14 +1546,21 @@ class RenderClipRRect extends _RenderCustomClip<RRect> {
@override @override
void paint(PaintingContext context, Offset offset) { void paint(PaintingContext context, Offset offset) {
if (child != null) { if (child != null) {
_updateClip(); if (clipBehavior != Clip.none) {
layer = context.pushClipRRect( _updateClip();
needsCompositing, layer = context.pushClipRRect(
offset, needsCompositing,
_clip!.outerRect, offset,
_clip!, _clip!.outerRect,
super.paint, clipBehavior: clipBehavior, oldLayer: layer as ClipRRectLayer?, _clip!,
); super.paint,
clipBehavior: clipBehavior,
oldLayer: layer as ClipRRectLayer?,
);
} else {
context.paintChild(child!, offset);
layer = null;
}
} else { } else {
layer = null; layer = null;
} }
...@@ -1578,13 +1590,13 @@ class RenderClipOval extends _RenderCustomClip<Rect> { ...@@ -1578,13 +1590,13 @@ class RenderClipOval extends _RenderCustomClip<Rect> {
/// If [clipper] is null, the oval will be inscribed into the layout size and /// If [clipper] is null, the oval will be inscribed into the layout size and
/// position of the child. /// position of the child.
/// ///
/// The [clipBehavior] argument must not be null or [Clip.none]. /// The [clipBehavior] argument must not be null. If [clipBehavior] is
/// [Clip.none], no clipping will be applied.
RenderClipOval({ RenderClipOval({
RenderBox? child, RenderBox? child,
CustomClipper<Rect>? clipper, CustomClipper<Rect>? clipper,
Clip clipBehavior = Clip.antiAlias, Clip clipBehavior = Clip.antiAlias,
}) : assert(clipBehavior != null), }) : assert(clipBehavior != null),
assert(clipBehavior != Clip.none),
super(child: child, clipper: clipper, clipBehavior: clipBehavior); super(child: child, clipper: clipper, clipBehavior: clipBehavior);
Rect? _cachedRect; Rect? _cachedRect;
...@@ -1620,16 +1632,21 @@ class RenderClipOval extends _RenderCustomClip<Rect> { ...@@ -1620,16 +1632,21 @@ class RenderClipOval extends _RenderCustomClip<Rect> {
@override @override
void paint(PaintingContext context, Offset offset) { void paint(PaintingContext context, Offset offset) {
if (child != null) { if (child != null) {
_updateClip(); if (clipBehavior != Clip.none) {
layer = context.pushClipPath( _updateClip();
needsCompositing, layer = context.pushClipPath(
offset, needsCompositing,
_clip!, offset,
_getClipPath(_clip!), _clip!,
super.paint, _getClipPath(_clip!),
clipBehavior: clipBehavior, super.paint,
oldLayer: layer as ClipPathLayer?, clipBehavior: clipBehavior,
); oldLayer: layer as ClipPathLayer?,
);
} else {
context.paintChild(child!, offset);
layer = null;
}
} else { } else {
layer = null; layer = null;
} }
...@@ -1667,13 +1684,13 @@ class RenderClipPath extends _RenderCustomClip<Path> { ...@@ -1667,13 +1684,13 @@ class RenderClipPath extends _RenderCustomClip<Path> {
/// consider using a [RenderClipRect], which can achieve the same effect more /// consider using a [RenderClipRect], which can achieve the same effect more
/// efficiently. /// efficiently.
/// ///
/// The [clipBehavior] argument must not be null or [Clip.none]. /// The [clipBehavior] argument must not be null. If [clipBehavior] is
/// [Clip.none], no clipping will be applied.
RenderClipPath({ RenderClipPath({
RenderBox? child, RenderBox? child,
CustomClipper<Path>? clipper, CustomClipper<Path>? clipper,
Clip clipBehavior = Clip.antiAlias, Clip clipBehavior = Clip.antiAlias,
}) : assert(clipBehavior != null), }) : assert(clipBehavior != null),
assert(clipBehavior != Clip.none),
super(child: child, clipper: clipper, clipBehavior: clipBehavior); super(child: child, clipper: clipper, clipBehavior: clipBehavior);
@override @override
...@@ -1693,16 +1710,21 @@ class RenderClipPath extends _RenderCustomClip<Path> { ...@@ -1693,16 +1710,21 @@ class RenderClipPath extends _RenderCustomClip<Path> {
@override @override
void paint(PaintingContext context, Offset offset) { void paint(PaintingContext context, Offset offset) {
if (child != null) { if (child != null) {
_updateClip(); if (clipBehavior != Clip.none) {
layer = context.pushClipPath( _updateClip();
needsCompositing, layer = context.pushClipPath(
offset, needsCompositing,
Offset.zero & size, offset,
_clip!, Offset.zero & size,
super.paint, _clip!,
clipBehavior: clipBehavior, super.paint,
oldLayer: layer as ClipPathLayer?, clipBehavior: clipBehavior,
); oldLayer: layer as ClipPathLayer?,
);
} else {
context.paintChild(child!, offset);
layer = null;
}
} else { } else {
layer = null; layer = null;
} }
......
...@@ -662,10 +662,15 @@ class ClipRect extends SingleChildRenderObjectWidget { ...@@ -662,10 +662,15 @@ class ClipRect extends SingleChildRenderObjectWidget {
/// If [clipper] is null, the clip will match the layout size and position of /// If [clipper] is null, the clip will match the layout size and position of
/// the child. /// the child.
/// ///
/// The [clipBehavior] argument must not be null or [Clip.none]. /// The [clipBehavior] argument must not be null. If [clipBehavior] is
const ClipRect({ Key? key, this.clipper, this.clipBehavior = Clip.hardEdge, Widget? child }) /// [Clip.none], no clipping will be applied.
: assert(clipBehavior != null), const ClipRect({
super(key: key, child: child); Key? key,
this.clipper,
this.clipBehavior = Clip.hardEdge,
Widget? child,
}) : assert(clipBehavior != null),
super(key: key, child: child);
/// If non-null, determines which clip to use. /// If non-null, determines which clip to use.
final CustomClipper<Rect>? clipper; final CustomClipper<Rect>? clipper;
...@@ -677,13 +682,11 @@ class ClipRect extends SingleChildRenderObjectWidget { ...@@ -677,13 +682,11 @@ class ClipRect extends SingleChildRenderObjectWidget {
@override @override
RenderClipRect createRenderObject(BuildContext context) { RenderClipRect createRenderObject(BuildContext context) {
assert(clipBehavior != Clip.none);
return RenderClipRect(clipper: clipper, clipBehavior: clipBehavior); return RenderClipRect(clipper: clipper, clipBehavior: clipBehavior);
} }
@override @override
void updateRenderObject(BuildContext context, RenderClipRect renderObject) { void updateRenderObject(BuildContext context, RenderClipRect renderObject) {
assert(clipBehavior != Clip.none);
renderObject renderObject
..clipper = clipper ..clipper = clipper
..clipBehavior = clipBehavior; ..clipBehavior = clipBehavior;
...@@ -723,7 +726,8 @@ class ClipRRect extends SingleChildRenderObjectWidget { ...@@ -723,7 +726,8 @@ class ClipRRect extends SingleChildRenderObjectWidget {
/// ///
/// If [clipper] is non-null, then [borderRadius] is ignored. /// If [clipper] is non-null, then [borderRadius] is ignored.
/// ///
/// The [clipBehavior] argument must not be null or [Clip.none]. /// The [clipBehavior] argument must not be null. If [clipBehavior] is
/// [Clip.none], no clipping will be applied.
const ClipRRect({ const ClipRRect({
Key? key, Key? key,
this.borderRadius = BorderRadius.zero, this.borderRadius = BorderRadius.zero,
...@@ -752,13 +756,15 @@ class ClipRRect extends SingleChildRenderObjectWidget { ...@@ -752,13 +756,15 @@ class ClipRRect extends SingleChildRenderObjectWidget {
@override @override
RenderClipRRect createRenderObject(BuildContext context) { RenderClipRRect createRenderObject(BuildContext context) {
assert(clipBehavior != Clip.none); return RenderClipRRect(
return RenderClipRRect(borderRadius: borderRadius!, clipper: clipper, clipBehavior: clipBehavior); borderRadius: borderRadius!,
clipper: clipper,
clipBehavior: clipBehavior,
);
} }
@override @override
void updateRenderObject(BuildContext context, RenderClipRRect renderObject) { void updateRenderObject(BuildContext context, RenderClipRRect renderObject) {
assert(clipBehavior != Clip.none);
renderObject renderObject
..borderRadius = borderRadius! ..borderRadius = borderRadius!
..clipBehavior = clipBehavior ..clipBehavior = clipBehavior
...@@ -793,10 +799,15 @@ class ClipOval extends SingleChildRenderObjectWidget { ...@@ -793,10 +799,15 @@ class ClipOval extends SingleChildRenderObjectWidget {
/// If [clipper] is null, the oval will be inscribed into the layout size and /// If [clipper] is null, the oval will be inscribed into the layout size and
/// position of the child. /// position of the child.
/// ///
/// The [clipBehavior] argument must not be null or [Clip.none]. /// The [clipBehavior] argument must not be null. If [clipBehavior] is
const ClipOval({Key? key, this.clipper, this.clipBehavior = Clip.antiAlias, Widget? child}) /// [Clip.none], no clipping will be applied.
: assert(clipBehavior != null), const ClipOval({
super(key: key, child: child); Key? key,
this.clipper,
this.clipBehavior = Clip.antiAlias,
Widget? child,
}) : assert(clipBehavior != null),
super(key: key, child: child);
/// If non-null, determines which clip to use. /// If non-null, determines which clip to use.
/// ///
...@@ -816,13 +827,11 @@ class ClipOval extends SingleChildRenderObjectWidget { ...@@ -816,13 +827,11 @@ class ClipOval extends SingleChildRenderObjectWidget {
@override @override
RenderClipOval createRenderObject(BuildContext context) { RenderClipOval createRenderObject(BuildContext context) {
assert(clipBehavior != Clip.none);
return RenderClipOval(clipper: clipper, clipBehavior: clipBehavior); return RenderClipOval(clipper: clipper, clipBehavior: clipBehavior);
} }
@override @override
void updateRenderObject(BuildContext context, RenderClipOval renderObject) { void updateRenderObject(BuildContext context, RenderClipOval renderObject) {
assert(clipBehavior != Clip.none);
renderObject renderObject
..clipper = clipper ..clipper = clipper
..clipBehavior = clipBehavior; ..clipBehavior = clipBehavior;
...@@ -866,7 +875,8 @@ class ClipPath extends SingleChildRenderObjectWidget { ...@@ -866,7 +875,8 @@ class ClipPath extends SingleChildRenderObjectWidget {
/// consider using a [ClipRect], which can achieve the same effect more /// consider using a [ClipRect], which can achieve the same effect more
/// efficiently. /// efficiently.
/// ///
/// The [clipBehavior] argument must not be null or [Clip.none]. /// The [clipBehavior] argument must not be null. If [clipBehavior] is
/// [Clip.none], no clipping will be applied.
const ClipPath({ const ClipPath({
Key? key, Key? key,
this.clipper, this.clipper,
...@@ -886,7 +896,6 @@ class ClipPath extends SingleChildRenderObjectWidget { ...@@ -886,7 +896,6 @@ class ClipPath extends SingleChildRenderObjectWidget {
Widget? child, Widget? child,
}) { }) {
assert(clipBehavior != null); assert(clipBehavior != null);
assert(clipBehavior != Clip.none);
assert(shape != null); assert(shape != null);
return Builder( return Builder(
key: key, key: key,
...@@ -917,13 +926,11 @@ class ClipPath extends SingleChildRenderObjectWidget { ...@@ -917,13 +926,11 @@ class ClipPath extends SingleChildRenderObjectWidget {
@override @override
RenderClipPath createRenderObject(BuildContext context) { RenderClipPath createRenderObject(BuildContext context) {
assert(clipBehavior != Clip.none);
return RenderClipPath(clipper: clipper, clipBehavior: clipBehavior); return RenderClipPath(clipper: clipper, clipBehavior: clipBehavior);
} }
@override @override
void updateRenderObject(BuildContext context, RenderClipPath renderObject) { void updateRenderObject(BuildContext context, RenderClipPath renderObject) {
assert(clipBehavior != Clip.none);
renderObject renderObject
..clipper = clipper ..clipper = clipper
..clipBehavior = clipBehavior; ..clipBehavior = clipBehavior;
...@@ -1014,7 +1021,8 @@ class PhysicalModel extends SingleChildRenderObjectWidget { ...@@ -1014,7 +1021,8 @@ class PhysicalModel extends SingleChildRenderObjectWidget {
shape: shape, shape: shape,
clipBehavior: clipBehavior, clipBehavior: clipBehavior,
borderRadius: borderRadius, borderRadius: borderRadius,
elevation: elevation, color: color, elevation: elevation,
color: color,
shadowColor: shadowColor, shadowColor: shadowColor,
); );
} }
......
...@@ -87,6 +87,10 @@ void main() { ...@@ -87,6 +87,10 @@ void main() {
await tester.pumpWidget(const ClipRect(clipBehavior: Clip.antiAlias)); await tester.pumpWidget(const ClipRect(clipBehavior: Clip.antiAlias));
expect(renderClip.clipBehavior, equals(Clip.antiAlias)); expect(renderClip.clipBehavior, equals(Clip.antiAlias));
await tester.pumpWidget(const ClipRect(clipBehavior: Clip.none));
expect(renderClip.clipBehavior, equals(Clip.none));
}); });
test('ClipRRect constructs with the right default values', () { test('ClipRRect constructs with the right default values', () {
...@@ -105,6 +109,10 @@ void main() { ...@@ -105,6 +109,10 @@ void main() {
await tester.pumpWidget(const ClipRRect(clipBehavior: Clip.hardEdge)); await tester.pumpWidget(const ClipRRect(clipBehavior: Clip.hardEdge));
expect(renderClip.clipBehavior, equals(Clip.hardEdge)); expect(renderClip.clipBehavior, equals(Clip.hardEdge));
await tester.pumpWidget(const ClipRRect(clipBehavior: Clip.none));
expect(renderClip.clipBehavior, equals(Clip.none));
}); });
testWidgets('ClipOval updates clipBehavior in updateRenderObject', (WidgetTester tester) async { testWidgets('ClipOval updates clipBehavior in updateRenderObject', (WidgetTester tester) async {
...@@ -117,6 +125,10 @@ void main() { ...@@ -117,6 +125,10 @@ void main() {
await tester.pumpWidget(const ClipOval(clipBehavior: Clip.hardEdge)); await tester.pumpWidget(const ClipOval(clipBehavior: Clip.hardEdge));
expect(renderClip.clipBehavior, equals(Clip.hardEdge)); expect(renderClip.clipBehavior, equals(Clip.hardEdge));
await tester.pumpWidget(const ClipOval(clipBehavior: Clip.none));
expect(renderClip.clipBehavior, equals(Clip.none));
}); });
testWidgets('ClipPath updates clipBehavior in updateRenderObject', (WidgetTester tester) async { testWidgets('ClipPath updates clipBehavior in updateRenderObject', (WidgetTester tester) async {
...@@ -129,6 +141,10 @@ void main() { ...@@ -129,6 +141,10 @@ void main() {
await tester.pumpWidget(const ClipPath(clipBehavior: Clip.hardEdge)); await tester.pumpWidget(const ClipPath(clipBehavior: Clip.hardEdge));
expect(renderClip.clipBehavior, equals(Clip.hardEdge)); expect(renderClip.clipBehavior, equals(Clip.hardEdge));
await tester.pumpWidget(const ClipPath(clipBehavior: Clip.none));
expect(renderClip.clipBehavior, equals(Clip.none));
}); });
testWidgets('ClipPath', (WidgetTester tester) async { testWidgets('ClipPath', (WidgetTester tester) async {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment