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 '../app.dart'; | 10 import '../app.dart'; |
(...skipping 729 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
740 } | 740 } |
741 | 741 |
742 assert(root == this.root); // TODO(ianh): Remove this once the analyzer is c
leverer | 742 assert(root == this.root); // TODO(ianh): Remove this once the analyzer is c
leverer |
743 } | 743 } |
744 | 744 |
745 } | 745 } |
746 | 746 |
747 | 747 |
748 class UINodeAppView extends AppView { | 748 class UINodeAppView extends AppView { |
749 | 749 |
750 UINodeAppView() { | 750 UINodeAppView({ RenderView renderViewOverride: null }) |
| 751 : super(renderViewOverride: renderViewOverride) { |
751 assert(_appView == null); | 752 assert(_appView == null); |
752 } | 753 } |
753 | 754 |
754 static UINodeAppView _appView; | 755 static UINodeAppView _appView; |
755 static AppView get appView => _appView; | 756 static AppView get appView => _appView; |
756 static void initUINodeAppView() { | 757 static void initUINodeAppView({ RenderView renderViewOverride: null }) { |
757 if (_appView == null) | 758 _appView = new UINodeAppView(renderViewOverride: renderViewOverride); |
758 _appView = new UINodeAppView(); | |
759 } | 759 } |
760 | 760 |
761 void dispatchEvent(sky.Event event, HitTestResult result) { | 761 void dispatchEvent(sky.Event event, HitTestResult result) { |
762 assert(_appView == this); | 762 assert(_appView == this); |
763 super.dispatchEvent(event, result); | 763 super.dispatchEvent(event, result); |
764 for (HitTestEntry entry in result.path.reversed) { | 764 for (HitTestEntry entry in result.path.reversed) { |
765 UINode target = RenderObjectWrapper._getMounted(entry.target); | 765 UINode target = RenderObjectWrapper._getMounted(entry.target); |
766 if (target == null) | 766 if (target == null) |
767 continue; | 767 continue; |
768 RenderObject targetRoot = target.root; | 768 RenderObject targetRoot = target.root; |
769 while (target != null && target.root == targetRoot) { | 769 while (target != null && target.root == targetRoot) { |
770 if (target is EventListenerNode) | 770 if (target is EventListenerNode) |
771 target._handleEvent(event); | 771 target._handleEvent(event); |
772 target = target._parent; | 772 target = target._parent; |
773 } | 773 } |
774 } | 774 } |
775 } | 775 } |
776 | 776 |
777 } | 777 } |
778 | 778 |
779 abstract class AbstractUINodeRoot extends Component { | 779 abstract class AbstractUINodeRoot extends Component { |
780 | 780 |
781 AbstractUINodeRoot() : super(stateful: true) { | 781 AbstractUINodeRoot({ RenderView renderViewOverride }) : super(stateful: true)
{ |
782 UINodeAppView.initUINodeAppView(); | 782 UINodeAppView.initUINodeAppView(renderViewOverride: renderViewOverride); |
783 _mounted = true; | 783 _mounted = true; |
784 _scheduleComponentForRender(this); | 784 _scheduleComponentForRender(this); |
785 } | 785 } |
786 | 786 |
787 void syncFields(AbstractUINodeRoot source) { | 787 void syncFields(AbstractUINodeRoot source) { |
788 assert(false); | 788 assert(false); |
789 // if we get here, it implies that we have a parent | 789 // if we get here, it implies that we have a parent |
790 } | 790 } |
791 | 791 |
792 void _buildIfDirty() { | 792 void _buildIfDirty() { |
793 assert(_dirty); | 793 assert(_dirty); |
794 assert(_mounted); | 794 assert(_mounted); |
795 assert(parent == null); | 795 assert(parent == null); |
796 _sync(null, null); | 796 _sync(null, null); |
797 } | 797 } |
798 | 798 |
799 } | 799 } |
800 | 800 |
801 abstract class App extends AbstractUINodeRoot { | 801 abstract class App extends AbstractUINodeRoot { |
802 | 802 |
803 App(); | 803 App({ RenderView renderViewOverride }) : super(renderViewOverride: renderViewO
verride); |
804 | 804 |
805 void _buildIfDirty() { | 805 void _buildIfDirty() { |
806 super._buildIfDirty(); | 806 super._buildIfDirty(); |
807 | 807 |
808 if (root.parent == null) { | 808 if (root.parent == null) { |
809 // we haven't attached it yet | 809 // we haven't attached it yet |
810 UINodeAppView._appView.root = root; | 810 UINodeAppView._appView.root = root; |
811 } | 811 } |
812 assert(root.parent is RenderView); | 812 assert(root.parent is RenderView); |
813 } | 813 } |
814 | 814 |
815 } | 815 } |
816 | 816 |
817 typedef UINode Builder(); | 817 typedef UINode Builder(); |
818 | 818 |
819 class RenderObjectToUINodeAdapter extends AbstractUINodeRoot { | 819 class RenderObjectToUINodeAdapter extends AbstractUINodeRoot { |
820 | 820 |
821 RenderObjectToUINodeAdapter( | 821 RenderObjectToUINodeAdapter( |
822 RenderObjectWithChildMixin<RenderBox> container, | 822 RenderObjectWithChildMixin<RenderBox> container, |
823 this.builder | 823 this.builder |
824 ) : _container = container { | 824 ) : _container = container, super() { |
825 assert(builder != null); | 825 assert(builder != null); |
826 } | 826 } |
827 | 827 |
828 RenderObjectWithChildMixin<RenderBox> _container; | 828 RenderObjectWithChildMixin<RenderBox> _container; |
829 RenderObjectWithChildMixin<RenderBox> get container => _container; | 829 RenderObjectWithChildMixin<RenderBox> get container => _container; |
830 void set container(RenderObjectWithChildMixin<RenderBox> value) { | 830 void set container(RenderObjectWithChildMixin<RenderBox> value) { |
831 if (_container != value) { | 831 if (_container != value) { |
832 assert(value.child == null); | 832 assert(value.child == null); |
833 if (root != null) { | 833 if (root != null) { |
834 assert(_container.child == root); | 834 assert(_container.child == root); |
(...skipping 15 matching lines...) Expand all Loading... |
850 // we haven't attached it yet | 850 // we haven't attached it yet |
851 assert(_container.child == null); | 851 assert(_container.child == null); |
852 _container.child = root; | 852 _container.child = root; |
853 } | 853 } |
854 assert(root.parent == _container); | 854 assert(root.parent == _container); |
855 } | 855 } |
856 | 856 |
857 UINode build() => builder(); | 857 UINode build() => builder(); |
858 | 858 |
859 } | 859 } |
OLD | NEW |