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

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

Issue 1178703002: Abstract out the AppView logic in fn so that it can also be used in non-pure-fn apps. (Closed) Base URL: https://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 | « sky/sdk/lib/framework/app.dart ('k') | 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 '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 749 matching lines...) Expand 10 before | Expand all | Expand 10 after
760 root.text = text; 760 root.text = text;
761 } 761 }
762 762
763 void insert(RenderObjectWrapper child, dynamic slot) { 763 void insert(RenderObjectWrapper child, dynamic slot) {
764 assert(false); 764 assert(false);
765 // Paragraph does not support having children currently 765 // Paragraph does not support having children currently
766 } 766 }
767 767
768 } 768 }
769 769
770 class Text extends Component {
771 Text(this.data) : super(key: '*text*');
772 final String data;
773 bool get interchangeable => true;
774 UINode build() => new Paragraph(text: data);
775 }
776
770 class Flex extends MultiChildRenderObjectWrapper { 777 class Flex extends MultiChildRenderObjectWrapper {
771 778
772 Flex(List<UINode> children, { 779 Flex(List<UINode> children, {
773 Object key, 780 Object key,
774 this.direction: FlexDirection.horizontal, 781 this.direction: FlexDirection.horizontal,
775 this.justifyContent: FlexJustifyContent.flexStart 782 this.justifyContent: FlexJustifyContent.flexStart
776 }) : super(key: key, children: children); 783 }) : super(key: key, children: children);
777 784
778 RenderFlex get root { RenderFlex result = super.root; return result; } 785 RenderFlex get root { RenderFlex result = super.root; return result; }
779 RenderFlex createNode() => new RenderFlex(direction: this.direction); 786 RenderFlex createNode() => new RenderFlex(direction: this.direction);
(...skipping 272 matching lines...) Expand 10 before | Expand all | Expand 10 after
1052 current = new Padding(padding: margin, child: current); 1059 current = new Padding(padding: margin, child: current);
1053 1060
1054 if (transform != null) 1061 if (transform != null)
1055 current = new Transform(transform: transform, child: current); 1062 current = new Transform(transform: transform, child: current);
1056 1063
1057 return current; 1064 return current;
1058 } 1065 }
1059 1066
1060 } 1067 }
1061 1068
1062 class _AppView extends AppView { 1069 class UINodeAppView extends AppView {
1063 _AppView() : super(null); 1070
1071 UINodeAppView() {
1072 assert(_appView == null);
1073 }
1074
1075 static UINodeAppView _appView;
1076 static void initUINodeAppView() {
1077 if (_appView == null)
1078 _appView = new UINodeAppView();
1079 }
1064 1080
1065 void dispatchEvent(sky.Event event, HitTestResult result) { 1081 void dispatchEvent(sky.Event event, HitTestResult result) {
1082 assert(_appView == this);
1066 super.dispatchEvent(event, result); 1083 super.dispatchEvent(event, result);
1067 1084
1068 UINode target = RenderObjectWrapper._getMounted(result.path.first.target); 1085 UINode target = RenderObjectWrapper._getMounted(result.path.first.target);
1069 1086
1070 // TODO(rafaelw): StopPropagation? 1087 // TODO(rafaelw): StopPropagation?
1071 while (target != null) { 1088 while (target != null) {
1072 if (target is EventListenerNode) 1089 if (target is EventListenerNode)
1073 target._handleEvent(event); 1090 target._handleEvent(event);
1074 target = target._parent; 1091 target = target._parent;
1075 } 1092 }
1076 } 1093 }
1094
1077 } 1095 }
1078 1096
1079 abstract class App extends Component { 1097 abstract class AbstractUINodeRoot extends Component {
1080 1098
1081 App() : super(stateful: true) { 1099 AbstractUINodeRoot() : super(stateful: true) {
1082 _appView = new _AppView(); 1100 UINodeAppView.initUINodeAppView();
1101 _mounted = true;
1083 _scheduleComponentForRender(this); 1102 _scheduleComponentForRender(this);
1084 _mounted = true;
1085 } 1103 }
1086 1104
1087 AppView _appView; 1105 void syncFields(AbstractUINodeRoot source) {
1088 AppView get appView => _appView; 1106 assert(false);
1107 // if we get here, it implies that we have a parent
1108 }
1089 1109
1090 void _buildIfDirty() { 1110 void _buildIfDirty() {
1091 assert(_dirty); 1111 assert(_dirty);
1092 assert(_mounted); 1112 assert(_mounted);
1113 assert(parent == null);
1093 _sync(null, null); 1114 _sync(null, null);
1094 if (root.parent == null) 1115 }
1095 _appView.root = root; 1116
1117 }
1118
1119 abstract class App extends AbstractUINodeRoot {
1120
1121 App();
1122
1123 AppView get appView => UINodeAppView._appView;
1124
1125 void _buildIfDirty() {
1126 super._buildIfDirty();
1127
1128 if (root.parent == null) {
1129 // we haven't attached it yet
1130 UINodeAppView._appView.root = root;
1131 }
1096 assert(root.parent is RenderView); 1132 assert(root.parent is RenderView);
1097 } 1133 }
1098 1134
1099 } 1135 }
1100 1136
1101 class Text extends Component { 1137 typedef UINode Builder();
1102 Text(this.data) : super(key: '*text*'); 1138
1103 final String data; 1139 class RenderNodeToUINodeAdapter extends AbstractUINodeRoot {
1104 bool get interchangeable => true; 1140
1105 UINode build() => new Paragraph(text: data); 1141 RenderNodeToUINodeAdapter(
1142 RenderObjectWithChildMixin<RenderBox> container,
1143 this.builder
1144 ) : _container = container {
1145 assert(builder != null);
1146 }
1147
1148 RenderObjectWithChildMixin<RenderBox> _container;
1149 RenderObjectWithChildMixin<RenderBox> get container => _container;
1150 void set container(RenderObjectWithChildMixin<RenderBox> value) {
1151 if (_container != value) {
1152 assert(value.child == null);
1153 if (root != null) {
1154 assert(_container.child == root);
1155 _container.child = null;
1156 }
1157 _container = value;
1158 if (root != null) {
1159 _container.child = root;
1160 assert(_container.child == root);
1161 }
1162 }
1163 }
1164
1165 final Builder builder;
1166
1167 void _buildIfDirty() {
1168 super._buildIfDirty();
1169 if (root.parent == null) {
1170 // we haven't attached it yet
1171 assert(_container.child == null);
1172 _container.child = root;
1173 }
1174 assert(root.parent == _container);
1175 }
1176
1177 UINode build() => builder();
1178
1106 } 1179 }
OLDNEW
« no previous file with comments | « sky/sdk/lib/framework/app.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698