Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

Commit 873ac3b

Browse files
authored
[web] Fixing clipping not being applied when height is zero (#27771)
1 parent 1138389 commit 873ac3b

File tree

3 files changed

+57
-10
lines changed

3 files changed

+57
-10
lines changed

lib/web_ui/dev/goldens_lock.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
repository: https://github.com/flutter/goldens.git
2-
revision: f1baad46498ce1a754a15d02249827bb042b446b
2+
revision: 8517dd15b8eb62e07ecde82170f8a4016566ea49

lib/web_ui/lib/src/engine/html/recording_canvas.dart

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1832,19 +1832,19 @@ class _PaintBounds {
18321832
}
18331833

18341834
if (_clipRectInitialized) {
1835-
if (transformedPointLeft > _currentClipRight) {
1835+
if (transformedPointLeft >= _currentClipRight) {
18361836
command.isClippedOut = true;
18371837
return;
18381838
}
1839-
if (transformedPointRight < _currentClipLeft) {
1839+
if (transformedPointRight <= _currentClipLeft) {
18401840
command.isClippedOut = true;
18411841
return;
18421842
}
1843-
if (transformedPointTop > _currentClipBottom) {
1843+
if (transformedPointTop >= _currentClipBottom) {
18441844
command.isClippedOut = true;
18451845
return;
18461846
}
1847-
if (transformedPointBottom < _currentClipTop) {
1847+
if (transformedPointBottom <= _currentClipTop) {
18481848
command.isClippedOut = true;
18491849
return;
18501850
}

lib/web_ui/test/html/clip_op_golden_test.dart

Lines changed: 52 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,29 +6,30 @@ import 'package:test/bootstrap/browser.dart';
66
import 'package:test/test.dart';
77
import 'package:ui/src/engine.dart';
88
import 'package:ui/ui.dart';
9+
10+
import 'paragraph/helper.dart';
911
import 'screenshot.dart';
1012

1113
void main() {
1214
internalBootstrapBrowserTest(() => testMain);
1315
}
1416

1517
Future<void> testMain() async {
16-
setUp(() async {
17-
debugEmulateFlutterTesterEnvironment = true;
18-
});
18+
setUpStableTestFonts();
1919

2020
/// Regression test for https://github.com/flutter/flutter/issues/64734.
2121
test('Clips using difference', () async {
22+
const Offset shift = Offset(8, 8);
2223
const Rect region = Rect.fromLTRB(0, 0, 400, 300);
2324
final RecordingCanvas canvas = RecordingCanvas(region);
24-
const Rect titleRect = Rect.fromLTWH(20, 0, 50, 20);
25+
final Rect titleRect = const Rect.fromLTWH(20, 0, 50, 20).shift(shift);
2526
final SurfacePaint paint = SurfacePaint()
2627
..style = PaintingStyle.stroke
2728
..color = const Color(0xff000000)
2829
..strokeWidth = 1;
2930
canvas.save();
3031
try {
31-
final Rect borderRect = Rect.fromLTRB(0, 10, region.width, region.height);
32+
final Rect borderRect = Rect.fromLTRB(0, 10, region.width, region.height).shift(shift);
3233
canvas.clipRect(titleRect, ClipOp.difference);
3334
canvas.drawRect(borderRect, paint);
3435
} finally {
@@ -38,4 +39,50 @@ Future<void> testMain() async {
3839
await canvasScreenshot(canvas, 'clip_op_difference',
3940
region: const Rect.fromLTRB(0, 0, 420, 360));
4041
});
42+
43+
/// Regression test for https://github.com/flutter/flutter/issues/86345
44+
test('Clips with zero width or height', () async {
45+
const Rect region = Rect.fromLTRB(0, 0, 400, 300);
46+
final RecordingCanvas canvas = RecordingCanvas(region);
47+
48+
final SurfacePaint paint = SurfacePaint()
49+
..style = PaintingStyle.fill
50+
..color = const Color(0xff00ff00);
51+
final SurfacePaint borderPaint = SurfacePaint()
52+
..style = PaintingStyle.stroke
53+
..color = const Color(0xffff0000)
54+
..strokeWidth = 1;
55+
56+
for (int i = 0; i < 3; i++) {
57+
for (int j = 0; j < 3; j++) {
58+
final double x = 10 + i * 70;
59+
final double y = 10 + j * 70;
60+
canvas.save();
61+
// Clip.
62+
canvas.clipRect(
63+
Rect.fromLTWH(x, y, i * 25, j * 25),
64+
ClipOp.intersect,
65+
);
66+
// Draw the blue (clipped) rect.
67+
canvas.drawRect(
68+
Rect.fromLTWH(x, y, 50, 50),
69+
paint,
70+
);
71+
final Paragraph p = plain(
72+
EngineParagraphStyle(fontFamily: 'Roboto', fontSize: 34),
73+
'23',
74+
textStyle: EngineTextStyle.only(color: const Color(0xff0000ff)),
75+
);
76+
p.layout(const ParagraphConstraints(width: double.infinity));
77+
canvas.drawParagraph(p, Offset(x, y));
78+
canvas.restore();
79+
// Draw the red border.
80+
canvas.drawRect(
81+
Rect.fromLTWH(x, y, 50, 50),
82+
borderPaint,
83+
);
84+
}
85+
}
86+
await canvasScreenshot(canvas, 'clip_zero_width_height', region: region);
87+
});
4188
}

0 commit comments

Comments
 (0)