Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 /** | 5 /** |
| 6 * Returns the height of the intersection of two rectangles. | 6 * Returns the height of the intersection of two rectangles. |
| 7 * @param {Object} rect1 the first rect | 7 * @param {Object} rect1 the first rect |
| 8 * @param {Object} rect2 the second rect | 8 * @param {Object} rect2 the second rect |
| 9 * @return {number} the height of the intersection of the rects | 9 * @return {number} the height of the intersection of the rects |
| 10 */ | 10 */ |
| 11 function getIntersectionHeight(rect1, rect2) { | 11 function getIntersectionHeight(rect1, rect2) { |
| 12 return Math.max(0, | 12 return Math.max(0, |
| 13 Math.min(rect1.y + rect1.height, rect2.y + rect2.height) - | 13 Math.min(rect1.y + rect1.height, rect2.y + rect2.height) - |
| 14 Math.max(rect1.y, rect2.y)); | 14 Math.max(rect1.y, rect2.y)); |
| 15 } | 15 } |
| 16 | 16 |
| 17 /** | 17 /** |
| 18 * Create a new viewport. | 18 * Create a new viewport. |
| 19 * @param {Window} window the window | 19 * @param {Window} window the window |
| 20 * @param {Object} sizer is the element which represents the size of the | 20 * @param {Object} sizer is the element which represents the size of the |
| 21 * document in the viewport | 21 * document in the viewport |
| 22 * @param {Function} viewportChangedCallback is run when the viewport changes | 22 * @param {Function} viewportChangedCallback is run when the viewport changes |
| 23 * @param {Function} beforeZoomCallback is run before a change in zoom | 23 * @param {Function} beforeZoomCallback is run before a change in zoom |
| 24 * @param {Function} afterZoomCallback is run after a change in zoom | 24 * @param {Function} afterZoomCallback is run after a change in zoom |
| 25 * @param {number} scrollbarWidth the width of scrollbars on the page | 25 * @param {number} scrollbarWidth the width of scrollbars on the page |
| 26 * @param {number} yPos the offset of the viewport from the top of the window | |
| 26 */ | 27 */ |
| 27 function Viewport(window, | 28 function Viewport(window, |
| 28 sizer, | 29 sizer, |
| 29 viewportChangedCallback, | 30 viewportChangedCallback, |
| 30 beforeZoomCallback, | 31 beforeZoomCallback, |
| 31 afterZoomCallback, | 32 afterZoomCallback, |
| 32 scrollbarWidth) { | 33 scrollbarWidth, |
| 34 yPos) { | |
| 33 this.window_ = window; | 35 this.window_ = window; |
| 34 this.sizer_ = sizer; | 36 this.sizer_ = sizer; |
| 35 this.viewportChangedCallback_ = viewportChangedCallback; | 37 this.viewportChangedCallback_ = viewportChangedCallback; |
| 36 this.beforeZoomCallback_ = beforeZoomCallback; | 38 this.beforeZoomCallback_ = beforeZoomCallback; |
| 37 this.afterZoomCallback_ = afterZoomCallback; | 39 this.afterZoomCallback_ = afterZoomCallback; |
| 38 this.allowedToChangeZoom_ = false; | 40 this.allowedToChangeZoom_ = false; |
| 39 this.zoom_ = 1; | 41 this.zoom_ = 1; |
| 40 this.documentDimensions_ = null; | 42 this.documentDimensions_ = null; |
| 41 this.pageDimensions_ = []; | 43 this.pageDimensions_ = []; |
| 42 this.scrollbarWidth_ = scrollbarWidth; | 44 this.scrollbarWidth_ = scrollbarWidth; |
| 43 this.fittingType_ = Viewport.FittingType.NONE; | 45 this.fittingType_ = Viewport.FittingType.NONE; |
| 46 var toolbar = $('pdf-toolbar'); | |
|
Sam McNally
2015/01/13 07:03:57
Is this used?
Alexandre Carlton
2015/01/14 22:42:50
Removed.
| |
| 47 this.yPos = yPos; | |
| 44 | 48 |
| 45 window.addEventListener('scroll', this.updateViewport_.bind(this)); | 49 window.addEventListener('scroll', this.updateViewport_.bind(this)); |
| 46 window.addEventListener('resize', this.resize_.bind(this)); | 50 window.addEventListener('resize', this.resize_.bind(this)); |
| 47 } | 51 } |
| 48 | 52 |
| 49 /** | 53 /** |
| 50 * Enumeration of page fitting types. | 54 * Enumeration of page fitting types. |
| 51 * @enum {string} | 55 * @enum {string} |
| 52 */ | 56 */ |
| 53 Viewport.FittingType = { | 57 Viewport.FittingType = { |
| (...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 129 | 133 |
| 130 /** | 134 /** |
| 131 * @private | 135 * @private |
| 132 * Helper function called when the zoomed document size changes. | 136 * Helper function called when the zoomed document size changes. |
| 133 */ | 137 */ |
| 134 contentSizeChanged_: function() { | 138 contentSizeChanged_: function() { |
| 135 if (this.documentDimensions_) { | 139 if (this.documentDimensions_) { |
| 136 this.sizer_.style.width = | 140 this.sizer_.style.width = |
| 137 this.documentDimensions_.width * this.zoom_ + 'px'; | 141 this.documentDimensions_.width * this.zoom_ + 'px'; |
| 138 this.sizer_.style.height = | 142 this.sizer_.style.height = |
| 139 this.documentDimensions_.height * this.zoom_ + 'px'; | 143 this.documentDimensions_.height * this.zoom_ + this.yPos + 'px'; |
| 140 } | 144 } |
| 141 }, | 145 }, |
| 142 | 146 |
| 143 /** | 147 /** |
| 144 * @private | 148 * @private |
| 145 * Called when the viewport should be updated. | 149 * Called when the viewport should be updated. |
| 146 */ | 150 */ |
| 147 updateViewport_: function() { | 151 updateViewport_: function() { |
| 148 this.viewportChangedCallback_(); | 152 this.viewportChangedCallback_(); |
| 149 }, | 153 }, |
| (...skipping 389 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 539 spaceOnLeft = Math.max(spaceOnLeft, 0); | 543 spaceOnLeft = Math.max(spaceOnLeft, 0); |
| 540 | 544 |
| 541 return { | 545 return { |
| 542 x: x * this.zoom_ + spaceOnLeft - this.window_.pageXOffset, | 546 x: x * this.zoom_ + spaceOnLeft - this.window_.pageXOffset, |
| 543 y: insetDimensions.y * this.zoom_ - this.window_.pageYOffset, | 547 y: insetDimensions.y * this.zoom_ - this.window_.pageYOffset, |
| 544 width: insetDimensions.width * this.zoom_, | 548 width: insetDimensions.width * this.zoom_, |
| 545 height: insetDimensions.height * this.zoom_ | 549 height: insetDimensions.height * this.zoom_ |
| 546 }; | 550 }; |
| 547 } | 551 } |
| 548 }; | 552 }; |
| OLD | NEW |