OLD | NEW |
1 // Copyright 2006 The Closure Library Authors. All Rights Reserved. | 1 // Copyright 2006 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 390 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
401 goog.fx.Dragger.prototype.startDrag = function(e) { | 401 goog.fx.Dragger.prototype.startDrag = function(e) { |
402 var isMouseDown = e.type == goog.events.EventType.MOUSEDOWN; | 402 var isMouseDown = e.type == goog.events.EventType.MOUSEDOWN; |
403 | 403 |
404 // Dragger.startDrag() can be called by AbstractDragDrop with a mousemove | 404 // Dragger.startDrag() can be called by AbstractDragDrop with a mousemove |
405 // event and IE does not report pressed mouse buttons on mousemove. Also, | 405 // event and IE does not report pressed mouse buttons on mousemove. Also, |
406 // it does not make sense to check for the button if the user is already | 406 // it does not make sense to check for the button if the user is already |
407 // dragging. | 407 // dragging. |
408 | 408 |
409 if (this.enabled_ && !this.dragging_ && | 409 if (this.enabled_ && !this.dragging_ && |
410 (!isMouseDown || e.isMouseActionButton())) { | 410 (!isMouseDown || e.isMouseActionButton())) { |
411 this.maybeReinitTouchEvent_(e); | |
412 if (this.hysteresisDistanceSquared_ == 0) { | 411 if (this.hysteresisDistanceSquared_ == 0) { |
413 if (this.fireDragStart_(e)) { | 412 if (this.fireDragStart_(e)) { |
414 this.dragging_ = true; | 413 this.dragging_ = true; |
415 e.preventDefault(); | 414 e.preventDefault(); |
416 } else { | 415 } else { |
417 // If the start drag is cancelled, don't setup for a drag. | 416 // If the start drag is cancelled, don't setup for a drag. |
418 return; | 417 return; |
419 } | 418 } |
420 } else { | 419 } else { |
421 // Need to preventDefault for hysteresis to prevent page getting selected. | 420 // Need to preventDefault for hysteresis to prevent page getting selected. |
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
512 | 511 |
513 /** | 512 /** |
514 * Event handler that is used to end the drag. | 513 * Event handler that is used to end the drag. |
515 * @param {goog.events.BrowserEvent} e Event object. | 514 * @param {goog.events.BrowserEvent} e Event object. |
516 * @param {boolean=} opt_dragCanceled Whether the drag has been canceled. | 515 * @param {boolean=} opt_dragCanceled Whether the drag has been canceled. |
517 */ | 516 */ |
518 goog.fx.Dragger.prototype.endDrag = function(e, opt_dragCanceled) { | 517 goog.fx.Dragger.prototype.endDrag = function(e, opt_dragCanceled) { |
519 this.cleanUpAfterDragging_(); | 518 this.cleanUpAfterDragging_(); |
520 | 519 |
521 if (this.dragging_) { | 520 if (this.dragging_) { |
522 this.maybeReinitTouchEvent_(e); | |
523 this.dragging_ = false; | 521 this.dragging_ = false; |
524 | 522 |
525 var x = this.limitX(this.deltaX); | 523 var x = this.limitX(this.deltaX); |
526 var y = this.limitY(this.deltaY); | 524 var y = this.limitY(this.deltaY); |
527 var dragCanceled = opt_dragCanceled || | 525 var dragCanceled = opt_dragCanceled || |
528 e.type == goog.events.EventType.TOUCHCANCEL; | 526 e.type == goog.events.EventType.TOUCHCANCEL; |
529 this.dispatchEvent(new goog.fx.DragEvent( | 527 this.dispatchEvent(new goog.fx.DragEvent( |
530 goog.fx.Dragger.EventType.END, this, e.clientX, e.clientY, e, x, y, | 528 goog.fx.Dragger.EventType.END, this, e.clientX, e.clientY, e, x, y, |
531 dragCanceled)); | 529 dragCanceled)); |
532 } else { | 530 } else { |
(...skipping 12 matching lines...) Expand all Loading... |
545 /** | 543 /** |
546 * Event handler that is used to end the drag by cancelling it. | 544 * Event handler that is used to end the drag by cancelling it. |
547 * @param {goog.events.BrowserEvent} e Event object. | 545 * @param {goog.events.BrowserEvent} e Event object. |
548 */ | 546 */ |
549 goog.fx.Dragger.prototype.endDragCancel = function(e) { | 547 goog.fx.Dragger.prototype.endDragCancel = function(e) { |
550 this.endDrag(e, true); | 548 this.endDrag(e, true); |
551 }; | 549 }; |
552 | 550 |
553 | 551 |
554 /** | 552 /** |
555 * Re-initializes the event with the first target touch event or, in the case | |
556 * of a stop event, the last changed touch. | |
557 * @param {goog.events.BrowserEvent} e A TOUCH... event. | |
558 * @private | |
559 */ | |
560 goog.fx.Dragger.prototype.maybeReinitTouchEvent_ = function(e) { | |
561 var type = e.type; | |
562 | |
563 if (type == goog.events.EventType.TOUCHSTART || | |
564 type == goog.events.EventType.TOUCHMOVE) { | |
565 e.init(e.getBrowserEvent().targetTouches[0], e.currentTarget); | |
566 } else if (type == goog.events.EventType.TOUCHEND || | |
567 type == goog.events.EventType.TOUCHCANCEL) { | |
568 e.init(e.getBrowserEvent().changedTouches[0], e.currentTarget); | |
569 } | |
570 }; | |
571 | |
572 | |
573 /** | |
574 * Event handler that is used on mouse / touch move to update the drag | 553 * Event handler that is used on mouse / touch move to update the drag |
575 * @param {goog.events.BrowserEvent} e Event object. | 554 * @param {goog.events.BrowserEvent} e Event object. |
576 * @private | 555 * @private |
577 */ | 556 */ |
578 goog.fx.Dragger.prototype.handleMove_ = function(e) { | 557 goog.fx.Dragger.prototype.handleMove_ = function(e) { |
579 if (this.enabled_) { | 558 if (this.enabled_) { |
580 this.maybeReinitTouchEvent_(e); | |
581 // dx in right-to-left cases is relative to the right. | 559 // dx in right-to-left cases is relative to the right. |
582 var sign = this.useRightPositioningForRtl_ && | 560 var sign = this.useRightPositioningForRtl_ && |
583 this.isRightToLeft_() ? -1 : 1; | 561 this.isRightToLeft_() ? -1 : 1; |
584 var dx = sign * (e.clientX - this.clientX); | 562 var dx = sign * (e.clientX - this.clientX); |
585 var dy = e.clientY - this.clientY; | 563 var dy = e.clientY - this.clientY; |
586 this.clientX = e.clientX; | 564 this.clientX = e.clientX; |
587 this.clientY = e.clientY; | 565 this.clientY = e.clientY; |
588 this.screenX = e.screenX; | 566 this.screenX = e.screenX; |
589 this.screenY = e.screenY; | 567 this.screenY = e.screenY; |
590 | 568 |
(...skipping 211 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
802 * event on FireFox when user drags the mouse out of the window, 2) with | 780 * event on FireFox when user drags the mouse out of the window, 2) with |
803 * drag END event on IE7 which is generated on MOUSEMOVE event when user | 781 * drag END event on IE7 which is generated on MOUSEMOVE event when user |
804 * moves the mouse into the document after the mouse button has been | 782 * moves the mouse into the document after the mouse button has been |
805 * released, 3) when TOUCHCANCEL is raised instead of TOUCHEND (on touch | 783 * released, 3) when TOUCHCANCEL is raised instead of TOUCHEND (on touch |
806 * events). | 784 * events). |
807 * @type {boolean} | 785 * @type {boolean} |
808 */ | 786 */ |
809 this.dragCanceled = !!opt_dragCanceled; | 787 this.dragCanceled = !!opt_dragCanceled; |
810 }; | 788 }; |
811 goog.inherits(goog.fx.DragEvent, goog.events.Event); | 789 goog.inherits(goog.fx.DragEvent, goog.events.Event); |
OLD | NEW |