| 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:collection'; | 5 import 'dart:collection'; |
| 6 | 6 |
| 7 import '../rendering/block.dart'; | 7 import 'package:sky/rendering/block.dart'; |
| 8 import '../rendering/box.dart'; | 8 import 'package:sky/rendering/box.dart'; |
| 9 import '../rendering/object.dart'; | 9 import 'package:sky/rendering/object.dart'; |
| 10 import 'widget.dart'; | 10 import 'package:sky/widgets/widget.dart'; |
| 11 | 11 |
| 12 // return null if index is greater than index of last entry | 12 // return null if index is greater than index of last entry |
| 13 typedef Widget IndexedBuilder(int index); | 13 typedef Widget IndexedBuilder(int index); |
| 14 | 14 |
| 15 typedef void LayoutChangedCallback( | 15 typedef void LayoutChangedCallback( |
| 16 int firstVisibleChildIndex, | 16 int firstVisibleChildIndex, |
| 17 int visibleChildCount, | 17 int visibleChildCount, |
| 18 UnmodifiableListView<double> childOffsets, | 18 UnmodifiableListView<double> childOffsets, |
| 19 bool didReachLastChild | 19 bool didReachLastChild |
| 20 ); | 20 ); |
| 21 | 21 |
| 22 class _Key { | 22 class _Key { |
| 23 const _Key(this.type, this.key); | 23 const _Key(this.type, this.key); |
| 24 factory _Key.fromWidget(Widget widget) => new _Key(widget.runtimeType, widget.
key); | 24 factory _Key.fromWidget(Widget widget) => new _Key(widget.runtimeType, widget.
key); |
| 25 final Type type; | 25 final Type type; |
| 26 final String key; | 26 final String key; |
| 27 bool operator ==(other) => other is _Key && other.type == type && other.key ==
key; | 27 bool operator ==(other) => other is _Key && other.type == type && other.key ==
key; |
| 28 int get hashCode => 373 * 37 * type.hashCode + key.hashCode; | 28 int get hashCode => 373 * 37 * type.hashCode + key.hashCode; |
| 29 } | 29 } |
| 30 | 30 |
| 31 class BlockViewport extends RenderObjectWrapper { | 31 class BlockViewport extends RenderObjectWrapper { |
| 32 BlockViewport({ this.builder, this.startOffset, this.token, this.onLayoutChang
ed, String key }) | 32 BlockViewport({ this.builder, this.startOffset, this.token, this.onLayoutChang
ed, String key }) |
| 33 : super(key: key); | 33 : super(key: key); |
| 34 | 34 |
| 35 IndexedBuilder builder; | 35 IndexedBuilder builder; |
| 36 double startOffset; | 36 double startOffset; |
| 37 Object token; | 37 Object token; |
| 38 LayoutChangedCallback onLayoutChanged; | 38 LayoutChangedCallback onLayoutChanged; |
| 39 | 39 |
| 40 RenderBlockViewport get root => super.root; | 40 RenderBlockViewport get root => super.root; |
| 41 RenderBlockViewport createNode() => new RenderBlockViewport(); | 41 RenderBlockViewport createNode() => new RenderBlockViewport(); |
| 42 | 42 |
| 43 Map<_Key, Widget> _childrenByKey = new Map<_Key, Widget>(); | 43 Map<_Key, Widget> _childrenByKey = new Map<_Key, Widget>(); |
| 44 | 44 |
| 45 void walkChildren(WidgetTreeWalker walker) { | 45 void walkChildren(WidgetTreeWalker walker) { |
| 46 for (Widget child in _childrenByKey.values) | 46 for (Widget child in _childrenByKey.values) |
| 47 walker(child); | 47 walker(child); |
| 48 } | 48 } |
| 49 | 49 |
| 50 static const _omit = const Object(); // used as a slot when it's not yet time
to attach the child | 50 static const _omit = const Object(); // used as a slot when it's not yet time
to attach the child |
| 51 | 51 |
| 52 void insertChildRoot(RenderObjectWrapper child, dynamic slot) { | 52 void insertChildRoot(RenderObjectWrapper child, dynamic slot) { |
| 53 if (slot == _omit) | 53 if (slot == _omit) |
| (...skipping 238 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 292 index -= 1; | 292 index -= 1; |
| 293 Widget widget = builtChildren[index]; | 293 Widget widget = builtChildren[index]; |
| 294 if (widget.root.parent == root) { | 294 if (widget.root.parent == root) { |
| 295 root.move(widget.root, before: nextSibling); | 295 root.move(widget.root, before: nextSibling); |
| 296 } else { | 296 } else { |
| 297 assert(widget.root.parent == null); | 297 assert(widget.root.parent == null); |
| 298 root.add(widget.root, before: nextSibling); | 298 root.add(widget.root, before: nextSibling); |
| 299 } | 299 } |
| 300 widget.updateSlot(nextSibling); | 300 widget.updateSlot(nextSibling); |
| 301 nextSibling = widget.root; | 301 nextSibling = widget.root; |
| 302 } | 302 } |
| 303 } | 303 } |
| 304 | 304 |
| 305 _childrenByKey = newChildren; | 305 _childrenByKey = newChildren; |
| 306 _currentStartIndex = startIndex; | 306 _currentStartIndex = startIndex; |
| 307 _currentChildCount = _childrenByKey.length; | 307 _currentChildCount = _childrenByKey.length; |
| 308 | 308 |
| 309 if (onLayoutChanged != null) { | 309 if (onLayoutChanged != null) { |
| 310 onLayoutChanged( | 310 onLayoutChanged( |
| 311 _currentStartIndex, | 311 _currentStartIndex, |
| 312 _currentChildCount, | 312 _currentChildCount, |
| 313 new UnmodifiableListView<double>(_offsets), | 313 new UnmodifiableListView<double>(_offsets), |
| 314 _didReachLastChild | 314 _didReachLastChild |
| 315 ); | 315 ); |
| 316 } | 316 } |
| 317 } | 317 } |
| 318 | 318 |
| 319 } | 319 } |
| OLD | NEW |