| 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 243 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 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 * RenderObjectWrappers correspond to a desired state of a RenderObject. | 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 OneChildListRenderObjectWrapper's | 264 * Component which lives within an MultiChildRenderObjectWrapper'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 RenderObjectWrapper extends UINode { | 268 abstract class RenderObjectWrapper extends UINode { |
| 269 | 269 |
| 270 static final Map<RenderObject, RenderObjectWrapper> _nodeMap = | 270 static final Map<RenderObject, RenderObjectWrapper> _nodeMap = |
| 271 new HashMap<RenderObject, RenderObjectWrapper>(); | 271 new HashMap<RenderObject, RenderObjectWrapper>(); |
| 272 | 272 |
| 273 static RenderObjectWrapper _getMounted(RenderObject node) => _nodeMap[node]; | 273 static RenderObjectWrapper _getMounted(RenderObject node) => _nodeMap[node]; |
| 274 | 274 |
| (...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 407 RenderTransform createNode() => new RenderTransform(transform: transform); | 407 RenderTransform createNode() => new RenderTransform(transform: transform); |
| 408 | 408 |
| 409 void syncRenderObject(Transform old) { | 409 void syncRenderObject(Transform old) { |
| 410 super.syncRenderObject(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 OneChildListRenderObjectWrapper extends RenderObjectWrapper { | 417 abstract class MultiChildRenderObjectWrapper extends RenderObjectWrapper { |
| 418 | 418 |
| 419 // In OneChildListRenderObjectWrapper subclasses, slots are RenderObject nodes | 419 // In MultiChildRenderObjectWrapper subclasses, slots are RenderObject nodes |
| 420 // to use as the "insert before" sibling in ContainerRenderObjectMixin.add() c
alls | 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 OneChildListRenderObjectWrapper({ | 424 MultiChildRenderObjectWrapper({ |
| 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(RenderObjectWrapper child, dynamic slot) { | 434 void insert(RenderObjectWrapper child, dynamic slot) { |
| (...skipping 25 matching lines...) Expand all Loading... |
| 460 | 460 |
| 461 if (!idSet.add(child._key)) { | 461 if (!idSet.add(child._key)) { |
| 462 throw '''If multiple non-interchangeable nodes of the same type exist as
children | 462 throw '''If multiple non-interchangeable nodes of the same type exist as
children |
| 463 of another node, they must have unique keys. | 463 of another node, they must have unique keys. |
| 464 Duplicate: "${child._key}"'''; | 464 Duplicate: "${child._key}"'''; |
| 465 } | 465 } |
| 466 } | 466 } |
| 467 return false; | 467 return false; |
| 468 } | 468 } |
| 469 | 469 |
| 470 void syncRenderObject(OneChildListRenderObjectWrapper old) { | 470 void syncRenderObject(MultiChildRenderObjectWrapper old) { |
| 471 super.syncRenderObject(old); | 471 super.syncRenderObject(old); |
| 472 | 472 |
| 473 if (root is! ContainerRenderObjectMixin) | 473 if (root is! ContainerRenderObjectMixin) |
| 474 return; | 474 return; |
| 475 | 475 |
| 476 var startIndex = 0; | 476 var startIndex = 0; |
| 477 var endIndex = children.length; | 477 var endIndex = children.length; |
| 478 | 478 |
| 479 var oldChildren = old == null ? [] : old.children; | 479 var oldChildren = old == null ? [] : old.children; |
| 480 var oldStartIndex = 0; | 480 var oldStartIndex = 0; |
| (...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 583 // Removals | 583 // Removals |
| 584 currentNode = null; | 584 currentNode = null; |
| 585 while (oldStartIndex < oldEndIndex) { | 585 while (oldStartIndex < oldEndIndex) { |
| 586 oldNode = oldChildren[oldStartIndex]; | 586 oldNode = oldChildren[oldStartIndex]; |
| 587 removeChild(oldNode); | 587 removeChild(oldNode); |
| 588 advanceOldStartIndex(); | 588 advanceOldStartIndex(); |
| 589 } | 589 } |
| 590 } | 590 } |
| 591 } | 591 } |
| 592 | 592 |
| 593 class BlockContainer extends OneChildListRenderObjectWrapper { | 593 class BlockContainer extends MultiChildRenderObjectWrapper { |
| 594 RenderBlock root; | 594 RenderBlock root; |
| 595 RenderBlock createNode() => new RenderBlock(); | 595 RenderBlock createNode() => new RenderBlock(); |
| 596 | 596 |
| 597 BlockContainer({ Object key, List<UINode> children }) | 597 BlockContainer({ Object key, List<UINode> children }) |
| 598 : super(key: key, children: children); | 598 : super(key: key, children: children); |
| 599 } | 599 } |
| 600 | 600 |
| 601 class StackContainer extends OneChildListRenderObjectWrapper { | 601 class StackContainer extends MultiChildRenderObjectWrapper { |
| 602 RenderStack root; | 602 RenderStack root; |
| 603 RenderStack createNode() => new RenderStack(); | 603 RenderStack createNode() => new RenderStack(); |
| 604 | 604 |
| 605 StackContainer({ Object key, List<UINode> children }) | 605 StackContainer({ Object key, List<UINode> children }) |
| 606 : super(key: key, children: children); | 606 : super(key: key, children: children); |
| 607 } | 607 } |
| 608 | 608 |
| 609 class Paragraph extends RenderObjectWrapper { | 609 class Paragraph extends RenderObjectWrapper { |
| 610 RenderParagraph root; | 610 RenderParagraph root; |
| 611 RenderParagraph createNode() => new RenderParagraph(text: text); | 611 RenderParagraph createNode() => new RenderParagraph(text: text); |
| 612 | 612 |
| 613 final String text; | 613 final String text; |
| 614 | 614 |
| 615 Paragraph({ Object key, this.text }) : super(key: key); | 615 Paragraph({ Object key, this.text }) : super(key: key); |
| 616 | 616 |
| 617 void syncRenderObject(UINode old) { | 617 void syncRenderObject(UINode old) { |
| 618 super.syncRenderObject(old); | 618 super.syncRenderObject(old); |
| 619 root.text = text; | 619 root.text = text; |
| 620 } | 620 } |
| 621 } | 621 } |
| 622 | 622 |
| 623 class FlexContainer extends OneChildListRenderObjectWrapper { | 623 class FlexContainer extends MultiChildRenderObjectWrapper { |
| 624 RenderFlex root; | 624 RenderFlex root; |
| 625 RenderFlex createNode() => new RenderFlex(direction: this.direction); | 625 RenderFlex createNode() => new RenderFlex(direction: this.direction); |
| 626 | 626 |
| 627 final FlexDirection direction; | 627 final FlexDirection direction; |
| 628 | 628 |
| 629 FlexContainer({ | 629 FlexContainer({ |
| 630 Object key, | 630 Object key, |
| 631 List<UINode> children, | 631 List<UINode> children, |
| 632 this.direction: FlexDirection.Horizontal | 632 this.direction: FlexDirection.Horizontal |
| 633 }) : super(key: key, children: children); | 633 }) : super(key: key, children: children); |
| (...skipping 320 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 954 assert(root.parent is RenderView); | 954 assert(root.parent is RenderView); |
| 955 } | 955 } |
| 956 } | 956 } |
| 957 | 957 |
| 958 class Text extends Component { | 958 class Text extends Component { |
| 959 Text(this.data) : super(key: '*text*'); | 959 Text(this.data) : super(key: '*text*'); |
| 960 final String data; | 960 final String data; |
| 961 bool get interchangeable => true; | 961 bool get interchangeable => true; |
| 962 UINode build() => new Paragraph(text: data); | 962 UINode build() => new Paragraph(text: data); |
| 963 } | 963 } |
| OLD | NEW |