| 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 $LIBRARYNAME; | 5 part of $LIBRARYNAME; |
| 6 | 6 |
| 7 $(ANNOTATIONS)class $CLASSNAME$EXTENDS$IMPLEMENTS$NATIVESPEC { | 7 $(ANNOTATIONS)class $CLASSNAME$EXTENDS$IMPLEMENTS$NATIVESPEC { |
| 8 | 8 |
| 9 factory WheelEvent(String type, | 9 factory WheelEvent(String type, |
| 10 {Window view, int deltaX: 0, int deltaY: 0, | 10 {Window view, int deltaX: 0, int deltaY: 0, |
| 11 int detail: 0, int screenX: 0, int screenY: 0, int clientX: 0, | 11 int detail: 0, int screenX: 0, int screenY: 0, int clientX: 0, |
| 12 int clientY: 0, int button: 0, bool canBubble: true, | 12 int clientY: 0, int button: 0, bool canBubble: true, |
| 13 bool cancelable: true, bool ctrlKey: false, bool altKey: false, | 13 bool cancelable: true, bool ctrlKey: false, bool altKey: false, |
| 14 bool shiftKey: false, bool metaKey: false, EventTarget relatedTarget}) { | 14 bool shiftKey: false, bool metaKey: false, EventTarget relatedTarget}) { |
| 15 | 15 |
| 16 if (view == null) { | 16 if (view == null) { |
| 17 view = window; | 17 view = window; |
| 18 } | 18 } |
| 19 var eventType = 'WheelEvent'; | 19 var eventType = 'WheelEvent'; |
| 20 if (Device.isFirefox) { | 20 if (Device.isFirefox) { |
| 21 eventType = 'MouseScrollEvents'; | 21 eventType = 'MouseScrollEvents'; |
| 22 } | 22 } |
| 23 final event = document.$dom_createEvent(eventType); | 23 final event = document.$dom_createEvent(eventType); |
| 24 $if DART2JS | 24 $if DART2JS |
| 25 // If polyfilling, then flip these because we'll flip them back to match |
| 26 // the W3C standard: |
| 27 // http://dev.w3.org/2006/webapi/DOM-Level-3-Events/html/DOM3-Events.html#ev
ents-WheelEvent-deltaY |
| 28 if (JS('bool', '#.deltaY === undefined', event)) { |
| 29 deltaX = -deltaX; |
| 30 deltaY = -deltaY; |
| 31 } |
| 25 if (event._hasInitWheelEvent) { | 32 if (event._hasInitWheelEvent) { |
| 26 var modifiers = []; | 33 var modifiers = []; |
| 27 if (ctrlKey) { | 34 if (ctrlKey) { |
| 28 modifiers.push('Control'); | 35 modifiers.push('Control'); |
| 29 } | 36 } |
| 30 if (altKey) { | 37 if (altKey) { |
| 31 modifiers.push('Alt'); | 38 modifiers.push('Alt'); |
| 32 } | 39 } |
| 33 if (shiftKey) { | 40 if (shiftKey) { |
| 34 modifiers.push('Shift'); | 41 modifiers.push('Shift'); |
| (...skipping 15 matching lines...) Expand all Loading... |
| 50 detail = deltaY; | 57 detail = deltaY; |
| 51 axis = JS('int', 'MouseScrollEvent.VERTICAL_AXIS'); | 58 axis = JS('int', 'MouseScrollEvent.VERTICAL_AXIS'); |
| 52 } else if (deltaX != 0) { | 59 } else if (deltaX != 0) { |
| 53 detail = deltaX; | 60 detail = deltaX; |
| 54 axis = JS('int', 'MouseScrollEvent.HORIZONTAL_AXIS'); | 61 axis = JS('int', 'MouseScrollEvent.HORIZONTAL_AXIS'); |
| 55 } | 62 } |
| 56 event._initMouseScrollEvent(type, canBubble, cancelable, view, detail, | 63 event._initMouseScrollEvent(type, canBubble, cancelable, view, detail, |
| 57 screenX, screenY, clientX, clientY, ctrlKey, altKey, shiftKey, | 64 screenX, screenY, clientX, clientY, ctrlKey, altKey, shiftKey, |
| 58 metaKey, button, relatedTarget, axis); | 65 metaKey, button, relatedTarget, axis); |
| 59 } else { | 66 } else { |
| 67 $else |
| 68 // Dartium always needs these flipped because we're essentially always |
| 69 // polyfilling (see similar dart2js code as well) |
| 70 deltaX = -deltaX; |
| 71 deltaY = -deltaY; |
| 60 $endif | 72 $endif |
| 61 // Fallthrough for Dartium. | 73 // Fallthrough for Dartium. |
| 62 event.$dom_initMouseEvent(type, canBubble, cancelable, view, detail, | 74 event.$dom_initMouseEvent(type, canBubble, cancelable, view, detail, |
| 63 screenX, screenY, clientX, clientY, ctrlKey, altKey, shiftKey, | 75 screenX, screenY, clientX, clientY, ctrlKey, altKey, shiftKey, |
| 64 metaKey, button, relatedTarget); | 76 metaKey, button, relatedTarget); |
| 65 event.$dom_initWebKitWheelEvent(deltaX, | 77 event.$dom_initWebKitWheelEvent(deltaX, |
| 66 deltaY ~/ 120, // Chrome does an auto-convert to pixels. | 78 deltaY ~/ 120, // Chrome does an auto-convert to pixels. |
| 67 view, screenX, screenY, clientX, clientY, ctrlKey, altKey, shiftKey, | 79 view, screenX, screenY, clientX, clientY, ctrlKey, altKey, shiftKey, |
| 68 metaKey); | 80 metaKey); |
| 69 $if DART2JS | 81 $if DART2JS |
| 70 } | 82 } |
| 71 $endif | 83 $endif |
| 72 | 84 |
| 73 return event; | 85 return event; |
| 74 } | 86 } |
| 75 | 87 |
| 76 $!MEMBERS | 88 $!MEMBERS |
| 77 | 89 |
| 78 $if DART2JS | 90 $if DART2JS |
| 91 /** |
| 92 * The amount that is expected to scroll vertically, in units determined by |
| 93 * [deltaMode]. |
| 94 * |
| 95 * See also: |
| 96 * |
| 97 * * [WheelEvent.deltaY](http://dev.w3.org/2006/webapi/DOM-Level-3-Events/html
/DOM3-Events.html#events-WheelEvent-deltaY) from the W3C. |
| 98 */ |
| 79 @DomName('WheelEvent.deltaY') | 99 @DomName('WheelEvent.deltaY') |
| 80 num get deltaY { | 100 num get deltaY { |
| 81 if (JS('bool', '#.deltaY !== undefined', this)) { | 101 if (JS('bool', '#.deltaY !== undefined', this)) { |
| 82 // W3C WheelEvent | 102 // W3C WheelEvent |
| 83 return this._deltaY; | 103 return this._deltaY; |
| 84 } else if (JS('bool', '#.wheelDelta !== undefined', this)) { | 104 } else if (JS('bool', '#.wheelDelta !== undefined', this)) { |
| 85 // Chrome and IE | 105 // Chrome and IE |
| 86 return this._wheelDelta; | 106 return -this._wheelDelta; |
| 87 } else if (JS('bool', '#.detail !== undefined', this)) { | 107 } else if (JS('bool', '#.detail !== undefined', this)) { |
| 88 // Firefox | 108 // Firefox |
| 89 | 109 |
| 90 // Handle DOMMouseScroll case where it uses detail and the axis to | 110 // Handle DOMMouseScroll case where it uses detail and the axis to |
| 91 // differentiate. | 111 // differentiate. |
| 92 if (JS('bool', '#.axis == MouseScrollEvent.VERTICAL_AXIS', this)) { | 112 if (JS('bool', '#.axis == MouseScrollEvent.VERTICAL_AXIS', this)) { |
| 93 var detail = this._detail; | 113 var detail = this._detail; |
| 94 // Firefox is normally the number of lines to scale (normally 3) | 114 // Firefox is normally the number of lines to scale (normally 3) |
| 95 // so multiply it by 40 to get pixels to move, matching IE & WebKit. | 115 // so multiply it by 40 to get pixels to move, matching IE & WebKit. |
| 96 if (detail < 100) { | 116 if (detail.abs() < 100) { |
| 97 return detail * 40; | 117 return -detail * 40; |
| 98 } | 118 } |
| 99 return detail; | 119 return -detail; |
| 100 } | 120 } |
| 101 return 0; | 121 return 0; |
| 102 } | 122 } |
| 103 throw new UnsupportedError( | 123 throw new UnsupportedError( |
| 104 'deltaY is not supported'); | 124 'deltaY is not supported'); |
| 105 } | 125 } |
| 106 | 126 |
| 127 /** |
| 128 * The amount that is expected to scroll horizontally, in units determined by |
| 129 * [deltaMode]. |
| 130 * |
| 131 * See also: |
| 132 * |
| 133 * * [WheelEvent.deltaX](http://dev.w3.org/2006/webapi/DOM-Level-3-Events/html
/DOM3-Events.html#events-WheelEvent-deltaX) from the W3C. |
| 134 */ |
| 107 @DomName('WheelEvent.deltaX') | 135 @DomName('WheelEvent.deltaX') |
| 108 num get deltaX { | 136 num get deltaX { |
| 109 if (JS('bool', '#.deltaX !== undefined', this)) { | 137 if (JS('bool', '#.deltaX !== undefined', this)) { |
| 110 // W3C WheelEvent | 138 // W3C WheelEvent |
| 111 return this._deltaX; | 139 return this._deltaX; |
| 112 } else if (JS('bool', '#.wheelDeltaX !== undefined', this)) { | 140 } else if (JS('bool', '#.wheelDeltaX !== undefined', this)) { |
| 113 // Chrome | 141 // Chrome |
| 114 return this._wheelDeltaX; | 142 return -this._wheelDeltaX; |
| 115 } else if (JS('bool', '#.detail !== undefined', this)) { | 143 } else if (JS('bool', '#.detail !== undefined', this)) { |
| 116 // Firefox and IE. | 144 // Firefox and IE. |
| 117 // IE will have detail set but will not set axis. | 145 // IE will have detail set but will not set axis. |
| 118 | 146 |
| 119 // Handle DOMMouseScroll case where it uses detail and the axis to | 147 // Handle DOMMouseScroll case where it uses detail and the axis to |
| 120 // differentiate. | 148 // differentiate. |
| 121 if (JS('bool', '#.axis !== undefined && ' | 149 if (JS('bool', '#.axis !== undefined && ' |
| 122 '#.axis == MouseScrollEvent.HORIZONTAL_AXIS', this, this)) { | 150 '#.axis == MouseScrollEvent.HORIZONTAL_AXIS', this, this)) { |
| 123 var detail = this._detail; | 151 var detail = this._detail; |
| 124 // Firefox is normally the number of lines to scale (normally 3) | 152 // Firefox is normally the number of lines to scale (normally 3) |
| 125 // so multiply it by 40 to get pixels to move, matching IE & WebKit. | 153 // so multiply it by 40 to get pixels to move, matching IE & WebKit. |
| 126 if (detail < 100) { | 154 if (detail < 100) { |
| 127 return detail * 40; | 155 return -detail * 40; |
| 128 } | 156 } |
| 129 return detail; | 157 return -detail; |
| 130 } | 158 } |
| 131 return 0; | 159 return 0; |
| 132 } | 160 } |
| 133 throw new UnsupportedError( | 161 throw new UnsupportedError( |
| 134 'deltaX is not supported'); | 162 'deltaX is not supported'); |
| 135 } | 163 } |
| 136 | 164 |
| 137 @DomName('WheelEvent.deltaMode') | 165 @DomName('WheelEvent.deltaMode') |
| 138 int get deltaMode { | 166 int get deltaMode { |
| 139 if (JS('bool', '!!(#.deltaMode)', this)) { | 167 if (JS('bool', '!!(#.deltaMode)', this)) { |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 186 int clientY, | 214 int clientY, |
| 187 int button, | 215 int button, |
| 188 EventTarget relatedTarget, | 216 EventTarget relatedTarget, |
| 189 String modifiersList, | 217 String modifiersList, |
| 190 int deltaX, | 218 int deltaX, |
| 191 int deltaY, | 219 int deltaY, |
| 192 int deltaZ, | 220 int deltaZ, |
| 193 int deltaMode) native; | 221 int deltaMode) native; |
| 194 | 222 |
| 195 $else | 223 $else |
| 224 /** |
| 225 * The amount that is expected to scroll horizontally, in units determined by |
| 226 * [deltaMode]. |
| 227 * |
| 228 * See also: |
| 229 * |
| 230 * * [WheelEvent.deltaX](http://dev.w3.org/2006/webapi/DOM-Level-3-Events/html
/DOM3-Events.html#events-WheelEvent-deltaX) from the W3C. |
| 231 */ |
| 196 @DomName('WheelEvent.deltaX') | 232 @DomName('WheelEvent.deltaX') |
| 197 num get deltaX => $dom_wheelDeltaX; | 233 num get deltaX => -$dom_wheelDeltaX; |
| 234 |
| 235 /** |
| 236 * The amount that is expected to scroll vertically, in units determined by |
| 237 * [deltaMode]. |
| 238 * |
| 239 * See also: |
| 240 * |
| 241 * * [WheelEvent.deltaY](http://dev.w3.org/2006/webapi/DOM-Level-3-Events/html
/DOM3-Events.html#events-WheelEvent-deltaY) from the W3C. |
| 242 */ |
| 198 @DomName('WheelEvent.deltaY') | 243 @DomName('WheelEvent.deltaY') |
| 199 num get deltaY => $dom_wheelDeltaY; | 244 num get deltaY => -$dom_wheelDeltaY; |
| 200 $endif | 245 $endif |
| 201 } | 246 } |
| OLD | NEW |