| 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 bool _hasVisualOverflow = false; | |
| 19 | |
| 20 RenderBlockBase({ | 18 RenderBlockBase({ |
| 21 List<RenderBox> children | 19 List<RenderBox> children |
| 22 }) { | 20 }) { |
| 23 addAll(children); | 21 addAll(children); |
| 24 } | 22 } |
| 25 | 23 |
| 26 void setupParentData(RenderBox child) { | 24 void setupParentData(RenderBox child) { |
| 27 if (child.parentData is! BlockParentData) | 25 if (child.parentData is! BlockParentData) |
| 28 child.parentData = new BlockParentData(); | 26 child.parentData = new BlockParentData(); |
| 29 } | 27 } |
| (...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 116 } | 114 } |
| 117 | 115 |
| 118 } | 116 } |
| 119 | 117 |
| 120 class RenderBlock extends RenderBlockBase { | 118 class RenderBlock extends RenderBlockBase { |
| 121 | 119 |
| 122 // sizes itself to the height of its child stack | 120 // sizes itself to the height of its child stack |
| 123 | 121 |
| 124 RenderBlock({ List<RenderBox> children }) : super(children: children); | 122 RenderBlock({ List<RenderBox> children }) : super(children: children); |
| 125 | 123 |
| 124 bool _hasVisualOverflow = false; |
| 125 |
| 126 void performLayout() { | 126 void performLayout() { |
| 127 super.performLayout(); | 127 super.performLayout(); |
| 128 size = constraints.constrain(new Size(constraints.maxWidth, childrenHeight))
; |
| 129 assert(!size.isInfinite); |
| 130 |
| 128 // FIXME(eseidel): Block lays out its children with unconstrained height | 131 // FIXME(eseidel): Block lays out its children with unconstrained height |
| 129 // yet itself remains constrained. Remember that our children wanted to | 132 // yet itself remains constrained. Remember that our children wanted to |
| 130 // 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 |
| 131 // mismatch of painting vs. hittesting). | 134 // mismatch of painting vs. hittesting). |
| 132 _hasVisualOverflow = childrenHeight > size.height; | 135 _hasVisualOverflow = childrenHeight > size.height; |
| 133 size = constraints.constrain(new Size(constraints.maxWidth, childrenHeight))
; | |
| 134 assert(!size.isInfinite); | |
| 135 } | 136 } |
| 136 | 137 |
| 137 void paint(PaintingCanvas canvas, Offset offset) { | 138 void paint(PaintingCanvas canvas, Offset offset) { |
| 138 if (_hasVisualOverflow) { | 139 if (_hasVisualOverflow) { |
| 139 canvas.save(); | 140 canvas.save(); |
| 140 canvas.clipRect(offset & size); | 141 canvas.clipRect(offset & size); |
| 141 } | 142 } |
| 142 super.paint(canvas, offset); | 143 super.paint(canvas, offset); |
| 143 if (_hasVisualOverflow) { | 144 if (_hasVisualOverflow) { |
| 144 canvas.restore(); | 145 canvas.restore(); |
| 145 } | 146 } |
| 146 } | 147 } |
| 147 | 148 |
| 148 } | 149 } |
| 149 | |
| OLD | NEW |