OLD | NEW |
| (Empty) |
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 | |
3 // found in the LICENSE file. | |
4 | |
5 import 'box.dart'; | |
6 import 'dart:math' as math; | |
7 import 'object.dart'; | |
8 | |
9 class BlockParentData extends BoxParentData with ContainerParentDataMixin<Render
Box> { } | |
10 | |
11 class RenderBlock extends RenderBox with ContainerRenderObjectMixin<RenderBox, B
lockParentData>, | |
12 RenderBoxContainerDefaultsMixin<RenderB
ox, BlockParentData> { | |
13 // lays out RenderBox children in a vertical stack | |
14 // uses the maximum width provided by the parent | |
15 // sizes itself to the height of its child stack | |
16 | |
17 RenderBlock({ | |
18 List<RenderBox> children | |
19 }) { | |
20 if (children != null) | |
21 children.forEach((child) { add(child); }); | |
22 } | |
23 | |
24 void setParentData(RenderBox child) { | |
25 if (child.parentData is! BlockParentData) | |
26 child.parentData = new BlockParentData(); | |
27 } | |
28 | |
29 double getMinIntrinsicWidth(BoxConstraints constraints) { | |
30 double width = 0.0; | |
31 BoxConstraints innerConstraints = new BoxConstraints( | |
32 minWidth: constraints.minWidth, maxWidth: constraints.maxWidth); | |
33 RenderBox child = firstChild; | |
34 while (child != null) { | |
35 width = math.max(width, child.getMinIntrinsicWidth(innerConstraints)); | |
36 child = child.parentData.nextSibling; | |
37 } | |
38 return width; | |
39 } | |
40 | |
41 double getMaxIntrinsicWidth(BoxConstraints constraints) { | |
42 double width = 0.0; | |
43 BoxConstraints innerConstraints = new BoxConstraints( | |
44 minWidth: constraints.minWidth, maxWidth: constraints.maxWidth); | |
45 RenderBox child = firstChild; | |
46 while (child != null) { | |
47 width = math.max(width, child.getMaxIntrinsicWidth(innerConstraints)); | |
48 child = child.parentData.nextSibling; | |
49 } | |
50 return width; | |
51 } | |
52 | |
53 BoxConstraints _getInnerConstraintsForWidth(double width) { | |
54 return new BoxConstraints(minWidth: width, maxWidth: width); | |
55 } | |
56 | |
57 double _getIntrinsicHeight(BoxConstraints constraints) { | |
58 double height = 0.0; | |
59 double width = constraints.constrainWidth(constraints.maxWidth); | |
60 BoxConstraints innerConstraints = _getInnerConstraintsForWidth(width); | |
61 RenderBox child = firstChild; | |
62 while (child != null) { | |
63 double childHeight = child.getMinIntrinsicHeight(innerConstraints); | |
64 assert(childHeight == child.getMaxIntrinsicHeight(innerConstraints)); | |
65 height += childHeight; | |
66 child = child.parentData.nextSibling; | |
67 } | |
68 return height; | |
69 } | |
70 | |
71 double getMinIntrinsicHeight(BoxConstraints constraints) { | |
72 return _getIntrinsicHeight(constraints); | |
73 } | |
74 | |
75 double getMaxIntrinsicHeight(BoxConstraints constraints) { | |
76 return _getIntrinsicHeight(constraints); | |
77 } | |
78 | |
79 void performLayout() { | |
80 assert(constraints is BoxConstraints); | |
81 double width = constraints.constrainWidth(constraints.maxWidth); | |
82 BoxConstraints innerConstraints = _getInnerConstraintsForWidth(width); | |
83 double y = 0.0; | |
84 RenderBox child = firstChild; | |
85 while (child != null) { | |
86 child.layout(innerConstraints, parentUsesSize: true); | |
87 assert(child.parentData is BlockParentData); | |
88 child.parentData.position = new Point(0.0, y); | |
89 y += child.size.height; | |
90 child = child.parentData.nextSibling; | |
91 } | |
92 size = new Size(width, constraints.constrainHeight(y)); | |
93 assert(size.width < double.INFINITY); | |
94 assert(size.height < double.INFINITY); | |
95 } | |
96 | |
97 void hitTestChildren(HitTestResult result, { Point position }) { | |
98 defaultHitTestChildren(result, position: position); | |
99 } | |
100 | |
101 void paint(RenderObjectDisplayList canvas) { | |
102 defaultPaint(canvas); | |
103 } | |
104 | |
105 } | |
106 | |
OLD | NEW |