| 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 '../rendering/block.dart'; | 5 import '../rendering/block.dart'; |
| 6 import '../rendering/box.dart'; | 6 import '../rendering/box.dart'; |
| 7 import '../rendering/object.dart'; | 7 import '../rendering/object.dart'; |
| 8 import 'widget.dart'; | 8 import 'widget.dart'; |
| 9 | 9 |
| 10 // return null if index is greater than index of last entry | 10 // return null if index is greater than index of last entry |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 74 void didUnmount() { | 74 void didUnmount() { |
| 75 root.callback = null; | 75 root.callback = null; |
| 76 super.didUnmount(); | 76 super.didUnmount(); |
| 77 } | 77 } |
| 78 | 78 |
| 79 // _offsets contains the offsets of each child from the top of the | 79 // _offsets contains the offsets of each child from the top of the |
| 80 // list up to the last one we've ever created, and the offset of the | 80 // list up to the last one we've ever created, and the offset of the |
| 81 // end of the last one. If there's no children, then the only offset | 81 // end of the last one. If there's no children, then the only offset |
| 82 // is 0.0. | 82 // is 0.0. |
| 83 List<double> _offsets = <double>[0.0]; | 83 List<double> _offsets = <double>[0.0]; |
| 84 int _currentStartIndex = 0; |
| 85 int _currentChildCount = 0; |
| 84 | 86 |
| 85 int _findIndexForOffsetBeforeOrAt(double offset) { | 87 int _findIndexForOffsetBeforeOrAt(double offset) { |
| 86 int left = 0; | 88 int left = 0; |
| 87 int right = _offsets.length - 1; | 89 int right = _offsets.length - 1; |
| 88 while (right >= left) { | 90 while (right >= left) { |
| 89 int middle = left + ((right - left) ~/ 2); | 91 int middle = left + ((right - left) ~/ 2); |
| 90 if (_offsets[middle] < offset) { | 92 if (_offsets[middle] < offset) { |
| 91 left = middle + 1; | 93 left = middle + 1; |
| 92 } else if (_offsets[middle] > offset) { | 94 } else if (_offsets[middle] > offset) { |
| 93 right = middle - 1; | 95 right = middle - 1; |
| (...skipping 16 matching lines...) Expand all Loading... |
| 110 _dirty = true; | 112 _dirty = true; |
| 111 builder = newNode.builder; | 113 builder = newNode.builder; |
| 112 token = newNode.token; | 114 token = newNode.token; |
| 113 _offsets = <double>[0.0]; | 115 _offsets = <double>[0.0]; |
| 114 } | 116 } |
| 115 return true; | 117 return true; |
| 116 } | 118 } |
| 117 | 119 |
| 118 void syncRenderObject(BlockViewport old) { | 120 void syncRenderObject(BlockViewport old) { |
| 119 super.syncRenderObject(old); | 121 super.syncRenderObject(old); |
| 120 if (_dirty) | 122 if (_dirty) { |
| 121 root.markNeedsLayout(); | 123 root.markNeedsLayout(); |
| 124 } else { |
| 125 if (_currentChildCount > 0) { |
| 126 assert(_currentStartIndex >= 0); |
| 127 assert(builder != null); |
| 128 assert(root != null); |
| 129 int lastIndex = _currentStartIndex + _currentChildCount; |
| 130 for (int index = _currentStartIndex; index <= lastIndex; index += 1) { |
| 131 Widget widget = builder(index); |
| 132 assert(widget != null); |
| 133 assert(widget.key != null); |
| 134 _Key key = new _Key.fromWidget(widget); |
| 135 Widget oldWidget = _childrenByKey[key]; |
| 136 assert(oldWidget != null); |
| 137 assert(oldWidget.root.parent == root); |
| 138 widget = syncChild(widget, oldWidget, root.childAfter(oldWidget.root))
; |
| 139 assert(widget != null); |
| 140 _childrenByKey[key] = widget; |
| 141 } |
| 142 } |
| 143 } |
| 122 } | 144 } |
| 123 | 145 |
| 124 Widget _getWidget(int index, BoxConstraints innerConstraints) { | 146 Widget _getWidget(int index, BoxConstraints innerConstraints) { |
| 125 LayoutCallbackBuilderHandle handle = enterLayoutCallbackBuilder(); | 147 LayoutCallbackBuilderHandle handle = enterLayoutCallbackBuilder(); |
| 126 try { | 148 try { |
| 127 assert(index >= 0); | 149 assert(index >= 0); |
| 128 Widget widget = builder == null ? null : builder(index); | 150 Widget widget = builder == null ? null : builder(index); |
| 129 if (widget == null) | 151 if (widget == null) |
| 130 return null; | 152 return null; |
| 131 assert(widget.key != null); // items in lists must have keys | 153 assert(widget.key != null); // items in lists must have keys |
| (...skipping 10 matching lines...) Expand all Loading... |
| 142 final double widgetEndOffset = widgetStartOffset + widgetRoot.getMaxIntr
insicHeight(innerConstraints); | 164 final double widgetEndOffset = widgetStartOffset + widgetRoot.getMaxIntr
insicHeight(innerConstraints); |
| 143 _offsets.add(widgetEndOffset); | 165 _offsets.add(widgetEndOffset); |
| 144 } | 166 } |
| 145 return widget; | 167 return widget; |
| 146 } finally { | 168 } finally { |
| 147 exitLayoutCallbackBuilder(handle); | 169 exitLayoutCallbackBuilder(handle); |
| 148 } | 170 } |
| 149 } | 171 } |
| 150 | 172 |
| 151 void layout(BoxConstraints constraints) { | 173 void layout(BoxConstraints constraints) { |
| 174 if (!_dirty) |
| 175 return; |
| 152 _dirty = false; | 176 _dirty = false; |
| 153 | 177 |
| 154 Map<_Key, Widget> newChildren = new Map<_Key, Widget>(); | 178 Map<_Key, Widget> newChildren = new Map<_Key, Widget>(); |
| 155 Map<int, Widget> builtChildren = new Map<int, Widget>(); | 179 Map<int, Widget> builtChildren = new Map<int, Widget>(); |
| 156 | 180 |
| 157 final double height = root.size.height; | 181 final double height = root.size.height; |
| 158 final double endOffset = startOffset + height; | 182 final double endOffset = startOffset + height; |
| 159 BoxConstraints innerConstraints = new BoxConstraints.tightFor(width: constra
ints.constrainWidth()); | 183 BoxConstraints innerConstraints = new BoxConstraints.tightFor(width: constra
ints.constrainWidth()); |
| 160 | 184 |
| 161 int startIndex; | 185 int startIndex; |
| (...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 254 } else { | 278 } else { |
| 255 assert(widget.root.parent == null); | 279 assert(widget.root.parent == null); |
| 256 root.add(widget.root, before: nextSibling); | 280 root.add(widget.root, before: nextSibling); |
| 257 } | 281 } |
| 258 widget.updateSlot(nextSibling); | 282 widget.updateSlot(nextSibling); |
| 259 nextSibling = widget.root; | 283 nextSibling = widget.root; |
| 260 } | 284 } |
| 261 } | 285 } |
| 262 | 286 |
| 263 _childrenByKey = newChildren; | 287 _childrenByKey = newChildren; |
| 288 _currentStartIndex = startIndex; |
| 289 _currentChildCount = _childrenByKey.length; |
| 264 } | 290 } |
| 265 | 291 |
| 266 } | 292 } |
| OLD | NEW |