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 '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 150 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
161 super._remove(); | 161 super._remove(); |
162 } | 162 } |
163 } | 163 } |
164 | 164 |
165 class ParentDataNode extends ContentNode { | 165 class ParentDataNode extends ContentNode { |
166 final ParentData parentData; | 166 final ParentData parentData; |
167 | 167 |
168 ParentDataNode(UINode content, this.parentData): super(content); | 168 ParentDataNode(UINode content, this.parentData): super(content); |
169 } | 169 } |
170 | 170 |
171 typedef GestureEventListener(sky.GestureEvent e); | 171 typedef void GestureEventListener(sky.GestureEvent e); |
172 typedef PointerEventListener(sky.PointerEvent e); | 172 typedef void PointerEventListener(sky.PointerEvent e); |
173 typedef EventListener(sky.Event e); | 173 typedef void EventListener(sky.Event e); |
174 | 174 |
175 class EventListenerNode extends ContentNode { | 175 class EventListenerNode extends ContentNode { |
176 final Map<String, sky.EventListener> listeners; | 176 final Map<String, sky.EventListener> listeners; |
177 | 177 |
178 static final Set<String> _registeredEvents = new HashSet<String>(); | |
179 | |
180 static Map<String, sky.EventListener> _createListeners({ | 178 static Map<String, sky.EventListener> _createListeners({ |
181 EventListener onWheel, | 179 EventListener onWheel, |
182 GestureEventListener onGestureFlingCancel, | 180 GestureEventListener onGestureFlingCancel, |
183 GestureEventListener onGestureFlingStart, | 181 GestureEventListener onGestureFlingStart, |
184 GestureEventListener onGestureScrollStart, | 182 GestureEventListener onGestureScrollStart, |
185 GestureEventListener onGestureScrollUpdate, | 183 GestureEventListener onGestureScrollUpdate, |
186 GestureEventListener onGestureTap, | 184 GestureEventListener onGestureTap, |
187 GestureEventListener onGestureTapDown, | 185 GestureEventListener onGestureTapDown, |
188 PointerEventListener onPointerCancel, | 186 PointerEventListener onPointerCancel, |
189 PointerEventListener onPointerDown, | 187 PointerEventListener onPointerDown, |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
249 custom: custom | 247 custom: custom |
250 ), | 248 ), |
251 super(content); | 249 super(content); |
252 | 250 |
253 void _handleEvent(sky.Event e) { | 251 void _handleEvent(sky.Event e) { |
254 sky.EventListener listener = listeners[e.type]; | 252 sky.EventListener listener = listeners[e.type]; |
255 if (listener != null) { | 253 if (listener != null) { |
256 listener(e); | 254 listener(e); |
257 } | 255 } |
258 } | 256 } |
259 | |
260 static void _dispatchEvent(sky.Event e) { | |
261 UINode target = RenderNodeWrapper._getMounted(bridgeEventTargetToRenderNode( e.target)); | |
262 | |
263 // TODO(rafaelw): StopPropagation? | |
264 while (target != null) { | |
265 if (target is EventListenerNode) { | |
266 target._handleEvent(e); | |
267 } | |
268 | |
269 target = target._parent; | |
270 } | |
271 } | |
272 | |
273 static void _ensureDocumentListener(String eventType) { | |
274 if (_registeredEvents.add(eventType)) { | |
275 sky.document.addEventListener(eventType, _dispatchEvent); | |
276 } | |
277 } | |
278 | |
279 void _sync(UINode old, dynamic slot) { | |
280 for (var type in listeners.keys) { | |
281 _ensureDocumentListener(type); | |
282 } | |
283 super._sync(old, slot); | |
284 } | |
285 } | 257 } |
286 | 258 |
287 /* | 259 /* |
288 * RenderNodeWrappers correspond to a desired state of a RenderNode. | 260 * RenderNodeWrappers correspond to a desired state of a RenderNode. |
289 * They are fully immutable, with one exception: A UINode which is a | 261 * They are fully immutable, with one exception: A UINode which is a |
290 * Component which lives within an OneChildListRenderNodeWrapper's | 262 * Component which lives within an OneChildListRenderNodeWrapper's |
291 * children list, may be replaced with the "old" instance if it has | 263 * children list, may be replaced with the "old" instance if it has |
292 * become stateful. | 264 * become stateful. |
293 */ | 265 */ |
294 abstract class RenderNodeWrapper extends UINode { | 266 abstract class RenderNodeWrapper extends UINode { |
(...skipping 596 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
891 if (_isBuilding || _dirty || _defunct) | 863 if (_isBuilding || _dirty || _defunct) |
892 return; | 864 return; |
893 | 865 |
894 _dirty = true; | 866 _dirty = true; |
895 _scheduleComponentForRender(this); | 867 _scheduleComponentForRender(this); |
896 } | 868 } |
897 | 869 |
898 UINode build(); | 870 UINode build(); |
899 } | 871 } |
900 | 872 |
873 class _AppView extends AppView { | |
eseidel
2015/06/02 19:12:47
FnAppView?
| |
874 _AppView() : super(null); | |
875 | |
876 void dispatchPointerEvent(sky.PointerEvent event, HitTestResult result) { | |
877 super.dispatchPointerEvent(event, result); | |
878 | |
879 UINode target = RenderNodeWrapper._getMounted(result.path.first); | |
880 | |
881 // TODO(rafaelw): StopPropagation? | |
882 while (target != null) { | |
883 if (target is EventListenerNode) | |
884 target._handleEvent(event); | |
885 target = target._parent; | |
886 } | |
887 } | |
888 } | |
889 | |
901 abstract class App extends Component { | 890 abstract class App extends Component { |
902 | 891 |
903 App() : super(stateful: true) { | 892 App() : super(stateful: true) { |
904 _appView = new AppView(null); | 893 _appView = new _AppView(); |
905 _scheduleComponentForRender(this); | 894 _scheduleComponentForRender(this); |
906 } | 895 } |
907 | 896 |
908 AppView _appView; | 897 AppView _appView; |
909 | 898 |
910 void _buildIfDirty() { | 899 void _buildIfDirty() { |
911 assert(_dirty); | 900 assert(_dirty); |
912 assert(!_defunct); | 901 assert(!_defunct); |
913 _trace('$_key rebuilding app...'); | 902 _trace('$_key rebuilding app...'); |
914 _sync(null, null); | 903 _sync(null, null); |
(...skipping 12 matching lines...) Expand all Loading... | |
927 | 916 |
928 | 917 |
929 // for now, but only for now: | 918 // for now, but only for now: |
930 | 919 |
931 class RenderSolidColor extends RenderDecoratedBox { | 920 class RenderSolidColor extends RenderDecoratedBox { |
932 final sky.Size desiredSize; | 921 final sky.Size desiredSize; |
933 final int backgroundColor; | 922 final int backgroundColor; |
934 | 923 |
935 RenderSolidColor(int backgroundColor, { this.desiredSize }) | 924 RenderSolidColor(int backgroundColor, { this.desiredSize }) |
936 : backgroundColor = backgroundColor, | 925 : backgroundColor = backgroundColor, |
937 super(new BoxDecoration(backgroundColor: backgroundColor)); | 926 super(decoration: new BoxDecoration(backgroundColor: backgroundColor)); |
938 | 927 |
939 sky.Size getIntrinsicDimensions(BoxConstraints constraints) { | 928 sky.Size getIntrinsicDimensions(BoxConstraints constraints) { |
940 return constraints.constrain(desiredSize); | 929 return constraints.constrain(desiredSize); |
941 } | 930 } |
942 | 931 |
943 void performLayout() { | 932 void performLayout() { |
944 size = constraints.constrain(desiredSize); | 933 size = constraints.constrain(desiredSize); |
945 } | 934 } |
946 | 935 |
947 void handlePointer(sky.PointerEvent event) { | 936 void handlePointer(sky.PointerEvent event) { |
(...skipping 14 matching lines...) Expand all Loading... | |
962 | 951 |
963 final int color; | 952 final int color; |
964 | 953 |
965 RenderSolidColor root; | 954 RenderSolidColor root; |
966 RenderSolidColor createNode() => new RenderSolidColor(color, desiredSize: new sky.Size(40.0, 130.0)); | 955 RenderSolidColor createNode() => new RenderSolidColor(color, desiredSize: new sky.Size(40.0, 130.0)); |
967 | 956 |
968 static final Rectangle _emptyRectangle = new Rectangle(0); | 957 static final Rectangle _emptyRectangle = new Rectangle(0); |
969 RenderNodeWrapper get emptyNode => _emptyRectangle; | 958 RenderNodeWrapper get emptyNode => _emptyRectangle; |
970 | 959 |
971 } | 960 } |
OLD | NEW |