From 3fe1c0b38cc8e3461edff5d7564264dcb051173a Mon Sep 17 00:00:00 2001 From: Hixie Date: Wed, 3 Jun 2015 10:25:05 -0700 Subject: [PATCH] Fix logic in RenderPadding. Previously, we were not adjusting the minimum width, so we ended up offsetting the child but not shrinking it, when the parent expected the child to be exactly fit to its dimensions. R=abarth@chromium.org Review URL: https://codereview.chromium.org/1155303005 --- sdk/lib/framework/rendering/block.dart | 7 +++++++ sdk/lib/framework/rendering/box.dart | 16 ++++++++++------ tests/raw/box_layout-expected.txt | 19 +++++++++++++++++++ tests/raw/box_layout.dart | 24 ++++++++++++++++++++++++ 4 files changed, 60 insertions(+), 6 deletions(-) create mode 100644 tests/raw/box_layout-expected.txt create mode 100644 tests/raw/box_layout.dart diff --git a/sdk/lib/framework/rendering/block.dart b/sdk/lib/framework/rendering/block.dart index 8bc53939b5..942b0de0d3 100644 --- a/sdk/lib/framework/rendering/block.dart +++ b/sdk/lib/framework/rendering/block.dart @@ -14,6 +14,13 @@ class RenderBlock extends RenderBox with ContainerRenderNodeMixin children + }) { + if (children != null) + children.forEach((child) { add(child); }); + } + void setParentData(RenderBox child) { if (child.parentData is! BlockParentData) child.parentData = new BlockParentData(); diff --git a/sdk/lib/framework/rendering/box.dart b/sdk/lib/framework/rendering/box.dart index 76002fc56f..100219477b 100644 --- a/sdk/lib/framework/rendering/box.dart +++ b/sdk/lib/framework/rendering/box.dart @@ -2,6 +2,7 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. +import 'dart:math' as math; import 'dart:sky' as sky; import 'dart:typed_data'; import 'node.dart'; @@ -51,11 +52,13 @@ class BoxConstraints { BoxConstraints deflate(EdgeDims edges) { assert(edges != null); + double horizontal = edges.left + edges.right; + double vertical = edges.top + edges.bottom; return new BoxConstraints( - minWidth: minWidth, - maxWidth: maxWidth - (edges.left + edges.right), - minHeight: minHeight, - maxHeight: maxHeight - (edges.top + edges.bottom) + minWidth: math.min(0.0, minWidth - horizontal), + maxWidth: maxWidth - horizontal, + minHeight: math.min(0.0, minHeight - vertical), + maxHeight: maxHeight - vertical ); } @@ -182,7 +185,8 @@ class RenderSizedBox extends RenderProxyBox { void performLayout() { size = constraints.constrain(_desiredSize); - child.layout(new BoxConstraints.tight(size)); + if (child != null) + child.layout(new BoxConstraints.tight(size)); } } @@ -429,7 +433,7 @@ class RenderView extends RenderNode with RenderNodeWithChildMixin { void paintFrame() { RenderNode.debugDoingPaint = true; - var canvas = new RenderNodeDisplayList(sky.view.width, sky.view.height); + RenderNodeDisplayList canvas = new RenderNodeDisplayList(sky.view.width, sky.view.height); paint(canvas); sky.view.picture = canvas.endRecording(); RenderNode.debugDoingPaint = false; diff --git a/tests/raw/box_layout-expected.txt b/tests/raw/box_layout-expected.txt new file mode 100644 index 0000000000..511893d78a --- /dev/null +++ b/tests/raw/box_layout-expected.txt @@ -0,0 +1,19 @@ +CONSOLE: unittest-suite-wait-for-done +CONSOLE: TestView enabled +CONSOLE: +PAINT FOR FRAME #1 ---------------------------------------------- +1 | TestDisplayList() constructor: 800.0 x 600.0 +1 | paintChild at 0.0,0.0 +1 | | TestDisplayList() constructor: 800.0 x 600.0 +1 | | drawRect(0.0:0.0:600.0:800.0, Paint(0xff0000ff)) +1 | | paintChild at 0.0,0.0 +1 | | | TestDisplayList() constructor: 800.0 x 600.0 +1 | | | paintChild at 50.0,50.0 +1 | | | | TestDisplayList() constructor: 800.0 x 600.0 +1 | | | | drawRect(0.0:0.0:100.0:700.0, Paint(0xff00ff00)) +------------------------------------------------------------------------ +CONSOLE: PASS: padding +CONSOLE: +CONSOLE: All 1 tests passed. +CONSOLE: unittest-suite-success +DONE diff --git a/tests/raw/box_layout.dart b/tests/raw/box_layout.dart new file mode 100644 index 0000000000..7e686632b2 --- /dev/null +++ b/tests/raw/box_layout.dart @@ -0,0 +1,24 @@ +import '../resources/third_party/unittest/unittest.dart'; +import '../resources/unit.dart'; +import '../resources/display_list.dart'; +import 'dart:math' as math; +import 'dart:sky' as sky; +import 'package:sky/framework/app.dart'; +import 'package:sky/framework/rendering/box.dart'; +import 'package:sky/framework/rendering/block.dart'; +import 'package:sky/framework/rendering/node.dart'; + +TestApp app; + +void main() { + initUnit(); + + test("padding", () { + var size = new RenderSizedBox(desiredSize: new sky.Size(double.INFINITY, 100.0)); + var inner = new RenderDecoratedBox(decoration: new BoxDecoration(backgroundColor: 0xFF00FF00), child: size); + var padding = new RenderPadding(padding: new EdgeDims.all(50.0), child: inner); + var block = new RenderBlock(children: [padding]); + var outer = new RenderDecoratedBox(decoration: new BoxDecoration(backgroundColor: 0xFF0000FF), child: block); + app = new TestApp(outer); + }); +} -- GitLab