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 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 '../rendering/box.dart'; | 11 import '../rendering/box.dart'; |
11 import '../rendering/object.dart'; | 12 import '../rendering/object.dart'; |
12 import '../rendering/sky_binding.dart'; | 13 import '../rendering/sky_binding.dart'; |
13 | 14 |
14 export '../rendering/box.dart' show BoxConstraints, BoxDecoration, Border, Borde
rSide, EdgeDims; | 15 export '../rendering/box.dart' show BoxConstraints, BoxDecoration, Border, Borde
rSide, EdgeDims; |
15 export '../rendering/flex.dart' show FlexDirection; | 16 export '../rendering/flex.dart' show FlexDirection; |
16 export '../rendering/object.dart' show Point, Size, Rect, Color, Paint, Path; | 17 export '../rendering/object.dart' show Point, Size, Rect, Color, Paint, Path; |
17 | 18 |
18 final bool _shouldLogRenderDuration = false; | 19 final bool _shouldLogRenderDuration = false; |
19 | 20 |
(...skipping 478 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
498 // TODO(abarth): We should split RenderObjectWrapper into two pieces so that | 499 // TODO(abarth): We should split RenderObjectWrapper into two pieces so that |
499 // RenderViewObject doesn't need to inherit all this code it | 500 // RenderViewObject doesn't need to inherit all this code it |
500 // doesn't need. | 501 // doesn't need. |
501 assert(parent != null || this is RenderViewWrapper); | 502 assert(parent != null || this is RenderViewWrapper); |
502 if (old == null) { | 503 if (old == null) { |
503 _root = createNode(); | 504 _root = createNode(); |
504 _ancestor = findAncestor(RenderObjectWrapper); | 505 _ancestor = findAncestor(RenderObjectWrapper); |
505 if (_ancestor is RenderObjectWrapper) | 506 if (_ancestor is RenderObjectWrapper) |
506 _ancestor.insertChildRoot(this, slot); | 507 _ancestor.insertChildRoot(this, slot); |
507 } else { | 508 } else { |
| 509 assert(old is RenderObjectWrapper); |
508 _root = old.root; | 510 _root = old.root; |
509 _ancestor = old._ancestor; | 511 _ancestor = old._ancestor; |
510 } | 512 } |
511 assert(_root == root); // in case a subclass reintroduces it | 513 assert(_root == root); // in case a subclass reintroduces it |
512 assert(root != null); | 514 assert(root != null); |
513 assert(mounted); | 515 assert(mounted); |
514 _nodeMap[root] = this; | 516 _nodeMap[root] = this; |
515 syncRenderObject(old); | 517 syncRenderObject(old); |
516 } | 518 } |
517 | 519 |
(...skipping 259 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
777 } | 779 } |
778 | 780 |
779 assert(root == this.root); // TODO(ianh): Remove this once the analyzer is c
leverer | 781 assert(root == this.root); // TODO(ianh): Remove this once the analyzer is c
leverer |
780 } | 782 } |
781 | 783 |
782 } | 784 } |
783 | 785 |
784 class WidgetSkyBinding extends SkyBinding { | 786 class WidgetSkyBinding extends SkyBinding { |
785 | 787 |
786 WidgetSkyBinding({ RenderView renderViewOverride: null }) | 788 WidgetSkyBinding({ RenderView renderViewOverride: null }) |
787 : super(renderViewOverride: renderViewOverride) { | 789 : super(renderViewOverride: renderViewOverride); |
788 assert(_skyBinding == null); | |
789 } | |
790 | 790 |
791 static WidgetSkyBinding _skyBinding; | |
792 static SkyBinding get skyBinding => _skyBinding; | |
793 static void initWidgetSkyBinding({ RenderView renderViewOverride: null }) { | 791 static void initWidgetSkyBinding({ RenderView renderViewOverride: null }) { |
794 if (_skyBinding == null) | 792 if (SkyBinding.instance == null) |
795 _skyBinding = new WidgetSkyBinding(renderViewOverride: renderViewOverride)
; | 793 new WidgetSkyBinding(renderViewOverride: renderViewOverride); |
| 794 assert(SkyBinding.instance is WidgetSkyBinding); |
796 } | 795 } |
797 | 796 |
798 void dispatchEvent(sky.Event event, HitTestResult result) { | 797 void dispatchEvent(sky.Event event, HitTestResult result) { |
799 assert(_skyBinding == this); | 798 assert(SkyBinding.instance == this); |
800 super.dispatchEvent(event, result); | 799 super.dispatchEvent(event, result); |
801 for (HitTestEntry entry in result.path.reversed) { | 800 for (HitTestEntry entry in result.path.reversed) { |
802 Widget target = RenderObjectWrapper._getMounted(entry.target); | 801 Widget target = RenderObjectWrapper._getMounted(entry.target); |
803 if (target == null) | 802 if (target == null) |
804 continue; | 803 continue; |
805 RenderObject targetRoot = target.root; | 804 RenderObject targetRoot = target.root; |
806 while (target != null && target.root == targetRoot) { | 805 while (target != null && target.root == targetRoot) { |
807 if (target is Listener) | 806 if (target is Listener) |
808 target._handleEvent(event); | 807 target._handleEvent(event); |
809 target = target._parent; | 808 target = target._parent; |
(...skipping 24 matching lines...) Expand all Loading... |
834 assert(_dirty); | 833 assert(_dirty); |
835 assert(_mounted); | 834 assert(_mounted); |
836 assert(parent == null); | 835 assert(parent == null); |
837 _sync(null, null); | 836 _sync(null, null); |
838 } | 837 } |
839 | 838 |
840 } | 839 } |
841 | 840 |
842 class RenderViewWrapper extends OneChildRenderObjectWrapper { | 841 class RenderViewWrapper extends OneChildRenderObjectWrapper { |
843 RenderViewWrapper({ String key, Widget child }) : super(key: key, child: child
); | 842 RenderViewWrapper({ String key, Widget child }) : super(key: key, child: child
); |
844 | |
845 RenderView get root => super.root; | 843 RenderView get root => super.root; |
846 RenderView createNode() => WidgetSkyBinding._skyBinding.renderView; | 844 RenderView createNode() => SkyBinding.instance.renderView; |
847 } | 845 } |
848 | 846 |
849 class AppContainer extends AbstractWidgetRoot { | 847 class AppContainer extends AbstractWidgetRoot { |
850 AppContainer(this.app); | 848 AppContainer(this.app) { |
851 | 849 assert(SkyBinding.instance is WidgetSkyBinding); |
| 850 } |
852 final App app; | 851 final App app; |
853 | |
854 Widget build() => new RenderViewWrapper(child: app); | 852 Widget build() => new RenderViewWrapper(child: app); |
855 } | 853 } |
856 | 854 |
857 void runApp(App app, { RenderView renderViewOverride }) { | 855 void runApp(App app, { RenderView renderViewOverride }) { |
858 WidgetSkyBinding.initWidgetSkyBinding(renderViewOverride: renderViewOverride); | 856 WidgetSkyBinding.initWidgetSkyBinding(renderViewOverride: renderViewOverride); |
859 new AppContainer(app); | 857 new AppContainer(app); |
860 } | 858 } |
861 | 859 |
862 typedef Widget Builder(); | 860 typedef Widget Builder(); |
863 | 861 |
(...skipping 30 matching lines...) Expand all Loading... |
894 if (root.parent == null) { | 892 if (root.parent == null) { |
895 // we haven't attached it yet | 893 // we haven't attached it yet |
896 assert(_container.child == null); | 894 assert(_container.child == null); |
897 _container.child = root; | 895 _container.child = root; |
898 } | 896 } |
899 assert(root.parent == _container); | 897 assert(root.parent == _container); |
900 } | 898 } |
901 | 899 |
902 Widget build() => builder(); | 900 Widget build() => builder(); |
903 } | 901 } |
OLD | NEW |