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

Side by Side Diff: sky/sdk/lib/framework/fn2.dart

Issue 1163933002: Remove the concept of an empty RenderNodeWrapper (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: Created 5 years, 6 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
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 library fn; 5 library fn;
6 6
7 import 'dart:async'; 7 import 'dart:async';
8 import 'dart:collection'; 8 import 'dart:collection';
9 import 'dart:mirrors'; 9 import 'dart:mirrors';
10 import 'dart:sky' as sky; 10 import 'dart:sky' as sky;
(...skipping 257 matching lines...) Expand 10 before | Expand all | Expand 10 after
268 static final Map<RenderNode, RenderNodeWrapper> _nodeMap = 268 static final Map<RenderNode, RenderNodeWrapper> _nodeMap =
269 new HashMap<RenderNode, RenderNodeWrapper>(); 269 new HashMap<RenderNode, RenderNodeWrapper>();
270 270
271 static RenderNodeWrapper _getMounted(RenderNode node) => _nodeMap[node]; 271 static RenderNodeWrapper _getMounted(RenderNode node) => _nodeMap[node];
272 272
273 RenderNodeWrapper({ 273 RenderNodeWrapper({
274 Object key 274 Object key
275 }) : super(key: key); 275 }) : super(key: key);
276 276
277 RenderNode createNode(); 277 RenderNode createNode();
278 RenderNodeWrapper get emptyNode;
279 278
280 void insert(RenderNodeWrapper child, dynamic slot); 279 void insert(RenderNodeWrapper child, dynamic slot);
281 280
282 void _sync(UINode old, dynamic slot) { 281 void _sync(UINode old, dynamic slot) {
283 if (old == null) { 282 if (old == null) {
284 root = createNode(); 283 root = createNode();
285 assert(root != null); 284 assert(root != null);
286 var ancestor = findAncestor(RenderNodeWrapper); 285 var ancestor = findAncestor(RenderNodeWrapper);
287 if (ancestor is RenderNodeWrapper) 286 if (ancestor is RenderNodeWrapper)
288 ancestor.insert(this, slot); 287 ancestor.insert(this, slot);
289 old = emptyNode;
290 } else { 288 } else {
291 root = old.root; 289 root = old.root;
292 assert(root != null); 290 assert(root != null);
293 } 291 }
294 292
295 _nodeMap[root] = this; 293 _nodeMap[root] = this;
296 syncRenderNode(old); 294 syncRenderNode(old);
297 } 295 }
298 296
299 void syncRenderNode(RenderNodeWrapper old) { 297 void syncRenderNode(RenderNodeWrapper old) {
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after
380 378
381 void syncRenderNode(OneChildListRenderNodeWrapper old) { 379 void syncRenderNode(OneChildListRenderNodeWrapper old) {
382 super.syncRenderNode(old); 380 super.syncRenderNode(old);
383 381
384 if (root is! ContainerRenderNodeMixin) 382 if (root is! ContainerRenderNodeMixin)
385 return; 383 return;
386 384
387 var startIndex = 0; 385 var startIndex = 0;
388 var endIndex = children.length; 386 var endIndex = children.length;
389 387
390 var oldChildren = old.children; 388 var oldChildren = old == null ? [] : old.children;
391 var oldStartIndex = 0; 389 var oldStartIndex = 0;
392 var oldEndIndex = oldChildren.length; 390 var oldEndIndex = oldChildren.length;
393 391
394 RenderNode nextSibling = null; 392 RenderNode nextSibling = null;
395 UINode currentNode = null; 393 UINode currentNode = null;
396 UINode oldNode = null; 394 UINode oldNode = null;
397 395
398 void sync(int atIndex) { 396 void sync(int atIndex) {
399 children[atIndex] = syncChild(currentNode, oldNode, nextSibling); 397 children[atIndex] = syncChild(currentNode, oldNode, nextSibling);
400 assert(children[atIndex] != null); 398 assert(children[atIndex] != null);
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after
495 currentNode = null; 493 currentNode = null;
496 while (oldStartIndex < oldEndIndex) { 494 while (oldStartIndex < oldEndIndex) {
497 oldNode = oldChildren[oldStartIndex]; 495 oldNode = oldChildren[oldStartIndex];
498 removeChild(oldNode); 496 removeChild(oldNode);
499 advanceOldStartIndex(); 497 advanceOldStartIndex();
500 } 498 }
501 } 499 }
502 } 500 }
503 501
504 class BlockContainer extends OneChildListRenderNodeWrapper { 502 class BlockContainer extends OneChildListRenderNodeWrapper {
505
506 RenderBlock root;
Hixie 2015/06/02 19:44:51 put this back
abarth-chromium 2015/06/02 19:45:16 Done./
507 RenderBlock createNode() => new RenderBlock(); 503 RenderBlock createNode() => new RenderBlock();
508 504
509 static final BlockContainer _emptyContainer = new BlockContainer(); 505 BlockContainer({ Object key, List<UINode> children })
510 506 : super(key: key, children: children);
511 RenderNodeWrapper get emptyNode => _emptyContainer;
512
513 BlockContainer({
514 Object key,
515 List<UINode> children
516 }) : super(
517 key: key,
518 children: children
519 );
520 } 507 }
521 508
522 class Paragraph extends RenderNodeWrapper { 509 class Paragraph extends RenderNodeWrapper {
523
524 RenderParagraph root; 510 RenderParagraph root;
525 RenderParagraph createNode() => new RenderParagraph(text); 511 RenderParagraph createNode() => new RenderParagraph(text);
526 String text;
527 512
528 static final Paragraph _emptyContainer = new Paragraph(); 513 final String text;
529 514
530 RenderNodeWrapper get emptyNode => _emptyContainer; 515 Paragraph({ Object key, this.text }) : super(key: key);
531
532 Paragraph({
533 Object key,
534 this.text
535 }) : super(
536 key: key
537 );
538 516
539 void syncRenderNode(UINode old) { 517 void syncRenderNode(UINode old) {
540 super.syncRenderNode(old); 518 super.syncRenderNode(old);
541 root.text = text; 519 root.text = text;
542 } 520 }
543 } 521 }
544 522
545 class FlexContainer extends OneChildListRenderNodeWrapper { 523 class FlexContainer extends OneChildListRenderNodeWrapper {
546
547 RenderFlex root; 524 RenderFlex root;
548 RenderFlex createNode() => new RenderFlex(direction: this.direction); 525 RenderFlex createNode() => new RenderFlex(direction: this.direction);
549 526
550 static final FlexContainer _emptyContainer = new FlexContainer();
551 // direction doesn't matter if it's empty
552
553 RenderNodeWrapper get emptyNode => _emptyContainer;
554
555 final FlexDirection direction; 527 final FlexDirection direction;
556 528
557 FlexContainer({ 529 FlexContainer({
558 Object key, 530 Object key,
559 List<UINode> children, 531 List<UINode> children,
560 this.direction: FlexDirection.Horizontal 532 this.direction: FlexDirection.Horizontal
561 }) : super( 533 }) : super(key: key, children: children);
562 key: key,
563 children: children
564 );
565 534
566 void syncRenderNode(UINode old) { 535 void syncRenderNode(UINode old) {
567 super.syncRenderNode(old); 536 super.syncRenderNode(old);
568 root.direction = direction; 537 root.direction = direction;
569 } 538 }
570 } 539 }
571 540
572 class FlexExpandingChild extends ParentDataNode { 541 class FlexExpandingChild extends ParentDataNode {
573 FlexExpandingChild(UINode content, [int flex = 1]): super(content, new FlexBox ParentData()..flex = flex); 542 FlexExpandingChild(UINode content, [int flex = 1])
574 } 543 : super(content, new FlexBoxParentData()..flex = flex);
575
576 class FillStackContainer extends OneChildListRenderNodeWrapper {
577
578 RenderCSSStack root;
579 RenderCSSStack createNode() => new RenderCSSStack(this);
580
581 static final FillStackContainer _emptyContainer = new FillStackContainer();
582
583 RenderNodeWrapper get emptyNode => _emptyContainer;
584
585 FillStackContainer({
586 Object key,
587 List<UINode> children
588 }) : super(
589 key: key,
590 children: _positionNodesToFill(children)
591 );
592
593 static StackParentData _fillParentData = new StackParentData()
594 ..top = 0.0
595 ..left = 0.0
596 ..right = 0.0
597 ..bottom = 0.0;
598
599 static List<UINode> _positionNodesToFill(List<UINode> input) {
600 if (input == null)
601 return null;
602 return input.map((node) {
603 return new ParentDataNode(node, _fillParentData);
604 }).toList();
605 }
606 }
607
608 abstract class OneChildRenderNodeWrapper extends RenderNodeWrapper {
609
610 final UINode child;
611 RenderNodeWithChildMixin root;
612
613 OneChildRenderNodeWrapper({
614 Object key,
615 this.child
616 }) : super(key: key);
617
618 void insert(RenderNodeWrapper child, dynamic slot) {
619 assert(slot == null);
620 root.child = child.root;
621 }
622
623 void _remove() {
624 assert(child != null);
625 removeChild(child);
626 super._remove();
627 }
628 } 544 }
629 545
630 class Image extends RenderNodeWrapper { 546 class Image extends RenderNodeWrapper {
631
632 RenderCSSImage root; 547 RenderCSSImage root;
633 RenderCSSImage createNode() => new RenderCSSImage(this, this.src, this.width, this.height); 548 RenderCSSImage createNode() => new RenderCSSImage(this, this.src, this.width, this.height);
634 549
635 static final Image _emptyImage = new Image();
636
637 RenderNodeWrapper get emptyNode => _emptyImage;
638
639 final String src; 550 final String src;
640 final int width; 551 final int width;
641 final int height; 552 final int height;
642 553
643 Image({ 554 Image({
644 Object key, 555 Object key,
645 this.width, 556 this.width,
646 this.height, 557 this.height,
647 this.src 558 this.src
648 }) : super( 559 }) : super(key: key);
649 key: key
650 );
651 560
652 void syncRenderNode(UINode old) { 561 void syncRenderNode(UINode old) {
653 super.syncRenderNode(old); 562 super.syncRenderNode(old);
654 root.configure(this.src, this.width, this.height); 563 root.configure(this.src, this.width, this.height);
655 } 564 }
656 } 565 }
657 566
658 567
659 Set<Component> _mountedComponents = new HashSet<Component>(); 568 Set<Component> _mountedComponents = new HashSet<Component>();
660 Set<Component> _unmountedComponents = new HashSet<Component>(); 569 Set<Component> _unmountedComponents = new HashSet<Component>();
(...skipping 274 matching lines...) Expand 10 before | Expand all | Expand 10 after
935 844
936 void handlePointer(sky.PointerEvent event) { 845 void handlePointer(sky.PointerEvent event) {
937 if (event.type == 'pointerdown') 846 if (event.type == 'pointerdown')
938 decoration = new BoxDecoration(backgroundColor: 0xFFFF0000); 847 decoration = new BoxDecoration(backgroundColor: 0xFFFF0000);
939 else if (event.type == 'pointerup') 848 else if (event.type == 'pointerup')
940 decoration = new BoxDecoration(backgroundColor: backgroundColor); 849 decoration = new BoxDecoration(backgroundColor: backgroundColor);
941 } 850 }
942 } 851 }
943 852
944 class Rectangle extends RenderNodeWrapper { 853 class Rectangle extends RenderNodeWrapper {
945 854 RenderSolidColor root;
946 Rectangle(this.color, { 855 RenderSolidColor createNode() =>
947 Object key 856 new RenderSolidColor(color, desiredSize: new sky.Size(40.0, 130.0));
948 }) : super(
949 key: key
950 );
951 857
952 final int color; 858 final int color;
953 859
954 RenderSolidColor root; 860 Rectangle(this.color, { Object key }) : super(key: key);
955 RenderSolidColor createNode() => new RenderSolidColor(color, desiredSize: new sky.Size(40.0, 130.0));
956
957 static final Rectangle _emptyRectangle = new Rectangle(0);
958 RenderNodeWrapper get emptyNode => _emptyRectangle;
959
960 } 861 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698