Add RenderObject.childCount

R=ianh@google.com

Review URL: https://codereview.chromium.org/1217533002.
This commit is contained in:
Hans Muller 2015-06-26 11:17:31 -07:00
parent ce7e8260c3
commit 06af2f7d15
2 changed files with 7 additions and 18 deletions

View File

@ -367,7 +367,6 @@ abstract class ContainerParentDataMixin<ChildType extends RenderObject> {
}
abstract class ContainerRenderObjectMixin<ChildType extends RenderObject, ParentDataType extends ContainerParentDataMixin<ChildType>> implements RenderObject {
// abstract class that has only InlineNode children
bool _debugUltimatePreviousSiblingOf(ChildType child, { ChildType equals }) {
assert(child.parentData is ParentDataType);
@ -388,12 +387,17 @@ abstract class ContainerRenderObjectMixin<ChildType extends RenderObject, Parent
return child == equals;
}
int _childCount = 0;
int get childCount => _childCount;
ChildType _firstChild;
ChildType _lastChild;
void _addToChildList(ChildType child, { ChildType before }) {
assert(child.parentData is ParentDataType);
assert(child.parentData.nextSibling == null);
assert(child.parentData.previousSibling == null);
_childCount += 1;
assert(_childCount > 0);
if (before == null) {
// append at the end (_lastChild)
child.parentData.previousSibling = _lastChild;
@ -448,6 +452,8 @@ abstract class ContainerRenderObjectMixin<ChildType extends RenderObject, Parent
assert(child.parentData is ParentDataType);
assert(_debugUltimatePreviousSiblingOf(child, equals: _firstChild));
assert(_debugUltimateNextSiblingOf(child, equals: _lastChild));
_childCount -= 1;
assert(_childCount > 0);
if (child.parentData.previousSibling == null) {
assert(_firstChild == child);
_firstChild = child.parentData.nextSibling;

View File

@ -63,11 +63,9 @@ class RenderTabBar extends RenderBox with
BoxConstraints widthConstraints =
new BoxConstraints(maxWidth: constraints.maxWidth, maxHeight: constraints.maxHeight);
double maxWidth = 0.0;
int childCount = 0;
RenderBox child = firstChild;
while (child != null) {
maxWidth = math.max(maxWidth, child.getMinIntrinsicWidth(widthConstraints));
++childCount;
assert(child.parentData is TabBarParentData);
child = child.parentData.nextSibling;
}
@ -78,11 +76,9 @@ class RenderTabBar extends RenderBox with
BoxConstraints widthConstraints =
new BoxConstraints(maxWidth: constraints.maxWidth, maxHeight: constraints.maxHeight);
double maxWidth = 0.0;
int childCount = 0;
RenderBox child = firstChild;
while (child != null) {
maxWidth = math.max(maxWidth, child.getMaxIntrinsicWidth(widthConstraints));
++childCount;
assert(child.parentData is TabBarParentData);
child = child.parentData.nextSibling;
}
@ -95,25 +91,12 @@ class RenderTabBar extends RenderBox with
double getMaxIntrinsicHeight(BoxConstraints constraints) => _getIntrinsicHeight(constraints);
// TODO(hansmuller): track this value in the parent rather than computing it.
int _childCount() {
int childCount = 0;
RenderBox child = firstChild;
while (child != null) {
++childCount;
assert(child.parentData is TabBarParentData);
child = child.parentData.nextSibling;
}
return childCount;
}
void performLayout() {
assert(constraints is BoxConstraints);
size = constraints.constrain(new Size(constraints.maxWidth, _kTabBarHeight));
assert(!size.isInfinite);
int childCount = _childCount();
if (childCount == 0)
return;