summaryrefslogtreecommitdiff
path: root/chromium/chrome/browser/resources/pdf/pdf.js
diff options
context:
space:
mode:
Diffstat (limited to 'chromium/chrome/browser/resources/pdf/pdf.js')
-rw-r--r--chromium/chrome/browser/resources/pdf/pdf.js62
1 files changed, 61 insertions, 1 deletions
diff --git a/chromium/chrome/browser/resources/pdf/pdf.js b/chromium/chrome/browser/resources/pdf/pdf.js
index f3828af7181..14aebcf8cdd 100644
--- a/chromium/chrome/browser/resources/pdf/pdf.js
+++ b/chromium/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;
@@ -658,6 +667,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
+ });
+ }
},
/**
@@ -668,17 +690,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() {