提交 3fe1c0b3 编写于 作者: H Hixie

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
上级 81b8512b
......@@ -14,6 +14,13 @@ class RenderBlock extends RenderBox with ContainerRenderNodeMixin<RenderBox, Blo
// uses the maximum width provided by the parent
// sizes itself to the height of its child stack
RenderBlock({
List<RenderBox> children
}) {
if (children != null)
children.forEach((child) { add(child); });
}
void setParentData(RenderBox child) {
if (child.parentData is! BlockParentData)
child.parentData = new BlockParentData();
......
......@@ -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<RenderBox> {
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;
......
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
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);
});
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册