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

Side by Side Diff: lib/dom/templates/html/dartium/impl_EventTarget.darttemplate

Issue 10383302: Move dart:dom implementation classes to dart:html library. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: . Created 8 years, 7 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 | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 class _EventsImpl implements Events { 5 class _EventsImpl implements Events {
6 6 // TODO(podivilov): add type.
7 final _EventTargetImpl _ptr; 7 final _ptr;
8 8
9 final Map<String, EventListenerList> _listenerMap; 9 final Map<String, EventListenerList> _listenerMap;
10 10
11 _EventsImpl(this._ptr) : _listenerMap = <EventListenerList>{}; 11 _EventsImpl(this._ptr) : _listenerMap = <EventListenerList>{};
12 12
13 EventListenerList operator [](String type) { 13 EventListenerList operator [](String type) {
14 return _get(type.toLowerCase()); 14 return _get(type.toLowerCase());
15 } 15 }
16 16
17 EventListenerList _get(String type) { 17 EventListenerList _get(String type) {
18 return _listenerMap.putIfAbsent(type, 18 return _listenerMap.putIfAbsent(type,
19 () => new _EventListenerListImpl(_ptr, type)); 19 () => new _EventListenerListImpl(_ptr, type));
20 } 20 }
21 } 21 }
22 22
23 class _EventListenerWrapper { 23 class _EventListenerWrapper {
24 final EventListener raw; 24 final EventListener raw;
25 final Function wrapped; 25 final Function wrapped;
26 final bool useCapture; 26 final bool useCapture;
27 _EventListenerWrapper(this.raw, this.wrapped, this.useCapture); 27 _EventListenerWrapper(this.raw, this.wrapped, this.useCapture);
28 } 28 }
29 29
30 class _EventListenerListImpl implements EventListenerList { 30 class _EventListenerListImpl implements EventListenerList {
31 final _EventTargetImpl _ptr; 31 // TODO(podivilov): add type.
32 final _ptr;
32 final String _type; 33 final String _type;
33 List<_EventListenerWrapper> _wrappers; 34 List<_EventListenerWrapper> _wrappers;
34 35
35 _EventListenerListImpl(this._ptr, this._type) : 36 _EventListenerListImpl(this._ptr, this._type) :
36 // TODO(jacobr): switch to <_EventListenerWrapper>[] when the VM allow it. 37 // TODO(jacobr): switch to <_EventListenerWrapper>[] when the VM allow it.
37 _wrappers = new List<_EventListenerWrapper>(); 38 _wrappers = new List<_EventListenerWrapper>();
38 39
39 EventListenerList add(EventListener listener, [bool useCapture = false]) { 40 EventListenerList add(EventListener listener, [bool useCapture = false]) {
40 _add(listener, useCapture); 41 _add(listener, useCapture);
41 return this; 42 return this;
42 } 43 }
43 44
44 EventListenerList remove(EventListener listener, [bool useCapture = false]) { 45 EventListenerList remove(EventListener listener, [bool useCapture = false]) {
45 _remove(listener, useCapture); 46 _remove(listener, useCapture);
46 return this; 47 return this;
47 } 48 }
48 49
49 bool dispatch(Event evt) { 50 bool dispatch(Event evt) {
50 // TODO(jacobr): what is the correct behavior here. We could alternately 51 // TODO(jacobr): what is the correct behavior here. We could alternately
51 // force the event to have the expected type. 52 // force the event to have the expected type.
52 assert(evt.type == _type); 53 assert(evt.type == _type);
53 return _ptr.$dom_dispatchEvent(evt); 54 return _ptr.dispatchEvent(_unwrap(evt));
54 } 55 }
55 56
56 void _add(EventListener listener, bool useCapture) { 57 void _add(EventListener listener, bool useCapture) {
57 _ptr.$dom_addEventListener(_type, 58 _ptr.addEventListener(_type,
58 _findOrAddWrapper(listener, useCapture), 59 _findOrAddWrapper(listener, useCapture),
59 useCapture); 60 useCapture);
60 } 61 }
61 62
62 void _remove(EventListener listener, bool useCapture) { 63 void _remove(EventListener listener, bool useCapture) {
63 Function wrapper = _removeWrapper(listener, useCapture); 64 Function wrapper = _removeWrapper(listener, useCapture);
64 if (wrapper !== null) { 65 if (wrapper !== null) {
65 _ptr.$dom_removeEventListener(_type, wrapper, useCapture); 66 _ptr.removeEventListener(_type, wrapper, useCapture);
66 } 67 }
67 } 68 }
68 69
69 Function _removeWrapper(EventListener listener, bool useCapture) { 70 Function _removeWrapper(EventListener listener, bool useCapture) {
70 if (_wrappers === null) { 71 if (_wrappers === null) {
71 return null; 72 return null;
72 } 73 }
73 for (int i = 0; i < _wrappers.length; i++) { 74 for (int i = 0; i < _wrappers.length; i++) {
74 _EventListenerWrapper wrapper = _wrappers[i]; 75 _EventListenerWrapper wrapper = _wrappers[i];
75 if (wrapper.raw === listener && wrapper.useCapture == useCapture) { 76 if (wrapper.raw === listener && wrapper.useCapture == useCapture) {
(...skipping 30 matching lines...) Expand all
106 107
107 Events _on; 108 Events _on;
108 109
109 Events get on() { 110 Events get on() {
110 if (_on == null) _on = new _EventsImpl(this); 111 if (_on == null) _on = new _EventsImpl(this);
111 return _on; 112 return _on;
112 } 113 }
113 114
114 $!MEMBERS 115 $!MEMBERS
115 } 116 }
OLDNEW
« no previous file with comments | « lib/dom/templates/html/dartium/html_dartium.darttemplate ('k') | lib/html/src/dartium_FactoryProviders.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698