| OLD | NEW |
| 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 @override |
| 24 void setupParentData(RenderBox child) { | 25 void setupParentData(RenderBox child) { |
| 25 if (child.parentData is! BlockParentData) | 26 if (child.parentData is! BlockParentData) |
| 26 child.parentData = new BlockParentData(); | 27 child.parentData = new BlockParentData(); |
| 27 } | 28 } |
| 28 | 29 |
| 29 double _childrenHeight; | 30 double _childrenHeight; |
| 30 double get childrenHeight => _childrenHeight; | 31 double get childrenHeight => _childrenHeight; |
| 31 | 32 |
| 33 @override |
| 32 void markNeedsLayout() { | 34 void markNeedsLayout() { |
| 33 _childrenHeight = null; | 35 _childrenHeight = null; |
| 34 super.markNeedsLayout(); | 36 super.markNeedsLayout(); |
| 35 } | 37 } |
| 36 | 38 |
| 39 @override |
| 37 void performLayout() { | 40 void performLayout() { |
| 38 assert(constraints is BoxConstraints); | 41 assert(constraints is BoxConstraints); |
| 39 double width = constraints.constrainWidth(constraints.maxWidth); | 42 double width = constraints.constrainWidth(constraints.maxWidth); |
| 40 BoxConstraints innerConstraints = new BoxConstraints.tightFor(width: width); | 43 BoxConstraints innerConstraints = new BoxConstraints.tightFor(width: width); |
| 41 double y = 0.0; | 44 double y = 0.0; |
| 42 RenderBox child = firstChild; | 45 RenderBox child = firstChild; |
| 43 while (child != null) { | 46 while (child != null) { |
| 44 child.layout(innerConstraints, parentUsesSize: true); | 47 child.layout(innerConstraints, parentUsesSize: true); |
| 45 assert(child.parentData is BlockParentData); | 48 assert(child.parentData is BlockParentData); |
| 46 child.parentData.position = new Point(0.0, y); | 49 child.parentData.position = new Point(0.0, y); |
| 47 y += child.size.height; | 50 y += child.size.height; |
| 48 child = child.parentData.nextSibling; | 51 child = child.parentData.nextSibling; |
| 49 } | 52 } |
| 50 _childrenHeight = y; | 53 _childrenHeight = y; |
| 51 } | 54 } |
| 52 | 55 |
| 53 } | 56 } |
| 54 | 57 |
| 55 class RenderBlock extends RenderBlockBase { | 58 class RenderBlock extends RenderBlockBase { |
| 56 | 59 |
| 57 // sizes itself to the height of its child stack | 60 // sizes itself to the height of its child stack |
| 58 | 61 |
| 59 RenderBlock({ List<RenderBox> children }) : super(children: children); | 62 RenderBlock({ List<RenderBox> children }) : super(children: children); |
| 60 | 63 |
| 64 @override |
| 61 double getMinIntrinsicWidth(BoxConstraints constraints) { | 65 double getMinIntrinsicWidth(BoxConstraints constraints) { |
| 62 double width = 0.0; | 66 double width = 0.0; |
| 63 BoxConstraints innerConstraints = constraints.widthConstraints(); | 67 BoxConstraints innerConstraints = constraints.widthConstraints(); |
| 64 RenderBox child = firstChild; | 68 RenderBox child = firstChild; |
| 65 while (child != null) { | 69 while (child != null) { |
| 66 width = math.max(width, child.getMinIntrinsicWidth(innerConstraints)); | 70 width = math.max(width, child.getMinIntrinsicWidth(innerConstraints)); |
| 67 assert(child.parentData is BlockParentData); | 71 assert(child.parentData is BlockParentData); |
| 68 child = child.parentData.nextSibling; | 72 child = child.parentData.nextSibling; |
| 69 } | 73 } |
| 70 return width; | 74 return width; |
| 71 } | 75 } |
| 72 | 76 |
| 77 @override |
| 73 double getMaxIntrinsicWidth(BoxConstraints constraints) { | 78 double getMaxIntrinsicWidth(BoxConstraints constraints) { |
| 74 double width = 0.0; | 79 double width = 0.0; |
| 75 BoxConstraints innerConstraints = constraints.widthConstraints(); | 80 BoxConstraints innerConstraints = constraints.widthConstraints(); |
| 76 RenderBox child = firstChild; | 81 RenderBox child = firstChild; |
| 77 while (child != null) { | 82 while (child != null) { |
| 78 width = math.max(width, child.getMaxIntrinsicWidth(innerConstraints)); | 83 width = math.max(width, child.getMaxIntrinsicWidth(innerConstraints)); |
| 79 assert(child.parentData is BlockParentData); | 84 assert(child.parentData is BlockParentData); |
| 80 child = child.parentData.nextSibling; | 85 child = child.parentData.nextSibling; |
| 81 } | 86 } |
| 82 return width; | 87 return width; |
| 83 } | 88 } |
| 84 | 89 |
| 85 double _getIntrinsicHeight(BoxConstraints constraints) { | 90 double _getIntrinsicHeight(BoxConstraints constraints) { |
| 86 double height = 0.0; | 91 double height = 0.0; |
| 87 double width = constraints.constrainWidth(constraints.maxWidth); | 92 double width = constraints.constrainWidth(constraints.maxWidth); |
| 88 BoxConstraints innerConstraints = new BoxConstraints.tightFor(width: width); | 93 BoxConstraints innerConstraints = new BoxConstraints.tightFor(width: width); |
| 89 RenderBox child = firstChild; | 94 RenderBox child = firstChild; |
| 90 while (child != null) { | 95 while (child != null) { |
| 91 double childHeight = child.getMinIntrinsicHeight(innerConstraints); | 96 double childHeight = child.getMinIntrinsicHeight(innerConstraints); |
| 92 assert(childHeight == child.getMaxIntrinsicHeight(innerConstraints)); | 97 assert(childHeight == child.getMaxIntrinsicHeight(innerConstraints)); |
| 93 height += childHeight; | 98 height += childHeight; |
| 94 assert(child.parentData is BlockParentData); | 99 assert(child.parentData is BlockParentData); |
| 95 child = child.parentData.nextSibling; | 100 child = child.parentData.nextSibling; |
| 96 } | 101 } |
| 97 return height; | 102 return height; |
| 98 } | 103 } |
| 99 | 104 |
| 105 @override |
| 100 double getMinIntrinsicHeight(BoxConstraints constraints) { | 106 double getMinIntrinsicHeight(BoxConstraints constraints) { |
| 101 return _getIntrinsicHeight(constraints); | 107 return _getIntrinsicHeight(constraints); |
| 102 } | 108 } |
| 103 | 109 |
| 110 @override |
| 104 double getMaxIntrinsicHeight(BoxConstraints constraints) { | 111 double getMaxIntrinsicHeight(BoxConstraints constraints) { |
| 105 return _getIntrinsicHeight(constraints); | 112 return _getIntrinsicHeight(constraints); |
| 106 } | 113 } |
| 107 | 114 |
| 108 double computeDistanceToActualBaseline(TextBaseline baseline) { | 115 double computeDistanceToActualBaseline(TextBaseline baseline) { |
| 109 return defaultComputeDistanceToFirstActualBaseline(baseline); | 116 return defaultComputeDistanceToFirstActualBaseline(baseline); |
| 110 } | 117 } |
| 111 | 118 |
| 112 bool _hasVisualOverflow = false; | 119 bool _hasVisualOverflow = false; |
| 113 | 120 |
| 121 @override |
| 114 void performLayout() { | 122 void performLayout() { |
| 115 super.performLayout(); | 123 super.performLayout(); |
| 116 size = constraints.constrain(new Size(constraints.maxWidth, childrenHeight))
; | 124 size = constraints.constrain(new Size(constraints.maxWidth, childrenHeight))
; |
| 117 assert(!size.isInfinite); | 125 assert(!size.isInfinite); |
| 118 | 126 |
| 119 // FIXME(eseidel): Block lays out its children with unconstrained height | 127 // FIXME(eseidel): Block lays out its children with unconstrained height |
| 120 // yet itself remains constrained. Remember that our children wanted to | 128 // yet itself remains constrained. Remember that our children wanted to |
| 121 // be taller than we are so we know to clip them (and not cause confusing | 129 // be taller than we are so we know to clip them (and not cause confusing |
| 122 // mismatch of painting vs. hittesting). | 130 // mismatch of painting vs. hittesting). |
| 123 _hasVisualOverflow = childrenHeight > size.height; | 131 _hasVisualOverflow = childrenHeight > size.height; |
| 124 } | 132 } |
| 125 | 133 |
| 134 @override |
| 126 void paint(PaintingCanvas canvas, Offset offset) { | 135 void paint(PaintingCanvas canvas, Offset offset) { |
| 127 if (_hasVisualOverflow) { | 136 if (_hasVisualOverflow) { |
| 128 canvas.save(); | 137 canvas.save(); |
| 129 canvas.clipRect(offset & size); | 138 canvas.clipRect(offset & size); |
| 130 } | 139 } |
| 131 defaultPaint(canvas, offset); | 140 defaultPaint(canvas, offset); |
| 132 if (_hasVisualOverflow) { | 141 if (_hasVisualOverflow) { |
| 133 canvas.restore(); | 142 canvas.restore(); |
| 134 } | 143 } |
| 135 } | 144 } |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 167 double _startOffset; | 176 double _startOffset; |
| 168 double get startOffset => _startOffset; | 177 double get startOffset => _startOffset; |
| 169 void set startOffset(double value) { | 178 void set startOffset(double value) { |
| 170 if (value == _startOffset) | 179 if (value == _startOffset) |
| 171 return; | 180 return; |
| 172 _startOffset = value; | 181 _startOffset = value; |
| 173 if (!_inCallback) | 182 if (!_inCallback) |
| 174 markNeedsPaint(); | 183 markNeedsPaint(); |
| 175 } | 184 } |
| 176 | 185 |
| 186 @override |
| 177 double getMinIntrinsicWidth(BoxConstraints constraints) { | 187 double getMinIntrinsicWidth(BoxConstraints constraints) { |
| 178 return constraints.constrainWidth(); | 188 return constraints.constrainWidth(); |
| 179 } | 189 } |
| 180 | 190 |
| 191 @override |
| 181 double getMaxIntrinsicWidth(BoxConstraints constraints) { | 192 double getMaxIntrinsicWidth(BoxConstraints constraints) { |
| 182 return constraints.constrainWidth(); | 193 return constraints.constrainWidth(); |
| 183 } | 194 } |
| 184 | 195 |
| 196 @override |
| 185 double getMinIntrinsicHeight(BoxConstraints constraints) { | 197 double getMinIntrinsicHeight(BoxConstraints constraints) { |
| 186 return constraints.constrainHeight(); | 198 return constraints.constrainHeight(); |
| 187 } | 199 } |
| 188 | 200 |
| 201 @override |
| 189 double getMaxIntrinsicHeight(BoxConstraints constraints) { | 202 double getMaxIntrinsicHeight(BoxConstraints constraints) { |
| 190 return constraints.constrainHeight(); | 203 return constraints.constrainHeight(); |
| 191 } | 204 } |
| 192 | 205 |
| 193 // We don't override computeDistanceToActualBaseline(), because we | 206 // We don't override computeDistanceToActualBaseline(), because we |
| 194 // want the default behaviour (returning null). Otherwise, as you | 207 // want the default behaviour (returning null). Otherwise, as you |
| 195 // scroll the RenderBlockViewport, it would shift in its parent if | 208 // scroll the RenderBlockViewport, it would shift in its parent if |
| 196 // the parent was baseline-aligned, which makes no sense. | 209 // the parent was baseline-aligned, which makes no sense. |
| 197 | 210 |
| 211 @override |
| 198 bool get sizedByParent => true; | 212 bool get sizedByParent => true; |
| 199 | 213 |
| 214 @override |
| 200 void performResize() { | 215 void performResize() { |
| 201 size = constraints.biggest; | 216 size = constraints.biggest; |
| 202 assert(!size.isInfinite); | 217 assert(!size.isInfinite); |
| 203 } | 218 } |
| 204 | 219 |
| 205 bool get debugDoesLayoutWithCallback => true; | 220 bool get debugDoesLayoutWithCallback => true; |
| 221 |
| 222 @override |
| 206 void performLayout() { | 223 void performLayout() { |
| 207 if (_callback != null) { | 224 if (_callback != null) { |
| 208 try { | 225 try { |
| 209 _inCallback = true; | 226 _inCallback = true; |
| 210 invokeLayoutCallback(_callback); | 227 invokeLayoutCallback(_callback); |
| 211 } finally { | 228 } finally { |
| 212 _inCallback = false; | 229 _inCallback = false; |
| 213 } | 230 } |
| 214 } | 231 } |
| 215 super.performLayout(); | 232 super.performLayout(); |
| 216 } | 233 } |
| 217 | 234 |
| 235 @override |
| 218 void paint(PaintingCanvas canvas, Offset offset) { | 236 void paint(PaintingCanvas canvas, Offset offset) { |
| 219 canvas.save(); | 237 canvas.save(); |
| 220 canvas.clipRect(offset & size); | 238 canvas.clipRect(offset & size); |
| 221 defaultPaint(canvas, offset.translate(0.0, startOffset)); | 239 defaultPaint(canvas, offset.translate(0.0, startOffset)); |
| 222 canvas.restore(); | 240 canvas.restore(); |
| 223 } | 241 } |
| 224 | 242 |
| 243 @override |
| 225 void hitTestChildren(HitTestResult result, { Point position }) { | 244 void hitTestChildren(HitTestResult result, { Point position }) { |
| 226 defaultHitTestChildren(result, position: position + new Offset(0.0, -startOf
fset)); | 245 defaultHitTestChildren(result, position: position + new Offset(0.0, -startOf
fset)); |
| 227 } | 246 } |
| 228 | 247 |
| 229 } | 248 } |
| 230 | 249 |
| OLD | NEW |