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

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

Issue 1255403002: Add a scroll offset to PDF documents to account for the top material design toolbar. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 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/pdf.js ('k') | chrome/test/data/pdf/basic_plugin_test.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 47c25079faaa3b23ee3346b6ddc7f68f3f4c7b43..35a5f6590e49a84619c6c44d805e1b3f9c9b6f9f 100644
--- a/chrome/browser/resources/pdf/viewport.js
+++ b/chrome/browser/resources/pdf/viewport.js
@@ -25,6 +25,8 @@ function getIntersectionHeight(rect1, rect2) {
* @param {Function} afterZoomCallback is run after a change in zoom
* @param {number} scrollbarWidth the width of scrollbars on the page
* @param {number} defaultZoom The default zoom level.
+ * @param {number} topToolbarHeight The number of pixels that should initially
+ * be left blank above the document for the toolbar.
*/
function Viewport(window,
sizer,
@@ -32,7 +34,8 @@ function Viewport(window,
beforeZoomCallback,
afterZoomCallback,
scrollbarWidth,
- defaultZoom) {
+ defaultZoom,
+ topToolbarHeight) {
this.window_ = window;
this.sizer_ = sizer;
this.viewportChangedCallback_ = viewportChangedCallback;
@@ -45,6 +48,7 @@ function Viewport(window,
this.scrollbarWidth_ = scrollbarWidth;
this.fittingType_ = Viewport.FittingType.NONE;
this.defaultZoom_ = defaultZoom;
+ this.topToolbarHeight_ = topToolbarHeight;
window.addEventListener('scroll', this.updateViewport_.bind(this));
window.addEventListener('resize', this.resize_.bind(this));
@@ -139,8 +143,8 @@ Viewport.prototype = {
if (this.documentDimensions_) {
this.sizer_.style.width =
this.documentDimensions_.width * this.zoom_ + 'px';
- this.sizer_.style.height =
- this.documentDimensions_.height * this.zoom_ + 'px';
+ this.sizer_.style.height = this.documentDimensions_.height * this.zoom_ +
+ this.topToolbarHeight_ + 'px';
}
},
@@ -171,7 +175,7 @@ Viewport.prototype = {
get position() {
return {
x: this.window_.pageXOffset,
- y: this.window_.pageYOffset
+ y: this.window_.pageYOffset - this.topToolbarHeight_
};
},
@@ -180,7 +184,7 @@ Viewport.prototype = {
* @type {Object} position the position to scroll to.
*/
set position(position) {
- this.window_.scrollTo(position.x, position.y);
+ this.window_.scrollTo(position.x, position.y + this.topToolbarHeight_);
},
/**
@@ -229,15 +233,17 @@ Viewport.prototype = {
'Viewport.mightZoom_.';
}
// Record the scroll position (relative to the top-left of the window).
- var currentScrollPos = [
- this.window_.pageXOffset / this.zoom_,
- this.window_.pageYOffset / this.zoom_
- ];
+ var currentScrollPos = {
+ x: this.position.x / this.zoom_,
+ y: this.position.y / this.zoom_
+ };
this.zoom_ = newZoom;
this.contentSizeChanged_();
// Scroll to the scaled scroll position.
- this.window_.scrollTo(currentScrollPos[0] * newZoom,
- currentScrollPos[1] * newZoom);
+ this.position = {
+ x: currentScrollPos.x * newZoom,
+ y: currentScrollPos.y * newZoom
+ };
},
/**
@@ -426,8 +432,12 @@ Viewport.prototype = {
height: this.pageDimensions_[page].height,
};
this.setZoomInternal_(this.computeFittingZoom_(dimensions, false));
- if (scrollToTopOfPage)
- this.window_.scrollTo(0, this.pageDimensions_[page].y * this.zoom_);
+ if (scrollToTopOfPage) {
+ this.position = {
+ x: 0,
+ y: this.pageDimensions_[page].y * this.zoom_
+ };
+ }
this.updateViewport_();
}.bind(this));
},
@@ -485,8 +495,16 @@ Viewport.prototype = {
if (page >= this.pageDimensions_.length)
page = this.pageDimensions_.length - 1;
var dimensions = this.pageDimensions_[page];
- this.window_.scrollTo(dimensions.x * this.zoom_,
- dimensions.y * this.zoom_);
+ var toolbarOffset = 0;
+ // Unless we're in fit to page mode, scroll above the page by
+ // |this.topToolbarHeight_| so that the toolbar isn't covering it
+ // initially.
+ if (this.fittingType_ != Viewport.FittingType.FIT_TO_PAGE)
+ toolbarOffset = this.topToolbarHeight_;
+ this.position = {
+ x: dimensions.x * this.zoom_,
+ y: dimensions.y * this.zoom_ - toolbarOffset
+ };
this.updateViewport_();
}.bind(this));
},
@@ -504,7 +522,10 @@ Viewport.prototype = {
this.setZoomInternal_(
Math.min(this.defaultZoom_,
this.computeFittingZoom_(this.documentDimensions_, true)));
- this.window_.scrollTo(0, 0);
+ this.position = {
+ x: 0,
+ y: -this.topToolbarHeight_
+ };
}
this.contentSizeChanged_();
this.resize_();
« no previous file with comments | « chrome/browser/resources/pdf/pdf.js ('k') | chrome/test/data/pdf/basic_plugin_test.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698