This repository was archived by the owner on Feb 25, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 6k
[web] Fix some clip and stroke calculations #36801
Merged
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
3f7ec92
[web] Fix some clip and stroke calculations
mdebbar 4f6bc29
golden tests
mdebbar ffbfa00
remove unnecessary math.min() calls
mdebbar 0f166d3
Merge branch 'main' into fix_stroke
mdebbar 8d63393
fix framework test
mdebbar 5d9b55e
unit tests for adjustRectForDom
mdebbar 366907c
Merge branch 'main' into fix_stroke
mdebbar File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,77 @@ | ||
| // Copyright 2013 The Flutter Authors. All rights reserved. | ||
| // Use of this source code is governed by a BSD-style license that can be | ||
| // found in the LICENSE file. | ||
|
|
||
| import 'package:test/bootstrap/browser.dart'; | ||
| import 'package:test/test.dart'; | ||
| import 'package:ui/src/engine.dart'; | ||
| import 'package:ui/ui.dart'; | ||
|
|
||
| void main() { | ||
| internalBootstrapBrowserTest(() => testMain); | ||
| } | ||
|
|
||
| Future<void> testMain() async { | ||
| group('$adjustRectForDom', () { | ||
|
|
||
| test('does not change rect when not necessary', () async { | ||
| const Rect rect = Rect.fromLTWH(10, 20, 140, 160); | ||
| expect( | ||
| adjustRectForDom(rect, SurfacePaintData()..style=PaintingStyle.fill), | ||
| rect, | ||
| ); | ||
| expect( | ||
| adjustRectForDom(rect, SurfacePaintData()..style=PaintingStyle.stroke..strokeWidth=0), | ||
| rect, | ||
| ); | ||
| }); | ||
|
|
||
| test('takes stroke width into consideration', () async { | ||
| const Rect rect = Rect.fromLTWH(10, 20, 140, 160); | ||
| expect( | ||
| adjustRectForDom(rect, SurfacePaintData()..style=PaintingStyle.stroke..strokeWidth=1), | ||
| const Rect.fromLTWH(9.5, 19.5, 139, 159), | ||
| ); | ||
| expect( | ||
| adjustRectForDom(rect, SurfacePaintData()..style=PaintingStyle.stroke..strokeWidth=10), | ||
| const Rect.fromLTWH(5, 15, 130, 150), | ||
| ); | ||
| expect( | ||
| adjustRectForDom(rect, SurfacePaintData()..style=PaintingStyle.stroke..strokeWidth=15), | ||
| const Rect.fromLTWH(2.5, 12.5, 125, 145), | ||
| ); | ||
| }); | ||
|
|
||
| test('flips rect when necessary', () { | ||
| Rect rect = const Rect.fromLTWH(100, 200, -40, -60); | ||
| expect( | ||
| adjustRectForDom(rect, SurfacePaintData()..style=PaintingStyle.fill), | ||
| const Rect.fromLTWH(60, 140, 40, 60), | ||
| ); | ||
|
|
||
| rect = const Rect.fromLTWH(100, 200, 40, -60); | ||
| expect( | ||
| adjustRectForDom(rect, SurfacePaintData()..style=PaintingStyle.fill), | ||
| const Rect.fromLTWH(100, 140, 40, 60), | ||
| ); | ||
|
|
||
| rect = const Rect.fromLTWH(100, 200, -40, 60); | ||
| expect( | ||
| adjustRectForDom(rect, SurfacePaintData()..style=PaintingStyle.fill), | ||
| const Rect.fromLTWH(60, 200, 40, 60), | ||
| ); | ||
| }); | ||
|
|
||
| test('handles stroke width greater than width or height', () { | ||
| const Rect rect = Rect.fromLTWH(100, 200, 20, 70); | ||
| expect( | ||
| adjustRectForDom(rect, SurfacePaintData()..style=PaintingStyle.stroke..strokeWidth=50), | ||
| const Rect.fromLTWH(75, 175, 0, 20), | ||
| ); | ||
| expect( | ||
| adjustRectForDom(rect, SurfacePaintData()..style=PaintingStyle.stroke..strokeWidth=80), | ||
| const Rect.fromLTWH(60, 160, 0, 0), | ||
| ); | ||
| }); | ||
| }); | ||
| } |
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could we remove both of the
ifblocks below, if we did the following ahead of time?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unfortunately, we can't.
Stroke-related adjustments aren't the only ones needed. We need to also adjust
leftandtopto avoid flipped rectangles.E.g.
Rect.fromLTRB(200, 200, 100, 100)is completely fine in Flutter, but the DOM doesn't like it. If you dorect.widthon a flipped rectangle, you get a negative value. Setting a negative width/height on a DOM element is equivalent to zero.buildDrawRectElementand various draw operations used to handle it. See this:engine/lib/web_ui/lib/src/engine/html/dom_canvas.dart
Lines 175 to 178 in 2ced979
and:
engine/lib/web_ui/lib/src/engine/html/bitmap_canvas.dart
Lines 445 to 449 in 2ced979
All of that can go away now because rects produced by the new
adjustRectForDomare never flipped.