| 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 FlexBoxParentData extends BoxParentData with ContainerParentDataMixin<Rend
erBox> { | 8 class FlexBoxParentData extends BoxParentData with ContainerParentDataMixin<Rend
erBox> { |
| 10 int flex; | 9 int flex; |
| 11 void merge(FlexBoxParentData other) { | 10 void merge(FlexBoxParentData other) { |
| 12 if (other.flex != null) | 11 if (other.flex != null) |
| 13 flex = other.flex; | 12 flex = other.flex; |
| 14 super.merge(other); | 13 super.merge(other); |
| 15 } | 14 } |
| (...skipping 19 matching lines...) Expand all Loading... |
| 35 } | 34 } |
| 36 } | 35 } |
| 37 | 36 |
| 38 void setParentData(RenderBox child) { | 37 void setParentData(RenderBox child) { |
| 39 if (child.parentData is! FlexBoxParentData) | 38 if (child.parentData is! FlexBoxParentData) |
| 40 child.parentData = new FlexBoxParentData(); | 39 child.parentData = new FlexBoxParentData(); |
| 41 } | 40 } |
| 42 | 41 |
| 43 bool get sizedByParent => true; | 42 bool get sizedByParent => true; |
| 44 void performResize() { | 43 void performResize() { |
| 45 size = constraints.constrain(new sky.Size(constraints.maxWidth, constraints.
maxHeight)); | 44 size = constraints.constrain(new Size(constraints.maxWidth, constraints.maxH
eight)); |
| 46 assert(size.height < double.INFINITY); | 45 assert(size.height < double.INFINITY); |
| 47 assert(size.width < double.INFINITY); | 46 assert(size.width < double.INFINITY); |
| 48 } | 47 } |
| 49 | 48 |
| 50 int _getFlex(RenderBox child) { | 49 int _getFlex(RenderBox child) { |
| 51 assert(child.parentData is FlexBoxParentData); | 50 assert(child.parentData is FlexBoxParentData); |
| 52 return child.parentData.flex != null ? child.parentData.flex : 0; | 51 return child.parentData.flex != null ? child.parentData.flex : 0; |
| 53 } | 52 } |
| 54 | 53 |
| 55 void performLayout() { | 54 void performLayout() { |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 92 maxHeight: spaceForChild, | 91 maxHeight: spaceForChild, |
| 93 maxWidth: constraints.maxWidth
); | 92 maxWidth: constraints.maxWidth
); |
| 94 break; | 93 break; |
| 95 } | 94 } |
| 96 child.layout(innerConstraints, parentUsesSize: true); | 95 child.layout(innerConstraints, parentUsesSize: true); |
| 97 } | 96 } |
| 98 | 97 |
| 99 // For now, center the flex items in the cross direction | 98 // For now, center the flex items in the cross direction |
| 100 switch (_direction) { | 99 switch (_direction) { |
| 101 case FlexDirection.horizontal: | 100 case FlexDirection.horizontal: |
| 102 child.parentData.position = new sky.Point(usedSpace, size.height / 2.0
- child.size.height / 2.0); | 101 child.parentData.position = new Point(usedSpace, size.height / 2.0 - c
hild.size.height / 2.0); |
| 103 usedSpace += child.size.width; | 102 usedSpace += child.size.width; |
| 104 break; | 103 break; |
| 105 case FlexDirection.vertical: | 104 case FlexDirection.vertical: |
| 106 child.parentData.position = new sky.Point(size.width / 2.0 - child.siz
e.width / 2.0, usedSpace); | 105 child.parentData.position = new Point(size.width / 2.0 - child.size.wi
dth / 2.0, usedSpace); |
| 107 usedSpace += child.size.height; | 106 usedSpace += child.size.height; |
| 108 break; | 107 break; |
| 109 } | 108 } |
| 110 child = child.parentData.nextSibling; | 109 child = child.parentData.nextSibling; |
| 111 } | 110 } |
| 112 } | 111 } |
| 113 | 112 |
| 114 void hitTestChildren(HitTestResult result, { sky.Point position }) { | 113 void hitTestChildren(HitTestResult result, { Point position }) { |
| 115 defaultHitTestChildren(result, position: position); | 114 defaultHitTestChildren(result, position: position); |
| 116 } | 115 } |
| 117 | 116 |
| 118 void paint(RenderObjectDisplayList canvas) { | 117 void paint(RenderObjectDisplayList canvas) { |
| 119 defaultPaint(canvas); | 118 defaultPaint(canvas); |
| 120 } | 119 } |
| 121 } | 120 } |
| OLD | NEW |