Chromium Code Reviews| 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..153eef517daeb7addc9e9c9c4a7386f67c998b90 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,59 @@ PDFViewer.prototype = { |
| afterZoom_: function() { |
| var position = this.viewport_.position; |
| var zoom = this.viewport_.zoom; |
| + var pinchVector = this.viewport_.pinchPanVector; |
|
dpapad
2016/11/09 01:12:26
Nit:
var pinchVector = this.viewport_.pinchPanVect
Kevin McNee - google account
2016/11/09 16:36:09
Done.
|
| + var pinchCenter = this.viewport_.pinchCenter; |
| + var pinchPhase = this.viewport_.pinchPhase; |
| + |
| + if (!pinchVector) |
| + pinchVector = {x: 0, y: 0}; |
| + if (!pinchCenter) |
| + pinchCenter = {x: 0, y: 0}; |
| 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() { |