Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(455)

Side by Side Diff: sky/sdk/lib/widgets/widget.dart

Issue 1212943007: Fix spinning_mixed.dart, and resulting yak shave. (Closed) Base URL: https://github.com/domokit/mojo.git@master
Patch Set: Created 5 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 88 matching lines...) Expand 10 before | Expand all | Expand 10 after
99 RenderObject _root; 99 RenderObject _root;
100 RenderObject get root => _root; 100 RenderObject get root => _root;
101 101
102 // Subclasses which implements Nodes that become stateful may return true 102 // Subclasses which implements Nodes that become stateful may return true
103 // if the |old| node has become stateful and should be retained. 103 // if the |old| node has become stateful and should be retained.
104 // This is called immediately before _sync(). 104 // This is called immediately before _sync().
105 // Component._retainStatefulNodeIfPossible() calls syncFields(). 105 // Component._retainStatefulNodeIfPossible() calls syncFields().
106 bool _retainStatefulNodeIfPossible(Widget old) => false; 106 bool _retainStatefulNodeIfPossible(Widget old) => false;
107 107
108 void _sync(Widget old, dynamic slot); 108 void _sync(Widget old, dynamic slot);
109 // 'slot' is the identifier that the parent RenderObjectWrapper uses to know 109 void updateSlot(dynamic newSlot);
110 // where to put this descendant 110 // 'slot' is the identifier that the ancestor RenderObjectWrapper uses to know
111 // where to put this descendant. If you just defer to a child, then make sure
112 // to pass them the slot.
111 113
112 Widget findAncestor(Type targetType) { 114 Widget findAncestor(Type targetType) {
113 var ancestor = _parent; 115 var ancestor = _parent;
114 while (ancestor != null && !reflectClass(ancestor.runtimeType).isSubtypeOf(r eflectClass(targetType))) 116 while (ancestor != null && !reflectClass(ancestor.runtimeType).isSubtypeOf(r eflectClass(targetType)))
115 ancestor = ancestor._parent; 117 ancestor = ancestor._parent;
116 return ancestor; 118 return ancestor;
117 } 119 }
118 120
119 void remove() { 121 void remove() {
120 _root = null; 122 _root = null;
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
179 } 181 }
180 182
181 assert(oldNode == null || (oldNode.mounted == false && oldNode.parent == nul l)); 183 assert(oldNode == null || (oldNode.mounted == false && oldNode.parent == nul l));
182 assert(!newNode.mounted); 184 assert(!newNode.mounted);
183 newNode.setParent(this); 185 newNode.setParent(this);
184 newNode._sync(oldNode, slot); 186 newNode._sync(oldNode, slot);
185 assert(newNode.root is RenderObject); 187 assert(newNode.root is RenderObject);
186 return newNode; 188 return newNode;
187 } 189 }
188 190
189 String toString() { 191 String toString([String prefix = '', String startPrefix = '']) {
192 String childrenString = '';
193 List<Widget> children = new List<Widget>();
194 walkChildren(children.add);
195 if (children.length > 0) {
196 Widget lastChild = children.removeLast();
197 String nextStartPrefix = prefix + ' +-';
198 String nextPrefix = prefix + ' | ';
199 for (Widget child in children)
200 childrenString += child.toString(nextPrefix, nextStartPrefix);
201 String lastStartPrefix = prefix + ' \'-';
202 String lastPrefix = prefix + ' ';
203 childrenString += lastChild.toString(lastPrefix, lastStartPrefix);
204 }
190 if (key == null) 205 if (key == null)
191 return '$runtimeType(unkeyed)'; 206 return '$startPrefix$runtimeType(unkeyed)\n$childrenString';
192 return '$runtimeType("$key")'; 207 return '$startPrefix$runtimeType("$key")\n$childrenString';
193 } 208 }
194 209
195 } 210 }
196 211
197 212
198 // Descendants of TagNode provide a way to tag RenderObjectWrapper and 213 // Descendants of TagNode provide a way to tag RenderObjectWrapper and
199 // Component nodes with annotations, such as event listeners, 214 // Component nodes with annotations, such as event listeners,
200 // stylistic information, etc. 215 // stylistic information, etc.
201 abstract class TagNode extends Widget { 216 abstract class TagNode extends Widget {
202 217
203 TagNode(Widget child, { String key }) 218 TagNode(Widget child, { String key })
204 : this.child = child, super(key: key); 219 : this.child = child, super(key: key);
205 220
206 // TODO(jackson): Remove this workaround for limitation of Dart mixins 221 // TODO(jackson): Remove this workaround for limitation of Dart mixins
207 TagNode._withKey(Widget child, String key) 222 TagNode._withKey(Widget child, String key)
208 : this.child = child, super._withKey(key); 223 : this.child = child, super._withKey(key);
209 224
210 Widget child; 225 Widget child;
211 226
212 void walkChildren(WidgetTreeWalker walker) { 227 void walkChildren(WidgetTreeWalker walker) {
213 walker(child); 228 if (child != null)
229 walker(child);
214 } 230 }
215 231
216 void _sync(Widget old, dynamic slot) { 232 void _sync(Widget old, dynamic slot) {
217 Widget oldChild = old == null ? null : (old as TagNode).child; 233 Widget oldChild = old == null ? null : (old as TagNode).child;
218 child = syncChild(child, oldChild, slot); 234 child = syncChild(child, oldChild, slot);
219 assert(child.parent == this); 235 assert(child.parent == this);
220 assert(child.root != null); 236 assert(child.root != null);
221 _root = child.root; 237 _root = child.root;
222 assert(_root == root); // in case a subclass reintroduces it 238 assert(_root == root); // in case a subclass reintroduces it
223 } 239 }
224 240
241 void updateSlot(dynamic newSlot) {
242 child.updateSlot(newSlot);
243 }
244
225 void remove() { 245 void remove() {
226 if (child != null) 246 if (child != null)
227 removeChild(child); 247 removeChild(child);
228 super.remove(); 248 super.remove();
229 } 249 }
230 250
231 void detachRoot() { 251 void detachRoot() {
232 if (child != null) 252 if (child != null)
233 child.detachRoot(); 253 child.detachRoot();
234 } 254 }
(...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after
367 static Component _currentlyBuilding; 387 static Component _currentlyBuilding;
368 bool get _isBuilding => _currentlyBuilding == this; 388 bool get _isBuilding => _currentlyBuilding == this;
369 389
370 bool _stateful; 390 bool _stateful;
371 bool _dirty = true; 391 bool _dirty = true;
372 bool _disqualifiedFromEverAppearingAgain = false; 392 bool _disqualifiedFromEverAppearingAgain = false;
373 393
374 Widget _built; 394 Widget _built;
375 dynamic _slot; // cached slot from the last time we were synced 395 dynamic _slot; // cached slot from the last time we were synced
376 396
397 void updateSlot(dynamic newSlot) {
398 _slot = newSlot;
399 if (_built != null)
400 _built.updateSlot(newSlot);
401 }
402
403 void walkChildren(WidgetTreeWalker walker) {
404 if (_built != null)
405 walker(_built);
406 }
407
377 void didMount() { 408 void didMount() {
378 assert(!_disqualifiedFromEverAppearingAgain); 409 assert(!_disqualifiedFromEverAppearingAgain);
379 super.didMount(); 410 super.didMount();
380 } 411 }
381 412
382 void remove() { 413 void remove() {
383 assert(_built != null); 414 assert(_built != null);
384 assert(root != null); 415 assert(root != null);
385 removeChild(_built); 416 removeChild(_built);
386 _built = null; 417 _built = null;
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
452 // 1) Building for the first time: 483 // 1) Building for the first time:
453 // assert(_built == null && old == null) 484 // assert(_built == null && old == null)
454 // 2) Re-building (because a dirty flag got set): 485 // 2) Re-building (because a dirty flag got set):
455 // assert(_built != null && old == null) 486 // assert(_built != null && old == null)
456 // 3) Syncing against an old version 487 // 3) Syncing against an old version
457 // assert(_built == null && old != null) 488 // assert(_built == null && old != null)
458 void _sync(Component old, dynamic slot) { 489 void _sync(Component old, dynamic slot) {
459 assert(_built == null || old == null); 490 assert(_built == null || old == null);
460 assert(!_disqualifiedFromEverAppearingAgain); 491 assert(!_disqualifiedFromEverAppearingAgain);
461 492
462 _slot = slot; 493 updateSlot(slot);
463 494
464 var oldBuilt; 495 var oldBuilt;
465 if (old == null) { 496 if (old == null) {
466 oldBuilt = _built; 497 oldBuilt = _built;
467 } else { 498 } else {
468 assert(_built == null); 499 assert(_built == null);
469 oldBuilt = old._built; 500 oldBuilt = old._built;
470 } 501 }
471 502
472 int lastOrder = _currentOrder; 503 int lastOrder = _currentOrder;
(...skipping 10 matching lines...) Expand all
483 _dirty = false; 514 _dirty = false;
484 _root = _built.root; 515 _root = _built.root;
485 assert(_root == root); // in case a subclass reintroduces it 516 assert(_root == root); // in case a subclass reintroduces it
486 assert(root != null); 517 assert(root != null);
487 } 518 }
488 519
489 void _buildIfDirty() { 520 void _buildIfDirty() {
490 assert(!_disqualifiedFromEverAppearingAgain); 521 assert(!_disqualifiedFromEverAppearingAgain);
491 if (!_dirty || !_mounted) 522 if (!_dirty || !_mounted)
492 return; 523 return;
493
494 assert(root != null); 524 assert(root != null);
495 _sync(null, _slot); 525 _sync(null, _slot);
496 } 526 }
497 527
498 void scheduleBuild() { 528 void scheduleBuild() {
499 assert(!_disqualifiedFromEverAppearingAgain); 529 assert(!_disqualifiedFromEverAppearingAgain);
500 if (_isBuilding || _dirty || !_mounted) 530 if (_isBuilding || _dirty || !_mounted)
501 return; 531 return;
502 _dirty = true; 532 _dirty = true;
503 _scheduleComponentForRender(this); 533 _scheduleComponentForRender(this);
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after
611 _root = old.root; 641 _root = old.root;
612 _ancestor = old._ancestor; 642 _ancestor = old._ancestor;
613 } 643 }
614 assert(_root == root); // in case a subclass reintroduces it 644 assert(_root == root); // in case a subclass reintroduces it
615 assert(root != null); 645 assert(root != null);
616 assert(mounted); 646 assert(mounted);
617 _nodeMap[root] = this; 647 _nodeMap[root] = this;
618 syncRenderObject(old); 648 syncRenderObject(old);
619 } 649 }
620 650
651 void updateSlot(dynamic newSlot) {
652 // We never use the slot except during sync(), in which
653 // case our parent is handing it to us anyway.
654 // We don't need to propagate this to our children, since
655 // we give them their own slots for them to fit into us.
656 }
657
621 void syncRenderObject(RenderObjectWrapper old) { 658 void syncRenderObject(RenderObjectWrapper old) {
622 ParentData parentData = null; 659 ParentData parentData = null;
623 Widget ancestor = parent; 660 Widget ancestor = parent;
624 while (ancestor != null && ancestor is! RenderObjectWrapper) { 661 while (ancestor != null && ancestor is! RenderObjectWrapper) {
625 if (ancestor is ParentDataNode && ancestor.parentData != null) { 662 if (ancestor is ParentDataNode && ancestor.parentData != null) {
626 if (parentData != null) 663 if (parentData != null)
627 parentData.merge(ancestor.parentData); // this will throw if the types aren't the same 664 parentData.merge(ancestor.parentData); // this will throw if the types aren't the same
628 else 665 else
629 parentData = ancestor.parentData; 666 parentData = ancestor.parentData;
630 } 667 }
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
668 705
669 abstract class OneChildRenderObjectWrapper extends RenderObjectWrapper { 706 abstract class OneChildRenderObjectWrapper extends RenderObjectWrapper {
670 707
671 OneChildRenderObjectWrapper({ String key, Widget child }) 708 OneChildRenderObjectWrapper({ String key, Widget child })
672 : _child = child, super(key: key); 709 : _child = child, super(key: key);
673 710
674 Widget _child; 711 Widget _child;
675 Widget get child => _child; 712 Widget get child => _child;
676 713
677 void walkChildren(WidgetTreeWalker walker) { 714 void walkChildren(WidgetTreeWalker walker) {
678 walker(child); 715 if (child != null)
716 walker(child);
679 } 717 }
680 718
681 void syncRenderObject(RenderObjectWrapper old) { 719 void syncRenderObject(RenderObjectWrapper old) {
682 super.syncRenderObject(old); 720 super.syncRenderObject(old);
683 Widget oldChild = old == null ? null : (old as OneChildRenderObjectWrapper). child; 721 Widget oldChild = old == null ? null : (old as OneChildRenderObjectWrapper). child;
684 Widget newChild = child; 722 Widget newChild = child;
685 _child = syncChild(newChild, oldChild, null); 723 _child = syncChild(newChild, oldChild, null);
686 assert((newChild == null && child == null) || (newChild != null && child.par ent == this)); 724 assert((newChild == null && child == null) || (newChild != null && child.par ent == this));
687 assert(oldChild == null || child == oldChild || oldChild.parent == null); 725 assert(oldChild == null || child == oldChild || oldChild.parent == null);
688 } 726 }
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after
782 var oldEndIndex = oldChildren.length; 820 var oldEndIndex = oldChildren.length;
783 821
784 RenderObject nextSibling = null; 822 RenderObject nextSibling = null;
785 Widget currentNode = null; 823 Widget currentNode = null;
786 Widget oldNode = null; 824 Widget oldNode = null;
787 825
788 void sync(int atIndex) { 826 void sync(int atIndex) {
789 children[atIndex] = syncChild(currentNode, oldNode, nextSibling); 827 children[atIndex] = syncChild(currentNode, oldNode, nextSibling);
790 assert(children[atIndex] != null); 828 assert(children[atIndex] != null);
791 assert(children[atIndex].parent == this); 829 assert(children[atIndex].parent == this);
830 if (atIndex > 0)
831 children[atIndex-1].updateSlot(children[atIndex].root);
792 } 832 }
793 833
794 // Scan backwards from end of list while nodes can be directly synced 834 // Scan backwards from end of list while nodes can be directly synced
795 // without reordering. 835 // without reordering.
796 while (endIndex > startIndex && oldEndIndex > oldStartIndex) { 836 while (endIndex > startIndex && oldEndIndex > oldStartIndex) {
797 currentNode = children[endIndex - 1]; 837 currentNode = children[endIndex - 1];
798 oldNode = oldChildren[oldEndIndex - 1]; 838 oldNode = oldChildren[oldEndIndex - 1];
799 839
800 if (currentNode.runtimeType != oldNode.runtimeType || currentNode.key != o ldNode.key) { 840 if (currentNode.runtimeType != oldNode.runtimeType || currentNode.key != o ldNode.key) {
801 break; 841 break;
(...skipping 232 matching lines...) Expand 10 before | Expand all | Expand 10 after
1034 if (root.parent == null) { 1074 if (root.parent == null) {
1035 // we haven't attached it yet 1075 // we haven't attached it yet
1036 assert(_container.child == null); 1076 assert(_container.child == null);
1037 _container.child = root; 1077 _container.child = root;
1038 } 1078 }
1039 assert(root.parent == _container); 1079 assert(root.parent == _container);
1040 } 1080 }
1041 1081
1042 Widget build() => builder(); 1082 Widget build() => builder();
1043 } 1083 }
OLDNEW
« sky/sdk/lib/rendering/box.dart ('K') | « sky/sdk/lib/rendering/box.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698