Chromium Code Reviews| Index: chrome/browser/resources/pdf/gesture_detector.js |
| diff --git a/chrome/browser/resources/pdf/gesture_detector.js b/chrome/browser/resources/pdf/gesture_detector.js |
| index 091707649d2072235ef1aae33be0f23886b12f09..d19dd7048c1e540c5f438b8dc88aff66c351394b 100644 |
| --- a/chrome/browser/resources/pdf/gesture_detector.js |
| +++ b/chrome/browser/resources/pdf/gesture_detector.js |
| @@ -14,21 +14,34 @@ class GestureDetector { |
| * @param {!Element} element The element to monitor for touch gestures. |
| */ |
| constructor(element) { |
| + /** @private {!Element} */ |
| this.element_ = element; |
| this.element_.addEventListener( |
| - 'touchstart', this.onTouchStart_.bind(this), { passive: true }); |
| + 'touchstart', |
| + /** @type {function(!Event)} */ (this.onTouchStart_.bind(this)), |
|
dpapad
2017/05/23 18:38:38
Changed the code to use a different function refer
|
| + { passive: true }); |
| + |
| this.element_.addEventListener( |
| - 'touchmove', this.onTouch_.bind(this), { passive: false }); |
| + 'touchmove', |
| + /** @type {function(!Event)} */ (this.onTouch_.bind(this)), |
| + { passive: false }); |
| this.element_.addEventListener( |
| - 'touchend', this.onTouch_.bind(this), { passive: true }); |
| + 'touchend', |
| + /** @type {function(!Event)} */ (this.onTouch_.bind(this)), |
| + { passive: true }); |
| this.element_.addEventListener( |
| - 'touchcancel', this.onTouch_.bind(this), { passive: true }); |
| + 'touchcancel', |
| + /** @type {function(!Event)} */ (this.onTouch_.bind(this)), |
| + { passive: true }); |
| this.pinchStartEvent_ = null; |
| this.lastTouchTouchesCount_ = 0; |
| + |
| + /** @private {?TouchEvent} */ |
| this.lastEvent_ = null; |
| + /** @private {!Map<string, !Array<!Function>>} */ |
| this.listeners_ = new Map([ |
| ['pinchstart', []], |
| ['pinchupdate', []], |
| @@ -39,7 +52,7 @@ class GestureDetector { |
| /** |
| * Add a |listener| to be notified of |type| events. |
| * @param {string} type The event type to be notified for. |
| - * @param {Function} listener The callback. |
| + * @param {!Function} listener The callback. |
| */ |
| addEventListener(type, listener) { |
| if (this.listeners_.has(type)) { |
| @@ -94,12 +107,14 @@ class GestureDetector { |
| if (!this.pinchStartEvent_) |
| return; |
| + let lastEvent = /** @type {!TouchEvent} */ (this.lastEvent_); |
| + |
| // Check if the pinch ends with the current event. |
| if (event.touches.length < 2 || |
| - this.lastEvent_.touches.length !== event.touches.length) { |
| + lastEvent.touches.length !== event.touches.length) { |
| let startScaleRatio = GestureDetector.pinchScaleRatio_( |
| - this.lastEvent_, this.pinchStartEvent_); |
| - let center = GestureDetector.center_(this.lastEvent_); |
| + lastEvent, this.pinchStartEvent_); |
| + let center = GestureDetector.center_(lastEvent); |
| let endEvent = { |
| type: 'pinchend', |
| startScaleRatio: startScaleRatio, |
| @@ -115,7 +130,7 @@ class GestureDetector { |
| // pinch-zoom does not interfere with our way of handling the event. |
| event.preventDefault(); |
| - let scaleRatio = GestureDetector.pinchScaleRatio_(event, this.lastEvent_); |
| + let scaleRatio = GestureDetector.pinchScaleRatio_(event, lastEvent); |
| let startScaleRatio = GestureDetector.pinchScaleRatio_( |
| event, this.pinchStartEvent_); |
| let center = GestureDetector.center_(event); |