| 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 library fn; | 5 library fn; |
| 6 | 6 |
| 7 import 'app.dart'; | 7 import 'app.dart'; |
| 8 import 'dart:async'; | 8 import 'dart:async'; |
| 9 import 'dart:collection'; | 9 import 'dart:collection'; |
| 10 import 'dart:mirrors'; | 10 import 'dart:mirrors'; |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 44 // Subclasses which implements Nodes that become stateful may return true | 44 // Subclasses which implements Nodes that become stateful may return true |
| 45 // if the |old| node has become stateful and should be retained. | 45 // if the |old| node has become stateful and should be retained. |
| 46 bool _willSync(UINode old) => false; | 46 bool _willSync(UINode old) => false; |
| 47 | 47 |
| 48 bool get interchangeable => false; // if true, then keys can be duplicated | 48 bool get interchangeable => false; // if true, then keys can be duplicated |
| 49 | 49 |
| 50 void _sync(UINode old, dynamic slot); | 50 void _sync(UINode old, dynamic slot); |
| 51 // 'slot' is the identifier that the parent RenderObjectWrapper uses to know | 51 // 'slot' is the identifier that the parent RenderObjectWrapper uses to know |
| 52 // where to put this descendant | 52 // where to put this descendant |
| 53 | 53 |
| 54 void _remove() { | 54 void remove() { |
| 55 _defunct = true; | 55 _defunct = true; |
| 56 root = null; | 56 root = null; |
| 57 handleRemoved(); | 57 handleRemoved(); |
| 58 } | 58 } |
| 59 void handleRemoved() { } | 59 void handleRemoved() { } |
| 60 | 60 |
| 61 UINode findAncestor(Type targetType) { | 61 UINode findAncestor(Type targetType) { |
| 62 var ancestor = _parent; | 62 var ancestor = _parent; |
| 63 while (ancestor != null && !reflectClass(ancestor.runtimeType).isSubtypeOf(r
eflectClass(targetType))) | 63 while (ancestor != null && !reflectClass(ancestor.runtimeType).isSubtypeOf(r
eflectClass(targetType))) |
| 64 ancestor = ancestor._parent; | 64 ancestor = ancestor._parent; |
| (...skipping 24 matching lines...) Expand all Loading... |
| 89 if (!_shouldTrace) | 89 if (!_shouldTrace) |
| 90 return; | 90 return; |
| 91 | 91 |
| 92 String opString = op.toString().toLowerCase(); | 92 String opString = op.toString().toLowerCase(); |
| 93 String outString = opString.substring(opString.indexOf('.') + 1); | 93 String outString = opString.substring(opString.indexOf('.') + 1); |
| 94 _trace('_sync($outString) $key'); | 94 _trace('_sync($outString) $key'); |
| 95 } | 95 } |
| 96 | 96 |
| 97 void removeChild(UINode node) { | 97 void removeChild(UINode node) { |
| 98 _traceSync(_SyncOperation.removal, node._key); | 98 _traceSync(_SyncOperation.removal, node._key); |
| 99 node._remove(); | 99 node.remove(); |
| 100 } | 100 } |
| 101 | 101 |
| 102 // Returns the child which should be retained as the child of this node. | 102 // Returns the child which should be retained as the child of this node. |
| 103 UINode syncChild(UINode node, UINode oldNode, dynamic slot) { | 103 UINode syncChild(UINode node, UINode oldNode, dynamic slot) { |
| 104 if (node == oldNode) { | 104 if (node == oldNode) { |
| 105 _traceSync(_SyncOperation.identical, node == null ? '*null*' : node._key); | 105 _traceSync(_SyncOperation.identical, node == null ? '*null*' : node._key); |
| 106 return node; // Nothing to do. Subtrees must be identical. | 106 return node; // Nothing to do. Subtrees must be identical. |
| 107 } | 107 } |
| 108 | 108 |
| 109 if (node == null) { | 109 if (node == null) { |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 150 | 150 |
| 151 ContentNode(UINode content) : this.content = content, super(key: content._key)
; | 151 ContentNode(UINode content) : this.content = content, super(key: content._key)
; |
| 152 | 152 |
| 153 void _sync(UINode old, dynamic slot) { | 153 void _sync(UINode old, dynamic slot) { |
| 154 UINode oldContent = old == null ? null : (old as ContentNode).content; | 154 UINode oldContent = old == null ? null : (old as ContentNode).content; |
| 155 content = syncChild(content, oldContent, slot); | 155 content = syncChild(content, oldContent, slot); |
| 156 assert(content.root != null); | 156 assert(content.root != null); |
| 157 root = content.root; | 157 root = content.root; |
| 158 } | 158 } |
| 159 | 159 |
| 160 void _remove() { | 160 void remove() { |
| 161 if (content != null) | 161 if (content != null) |
| 162 removeChild(content); | 162 removeChild(content); |
| 163 super._remove(); | 163 super.remove(); |
| 164 } | 164 } |
| 165 } | 165 } |
| 166 | 166 |
| 167 class ParentDataNode extends ContentNode { | 167 class ParentDataNode extends ContentNode { |
| 168 final ParentData parentData; | 168 final ParentData parentData; |
| 169 | 169 |
| 170 ParentDataNode(UINode content, this.parentData): super(content); | 170 ParentDataNode(UINode content, this.parentData): super(content); |
| 171 } | 171 } |
| 172 | 172 |
| 173 typedef void GestureEventListener(sky.GestureEvent e); | 173 typedef void GestureEventListener(sky.GestureEvent e); |
| (...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 310 } | 310 } |
| 311 if (parentData != null) { | 311 if (parentData != null) { |
| 312 assert(root.parentData != null); | 312 assert(root.parentData != null); |
| 313 root.parentData.merge(parentData); // this will throw if the types aren't
approriate | 313 root.parentData.merge(parentData); // this will throw if the types aren't
approriate |
| 314 assert(parent != null); | 314 assert(parent != null); |
| 315 assert(parent.root != null); | 315 assert(parent.root != null); |
| 316 parent.root.markNeedsLayout(); | 316 parent.root.markNeedsLayout(); |
| 317 } | 317 } |
| 318 } | 318 } |
| 319 | 319 |
| 320 void _remove() { | 320 void remove() { |
| 321 assert(root != null); | 321 assert(root != null); |
| 322 _nodeMap.remove(root); | 322 _nodeMap.remove(root); |
| 323 super._remove(); | 323 super.remove(); |
| 324 } | 324 } |
| 325 } | 325 } |
| 326 | 326 |
| 327 abstract class OneChildRenderObjectWrapper extends RenderObjectWrapper { | 327 abstract class OneChildRenderObjectWrapper extends RenderObjectWrapper { |
| 328 final UINode child; | 328 final UINode child; |
| 329 | 329 |
| 330 OneChildRenderObjectWrapper({ this.child, Object key }) : super(key: key); | 330 OneChildRenderObjectWrapper({ this.child, Object key }) : super(key: key); |
| 331 | 331 |
| 332 void syncRenderObject(RenderObjectWrapper old) { | 332 void syncRenderObject(RenderObjectWrapper old) { |
| 333 super.syncRenderObject(old); | 333 super.syncRenderObject(old); |
| 334 UINode oldChild = old == null ? null : (old as OneChildRenderObjectWrapper).
child; | 334 UINode oldChild = old == null ? null : (old as OneChildRenderObjectWrapper).
child; |
| 335 syncChild(child, oldChild, null); | 335 syncChild(child, oldChild, null); |
| 336 } | 336 } |
| 337 | 337 |
| 338 void insert(RenderObjectWrapper child, dynamic slot) { | 338 void insert(RenderObjectWrapper child, dynamic slot) { |
| 339 assert(slot == null); | 339 assert(slot == null); |
| 340 root.child = child.root; | 340 root.child = child.root; |
| 341 } | 341 } |
| 342 | 342 |
| 343 void removeChild(UINode node) { | 343 void removeChild(UINode node) { |
| 344 root.child = null; | 344 root.child = null; |
| 345 super.removeChild(node); | 345 super.removeChild(node); |
| 346 } | 346 } |
| 347 | 347 |
| 348 void _remove() { | 348 void remove() { |
| 349 if (child != null) | 349 if (child != null) |
| 350 removeChild(child); | 350 removeChild(child); |
| 351 super._remove(); | 351 super.remove(); |
| 352 } | 352 } |
| 353 } | 353 } |
| 354 | 354 |
| 355 class Clip extends OneChildRenderObjectWrapper { | 355 class Clip extends OneChildRenderObjectWrapper { |
| 356 RenderClip root; | 356 RenderClip root; |
| 357 | 357 |
| 358 Clip({ UINode child, Object key }) | 358 Clip({ UINode child, Object key }) |
| 359 : super(child: child, key: key); | 359 : super(child: child, key: key); |
| 360 | 360 |
| 361 RenderClip createNode() => new RenderClip(); | 361 RenderClip createNode() => new RenderClip(); |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 428 SizeObserver({ this.callback, UINode child, Object key }) | 428 SizeObserver({ this.callback, UINode child, Object key }) |
| 429 : super(child: child, key: key); | 429 : super(child: child, key: key); |
| 430 | 430 |
| 431 RenderSizeObserver createNode() => new RenderSizeObserver(callback: callback); | 431 RenderSizeObserver createNode() => new RenderSizeObserver(callback: callback); |
| 432 | 432 |
| 433 void syncRenderObject(SizeObserver old) { | 433 void syncRenderObject(SizeObserver old) { |
| 434 super.syncRenderObject(old); | 434 super.syncRenderObject(old); |
| 435 root.callback = callback; | 435 root.callback = callback; |
| 436 } | 436 } |
| 437 | 437 |
| 438 void _remove() { | 438 void remove() { |
| 439 root.callback = null; | 439 root.callback = null; |
| 440 super._remove(); | 440 super.remove(); |
| 441 } | 441 } |
| 442 } | 442 } |
| 443 | 443 |
| 444 // TODO(jackson) need a mechanism for marking the RenderCustomPaint as needing p
aint | 444 // TODO(jackson) need a mechanism for marking the RenderCustomPaint as needing p
aint |
| 445 class CustomPaint extends OneChildRenderObjectWrapper { | 445 class CustomPaint extends OneChildRenderObjectWrapper { |
| 446 RenderCustomPaint root; | 446 RenderCustomPaint root; |
| 447 final CustomPaintCallback callback; | 447 final CustomPaintCallback callback; |
| 448 | 448 |
| 449 CustomPaint({ this.callback, UINode child, Object key }) | 449 CustomPaint({ this.callback, UINode child, Object key }) |
| 450 : super(child: child, key: key); | 450 : super(child: child, key: key); |
| 451 | 451 |
| 452 RenderCustomPaint createNode() => new RenderCustomPaint(callback: callback); | 452 RenderCustomPaint createNode() => new RenderCustomPaint(callback: callback); |
| 453 | 453 |
| 454 void syncRenderObject(CustomPaint old) { | 454 void syncRenderObject(CustomPaint old) { |
| 455 super.syncRenderObject(old); | 455 super.syncRenderObject(old); |
| 456 root.callback = callback; | 456 root.callback = callback; |
| 457 } | 457 } |
| 458 | 458 |
| 459 void _remove() { | 459 void remove() { |
| 460 root.callback = null; | 460 root.callback = null; |
| 461 super._remove(); | 461 super.remove(); |
| 462 } | 462 } |
| 463 } | 463 } |
| 464 | 464 |
| 465 final List<UINode> _emptyList = new List<UINode>(); | 465 final List<UINode> _emptyList = new List<UINode>(); |
| 466 | 466 |
| 467 abstract class MultiChildRenderObjectWrapper extends RenderObjectWrapper { | 467 abstract class MultiChildRenderObjectWrapper extends RenderObjectWrapper { |
| 468 | 468 |
| 469 // In MultiChildRenderObjectWrapper subclasses, slots are RenderObject nodes | 469 // In MultiChildRenderObjectWrapper subclasses, slots are RenderObject nodes |
| 470 // to use as the "insert before" sibling in ContainerRenderObjectMixin.add() c
alls | 470 // to use as the "insert before" sibling in ContainerRenderObjectMixin.add() c
alls |
| 471 | 471 |
| (...skipping 14 matching lines...) Expand all Loading... |
| 486 assert(root is ContainerRenderObjectMixin); | 486 assert(root is ContainerRenderObjectMixin); |
| 487 root.add(child.root, before: slot); | 487 root.add(child.root, before: slot); |
| 488 } | 488 } |
| 489 | 489 |
| 490 void removeChild(UINode node) { | 490 void removeChild(UINode node) { |
| 491 assert(root is ContainerRenderObjectMixin); | 491 assert(root is ContainerRenderObjectMixin); |
| 492 root.remove(node.root); | 492 root.remove(node.root); |
| 493 super.removeChild(node); | 493 super.removeChild(node); |
| 494 } | 494 } |
| 495 | 495 |
| 496 void _remove() { | 496 void remove() { |
| 497 assert(children != null); | 497 assert(children != null); |
| 498 for (var child in children) { | 498 for (var child in children) { |
| 499 assert(child != null); | 499 assert(child != null); |
| 500 removeChild(child); | 500 removeChild(child); |
| 501 } | 501 } |
| 502 super._remove(); | 502 super.remove(); |
| 503 } | 503 } |
| 504 | 504 |
| 505 bool _debugHasDuplicateIds() { | 505 bool _debugHasDuplicateIds() { |
| 506 var idSet = new HashSet<String>(); | 506 var idSet = new HashSet<String>(); |
| 507 for (var child in children) { | 507 for (var child in children) { |
| 508 assert(child != null); | 508 assert(child != null); |
| 509 if (child.interchangeable) | 509 if (child.interchangeable) |
| 510 continue; // when these nodes are reordered, we just reassign the data | 510 continue; // when these nodes are reordered, we just reassign the data |
| 511 | 511 |
| 512 if (!idSet.add(child._key)) { | 512 if (!idSet.add(child._key)) { |
| (...skipping 328 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 841 | 841 |
| 842 void _didUnmount() { | 842 void _didUnmount() { |
| 843 if (_unmountCallbacks != null) | 843 if (_unmountCallbacks != null) |
| 844 _unmountCallbacks.forEach((fn) => fn()); | 844 _unmountCallbacks.forEach((fn) => fn()); |
| 845 } | 845 } |
| 846 | 846 |
| 847 // TODO(rafaelw): It seems wrong to expose DOM at all. This is presently | 847 // TODO(rafaelw): It seems wrong to expose DOM at all. This is presently |
| 848 // needed to get sizing info. | 848 // needed to get sizing info. |
| 849 RenderObject getRoot() => root; | 849 RenderObject getRoot() => root; |
| 850 | 850 |
| 851 void _remove() { | 851 void remove() { |
| 852 assert(_built != null); | 852 assert(_built != null); |
| 853 assert(root != null); | 853 assert(root != null); |
| 854 removeChild(_built); | 854 removeChild(_built); |
| 855 _built = null; | 855 _built = null; |
| 856 _enqueueDidUnmount(this); | 856 _enqueueDidUnmount(this); |
| 857 super._remove(); | 857 super.remove(); |
| 858 } | 858 } |
| 859 | 859 |
| 860 bool _willSync(UINode old) { | 860 bool _willSync(UINode old) { |
| 861 Component oldComponent = old as Component; | 861 Component oldComponent = old as Component; |
| 862 if (oldComponent == null || !oldComponent._stateful) | 862 if (oldComponent == null || !oldComponent._stateful) |
| 863 return false; | 863 return false; |
| 864 | 864 |
| 865 // Make |this| the "old" Component | 865 // Make |this| the "old" Component |
| 866 _stateful = false; | 866 _stateful = false; |
| 867 _built = oldComponent._built; | 867 _built = oldComponent._built; |
| (...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1017 assert(root.parent is RenderView); | 1017 assert(root.parent is RenderView); |
| 1018 } | 1018 } |
| 1019 } | 1019 } |
| 1020 | 1020 |
| 1021 class Text extends Component { | 1021 class Text extends Component { |
| 1022 Text(this.data) : super(key: '*text*'); | 1022 Text(this.data) : super(key: '*text*'); |
| 1023 final String data; | 1023 final String data; |
| 1024 bool get interchangeable => true; | 1024 bool get interchangeable => true; |
| 1025 UINode build() => new Paragraph(text: data); | 1025 UINode build() => new Paragraph(text: data); |
| 1026 } | 1026 } |
| OLD | NEW |