OLD | NEW |
(Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 import 'dart:sky' as sky; |
| 6 import 'render_box.dart'; |
| 7 import 'render_node.dart'; |
| 8 |
| 9 class BlockParentData extends BoxParentData with ContainerParentDataMixin<Render
Box> { } |
| 10 |
| 11 class RenderBlock extends RenderBox with ContainerRenderNodeMixin<RenderBox, Blo
ckParentData>, |
| 12 RenderBoxContainerDefaultsMixin<RenderB
ox, BlockParentData> { |
| 13 // lays out RenderBox children in a vertical stack |
| 14 // uses the maximum width provided by the parent |
| 15 // sizes itself to the height of its child stack |
| 16 |
| 17 void setParentData(RenderBox child) { |
| 18 if (child.parentData is! BlockParentData) |
| 19 child.parentData = new BlockParentData(); |
| 20 } |
| 21 |
| 22 // override this to report what dimensions you would have if you |
| 23 // were laid out with the given constraints this can walk the tree |
| 24 // if it must, but it should be as cheap as possible; just get the |
| 25 // dimensions and nothing else (e.g. don't calculate hypothetical |
| 26 // child positions if they're not needed to determine dimensions) |
| 27 sky.Size getIntrinsicDimensions(BoxConstraints constraints) { |
| 28 double height = 0.0; |
| 29 double width = constraints.constrainWidth(constraints.maxWidth); |
| 30 assert(width < double.INFINITY); |
| 31 RenderBox child = firstChild; |
| 32 BoxConstraints innerConstraints = new BoxConstraints(minWidth: width, |
| 33 maxWidth: width); |
| 34 while (child != null) { |
| 35 height += child.getIntrinsicDimensions(innerConstraints).height; |
| 36 assert(child.parentData is BlockParentData); |
| 37 child = child.parentData.nextSibling; |
| 38 } |
| 39 |
| 40 return new sky.Size(width, constraints.constrainHeight(height)); |
| 41 } |
| 42 |
| 43 void performLayout() { |
| 44 assert(constraints is BoxConstraints); |
| 45 double width = constraints.constrainWidth(constraints.maxWidth); |
| 46 double y = 0.0; |
| 47 RenderBox child = firstChild; |
| 48 while (child != null) { |
| 49 child.layout(new BoxConstraints(minWidth: width, maxWidth: width), parentU
sesSize: true); |
| 50 assert(child.parentData is BlockParentData); |
| 51 child.parentData.position = new sky.Point(0.0, y); |
| 52 y += child.size.height; |
| 53 child = child.parentData.nextSibling; |
| 54 } |
| 55 size = new sky.Size(width, constraints.constrainHeight(y)); |
| 56 assert(size.width < double.INFINITY); |
| 57 assert(size.height < double.INFINITY); |
| 58 } |
| 59 |
| 60 void hitTestChildren(HitTestResult result, { sky.Point position }) { |
| 61 defaultHitTestChildren(result, position: position); |
| 62 } |
| 63 |
| 64 void paint(RenderNodeDisplayList canvas) { |
| 65 defaultPaint(canvas); |
| 66 } |
| 67 |
| 68 } |
| 69 |
OLD | NEW |