Unverified Commit 0b3f2f61 authored by Tom Robinson's avatar Tom Robinson Committed by GitHub

Change RenderObject.getTransformTo to include ancestor. (#37652)



getTransformTo now includes ancestor in the transform it returns, except
for if ancestor is the root view, ensuring that the transform remains in
logical pixel space.
parent 1df165ea
......@@ -1002,7 +1002,7 @@ class RenderListWheelViewport
final ListWheelParentData parentData = child.parentData;
final double targetOffset = parentData.offset.dy; // the so-called "centerPosition"
final Matrix4 transform = target.getTransformTo(this);
final Matrix4 transform = target.getTransformTo(child);
final Rect bounds = MatrixUtils.transformRect(transform, rect);
final Rect targetRect = bounds.translate(0.0, (size.height - itemExtent) / 2);
......
......@@ -2171,6 +2171,7 @@ abstract class RenderObject extends AbstractNode with DiagnosticableTreeMixin im
/// logical pixels. To get physical pixels, use [applyPaintTransform] from the
/// [RenderView] to further transform the coordinate.
Matrix4 getTransformTo(RenderObject ancestor) {
final bool ancestorSpecified = ancestor != null;
assert(attached);
if (ancestor == null) {
final AbstractNode rootNode = owner.rootNode;
......@@ -2182,6 +2183,8 @@ abstract class RenderObject extends AbstractNode with DiagnosticableTreeMixin im
assert(renderer != null); // Failed to find ancestor in parent chain.
renderers.add(renderer);
}
if (ancestorSpecified)
renderers.add(ancestor);
final Matrix4 transform = Matrix4.identity();
for (int index = renderers.length - 1; index > 0; index -= 1) {
renderers[index].applyPaintTransform(renderers[index - 1], transform);
......
......@@ -576,7 +576,7 @@ class _RenderSingleChildViewport extends RenderBox with RenderObjectWithChildMix
return RevealedOffset(offset: offset.pixels, rect: rect);
final RenderBox targetBox = target;
final Matrix4 transform = targetBox.getTransformTo(this);
final Matrix4 transform = targetBox.getTransformTo(child);
final Rect bounds = MatrixUtils.transformRect(transform, rect);
final Size contentSize = child.size;
......
......@@ -995,6 +995,17 @@ void main() {
);
}
});
test('localToGlobal with ancestor', () {
final RenderConstrainedBox innerConstrained = RenderConstrainedBox(additionalConstraints: const BoxConstraints.tightFor(width: 50, height: 50));
final RenderPositionedBox innerCenter = RenderPositionedBox(alignment: Alignment.center, child: innerConstrained);
final RenderConstrainedBox outerConstrained = RenderConstrainedBox(additionalConstraints: const BoxConstraints.tightFor(width: 100, height: 100), child: innerCenter);
final RenderPositionedBox outerCentered = RenderPositionedBox(alignment: Alignment.center, child: outerConstrained);
layout(outerCentered);
expect(innerConstrained.localToGlobal(Offset.zero, ancestor: outerConstrained).dy, 25.0);
});
});
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment