Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(58)

Unified Diff: sky/sdk/lib/rendering/box.dart

Issue 1212943007: Fix spinning_mixed.dart, and resulting yak shave. (Closed) Base URL: https://github.com/domokit/mojo.git@master
Patch Set: Created 5 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « sky/sdk/example/widgets/spinning_mixed.dart ('k') | sky/sdk/lib/widgets/widget.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: sky/sdk/lib/rendering/box.dart
diff --git a/sky/sdk/lib/rendering/box.dart b/sky/sdk/lib/rendering/box.dart
index 78ec1d2c4d75075e52810734de486bb14c51c378..61971bef0c06781102c88e75df870446ecf96f8e 100644
--- a/sky/sdk/lib/rendering/box.dart
+++ b/sky/sdk/lib/rendering/box.dart
@@ -1048,22 +1048,36 @@ class RenderImage extends RenderBox {
return constraints.constrain(new Size(width, height));
}
- // If neither height nor width are specified, use inherent image dimensions
- // If only one dimension is specified, adjust the other dimension to
- // maintain the aspect ratio
- if (requestedSize.width == null) {
- if (requestedSize.height == null) {
- return constraints.constrain(new Size(_image.width.toDouble(), _image.height.toDouble()));
- } else {
+ if (!innerConstraints.isTight) {
+ // If neither height nor width are specified, use inherent image
+ // dimensions. If only one dimension is specified, adjust the
+ // other dimension to maintain the aspect ratio. In both cases,
+ // constrain dimensions first, otherwise we end up losing the
+ // ratio after constraining.
+ if (requestedSize.width == null) {
+ if (requestedSize.height == null) {
+ // autosize
+ double maxHeight = math.min(math.max(constraints.minHeight, constraints.maxHeight), _image.height.toDouble());
abarth-chromium 2015/07/07 00:11:15 Is this not just constraints.constrainHeight ?
+ double width = math.min(math.max(constraints.minWidth, constraints.maxWidth), _image.width.toDouble());
abarth-chromium 2015/07/07 00:11:15 Ditto
+ double ratio = _image.height / _image.width;
+ double height = width * ratio;
+ if (height > maxHeight) {
+ height = maxHeight;
+ width = maxHeight / ratio;
+ }
+ return constraints.constrain(new Size(width, height));
+ }
+ // determine width from height
double width = requestedSize.height * _image.width / _image.height;
return constraints.constrain(new Size(width, requestedSize.height));
}
- } else if (requestedSize.height == null) {
- double height = requestedSize.width * _image.height / _image.width;
- return constraints.constrain(new Size(requestedSize.width, height));
- } else {
- return constraints.constrain(requestedSize);
+ if (requestedSize.height == null) {
+ // determine height from width
+ double height = requestedSize.width * _image.height / _image.width;
+ return constraints.constrain(new Size(requestedSize.width, height));
+ }
}
+ return constraints.constrain(requestedSize);
}
double getMinIntrinsicWidth(BoxConstraints constraints) {
« no previous file with comments | « sky/sdk/example/widgets/spinning_mixed.dart ('k') | sky/sdk/lib/widgets/widget.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698