Chromium Code Reviews| 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..04e34d4715b8b62b8eb009e759ee0384e23c9b55 100644 |
| --- a/chrome/browser/resources/pdf/viewport.js |
| +++ b/chrome/browser/resources/pdf/viewport.js |
| @@ -45,6 +45,7 @@ function Viewport(window, |
| this.scrollbarWidth_ = scrollbarWidth; |
| this.fittingType_ = Viewport.FittingType.NONE; |
| this.defaultZoom_ = defaultZoom; |
| + this.topToolbarHeight = 0; |
|
Sam McNally
2015/08/03 08:06:45
Please make this a constructor param instead of a
raymes
2015/08/04 00:28:46
Done.
|
| window.addEventListener('scroll', this.updateViewport_.bind(this)); |
| window.addEventListener('resize', this.resize_.bind(this)); |
| @@ -139,8 +140,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 +172,7 @@ Viewport.prototype = { |
| get position() { |
| return { |
| x: this.window_.pageXOffset, |
| - y: this.window_.pageYOffset |
| + y: this.window_.pageYOffset - this.topToolbarHeight |
| }; |
| }, |
| @@ -180,7 +181,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 +230,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 +429,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 +492,15 @@ 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 a bit above the page so that |
|
Sam McNally
2015/08/03 08:06:45
Can you be a bit more precise than "a bit above"?
raymes
2015/08/04 00:28:46
Done.
|
| + // 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 +518,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_(); |