Chromium Code Reviews| 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 |
|
Andrei Mouravski
2013/04/03 00:10:31
Could you add some minimal dartdoc documentation?
blois
2013/04/03 00:35:34
Added some comments to the deltaX/deltaY members.
| |
| 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 to match W3C wheel spec. | |
|
Emily Fortuna
2013/04/02 23:59:09
Can you link to the w3c spec or (better) say which
blois
2013/04/03 00:35:34
Added link to the spec, but it doesn't actually sp
| |
| 26 if (JS('bool', '#.deltaY === undefined', event)) { | |
| 27 deltaX = -deltaX; | |
| 28 deltaY = -deltaY; | |
| 29 } | |
| 25 if (event._hasInitWheelEvent) { | 30 if (event._hasInitWheelEvent) { |
| 26 var modifiers = []; | 31 var modifiers = []; |
| 27 if (ctrlKey) { | 32 if (ctrlKey) { |
| 28 modifiers.push('Control'); | 33 modifiers.push('Control'); |
| 29 } | 34 } |
| 30 if (altKey) { | 35 if (altKey) { |
| 31 modifiers.push('Alt'); | 36 modifiers.push('Alt'); |
| 32 } | 37 } |
| 33 if (shiftKey) { | 38 if (shiftKey) { |
| 34 modifiers.push('Shift'); | 39 modifiers.push('Shift'); |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 76 $!MEMBERS | 81 $!MEMBERS |
| 77 | 82 |
| 78 $if DART2JS | 83 $if DART2JS |
| 79 @DomName('WheelEvent.deltaY') | 84 @DomName('WheelEvent.deltaY') |
| 80 num get deltaY { | 85 num get deltaY { |
| 81 if (JS('bool', '#.deltaY !== undefined', this)) { | 86 if (JS('bool', '#.deltaY !== undefined', this)) { |
| 82 // W3C WheelEvent | 87 // W3C WheelEvent |
| 83 return this._deltaY; | 88 return this._deltaY; |
| 84 } else if (JS('bool', '#.wheelDelta !== undefined', this)) { | 89 } else if (JS('bool', '#.wheelDelta !== undefined', this)) { |
| 85 // Chrome and IE | 90 // Chrome and IE |
| 86 return this._wheelDelta; | 91 return -this._wheelDelta; |
| 87 } else if (JS('bool', '#.detail !== undefined', this)) { | 92 } else if (JS('bool', '#.detail !== undefined', this)) { |
| 88 // Firefox | 93 // Firefox |
| 89 | 94 |
| 90 // Handle DOMMouseScroll case where it uses detail and the axis to | 95 // Handle DOMMouseScroll case where it uses detail and the axis to |
| 91 // differentiate. | 96 // differentiate. |
| 92 if (JS('bool', '#.axis == MouseScrollEvent.VERTICAL_AXIS', this)) { | 97 if (JS('bool', '#.axis == MouseScrollEvent.VERTICAL_AXIS', this)) { |
| 93 var detail = this._detail; | 98 var detail = this._detail; |
| 94 // Firefox is normally the number of lines to scale (normally 3) | 99 // 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. | 100 // so multiply it by 40 to get pixels to move, matching IE & WebKit. |
| 96 if (detail < 100) { | 101 if (detail < 100) { |
| 97 return detail * 40; | 102 return -detail * 40; |
| 98 } | 103 } |
| 99 return detail; | 104 return -detail; |
| 100 } | 105 } |
| 101 return 0; | 106 return 0; |
| 102 } | 107 } |
| 103 throw new UnsupportedError( | 108 throw new UnsupportedError( |
| 104 'deltaY is not supported'); | 109 'deltaY is not supported'); |
| 105 } | 110 } |
| 106 | 111 |
| 107 @DomName('WheelEvent.deltaX') | 112 @DomName('WheelEvent.deltaX') |
| 108 num get deltaX { | 113 num get deltaX { |
| 109 if (JS('bool', '#.deltaX !== undefined', this)) { | 114 if (JS('bool', '#.deltaX !== undefined', this)) { |
| 110 // W3C WheelEvent | 115 // W3C WheelEvent |
| 111 return this._deltaX; | 116 return this._deltaX; |
| 112 } else if (JS('bool', '#.wheelDeltaX !== undefined', this)) { | 117 } else if (JS('bool', '#.wheelDeltaX !== undefined', this)) { |
| 113 // Chrome | 118 // Chrome |
| 114 return this._wheelDeltaX; | 119 return -this._wheelDeltaX; |
| 115 } else if (JS('bool', '#.detail !== undefined', this)) { | 120 } else if (JS('bool', '#.detail !== undefined', this)) { |
| 116 // Firefox and IE. | 121 // Firefox and IE. |
| 117 // IE will have detail set but will not set axis. | 122 // IE will have detail set but will not set axis. |
| 118 | 123 |
| 119 // Handle DOMMouseScroll case where it uses detail and the axis to | 124 // Handle DOMMouseScroll case where it uses detail and the axis to |
| 120 // differentiate. | 125 // differentiate. |
| 121 if (JS('bool', '#.axis !== undefined && ' | 126 if (JS('bool', '#.axis !== undefined && ' |
| 122 '#.axis == MouseScrollEvent.HORIZONTAL_AXIS', this, this)) { | 127 '#.axis == MouseScrollEvent.HORIZONTAL_AXIS', this, this)) { |
| 123 var detail = this._detail; | 128 var detail = this._detail; |
| 124 // Firefox is normally the number of lines to scale (normally 3) | 129 // 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. | 130 // so multiply it by 40 to get pixels to move, matching IE & WebKit. |
| 126 if (detail < 100) { | 131 if (detail < 100) { |
| 127 return detail * 40; | 132 return -detail * 40; |
| 128 } | 133 } |
| 129 return detail; | 134 return -detail; |
| 130 } | 135 } |
| 131 return 0; | 136 return 0; |
| 132 } | 137 } |
| 133 throw new UnsupportedError( | 138 throw new UnsupportedError( |
| 134 'deltaX is not supported'); | 139 'deltaX is not supported'); |
| 135 } | 140 } |
| 136 | 141 |
| 137 @DomName('WheelEvent.deltaMode') | 142 @DomName('WheelEvent.deltaMode') |
| 138 int get deltaMode { | 143 int get deltaMode { |
| 139 if (JS('bool', '!!(#.deltaMode)', this)) { | 144 if (JS('bool', '!!(#.deltaMode)', this)) { |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 187 int button, | 192 int button, |
| 188 EventTarget relatedTarget, | 193 EventTarget relatedTarget, |
| 189 String modifiersList, | 194 String modifiersList, |
| 190 int deltaX, | 195 int deltaX, |
| 191 int deltaY, | 196 int deltaY, |
| 192 int deltaZ, | 197 int deltaZ, |
| 193 int deltaMode) native; | 198 int deltaMode) native; |
| 194 | 199 |
| 195 $else | 200 $else |
| 196 @DomName('WheelEvent.deltaX') | 201 @DomName('WheelEvent.deltaX') |
| 197 num get deltaX => $dom_wheelDeltaX; | 202 num get deltaX => -$dom_wheelDeltaX; |
| 198 @DomName('WheelEvent.deltaY') | 203 @DomName('WheelEvent.deltaY') |
| 199 num get deltaY => $dom_wheelDeltaY; | 204 num get deltaY => -$dom_wheelDeltaY; |
| 200 $endif | 205 $endif |
| 201 } | 206 } |
| OLD | NEW |