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