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

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: 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
35 if (_Device.isWebKit) {
36 event.$dom_initMouseEvent(
37 type,
38 canBubble,
39 cancelable,
40 view,
41 detail,
42 screenX,
43 screenY,
44 clientX,
45 clientY,
46 ctrlKey,
47 altKey,
48 shiftKey,
49 metaKey,
50 button,
51 relatedTarget);
52 event.$dom_initWebKitWheelEvent(
53 wheelDeltaX,
54 (wheelDeltaY / 120).toInt(), // Chrome does an auto-convert to pixels.
55 view,
56 screenX,
57 screenY,
58 clientX,
59 clientY,
60 ctrlKey,
61 altKey,
62 shiftKey,
63 metaKey);
64 }
65 $if DART2JS
66 else if (_Device.isIE) {
67 var modifiers = [];
68 if (ctrlKey) {
69 modifiers.push('Control');
70 }
71 if (altKey) {
72 modifiers.push('Alt');
73 }
74 if (shiftKey) {
75 modifiers.push('Shift');
76 }
77 if (metaKey) {
78 modifiers.push('Meta');
79 }
80 var modifiersList = modifiers.join(' ');
81 event._initIEWheelEvent(
82 type,
83 canBubble,
84 cancelable,
85 view,
86 detail,
87 screenX,
88 screenY,
89 clientX,
90 clientY,
91 button,
92 relatedTarget,
93 modifiersList,
94 wheelDeltaX,
95 wheelDeltaY,
96 0,
97 0);
98 } else if (_Device.isFirefox) {
99 var axis = 0;
100 var detail = 0;
101 if (wheelDeltaX != 0 && wheelDeltaY != 0) {
102 throw UnsupportedError(
103 'Cannot modify wheelDeltaX and wheelDeltaY simultaneously');
104 }
105 if (wheelDeltaY != 0) {
106 detail = wheelDeltaY;
107 axis = JS('int', 'MouseScrollEvent.VERTICAL_AXIS');
108 } else if (wheelDeltaX != 0) {
109 detail = wheelDeltaX;
110 axis = JS('int', 'MouseScrollEvent.HORIZONTAL_AXIS');
111 }
112 event._initFireFoxMouseScrollEvent(
113 type,
114 canBubble,
115 cancelable,
116 view,
117 detail,
118 screenX,
119 screenY,
120 clientX,
121 clientY,
122 ctrlKey,
123 altKey,
124 shiftKey,
125 metaKey,
126 button,
127 relatedTarget,
128 axis);
129 }
130 $endif
131 return event;
132 }
133
9 $!MEMBERS 134 $!MEMBERS
10 135
11 $if DART2JS 136 $if DART2JS
12 /** @domName WheelEvent.deltaY */ 137 /** @domName WheelEvent.deltaY */
13 num get deltaY { 138 num get deltaY {
14 if (JS('bool', '#.deltaY !== undefined', this)) { 139 if (JS('bool', '#.deltaY !== undefined', this)) {
15 // W3C WheelEvent 140 // W3C WheelEvent
16 return this._deltaY; 141 return this._deltaY;
17 } else if (JS('bool', '#.wheelDelta !== undefined', this)) { 142 } else if (JS('bool', '#.wheelDelta !== undefined', this)) {
18 // Chrome and IE 143 // Chrome and IE
(...skipping 25 matching lines...) Expand all
44 return this._deltaX; 169 return this._deltaX;
45 } else if (JS('bool', '#.wheelDeltaX !== undefined', this)) { 170 } else if (JS('bool', '#.wheelDeltaX !== undefined', this)) {
46 // Chrome 171 // Chrome
47 return this._wheelDeltaX; 172 return this._wheelDeltaX;
48 } else if (JS('bool', '#.detail !== undefined', this)) { 173 } else if (JS('bool', '#.detail !== undefined', this)) {
49 // Firefox and IE. 174 // Firefox and IE.
50 // IE will have detail set but will not set axis. 175 // IE will have detail set but will not set axis.
51 176
52 // Handle DOMMouseScroll case where it uses detail and the axis to 177 // Handle DOMMouseScroll case where it uses detail and the axis to
53 // differentiate. 178 // differentiate.
54 if (JS('bool', '#.axis !== undefined && #.axis == MouseScrollEvent.HORIZON TAL_AXIS', this, this)) { 179 if (JS('bool', '#.axis !== undefined && '
180 '#.axis == MouseScrollEvent.HORIZONTAL_AXIS', this, this)) {
55 var detail = this._detail; 181 var detail = this._detail;
56 // Firefox is normally the number of lines to scale (normally 3) 182 // 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. 183 // so multiply it by 40 to get pixels to move, matching IE & WebKit.
58 if (detail < 100) { 184 if (detail < 100) {
59 return detail * 40; 185 return detail * 40;
60 } 186 }
61 return detail; 187 return detail;
62 } 188 }
63 return 0; 189 return 0;
64 } 190 }
65 throw new UnsupportedError( 191 throw new UnsupportedError(
66 'deltaX is not supported'); 192 'deltaX is not supported');
67 } 193 }
68 194
69 int get deltaMode { 195 int get deltaMode {
70 if (JS('bool', '!!#.deltaMode', this)) { 196 if (JS('bool', '!!#.deltaMode', this)) {
71 // If not available then we're poly-filling and doing pixel scroll. 197 // If not available then we're poly-filling and doing pixel scroll.
72 return 0; 198 return 0;
73 } 199 }
74 return this._deltaMode; 200 return this._deltaMode;
75 } 201 }
76 202
77 num get _deltaY => JS('num', '#.deltaY', this); 203 num get _deltaY => JS('num', '#.deltaY', this);
78 num get _deltaX => JS('num', '#.deltaX', this); 204 num get _deltaX => JS('num', '#.deltaX', this);
79 num get _wheelDelta => JS('num', '#.wheelDelta', this); 205 num get _wheelDelta => JS('num', '#.wheelDelta', this);
80 num get _wheelDeltaX => JS('num', '#.wheelDeltaX', this); 206 num get _wheelDeltaX => JS('num', '#.wheelDeltaX', this);
81 num get _detail => JS('num', '#.detail', this); 207 num get _detail => JS('num', '#.detail', this);
82 int get _deltaMode => JS('int', '#.deltaMode', this); 208 int get _deltaMode => JS('int', '#.deltaMode', this);
83 209
210 @JSName('initMouseScrollEvent')
211 void _initFireFoxMouseScrollEvent(
212 String type,
213 bool canBubble,
214 bool cancelable,
215 Window view,
216 int detail,
217 int screenX,
218 int screenY,
219 int clientX,
220 int clientY,
221 bool ctrlKey,
222 bool altKey,
223 bool shiftKey,
224 bool metaKey,
225 int button,
226 EventTarget relatedTarget,
227 int axis) native;
228
229 @JSName('initWheelEvent')
230 void _initIEWheelEvent(
231 String eventType,
232 bool canBubble,
233 bool cancelable,
234 Window view,
235 int detail,
236 int screenX,
237 int screenY,
238 int clientX,
239 int clientY,
240 int button,
241 EventTarget relatedTarget,
242 String modifiersList,
243 int deltaX,
244 int deltaY,
245 int deltaZ,
246 int deltaMode) native;
247
84 $else 248 $else
85 /** @domName WheelEvent.deltaX */ 249 /** @domName WheelEvent.deltaX */
86 num get deltaX => $dom_wheelDeltaX; 250 num get deltaX => $dom_wheelDeltaX;
87 /** @domName WheelEvent.deltaY */ 251 /** @domName WheelEvent.deltaY */
88 num get deltaY => $dom_wheelDeltaY; 252 num get deltaY => $dom_wheelDeltaY;
89 /** @domName WheelEvent.deltaMode */ 253 /** @domName WheelEvent.deltaMode */
90 int get deltaMode => 0; 254 int get deltaMode => 0;
91 255
92 $endif 256 $endif
93 } 257 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698