Index: chrome/browser/resources/pdf/pdf.js |
diff --git a/chrome/browser/resources/pdf/pdf.js b/chrome/browser/resources/pdf/pdf.js |
index dab584d9d0bdc9afb6d3a68f1631627bba6bd8ac..41d9b59ec4043d73abbe3803c3224b9a6563d160 100644 |
--- a/chrome/browser/resources/pdf/pdf.js |
+++ b/chrome/browser/resources/pdf/pdf.js |
@@ -217,6 +217,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 browser |
+ // 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', function(ev) { |
+ this.pinchZoomStart(ev); |
+ }.bind(this.viewport_)); |
+ |
+ this.hammertime_.on('pinch', function(ev) { |
+ if(!this.didPinch_) { |
+ this.didPinch_ = true; |
+ window.requestAnimationFrame(function() { |
+ this.didPinch_ = false; |
+ this.pinchZoom(ev); |
+ }.bind(this)); |
+ } |
+ }.bind(this.viewport_)); |
+ |
+ this.hammertime_.on('pinchend', function(ev) { |
+ if(!this.didPinchEnd_) { |
+ this.didPinchEnd_ = true; |
+ window.requestAnimationFrame(function() { |
bokan
2016/05/12 14:57:57
I don't think we need to rAF the PinchEnd event.
|
+ this.didPinchEnd_ = false; |
+ this.pinchZoomEnd(ev); |
+ }.bind(this)); |
+ } |
+ }.bind(this.viewport_)); |
+ |
if (toolbarEnabled) { |
this.toolbar_ = $('toolbar'); |
this.toolbar_.hidden = false; |
@@ -687,11 +727,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 doRender = this.viewport.doRender_; |
+ |
+ 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, |
+ render: doRender, // Render or not |
bokan
2016/05/12 14:57:57
I think a better name here would be needsReraster
|
+ px: pinchCenter.x, |
+ py: pinchCenter.y, |
+ pinchVectorX: pinchVector.x, |
+ pinchVectorY: pinchVector.y |
}); |
this.zoomManager_.onPdfZoomChange(); |
}, |