Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1703)

Unified Diff: chrome/browser/resources/pdf/gesture_detector.js

Issue 2855953003: Handle long press in PDF documents. (Closed)
Patch Set: Created 3 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | chrome/browser/resources/pdf/pdf.js » ('j') | chrome/browser/resources/pdf/pdf.js » ('J')
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 fde4650d92bbbc6db1d8ed7aa7259c90a9e144c3..ba6ce23a26d98b51962ac4530992c2ae61622088 100644
--- a/chrome/browser/resources/pdf/gesture_detector.js
+++ b/chrome/browser/resources/pdf/gesture_detector.js
@@ -19,13 +19,13 @@ class GestureDetector {
this.element_.addEventListener(
'touchstart', this.onTouchStart_.bind(this), { passive: false });
Kevin McNee 2017/05/02 23:18:18 Since we're no longer calling preventDefault in th
dsinclair 2017/05/03 14:18:40 Yea, I'm going to use your Cl for this bit, I'd do
this.element_.addEventListener(
- 'touchmove', this.onTouch_.bind(this), { passive: true });
+ 'touchmove', this.onTouch_.bind(this), { passive: false });
this.element_.addEventListener(
'touchend', this.onTouch_.bind(this), { passive: true });
this.element_.addEventListener(
'touchcancel', this.onTouch_.bind(this), { passive: true });
- this.pinchStartEvent_ = null;
+ this.touchStartEvent_ = null;
this.lastEvent_ = null;
this.listeners_ = new Map([
@@ -47,6 +47,14 @@ class GestureDetector {
}
/**
+ * Returns true if the previous touch start was a two finger touch.
+ * @return {!bool} True if touch start was two finger.
Kevin McNee 2017/05/02 23:18:18 The ! is redundant since booleans are non-nullable
dsinclair 2017/05/03 14:18:40 Done.
+ */
+ isTwoFingerTouch() {
+ return this.touchStartEvent_ && this.touchStartEvent_.touches.length == 2;
Kevin McNee 2017/05/02 23:18:19 I notice that |touchStartEvent_| is never cleared
dsinclair 2017/05/03 14:18:40 Done.
+ }
+
+ /**
* Call the relevant listeners with the given |pinchEvent|.
* @private
* @param {!Object} pinchEvent The event to notify the listeners of.
@@ -64,11 +72,9 @@ class GestureDetector {
* @param {!TouchEvent} event Touch event on the element.
*/
onTouchStart_(event) {
- // We must preventDefault if there is a two finger touch. By doing so
- // native pinch-zoom does not interfere with our way of handling the event.
- if (event.touches.length == 2) {
- event.preventDefault();
- this.pinchStartEvent_ = event;
+ this.touchStartEvent_ = event;
+
+ if (this.isTwoFingerTouch()) {
this.lastEvent_ = event;
this.notify_({
type: 'pinchstart',
@@ -83,21 +89,27 @@ class GestureDetector {
* @param {!TouchEvent} event Touch event on the element.
*/
onTouch_(event) {
- if (!this.pinchStartEvent_)
+ // Missing a lastEvent_ means we either haven't got a touchstart or we've
+ // finished handling the pinch already.
+ if (!this.lastEvent_ || !this.isTwoFingerTouch())
return;
+ // Prevent default the touchmove to block the native pinch-zoom.
+ if (event.type == "touchmove")
+ event.preventDefault();
dsinclair 2017/05/02 19:44:05 This is very similar to https://codereview.chromiu
+
// Check if the pinch ends with the current event.
if (event.touches.length < 2 ||
this.lastEvent_.touches.length !== event.touches.length) {
let startScaleRatio = GestureDetector.pinchScaleRatio_(
- this.lastEvent_, this.pinchStartEvent_);
+ this.lastEvent_, this.touchStartEvent_);
let center = GestureDetector.center_(this.lastEvent_);
let endEvent = {
type: 'pinchend',
startScaleRatio: startScaleRatio,
center: center
};
- this.pinchStartEvent_ = null;
+
this.lastEvent_ = null;
this.notify_(endEvent);
return;
@@ -105,7 +117,7 @@ class GestureDetector {
let scaleRatio = GestureDetector.pinchScaleRatio_(event, this.lastEvent_);
let startScaleRatio = GestureDetector.pinchScaleRatio_(
- event, this.pinchStartEvent_);
+ event, this.touchStartEvent_);
let center = GestureDetector.center_(event);
this.notify_({
type: 'pinchupdate',
« no previous file with comments | « no previous file | chrome/browser/resources/pdf/pdf.js » ('j') | chrome/browser/resources/pdf/pdf.js » ('J')

Powered by Google App Engine
This is Rietveld 408576698