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

Side by Side Diff: sky/sdk/lib/rendering/box.dart

Issue 1209233002: Let's hide double.INFINITY a bit more, by providing cleaner APIs for the cases where we're currentl… (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 unified diff | Download patch
« no previous file with comments | « sky/sdk/lib/rendering/block.dart ('k') | sky/sdk/lib/rendering/stack.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
70 this.minHeight: 0.0, 70 this.minHeight: 0.0,
71 this.maxHeight: double.INFINITY 71 this.maxHeight: double.INFINITY
72 }); 72 });
73 73
74 BoxConstraints.tight(Size size) 74 BoxConstraints.tight(Size size)
75 : minWidth = size.width, 75 : minWidth = size.width,
76 maxWidth = size.width, 76 maxWidth = size.width,
77 minHeight = size.height, 77 minHeight = size.height,
78 maxHeight = size.height; 78 maxHeight = size.height;
79 79
80 BoxConstraints.tightFor({ 80 const BoxConstraints.tightFor({
81 double width, 81 double width,
82 double height 82 double height
83 }): minWidth = width != null ? width : 0.0, 83 }): minWidth = width != null ? width : 0.0,
84 maxWidth = width != null ? width : double.INFINITY, 84 maxWidth = width != null ? width : double.INFINITY,
85 minHeight = height != null ? height : 0.0, 85 minHeight = height != null ? height : 0.0,
86 maxHeight = height != null ? height : double.INFINITY; 86 maxHeight = height != null ? height : double.INFINITY;
87 87
88 BoxConstraints.loose(Size size) 88 BoxConstraints.loose(Size size)
89 : minWidth = 0.0, 89 : minWidth = 0.0,
90 maxWidth = size.width, 90 maxWidth = size.width,
91 minHeight = 0.0, 91 minHeight = 0.0,
92 maxHeight = size.height; 92 maxHeight = size.height;
93 93
94 const BoxConstraints.expandWidth({
95 this.maxHeight: double.INFINITY
96 }): minWidth = double.INFINITY,
97 maxWidth = double.INFINITY,
98 minHeight = 0.0;
99
100 const BoxConstraints.expandHeight({
101 this.maxWidth: double.INFINITY
102 }): minWidth = 0.0,
103 minHeight = double.INFINITY,
104 maxHeight = double.INFINITY;
105
106 static const BoxConstraints expand = const BoxConstraints(
107 minWidth: double.INFINITY,
108 maxWidth: double.INFINITY,
109 minHeight: double.INFINITY,
110 maxHeight: double.INFINITY
111 );
112
94 BoxConstraints deflate(EdgeDims edges) { 113 BoxConstraints deflate(EdgeDims edges) {
95 assert(edges != null); 114 assert(edges != null);
96 double horizontal = edges.left + edges.right; 115 double horizontal = edges.left + edges.right;
97 double vertical = edges.top + edges.bottom; 116 double vertical = edges.top + edges.bottom;
98 return new BoxConstraints( 117 return new BoxConstraints(
99 minWidth: math.max(0.0, minWidth - horizontal), 118 minWidth: math.max(0.0, minWidth - horizontal),
100 maxWidth: maxWidth - horizontal, 119 maxWidth: maxWidth - horizontal,
101 minHeight: math.max(0.0, minHeight - vertical), 120 minHeight: math.max(0.0, minHeight - vertical),
102 maxHeight: maxHeight - vertical 121 maxHeight: maxHeight - vertical
103 ); 122 );
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
165 184
166 BoxConstraints widthConstraints() => new BoxConstraints(minWidth: minWidth, ma xWidth: maxWidth); 185 BoxConstraints widthConstraints() => new BoxConstraints(minWidth: minWidth, ma xWidth: maxWidth);
167 186
168 BoxConstraints heightConstraints() => new BoxConstraints(minHeight: minHeight, maxHeight: maxHeight); 187 BoxConstraints heightConstraints() => new BoxConstraints(minHeight: minHeight, maxHeight: maxHeight);
169 188
170 final double minWidth; 189 final double minWidth;
171 final double maxWidth; 190 final double maxWidth;
172 final double minHeight; 191 final double minHeight;
173 final double maxHeight; 192 final double maxHeight;
174 193
175 double constrainWidth(double width) { 194 double constrainWidth([double width = double.INFINITY]) {
176 return clamp(min: minWidth, max: maxWidth, value: width); 195 return clamp(min: minWidth, max: maxWidth, value: width);
177 } 196 }
178 197
179 double constrainHeight(double height) { 198 double constrainHeight([double height = double.INFINITY]) {
180 return clamp(min: minHeight, max: maxHeight, value: height); 199 return clamp(min: minHeight, max: maxHeight, value: height);
181 } 200 }
182 201
183 Size constrain(Size size) { 202 Size constrain(Size size) {
184 Size result = new Size(constrainWidth(size.width), constrainHeight(size.heig ht)); 203 Size result = new Size(constrainWidth(size.width), constrainHeight(size.heig ht));
185 if (size is _DebugSize) 204 if (size is _DebugSize)
186 result = new _DebugSize(result, size._owner, size._canBeUsedByParent); 205 result = new _DebugSize(result, size._owner, size._canBeUsedByParent);
187 return result; 206 return result;
188 } 207 }
189 208
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after
305 _debugCanParentUseSize = parentUsesSize; 324 _debugCanParentUseSize = parentUsesSize;
306 super.layout(constraints, parentUsesSize: parentUsesSize); 325 super.layout(constraints, parentUsesSize: parentUsesSize);
307 _debugCanParentUseSize = null; 326 _debugCanParentUseSize = null;
308 _debugDoingThisLayout = false; 327 _debugDoingThisLayout = false;
309 } 328 }
310 329
311 BoxConstraints get constraints => super.constraints; 330 BoxConstraints get constraints => super.constraints;
312 void performResize() { 331 void performResize() {
313 // default behaviour for subclasses that have sizedByParent = true 332 // default behaviour for subclasses that have sizedByParent = true
314 size = constraints.constrain(Size.zero); 333 size = constraints.constrain(Size.zero);
315 assert(size.height < double.INFINITY); 334 assert(!size.isInfinite);
316 assert(size.width < double.INFINITY);
317 } 335 }
318 void performLayout() { 336 void performLayout() {
319 // descendants have to either override performLayout() to set both 337 // descendants have to either override performLayout() to set both
320 // width and height and lay out children, or, set sizedByParent to 338 // width and height and lay out children, or, set sizedByParent to
321 // true so that performResize()'s logic above does its thing. 339 // true so that performResize()'s logic above does its thing.
322 assert(sizedByParent); 340 assert(sizedByParent);
323 } 341 }
324 342
325 bool hitTest(HitTestResult result, { Point position }) { 343 bool hitTest(HitTestResult result, { Point position }) {
326 hitTestChildren(result, position: position); 344 hitTestChildren(result, position: position);
(...skipping 797 matching lines...) Expand 10 before | Expand all | Expand 10 after
1124 assert(false); 1142 assert(false);
1125 } 1143 }
1126 1144
1127 void performLayout() { 1145 void performLayout() {
1128 if (_rootConstraints.orientation != _orientation) { 1146 if (_rootConstraints.orientation != _orientation) {
1129 if (_orientation != null && child != null) 1147 if (_orientation != null && child != null)
1130 child.rotate(oldAngle: _orientation, newAngle: _rootConstraints.orientat ion, time: timeForRotation); 1148 child.rotate(oldAngle: _orientation, newAngle: _rootConstraints.orientat ion, time: timeForRotation);
1131 _orientation = _rootConstraints.orientation; 1149 _orientation = _rootConstraints.orientation;
1132 } 1150 }
1133 _size = new Size(_rootConstraints.width, _rootConstraints.height); 1151 _size = new Size(_rootConstraints.width, _rootConstraints.height);
1134 assert(_size.height < double.INFINITY); 1152 assert(!_size.isInfinite);
1135 assert(_size.width < double.INFINITY);
1136 1153
1137 if (child != null) { 1154 if (child != null) {
1138 child.layout(new BoxConstraints.tight(_size)); 1155 child.layout(new BoxConstraints.tight(_size));
1139 assert(child.size.width == width); 1156 assert(child.size.width == width);
1140 assert(child.size.height == height); 1157 assert(child.size.height == height);
1141 } 1158 }
1142 } 1159 }
1143 1160
1144 void rotate({ int oldAngle, int newAngle, Duration time }) { 1161 void rotate({ int oldAngle, int newAngle, Duration time }) {
1145 assert(false); // nobody tells the screen to rotate, the whole rotate() danc e is started from our performResize() 1162 assert(false); // nobody tells the screen to rotate, the whole rotate() danc e is started from our performResize()
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after
1231 1248
1232 void defaultPaint(RenderCanvas canvas) { 1249 void defaultPaint(RenderCanvas canvas) {
1233 RenderBox child = firstChild; 1250 RenderBox child = firstChild;
1234 while (child != null) { 1251 while (child != null) {
1235 assert(child.parentData is ParentDataType); 1252 assert(child.parentData is ParentDataType);
1236 canvas.paintChild(child, child.parentData.position); 1253 canvas.paintChild(child, child.parentData.position);
1237 child = child.parentData.nextSibling; 1254 child = child.parentData.nextSibling;
1238 } 1255 }
1239 } 1256 }
1240 } 1257 }
OLDNEW
« no previous file with comments | « sky/sdk/lib/rendering/block.dart ('k') | sky/sdk/lib/rendering/stack.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698