| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 'use strict'; | 5 'use strict'; |
| 6 | 6 |
| 7 /** | 7 /** |
| 8 * A class that listens for touch events and produces events when these | 8 * A class that listens for touch events and produces events when these |
| 9 * touches form gestures (e.g. pinching). | 9 * touches form gestures (e.g. pinching). |
| 10 */ | 10 */ |
| 11 class GestureDetector { | 11 class GestureDetector { |
| 12 /** | 12 /** |
| 13 * Constructs a GestureDetector. | 13 * Constructs a GestureDetector. |
| 14 * @param {!Element} element The element to monitor for touch gestures. | 14 * @param {!Element} element The element to monitor for touch gestures. |
| 15 */ | 15 */ |
| 16 constructor(element) { | 16 constructor(element) { |
| 17 this.element_ = element; | 17 this.element_ = element; |
| 18 | 18 |
| 19 this.element_.addEventListener('touchstart', this.onTouchStart_.bind(this)); | 19 this.element_.addEventListener( |
| 20 this.element_.addEventListener('touchmove', this.onTouch_.bind(this)); | 20 'touchstart', this.onTouchStart_.bind(this), { passive: false }); |
| 21 this.element_.addEventListener('touchend', this.onTouch_.bind(this)); | 21 this.element_.addEventListener( |
| 22 this.element_.addEventListener('touchcancel', this.onTouch_.bind(this)); | 22 'touchmove', this.onTouch_.bind(this), { passive: true }); |
| 23 this.element_.addEventListener( |
| 24 'touchend', this.onTouch_.bind(this), { passive: true }); |
| 25 this.element_.addEventListener( |
| 26 'touchcancel', this.onTouch_.bind(this), { passive: true }); |
| 23 | 27 |
| 24 this.pinchStartEvent_ = null; | 28 this.pinchStartEvent_ = null; |
| 25 this.lastEvent_ = null; | 29 this.lastEvent_ = null; |
| 26 | 30 |
| 27 this.listeners_ = new Map([ | 31 this.listeners_ = new Map([ |
| 28 ['pinchstart', []], | 32 ['pinchstart', []], |
| 29 ['pinchupdate', []], | 33 ['pinchupdate', []], |
| 30 ['pinchend', []] | 34 ['pinchend', []] |
| 31 ]); | 35 ]); |
| 32 } | 36 } |
| (...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 151 */ | 155 */ |
| 152 static center_(event) { | 156 static center_(event) { |
| 153 let touch1 = event.touches[0]; | 157 let touch1 = event.touches[0]; |
| 154 let touch2 = event.touches[1]; | 158 let touch2 = event.touches[1]; |
| 155 return { | 159 return { |
| 156 x: (touch1.clientX + touch2.clientX) / 2, | 160 x: (touch1.clientX + touch2.clientX) / 2, |
| 157 y: (touch1.clientY + touch2.clientY) / 2 | 161 y: (touch1.clientY + touch2.clientY) / 2 |
| 158 }; | 162 }; |
| 159 } | 163 } |
| 160 }; | 164 }; |
| OLD | NEW |