提交 903ef07a 编写于 作者: A Adam Barth

Split getIntrinsicDimensions into four pieces

This CL splits getIntrinsicDimensions into getMinIntrinsicWidth,
getMaxIntrinsicWidth, getMinIntrinsicHeight, and getMaxIntrinsicHeight so that
we can properly shrink-wrap the stocks app menu. This CL just contains the
refactoring. The use in stocks app will come in a later CL.

R=ianh@google.com

Review URL: https://codereview.chromium.org/1167293003
上级 44ad012a
......@@ -13,8 +13,20 @@ class RenderSolidColorBox extends RenderDecoratedBox {
: backgroundColor = backgroundColor,
super(decoration: new BoxDecoration(backgroundColor: backgroundColor));
Size getIntrinsicDimensions(BoxConstraints constraints) {
return constraints.constrain(desiredSize);
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() {
......
......@@ -25,25 +25,51 @@ class RenderBlock extends RenderBox with ContainerRenderObjectMixin<RenderBox, B
child.parentData = new BlockParentData();
}
// override this to report what dimensions you would have if you
// were laid out with the given constraints this can walk the tree
// if it must, but it should be as cheap as possible; just get the
// dimensions and nothing else (e.g. don't calculate hypothetical
// child positions if they're not needed to determine dimensions)
Size getIntrinsicDimensions(BoxConstraints constraints) {
double getMinIntrinsicWidth(BoxConstraints constraints) {
double width = 0.0;
BoxConstraints innerConstraints = new BoxConstraints(
minWidth: constraints.minWidth, maxWidth: constraints.maxWidth);
RenderBox child = firstChild;
while (child != null) {
width = math.max(width, child.getMinIntrinsicWidth(innerConstraints));
child = child.parentData.nextSibling;
}
return width;
}
double getMaxIntrinsicWidth(BoxConstraints constraints) {
double width = 0.0;
BoxConstraints innerConstraints = new BoxConstraints(
minWidth: constraints.minWidth, maxWidth: constraints.maxWidth);
RenderBox child = firstChild;
while (child != null) {
width = math.max(width, child.getMaxIntrinsicWidth(innerConstraints));
child = child.parentData.nextSibling;
}
return width;
}
double _getIntrinsicHeight(BoxConstraints constraints) {
double height = 0.0;
double width = constraints.constrainWidth(constraints.maxWidth);
assert(width < double.INFINITY);
RenderBox child = firstChild;
BoxConstraints innerConstraints = new BoxConstraints(minWidth: width,
maxWidth: width);
RenderBox child = firstChild;
while (child != null) {
height += child.getIntrinsicDimensions(innerConstraints).height;
assert(child.parentData is BlockParentData);
double childHeight = child.getMinIntrinsicHeight(innerConstraints);
assert(childHeight == child.getMaxIntrinsicHeight(innerConstraints));
height += childHeight;
child = child.parentData.nextSibling;
}
return height;
}
double getMinIntrinsicHeight(BoxConstraints constraints) {
return _getIntrinsicHeight(constraints);
}
return new Size(width, constraints.constrainHeight(height));
double getMaxIntrinsicHeight(BoxConstraints constraints) {
return _getIntrinsicHeight(constraints);
}
void performLayout() {
......
......@@ -127,13 +127,31 @@ abstract class RenderBox extends RenderObject {
child.parentData = new BoxParentData();
}
// override this to report what dimensions you would have if you
// were laid out with the given constraints this can walk the tree
// if it must, but it should be as cheap as possible; just get the
// dimensions and nothing else (e.g. don't calculate hypothetical
// child positions if they're not needed to determine dimensions)
Size getIntrinsicDimensions(BoxConstraints constraints) {
return constraints.constrain(Size.zero);
// getMinIntrinsicWidth() should return the minimum width that this box could
// be without failing to render its contents within itself.
double getMinIntrinsicWidth(BoxConstraints constraints) {
return constraints.constrainWidth(0.0);
}
// getMaxIntrinsicWidth() should return the smallest width beyond which
// increasing the width never decreases the height.
double getMaxIntrinsicWidth(BoxConstraints constraints) {
return constraints.constrainWidth(0.0);
}
// getMinIntrinsicHeight() should return the minimum height that this box could
// be without failing to render its contents within itself.
double getMinIntrinsicHeight(BoxConstraints constraints) {
return constraints.constrainHeight(0.0);
}
// getMaxIntrinsicHeight should return the smallest height beyond which
// increasing the height never decreases the width.
// If the layout algorithm used is width-in-height-out, i.e. the height
// depends on the width and not vice versa, then this will return the same
// as getMinIntrinsicHeight().
double getMaxIntrinsicHeight(BoxConstraints constraints) {
return constraints.constrainHeight(0.0);
}
BoxConstraints get constraints => super.constraints as BoxConstraints;
......@@ -167,10 +185,28 @@ abstract class RenderProxyBox extends RenderBox with RenderObjectWithChildMixin<
this.child = child;
}
Size getIntrinsicDimensions(BoxConstraints constraints) {
double getMinIntrinsicWidth(BoxConstraints constraints) {
if (child != null)
return child.getIntrinsicDimensions(constraints);
return super.getIntrinsicDimensions(constraints);
return child.getMinIntrinsicWidth(constraints);
return super.getMinIntrinsicWidth(constraints);
}
double getMaxIntrinsicWidth(BoxConstraints constraints) {
if (child != null)
return child.getMaxIntrinsicWidth(constraints);
return super.getMaxIntrinsicWidth(constraints);
}
double getMinIntrinsicHeight(BoxConstraints constraints) {
if (child != null)
return child.getMinIntrinsicHeight(constraints);
return super.getMinIntrinsicHeight(constraints);
}
double getMaxIntrinsicHeight(BoxConstraints constraints) {
if (child != null)
return child.getMaxIntrinsicHeight(constraints);
return super.getMaxIntrinsicHeight(constraints);
}
void performLayout() {
......@@ -214,8 +250,20 @@ class RenderSizedBox extends RenderProxyBox {
markNeedsLayout();
}
Size getIntrinsicDimensions(BoxConstraints constraints) {
return constraints.constrain(_desiredSize);
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() {
......@@ -245,10 +293,28 @@ class RenderConstrainedBox extends RenderProxyBox {
markNeedsLayout();
}
Size getIntrinsicDimensions(BoxConstraints constraints) {
if (child == null)
return constraints.constrain(Size.zero);
return child.getIntrinsicDimensions(constraints.apply(_additionalConstraints));
double getMinIntrinsicWidth(BoxConstraints constraints) {
if (child != null)
return child.getMinIntrinsicWidth(constraints.apply(_additionalConstraints));
return constraints.constrainWidth(0.0);
}
double getMaxIntrinsicWidth(BoxConstraints constraints) {
if (child != null)
return child.getMaxIntrinsicWidth(constraints.apply(_additionalConstraints));
return constraints.constrainWidth(0.0);
}
double getMinIntrinsicHeight(BoxConstraints constraints) {
if (child != null)
return child.getMinIntrinsicHeight(constraints.apply(_additionalConstraints));
return constraints.constrainHeight(0.0);
}
double getMaxIntrinsicHeight(BoxConstraints constraints) {
if (child != null)
return child.getMaxIntrinsicHeight(constraints.apply(_additionalConstraints));
return constraints.constrainHeight(0.0);
}
void performLayout() {
......@@ -294,12 +360,28 @@ class RenderPadding extends RenderBox with RenderObjectWithChildMixin<RenderBox>
markNeedsLayout();
}
Size getIntrinsicDimensions(BoxConstraints constraints) {
assert(padding != null);
constraints = constraints.deflate(padding);
if (child == null)
return super.getIntrinsicDimensions(constraints);
return child.getIntrinsicDimensions(constraints);
double getMinIntrinsicWidth(BoxConstraints constraints) {
if (child != null)
return child.getMinIntrinsicWidth(constraints.deflate(padding));
return constraints.constrainWidth(padding.left + padding.right);
}
double getMaxIntrinsicWidth(BoxConstraints constraints) {
if (child != null)
return child.getMaxIntrinsicWidth(constraints.deflate(padding));
return constraints.constrainWidth(padding.left + padding.right);
}
double getMinIntrinsicHeight(BoxConstraints constraints) {
if (child != null)
return child.getMinIntrinsicHeight(constraints.deflate(padding));
return constraints.constrainHeight(padding.top + padding.bottom);
}
double getMaxIntrinsicHeight(BoxConstraints constraints) {
if (child != null)
return child.getMaxIntrinsicHeight(constraints.deflate(padding));
return constraints.constrainHeight(padding.top + padding.bottom);
}
void performLayout() {
......
......@@ -57,6 +57,30 @@ class RenderFlex extends RenderBox with ContainerRenderObjectMixin<RenderBox, Fl
child.parentData = new FlexBoxParentData();
}
// We don't currently support this for RenderFlex
double getMinIntrinsicWidth(BoxConstraints constraints) {
assert(false);
return constraints.constrainWidth(0.0);
}
// We don't currently support this for RenderFlex
double getMaxIntrinsicWidth(BoxConstraints constraints) {
assert(false);
return constraints.constrainWidth(0.0);
}
// We don't currently support this for RenderFlex
double getMinIntrinsicHeight(BoxConstraints constraints) {
assert(false);
return constraints.constrainHeight(0.0);
}
// We don't currently support this for RenderFlex
double getMaxIntrinsicHeight(BoxConstraints constraints) {
assert(false);
return constraints.constrainHeight(0.0);
}
bool get sizedByParent => true;
void performResize() {
size = constraints.constrain(new Size(constraints.maxWidth, constraints.maxHeight));
......
......@@ -40,10 +40,28 @@ class RenderParagraph extends RenderBox {
}
}
Size getIntrinsicDimensions(BoxConstraints constraints) {
// We don't currently support this for RenderParagraph
double getMinIntrinsicWidth(BoxConstraints constraints) {
assert(false);
return null;
// we don't currently support this for RenderParagraph
return constraints.constrainWidth(0.0);
}
// We don't currently support this for RenderParagraph
double getMaxIntrinsicWidth(BoxConstraints constraints) {
assert(false);
return constraints.constrainWidth(0.0);
}
// We don't currently support this for RenderParagraph
double getMinIntrinsicHeight(BoxConstraints constraints) {
assert(false);
return constraints.constrainHeight(0.0);
}
// We don't currently support this for RenderParagraph
double getMaxIntrinsicHeight(BoxConstraints constraints) {
assert(false);
return constraints.constrainHeight(0.0);
}
void performLayout() {
......
......@@ -21,8 +21,20 @@ class RenderStack extends RenderBox with ContainerRenderObjectMixin<RenderBox, S
child.parentData = new StackParentData();
}
Size getIntrinsicDimensions(BoxConstraints constraints) {
return constraints.constrain(Size.infinite);
double getMinIntrinsicWidth(BoxConstraints constraints) {
return constraints.constrainWidth(double.INFINITY);
}
double getMaxIntrinsicWidth(BoxConstraints constraints) {
return constraints.constrainWidth(double.INFINITY);
}
double getMinIntrinsicHeight(BoxConstraints constraints) {
return constraints.constrainHeight(double.INFINITY);
}
double getMaxIntrinsicHeight(BoxConstraints constraints) {
return constraints.constrainHeight(double.INFINITY);
}
void performLayout() {
......
......@@ -20,8 +20,20 @@ class RenderSolidColor extends RenderDecoratedBox {
super(decoration: new BoxDecoration(backgroundColor: backgroundColor)) {
}
sky.Size getIntrinsicDimensions(BoxConstraints constraints) {
return constraints.constrain(desiredSize);
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() {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册