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'; |
11 import 'dart:sky' as sky; | 11 import 'dart:sky' as sky; |
12 import 'package:vector_math/vector_math.dart'; | 12 import 'package:vector_math/vector_math.dart'; |
13 import 'reflect.dart' as reflect; | 13 import 'reflect.dart' as reflect; |
14 import 'rendering/block.dart'; | 14 import 'rendering/block.dart'; |
15 import 'rendering/box.dart'; | 15 import 'rendering/box.dart'; |
16 import 'rendering/flex.dart'; | 16 import 'rendering/flex.dart'; |
17 import 'rendering/object.dart'; | 17 import 'rendering/object.dart'; |
18 import 'rendering/paragraph.dart'; | 18 import 'rendering/paragraph.dart'; |
19 import 'rendering/stack.dart'; | 19 import 'rendering/stack.dart'; |
20 | 20 |
21 // final sky.Tracing _tracing = sky.window.tracing; | 21 // final sky.Tracing _tracing = sky.window.tracing; |
22 | 22 |
23 final bool _shouldLogRenderDuration = false; | 23 final bool _shouldLogRenderDuration = false; |
24 final bool _shouldTrace = false; | 24 final bool _shouldTrace = false; |
25 | 25 |
26 enum _SyncOperation { IDENTICAL, INSERTION, STATEFUL, STATELESS, REMOVAL } | 26 enum _SyncOperation { identical, insertion, stateful, stateless, removal } |
27 | 27 |
28 /* | 28 /* |
29 * All Effen nodes derive from UINode. All nodes have a _parent, a _key and | 29 * All Effen nodes derive from UINode. All nodes have a _parent, a _key and |
30 * can be sync'd. | 30 * can be sync'd. |
31 */ | 31 */ |
32 abstract class UINode { | 32 abstract class UINode { |
33 String _key; | 33 String _key; |
34 UINode _parent; | 34 UINode _parent; |
35 UINode get parent => _parent; | 35 UINode get parent => _parent; |
36 RenderObject root; | 36 RenderObject root; |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
88 void _traceSync(_SyncOperation op, String key) { | 88 void _traceSync(_SyncOperation op, String key) { |
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) { |
110 // the child in this slot has gone away | 110 // the child in this slot has gone away |
111 removeChild(oldNode); | 111 removeChild(oldNode); |
112 return null; | 112 return null; |
113 } | 113 } |
114 assert(oldNode == null || node._key == oldNode._key); | 114 assert(oldNode == null || node._key == oldNode._key); |
115 | 115 |
116 // TODO(rafaelw): This eagerly removes the old DOM. It may be that a | 116 // TODO(rafaelw): This eagerly removes the old DOM. It may be that a |
117 // new component was built that could re-use some of it. Consider | 117 // new component was built that could re-use some of it. Consider |
118 // syncing the new VDOM against the old one. | 118 // syncing the new VDOM against the old one. |
119 if (oldNode != null && node._key != oldNode._key) { | 119 if (oldNode != null && node._key != oldNode._key) { |
120 removeChild(oldNode); | 120 removeChild(oldNode); |
121 } | 121 } |
122 | 122 |
123 if (node._willSync(oldNode)) { | 123 if (node._willSync(oldNode)) { |
124 _traceSync(_SyncOperation.STATEFUL, node._key); | 124 _traceSync(_SyncOperation.stateful, node._key); |
125 oldNode._sync(node, slot); | 125 oldNode._sync(node, slot); |
126 node._defunct = true; | 126 node._defunct = true; |
127 assert(oldNode.root is RenderObject); | 127 assert(oldNode.root is RenderObject); |
128 return oldNode; | 128 return oldNode; |
129 } | 129 } |
130 | 130 |
131 assert(!node._defunct); | 131 assert(!node._defunct); |
132 node._parent = this; | 132 node._parent = this; |
133 | 133 |
134 if (oldNode == null) { | 134 if (oldNode == null) { |
135 _traceSync(_SyncOperation.INSERTION, node._key); | 135 _traceSync(_SyncOperation.insertion, node._key); |
136 } else { | 136 } else { |
137 _traceSync(_SyncOperation.STATELESS, node._key); | 137 _traceSync(_SyncOperation.stateless, node._key); |
138 } | 138 } |
139 node._sync(oldNode, slot); | 139 node._sync(oldNode, slot); |
140 if (oldNode != null) | 140 if (oldNode != null) |
141 oldNode._defunct = true; | 141 oldNode._defunct = true; |
142 | 142 |
143 assert(node.root is RenderObject); | 143 assert(node.root is RenderObject); |
144 return node; | 144 return node; |
145 } | 145 } |
146 } | 146 } |
147 | 147 |
(...skipping 483 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
631 | 631 |
632 class FlexContainer extends MultiChildRenderObjectWrapper { | 632 class FlexContainer extends MultiChildRenderObjectWrapper { |
633 RenderFlex root; | 633 RenderFlex root; |
634 RenderFlex createNode() => new RenderFlex(direction: this.direction); | 634 RenderFlex createNode() => new RenderFlex(direction: this.direction); |
635 | 635 |
636 final FlexDirection direction; | 636 final FlexDirection direction; |
637 | 637 |
638 FlexContainer({ | 638 FlexContainer({ |
639 Object key, | 639 Object key, |
640 List<UINode> children, | 640 List<UINode> children, |
641 this.direction: FlexDirection.Horizontal | 641 this.direction: FlexDirection.horizontal |
642 }) : super(key: key, children: children); | 642 }) : super(key: key, children: children); |
643 | 643 |
644 void syncRenderObject(UINode old) { | 644 void syncRenderObject(UINode old) { |
645 super.syncRenderObject(old); | 645 super.syncRenderObject(old); |
646 root.direction = direction; | 646 root.direction = direction; |
647 } | 647 } |
648 } | 648 } |
649 | 649 |
650 class FlexExpandingChild extends ParentDataNode { | 650 class FlexExpandingChild extends ParentDataNode { |
651 FlexExpandingChild(UINode content, [int flex = 1]) | 651 FlexExpandingChild(UINode content, [int flex = 1]) |
(...skipping 311 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
963 assert(root.parent is RenderView); | 963 assert(root.parent is RenderView); |
964 } | 964 } |
965 } | 965 } |
966 | 966 |
967 class Text extends Component { | 967 class Text extends Component { |
968 Text(this.data) : super(key: '*text*'); | 968 Text(this.data) : super(key: '*text*'); |
969 final String data; | 969 final String data; |
970 bool get interchangeable => true; | 970 bool get interchangeable => true; |
971 UINode build() => new Paragraph(text: data); | 971 UINode build() => new Paragraph(text: data); |
972 } | 972 } |
OLD | NEW |