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

Commit 9565fa0

Browse files
[skwasm] Combine offset and transform properly.
1 parent 2b38f76 commit 9565fa0

File tree

3 files changed

+35
-23
lines changed

3 files changed

+35
-23
lines changed

lib/web_ui/lib/src/engine/layers.dart

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -500,15 +500,15 @@ class PlatformViewPosition {
500500

501501
// Otherwise, at least one of the positions involves a matrix transform.
502502
final Matrix4 newTransform;
503-
if (outerOffset != null) {
504-
newTransform = Matrix4.translationValues(outerOffset.dx, outerOffset.dy, 0);
503+
if (innerOffset != null) {
504+
newTransform = Matrix4.translationValues(innerOffset.dx, innerOffset.dy, 0);
505505
} else {
506-
newTransform = outer.transform!.clone();
506+
newTransform = inner.transform!.clone();
507507
}
508-
if (innerOffset != null) {
509-
newTransform.translate(innerOffset.dx, innerOffset.dy);
508+
if (outerOffset != null) {
509+
newTransform.translate(outerOffset.dx, outerOffset.dy);
510510
} else {
511-
newTransform.multiply(inner.transform!);
511+
newTransform.multiply(outer.transform!);
512512
}
513513
return PlatformViewPosition.transform(newTransform);
514514
}

lib/web_ui/lib/src/engine/scene_view.dart

Lines changed: 24 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -308,26 +308,34 @@ final class PlatformViewContainer extends SliceContainer {
308308
assert(_bounds != null);
309309
if (_dirty) {
310310
final DomCSSStyleDeclaration style = container.style;
311-
final double devicePixelRatio = EngineFlutterDisplay.instance.devicePixelRatio;
312-
final double logicalWidth = _bounds!.width / devicePixelRatio;
313-
final double logicalHeight = _bounds!.height / devicePixelRatio;
314-
style.width = '${logicalWidth}px';
315-
style.height = '${logicalHeight}px';
316311
style.position = 'absolute';
317-
318-
final PlatformViewPosition position = PlatformViewPosition.combine(
319-
_styling!.position,
320-
PlatformViewPosition.offset(_bounds!.topLeft),
321-
);
312+
final double devicePixelRatio = EngineFlutterDisplay.instance.devicePixelRatio;
313+
final PlatformViewPosition position = _styling!.position;
322314

323315
final ui.Offset offset = position.offset ?? ui.Offset.zero;
324-
final double logicalLeft = offset.dx / devicePixelRatio;
325-
final double logicalTop = offset.dy / devicePixelRatio;
326-
style.left = '${logicalLeft}px';
327-
style.top = '${logicalTop}px';
328-
329316
final Matrix4? transform = position.transform;
330-
style.transform = transform != null ? float64ListToCssTransform3d(transform.storage) : '';
317+
if (transform == null) {
318+
final ui.Offset newOffset = offset + _bounds!.topLeft;
319+
final double logicalWidth = _bounds!.width / devicePixelRatio;
320+
final double logicalHeight = _bounds!.height / devicePixelRatio;
321+
final double logicalLeft = newOffset.dx / devicePixelRatio;
322+
final double logicalTop = newOffset.dy / devicePixelRatio;
323+
style.width = '${logicalWidth}px';
324+
style.height = '${logicalHeight}px';
325+
style.left = '${logicalLeft}px';
326+
style.top = '${logicalTop}px';
327+
style.transform = '';
328+
} else {
329+
style.width = '${_bounds!.width}px';
330+
style.height = '${_bounds!.height}px';
331+
style.left = '0px';
332+
style.top = '0px';
333+
334+
final Matrix4 newTransform = transform.clone();
335+
newTransform.translate(_bounds!.left, _bounds!.top);
336+
newTransform.scale(1 / devicePixelRatio);
337+
style.transform = float64ListToCssTransform3d(newTransform.storage);
338+
}
331339
style.opacity = _styling!.opacity != 1.0 ? '${_styling!.opacity}' : '';
332340
// TODO(jacksongardner): Implement clip styling for platform views
333341

lib/web_ui/test/ui/platform_view_test.dart

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,10 +120,14 @@ Future<void> testMain() async {
120120
sb.pushOffset(0, 0);
121121
sb.addPicture(const ui.Offset(100, 100), recorder.endRecording());
122122

123+
// Nest offsets both before and after the transform to make sure that they
124+
// are applied properly.
125+
sb.pushOffset(50, 50);
123126
sb.pushTransform(Matrix4.rotationZ(0.1).toFloat64());
127+
sb.pushOffset(25, 25);
124128
sb.addPlatformView(
125129
1,
126-
offset: const ui.Offset(125, 125),
130+
offset: const ui.Offset(50, 50),
127131
width: 50,
128132
height: 50,
129133
);

0 commit comments

Comments
 (0)