Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(3920)

Unified Diff: chrome/browser/resources/pdf/pdf.js

Issue 420063002: OOP PDF - Add support for "zoom" open pdf parameter (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Review feedback Created 6 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « chrome/browser/resources/pdf/open_pdf_params_parser.js ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/resources/pdf/pdf.js
diff --git a/chrome/browser/resources/pdf/pdf.js b/chrome/browser/resources/pdf/pdf.js
index 2bb5511402abe108e48da0d5f28c52449bf086c0..0aa437aef03c7e1747929fe50925367d29164878 100644
--- a/chrome/browser/resources/pdf/pdf.js
+++ b/chrome/browser/resources/pdf/pdf.js
@@ -147,7 +147,10 @@ function PDFViewer() {
var MIN_ZOOM_DELTA = 0.01;
var zoomDelta = Math.abs(this.viewport_.zoom -
zoomChangeInfo.newZoomFactor);
- if (zoomDelta > MIN_ZOOM_DELTA)
+ // We should not change zoom level when we are responsible for initiating
+ // the zoom. onZoomChange() is called before setZoomComplete() callback
+ // when we initiate the zoom.
+ if ((zoomDelta > MIN_ZOOM_DELTA) && !this.setZoomInProgress_)
this.viewport_.setZoom(zoomChangeInfo.newZoomFactor);
}.bind(this));
}
@@ -270,6 +273,26 @@ PDFViewer.prototype = {
/**
* @private
+ * Handle open pdf parameters. This function updates the viewport as per
+ * the parameters mentioned in the url while opening pdf. The order is
+ * important as later actions can override the effects of previous actions.
+ */
+ handleURLParams_: function() {
+ if (this.urlParams_.page)
+ this.viewport_.goToPage(this.urlParams_.page);
+ if (this.urlParams_.position) {
+ // Make sure we don't cancel effect of page parameter.
+ this.viewport_.position = {
+ x: this.viewport_.position.x + this.urlParams_.position.x,
+ y: this.viewport_.position.y + this.urlParams_.position.y
+ };
+ }
+ if (this.urlParams_.zoom)
+ this.viewport_.setZoom(this.urlParams_.zoom);
+ },
+
+ /**
+ * @private
* Update the loading progress of the document in response to a progress
* message being received from the plugin.
* @param {number} progress the progress as a percentage.
@@ -287,19 +310,15 @@ PDFViewer.prototype = {
}
} else if (progress == 100) {
// Document load complete.
+ if (this.lastViewportPosition_)
+ this.viewport_.position = this.lastViewportPosition_;
+ this.handleURLParams_();
this.loaded = true;
var loadEvent = new Event('pdfload');
window.dispatchEvent(loadEvent);
this.sendScriptingMessage_({
type: 'documentLoaded'
});
- if (this.lastViewportPosition_)
- this.viewport_.position = this.lastViewportPosition_;
-
- // Handle open pdf params. Order is important as later actions can
- // override the effects of previous actions.
- if (this.urlParams_.page)
- this.viewport_.goToPage(this.urlParams_.page);
}
},
« no previous file with comments | « chrome/browser/resources/pdf/open_pdf_params_parser.js ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698