Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 13 additions & 9 deletions lib/web_ui/lib/src/engine/canvaskit/embedded_views.dart
Original file line number Diff line number Diff line change
Expand Up @@ -262,10 +262,12 @@ class HtmlViewEmbedder {
html.Element pathDefs =
_svgPathDefs!.querySelector('#sk_path_defs')!;
_clipPathCount += 1;
html.Element newClipPath =
html.Element.html('<clipPath id="svgClip$_clipPathCount">'
'<path d="${path.toSvgString()}">'
'</path></clipPath>');
html.Node newClipPath = html.DocumentFragment.svg(
'<clipPath id="svgClip$_clipPathCount">'
'<path d="${path.toSvgString()}">'
'</path></clipPath>',
treeSanitizer: _NullTreeSanitizer(),
);
pathDefs.append(newClipPath);
clipView.style.clipPath = 'url(#svgClip$_clipPathCount)';
} else if (mutator.path != null) {
Expand All @@ -274,10 +276,12 @@ class HtmlViewEmbedder {
html.Element pathDefs =
_svgPathDefs!.querySelector('#sk_path_defs')!;
_clipPathCount += 1;
html.Element newClipPath =
html.Element.html('<clipPath id="svgClip$_clipPathCount">'
'<path d="${path.toSvgString()}">'
'</path></clipPath>');
html.Node newClipPath = html.DocumentFragment.svg(
'<clipPath id="svgClip$_clipPathCount">'
'<path d="${path.toSvgString()}">'
'</path></clipPath>',
treeSanitizer: _NullTreeSanitizer(),
);
pathDefs.append(newClipPath);
clipView.style.clipPath = 'url(#svgClip$_clipPathCount)';
}
Expand Down Expand Up @@ -324,7 +328,7 @@ class HtmlViewEmbedder {
return;
}
_svgPathDefs = html.Element.html(
'$kSvgResourceHeader><defs id="sk_path_defs"></defs></svg>',
'$kSvgResourceHeader<defs id="sk_path_defs"></defs></svg>',
treeSanitizer: _NullTreeSanitizer(),
);
skiaSceneHost!.append(_svgPathDefs!);
Expand Down
35 changes: 35 additions & 0 deletions lib/web_ui/test/canvaskit/embedded_views_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,41 @@ void testMain() {
);
});

test('clips platform views with RRects', () async {
ui.platformViewRegistry.registerViewFactory(
'test-platform-view',
(viewId) => html.DivElement()..id = 'view-0',
);
await _createPlatformView(0, 'test-platform-view');

final EnginePlatformDispatcher dispatcher =
ui.window.platformDispatcher as EnginePlatformDispatcher;
final LayerSceneBuilder sb = LayerSceneBuilder();
sb.pushOffset(0, 0);
sb.pushClipRRect(ui.RRect.fromLTRBR(0, 0, 10, 10, ui.Radius.circular(3)));
sb.addPlatformView(0, width: 10, height: 10);
dispatcher.rasterizer!.draw(sb.build().layerTree);
expect(
domRenderer.sceneElement!.querySelectorAll('#sk_path_defs').single,
isNotNull,
);
expect(
domRenderer.sceneElement!
.querySelectorAll('#sk_path_defs')
.single
.querySelectorAll('clipPath')
.single,
isNotNull,
);
expect(
domRenderer.sceneElement!
.querySelectorAll('flt-clip')
.single
.style
.clipPath,
'url("#svgClip1")',
);
});
test('correctly transforms platform views', () async {
ui.platformViewRegistry.registerViewFactory(
'test-platform-view',
Expand Down