Skip to content

Commit 360a16a

Browse files
author
Harry Terkelsen
authored
CanvasKit fix embedded view clipping (flutter#22937)
1 parent 46d7bf9 commit 360a16a

File tree

2 files changed

+48
-9
lines changed

2 files changed

+48
-9
lines changed

lib/web_ui/lib/src/engine/canvaskit/embedded_views.dart

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -262,10 +262,12 @@ class HtmlViewEmbedder {
262262
html.Element pathDefs =
263263
_svgPathDefs!.querySelector('#sk_path_defs')!;
264264
_clipPathCount += 1;
265-
html.Element newClipPath =
266-
html.Element.html('<clipPath id="svgClip$_clipPathCount">'
267-
'<path d="${path.toSvgString()}">'
268-
'</path></clipPath>');
265+
html.Node newClipPath = html.DocumentFragment.svg(
266+
'<clipPath id="svgClip$_clipPathCount">'
267+
'<path d="${path.toSvgString()}">'
268+
'</path></clipPath>',
269+
treeSanitizer: _NullTreeSanitizer(),
270+
);
269271
pathDefs.append(newClipPath);
270272
clipView.style.clipPath = 'url(#svgClip$_clipPathCount)';
271273
} else if (mutator.path != null) {
@@ -274,10 +276,12 @@ class HtmlViewEmbedder {
274276
html.Element pathDefs =
275277
_svgPathDefs!.querySelector('#sk_path_defs')!;
276278
_clipPathCount += 1;
277-
html.Element newClipPath =
278-
html.Element.html('<clipPath id="svgClip$_clipPathCount">'
279-
'<path d="${path.toSvgString()}">'
280-
'</path></clipPath>');
279+
html.Node newClipPath = html.DocumentFragment.svg(
280+
'<clipPath id="svgClip$_clipPathCount">'
281+
'<path d="${path.toSvgString()}">'
282+
'</path></clipPath>',
283+
treeSanitizer: _NullTreeSanitizer(),
284+
);
281285
pathDefs.append(newClipPath);
282286
clipView.style.clipPath = 'url(#svgClip$_clipPathCount)';
283287
}
@@ -324,7 +328,7 @@ class HtmlViewEmbedder {
324328
return;
325329
}
326330
_svgPathDefs = html.Element.html(
327-
'$kSvgResourceHeader><defs id="sk_path_defs"></defs></svg>',
331+
'$kSvgResourceHeader<defs id="sk_path_defs"></defs></svg>',
328332
treeSanitizer: _NullTreeSanitizer(),
329333
);
330334
skiaSceneHost!.append(_svgPathDefs!);

lib/web_ui/test/canvaskit/embedded_views_test.dart

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,41 @@ void testMain() {
4949
);
5050
});
5151

52+
test('clips platform views with RRects', () async {
53+
ui.platformViewRegistry.registerViewFactory(
54+
'test-platform-view',
55+
(viewId) => html.DivElement()..id = 'view-0',
56+
);
57+
await _createPlatformView(0, 'test-platform-view');
58+
59+
final EnginePlatformDispatcher dispatcher =
60+
ui.window.platformDispatcher as EnginePlatformDispatcher;
61+
final LayerSceneBuilder sb = LayerSceneBuilder();
62+
sb.pushOffset(0, 0);
63+
sb.pushClipRRect(ui.RRect.fromLTRBR(0, 0, 10, 10, ui.Radius.circular(3)));
64+
sb.addPlatformView(0, width: 10, height: 10);
65+
dispatcher.rasterizer!.draw(sb.build().layerTree);
66+
expect(
67+
domRenderer.sceneElement!.querySelectorAll('#sk_path_defs').single,
68+
isNotNull,
69+
);
70+
expect(
71+
domRenderer.sceneElement!
72+
.querySelectorAll('#sk_path_defs')
73+
.single
74+
.querySelectorAll('clipPath')
75+
.single,
76+
isNotNull,
77+
);
78+
expect(
79+
domRenderer.sceneElement!
80+
.querySelectorAll('flt-clip')
81+
.single
82+
.style
83+
.clipPath,
84+
'url("#svgClip1")',
85+
);
86+
});
5287
test('correctly transforms platform views', () async {
5388
ui.platformViewRegistry.registerViewFactory(
5489
'test-platform-view',

0 commit comments

Comments
 (0)