| 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..a14745df931fae4eca9cfc7d2a46c5a0f00684d3 100644
|
| --- a/chrome/browser/resources/pdf/pdf.js
|
| +++ b/chrome/browser/resources/pdf/pdf.js
|
| @@ -191,6 +191,46 @@ function PDFViewer(browserApi) {
|
| this.zoomToolbar_.addEventListener('zoom-out',
|
| this.viewport_.zoomOut.bind(this.viewport_));
|
|
|
| + // We add Hammer.js in order to handle touch events like pinch-zoom.
|
| + this.hammertime_ = new Hammer($('plugin'));
|
| +
|
| + // 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.
|
| + this.plugin_.addEventListener('touchstart', function(e) {
|
| + if (e.touches.length >= 2) {
|
| + e.preventDefault();
|
| + this.hammertime_.get('pinch').set({enable: true});
|
| + }
|
| + }.bind(this));
|
| +
|
| + this.plugin_.addEventListener('touchend', function(e) {
|
| + this.hammertime_.get('pinch').set({enable: false});
|
| + }.bind(this));
|
| +
|
| + this.hammertime_.on('pinchstart',
|
| + this.viewport_.pinchZoomStart.bind(this.viewport_));
|
| +
|
| + // Throttle number of pinch events to one per frame.
|
| + this.sentPinchEvent_ = false;
|
| +
|
| + this.hammertime_.on('pinch', function(ev) {
|
| + if (!this.sentPinchEvent_) {
|
| + this.sentPinchEvent_ = true;
|
| + window.requestAnimationFrame(function() {
|
| + this.sentPinchEvent_ = false;
|
| + this.viewport_.pinchZoom(ev);
|
| + }.bind(this));
|
| + }
|
| + }.bind(this));
|
| +
|
| + this.hammertime_.on('pinchend', function(ev) {
|
| + // Using rAF for pinch end prevents pinch updates scheduled by rAF getting
|
| + // sent after the pinch end.
|
| + window.requestAnimationFrame(function() {
|
| + this.viewport_.pinchZoomEnd(ev);
|
| + }.bind(this));
|
| + }.bind(this));
|
| +
|
| if (toolbarEnabled) {
|
| this.toolbar_ = $('toolbar');
|
| this.toolbar_.hidden = false;
|
| @@ -659,6 +699,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,11 +722,24 @@ PDFViewer.prototype = {
|
| afterZoom_: function() {
|
| var position = this.viewport_.position;
|
| var zoom = this.viewport_.zoom;
|
| + var pinchVector = this.viewport_.pinchPanVector;
|
| + 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();
|
| },
|
|
|