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

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

Issue 11931009: Adding support for the MouseWheel event in Streams. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Adding more dynamic checking for which init function to use. Created 7 years, 11 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 part of html; 5 part of html;
6 6
7 /// @domName $DOMNAME 7 /// @domName $DOMNAME
8 class $CLASSNAME$EXTENDS$IMPLEMENTS$NATIVESPEC { 8 class $CLASSNAME$EXTENDS$IMPLEMENTS$NATIVESPEC {
9
10 factory WheelEvent(
11 String type,
12 Window view,
13 int wheelDeltaX,
14 int wheelDeltaY,
15 int detail,
16 int screenX,
17 int screenY,
18 int clientX,
19 int clientY,
20 int button,
21 [bool canBubble = true,
22 bool cancelable = true,
23 bool ctrlKey = false,
24 bool altKey = false,
25 bool shiftKey = false,
26 bool metaKey = false,
27 EventTarget relatedTarget = null]) {
28
29 var eventType = 'WheelEvent';
30 if (_Device.isFirefox) {
31 eventType = 'MouseScrollEvents';
32 }
33 final event = document.$dom_createEvent(eventType);
34 $if DART2JS
35 if (event._hasInitWheelEvent) {
36 var modifiers = [];
37 if (ctrlKey) {
38 modifiers.push('Control');
39 }
40 if (altKey) {
41 modifiers.push('Alt');
42 }
43 if (shiftKey) {
44 modifiers.push('Shift');
45 }
46 if (metaKey) {
47 modifiers.push('Meta');
48 }
49 var modifiersList = modifiers.join(' ');
50 event._initWheelEvent(
51 type,
52 canBubble,
53 cancelable,
54 view,
55 detail,
56 screenX,
57 screenY,
58 clientX,
59 clientY,
60 button,
61 relatedTarget,
62 modifiersList,
63 wheelDeltaX,
64 wheelDeltaY,
65 0,
66 0);
67 } else if (event._hasInitMouseScrollEvent) {
68 var axis = 0;
69 var detail = 0;
70 if (wheelDeltaX != 0 && wheelDeltaY != 0) {
71 throw UnsupportedError(
72 'Cannot modify wheelDeltaX and wheelDeltaY simultaneously');
73 }
74 if (wheelDeltaY != 0) {
75 detail = wheelDeltaY;
76 axis = JS('int', 'MouseScrollEvent.VERTICAL_AXIS');
77 } else if (wheelDeltaX != 0) {
78 detail = wheelDeltaX;
79 axis = JS('int', 'MouseScrollEvent.HORIZONTAL_AXIS');
80 }
81 event._initMouseScrollEvent(
82 type,
83 canBubble,
84 cancelable,
85 view,
86 detail,
87 screenX,
88 screenY,
89 clientX,
90 clientY,
91 ctrlKey,
92 altKey,
93 shiftKey,
94 metaKey,
95 button,
96 relatedTarget,
97 axis);
98 } else {
99 $endif
100 // Fallthrough for Dartium.
101 event.$dom_initMouseEvent(
102 type,
103 canBubble,
104 cancelable,
105 view,
106 detail,
107 screenX,
108 screenY,
109 clientX,
110 clientY,
111 ctrlKey,
112 altKey,
113 shiftKey,
114 metaKey,
115 button,
116 relatedTarget);
117 event.$dom_initWebKitWheelEvent(
118 wheelDeltaX,
119 (wheelDeltaY / 120).toInt(), // Chrome does an auto-convert to pixels.
120 view,
121 screenX,
122 screenY,
123 clientX,
124 clientY,
125 ctrlKey,
126 altKey,
127 shiftKey,
128 metaKey);
129 $if DART2JS
130 }
131 $endif
132
133 return event;
134 }
135
9 $!MEMBERS 136 $!MEMBERS
10 137
11 $if DART2JS 138 $if DART2JS
12 /** @domName WheelEvent.deltaY */ 139 /** @domName WheelEvent.deltaY */
13 num get deltaY { 140 num get deltaY {
14 if (JS('bool', '#.deltaY !== undefined', this)) { 141 if (JS('bool', '#.deltaY !== undefined', this)) {
15 // W3C WheelEvent 142 // W3C WheelEvent
16 return this._deltaY; 143 return this._deltaY;
17 } else if (JS('bool', '#.wheelDelta !== undefined', this)) { 144 } else if (JS('bool', '#.wheelDelta !== undefined', this)) {
18 // Chrome and IE 145 // Chrome and IE
(...skipping 25 matching lines...) Expand all
44 return this._deltaX; 171 return this._deltaX;
45 } else if (JS('bool', '#.wheelDeltaX !== undefined', this)) { 172 } else if (JS('bool', '#.wheelDeltaX !== undefined', this)) {
46 // Chrome 173 // Chrome
47 return this._wheelDeltaX; 174 return this._wheelDeltaX;
48 } else if (JS('bool', '#.detail !== undefined', this)) { 175 } else if (JS('bool', '#.detail !== undefined', this)) {
49 // Firefox and IE. 176 // Firefox and IE.
50 // IE will have detail set but will not set axis. 177 // IE will have detail set but will not set axis.
51 178
52 // Handle DOMMouseScroll case where it uses detail and the axis to 179 // Handle DOMMouseScroll case where it uses detail and the axis to
53 // differentiate. 180 // differentiate.
54 if (JS('bool', '#.axis !== undefined && #.axis == MouseScrollEvent.HORIZON TAL_AXIS', this, this)) { 181 if (JS('bool', '#.axis !== undefined && '
182 '#.axis == MouseScrollEvent.HORIZONTAL_AXIS', this, this)) {
55 var detail = this._detail; 183 var detail = this._detail;
56 // Firefox is normally the number of lines to scale (normally 3) 184 // Firefox is normally the number of lines to scale (normally 3)
57 // so multiply it by 40 to get pixels to move, matching IE & WebKit. 185 // so multiply it by 40 to get pixels to move, matching IE & WebKit.
58 if (detail < 100) { 186 if (detail < 100) {
59 return detail * 40; 187 return detail * 40;
60 } 188 }
61 return detail; 189 return detail;
62 } 190 }
63 return 0; 191 return 0;
64 } 192 }
65 throw new UnsupportedError( 193 throw new UnsupportedError(
66 'deltaX is not supported'); 194 'deltaX is not supported');
67 } 195 }
68 196
69 int get deltaMode { 197 int get deltaMode {
70 if (JS('bool', '!!#.deltaMode', this)) { 198 if (JS('bool', '!!#.deltaMode', this)) {
71 // If not available then we're poly-filling and doing pixel scroll. 199 // If not available then we're poly-filling and doing pixel scroll.
72 return 0; 200 return 0;
73 } 201 }
74 return this._deltaMode; 202 return this._deltaMode;
75 } 203 }
76 204
77 num get _deltaY => JS('num', '#.deltaY', this); 205 num get _deltaY => JS('num', '#.deltaY', this);
78 num get _deltaX => JS('num', '#.deltaX', this); 206 num get _deltaX => JS('num', '#.deltaX', this);
79 num get _wheelDelta => JS('num', '#.wheelDelta', this); 207 num get _wheelDelta => JS('num', '#.wheelDelta', this);
80 num get _wheelDeltaX => JS('num', '#.wheelDeltaX', this); 208 num get _wheelDeltaX => JS('num', '#.wheelDeltaX', this);
81 num get _detail => JS('num', '#.detail', this); 209 num get _detail => JS('num', '#.detail', this);
82 int get _deltaMode => JS('int', '#.deltaMode', this); 210 int get _deltaMode => JS('int', '#.deltaMode', this);
83 211
212 bool get _hasInitMouseScrollEvent =>
213 JS('bool', '!!(#.initMouseScrollEvent)', this);
214
215 @JSName('initMouseScrollEvent')
216 void _initMouseScrollEvent(
217 String type,
218 bool canBubble,
219 bool cancelable,
220 Window view,
221 int detail,
222 int screenX,
223 int screenY,
224 int clientX,
225 int clientY,
226 bool ctrlKey,
227 bool altKey,
228 bool shiftKey,
229 bool metaKey,
230 int button,
231 EventTarget relatedTarget,
232 int axis) native;
233
234 bool get _hasInitWheelEvent =>
235 JS('bool', '!!(#.initWheelEvent)', this);
236 @JSName('initWheelEvent')
237 void _initWheelEvent(
238 String eventType,
239 bool canBubble,
240 bool cancelable,
241 Window view,
242 int detail,
243 int screenX,
244 int screenY,
245 int clientX,
246 int clientY,
247 int button,
248 EventTarget relatedTarget,
249 String modifiersList,
250 int deltaX,
251 int deltaY,
252 int deltaZ,
253 int deltaMode) native;
254
84 $else 255 $else
85 /** @domName WheelEvent.deltaX */ 256 /** @domName WheelEvent.deltaX */
86 num get deltaX => $dom_wheelDeltaX; 257 num get deltaX => $dom_wheelDeltaX;
87 /** @domName WheelEvent.deltaY */ 258 /** @domName WheelEvent.deltaY */
88 num get deltaY => $dom_wheelDeltaY; 259 num get deltaY => $dom_wheelDeltaY;
89 /** @domName WheelEvent.deltaMode */ 260 /** @domName WheelEvent.deltaMode */
90 int get deltaMode => 0; 261 int get deltaMode => 0;
91 262
92 $endif 263 $endif
93 } 264 }
OLDNEW
« tests/html/wheelevent_test.dart ('K') | « tools/dom/templates/html/impl/impl_Element.darttemplate ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698