Unverified Commit da105b2b authored by Casey Hillers's avatar Casey Hillers Committed by GitHub

Revert "[framework] inline AbstractNode into RenderObject" (#104257)

parent 52e19ef7
......@@ -1566,7 +1566,9 @@ class _ActionButtonParentDataWidget
parentData.isPressed = isPressed;
// Force a repaint.
renderObject.parent?.markNeedsPaint();
final AbstractNode? targetParent = renderObject.parent;
if (targetParent is RenderObject)
targetParent.markNeedsPaint();
}
}
......
......@@ -4,6 +4,7 @@
import 'dart:math' as math;
import 'package:flutter/foundation.dart';
import 'package:flutter/rendering.dart';
import 'package:flutter/widgets.dart';
......@@ -1085,9 +1086,9 @@ class TableRowInkWell extends InkResponse {
RectCallback getRectCallback(RenderBox referenceBox) {
return () {
RenderObject cell = referenceBox;
RenderObject? table = cell.parent;
AbstractNode? table = cell.parent;
final Matrix4 transform = Matrix4.identity();
while (table != null && table is! RenderTable) {
while (table is RenderObject && table is! RenderTable) {
table.applyPaintTransform(cell, transform);
assert(table == cell.parent);
cell = table;
......
......@@ -683,7 +683,7 @@ abstract class InkFeature {
RenderObject node = referenceBox;
while (node != _controller) {
final RenderObject childNode = node;
node = node.parent!;
node = node.parent! as RenderObject;
if (!node.paintsChild(childNode)) {
// Some node between the reference box and this would skip painting on
// the reference box, so bail out early and avoid unnecessary painting.
......
......@@ -2145,7 +2145,7 @@ abstract class RenderBox extends RenderObject {
assert(!_debugDoingBaseline, 'Please see the documentation for computeDistanceToActualBaseline for the required calling conventions of this method.');
assert(!debugNeedsLayout);
assert(() {
final RenderObject? parent = this.parent;
final RenderObject? parent = this.parent as RenderObject?;
if (owner!.debugDoingLayout)
return (RenderObject.debugActiveLayout == parent) && parent!.debugDoingThisLayout;
if (owner!.debugDoingPaint)
......@@ -2367,7 +2367,7 @@ abstract class RenderBox extends RenderObject {
@override
void markNeedsLayout() {
if (_clearCachedData() && parent != null) {
if (_clearCachedData() && parent is RenderObject) {
markParentNeedsLayout();
return;
}
......
......@@ -1039,7 +1039,7 @@ class RenderListWheelViewport
// `child` will be the last RenderObject before the viewport when walking up from `target`.
RenderObject child = target;
while (child.parent != this)
child = child.parent!;
child = child.parent! as RenderObject;
final ListWheelParentData parentData = child.parentData! as ListWheelParentData;
final double targetOffset = parentData.offset.dy; // the so-called "centerPosition"
......
......@@ -43,7 +43,7 @@ abstract class RenderAbstractViewport extends RenderObject {
while (object != null) {
if (object is RenderAbstractViewport)
return object;
object = object.parent;
object = object.parent as RenderObject?;
}
return null;
}
......@@ -764,7 +764,7 @@ abstract class RenderViewportBase<ParentDataClass extends ContainerParentDataMix
RenderBox? pivot;
bool onlySlivers = target is RenderSliver; // ... between viewport and `target` (`target` included).
while (child.parent != this) {
final RenderObject parent = child.parent!;
final RenderObject parent = child.parent! as RenderObject;
assert(parent != null, '$target must be a descendant of $this');
if (child is RenderBox) {
pivot = child;
......@@ -1214,7 +1214,7 @@ abstract class RenderViewportBase<ParentDataClass extends ContainerParentDataMix
} else {
// `descendant` is between leading and trailing edge and hence already
// fully shown on screen. No action necessary.
final Matrix4 transform = descendant.getTransformTo(viewport.parent);
final Matrix4 transform = descendant.getTransformTo(viewport.parent! as RenderObject);
return MatrixUtils.transformRect(transform, rect ?? descendant.paintBounds);
}
......
......@@ -2169,8 +2169,8 @@ class LayoutId extends ParentDataWidget<MultiChildLayoutParentData> {
final MultiChildLayoutParentData parentData = renderObject.parentData! as MultiChildLayoutParentData;
if (parentData.id != id) {
parentData.id = id;
final RenderObject? targetParent = renderObject.parent;
if (targetParent != null)
final AbstractNode? targetParent = renderObject.parent;
if (targetParent is RenderObject)
targetParent.markNeedsLayout();
}
}
......@@ -4132,8 +4132,8 @@ class Positioned extends ParentDataWidget<StackParentData> {
}
if (needsLayout) {
final RenderObject? targetParent = renderObject.parent;
if (targetParent != null)
final AbstractNode? targetParent = renderObject.parent;
if (targetParent is RenderObject)
targetParent.markNeedsLayout();
}
}
......@@ -4992,8 +4992,8 @@ class Flexible extends ParentDataWidget<FlexParentData> {
}
if (needsLayout) {
final RenderObject? targetParent = renderObject.parent;
if (targetParent != null)
final AbstractNode? targetParent = renderObject.parent;
if (targetParent is RenderObject)
targetParent.markNeedsLayout();
}
}
......
......@@ -1747,8 +1747,8 @@ class KeepAlive extends ParentDataWidget<KeepAliveParentDataMixin> {
final KeepAliveParentDataMixin parentData = renderObject.parentData! as KeepAliveParentDataMixin;
if (parentData.keepAlive != keepAlive) {
parentData.keepAlive = keepAlive;
final RenderObject? targetParent = renderObject.parent;
if (targetParent != null && !keepAlive)
final AbstractNode? targetParent = renderObject.parent;
if (targetParent is RenderObject && !keepAlive)
targetParent.markNeedsLayout(); // No need to redo layout if it became true.
}
}
......
......@@ -433,8 +433,8 @@ class TableCell extends ParentDataWidget<TableCellParentData> {
final TableCellParentData parentData = renderObject.parentData! as TableCellParentData;
if (parentData.verticalAlignment != verticalAlignment) {
parentData.verticalAlignment = verticalAlignment;
final RenderObject? targetParent = renderObject.parent;
if (targetParent != null)
final AbstractNode? targetParent = renderObject.parent;
if (targetParent is RenderObject)
targetParent.markNeedsLayout();
}
}
......
......@@ -552,7 +552,7 @@ class _ScreenshotPaintingContext extends PaintingContext {
}) {
RenderObject repaintBoundary = renderObject;
while (repaintBoundary != null && !repaintBoundary.isRepaintBoundary) {
repaintBoundary = repaintBoundary.parent!;
repaintBoundary = repaintBoundary.parent! as RenderObject;
}
assert(repaintBoundary != null);
final _ScreenshotData data = _ScreenshotData(target: renderObject);
......@@ -1510,7 +1510,7 @@ mixin WidgetInspectorService {
final List<RenderObject> chain = <RenderObject>[];
while (renderObject != null) {
chain.add(renderObject);
renderObject = renderObject.parent;
renderObject = renderObject.parent as RenderObject?;
}
return _followDiagnosticableChain(chain.reversed.toList());
}
......@@ -2565,7 +2565,7 @@ class _RenderInspectorOverlay extends RenderBox {
context.addLayer(_InspectorOverlayLayer(
overlayRect: Rect.fromLTWH(offset.dx, offset.dy, size.width, size.height),
selection: selection,
rootRenderObject: parent != null ? parent! : null,
rootRenderObject: parent is RenderObject ? parent! as RenderObject : null,
));
}
}
......@@ -2841,14 +2841,14 @@ class _InspectorOverlayLayer extends Layer {
/// overlays in the same app (i.e. an storyboard), a selected or candidate
/// render object may not belong to this tree.
bool _isInInspectorRenderObjectTree(RenderObject child) {
RenderObject? current = child.parent;
RenderObject? current = child.parent as RenderObject?;
while (current != null) {
// We found the widget inspector render object.
if (current is RenderStack
&& current.lastChild is _RenderInspectorOverlay) {
return rootRenderObject == current;
}
current = current.parent;
current = current.parent as RenderObject?;
}
return false;
}
......
......@@ -1941,5 +1941,5 @@ Future<void> testGestureTap(WidgetTester tester, Finder tooltip) async {
SemanticsNode findDebugSemantics(RenderObject object) {
if (object.debugSemantics != null)
return object.debugSemantics!;
return findDebugSemantics(object.parent!);
return findDebugSemantics(object.parent! as RenderObject);
}
......@@ -1357,5 +1357,5 @@ void main() {
SemanticsNode findDebugSemantics(RenderObject object) {
if (object.debugSemantics != null)
return object.debugSemantics!;
return findDebugSemantics(object.parent!);
return findDebugSemantics(object.parent! as RenderObject);
}
......@@ -118,7 +118,7 @@ void main() {
expect(parentData!.offset.dy, -(viewHeight / 2.0));
expect(test.calls, 2); // The layout constraints change will clear the cached data.
final RenderObject parent = test.parent!;
final RenderObject parent = test.parent! as RenderObject;
expect(parent.debugNeedsLayout, false);
// Do not forget notify parent dirty after the cached data be cleared by `layout()`
......
......@@ -935,7 +935,7 @@ void main() {
editable.painter = null;
editable.paintCount = 0;
final RenderObject? parent = editable.parent;
final AbstractNode? parent = editable.parent;
if (parent is RenderConstrainedBox)
parent.child = null;
});
......
// Copyright 2014 The Flutter Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
import 'package:flutter/foundation.dart';
import 'package:flutter/rendering.dart';
import 'package:flutter_test/flutter_test.dart';
import 'rendering_tester.dart';
class RealRoot extends AbstractNode {
RealRoot(this.child) {
adoptChild(child);
}
final RenderObject child;
@override
void redepthChildren() {
redepthChild(child);
}
@override
void attach(Object owner) {
super.attach(owner);
child.attach(owner as PipelineOwner);
}
@override
void detach() {
super.detach();
child.detach();
}
@override
PipelineOwner? get owner => super.owner as PipelineOwner?;
void layout() {
child.layout(BoxConstraints.tight(const Size(500.0, 500.0)));
}
}
void main() {
TestRenderingFlutterBinding.ensureInitialized();
test('non-RenderObject roots', () {
RenderPositionedBox child;
final RealRoot root = RealRoot(
child = RenderPositionedBox(
child: RenderSizedBox(const Size(100.0, 100.0)),
),
);
root.attach(PipelineOwner());
child.scheduleInitialLayout();
root.layout();
child.markNeedsLayout();
root.layout();
});
}
......@@ -689,9 +689,9 @@ void main() {
test('Offstage implements paintsChild correctly', () {
final RenderBox box = RenderConstrainedBox(additionalConstraints: const BoxConstraints.tightFor(width: 20));
final RenderProxyBox parent = RenderConstrainedBox(additionalConstraints: const BoxConstraints.tightFor(width: 20));
final RenderBox parent = RenderConstrainedBox(additionalConstraints: const BoxConstraints.tightFor(width: 20));
final RenderOffstage offstage = RenderOffstage(offstage: false, child: box);
parent.child = offstage;
parent.adoptChild(offstage);
expect(offstage.paintsChild(box), true);
......@@ -702,9 +702,9 @@ void main() {
test('Opacity implements paintsChild correctly', () {
final RenderBox box = RenderConstrainedBox(additionalConstraints: const BoxConstraints.tightFor(width: 20));
final RenderProxyBox parent = RenderConstrainedBox(additionalConstraints: const BoxConstraints.tightFor(width: 20));
final RenderBox parent = RenderConstrainedBox(additionalConstraints: const BoxConstraints.tightFor(width: 20));
final RenderOpacity opacity = RenderOpacity(child: box);
parent.child = opacity;
parent.adoptChild(opacity);
expect(opacity.paintsChild(box), true);
......@@ -714,11 +714,11 @@ void main() {
});
test('AnimatedOpacity sets paint matrix to zero when alpha == 0', () {
final RenderProxyBox box = RenderConstrainedBox(additionalConstraints: const BoxConstraints.tightFor(width: 20));
final RenderProxyBox parent = RenderConstrainedBox(additionalConstraints: const BoxConstraints.tightFor(width: 20));
final RenderBox box = RenderConstrainedBox(additionalConstraints: const BoxConstraints.tightFor(width: 20));
final RenderBox parent = RenderConstrainedBox(additionalConstraints: const BoxConstraints.tightFor(width: 20));
final AnimationController opacityAnimation = AnimationController(value: 1, vsync: FakeTickerProvider());
final RenderAnimatedOpacity opacity = RenderAnimatedOpacity(opacity: opacityAnimation, child: box);
parent.child = opacity;
parent.adoptChild(opacity);
// Make it listen to the animation.
opacity.attach(PipelineOwner());
......@@ -732,10 +732,10 @@ void main() {
test('AnimatedOpacity sets paint matrix to zero when alpha == 0 (sliver)', () {
final RenderSliver sliver = RenderSliverToBoxAdapter(child: RenderConstrainedBox(additionalConstraints: const BoxConstraints.tightFor(width: 20)));
final RenderSliverPadding parent = RenderSliverPadding(padding: const EdgeInsets.all(4));
final RenderBox parent = RenderConstrainedBox(additionalConstraints: const BoxConstraints.tightFor(width: 20));
final AnimationController opacityAnimation = AnimationController(value: 1, vsync: FakeTickerProvider());
final RenderSliverAnimatedOpacity opacity = RenderSliverAnimatedOpacity(opacity: opacityAnimation, sliver: sliver);
parent.child = opacity;
parent.adoptChild(opacity);
// Make it listen to the animation.
opacity.attach(PipelineOwner());
......
......@@ -2924,8 +2924,8 @@ Future<void> main() async {
final ScrollController controller = ScrollController();
RenderAnimatedOpacity? findRenderAnimatedOpacity() {
RenderObject? parent = tester.renderObject(find.byType(Placeholder));
while (parent != null && parent is! RenderAnimatedOpacity) {
AbstractNode? parent = tester.renderObject(find.byType(Placeholder));
while (parent is RenderObject && parent is! RenderAnimatedOpacity) {
parent = parent.parent;
}
return parent is RenderAnimatedOpacity ? parent : null;
......
......@@ -308,7 +308,7 @@ mixin CommandHandlerFactory {
SemanticsNode? node;
while (renderObject != null && node == null) {
node = renderObject.debugSemantics;
renderObject = renderObject.parent;
renderObject = renderObject.parent as RenderObject?;
}
if (node == null)
throw StateError('No semantics data found');
......
......@@ -23,7 +23,7 @@ Future<ui.Image> captureImage(Element element) {
assert(element.renderObject != null);
RenderObject renderObject = element.renderObject!;
while (!renderObject.isRepaintBoundary) {
renderObject = renderObject.parent!;
renderObject = renderObject.parent! as RenderObject;
}
assert(!renderObject.debugNeedsPaint);
final OffsetLayer layer = renderObject.debugLayer! as OffsetLayer;
......
......@@ -82,7 +82,7 @@ RenderObject _findRepaintBoundary(Element element) {
assert(element.renderObject != null);
RenderObject renderObject = element.renderObject!;
while (!renderObject.isRepaintBoundary) {
renderObject = renderObject.parent!;
renderObject = renderObject.parent! as RenderObject;
}
return renderObject;
}
......
......@@ -1168,7 +1168,7 @@ abstract class WidgetController {
RenderObject? renderObject = element.findRenderObject();
SemanticsNode? result = renderObject?.debugSemantics;
while (renderObject != null && (result == null || result.isMergedIntoParent)) {
renderObject = renderObject.parent;
renderObject = renderObject.parent as RenderObject?;
result = renderObject?.debugSemantics;
}
if (result == null)
......
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