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

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

Issue 1167293003: Split getIntrinsicDimensions into four pieces (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: more worky Created 5 years, 6 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/framework/rendering/block.dart ('k') | sky/sdk/lib/framework/rendering/flex.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 import 'dart:typed_data'; 7 import 'dart:typed_data';
8 import 'object.dart'; 8 import 'object.dart';
9 import 'package:vector_math/vector_math.dart'; 9 import 'package:vector_math/vector_math.dart';
10 import 'package:sky/framework/net/image_cache.dart' as image_cache; 10 import 'package:sky/framework/net/image_cache.dart' as image_cache;
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after
120 String toString() => 'position=$position'; 120 String toString() => 'position=$position';
121 } 121 }
122 122
123 abstract class RenderBox extends RenderObject { 123 abstract class RenderBox extends RenderObject {
124 124
125 void setParentData(RenderObject child) { 125 void setParentData(RenderObject child) {
126 if (child.parentData is! BoxParentData) 126 if (child.parentData is! BoxParentData)
127 child.parentData = new BoxParentData(); 127 child.parentData = new BoxParentData();
128 } 128 }
129 129
130 // override this to report what dimensions you would have if you 130 double getMinIntrinsicWidth(BoxConstraints constraints) {
131 // were laid out with the given constraints this can walk the tree 131 return constraints.constrainWidth(0.0);
132 // if it must, but it should be as cheap as possible; just get the 132 }
133 // dimensions and nothing else (e.g. don't calculate hypothetical 133
134 // child positions if they're not needed to determine dimensions) 134 double getMaxIntrinsicWidth(BoxConstraints constraints) {
135 Size getIntrinsicDimensions(BoxConstraints constraints) { 135 return constraints.constrainWidth(0.0);
136 return constraints.constrain(Size.zero); 136 }
137
138 double getMinIntrinsicHeight(BoxConstraints constraints) {
139 return constraints.constrainHeight(0.0);
140 }
141
142 double getMaxIntrinsicHeight(BoxConstraints constraints) {
143 return constraints.constrainHeight(0.0);
137 } 144 }
138 145
139 BoxConstraints get constraints => super.constraints as BoxConstraints; 146 BoxConstraints get constraints => super.constraints as BoxConstraints;
140 void performResize() { 147 void performResize() {
141 // default behaviour for subclasses that have sizedByParent = true 148 // default behaviour for subclasses that have sizedByParent = true
142 size = constraints.constrain(Size.zero); 149 size = constraints.constrain(Size.zero);
143 assert(size.height < double.INFINITY); 150 assert(size.height < double.INFINITY);
144 assert(size.width < double.INFINITY); 151 assert(size.width < double.INFINITY);
145 } 152 }
146 void performLayout() { 153 void performLayout() {
(...skipping 13 matching lines...) Expand all
160 Size size = Size.zero; 167 Size size = Size.zero;
161 168
162 String debugDescribeSettings(String prefix) => '${super.debugDescribeSettings( prefix)}${prefix}size: ${size}\n'; 169 String debugDescribeSettings(String prefix) => '${super.debugDescribeSettings( prefix)}${prefix}size: ${size}\n';
163 } 170 }
164 171
165 abstract class RenderProxyBox extends RenderBox with RenderObjectWithChildMixin< RenderBox> { 172 abstract class RenderProxyBox extends RenderBox with RenderObjectWithChildMixin< RenderBox> {
166 RenderProxyBox(RenderBox child) { 173 RenderProxyBox(RenderBox child) {
167 this.child = child; 174 this.child = child;
168 } 175 }
169 176
170 Size getIntrinsicDimensions(BoxConstraints constraints) { 177 double getMinIntrinsicWidth(BoxConstraints constraints) {
171 if (child != null) 178 if (child != null)
172 return child.getIntrinsicDimensions(constraints); 179 return child.getMinIntrinsicWidth(constraints);
173 return super.getIntrinsicDimensions(constraints); 180 return super.getMinIntrinsicWidth(constraints);
181 }
182
183 double getMaxIntrinsicWidth(BoxConstraints constraints) {
184 if (child != null)
185 return child.getMaxIntrinsicWidth(constraints);
186 return super.getMaxIntrinsicWidth(constraints);
187 }
188
189 double getMinIntrinsicHeight(BoxConstraints constraints) {
190 if (child != null)
191 return child.getMinIntrinsicHeight(constraints);
192 return super.getMinIntrinsicHeight(constraints);
193 }
194
195 double getMaxIntrinsicHeight(BoxConstraints constraints) {
196 if (child != null)
197 return child.getMaxIntrinsicHeight(constraints);
198 return super.getMaxIntrinsicHeight(constraints);
174 } 199 }
175 200
176 void performLayout() { 201 void performLayout() {
177 if (child != null) { 202 if (child != null) {
178 child.layout(constraints, parentUsesSize: true); 203 child.layout(constraints, parentUsesSize: true);
179 size = child.size; 204 size = child.size;
180 } else { 205 } else {
181 performResize(); 206 performResize();
182 } 207 }
183 } 208 }
(...skipping 23 matching lines...) Expand all
207 Size _desiredSize; 232 Size _desiredSize;
208 Size get desiredSize => _desiredSize; 233 Size get desiredSize => _desiredSize;
209 void set desiredSize (Size value) { 234 void set desiredSize (Size value) {
210 assert(value != null); 235 assert(value != null);
211 if (_desiredSize == value) 236 if (_desiredSize == value)
212 return; 237 return;
213 _desiredSize = value; 238 _desiredSize = value;
214 markNeedsLayout(); 239 markNeedsLayout();
215 } 240 }
216 241
217 Size getIntrinsicDimensions(BoxConstraints constraints) { 242 double getMinIntrinsicWidth(BoxConstraints constraints) {
218 return constraints.constrain(_desiredSize); 243 return constraints.constrainWidth(_desiredSize.width);
244 }
245
246 double getMaxIntrinsicWidth(BoxConstraints constraints) {
247 return constraints.constrainWidth(_desiredSize.width);
248 }
249
250 double getMinIntrinsicHeight(BoxConstraints constraints) {
251 return constraints.constrainHeight(_desiredSize.height);
252 }
253
254 double getMaxIntrinsicHeight(BoxConstraints constraints) {
255 return constraints.constrainHeight(_desiredSize.height);
219 } 256 }
220 257
221 void performLayout() { 258 void performLayout() {
222 size = constraints.constrain(_desiredSize); 259 size = constraints.constrain(_desiredSize);
223 if (child != null) 260 if (child != null)
224 child.layout(new BoxConstraints.tight(size)); 261 child.layout(new BoxConstraints.tight(size));
225 } 262 }
226 263
227 String debugDescribeSettings(String prefix) => '${super.debugDescribeSettings( prefix)}${prefix}desiredSize: ${desiredSize}\n'; 264 String debugDescribeSettings(String prefix) => '${super.debugDescribeSettings( prefix)}${prefix}desiredSize: ${desiredSize}\n';
228 } 265 }
229 266
230 class RenderConstrainedBox extends RenderProxyBox { 267 class RenderConstrainedBox extends RenderProxyBox {
231 RenderConstrainedBox({ 268 RenderConstrainedBox({
232 RenderBox child, 269 RenderBox child,
233 BoxConstraints additionalConstraints 270 BoxConstraints additionalConstraints
234 }) : super(child), _additionalConstraints = additionalConstraints { 271 }) : super(child), _additionalConstraints = additionalConstraints {
235 assert(additionalConstraints != null); 272 assert(additionalConstraints != null);
236 } 273 }
237 274
238 BoxConstraints _additionalConstraints; 275 BoxConstraints _additionalConstraints;
239 BoxConstraints get additionalConstraints => _additionalConstraints; 276 BoxConstraints get additionalConstraints => _additionalConstraints;
240 void set additionalConstraints (BoxConstraints value) { 277 void set additionalConstraints (BoxConstraints value) {
241 assert(value != null); 278 assert(value != null);
242 if (_additionalConstraints == value) 279 if (_additionalConstraints == value)
243 return; 280 return;
244 _additionalConstraints = value; 281 _additionalConstraints = value;
245 markNeedsLayout(); 282 markNeedsLayout();
246 } 283 }
247 284
248 Size getIntrinsicDimensions(BoxConstraints constraints) { 285 double getMinIntrinsicWidth(BoxConstraints constraints) {
249 if (child == null) 286 if (child != null)
250 return constraints.constrain(Size.zero); 287 return child.getMinIntrinsicWidth(constraints.apply(_additionalConstraints ));
251 return child.getIntrinsicDimensions(constraints.apply(_additionalConstraints )); 288 return constraints.constrainWidth(0.0);
289 }
290
291 double getMaxIntrinsicWidth(BoxConstraints constraints) {
292 if (child != null)
293 return child.getMaxIntrinsicWidth(constraints.apply(_additionalConstraints ));
294 return constraints.constrainWidth(0.0);
295 }
296
297 double getMinIntrinsicHeight(BoxConstraints constraints) {
298 if (child != null)
299 return child.getMinIntrinsicHeight(constraints.apply(_additionalConstraint s));
300 return constraints.constrainHeight(0.0);
301 }
302
303 double getMaxIntrinsicHeight(BoxConstraints constraints) {
304 if (child != null)
305 return child.getMaxIntrinsicHeight(constraints.apply(_additionalConstraint s));
306 return constraints.constrainHeight(0.0);
252 } 307 }
253 308
254 void performLayout() { 309 void performLayout() {
255 if (child != null) { 310 if (child != null) {
256 child.layout(constraints.apply(_additionalConstraints)); 311 child.layout(constraints.apply(_additionalConstraints));
257 size = child.size; 312 size = child.size;
258 } else { 313 } else {
259 performResize(); 314 performResize();
260 } 315 }
261 } 316 }
(...skipping 25 matching lines...) Expand all
287 EdgeDims _padding; 342 EdgeDims _padding;
288 EdgeDims get padding => _padding; 343 EdgeDims get padding => _padding;
289 void set padding (EdgeDims value) { 344 void set padding (EdgeDims value) {
290 assert(value != null); 345 assert(value != null);
291 if (_padding == value) 346 if (_padding == value)
292 return; 347 return;
293 _padding = value; 348 _padding = value;
294 markNeedsLayout(); 349 markNeedsLayout();
295 } 350 }
296 351
297 Size getIntrinsicDimensions(BoxConstraints constraints) { 352 double getMinIntrinsicWidth(BoxConstraints constraints) {
298 assert(padding != null); 353 if (child != null)
299 constraints = constraints.deflate(padding); 354 return child.getMinIntrinsicWidth(constraints.deflate(padding));
300 if (child == null) 355 return constraints.constrainWidth(padding.left + padding.right);
301 return super.getIntrinsicDimensions(constraints); 356 }
302 return child.getIntrinsicDimensions(constraints); 357
358 double getMaxIntrinsicWidth(BoxConstraints constraints) {
359 if (child != null)
360 return child.getMaxIntrinsicWidth(constraints.deflate(padding));
361 return constraints.constrainWidth(padding.left + padding.right);
362 }
363
364 double getMinIntrinsicHeight(BoxConstraints constraints) {
365 if (child != null)
366 return child.getMinIntrinsicHeight(constraints.deflate(padding));
367 return constraints.constrainHeight(padding.top + padding.bottom);
368 }
369
370 double getMaxIntrinsicHeight(BoxConstraints constraints) {
371 if (child != null)
372 return child.getMaxIntrinsicHeight(constraints.deflate(padding));
373 return constraints.constrainHeight(padding.top + padding.bottom);
303 } 374 }
304 375
305 void performLayout() { 376 void performLayout() {
306 assert(padding != null); 377 assert(padding != null);
307 BoxConstraints innerConstraints = constraints.deflate(padding); 378 BoxConstraints innerConstraints = constraints.deflate(padding);
308 if (child == null) { 379 if (child == null) {
309 size = innerConstraints.constrain( 380 size = innerConstraints.constrain(
310 new Size(padding.left + padding.right, padding.top + padding.bottom)); 381 new Size(padding.left + padding.right, padding.top + padding.bottom));
311 return; 382 return;
312 } 383 }
(...skipping 529 matching lines...) Expand 10 before | Expand all | Expand 10 after
842 913
843 void defaultPaint(RenderObjectDisplayList canvas) { 914 void defaultPaint(RenderObjectDisplayList canvas) {
844 RenderBox child = firstChild; 915 RenderBox child = firstChild;
845 while (child != null) { 916 while (child != null) {
846 assert(child.parentData is ParentDataType); 917 assert(child.parentData is ParentDataType);
847 canvas.paintChild(child, child.parentData.position); 918 canvas.paintChild(child, child.parentData.position);
848 child = child.parentData.nextSibling; 919 child = child.parentData.nextSibling;
849 } 920 }
850 } 921 }
851 } 922 }
OLDNEW
« no previous file with comments | « sky/sdk/lib/framework/rendering/block.dart ('k') | sky/sdk/lib/framework/rendering/flex.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698