Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 import 'dart:math' as math; | 5 import 'dart:math' as math; |
| 6 import 'dart:sky' as sky; | 6 import 'dart:sky' as sky; |
| 7 | 7 |
| 8 import 'package:vector_math/vector_math.dart'; | 8 import 'package:vector_math/vector_math.dart'; |
| 9 | 9 |
| 10 import '../base/debug.dart'; | 10 import '../base/debug.dart'; |
| (...skipping 1030 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1041 } | 1041 } |
| 1042 | 1042 |
| 1043 Size _sizeForConstraints(BoxConstraints innerConstraints) { | 1043 Size _sizeForConstraints(BoxConstraints innerConstraints) { |
| 1044 // If there's no image, we can't size ourselves automatically | 1044 // If there's no image, we can't size ourselves automatically |
| 1045 if (_image == null) { | 1045 if (_image == null) { |
| 1046 double width = requestedSize.width == null ? 0.0 : requestedSize.width; | 1046 double width = requestedSize.width == null ? 0.0 : requestedSize.width; |
| 1047 double height = requestedSize.height == null ? 0.0 : requestedSize.height; | 1047 double height = requestedSize.height == null ? 0.0 : requestedSize.height; |
| 1048 return constraints.constrain(new Size(width, height)); | 1048 return constraints.constrain(new Size(width, height)); |
| 1049 } | 1049 } |
| 1050 | 1050 |
| 1051 // If neither height nor width are specified, use inherent image dimensions | 1051 if (!innerConstraints.isTight) { |
| 1052 // If only one dimension is specified, adjust the other dimension to | 1052 // If neither height nor width are specified, use inherent image |
| 1053 // maintain the aspect ratio | 1053 // dimensions. If only one dimension is specified, adjust the |
| 1054 if (requestedSize.width == null) { | 1054 // other dimension to maintain the aspect ratio. In both cases, |
| 1055 if (requestedSize.height == null) { | 1055 // constrain dimensions first, otherwise we end up losing the |
| 1056 return constraints.constrain(new Size(_image.width.toDouble(), _image.he ight.toDouble())); | 1056 // ratio after constraining. |
| 1057 } else { | 1057 if (requestedSize.width == null) { |
| 1058 if (requestedSize.height == null) { | |
| 1059 // autosize | |
| 1060 double maxHeight = math.min(math.max(constraints.minHeight, constraint s.maxHeight), _image.height.toDouble()); | |
|
abarth-chromium
2015/07/07 00:11:15
Is this not just constraints.constrainHeight ?
| |
| 1061 double width = math.min(math.max(constraints.minWidth, constraints.max Width), _image.width.toDouble()); | |
|
abarth-chromium
2015/07/07 00:11:15
Ditto
| |
| 1062 double ratio = _image.height / _image.width; | |
| 1063 double height = width * ratio; | |
| 1064 if (height > maxHeight) { | |
| 1065 height = maxHeight; | |
| 1066 width = maxHeight / ratio; | |
| 1067 } | |
| 1068 return constraints.constrain(new Size(width, height)); | |
| 1069 } | |
| 1070 // determine width from height | |
| 1058 double width = requestedSize.height * _image.width / _image.height; | 1071 double width = requestedSize.height * _image.width / _image.height; |
| 1059 return constraints.constrain(new Size(width, requestedSize.height)); | 1072 return constraints.constrain(new Size(width, requestedSize.height)); |
| 1060 } | 1073 } |
| 1061 } else if (requestedSize.height == null) { | 1074 if (requestedSize.height == null) { |
| 1062 double height = requestedSize.width * _image.height / _image.width; | 1075 // determine height from width |
| 1063 return constraints.constrain(new Size(requestedSize.width, height)); | 1076 double height = requestedSize.width * _image.height / _image.width; |
| 1064 } else { | 1077 return constraints.constrain(new Size(requestedSize.width, height)); |
| 1065 return constraints.constrain(requestedSize); | 1078 } |
| 1066 } | 1079 } |
| 1080 return constraints.constrain(requestedSize); | |
| 1067 } | 1081 } |
| 1068 | 1082 |
| 1069 double getMinIntrinsicWidth(BoxConstraints constraints) { | 1083 double getMinIntrinsicWidth(BoxConstraints constraints) { |
| 1070 if (requestedSize.width == null && requestedSize.height == null) | 1084 if (requestedSize.width == null && requestedSize.height == null) |
| 1071 return constraints.constrainWidth(0.0); | 1085 return constraints.constrainWidth(0.0); |
| 1072 return _sizeForConstraints(constraints).width; | 1086 return _sizeForConstraints(constraints).width; |
| 1073 } | 1087 } |
| 1074 | 1088 |
| 1075 double getMaxIntrinsicWidth(BoxConstraints constraints) { | 1089 double getMaxIntrinsicWidth(BoxConstraints constraints) { |
| 1076 return _sizeForConstraints(constraints).width; | 1090 return _sizeForConstraints(constraints).width; |
| (...skipping 344 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1421 | 1435 |
| 1422 void defaultPaint(PaintingCanvas canvas, Offset offset) { | 1436 void defaultPaint(PaintingCanvas canvas, Offset offset) { |
| 1423 RenderBox child = firstChild; | 1437 RenderBox child = firstChild; |
| 1424 while (child != null) { | 1438 while (child != null) { |
| 1425 assert(child.parentData is ParentDataType); | 1439 assert(child.parentData is ParentDataType); |
| 1426 canvas.paintChild(child, child.parentData.position + offset); | 1440 canvas.paintChild(child, child.parentData.position + offset); |
| 1427 child = child.parentData.nextSibling; | 1441 child = child.parentData.nextSibling; |
| 1428 } | 1442 } |
| 1429 } | 1443 } |
| 1430 } | 1444 } |
| OLD | NEW |