OLD | NEW |
---|---|
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 $ANNOTATIONS | 6 $ANNOTATIONS |
7 class $CLASSNAME$EXTENDS$IMPLEMENTS$NATIVESPEC { | 7 class $CLASSNAME$EXTENDS$IMPLEMENTS$NATIVESPEC { |
8 | |
9 factory WheelEvent(String type, Window view, int wheelDeltaX, int wheelDeltaY, | |
10 int detail, int screenX, int screenY, int clientX, int clientY, | |
11 int button, | |
12 [bool canBubble = true, bool cancelable = true, bool ctrlKey = false, | |
13 bool altKey = false, bool shiftKey = false, bool metaKey = false, | |
14 EventTarget relatedTarget = null]) { | |
15 | |
16 var eventType = 'WheelEvent'; | |
17 if (_Device.isFirefox) { | |
18 eventType = 'MouseScrollEvents'; | |
19 } | |
20 final event = document.$dom_createEvent(eventType); | |
21 $if DART2JS | |
22 if (event._hasInitWheelEvent) { | |
23 var modifiers = []; | |
24 if (ctrlKey) { | |
25 modifiers.push('Control'); | |
26 } | |
27 if (altKey) { | |
28 modifiers.push('Alt'); | |
29 } | |
30 if (shiftKey) { | |
31 modifiers.push('Shift'); | |
32 } | |
33 if (metaKey) { | |
34 modifiers.push('Meta'); | |
35 } | |
36 event._initWheelEvent(type, canBubble, cancelable, view, detail, screenX, | |
37 screenY, clientX, clientY, button, relatedTarget, modifiers.join(' '), | |
38 wheelDeltaX, wheelDeltaY, 0, 0); | |
39 } else if (event._hasInitMouseScrollEvent) { | |
40 var axis = 0; | |
41 var detail = 0; | |
42 if (wheelDeltaX != 0 && wheelDeltaY != 0) { | |
43 throw UnsupportedError( | |
44 'Cannot modify wheelDeltaX and wheelDeltaY simultaneously'); | |
45 } | |
46 if (wheelDeltaY != 0) { | |
47 detail = wheelDeltaY; | |
48 axis = JS('int', 'MouseScrollEvent.VERTICAL_AXIS'); | |
49 } else if (wheelDeltaX != 0) { | |
50 detail = wheelDeltaX; | |
51 axis = JS('int', 'MouseScrollEvent.HORIZONTAL_AXIS'); | |
52 } | |
53 event._initMouseScrollEvent(type, canBubble, cancelable, view, detail, | |
54 screenX, screenY, clientX, clientY, ctrlKey, altKey, shiftKey, | |
55 metaKey, button, relatedTarget, axis); | |
56 } else { | |
57 $endif | |
58 // Fallthrough for Dartium. | |
59 event.$dom_initMouseEvent(type, canBubble, cancelable, view, detail, | |
60 screenX, screenY, clientX, clientY, ctrlKey, altKey, shiftKey, | |
61 metaKey, button, relatedTarget); | |
62 event.$dom_initWebKitWheelEvent(wheelDeltaX, | |
63 (wheelDeltaY / 120).toInt(), // Chrome does an auto-convert to pixels. | |
64 view, screenX, screenY, clientX, clientY, ctrlKey, altKey, shiftKey, | |
65 metaKey); | |
66 $if DART2JS | |
67 } | |
68 $endif | |
69 | |
70 return event; | |
71 } | |
72 | |
8 $!MEMBERS | 73 $!MEMBERS |
9 | 74 |
10 $if DART2JS | 75 $if DART2JS |
11 @DomName('WheelEvent.deltaY') | 76 @DomName('WheelEvent.deltaY') |
12 num get deltaY { | 77 num get deltaY { |
13 if (JS('bool', '#.deltaY !== undefined', this)) { | 78 if (JS('bool', '#.deltaY !== undefined', this)) { |
14 // W3C WheelEvent | 79 // W3C WheelEvent |
15 return this._deltaY; | 80 return this._deltaY; |
16 } else if (JS('bool', '#.wheelDelta !== undefined', this)) { | 81 } else if (JS('bool', '#.wheelDelta !== undefined', this)) { |
17 // Chrome and IE | 82 // Chrome and IE |
(...skipping 25 matching lines...) Expand all Loading... | |
43 return this._deltaX; | 108 return this._deltaX; |
44 } else if (JS('bool', '#.wheelDeltaX !== undefined', this)) { | 109 } else if (JS('bool', '#.wheelDeltaX !== undefined', this)) { |
45 // Chrome | 110 // Chrome |
46 return this._wheelDeltaX; | 111 return this._wheelDeltaX; |
47 } else if (JS('bool', '#.detail !== undefined', this)) { | 112 } else if (JS('bool', '#.detail !== undefined', this)) { |
48 // Firefox and IE. | 113 // Firefox and IE. |
49 // IE will have detail set but will not set axis. | 114 // IE will have detail set but will not set axis. |
50 | 115 |
51 // Handle DOMMouseScroll case where it uses detail and the axis to | 116 // Handle DOMMouseScroll case where it uses detail and the axis to |
52 // differentiate. | 117 // differentiate. |
53 if (JS('bool', '#.axis !== undefined && #.axis == MouseScrollEvent.HORIZON TAL_AXIS', this, this)) { | 118 if (JS('bool', '#.axis !== undefined && ' |
119 '#.axis == MouseScrollEvent.HORIZONTAL_AXIS', this, this)) { | |
54 var detail = this._detail; | 120 var detail = this._detail; |
55 // Firefox is normally the number of lines to scale (normally 3) | 121 // Firefox is normally the number of lines to scale (normally 3) |
56 // so multiply it by 40 to get pixels to move, matching IE & WebKit. | 122 // so multiply it by 40 to get pixels to move, matching IE & WebKit. |
57 if (detail < 100) { | 123 if (detail < 100) { |
58 return detail * 40; | 124 return detail * 40; |
59 } | 125 } |
60 return detail; | 126 return detail; |
61 } | 127 } |
62 return 0; | 128 return 0; |
63 } | 129 } |
64 throw new UnsupportedError( | 130 throw new UnsupportedError( |
65 'deltaX is not supported'); | 131 'deltaX is not supported'); |
66 } | 132 } |
67 | 133 |
68 int get deltaMode { | 134 int get deltaMode { |
69 if (JS('bool', '!!#.deltaMode', this)) { | 135 if (JS('bool', '!!#.deltaMode', this)) { |
70 // If not available then we're poly-filling and doing pixel scroll. | 136 // If not available then we're poly-filling and doing pixel scroll. |
71 return 0; | 137 return 0; |
72 } | 138 } |
73 return this._deltaMode; | 139 return this._deltaMode; |
74 } | 140 } |
75 | 141 |
76 num get _deltaY => JS('num', '#.deltaY', this); | 142 num get _deltaY => JS('num', '#.deltaY', this); |
77 num get _deltaX => JS('num', '#.deltaX', this); | 143 num get _deltaX => JS('num', '#.deltaX', this); |
78 num get _wheelDelta => JS('num', '#.wheelDelta', this); | 144 num get _wheelDelta => JS('num', '#.wheelDelta', this); |
79 num get _wheelDeltaX => JS('num', '#.wheelDeltaX', this); | 145 num get _wheelDeltaX => JS('num', '#.wheelDeltaX', this); |
80 num get _detail => JS('num', '#.detail', this); | 146 num get _detail => JS('num', '#.detail', this); |
81 int get _deltaMode => JS('int', '#.deltaMode', this); | 147 int get _deltaMode => JS('int', '#.deltaMode', this); |
82 | 148 |
149 bool get _hasInitMouseScrollEvent => | |
150 JS('bool', '!!(#.initMouseScrollEvent)', this); | |
151 | |
152 @JSName('initMouseScrollEvent') | |
153 void _initMouseScrollEvent( | |
154 String type, | |
Siggi Cherem (dart-lang)
2013/01/16 21:46:42
nit: ditto here on the convention
| |
155 bool canBubble, | |
156 bool cancelable, | |
157 Window view, | |
158 int detail, | |
159 int screenX, | |
160 int screenY, | |
161 int clientX, | |
162 int clientY, | |
163 bool ctrlKey, | |
164 bool altKey, | |
165 bool shiftKey, | |
166 bool metaKey, | |
167 int button, | |
168 EventTarget relatedTarget, | |
169 int axis) native; | |
170 | |
171 bool get _hasInitWheelEvent => | |
172 JS('bool', '!!(#.initWheelEvent)', this); | |
173 @JSName('initWheelEvent') | |
174 void _initWheelEvent( | |
175 String eventType, | |
176 bool canBubble, | |
177 bool cancelable, | |
178 Window view, | |
179 int detail, | |
180 int screenX, | |
181 int screenY, | |
182 int clientX, | |
183 int clientY, | |
184 int button, | |
185 EventTarget relatedTarget, | |
186 String modifiersList, | |
187 int deltaX, | |
188 int deltaY, | |
189 int deltaZ, | |
190 int deltaMode) native; | |
191 | |
83 $else | 192 $else |
84 @DomName('WheelEvent.deltaX') | 193 @DomName('WheelEvent.deltaX') |
85 num get deltaX => $dom_wheelDeltaX; | 194 num get deltaX => $dom_wheelDeltaX; |
86 @DomName('WheelEvent.deltaY') | 195 @DomName('WheelEvent.deltaY') |
87 num get deltaY => $dom_wheelDeltaY; | 196 num get deltaY => $dom_wheelDeltaY; |
88 @DomName('WheelEvent.deltaMode') | 197 @DomName('WheelEvent.deltaMode') |
89 int get deltaMode => 0; | 198 int get deltaMode => 0; |
90 | 199 |
91 $endif | 200 $endif |
92 } | 201 } |
OLD | NEW |