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

Side by Side Diff: tools/dom/templates/html/impl/impl_EventTarget.darttemplate

Issue 12217124: Removing deprecated events syntax. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 7 years, 10 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
« no previous file with comments | « tools/dom/src/Isolates.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 (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 part of $LIBRARYNAME; 5 part of $LIBRARYNAME;
6 6
7 /** 7 /**
8 * Base class that supports listening for and dispatching browser events. 8 * Base class that supports listening for and dispatching browser events.
9 * 9 *
10 * Events can either be accessed by string name (using the indexed getter) or by 10 * Events can either be accessed by string name (using the indexed getter) or by
11 * getters exposed by subclasses. Use the getters exposed by subclasses when 11 * getters exposed by subclasses. Use the getters exposed by subclasses when
12 * possible for better compile-time type checks. 12 * possible for better compile-time type checks.
13 * 13 *
14 * Using an indexed getter: 14 * Using an indexed getter:
15 * events['mouseover'].add((e) => print("Mouse over!")); 15 * events['mouseover'].add((e) => print("Mouse over!"));
16 * 16 *
17 * Using a getter provided by a subclass: 17 * Using a getter provided by a subclass:
18 * elementEvents.mouseOver.add((e) => print("Mouse over!")); 18 * elementEvents.mouseOver.add((e) => print("Mouse over!"));
19 */ 19 */
20 class Events { 20 class Events {
21 /* Raw event target. */ 21 /* Raw event target. */
22 final EventTarget _ptr; 22 final EventTarget _ptr;
23 23
24 Events(this._ptr); 24 Events(this._ptr);
25 25
26 EventListenerList operator [](String type) { 26 Stream operator [](String type) {
27 return new EventListenerList(_ptr, type); 27 return new _EventStream(_ptr, type, false);
28 } 28 }
29 } 29 }
30 30
31 /**
32 * Supports adding, removing, and dispatching events for a specific event type.
33 */
34 class EventListenerList {
35
36 final EventTarget _ptr;
37 final String _type;
38
39 EventListenerList(this._ptr, this._type);
40
41 // TODO(jacobr): implement equals.
42
43 EventListenerList add(EventListener listener,
44 [bool useCapture = false]) {
45 _add(listener, useCapture);
46 return this;
47 }
48
49 EventListenerList remove(EventListener listener,
50 [bool useCapture = false]) {
51 _remove(listener, useCapture);
52 return this;
53 }
54
55 bool dispatch(Event evt) {
56 return _ptr.dispatchEvent(evt);
57 }
58
59 void _add(EventListener listener, bool useCapture) {
60 _ptr.$dom_addEventListener(_type, listener, useCapture);
61 }
62
63 void _remove(EventListener listener, bool useCapture) {
64 _ptr.$dom_removeEventListener(_type, listener, useCapture);
65 }
66 }
67
68 /** 31 /**
69 * Base class for all browser objects that support events. 32 * Base class for all browser objects that support events.
70 * 33 *
71 * Use the [on] property to add, remove, and dispatch events (rather than 34 * Use the [on] property to add, remove, and dispatch events (rather than
72 * [$dom_addEventListener], [$dom_dispatchEvent], and 35 * [$dom_addEventListener], [$dom_dispatchEvent], and
73 * [$dom_removeEventListener]) for compile-time type checks and a more concise 36 * [$dom_removeEventListener]) for compile-time type checks and a more concise
74 * API. 37 * API.
75 */ 38 */
76 $(ANNOTATIONS)class $CLASSNAME$EXTENDS$IMPLEMENTS$NATIVESPEC { 39 $(ANNOTATIONS)class $CLASSNAME$EXTENDS$IMPLEMENTS$NATIVESPEC {
77 40
78 @DomName('EventTarget.addEventListener, EventTarget.removeEventListener, Event Target.dispatchEvent') 41 @DomName('EventTarget.addEventListener, EventTarget.removeEventListener, Event Target.dispatchEvent')
79 Events get on => new Events(this); 42 Events get on => new Events(this);
80 $!MEMBERS 43 $!MEMBERS
81 } 44 }
OLDNEW
« no previous file with comments | « tools/dom/src/Isolates.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698