| 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/node.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 RenderNode root; | 36 RenderObject root; |
| 37 bool _defunct = false; | 37 bool _defunct = false; |
| 38 | 38 |
| 39 UINode({ Object key }) { | 39 UINode({ Object key }) { |
| 40 _key = key == null ? "$runtimeType" : "$runtimeType-$key"; | 40 _key = key == null ? "$runtimeType" : "$runtimeType-$key"; |
| 41 assert(this is App || _inRenderDirtyComponents); // you should not build the
UI tree ahead of time, build it only during build() | 41 assert(this is App || _inRenderDirtyComponents); // you should not build the
UI tree ahead of time, build it only during build() |
| 42 } | 42 } |
| 43 | 43 |
| 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 RenderNodeWrapper 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) { |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 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 RenderNode); | 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 RenderNode); | 143 assert(node.root is RenderObject); |
| 144 return node; | 144 return node; |
| 145 } | 145 } |
| 146 } | 146 } |
| 147 | 147 |
| 148 abstract class ContentNode extends UINode { | 148 abstract class ContentNode extends UINode { |
| 149 UINode content; | 149 UINode content; |
| 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) { |
| (...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 252 | 252 |
| 253 void _handleEvent(sky.Event e) { | 253 void _handleEvent(sky.Event e) { |
| 254 sky.EventListener listener = listeners[e.type]; | 254 sky.EventListener listener = listeners[e.type]; |
| 255 if (listener != null) { | 255 if (listener != null) { |
| 256 listener(e); | 256 listener(e); |
| 257 } | 257 } |
| 258 } | 258 } |
| 259 } | 259 } |
| 260 | 260 |
| 261 /* | 261 /* |
| 262 * RenderNodeWrappers correspond to a desired state of a RenderNode. | 262 * RenderObjectWrappers correspond to a desired state of a RenderObject. |
| 263 * They are fully immutable, with one exception: A UINode which is a | 263 * They are fully immutable, with one exception: A UINode which is a |
| 264 * Component which lives within an OneChildListRenderNodeWrapper's | 264 * Component which lives within an OneChildListRenderObjectWrapper's |
| 265 * children list, may be replaced with the "old" instance if it has | 265 * children list, may be replaced with the "old" instance if it has |
| 266 * become stateful. | 266 * become stateful. |
| 267 */ | 267 */ |
| 268 abstract class RenderNodeWrapper extends UINode { | 268 abstract class RenderObjectWrapper extends UINode { |
| 269 | 269 |
| 270 static final Map<RenderNode, RenderNodeWrapper> _nodeMap = | 270 static final Map<RenderObject, RenderObjectWrapper> _nodeMap = |
| 271 new HashMap<RenderNode, RenderNodeWrapper>(); | 271 new HashMap<RenderObject, RenderObjectWrapper>(); |
| 272 | 272 |
| 273 static RenderNodeWrapper _getMounted(RenderNode node) => _nodeMap[node]; | 273 static RenderObjectWrapper _getMounted(RenderObject node) => _nodeMap[node]; |
| 274 | 274 |
| 275 RenderNodeWrapper({ | 275 RenderObjectWrapper({ |
| 276 Object key | 276 Object key |
| 277 }) : super(key: key); | 277 }) : super(key: key); |
| 278 | 278 |
| 279 RenderNode createNode(); | 279 RenderObject createNode(); |
| 280 | 280 |
| 281 void insert(RenderNodeWrapper child, dynamic slot); | 281 void insert(RenderObjectWrapper child, dynamic slot); |
| 282 | 282 |
| 283 void _sync(UINode old, dynamic slot) { | 283 void _sync(UINode old, dynamic slot) { |
| 284 if (old == null) { | 284 if (old == null) { |
| 285 root = createNode(); | 285 root = createNode(); |
| 286 assert(root != null); | 286 assert(root != null); |
| 287 var ancestor = findAncestor(RenderNodeWrapper); | 287 var ancestor = findAncestor(RenderObjectWrapper); |
| 288 if (ancestor is RenderNodeWrapper) | 288 if (ancestor is RenderObjectWrapper) |
| 289 ancestor.insert(this, slot); | 289 ancestor.insert(this, slot); |
| 290 } else { | 290 } else { |
| 291 root = old.root; | 291 root = old.root; |
| 292 assert(root != null); | 292 assert(root != null); |
| 293 } | 293 } |
| 294 | 294 |
| 295 _nodeMap[root] = this; | 295 _nodeMap[root] = this; |
| 296 syncRenderNode(old); | 296 syncRenderObject(old); |
| 297 } | 297 } |
| 298 | 298 |
| 299 void syncRenderNode(RenderNodeWrapper old) { | 299 void syncRenderObject(RenderObjectWrapper old) { |
| 300 ParentData parentData = null; | 300 ParentData parentData = null; |
| 301 UINode parent = _parent; | 301 UINode parent = _parent; |
| 302 while (parent != null && parent is! RenderNodeWrapper) { | 302 while (parent != null && parent is! RenderObjectWrapper) { |
| 303 if (parent is ParentDataNode && parent.parentData != null) { | 303 if (parent is ParentDataNode && parent.parentData != null) { |
| 304 if (parentData != null) | 304 if (parentData != null) |
| 305 parentData.merge(parent.parentData); // this will throw if the types a
ren't the same | 305 parentData.merge(parent.parentData); // this will throw if the types a
ren't the same |
| 306 else | 306 else |
| 307 parentData = parent.parentData; | 307 parentData = parent.parentData; |
| 308 } | 308 } |
| 309 parent = parent._parent; | 309 parent = parent._parent; |
| 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 removeChild(UINode node) { | 320 void removeChild(UINode node) { |
| 321 root.remove(node.root); | 321 root.remove(node.root); |
| 322 super.removeChild(node); | 322 super.removeChild(node); |
| 323 } | 323 } |
| 324 | 324 |
| 325 void _remove() { | 325 void _remove() { |
| 326 assert(root != null); | 326 assert(root != null); |
| 327 _nodeMap.remove(root); | 327 _nodeMap.remove(root); |
| 328 super._remove(); | 328 super._remove(); |
| 329 } | 329 } |
| 330 } | 330 } |
| 331 | 331 |
| 332 abstract class OneChildRenderNodeWrapper extends RenderNodeWrapper { | 332 abstract class OneChildRenderObjectWrapper extends RenderObjectWrapper { |
| 333 final UINode child; | 333 final UINode child; |
| 334 | 334 |
| 335 OneChildRenderNodeWrapper({ this.child, Object key }) : super(key: key); | 335 OneChildRenderObjectWrapper({ this.child, Object key }) : super(key: key); |
| 336 | 336 |
| 337 void insert(RenderNodeWrapper child, dynamic slot) { | 337 void insert(RenderObjectWrapper child, dynamic slot) { |
| 338 assert(slot == null); | 338 assert(slot == null); |
| 339 root.child = child.root; | 339 root.child = child.root; |
| 340 } | 340 } |
| 341 | 341 |
| 342 void syncRenderNode(RenderNodeWrapper old) { | 342 void syncRenderObject(RenderObjectWrapper old) { |
| 343 super.syncRenderNode(old); | 343 super.syncRenderObject(old); |
| 344 UINode oldChild = old == null ? null : (old as OneChildRenderNodeWrapper).ch
ild; | 344 UINode oldChild = old == null ? null : (old as OneChildRenderObjectWrapper).
child; |
| 345 syncChild(child, oldChild, null); | 345 syncChild(child, oldChild, null); |
| 346 } | 346 } |
| 347 | 347 |
| 348 void _remove() { | 348 void _remove() { |
| 349 assert(child != null); | 349 assert(child != null); |
| 350 removeChild(child); | 350 removeChild(child); |
| 351 super._remove(); | 351 super._remove(); |
| 352 } | 352 } |
| 353 } | 353 } |
| 354 | 354 |
| 355 class Padding extends OneChildRenderNodeWrapper { | 355 class Padding extends OneChildRenderObjectWrapper { |
| 356 RenderPadding root; | 356 RenderPadding root; |
| 357 final EdgeDims padding; | 357 final EdgeDims padding; |
| 358 | 358 |
| 359 Padding({ this.padding, UINode child, Object key }) | 359 Padding({ this.padding, UINode child, Object key }) |
| 360 : super(child: child, key: key); | 360 : super(child: child, key: key); |
| 361 | 361 |
| 362 RenderPadding createNode() => new RenderPadding(padding: padding); | 362 RenderPadding createNode() => new RenderPadding(padding: padding); |
| 363 | 363 |
| 364 void syncRenderNode(Padding old) { | 364 void syncRenderObject(Padding old) { |
| 365 super.syncRenderNode(old); | 365 super.syncRenderObject(old); |
| 366 root.padding = padding; | 366 root.padding = padding; |
| 367 } | 367 } |
| 368 } | 368 } |
| 369 | 369 |
| 370 class DecoratedBox extends OneChildRenderNodeWrapper { | 370 class DecoratedBox extends OneChildRenderObjectWrapper { |
| 371 RenderDecoratedBox root; | 371 RenderDecoratedBox root; |
| 372 final BoxDecoration decoration; | 372 final BoxDecoration decoration; |
| 373 | 373 |
| 374 DecoratedBox({ this.decoration, UINode child, Object key }) | 374 DecoratedBox({ this.decoration, UINode child, Object key }) |
| 375 : super(child: child, key: key); | 375 : super(child: child, key: key); |
| 376 | 376 |
| 377 RenderDecoratedBox createNode() => new RenderDecoratedBox(decoration: decorati
on); | 377 RenderDecoratedBox createNode() => new RenderDecoratedBox(decoration: decorati
on); |
| 378 | 378 |
| 379 void syncRenderNode(DecoratedBox old) { | 379 void syncRenderObject(DecoratedBox old) { |
| 380 super.syncRenderNode(old); | 380 super.syncRenderObject(old); |
| 381 root.decoration = decoration; | 381 root.decoration = decoration; |
| 382 } | 382 } |
| 383 } | 383 } |
| 384 | 384 |
| 385 class SizedBox extends OneChildRenderNodeWrapper { | 385 class SizedBox extends OneChildRenderObjectWrapper { |
| 386 RenderSizedBox root; | 386 RenderSizedBox root; |
| 387 final sky.Size desiredSize; | 387 final sky.Size desiredSize; |
| 388 | 388 |
| 389 SizedBox({ this.desiredSize, UINode child, Object key }) | 389 SizedBox({ this.desiredSize, UINode child, Object key }) |
| 390 : super(child: child, key: key); | 390 : super(child: child, key: key); |
| 391 | 391 |
| 392 RenderSizedBox createNode() => new RenderSizedBox(desiredSize: desiredSize); | 392 RenderSizedBox createNode() => new RenderSizedBox(desiredSize: desiredSize); |
| 393 | 393 |
| 394 void syncRenderNode(SizedBox old) { | 394 void syncRenderObject(SizedBox old) { |
| 395 super.syncRenderNode(old); | 395 super.syncRenderObject(old); |
| 396 root.desiredSize = desiredSize; | 396 root.desiredSize = desiredSize; |
| 397 } | 397 } |
| 398 } | 398 } |
| 399 | 399 |
| 400 class Transform extends OneChildRenderNodeWrapper { | 400 class Transform extends OneChildRenderObjectWrapper { |
| 401 RenderTransform root; | 401 RenderTransform root; |
| 402 final Matrix4 transform; | 402 final Matrix4 transform; |
| 403 | 403 |
| 404 Transform({ this.transform, UINode child, Object key }) | 404 Transform({ this.transform, UINode child, Object key }) |
| 405 : super(child: child, key: key); | 405 : super(child: child, key: key); |
| 406 | 406 |
| 407 RenderTransform createNode() => new RenderTransform(transform: transform); | 407 RenderTransform createNode() => new RenderTransform(transform: transform); |
| 408 | 408 |
| 409 void syncRenderNode(Transform old) { | 409 void syncRenderObject(Transform old) { |
| 410 super.syncRenderNode(old); | 410 super.syncRenderObject(old); |
| 411 root.transform = transform; | 411 root.transform = transform; |
| 412 } | 412 } |
| 413 } | 413 } |
| 414 | 414 |
| 415 final List<UINode> _emptyList = new List<UINode>(); | 415 final List<UINode> _emptyList = new List<UINode>(); |
| 416 | 416 |
| 417 abstract class OneChildListRenderNodeWrapper extends RenderNodeWrapper { | 417 abstract class OneChildListRenderObjectWrapper extends RenderObjectWrapper { |
| 418 | 418 |
| 419 // In OneChildListRenderNodeWrapper subclasses, slots are RenderNode nodes | 419 // In OneChildListRenderObjectWrapper subclasses, slots are RenderObject nodes |
| 420 // to use as the "insert before" sibling in ContainerRenderNodeMixin.add() cal
ls | 420 // to use as the "insert before" sibling in ContainerRenderObjectMixin.add() c
alls |
| 421 | 421 |
| 422 final List<UINode> children; | 422 final List<UINode> children; |
| 423 | 423 |
| 424 OneChildListRenderNodeWrapper({ | 424 OneChildListRenderObjectWrapper({ |
| 425 Object key, | 425 Object key, |
| 426 List<UINode> children | 426 List<UINode> children |
| 427 }) : this.children = children == null ? _emptyList : children, | 427 }) : this.children = children == null ? _emptyList : children, |
| 428 super( | 428 super( |
| 429 key: key | 429 key: key |
| 430 ) { | 430 ) { |
| 431 assert(!_debugHasDuplicateIds()); | 431 assert(!_debugHasDuplicateIds()); |
| 432 } | 432 } |
| 433 | 433 |
| 434 void insert(RenderNodeWrapper child, dynamic slot) { | 434 void insert(RenderObjectWrapper child, dynamic slot) { |
| 435 assert(slot == null || slot is RenderNode); | 435 assert(slot == null || slot is RenderObject); |
| 436 root.add(child.root, before: slot); | 436 root.add(child.root, before: slot); |
| 437 } | 437 } |
| 438 | 438 |
| 439 void _remove() { | 439 void _remove() { |
| 440 assert(children != null); | 440 assert(children != null); |
| 441 for (var child in children) { | 441 for (var child in children) { |
| 442 assert(child != null); | 442 assert(child != null); |
| 443 removeChild(child); | 443 removeChild(child); |
| 444 } | 444 } |
| 445 super._remove(); | 445 super._remove(); |
| 446 } | 446 } |
| 447 | 447 |
| 448 bool _debugHasDuplicateIds() { | 448 bool _debugHasDuplicateIds() { |
| 449 var idSet = new HashSet<String>(); | 449 var idSet = new HashSet<String>(); |
| 450 for (var child in children) { | 450 for (var child in children) { |
| 451 assert(child != null); | 451 assert(child != null); |
| 452 if (child.interchangeable) | 452 if (child.interchangeable) |
| 453 continue; // when these nodes are reordered, we just reassign the data | 453 continue; // when these nodes are reordered, we just reassign the data |
| 454 | 454 |
| 455 if (!idSet.add(child._key)) { | 455 if (!idSet.add(child._key)) { |
| 456 throw '''If multiple non-interchangeable nodes of the same type exist as
children | 456 throw '''If multiple non-interchangeable nodes of the same type exist as
children |
| 457 of another node, they must have unique keys. | 457 of another node, they must have unique keys. |
| 458 Duplicate: "${child._key}"'''; | 458 Duplicate: "${child._key}"'''; |
| 459 } | 459 } |
| 460 } | 460 } |
| 461 return false; | 461 return false; |
| 462 } | 462 } |
| 463 | 463 |
| 464 void syncRenderNode(OneChildListRenderNodeWrapper old) { | 464 void syncRenderObject(OneChildListRenderObjectWrapper old) { |
| 465 super.syncRenderNode(old); | 465 super.syncRenderObject(old); |
| 466 | 466 |
| 467 if (root is! ContainerRenderNodeMixin) | 467 if (root is! ContainerRenderObjectMixin) |
| 468 return; | 468 return; |
| 469 | 469 |
| 470 var startIndex = 0; | 470 var startIndex = 0; |
| 471 var endIndex = children.length; | 471 var endIndex = children.length; |
| 472 | 472 |
| 473 var oldChildren = old == null ? [] : old.children; | 473 var oldChildren = old == null ? [] : old.children; |
| 474 var oldStartIndex = 0; | 474 var oldStartIndex = 0; |
| 475 var oldEndIndex = oldChildren.length; | 475 var oldEndIndex = oldChildren.length; |
| 476 | 476 |
| 477 RenderNode nextSibling = null; | 477 RenderObject nextSibling = null; |
| 478 UINode currentNode = null; | 478 UINode currentNode = null; |
| 479 UINode oldNode = null; | 479 UINode oldNode = null; |
| 480 | 480 |
| 481 void sync(int atIndex) { | 481 void sync(int atIndex) { |
| 482 children[atIndex] = syncChild(currentNode, oldNode, nextSibling); | 482 children[atIndex] = syncChild(currentNode, oldNode, nextSibling); |
| 483 assert(children[atIndex] != null); | 483 assert(children[atIndex] != null); |
| 484 } | 484 } |
| 485 | 485 |
| 486 // Scan backwards from end of list while nodes can be directly synced | 486 // Scan backwards from end of list while nodes can be directly synced |
| 487 // without reordering. | 487 // without reordering. |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 529 bool searchForOldNode() { | 529 bool searchForOldNode() { |
| 530 if (currentNode.interchangeable) | 530 if (currentNode.interchangeable) |
| 531 return false; // never re-order these nodes | 531 return false; // never re-order these nodes |
| 532 | 532 |
| 533 ensureOldIdMap(); | 533 ensureOldIdMap(); |
| 534 oldNode = oldNodeIdMap[currentNode._key]; | 534 oldNode = oldNodeIdMap[currentNode._key]; |
| 535 if (oldNode == null) | 535 if (oldNode == null) |
| 536 return false; | 536 return false; |
| 537 | 537 |
| 538 oldNodeIdMap[currentNode._key] = null; // mark it reordered | 538 oldNodeIdMap[currentNode._key] = null; // mark it reordered |
| 539 assert(root is ContainerRenderNodeMixin); | 539 assert(root is ContainerRenderObjectMixin); |
| 540 assert(oldNode.root is ContainerRenderNodeMixin); | 540 assert(oldNode.root is ContainerRenderObjectMixin); |
| 541 | 541 |
| 542 old.root.remove(oldNode.root); | 542 old.root.remove(oldNode.root); |
| 543 root.add(oldNode.root, before: nextSibling); | 543 root.add(oldNode.root, before: nextSibling); |
| 544 | 544 |
| 545 return true; | 545 return true; |
| 546 } | 546 } |
| 547 | 547 |
| 548 // Scan forwards, this time we may re-order; | 548 // Scan forwards, this time we may re-order; |
| 549 nextSibling = root.firstChild; | 549 nextSibling = root.firstChild; |
| 550 while (startIndex < endIndex && oldStartIndex < oldEndIndex) { | 550 while (startIndex < endIndex && oldStartIndex < oldEndIndex) { |
| (...skipping 26 matching lines...) Expand all Loading... |
| 577 // Removals | 577 // Removals |
| 578 currentNode = null; | 578 currentNode = null; |
| 579 while (oldStartIndex < oldEndIndex) { | 579 while (oldStartIndex < oldEndIndex) { |
| 580 oldNode = oldChildren[oldStartIndex]; | 580 oldNode = oldChildren[oldStartIndex]; |
| 581 removeChild(oldNode); | 581 removeChild(oldNode); |
| 582 advanceOldStartIndex(); | 582 advanceOldStartIndex(); |
| 583 } | 583 } |
| 584 } | 584 } |
| 585 } | 585 } |
| 586 | 586 |
| 587 class BlockContainer extends OneChildListRenderNodeWrapper { | 587 class BlockContainer extends OneChildListRenderObjectWrapper { |
| 588 RenderBlock root; | 588 RenderBlock root; |
| 589 RenderBlock createNode() => new RenderBlock(); | 589 RenderBlock createNode() => new RenderBlock(); |
| 590 | 590 |
| 591 BlockContainer({ Object key, List<UINode> children }) | 591 BlockContainer({ Object key, List<UINode> children }) |
| 592 : super(key: key, children: children); | 592 : super(key: key, children: children); |
| 593 } | 593 } |
| 594 | 594 |
| 595 class StackContainer extends OneChildListRenderNodeWrapper { | 595 class StackContainer extends OneChildListRenderObjectWrapper { |
| 596 RenderStack root; | 596 RenderStack root; |
| 597 RenderStack createNode() => new RenderStack(); | 597 RenderStack createNode() => new RenderStack(); |
| 598 | 598 |
| 599 StackContainer({ Object key, List<UINode> children }) | 599 StackContainer({ Object key, List<UINode> children }) |
| 600 : super(key: key, children: children); | 600 : super(key: key, children: children); |
| 601 } | 601 } |
| 602 | 602 |
| 603 class Paragraph extends RenderNodeWrapper { | 603 class Paragraph extends RenderObjectWrapper { |
| 604 RenderParagraph root; | 604 RenderParagraph root; |
| 605 RenderParagraph createNode() => new RenderParagraph(text: text); | 605 RenderParagraph createNode() => new RenderParagraph(text: text); |
| 606 | 606 |
| 607 final String text; | 607 final String text; |
| 608 | 608 |
| 609 Paragraph({ Object key, this.text }) : super(key: key); | 609 Paragraph({ Object key, this.text }) : super(key: key); |
| 610 | 610 |
| 611 void syncRenderNode(UINode old) { | 611 void syncRenderObject(UINode old) { |
| 612 super.syncRenderNode(old); | 612 super.syncRenderObject(old); |
| 613 root.text = text; | 613 root.text = text; |
| 614 } | 614 } |
| 615 } | 615 } |
| 616 | 616 |
| 617 class FlexContainer extends OneChildListRenderNodeWrapper { | 617 class FlexContainer extends OneChildListRenderObjectWrapper { |
| 618 RenderFlex root; | 618 RenderFlex root; |
| 619 RenderFlex createNode() => new RenderFlex(direction: this.direction); | 619 RenderFlex createNode() => new RenderFlex(direction: this.direction); |
| 620 | 620 |
| 621 final FlexDirection direction; | 621 final FlexDirection direction; |
| 622 | 622 |
| 623 FlexContainer({ | 623 FlexContainer({ |
| 624 Object key, | 624 Object key, |
| 625 List<UINode> children, | 625 List<UINode> children, |
| 626 this.direction: FlexDirection.Horizontal | 626 this.direction: FlexDirection.Horizontal |
| 627 }) : super(key: key, children: children); | 627 }) : super(key: key, children: children); |
| 628 | 628 |
| 629 void syncRenderNode(UINode old) { | 629 void syncRenderObject(UINode old) { |
| 630 super.syncRenderNode(old); | 630 super.syncRenderObject(old); |
| 631 root.direction = direction; | 631 root.direction = direction; |
| 632 } | 632 } |
| 633 } | 633 } |
| 634 | 634 |
| 635 class FlexExpandingChild extends ParentDataNode { | 635 class FlexExpandingChild extends ParentDataNode { |
| 636 FlexExpandingChild(UINode content, [int flex = 1]) | 636 FlexExpandingChild(UINode content, [int flex = 1]) |
| 637 : super(content, new FlexBoxParentData()..flex = flex); | 637 : super(content, new FlexBoxParentData()..flex = flex); |
| 638 } | 638 } |
| 639 | 639 |
| 640 class Image extends RenderNodeWrapper { | 640 class Image extends RenderObjectWrapper { |
| 641 RenderImage root; | 641 RenderImage root; |
| 642 RenderImage createNode() => new RenderImage(this.src, this.size); | 642 RenderImage createNode() => new RenderImage(this.src, this.size); |
| 643 | 643 |
| 644 final String src; | 644 final String src; |
| 645 final sky.Size size; | 645 final sky.Size size; |
| 646 | 646 |
| 647 Image({ | 647 Image({ |
| 648 Object key, | 648 Object key, |
| 649 this.src, | 649 this.src, |
| 650 this.size | 650 this.size |
| 651 }) : super(key: key); | 651 }) : super(key: key); |
| 652 | 652 |
| 653 void syncRenderNode(UINode old) { | 653 void syncRenderObject(UINode old) { |
| 654 super.syncRenderNode(old); | 654 super.syncRenderObject(old); |
| 655 root.src = src; | 655 root.src = src; |
| 656 root.requestedSize = size; | 656 root.requestedSize = size; |
| 657 } | 657 } |
| 658 } | 658 } |
| 659 | 659 |
| 660 | 660 |
| 661 Set<Component> _mountedComponents = new HashSet<Component>(); | 661 Set<Component> _mountedComponents = new HashSet<Component>(); |
| 662 Set<Component> _unmountedComponents = new HashSet<Component>(); | 662 Set<Component> _unmountedComponents = new HashSet<Component>(); |
| 663 | 663 |
| 664 void _enqueueDidMount(Component c) { | 664 void _enqueueDidMount(Component c) { |
| (...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 771 _mountCallbacks.forEach((fn) => fn()); | 771 _mountCallbacks.forEach((fn) => fn()); |
| 772 } | 772 } |
| 773 | 773 |
| 774 void _didUnmount() { | 774 void _didUnmount() { |
| 775 if (_unmountCallbacks != null) | 775 if (_unmountCallbacks != null) |
| 776 _unmountCallbacks.forEach((fn) => fn()); | 776 _unmountCallbacks.forEach((fn) => fn()); |
| 777 } | 777 } |
| 778 | 778 |
| 779 // TODO(rafaelw): It seems wrong to expose DOM at all. This is presently | 779 // TODO(rafaelw): It seems wrong to expose DOM at all. This is presently |
| 780 // needed to get sizing info. | 780 // needed to get sizing info. |
| 781 RenderNode getRoot() => root; | 781 RenderObject getRoot() => root; |
| 782 | 782 |
| 783 void _remove() { | 783 void _remove() { |
| 784 assert(_built != null); | 784 assert(_built != null); |
| 785 assert(root != null); | 785 assert(root != null); |
| 786 removeChild(_built); | 786 removeChild(_built); |
| 787 _built = null; | 787 _built = null; |
| 788 _enqueueDidUnmount(this); | 788 _enqueueDidUnmount(this); |
| 789 super._remove(); | 789 super._remove(); |
| 790 } | 790 } |
| 791 | 791 |
| (...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 911 return current; | 911 return current; |
| 912 } | 912 } |
| 913 } | 913 } |
| 914 | 914 |
| 915 class _AppView extends AppView { | 915 class _AppView extends AppView { |
| 916 _AppView() : super(null); | 916 _AppView() : super(null); |
| 917 | 917 |
| 918 void dispatchEvent(sky.Event event, HitTestResult result) { | 918 void dispatchEvent(sky.Event event, HitTestResult result) { |
| 919 super.dispatchEvent(event, result); | 919 super.dispatchEvent(event, result); |
| 920 | 920 |
| 921 UINode target = RenderNodeWrapper._getMounted(result.path.first); | 921 UINode target = RenderObjectWrapper._getMounted(result.path.first); |
| 922 | 922 |
| 923 // TODO(rafaelw): StopPropagation? | 923 // TODO(rafaelw): StopPropagation? |
| 924 while (target != null) { | 924 while (target != null) { |
| 925 if (target is EventListenerNode) | 925 if (target is EventListenerNode) |
| 926 target._handleEvent(event); | 926 target._handleEvent(event); |
| 927 target = target._parent; | 927 target = target._parent; |
| 928 } | 928 } |
| 929 } | 929 } |
| 930 } | 930 } |
| 931 | 931 |
| (...skipping 16 matching lines...) Expand all Loading... |
| 948 assert(root.parent is RenderView); | 948 assert(root.parent is RenderView); |
| 949 } | 949 } |
| 950 } | 950 } |
| 951 | 951 |
| 952 class Text extends Component { | 952 class Text extends Component { |
| 953 Text(this.data) : super(key: '*text*'); | 953 Text(this.data) : super(key: '*text*'); |
| 954 final String data; | 954 final String data; |
| 955 bool get interchangeable => true; | 955 bool get interchangeable => true; |
| 956 UINode build() => new Paragraph(text: data); | 956 UINode build() => new Paragraph(text: data); |
| 957 } | 957 } |
| OLD | NEW |