diff --git a/webf/lib/src/rendering/box_model.dart b/webf/lib/src/rendering/box_model.dart index 72ef441aca..4aa095f9b7 100644 --- a/webf/lib/src/rendering/box_model.dart +++ b/webf/lib/src/rendering/box_model.dart @@ -37,13 +37,14 @@ class RenderLayoutParentData extends ContainerBoxParentData { // // ReturgetLayoutTransformTolocal layout coordinate system to the // coordinate system of `ancestor`. -Matrix4 getLayoutTransformTo(RenderObject current, RenderObject ancestor, {bool excludeScrollOffset = false}) { +Offset getLayoutTransformTo(RenderObject current, RenderObject ancestor, {bool excludeScrollOffset = false}) { final List renderers = []; for (RenderObject renderer = current; renderer != ancestor; renderer = renderer.parent!) { renderers.add(renderer); assert(renderer.parent != null); } renderers.add(ancestor); + Offset offset = Offset.zero; final Matrix4 transform = Matrix4.identity(); for (int index = renderers.length - 1; index > 0; index -= 1) { @@ -51,13 +52,16 @@ Matrix4 getLayoutTransformTo(RenderObject current, RenderObject ancestor, {bool RenderObject childRenderer = renderers[index - 1]; // Apply the layout transform for renderBoxModel and fallback to paint transform for other renderObject type. if (parentRenderer is RenderBoxModel) { - parentRenderer.applyLayoutTransform(childRenderer, transform, excludeScrollOffset); - } else { - parentRenderer.applyPaintTransform(childRenderer, transform); + offset += parentRenderer.obtainLayoutTransform(childRenderer, excludeScrollOffset); + } else if (parentRenderer is RenderBox) { + assert(childRenderer.parent == parentRenderer); + if (childRenderer.parentData is BoxParentData) { + offset += (childRenderer.parentData as BoxParentData).offset; + } } } - return transform; + return offset; } /// Modified from Flutter rendering/box.dart. @@ -1159,6 +1163,17 @@ class RenderBoxModel extends RenderBox transform.translate(offset.dx, offset.dy); } + Offset obtainLayoutTransform(RenderObject child, bool excludeScrollOffset) { + assert(child.parent == this); + assert(child.parentData is BoxParentData); + final BoxParentData childParentData = child.parentData! as BoxParentData; + Offset offset = childParentData.offset; + if (excludeScrollOffset) { + offset -= Offset(scrollLeft, scrollTop); + } + return offset; + } + // The max scrollable size. Size _maxScrollableSize = Size.zero; @@ -1355,9 +1370,7 @@ class RenderBoxModel extends RenderBox double ancestorBorderLeft = ancestor.renderStyle.borderLeftWidth?.computedValue ?? 0; Offset ancestorBorderWidth = Offset(ancestorBorderLeft, ancestorBorderTop); - return MatrixUtils.transformPoint( - getLayoutTransformTo(this, ancestor, excludeScrollOffset: excludeScrollOffset), point) - - ancestorBorderWidth; + return getLayoutTransformTo(this, ancestor, excludeScrollOffset: excludeScrollOffset) + point - ancestorBorderWidth; } bool _hasLocalBackgroundImage(CSSRenderStyle renderStyle) { diff --git a/webf/lib/src/rendering/render_position_holder.dart b/webf/lib/src/rendering/render_position_holder.dart index d69d8e8123..f71fe1bd71 100644 --- a/webf/lib/src/rendering/render_position_holder.dart +++ b/webf/lib/src/rendering/render_position_holder.dart @@ -48,8 +48,7 @@ class RenderPositionPlaceholder extends RenderPreferredSize { // Get the layout offset of renderObject to its ancestor which does not include the paint offset // such as scroll or transform. Offset getOffsetToAncestor(Offset point, RenderObject ancestor, {bool excludeScrollOffset = false}) { - return MatrixUtils.transformPoint( - getLayoutTransformTo(this, ancestor, excludeScrollOffset: excludeScrollOffset), point); + return getLayoutTransformTo(this, ancestor, excludeScrollOffset: excludeScrollOffset) + point; } }