| 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 StackParentData extends BoxParentData with ContainerParentDataMixin<Render
Box> { | 10 class StackParentData extends BoxParentData with ContainerParentDataMixin<Render
Box> { |
| 11 double top; | 11 double top; |
| 12 double right; | 12 double right; |
| 13 double bottom; | 13 double bottom; |
| 14 double left; | 14 double left; |
| 15 | 15 |
| 16 @override |
| 16 void merge(StackParentData other) { | 17 void merge(StackParentData other) { |
| 17 if (other.top != null) | 18 if (other.top != null) |
| 18 top = other.top; | 19 top = other.top; |
| 19 if (other.right != null) | 20 if (other.right != null) |
| 20 right = other.right; | 21 right = other.right; |
| 21 if (other.bottom != null) | 22 if (other.bottom != null) |
| 22 bottom = other.bottom; | 23 bottom = other.bottom; |
| 23 if (other.left != null) | 24 if (other.left != null) |
| 24 left = other.left; | 25 left = other.left; |
| 25 super.merge(other); | 26 super.merge(other); |
| 26 } | 27 } |
| 27 | 28 |
| 28 bool get isPositioned => top != null || right != null || bottom != null || lef
t != null; | 29 bool get isPositioned => top != null || right != null || bottom != null || lef
t != null; |
| 29 | 30 |
| 31 @override |
| 30 String toString() => '${super.toString()}; top=$top; right=$right; bottom=$bot
tom, left=$left'; | 32 String toString() => '${super.toString()}; top=$top; right=$right; bottom=$bot
tom, left=$left'; |
| 31 } | 33 } |
| 32 | 34 |
| 33 class RenderStack extends RenderBox with ContainerRenderObjectMixin<RenderBox, S
tackParentData>, | 35 class RenderStack extends RenderBox with ContainerRenderObjectMixin<RenderBox, S
tackParentData>, |
| 34 RenderBoxContainerDefaultsMixin<RenderB
ox, StackParentData> { | 36 RenderBoxContainerDefaultsMixin<RenderB
ox, StackParentData> { |
| 35 RenderStack({ | 37 RenderStack({ |
| 36 List<RenderBox> children | 38 List<RenderBox> children |
| 37 }) { | 39 }) { |
| 38 addAll(children); | 40 addAll(children); |
| 39 } | 41 } |
| 40 | 42 |
| 43 @override |
| 41 void setupParentData(RenderBox child) { | 44 void setupParentData(RenderBox child) { |
| 42 if (child.parentData is! StackParentData) | 45 if (child.parentData is! StackParentData) |
| 43 child.parentData = new StackParentData(); | 46 child.parentData = new StackParentData(); |
| 44 } | 47 } |
| 45 | 48 |
| 46 | 49 @override |
| 47 double getMinIntrinsicWidth(BoxConstraints constraints) { | 50 double getMinIntrinsicWidth(BoxConstraints constraints) { |
| 48 double width = constraints.minWidth; | 51 double width = constraints.minWidth; |
| 49 RenderBox child = firstChild; | 52 RenderBox child = firstChild; |
| 50 while (child != null) { | 53 while (child != null) { |
| 51 assert(child.parentData is StackParentData); | 54 assert(child.parentData is StackParentData); |
| 52 if (!child.parentData.isPositioned) | 55 if (!child.parentData.isPositioned) |
| 53 width = math.max(width, child.getMinIntrinsicWidth(constraints)); | 56 width = math.max(width, child.getMinIntrinsicWidth(constraints)); |
| 54 child = child.parentData.nextSibling; | 57 child = child.parentData.nextSibling; |
| 55 } | 58 } |
| 56 assert(width == constraints.constrainWidth(width)); | 59 assert(width == constraints.constrainWidth(width)); |
| 57 return width; | 60 return width; |
| 58 } | 61 } |
| 59 | 62 |
| 63 @override |
| 60 double getMaxIntrinsicWidth(BoxConstraints constraints) { | 64 double getMaxIntrinsicWidth(BoxConstraints constraints) { |
| 61 bool hasNonPositionedChildren = false; | 65 bool hasNonPositionedChildren = false; |
| 62 double width = constraints.minWidth; | 66 double width = constraints.minWidth; |
| 63 RenderBox child = firstChild; | 67 RenderBox child = firstChild; |
| 64 while (child != null) { | 68 while (child != null) { |
| 65 assert(child.parentData is StackParentData); | 69 assert(child.parentData is StackParentData); |
| 66 if (!child.parentData.isPositioned) { | 70 if (!child.parentData.isPositioned) { |
| 67 hasNonPositionedChildren = true; | 71 hasNonPositionedChildren = true; |
| 68 width = math.max(width, child.getMaxIntrinsicWidth(constraints)); | 72 width = math.max(width, child.getMaxIntrinsicWidth(constraints)); |
| 69 } | 73 } |
| 70 child = child.parentData.nextSibling; | 74 child = child.parentData.nextSibling; |
| 71 } | 75 } |
| 72 if (!hasNonPositionedChildren) | 76 if (!hasNonPositionedChildren) |
| 73 return constraints.constrainWidth(); | 77 return constraints.constrainWidth(); |
| 74 assert(width == constraints.constrainWidth(width)); | 78 assert(width == constraints.constrainWidth(width)); |
| 75 return width; | 79 return width; |
| 76 } | 80 } |
| 77 | 81 |
| 82 @override |
| 78 double getMinIntrinsicHeight(BoxConstraints constraints) { | 83 double getMinIntrinsicHeight(BoxConstraints constraints) { |
| 79 double height = constraints.minHeight; | 84 double height = constraints.minHeight; |
| 80 RenderBox child = firstChild; | 85 RenderBox child = firstChild; |
| 81 while (child != null) { | 86 while (child != null) { |
| 82 assert(child.parentData is StackParentData); | 87 assert(child.parentData is StackParentData); |
| 83 if (!child.parentData.isPositioned) | 88 if (!child.parentData.isPositioned) |
| 84 height = math.max(height, child.getMinIntrinsicHeight(constraints)); | 89 height = math.max(height, child.getMinIntrinsicHeight(constraints)); |
| 85 child = child.parentData.nextSibling; | 90 child = child.parentData.nextSibling; |
| 86 } | 91 } |
| 87 assert(height == constraints.constrainHeight(height)); | 92 assert(height == constraints.constrainHeight(height)); |
| 88 return height; | 93 return height; |
| 89 } | 94 } |
| 90 | 95 |
| 96 @override |
| 91 double getMaxIntrinsicHeight(BoxConstraints constraints) { | 97 double getMaxIntrinsicHeight(BoxConstraints constraints) { |
| 92 bool hasNonPositionedChildren = false; | 98 bool hasNonPositionedChildren = false; |
| 93 double height = constraints.minHeight; | 99 double height = constraints.minHeight; |
| 94 RenderBox child = firstChild; | 100 RenderBox child = firstChild; |
| 95 while (child != null) { | 101 while (child != null) { |
| 96 assert(child.parentData is StackParentData); | 102 assert(child.parentData is StackParentData); |
| 97 if (!child.parentData.isPositioned) { | 103 if (!child.parentData.isPositioned) { |
| 98 hasNonPositionedChildren = true; | 104 hasNonPositionedChildren = true; |
| 99 height = math.max(height, child.getMaxIntrinsicHeight(constraints)); | 105 height = math.max(height, child.getMaxIntrinsicHeight(constraints)); |
| 100 } | 106 } |
| 101 child = child.parentData.nextSibling; | 107 child = child.parentData.nextSibling; |
| 102 } | 108 } |
| 103 if (!hasNonPositionedChildren) | 109 if (!hasNonPositionedChildren) |
| 104 return constraints.constrainHeight(); | 110 return constraints.constrainHeight(); |
| 105 assert(height == constraints.constrainHeight(height)); | 111 assert(height == constraints.constrainHeight(height)); |
| 106 return height; | 112 return height; |
| 107 } | 113 } |
| 108 | 114 |
| 115 @override |
| 109 double computeDistanceToActualBaseline(TextBaseline baseline) { | 116 double computeDistanceToActualBaseline(TextBaseline baseline) { |
| 110 return defaultComputeDistanceToHighestActualBaseline(baseline); | 117 return defaultComputeDistanceToHighestActualBaseline(baseline); |
| 111 } | 118 } |
| 112 | 119 |
| 120 @override |
| 113 void performLayout() { | 121 void performLayout() { |
| 114 bool hasNonPositionedChildren = false; | 122 bool hasNonPositionedChildren = false; |
| 115 | 123 |
| 116 double width = 0.0; | 124 double width = 0.0; |
| 117 double height = 0.0; | 125 double height = 0.0; |
| 118 | 126 |
| 119 RenderBox child = firstChild; | 127 RenderBox child = firstChild; |
| 120 while (child != null) { | 128 while (child != null) { |
| 121 assert(child.parentData is StackParentData); | 129 assert(child.parentData is StackParentData); |
| 122 final StackParentData parentData = child.parentData; | 130 final StackParentData parentData = child.parentData; |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 184 y = size.height - childData.bottom - child.size.height; | 192 y = size.height - childData.bottom - child.size.height; |
| 185 assert(y >= 0.0 && y + child.size.height <= size.height); | 193 assert(y >= 0.0 && y + child.size.height <= size.height); |
| 186 | 194 |
| 187 childData.position = new Point(x, y); | 195 childData.position = new Point(x, y); |
| 188 } | 196 } |
| 189 | 197 |
| 190 child = childData.nextSibling; | 198 child = childData.nextSibling; |
| 191 } | 199 } |
| 192 } | 200 } |
| 193 | 201 |
| 202 @override |
| 194 void hitTestChildren(HitTestResult result, { Point position }) { | 203 void hitTestChildren(HitTestResult result, { Point position }) { |
| 195 defaultHitTestChildren(result, position: position); | 204 defaultHitTestChildren(result, position: position); |
| 196 } | 205 } |
| 197 | 206 |
| 207 @override |
| 198 void paint(PaintingCanvas canvas, Offset offset) { | 208 void paint(PaintingCanvas canvas, Offset offset) { |
| 199 defaultPaint(canvas, offset); | 209 defaultPaint(canvas, offset); |
| 200 } | 210 } |
| 201 } | 211 } |
| OLD | NEW |