| 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 class RenderBlock extends RenderBox with ContainerRenderObjectMixin<RenderBox, B
lockParentData>, | 12 class RenderBlock extends RenderBox with ContainerRenderObjectMixin<RenderBox, B
lockParentData>, |
| 13 RenderBoxContainerDefaultsMixin<RenderB
ox, BlockParentData> { | 13 RenderBoxContainerDefaultsMixin<RenderB
ox, BlockParentData> { |
| 14 // lays out RenderBox children in a vertical stack | 14 // lays out RenderBox children in a vertical stack |
| 15 // uses the maximum width provided by the parent | 15 // uses the maximum width provided by the parent |
| 16 // sizes itself to the height of its child stack | 16 // sizes itself to the height of its child stack |
| 17 | 17 |
| 18 bool _hasVisualOverflow = false; |
| 19 |
| 18 RenderBlock({ | 20 RenderBlock({ |
| 19 List<RenderBox> children | 21 List<RenderBox> children |
| 20 }) { | 22 }) { |
| 21 addAll(children); | 23 addAll(children); |
| 22 } | 24 } |
| 23 | 25 |
| 24 void setupParentData(RenderBox child) { | 26 void setupParentData(RenderBox child) { |
| 25 if (child.parentData is! BlockParentData) | 27 if (child.parentData is! BlockParentData) |
| 26 child.parentData = new BlockParentData(); | 28 child.parentData = new BlockParentData(); |
| 27 } | 29 } |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 87 BoxConstraints innerConstraints = _getInnerConstraintsForWidth(width); | 89 BoxConstraints innerConstraints = _getInnerConstraintsForWidth(width); |
| 88 double y = 0.0; | 90 double y = 0.0; |
| 89 RenderBox child = firstChild; | 91 RenderBox child = firstChild; |
| 90 while (child != null) { | 92 while (child != null) { |
| 91 child.layout(innerConstraints, parentUsesSize: true); | 93 child.layout(innerConstraints, parentUsesSize: true); |
| 92 assert(child.parentData is BlockParentData); | 94 assert(child.parentData is BlockParentData); |
| 93 child.parentData.position = new Point(0.0, y); | 95 child.parentData.position = new Point(0.0, y); |
| 94 y += child.size.height; | 96 y += child.size.height; |
| 95 child = child.parentData.nextSibling; | 97 child = child.parentData.nextSibling; |
| 96 } | 98 } |
| 99 // FIXME(eseidel): Block lays out its children with unconstrained height |
| 100 // yet itself remains constrained. Remember that our children wanted to |
| 101 // be taller than we are so we know to clip them (and not cause confusing |
| 102 // mismatch of painting vs. hittesting). |
| 97 size = new Size(width, constraints.constrainHeight(y)); | 103 size = new Size(width, constraints.constrainHeight(y)); |
| 104 _hasVisualOverflow = y > size.height; |
| 98 assert(!size.isInfinite); | 105 assert(!size.isInfinite); |
| 99 } | 106 } |
| 100 | 107 |
| 101 void hitTestChildren(HitTestResult result, { Point position }) { | 108 void hitTestChildren(HitTestResult result, { Point position }) { |
| 102 defaultHitTestChildren(result, position: position); | 109 defaultHitTestChildren(result, position: position); |
| 103 } | 110 } |
| 104 | 111 |
| 105 void paint(PaintingCanvas canvas, Offset offset) { | 112 void paint(PaintingCanvas canvas, Offset offset) { |
| 113 if (_hasVisualOverflow) { |
| 114 canvas.save(); |
| 115 canvas.clipRect(offset & size); |
| 116 } |
| 106 defaultPaint(canvas, offset); | 117 defaultPaint(canvas, offset); |
| 118 if (_hasVisualOverflow) { |
| 119 canvas.restore(); |
| 120 } |
| 107 } | 121 } |
| 108 | 122 |
| 109 } | 123 } |
| 110 | 124 |
| OLD | NEW |