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

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

Issue 1230833002: BlockViewport didn't implement the intrinsic dimension functions correctly. (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 | « no previous file | no next file » | 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 6
7 import 'box.dart'; 7 import 'box.dart';
8 import 'object.dart'; 8 import 'object.dart';
9 9
10 class BlockParentData extends BoxParentData with ContainerParentDataMixin<Render Box> { } 10 class BlockParentData extends BoxParentData with ContainerParentDataMixin<Render Box> { }
11 11
12 abstract class RenderBlockBase extends RenderBox with ContainerRenderObjectMixin <RenderBox, BlockParentData>, 12 abstract class RenderBlockBase extends RenderBox with ContainerRenderObjectMixin <RenderBox, BlockParentData>,
13 RenderBoxContainerDefaults Mixin<RenderBox, BlockParentData> { 13 RenderBoxContainerDefaults Mixin<RenderBox, BlockParentData> {
14 14
15 // lays out RenderBox children in a vertical stack 15 // lays out RenderBox children in a vertical stack
16 // uses the maximum width provided by the parent 16 // uses the maximum width provided by the parent
17 17
18 RenderBlockBase({ 18 RenderBlockBase({
19 List<RenderBox> children 19 List<RenderBox> children
20 }) { 20 }) {
21 addAll(children); 21 addAll(children);
22 } 22 }
23 23
24 void setupParentData(RenderBox child) { 24 void setupParentData(RenderBox child) {
25 if (child.parentData is! BlockParentData) 25 if (child.parentData is! BlockParentData)
26 child.parentData = new BlockParentData(); 26 child.parentData = new BlockParentData();
27 } 27 }
28 28
29 double computeDistanceToActualBaseline(TextBaseline baseline) {
30 return defaultComputeDistanceToFirstActualBaseline(baseline);
31 }
32
33 double _childrenHeight;
34 double get childrenHeight => _childrenHeight;
35
36 void markNeedsLayout() {
37 _childrenHeight = null;
38 super.markNeedsLayout();
39 }
40
41 void performLayout() {
42 assert(constraints is BoxConstraints);
43 double width = constraints.constrainWidth(constraints.maxWidth);
44 BoxConstraints innerConstraints = _getInnerConstraintsForWidth(width);
45 double y = 0.0;
46 RenderBox child = firstChild;
47 while (child != null) {
48 child.layout(innerConstraints, parentUsesSize: true);
49 assert(child.parentData is BlockParentData);
50 child.parentData.position = new Point(0.0, y);
51 y += child.size.height;
52 child = child.parentData.nextSibling;
53 }
54 _childrenHeight = y;
55 }
56
57 void hitTestChildren(HitTestResult result, { Point position }) {
58 defaultHitTestChildren(result, position: position);
59 }
60
61 void paint(PaintingCanvas canvas, Offset offset) {
62 defaultPaint(canvas, offset);
63 }
64
65 }
66
67 class RenderBlock extends RenderBlockBase {
68
69 // sizes itself to the height of its child stack
70
71 RenderBlock({ List<RenderBox> children }) : super(children: children);
72
29 double getMinIntrinsicWidth(BoxConstraints constraints) { 73 double getMinIntrinsicWidth(BoxConstraints constraints) {
30 double width = 0.0; 74 double width = 0.0;
31 BoxConstraints innerConstraints = constraints.widthConstraints(); 75 BoxConstraints innerConstraints = constraints.widthConstraints();
32 RenderBox child = firstChild; 76 RenderBox child = firstChild;
33 while (child != null) { 77 while (child != null) {
34 width = math.max(width, child.getMinIntrinsicWidth(innerConstraints)); 78 width = math.max(width, child.getMinIntrinsicWidth(innerConstraints));
35 assert(child.parentData is BlockParentData); 79 assert(child.parentData is BlockParentData);
36 child = child.parentData.nextSibling; 80 child = child.parentData.nextSibling;
37 } 81 }
38 return width; 82 return width;
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
70 } 114 }
71 115
72 double getMinIntrinsicHeight(BoxConstraints constraints) { 116 double getMinIntrinsicHeight(BoxConstraints constraints) {
73 return _getIntrinsicHeight(constraints); 117 return _getIntrinsicHeight(constraints);
74 } 118 }
75 119
76 double getMaxIntrinsicHeight(BoxConstraints constraints) { 120 double getMaxIntrinsicHeight(BoxConstraints constraints) {
77 return _getIntrinsicHeight(constraints); 121 return _getIntrinsicHeight(constraints);
78 } 122 }
79 123
80 double computeDistanceToActualBaseline(TextBaseline baseline) {
81 return defaultComputeDistanceToFirstActualBaseline(baseline);
82 }
83
84 double _childrenHeight;
85 double get childrenHeight => _childrenHeight;
86
87 void markNeedsLayout() {
88 _childrenHeight = null;
89 super.markNeedsLayout();
90 }
91
92 void performLayout() {
93 assert(constraints is BoxConstraints);
94 double width = constraints.constrainWidth(constraints.maxWidth);
95 BoxConstraints innerConstraints = _getInnerConstraintsForWidth(width);
96 double y = 0.0;
97 RenderBox child = firstChild;
98 while (child != null) {
99 child.layout(innerConstraints, parentUsesSize: true);
100 assert(child.parentData is BlockParentData);
101 child.parentData.position = new Point(0.0, y);
102 y += child.size.height;
103 child = child.parentData.nextSibling;
104 }
105 _childrenHeight = y;
106 }
107
108 void hitTestChildren(HitTestResult result, { Point position }) {
109 defaultHitTestChildren(result, position: position);
110 }
111
112 void paint(PaintingCanvas canvas, Offset offset) {
113 defaultPaint(canvas, offset);
114 }
115
116 }
117
118 class RenderBlock extends RenderBlockBase {
119
120 // sizes itself to the height of its child stack
121
122 RenderBlock({ List<RenderBox> children }) : super(children: children);
123
124 bool _hasVisualOverflow = false; 124 bool _hasVisualOverflow = false;
125 125
126 void performLayout() { 126 void performLayout() {
127 super.performLayout(); 127 super.performLayout();
128 size = constraints.constrain(new Size(constraints.maxWidth, childrenHeight)) ; 128 size = constraints.constrain(new Size(constraints.maxWidth, childrenHeight)) ;
129 assert(!size.isInfinite); 129 assert(!size.isInfinite);
130 130
131 // FIXME(eseidel): Block lays out its children with unconstrained height 131 // FIXME(eseidel): Block lays out its children with unconstrained height
132 // yet itself remains constrained. Remember that our children wanted to 132 // yet itself remains constrained. Remember that our children wanted to
133 // be taller than we are so we know to clip them (and not cause confusing 133 // be taller than we are so we know to clip them (and not cause confusing
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
175 double _startOffset; 175 double _startOffset;
176 double get startOffset => _startOffset; 176 double get startOffset => _startOffset;
177 void set startOffset(double value) { 177 void set startOffset(double value) {
178 if (value == _startOffset) 178 if (value == _startOffset)
179 return; 179 return;
180 _startOffset = value; 180 _startOffset = value;
181 if (!_inCallback) 181 if (!_inCallback)
182 markNeedsLayout(); 182 markNeedsLayout();
183 } 183 }
184 184
185 double getMinIntrinsicWidth(BoxConstraints constraints) {
186 return constraints.constrainWidth();
187 }
188
189 double getMaxIntrinsicWidth(BoxConstraints constraints) {
190 return constraints.constrainWidth();
191 }
192
193 double getMinIntrinsicHeight(BoxConstraints constraints) {
194 return constraints.constrainHeight();
195 }
196
197 double getMaxIntrinsicHeight(BoxConstraints constraints) {
198 return constraints.constrainHeight();
199 }
200
185 bool get sizedByParent => true; 201 bool get sizedByParent => true;
186 202
187 void performResize() { 203 void performResize() {
188 size = constraints.biggest; 204 size = constraints.biggest;
189 assert(!size.isInfinite); 205 assert(!size.isInfinite);
190 } 206 }
191 207
192 bool get debugDoesLayoutWithCallback => true; 208 bool get debugDoesLayoutWithCallback => true;
193 void performLayout() { 209 void performLayout() {
194 if (_callback != null) { 210 if (_callback != null) {
195 try { 211 try {
196 _inCallback = true; 212 _inCallback = true;
197 invokeLayoutCallback(_callback); 213 invokeLayoutCallback(_callback);
198 } finally { 214 } finally {
199 _inCallback = false; 215 _inCallback = false;
200 } 216 }
201 } 217 }
202 super.performLayout(); 218 super.performLayout();
203 } 219 }
204 220
205 void paint(PaintingCanvas canvas, Offset offset) { 221 void paint(PaintingCanvas canvas, Offset offset) {
206 canvas.save(); 222 canvas.save();
207 canvas.clipRect(offset & size); 223 canvas.clipRect(offset & size);
208 super.paint(canvas, offset.translate(0.0, _startOffset)); 224 super.paint(canvas, offset.translate(0.0, _startOffset));
209 canvas.restore(); 225 canvas.restore();
210 } 226 }
211 227
212 } 228 }
213 229
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698