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