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

Side by Side Diff: sky/sdk/lib/framework/rendering/block.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/examples/lib/solid_color_box.dart ('k') | sky/sdk/lib/framework/rendering/box.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 'box.dart'; 5 import 'box.dart';
6 import 'object.dart'; 6 import 'object.dart';
7 7
8 class BlockParentData extends BoxParentData with ContainerParentDataMixin<Render Box> { } 8 class BlockParentData extends BoxParentData with ContainerParentDataMixin<Render Box> { }
9 9
10 class RenderBlock extends RenderBox with ContainerRenderObjectMixin<RenderBox, B lockParentData>, 10 class RenderBlock extends RenderBox with ContainerRenderObjectMixin<RenderBox, B lockParentData>,
11 RenderBoxContainerDefaultsMixin<RenderB ox, BlockParentData> { 11 RenderBoxContainerDefaultsMixin<RenderB ox, BlockParentData> {
12 // lays out RenderBox children in a vertical stack 12 // lays out RenderBox children in a vertical stack
13 // uses the maximum width provided by the parent 13 // uses the maximum width provided by the parent
14 // sizes itself to the height of its child stack 14 // sizes itself to the height of its child stack
15 15
16 RenderBlock({ 16 RenderBlock({
17 List<RenderBox> children 17 List<RenderBox> children
18 }) { 18 }) {
19 if (children != null) 19 if (children != null)
20 children.forEach((child) { add(child); }); 20 children.forEach((child) { add(child); });
21 } 21 }
22 22
23 void setParentData(RenderBox child) { 23 void setParentData(RenderBox child) {
24 if (child.parentData is! BlockParentData) 24 if (child.parentData is! BlockParentData)
25 child.parentData = new BlockParentData(); 25 child.parentData = new BlockParentData();
26 } 26 }
27 27
28 // override this to report what dimensions you would have if you 28 double getMinIntrinsicWidth(BoxConstraints constraints) {
29 // were laid out with the given constraints this can walk the tree 29 double width = 0.0;
30 // if it must, but it should be as cheap as possible; just get the 30 BoxConstraints innerConstraints = new BoxConstraints(
31 // dimensions and nothing else (e.g. don't calculate hypothetical 31 minWidth: constraints.minWidth, maxWidth: constraints.maxWidth);
32 // child positions if they're not needed to determine dimensions) 32 RenderBox child = firstChild;
33 Size getIntrinsicDimensions(BoxConstraints constraints) { 33 while (child != null) {
34 width = math.max(width, child.getMinIntrinsicWidth(innerConstraints));
35 child = child.parentData.nextSibling;
36 }
37 return width;
38 }
39
40 double getMaxIntrinsicWidth(BoxConstraints constraints) {
41 double width = 0.0;
42 BoxConstraints innerConstraints = new BoxConstraints(
43 minWidth: constraints.minWidth, maxWidth: constraints.maxWidth);
44 RenderBox child = firstChild;
45 while (child != null) {
46 width = math.max(width, child.getMaxIntrinsicWidth(innerConstraints));
47 child = child.parentData.nextSibling;
48 }
49 return width;
50 }
51
52 double _getIntrinsicHeight(BoxConstraints constraints) {
34 double height = 0.0; 53 double height = 0.0;
35 double width = constraints.constrainWidth(constraints.maxWidth); 54 double width = constraints.constrainWidth(constraints.maxWidth);
36 assert(width < double.INFINITY); 55 assert(width < double.INFINITY);
37 RenderBox child = firstChild;
38 BoxConstraints innerConstraints = new BoxConstraints(minWidth: width, 56 BoxConstraints innerConstraints = new BoxConstraints(minWidth: width,
39 maxWidth: width); 57 maxWidth: width);
58 RenderBox child = firstChild;
40 while (child != null) { 59 while (child != null) {
41 height += child.getIntrinsicDimensions(innerConstraints).height; 60 double childHeight = child.getMinIntrinsicHeight(innerConstraints);
42 assert(child.parentData is BlockParentData); 61 assert(childHeight == child.getMaxIntrinsicHeight(innerConstraints));
62 height += childHeight;
43 child = child.parentData.nextSibling; 63 child = child.parentData.nextSibling;
44 } 64 }
65 return height;
66 }
45 67
46 return new Size(width, constraints.constrainHeight(height)); 68 double getMinIntrinsicHeight(BoxConstraints constraints) {
69 return _getIntrinsicHeight(constraints);
70 }
71
72 double getMaxIntrinsicHeight(BoxConstraints constraints) {
73 return _getIntrinsicHeight(constraints);
47 } 74 }
48 75
49 void performLayout() { 76 void performLayout() {
50 assert(constraints is BoxConstraints); 77 assert(constraints is BoxConstraints);
51 double width = constraints.constrainWidth(constraints.maxWidth); 78 double width = constraints.constrainWidth(constraints.maxWidth);
52 double y = 0.0; 79 double y = 0.0;
53 RenderBox child = firstChild; 80 RenderBox child = firstChild;
54 while (child != null) { 81 while (child != null) {
55 child.layout(new BoxConstraints(minWidth: width, maxWidth: width), parentU sesSize: true); 82 child.layout(new BoxConstraints(minWidth: width, maxWidth: width), parentU sesSize: true);
56 assert(child.parentData is BlockParentData); 83 assert(child.parentData is BlockParentData);
57 child.parentData.position = new Point(0.0, y); 84 child.parentData.position = new Point(0.0, y);
58 y += child.size.height; 85 y += child.size.height;
59 child = child.parentData.nextSibling; 86 child = child.parentData.nextSibling;
60 } 87 }
61 size = new Size(width, constraints.constrainHeight(y)); 88 size = new Size(width, constraints.constrainHeight(y));
62 assert(size.width < double.INFINITY); 89 assert(size.width < double.INFINITY);
63 assert(size.height < double.INFINITY); 90 assert(size.height < double.INFINITY);
64 } 91 }
65 92
66 void hitTestChildren(HitTestResult result, { Point position }) { 93 void hitTestChildren(HitTestResult result, { Point position }) {
67 defaultHitTestChildren(result, position: position); 94 defaultHitTestChildren(result, position: position);
68 } 95 }
69 96
70 void paint(RenderObjectDisplayList canvas) { 97 void paint(RenderObjectDisplayList canvas) {
71 defaultPaint(canvas); 98 defaultPaint(canvas);
72 } 99 }
73 100
74 } 101 }
75 102
OLDNEW
« no previous file with comments | « sky/examples/lib/solid_color_box.dart ('k') | sky/sdk/lib/framework/rendering/box.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698