Left: | ||
Right: |
LEFT | RIGHT |
---|---|
1 // Copyright 2005 The Closure Library Authors. All Rights Reserved. | 1 // Copyright 2005 The Closure Library Authors. All Rights Reserved. |
2 // | 2 // |
3 // Licensed under the Apache License, Version 2.0 (the "License"); | 3 // Licensed under the Apache License, Version 2.0 (the "License"); |
4 // you may not use this file except in compliance with the License. | 4 // you may not use this file except in compliance with the License. |
5 // You may obtain a copy of the License at | 5 // You may obtain a copy of the License at |
6 // | 6 // |
7 // http://www.apache.org/licenses/LICENSE-2.0 | 7 // http://www.apache.org/licenses/LICENSE-2.0 |
8 // | 8 // |
9 // Unless required by applicable law or agreed to in writing, software | 9 // Unless required by applicable law or agreed to in writing, software |
10 // distributed under the License is distributed on an "AS-IS" BASIS, | 10 // distributed under the License is distributed on an "AS-IS" BASIS, |
(...skipping 16 matching lines...) Expand all Loading... | |
27 * - clientX {number} X-coordinate relative to viewport | 27 * - clientX {number} X-coordinate relative to viewport |
28 * - clientY {number} Y-coordinate relative to viewport | 28 * - clientY {number} Y-coordinate relative to viewport |
29 * - screenX {number} X-coordinate relative to the edge of the screen | 29 * - screenX {number} X-coordinate relative to the edge of the screen |
30 * - screenY {number} Y-coordinate relative to the edge of the screen | 30 * - screenY {number} Y-coordinate relative to the edge of the screen |
31 * - button {number} Mouse button. Use isButton() to test. | 31 * - button {number} Mouse button. Use isButton() to test. |
32 * - keyCode {number} Key-code | 32 * - keyCode {number} Key-code |
33 * - ctrlKey {boolean} Was ctrl key depressed | 33 * - ctrlKey {boolean} Was ctrl key depressed |
34 * - altKey {boolean} Was alt key depressed | 34 * - altKey {boolean} Was alt key depressed |
35 * - shiftKey {boolean} Was shift key depressed | 35 * - shiftKey {boolean} Was shift key depressed |
36 * - metaKey {boolean} Was meta key depressed | 36 * - metaKey {boolean} Was meta key depressed |
37 * - defaultPrevented {boolean} Whether the default action has been prevented | |
37 * - state {Object} History state object | 38 * - state {Object} History state object |
38 * | 39 * |
39 * NOTE: The keyCode member contains the raw browser keyCode. For normalized | 40 * NOTE: The keyCode member contains the raw browser keyCode. For normalized |
40 * key and character code use {@link goog.events.KeyHandler}. | 41 * key and character code use {@link goog.events.KeyHandler}. |
41 * </pre> | 42 * </pre> |
42 * | 43 * |
43 */ | 44 */ |
44 | 45 |
45 goog.provide('goog.events.BrowserEvent'); | 46 goog.provide('goog.events.BrowserEvent'); |
46 goog.provide('goog.events.BrowserEvent.MouseButton'); | 47 goog.provide('goog.events.BrowserEvent.MouseButton'); |
(...skipping 188 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
235 * Accepts a browser event object and creates a patched, cross browser event | 236 * Accepts a browser event object and creates a patched, cross browser event |
236 * object. | 237 * object. |
237 * @param {Event} e Browser event object. | 238 * @param {Event} e Browser event object. |
238 * @param {Node=} opt_currentTarget Current target for event. | 239 * @param {Node=} opt_currentTarget Current target for event. |
239 */ | 240 */ |
240 goog.events.BrowserEvent.prototype.init = function(e, opt_currentTarget) { | 241 goog.events.BrowserEvent.prototype.init = function(e, opt_currentTarget) { |
241 var type = this.type = e.type; | 242 var type = this.type = e.type; |
242 goog.events.Event.call(this, type); | 243 goog.events.Event.call(this, type); |
243 | 244 |
244 /** @type {Touch} */ | 245 /** @type {Touch} */ |
245 var relevantTouch; | 246 var relevantTouch; |
nnaze
2012/02/06 23:54:48
var touch;
Andrew Mattie
2012/02/07 06:50:18
Done.
| |
246 | 247 |
247 if (type == goog.events.EventType.TOUCHSTART || | 248 if (type == goog.events.EventType.TOUCHSTART || |
248 type == goog.events.EventType.TOUCHMOVE) { | 249 type == goog.events.EventType.TOUCHMOVE) { |
249 relevantTouch = e.targetTouches[0]; | 250 relevantTouch = e.targetTouches[0]; |
250 } else if (type == goog.events.EventType.TOUCHEND || | 251 } else if (type == goog.events.EventType.TOUCHEND || |
251 type == goog.events.EventType.TOUCHCANCEL) { | 252 type == goog.events.EventType.TOUCHCANCEL) { |
252 relevantTouch = e.changedTouches[0]; | 253 relevantTouch = e.changedTouches[0]; |
253 } | 254 } |
254 | 255 |
255 // TODO(nicksantos): Change this.target to type EventTarget. | 256 // TODO(nicksantos): Change this.target to type EventTarget. |
256 if (!!relevantTouch) | 257 if (!!relevantTouch) |
nnaze
2012/02/06 23:54:48
drop "!!"
nnaze
2012/02/06 23:54:48
It doesn't seem there needs to be two if(touch) bl
Andrew Mattie
2012/02/07 06:50:18
Done.
Andrew Mattie
2012/02/07 06:50:18
Done.
| |
257 this.target = relevantTouch.target; | 258 this.target = relevantTouch.target; |
258 else | 259 else |
259 this.target = /** @type {Node} */ (e.target) || e.srcElement; | 260 this.target = /** @type {Node} */ (e.target) || e.srcElement; |
nnaze
2012/02/06 23:54:48
per style guide, braces required always, even on o
Andrew Mattie
2012/02/07 06:50:18
Done. FYI, Closure Linter didn't warn me even w/ -
| |
260 | 261 |
261 this.currentTarget = opt_currentTarget; | 262 this.currentTarget = opt_currentTarget; |
262 | 263 |
263 var relatedTarget = /** @type {Node} */ (e.relatedTarget); | 264 var relatedTarget = /** @type {Node} */ (e.relatedTarget); |
264 if (relatedTarget) { | 265 if (relatedTarget) { |
265 // There's a bug in FireFox where sometimes, relatedTarget will be a | 266 // There's a bug in FireFox where sometimes, relatedTarget will be a |
266 // chrome element, and accessing any property of it will get a permission | 267 // chrome element, and accessing any property of it will get a permission |
267 // denied exception. See: | 268 // denied exception. See: |
268 // https://bugzilla.mozilla.org/show_bug.cgi?id=497780 | 269 // https://bugzilla.mozilla.org/show_bug.cgi?id=497780 |
269 if (goog.userAgent.GECKO) { | 270 if (goog.userAgent.GECKO) { |
270 if (!goog.reflect.canAccessProperty(relatedTarget, 'nodeName')) { | 271 if (!goog.reflect.canAccessProperty(relatedTarget, 'nodeName')) { |
271 relatedTarget = null; | 272 relatedTarget = null; |
272 } | 273 } |
273 } | 274 } |
274 // TODO(arv): Use goog.events.EventType when it has been refactored into its | 275 // TODO(arv): Use goog.events.EventType when it has been refactored into its |
275 // own file. | 276 // own file. |
276 } else if (type == goog.events.EventType.MOUSEOVER) { | 277 } else if (type == goog.events.EventType.MOUSEOVER) { |
277 relatedTarget = e.fromElement; | 278 relatedTarget = e.fromElement; |
278 } else if (type == goog.events.EventType.MOUSEOUT) { | 279 } else if (type == goog.events.EventType.MOUSEOUT) { |
279 relatedTarget = e.toElement; | 280 relatedTarget = e.toElement; |
280 } | 281 } |
281 | 282 |
282 this.relatedTarget = relatedTarget; | 283 this.relatedTarget = relatedTarget; |
283 | 284 |
284 if (!!relevantTouch) { | 285 if (!!relevantTouch) { |
nnaze
2012/02/06 23:54:48
please drop "!!"
Andrew Mattie
2012/02/07 06:50:18
Done.
| |
285 this.clientX = relevantTouch.clientX; | 286 this.clientX = relevantTouch.clientX; |
286 this.clientY = relevantTouch.clientY; | 287 this.clientY = relevantTouch.clientY; |
287 this.screenX = relevantTouch.screenX; | 288 this.screenX = relevantTouch.screenX; |
288 this.screenY = relevantTouch.screenY; | 289 this.screenY = relevantTouch.screenY; |
289 } else { | 290 } else { |
290 // Webkit emits a lame warning whenever layerX/layerY is accessed. | 291 // Webkit emits a lame warning whenever layerX/layerY is accessed. |
291 // http://code.google.com/p/chromium/issues/detail?id=101733 | 292 // http://code.google.com/p/chromium/issues/detail?id=101733 |
292 this.offsetX = (goog.userAgent.WEBKIT || e.offsetX !== undefined) ? | 293 this.offsetX = (goog.userAgent.WEBKIT || e.offsetX !== undefined) ? |
293 e.offsetX : e.layerX; | 294 e.offsetX : e.layerX; |
294 this.offsetY = (goog.userAgent.WEBKIT || e.offsetY !== undefined) ? | 295 this.offsetY = (goog.userAgent.WEBKIT || e.offsetY !== undefined) ? |
295 e.offsetY : e.layerY; | 296 e.offsetY : e.layerY; |
296 | 297 |
297 this.clientX = e.clientX !== undefined ? e.clientX : e.pageX; | 298 this.clientX = e.clientX !== undefined ? e.clientX : e.pageX; |
298 this.clientY = e.clientY !== undefined ? e.clientY : e.pageY; | 299 this.clientY = e.clientY !== undefined ? e.clientY : e.pageY; |
299 this.screenX = e.screenX || 0; | 300 this.screenX = e.screenX || 0; |
300 this.screenY = e.screenY || 0; | 301 this.screenY = e.screenY || 0; |
301 } | 302 } |
302 | 303 |
303 this.button = e.button; | 304 this.button = e.button; |
304 | 305 |
305 this.keyCode = e.keyCode || 0; | 306 this.keyCode = e.keyCode || 0; |
306 this.charCode = e.charCode || (type == 'keypress' ? e.keyCode : 0); | 307 this.charCode = e.charCode || (type == 'keypress' ? e.keyCode : 0); |
307 this.ctrlKey = e.ctrlKey; | 308 this.ctrlKey = e.ctrlKey; |
308 this.altKey = e.altKey; | 309 this.altKey = e.altKey; |
309 this.shiftKey = e.shiftKey; | 310 this.shiftKey = e.shiftKey; |
310 this.metaKey = e.metaKey; | 311 this.metaKey = e.metaKey; |
311 this.platformModifierKey = goog.userAgent.MAC ? e.metaKey : e.ctrlKey; | 312 this.platformModifierKey = goog.userAgent.MAC ? e.metaKey : e.ctrlKey; |
312 this.state = e.state; | 313 this.state = e.state; |
313 this.event_ = e; | 314 this.event_ = e; |
314 delete this.returnValue_; | 315 if (e.defaultPrevented) { |
316 this.preventDefault(); | |
317 } | |
315 delete this.propagationStopped_; | 318 delete this.propagationStopped_; |
316 }; | 319 }; |
317 | 320 |
318 | 321 |
319 /** | 322 /** |
320 * Tests to see which button was pressed during the event. This is really only | 323 * Tests to see which button was pressed during the event. This is really only |
321 * useful in IE and Gecko browsers. And in IE, it's only useful for | 324 * useful in IE and Gecko browsers. And in IE, it's only useful for |
322 * mousedown/mouseup events, because click only fires for the left mouse button. | 325 * mousedown/mouseup events, because click only fires for the left mouse button. |
323 * | 326 * |
324 * Safari 2 only reports the left button being clicked, and uses the value '1' | 327 * Safari 2 only reports the left button being clicked, and uses the value '1' |
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
418 /** | 421 /** |
419 * @return {Event} The underlying browser event object. | 422 * @return {Event} The underlying browser event object. |
420 */ | 423 */ |
421 goog.events.BrowserEvent.prototype.getBrowserEvent = function() { | 424 goog.events.BrowserEvent.prototype.getBrowserEvent = function() { |
422 return this.event_; | 425 return this.event_; |
423 }; | 426 }; |
424 | 427 |
425 | 428 |
426 /** @override */ | 429 /** @override */ |
427 goog.events.BrowserEvent.prototype.disposeInternal = function() { | 430 goog.events.BrowserEvent.prototype.disposeInternal = function() { |
428 goog.events.BrowserEvent.superClass_.disposeInternal.call(this); | 431 }; |
429 this.event_ = null; | |
430 this.target = null; | |
431 this.currentTarget = null; | |
432 this.relatedTarget = null; | |
433 }; | |
LEFT | RIGHT |