From 903ef07abbb7a3bd5004e58881bbc403f6f802c8 Mon Sep 17 00:00:00 2001 From: Adam Barth Date: Mon, 8 Jun 2015 14:40:34 -0700 Subject: [PATCH] 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 --- examples/lib/solid_color_box.dart | 16 ++- sdk/lib/framework/rendering/block.dart | 54 ++++++--- sdk/lib/framework/rendering/box.dart | 126 +++++++++++++++++---- sdk/lib/framework/rendering/flex.dart | 24 ++++ sdk/lib/framework/rendering/paragraph.dart | 24 +++- sdk/lib/framework/rendering/stack.dart | 16 ++- tests/raw/render_flex.dart | 16 ++- 7 files changed, 231 insertions(+), 45 deletions(-) diff --git a/examples/lib/solid_color_box.dart b/examples/lib/solid_color_box.dart index ae008e39316..9c650ce3967 100644 --- a/examples/lib/solid_color_box.dart +++ b/examples/lib/solid_color_box.dart @@ -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() { diff --git a/sdk/lib/framework/rendering/block.dart b/sdk/lib/framework/rendering/block.dart index b56856073ff..cb9a5396ecd 100644 --- a/sdk/lib/framework/rendering/block.dart +++ b/sdk/lib/framework/rendering/block.dart @@ -25,25 +25,51 @@ class RenderBlock extends RenderBox with ContainerRenderObjectMixin 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 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() { diff --git a/sdk/lib/framework/rendering/flex.dart b/sdk/lib/framework/rendering/flex.dart index 0f5dc51072f..ae695ca6261 100644 --- a/sdk/lib/framework/rendering/flex.dart +++ b/sdk/lib/framework/rendering/flex.dart @@ -57,6 +57,30 @@ class RenderFlex extends RenderBox with ContainerRenderObjectMixin true; void performResize() { size = constraints.constrain(new Size(constraints.maxWidth, constraints.maxHeight)); diff --git a/sdk/lib/framework/rendering/paragraph.dart b/sdk/lib/framework/rendering/paragraph.dart index 911ad15ed0b..58ad8915d45 100644 --- a/sdk/lib/framework/rendering/paragraph.dart +++ b/sdk/lib/framework/rendering/paragraph.dart @@ -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() { diff --git a/sdk/lib/framework/rendering/stack.dart b/sdk/lib/framework/rendering/stack.dart index 7656ea1c702..466968b3298 100644 --- a/sdk/lib/framework/rendering/stack.dart +++ b/sdk/lib/framework/rendering/stack.dart @@ -21,8 +21,20 @@ class RenderStack extends RenderBox with ContainerRenderObjectMixin