Index: chrome/browser/resources/pdf/pdf.js |
diff --git a/chrome/browser/resources/pdf/pdf.js b/chrome/browser/resources/pdf/pdf.js |
index 9805660b562c34e82cae189e4670abaace68eb8e..f04dd4ae778bb92fd148fa740b50c4a04b326fa8 100644 |
--- a/chrome/browser/resources/pdf/pdf.js |
+++ b/chrome/browser/resources/pdf/pdf.js |
@@ -191,6 +191,15 @@ function PDFViewer(browserApi) { |
this.zoomToolbar_.addEventListener('zoom-out', |
this.viewport_.zoomOut.bind(this.viewport_)); |
+ this.gestureDetector_ = new GestureDetector(this.plugin_); |
+ this.gestureDetector_.addEventListener( |
+ 'pinchstart', this.viewport_.pinchZoomStart.bind(this.viewport_)); |
+ this.sentPinchEvent_ = false; |
+ this.gestureDetector_.addEventListener( |
+ 'pinchupdate', this.onPinchUpdate_.bind(this)); |
+ this.gestureDetector_.addEventListener( |
+ 'pinchend', this.onPinchEnd_.bind(this)); |
+ |
if (toolbarEnabled) { |
this.toolbar_ = $('toolbar'); |
this.toolbar_.hidden = false; |
@@ -659,6 +668,19 @@ PDFViewer.prototype = { |
this.plugin_.postMessage({ |
type: 'stopScrolling' |
}); |
+ |
+ if (this.viewport_.pinchPhase == Viewport.PinchPhase.PINCH_START) { |
+ var position = this.viewport_.position; |
+ var zoom = this.viewport_.zoom; |
+ var pinchPhase = this.viewport_.pinchPhase; |
+ this.plugin_.postMessage({ |
+ type: 'viewport', |
+ zoom: zoom, |
+ xOffset: position.x, |
+ yOffset: position.y, |
+ pinchPhase: pinchPhase |
+ }); |
+ } |
}, |
/** |
@@ -669,17 +691,55 @@ PDFViewer.prototype = { |
afterZoom_: function() { |
var position = this.viewport_.position; |
var zoom = this.viewport_.zoom; |
+ var pinchVector = this.viewport_.pinchPanVector || {x: 0, y: 0}; |
+ var pinchCenter = this.viewport_.pinchCenter || {x: 0, y: 0}; |
+ var pinchPhase = this.viewport_.pinchPhase; |
+ |
this.plugin_.postMessage({ |
type: 'viewport', |
zoom: zoom, |
xOffset: position.x, |
- yOffset: position.y |
+ yOffset: position.y, |
+ pinchPhase: pinchPhase, |
+ pinchX: pinchCenter.x, |
+ pinchY: pinchCenter.y, |
+ pinchVectorX: pinchVector.x, |
+ pinchVectorY: pinchVector.y |
}); |
this.zoomManager_.onPdfZoomChange(); |
}, |
/** |
* @private |
+ * A callback that's called when an update to a pinch zoom is detected. |
+ * @param {!Object} e the pinch event. |
+ */ |
+ onPinchUpdate_: function(e) { |
+ // Throttle number of pinch events to one per frame. |
+ if (!this.sentPinchEvent_) { |
+ this.sentPinchEvent_ = true; |
+ window.requestAnimationFrame(function() { |
+ this.sentPinchEvent_ = false; |
+ this.viewport_.pinchZoom(e); |
+ }.bind(this)); |
+ } |
+ }, |
+ |
+ /** |
+ * @private |
+ * A callback that's called when the end of a pinch zoom is detected. |
+ * @param {!Object} e the pinch event. |
+ */ |
+ onPinchEnd_: function(e) { |
+ // Using rAF for pinch end prevents pinch updates scheduled by rAF getting |
+ // sent after the pinch end. |
+ window.requestAnimationFrame(function() { |
+ this.viewport_.pinchZoomEnd(e); |
+ }.bind(this)); |
+ }, |
+ |
+ /** |
+ * @private |
* A callback that's called after the viewport changes. |
*/ |
viewportChanged_: function() { |