| 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:async'; | 5 import 'dart:async'; |
| 6 import 'dart:collection'; | 6 import 'dart:collection'; |
| 7 import 'dart:mirrors'; | 7 import 'dart:mirrors'; |
| 8 import 'dart:sky' as sky; | 8 import 'dart:sky' as sky; |
| 9 | 9 |
| 10 import '../base/hit_test.dart'; | 10 import '../base/hit_test.dart'; |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 50 assert(newParent._mounted); | 50 assert(newParent._mounted); |
| 51 if (_parent._mounted != _mounted) { | 51 if (_parent._mounted != _mounted) { |
| 52 _mounted = _parent._mounted; | 52 _mounted = _parent._mounted; |
| 53 _mountedChanged.add(this); | 53 _mountedChanged.add(this); |
| 54 } | 54 } |
| 55 } | 55 } |
| 56 } | 56 } |
| 57 | 57 |
| 58 static void _notifyMountStatusChanged() { | 58 static void _notifyMountStatusChanged() { |
| 59 try { | 59 try { |
| 60 sky.tracing.begin("Widget._notifyMountStatusChanged"); |
| 60 _notifyingMountStatus = true; | 61 _notifyingMountStatus = true; |
| 61 for (Widget node in _mountedChanged) { | 62 for (Widget node in _mountedChanged) { |
| 62 if (node._wasMounted != node._mounted) { | 63 if (node._wasMounted != node._mounted) { |
| 63 if (node._mounted) | 64 if (node._mounted) |
| 64 node.didMount(); | 65 node.didMount(); |
| 65 else | 66 else |
| 66 node.didUnmount(); | 67 node.didUnmount(); |
| 67 node._wasMounted = node._mounted; | 68 node._wasMounted = node._mounted; |
| 68 } | 69 } |
| 69 } | 70 } |
| 70 _mountedChanged.clear(); | 71 _mountedChanged.clear(); |
| 71 } finally { | 72 } finally { |
| 72 _notifyingMountStatus = false; | 73 _notifyingMountStatus = false; |
| 74 sky.tracing.end("Widget._notifyMountStatusChanged"); |
| 73 } | 75 } |
| 74 } | 76 } |
| 75 void didMount() { } | 77 void didMount() { } |
| 76 void didUnmount() { } | 78 void didUnmount() { } |
| 77 | 79 |
| 78 RenderObject _root; | 80 RenderObject _root; |
| 79 RenderObject get root => _root; | 81 RenderObject get root => _root; |
| 80 | 82 |
| 81 // Subclasses which implements Nodes that become stateful may return true | 83 // Subclasses which implements Nodes that become stateful may return true |
| 82 // if the |old| node has become stateful and should be retained. | 84 // if the |old| node has become stateful and should be retained. |
| (...skipping 344 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 427 | 429 |
| 428 Widget build(); | 430 Widget build(); |
| 429 | 431 |
| 430 } | 432 } |
| 431 | 433 |
| 432 Set<Component> _dirtyComponents = new Set<Component>(); | 434 Set<Component> _dirtyComponents = new Set<Component>(); |
| 433 bool _buildScheduled = false; | 435 bool _buildScheduled = false; |
| 434 bool _inRenderDirtyComponents = false; | 436 bool _inRenderDirtyComponents = false; |
| 435 | 437 |
| 436 void _buildDirtyComponents() { | 438 void _buildDirtyComponents() { |
| 437 //_tracing.begin('fn::_buildDirtyComponents'); | |
| 438 | |
| 439 Stopwatch sw; | 439 Stopwatch sw; |
| 440 if (_shouldLogRenderDuration) | 440 if (_shouldLogRenderDuration) |
| 441 sw = new Stopwatch()..start(); | 441 sw = new Stopwatch()..start(); |
| 442 | 442 |
| 443 try { | 443 try { |
| 444 sky.tracing.begin('Widgets._buildDirtyComponents'); |
| 444 _inRenderDirtyComponents = true; | 445 _inRenderDirtyComponents = true; |
| 445 | 446 |
| 446 List<Component> sortedDirtyComponents = _dirtyComponents.toList(); | 447 List<Component> sortedDirtyComponents = _dirtyComponents.toList(); |
| 447 sortedDirtyComponents.sort((Component a, Component b) => a._order - b._order
); | 448 sortedDirtyComponents.sort((Component a, Component b) => a._order - b._order
); |
| 448 for (var comp in sortedDirtyComponents) { | 449 for (var comp in sortedDirtyComponents) { |
| 449 comp._buildIfDirty(); | 450 comp._buildIfDirty(); |
| 450 } | 451 } |
| 451 | 452 |
| 452 _dirtyComponents.clear(); | 453 _dirtyComponents.clear(); |
| 453 _buildScheduled = false; | 454 _buildScheduled = false; |
| 454 } finally { | 455 } finally { |
| 455 _inRenderDirtyComponents = false; | 456 _inRenderDirtyComponents = false; |
| 457 sky.tracing.end('Widgets._buildDirtyComponents'); |
| 456 } | 458 } |
| 457 | 459 |
| 458 Widget._notifyMountStatusChanged(); | 460 Widget._notifyMountStatusChanged(); |
| 459 | 461 |
| 460 if (_shouldLogRenderDuration) { | 462 if (_shouldLogRenderDuration) { |
| 461 sw.stop(); | 463 sw.stop(); |
| 462 print('Render took ${sw.elapsedMicroseconds} microseconds'); | 464 print('Render took ${sw.elapsedMicroseconds} microseconds'); |
| 463 } | 465 } |
| 464 | |
| 465 //_tracing.end('fn::_buildDirtyComponents'); | |
| 466 } | 466 } |
| 467 | 467 |
| 468 void _scheduleComponentForRender(Component c) { | 468 void _scheduleComponentForRender(Component c) { |
| 469 assert(!_inRenderDirtyComponents); | 469 assert(!_inRenderDirtyComponents); |
| 470 _dirtyComponents.add(c); | 470 _dirtyComponents.add(c); |
| 471 | 471 |
| 472 if (!_buildScheduled) { | 472 if (!_buildScheduled) { |
| 473 _buildScheduled = true; | 473 _buildScheduled = true; |
| 474 new Future.microtask(_buildDirtyComponents); | 474 new Future.microtask(_buildDirtyComponents); |
| 475 } | 475 } |
| (...skipping 253 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 729 ensureOldIdMap(); | 729 ensureOldIdMap(); |
| 730 oldNode = oldNodeIdMap[currentNode.key]; | 730 oldNode = oldNodeIdMap[currentNode.key]; |
| 731 if (oldNode == null) | 731 if (oldNode == null) |
| 732 return false; | 732 return false; |
| 733 | 733 |
| 734 oldNodeIdMap[currentNode.key] = null; // mark it reordered | 734 oldNodeIdMap[currentNode.key] = null; // mark it reordered |
| 735 assert(root is ContainerRenderObjectMixin); | 735 assert(root is ContainerRenderObjectMixin); |
| 736 assert(old.root is ContainerRenderObjectMixin); | 736 assert(old.root is ContainerRenderObjectMixin); |
| 737 assert(oldNode.root != null); | 737 assert(oldNode.root != null); |
| 738 | 738 |
| 739 (old.root as ContainerRenderObjectMixin).remove(oldNode.root); // TODO(ian
h): Remove cast once the analyzer is cleverer | 739 if (old.root == root) { |
| 740 root.add(oldNode.root, before: nextSibling); | 740 root.move(oldNode.root, before: nextSibling); |
| 741 } else { |
| 742 (old.root as ContainerRenderObjectMixin).remove(oldNode.root); // TODO(i
anh): Remove cast once the analyzer is cleverer |
| 743 root.add(oldNode.root, before: nextSibling); |
| 744 } |
| 741 | 745 |
| 742 return true; | 746 return true; |
| 743 } | 747 } |
| 744 | 748 |
| 745 // Scan forwards, this time we may re-order; | 749 // Scan forwards, this time we may re-order; |
| 746 nextSibling = root.firstChild; | 750 nextSibling = root.firstChild; |
| 747 while (startIndex < endIndex && oldStartIndex < oldEndIndex) { | 751 while (startIndex < endIndex && oldStartIndex < oldEndIndex) { |
| 748 currentNode = children[startIndex]; | 752 currentNode = children[startIndex]; |
| 749 oldNode = oldChildren[oldStartIndex]; | 753 oldNode = oldChildren[oldStartIndex]; |
| 750 | 754 |
| (...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 911 if (root.parent == null) { | 915 if (root.parent == null) { |
| 912 // we haven't attached it yet | 916 // we haven't attached it yet |
| 913 assert(_container.child == null); | 917 assert(_container.child == null); |
| 914 _container.child = root; | 918 _container.child = root; |
| 915 } | 919 } |
| 916 assert(root.parent == _container); | 920 assert(root.parent == _container); |
| 917 } | 921 } |
| 918 | 922 |
| 919 Widget build() => builder(); | 923 Widget build() => builder(); |
| 920 } | 924 } |
| OLD | NEW |