提交 a22064a7 编写于 作者: H Hixie

Remove RenderSizedBox.

Make old users of RenderSizedBox use RenderConstrainedBox.
Change the semantics of BoxDecoration.apply* to actually apply the provided constraints to the current constraints, rather than the previous behaviour of merging them neutrally.

R=abarth@chromium.org

Review URL: https://codereview.chromium.org/1189603003.
上级 9bf2fe7f
......@@ -16,8 +16,8 @@ void main() {
var root = new RenderBlock(children: [
new RenderPadding(
padding: new EdgeDims.all(10.0),
child: new RenderSizedBox(
desiredSize: new sky.Size.fromHeight(100.0),
child: new RenderConstrainedBox(
additionalConstraints: new BoxConstraints.tightFor(height: 100.0),
child: new RenderDecoratedBox(
decoration: new BoxDecoration(
backgroundColor: new sky.Color(0xFFFFFF00)
......@@ -27,8 +27,8 @@ void main() {
),
new RenderPadding(
padding: new EdgeDims.all(10.0),
child: new RenderSizedBox(
desiredSize: new sky.Size.fromHeight(100.0),
child: new RenderConstrainedBox(
additionalConstraints: new BoxConstraints.tightFor(height: 100.0),
child: new RenderDecoratedBox(
decoration: new BoxDecoration(
border: new Border(
......@@ -44,8 +44,8 @@ void main() {
),
new RenderPadding(
padding: new EdgeDims.all(10.0),
child: new RenderSizedBox(
desiredSize: new sky.Size.fromHeight(100.0),
child: new RenderConstrainedBox(
additionalConstraints: new BoxConstraints.tightFor(height: 100.0),
child: new RenderDecoratedBox(
decoration: new BoxDecoration(
backgroundColor: new sky.Color(0xFFFFFF00)
......@@ -55,8 +55,8 @@ void main() {
),
new RenderPadding(
padding: new EdgeDims.all(10.0),
child: new RenderSizedBox(
desiredSize: new sky.Size.fromHeight(100.0),
child: new RenderConstrainedBox(
additionalConstraints: new BoxConstraints.tightFor(height: 100.0),
child: new RenderDecoratedBox(
decoration: new BoxDecoration(
backgroundColor: new sky.Color(0xFFFFFF00)
......@@ -66,8 +66,8 @@ void main() {
),
new RenderPadding(
padding: new EdgeDims.all(10.0),
child: new RenderSizedBox(
desiredSize: new sky.Size.fromHeight(100.0),
child: new RenderConstrainedBox(
additionalConstraints: new BoxConstraints.tightFor(height: 100.0),
child: new RenderDecoratedBox(
decoration: new BoxDecoration(
backgroundColor: new sky.Color(0xFFFFFF00)
......
......@@ -12,9 +12,12 @@ AppView app;
void main() {
RenderDecoratedBox green = new RenderDecoratedBox(
decoration: new BoxDecoration(backgroundColor: const sky.Color(0xFF00FF00)));
RenderSizedBox box = new RenderSizedBox(
desiredSize: new sky.Size(200.0, 200.0), child: green);
decoration: new BoxDecoration(backgroundColor: const sky.Color(0xFF00FF00))
);
RenderConstrainedBox box = new RenderConstrainedBox(
additionalConstraints: new BoxConstraints.tight(const Size(200.0, 200.0)),
child: green
);
Matrix4 transform = new Matrix4.identity();
RenderTransform spin = new RenderTransform(
......
......@@ -72,6 +72,14 @@ class BoxConstraints {
minHeight = size.height,
maxHeight = size.height;
BoxConstraints.tightFor({
double width,
double height
}): minWidth = width != null ? width : 0.0,
maxWidth = width != null ? width : double.INFINITY,
minHeight = height != null ? height : 0.0,
maxHeight = height != null ? height : double.INFINITY;
BoxConstraints.loose(Size size)
: minWidth = 0.0,
maxWidth = size.width,
......@@ -101,29 +109,30 @@ class BoxConstraints {
BoxConstraints apply(BoxConstraints constraints) {
return new BoxConstraints(
minWidth: math.max(minWidth, constraints.minWidth),
maxWidth: math.min(maxWidth, constraints.maxWidth),
minHeight: math.max(minHeight, constraints.minHeight),
maxHeight: math.min(maxHeight, constraints.maxHeight));
minWidth: clamp(min: constraints.minWidth, max: constraints.maxWidth, value: minWidth),
maxWidth: clamp(min: constraints.minWidth, max: constraints.maxWidth, value: maxWidth),
minHeight: clamp(min: constraints.minHeight, max: constraints.maxHeight, value: minHeight),
maxHeight: clamp(min: constraints.minHeight, max: constraints.maxHeight, value: maxHeight)
);
}
BoxConstraints applyWidth(double width) {
return new BoxConstraints(minWidth: math.max(minWidth, width),
maxWidth: math.min(maxWidth, width),
return new BoxConstraints(minWidth: math.max(math.min(maxWidth, width), minWidth),
maxWidth: math.max(math.min(maxWidth, width), minWidth),
minHeight: minHeight,
maxHeight: maxHeight);
}
BoxConstraints applyMinWidth(double width) {
return new BoxConstraints(minWidth: math.max(minWidth, width),
maxWidth: maxWidth,
BoxConstraints applyMinWidth(double newMinWidth) {
return new BoxConstraints(minWidth: math.max(minWidth, newMinWidth),
maxWidth: math.max(maxWidth, newMinWidth),
minHeight: minHeight,
maxHeight: maxHeight);
}
BoxConstraints applyMaxWidth(double width) {
BoxConstraints applyMaxWidth(double newMaxWidth) {
return new BoxConstraints(minWidth: minWidth,
maxWidth: math.min(maxWidth, width),
maxWidth: math.min(maxWidth, newMaxWidth),
minHeight: minHeight,
maxHeight: maxHeight);
}
......@@ -131,22 +140,22 @@ class BoxConstraints {
BoxConstraints applyHeight(double height) {
return new BoxConstraints(minWidth: minWidth,
maxWidth: maxWidth,
minHeight: math.max(minHeight, height),
maxHeight: math.min(maxHeight, height));
minHeight: math.max(math.min(maxHeight, height), minHeight),
maxHeight: math.max(math.min(maxHeight, height), minHeight));
}
BoxConstraints applyMinHeight(double height) {
BoxConstraints applyMinHeight(double newMinHeight) {
return new BoxConstraints(minWidth: minWidth,
maxWidth: maxWidth,
minHeight: math.max(minHeight, height),
maxHeight: maxHeight);
minHeight: math.max(minHeight, newMinHeight),
maxHeight: math.max(maxHeight, newMinHeight));
}
BoxConstraints applyMaxHeight(double height) {
BoxConstraints applyMaxHeight(double newMaxHeight) {
return new BoxConstraints(minWidth: minWidth,
maxWidth: maxWidth,
minHeight: minHeight,
maxHeight: math.min(maxHeight, height));
maxHeight: math.min(maxHeight, newMaxHeight));
}
final double minWidth;
......@@ -345,50 +354,6 @@ class RenderProxyBox extends RenderBox with RenderObjectWithChildMixin<RenderBox
}
class RenderSizedBox extends RenderProxyBox {
RenderSizedBox({
RenderBox child,
Size desiredSize: Size.infinite
}) : super(child), _desiredSize = desiredSize {
assert(desiredSize != null);
}
Size _desiredSize;
Size get desiredSize => _desiredSize;
void set desiredSize (Size value) {
assert(value != null);
if (_desiredSize == value)
return;
_desiredSize = value;
markNeedsLayout();
}
double getMinIntrinsicWidth(BoxConstraints constraints) {
return constraints.constrainWidth(_desiredSize.width);
}
double getMaxIntrinsicWidth(BoxConstraints constraints) {
return constraints.constrainWidth(_desiredSize.width);
}
double getMinIntrinsicHeight(BoxConstraints constraints) {
return constraints.constrainHeight(_desiredSize.height);
}
double getMaxIntrinsicHeight(BoxConstraints constraints) {
return constraints.constrainHeight(_desiredSize.height);
}
void performLayout() {
size = constraints.constrain(_desiredSize);
if (child != null)
child.layout(new BoxConstraints.tight(size));
}
String debugDescribeSettings(String prefix) => '${super.debugDescribeSettings(prefix)}${prefix}desiredSize: ${desiredSize}\n';
}
class RenderConstrainedBox extends RenderProxyBox {
RenderConstrainedBox({
RenderBox child,
......@@ -409,34 +374,34 @@ class RenderConstrainedBox extends RenderProxyBox {
double getMinIntrinsicWidth(BoxConstraints constraints) {
if (child != null)
return child.getMinIntrinsicWidth(constraints.apply(_additionalConstraints));
return child.getMinIntrinsicWidth(_additionalConstraints.apply(constraints));
return constraints.constrainWidth(0.0);
}
double getMaxIntrinsicWidth(BoxConstraints constraints) {
if (child != null)
return child.getMaxIntrinsicWidth(constraints.apply(_additionalConstraints));
return child.getMaxIntrinsicWidth(_additionalConstraints.apply(constraints));
return constraints.constrainWidth(0.0);
}
double getMinIntrinsicHeight(BoxConstraints constraints) {
if (child != null)
return child.getMinIntrinsicHeight(constraints.apply(_additionalConstraints));
return child.getMinIntrinsicHeight(_additionalConstraints.apply(constraints));
return constraints.constrainHeight(0.0);
}
double getMaxIntrinsicHeight(BoxConstraints constraints) {
if (child != null)
return child.getMaxIntrinsicHeight(constraints.apply(_additionalConstraints));
return child.getMaxIntrinsicHeight(_additionalConstraints.apply(constraints));
return constraints.constrainHeight(0.0);
}
void performLayout() {
if (child != null) {
child.layout(constraints.apply(_additionalConstraints), parentUsesSize: true);
child.layout(_additionalConstraints.apply(constraints), parentUsesSize: true);
size = child.size;
} else {
performResize();
size = _additionalConstraints.apply(constraints).constrain(Size.zero);
}
}
......
......@@ -250,7 +250,7 @@ abstract class RenderObject extends AbstractNode {
prefix += ' ';
return '${header}\n${debugDescribeSettings(prefix)}${debugDescribeChildren(prefix)}';
}
String debugDescribeSettings(String prefix) => '${prefix}parentData: ${parentData}\n';
String debugDescribeSettings(String prefix) => '${prefix}parentData: ${parentData}\n${prefix}constraints: ${constraints}\n';
String debugDescribeChildren(String prefix) => '';
}
......
......@@ -143,20 +143,31 @@ class Center extends OneChildRenderObjectWrapper {
class SizedBox extends OneChildRenderObjectWrapper {
SizedBox({
double width: double.INFINITY,
double height: double.INFINITY,
this.width,
this.height,
UINode child,
Object key
}) : desiredSize = new Size(width, height), super(child: child, key: key);
}) : super(child: child, key: key);
RenderConstrainedBox get root { RenderConstrainedBox result = super.root; return result; }
final double width;
final double height;
RenderSizedBox get root { RenderSizedBox result = super.root; return result; }
final Size desiredSize;
RenderConstrainedBox createNode() => new RenderConstrainedBox(additionalConstraints: _additionalConstraints());
RenderSizedBox createNode() => new RenderSizedBox(desiredSize: desiredSize);
BoxConstraints _additionalConstraints() {
var result = const BoxConstraints();
if (width != null)
result = result.applyWidth(width);
if (height != null)
result = result.applyHeight(height);
return result;
}
void syncRenderObject(SizedBox old) {
super.syncRenderObject(old);
root.desiredSize = desiredSize;
root.additionalConstraints = _additionalConstraints();
}
}
......@@ -240,7 +251,10 @@ class Container extends Component {
UINode current = child;
if (child == null && width == null && height == null)
current = new SizedBox();
current = new SizedBox(
width: double.INFINITY,
height: double.INFINITY
);
if (padding != null)
current = new Padding(padding: padding, child: current);
......@@ -250,8 +264,8 @@ class Container extends Component {
if (width != null || height != null)
current = new SizedBox(
width: width == null ? double.INFINITY : width,
height: height == null ? double.INFINITY : height,
width: width,
height: height,
child: current
);
......
......@@ -25,7 +25,7 @@ PAINT FOR FRAME #2 ----------------------------------------------
2 | | | | drawRect(Rect.fromLTRB(0.0, 0.0, 800.0, 81.0), Paint(Color(0xff9c27b0)))
2 | | | | paintChild RenderFlex at Point(8.0, 0.0)
2 | | | | | TestDisplayList() constructor: 800.0 x 600.0
2 | | | | | paintChild RenderSizedBox at Point(0.0, 25.0)
2 | | | | | paintChild RenderConstrainedBox at Point(0.0, 25.0)
2 | | | | | | TestDisplayList() constructor: 800.0 x 600.0
2 | | | | | | paintChild RenderPadding at Point(0.0, 8.0)
2 | | | | | | | TestDisplayList() constructor: 800.0 x 600.0
......
......@@ -14,7 +14,7 @@ void main() {
initUnit();
test("padding", () {
var size = new RenderSizedBox(desiredSize: new sky.Size(double.INFINITY, 100.0));
var size = new RenderConstrainedBox(additionalConstraints: new BoxConstraints().applyHeight(100.0));
var inner = new RenderDecoratedBox(decoration: new BoxDecoration(backgroundColor: const sky.Color(0xFF00FF00)), child: size);
var padding = new RenderPadding(padding: new EdgeDims.all(50.0), child: inner);
var block = new RenderBlock(children: [padding]);
......
......@@ -3,7 +3,7 @@ CONSOLE: TestRenderView enabled
CONSOLE:
PAINT FOR FRAME #1 ----------------------------------------------
1 | TestDisplayList() constructor: 800.0 x 600.0
1 | paintChild RenderSizedBox at Point(0.0, 0.0)
1 | paintChild RenderDecoratedBox at Point(0.0, 0.0)
1 | | TestDisplayList() constructor: 800.0 x 600.0
1 | | drawRect(Rect.fromLTRB(0.0, 0.0, 800.0, 600.0), Paint(Color(0xff00ff00)))
------------------------------------------------------------------------
......
......@@ -15,10 +15,8 @@ void main() {
initUnit();
test("should size to render view", () {
RenderSizedBox root = new RenderSizedBox(
child: new RenderDecoratedBox(
decoration: new BoxDecoration(backgroundColor: const sky.Color(0xFF00FF00))
)
RenderBox root = new RenderDecoratedBox(
decoration: new BoxDecoration(backgroundColor: const sky.Color(0xFF00FF00))
);
new TestRenderView(root);
expect(root.size.width, equals(sky.view.width));
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册