| 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)$(NATIVESPEC)$(CLASS_MODIFIERS)class $CLASSNAME$EXTENDS$IMPLEMENTS
{ | 7 $(ANNOTATIONS)$(NATIVESPEC)$(CLASS_MODIFIERS)class $CLASSNAME$EXTENDS$IMPLEMENTS
{ |
| 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, int deltaZ: 0, |
| 11 int deltaMode: 0, |
| 11 int detail: 0, int screenX: 0, int screenY: 0, int clientX: 0, | 12 int detail: 0, int screenX: 0, int screenY: 0, int clientX: 0, |
| 12 int clientY: 0, int button: 0, bool canBubble: true, | 13 int clientY: 0, int button: 0, bool canBubble: true, |
| 13 bool cancelable: true, bool ctrlKey: false, bool altKey: false, | 14 bool cancelable: true, bool ctrlKey: false, bool altKey: false, |
| 14 bool shiftKey: false, bool metaKey: false, EventTarget relatedTarget}) { | 15 bool shiftKey: false, bool metaKey: false, EventTarget relatedTarget}) { |
| 15 $if DART2JS | |
| 16 if (view == null) { | |
| 17 view = window; | |
| 18 } | |
| 19 var eventType = 'WheelEvent'; | |
| 20 if (Device.isFirefox) { | |
| 21 eventType = 'MouseScrollEvents'; | |
| 22 } | |
| 23 final event = document._createEvent(eventType); | |
| 24 // If polyfilling, then flip these because we'll flip them back to match | |
| 25 // the W3C standard: | |
| 26 // http://dev.w3.org/2006/webapi/DOM-Level-3-Events/html/DOM3-Events.html#ev
ents-WheelEvent-deltaY | |
| 27 if (JS('bool', '#.deltaY === undefined', event)) { | |
| 28 deltaX = -deltaX; | |
| 29 deltaY = -deltaY; | |
| 30 } | |
| 31 if (event._hasInitWheelEvent) { | |
| 32 var modifiers = []; | |
| 33 if (ctrlKey) { | |
| 34 modifiers.push('Control'); | |
| 35 } | |
| 36 if (altKey) { | |
| 37 modifiers.push('Alt'); | |
| 38 } | |
| 39 if (shiftKey) { | |
| 40 modifiers.push('Shift'); | |
| 41 } | |
| 42 if (metaKey) { | |
| 43 modifiers.push('Meta'); | |
| 44 } | |
| 45 event._initWheelEvent(type, canBubble, cancelable, view, detail, screenX, | |
| 46 screenY, clientX, clientY, button, relatedTarget, modifiers.join(' '), | |
| 47 deltaX, deltaY, 0, 0); | |
| 48 } else if (event._hasInitMouseScrollEvent) { | |
| 49 var axis = 0; | |
| 50 var detail = 0; | |
| 51 if (deltaX != 0 && deltaY != 0) { | |
| 52 throw new UnsupportedError( | |
| 53 'Cannot modify deltaX and deltaY simultaneously'); | |
| 54 } | |
| 55 if (deltaY != 0) { | |
| 56 detail = deltaY; | |
| 57 axis = JS('int', 'MouseScrollEvent.VERTICAL_AXIS'); | |
| 58 } else if (deltaX != 0) { | |
| 59 detail = deltaX; | |
| 60 axis = JS('int', 'MouseScrollEvent.HORIZONTAL_AXIS'); | |
| 61 } | |
| 62 event._initMouseScrollEvent(type, canBubble, cancelable, view, detail, | |
| 63 screenX, screenY, clientX, clientY, ctrlKey, altKey, shiftKey, | |
| 64 metaKey, button, relatedTarget, axis); | |
| 65 } else { | |
| 66 // Chrome does an auto-convert to pixels. | |
| 67 deltaY = deltaY ~/ 120; | |
| 68 | 16 |
| 69 event._initMouseEvent(type, canBubble, cancelable, view, detail, | |
| 70 screenX, screenY, clientX, clientY, ctrlKey, altKey, shiftKey, | |
| 71 metaKey, button, relatedTarget); | |
| 72 JS('void', '#.initWebKitWheelEvent(#, #, #, #, #, #, #, #, #, #, #)', | |
| 73 event, deltaX, deltaY, | |
| 74 view, screenX, screenY, clientX, clientY, ctrlKey, altKey, shiftKey, | |
| 75 metaKey); | |
| 76 } | |
| 77 | |
| 78 return event; | |
| 79 $else | |
| 80 var options = { | 17 var options = { |
| 81 'view': view, | 18 'view': view, |
| 19 'deltaMode': deltaMode, |
| 82 'deltaX': deltaX, | 20 'deltaX': deltaX, |
| 83 'deltaY': deltaY, | 21 'deltaY': deltaY, |
| 22 'deltaZ': deltaZ, |
| 84 'detail': detail, | 23 'detail': detail, |
| 85 'screenX': screenX, | 24 'screenX': screenX, |
| 86 'screenY': screenY, | 25 'screenY': screenY, |
| 87 'clientX': clientX, | 26 'clientX': clientX, |
| 88 'clientY': clientY, | 27 'clientY': clientY, |
| 89 'button': button, | 28 'button': button, |
| 90 'bubbles': canBubble, | 29 'bubbles': canBubble, |
| 91 'cancelable': cancelable, | 30 'cancelable': cancelable, |
| 92 'ctrlKey': ctrlKey, | 31 'ctrlKey': ctrlKey, |
| 93 'altKey': altKey, | 32 'altKey': altKey, |
| 94 'shiftKey': shiftKey, | 33 'shiftKey': shiftKey, |
| 95 'metaKey': metaKey, | 34 'metaKey': metaKey, |
| 96 'relatedTarget': relatedTarget, | 35 'relatedTarget': relatedTarget, |
| 97 }; | 36 }; |
| 37 |
| 38 $if DART2JS |
| 39 if (view == null) { |
| 40 view = window; |
| 41 } |
| 42 |
| 43 return JS('WheelEvent', 'new WheelEvent(#, #)', |
| 44 type, convertDartToNative_Dictionary(options)); |
| 45 |
| 46 $else |
| 98 return _blink.BlinkWheelEvent.constructorCallback_2(type, options); | 47 return _blink.BlinkWheelEvent.constructorCallback_2(type, options); |
| 99 $endif | 48 $endif |
| 100 } | 49 } |
| 101 | 50 |
| 102 $!MEMBERS | 51 $!MEMBERS |
| 103 | 52 |
| 104 $if DART2JS | 53 $if DART2JS |
| 105 /** | 54 /** |
| 106 * The amount that is expected to scroll vertically, in units determined by | 55 * The amount that is expected to scroll vertically, in units determined by |
| 107 * [deltaMode]. | 56 * [deltaMode]. |
| 108 * | 57 * |
| 109 * See also: | 58 * See also: |
| 110 * | 59 * |
| 111 * * [WheelEvent.deltaY](http://dev.w3.org/2006/webapi/DOM-Level-3-Events/html
/DOM3-Events.html#events-WheelEvent-deltaY) from the W3C. | 60 * * [WheelEvent.deltaY](http://dev.w3.org/2006/webapi/DOM-Level-3-Events/html
/DOM3-Events.html#events-WheelEvent-deltaY) from the W3C. |
| 112 */ | 61 */ |
| 113 @DomName('WheelEvent.deltaY') | 62 @DomName('WheelEvent.deltaY') |
| 114 num get deltaY { | 63 num get deltaY { |
| 115 if (JS('bool', '#.deltaY !== undefined', this)) { | 64 if (JS('bool', '#.deltaY !== undefined', this)) { |
| 116 // W3C WheelEvent | 65 // W3C WheelEvent |
| 117 return this._deltaY; | 66 return this._deltaY; |
| 118 } else if (JS('bool', '#.wheelDelta !== undefined', this)) { | |
| 119 // Chrome and IE | |
| 120 return -this._wheelDelta; | |
| 121 } else if (JS('bool', '#.detail !== undefined', this)) { | |
| 122 // Firefox | |
| 123 | |
| 124 // Handle DOMMouseScroll case where it uses detail and the axis to | |
| 125 // differentiate. | |
| 126 if (JS('bool', '#.axis == MouseScrollEvent.VERTICAL_AXIS', this)) { | |
| 127 var detail = this._detail; | |
| 128 // Firefox is normally the number of lines to scale (normally 3) | |
| 129 // so multiply it by 40 to get pixels to move, matching IE & WebKit. | |
| 130 if (detail.abs() < 100) { | |
| 131 return -detail * 40; | |
| 132 } | |
| 133 return -detail; | |
| 134 } | |
| 135 return 0; | |
| 136 } | 67 } |
| 137 throw new UnsupportedError( | 68 throw new UnsupportedError( |
| 138 'deltaY is not supported'); | 69 'deltaY is not supported'); |
| 139 } | 70 } |
| 140 | 71 |
| 141 /** | 72 /** |
| 142 * The amount that is expected to scroll horizontally, in units determined by | 73 * The amount that is expected to scroll horizontally, in units determined by |
| 143 * [deltaMode]. | 74 * [deltaMode]. |
| 144 * | 75 * |
| 145 * See also: | 76 * See also: |
| 146 * | 77 * |
| 147 * * [WheelEvent.deltaX](http://dev.w3.org/2006/webapi/DOM-Level-3-Events/html
/DOM3-Events.html#events-WheelEvent-deltaX) from the W3C. | 78 * * [WheelEvent.deltaX](http://dev.w3.org/2006/webapi/DOM-Level-3-Events/html
/DOM3-Events.html#events-WheelEvent-deltaX) from the W3C. |
| 148 */ | 79 */ |
| 149 @DomName('WheelEvent.deltaX') | 80 @DomName('WheelEvent.deltaX') |
| 150 num get deltaX { | 81 num get deltaX { |
| 151 if (JS('bool', '#.deltaX !== undefined', this)) { | 82 if (JS('bool', '#.deltaX !== undefined', this)) { |
| 152 // W3C WheelEvent | 83 // W3C WheelEvent |
| 153 return this._deltaX; | 84 return this._deltaX; |
| 154 } else if (JS('bool', '#.wheelDeltaX !== undefined', this)) { | |
| 155 // Chrome | |
| 156 return -this._wheelDeltaX; | |
| 157 } else if (JS('bool', '#.detail !== undefined', this)) { | |
| 158 // Firefox and IE. | |
| 159 // IE will have detail set but will not set axis. | |
| 160 | |
| 161 // Handle DOMMouseScroll case where it uses detail and the axis to | |
| 162 // differentiate. | |
| 163 if (JS('bool', '#.axis !== undefined && ' | |
| 164 '#.axis == MouseScrollEvent.HORIZONTAL_AXIS', this, this)) { | |
| 165 var detail = this._detail; | |
| 166 // Firefox is normally the number of lines to scale (normally 3) | |
| 167 // so multiply it by 40 to get pixels to move, matching IE & WebKit. | |
| 168 if (detail < 100) { | |
| 169 return -detail * 40; | |
| 170 } | |
| 171 return -detail; | |
| 172 } | |
| 173 return 0; | |
| 174 } | 85 } |
| 175 throw new UnsupportedError( | 86 throw new UnsupportedError( |
| 176 'deltaX is not supported'); | 87 'deltaX is not supported'); |
| 177 } | 88 } |
| 178 | 89 |
| 179 @DomName('WheelEvent.deltaMode') | 90 @DomName('WheelEvent.deltaMode') |
| 180 int get deltaMode { | 91 int get deltaMode { |
| 181 if (JS('bool', '!!(#.deltaMode)', this)) { | 92 if (JS('bool', '!!(#.deltaMode)', this)) { |
| 182 return JS('int', '#.deltaMode', this); | 93 return JS('int', '#.deltaMode', this); |
| 183 } | 94 } |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 249 * [deltaMode]. | 160 * [deltaMode]. |
| 250 * | 161 * |
| 251 * See also: | 162 * See also: |
| 252 * | 163 * |
| 253 * * [WheelEvent.deltaY](http://dev.w3.org/2006/webapi/DOM-Level-3-Events/html
/DOM3-Events.html#events-WheelEvent-deltaY) from the W3C. | 164 * * [WheelEvent.deltaY](http://dev.w3.org/2006/webapi/DOM-Level-3-Events/html
/DOM3-Events.html#events-WheelEvent-deltaY) from the W3C. |
| 254 */ | 165 */ |
| 255 @DomName('WheelEvent.deltaY') | 166 @DomName('WheelEvent.deltaY') |
| 256 num get deltaY => _deltaY; | 167 num get deltaY => _deltaY; |
| 257 $endif | 168 $endif |
| 258 } | 169 } |
| OLD | NEW |