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

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

Issue 931013002: OOP PDF: Fix incorrect scrolling during fit-to-page (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 10 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 | « no previous file | chrome/test/data/pdf/test_util.js » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/resources/pdf/viewport.js
diff --git a/chrome/browser/resources/pdf/viewport.js b/chrome/browser/resources/pdf/viewport.js
index 29b86ceb27de5392a8df010176fe06f5a16caf2f..06428a9d844797743f454e9df6798dde1d89c70e 100644
--- a/chrome/browser/resources/pdf/viewport.js
+++ b/chrome/browser/resources/pdf/viewport.js
@@ -155,7 +155,7 @@ Viewport.prototype = {
*/
resize_: function() {
if (this.fittingType_ == Viewport.FittingType.FIT_TO_PAGE)
- this.fitToPage();
+ this.fitToPageInternal_(false);
else if (this.fittingType_ == Viewport.FittingType.FIT_TO_WIDTH)
this.fitToWidth();
else
@@ -394,23 +394,23 @@ Viewport.prototype = {
this.fittingType_ = Viewport.FittingType.FIT_TO_WIDTH;
if (!this.documentDimensions_)
return;
- // Track the last y-position to stay at the same position after zooming.
- var oldY = this.window_.pageYOffset / this.zoom_;
// When computing fit-to-width, the maximum width of a page in the
// document is used, which is equal to the size of the document width.
this.setZoomInternal_(this.computeFittingZoom_(this.documentDimensions_,
true));
var page = this.getMostVisiblePage();
- this.window_.scrollTo(0, oldY * this.zoom_);
this.updateViewport_();
}.bind(this));
},
/**
- * Zoom the viewport so that a page consumes the entire viewport. Also scrolls
- * to the top of the most visible page.
+ * @private
+ * Zoom the viewport so that a page consumes the entire viewport.
+ * @param {boolean} scrollToTopOfPage Set to true if the viewport should be
+ * scrolled to the top of the current page. Set to false if the viewport
+ * should remain at the current scroll position.
*/
- fitToPage: function() {
+ fitToPageInternal_: function(scrollToTopOfPage) {
this.mightZoom_(function() {
this.fittingType_ = Viewport.FittingType.FIT_TO_PAGE;
if (!this.documentDimensions_)
@@ -422,12 +422,21 @@ Viewport.prototype = {
height: this.pageDimensions_[page].height,
};
this.setZoomInternal_(this.computeFittingZoom_(dimensions, false));
- this.window_.scrollTo(0, this.pageDimensions_[page].y * this.zoom_);
+ if (scrollToTopOfPage)
+ this.window_.scrollTo(0, this.pageDimensions_[page].y * this.zoom_);
this.updateViewport_();
}.bind(this));
},
/**
+ * Zoom the viewport so that a page consumes the entire viewport. Also scrolls
+ * the viewport to the top of the current page.
+ */
+ fitToPage: function() {
+ this.fitToPageInternal_(true);
+ },
+
+ /**
* Zoom out to the next predefined zoom level.
*/
zoomOut: function() {
« no previous file with comments | « no previous file | chrome/test/data/pdf/test_util.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698