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

Side by Side Diff: chrome/browser/resources/pdf/viewport.js

Issue 885733003: Remove toolbar offset in Material Design PDF Viewer (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 unified diff | Download patch
« no previous file with comments | « chrome/browser/resources/pdf/pdf.js ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 * @constructor 19 * @constructor
20 * @param {Window} window the window 20 * @param {Window} window the window
21 * @param {Object} sizer is the element which represents the size of the 21 * @param {Object} sizer is the element which represents the size of the
22 * document in the viewport 22 * document in the viewport
23 * @param {Function} viewportChangedCallback is run when the viewport changes 23 * @param {Function} viewportChangedCallback is run when the viewport changes
24 * @param {Function} beforeZoomCallback is run before a change in zoom 24 * @param {Function} beforeZoomCallback is run before a change in zoom
25 * @param {Function} afterZoomCallback is run after a change in zoom 25 * @param {Function} afterZoomCallback is run after a change in zoom
26 * @param {number} scrollbarWidth the width of scrollbars on the page 26 * @param {number} scrollbarWidth the width of scrollbars on the page
27 * @param {number} yPos the offset of the viewport from the top of the window
28 */ 27 */
29 function Viewport(window, 28 function Viewport(window,
30 sizer, 29 sizer,
31 viewportChangedCallback, 30 viewportChangedCallback,
32 beforeZoomCallback, 31 beforeZoomCallback,
33 afterZoomCallback, 32 afterZoomCallback,
34 scrollbarWidth, 33 scrollbarWidth) {
35 yPos) {
36 this.window_ = window; 34 this.window_ = window;
37 this.sizer_ = sizer; 35 this.sizer_ = sizer;
38 this.viewportChangedCallback_ = viewportChangedCallback; 36 this.viewportChangedCallback_ = viewportChangedCallback;
39 this.beforeZoomCallback_ = beforeZoomCallback; 37 this.beforeZoomCallback_ = beforeZoomCallback;
40 this.afterZoomCallback_ = afterZoomCallback; 38 this.afterZoomCallback_ = afterZoomCallback;
41 this.allowedToChangeZoom_ = false; 39 this.allowedToChangeZoom_ = false;
42 this.zoom_ = 1; 40 this.zoom_ = 1;
43 this.documentDimensions_ = null; 41 this.documentDimensions_ = null;
44 this.pageDimensions_ = []; 42 this.pageDimensions_ = [];
45 this.scrollbarWidth_ = scrollbarWidth; 43 this.scrollbarWidth_ = scrollbarWidth;
46 this.fittingType_ = Viewport.FittingType.NONE; 44 this.fittingType_ = Viewport.FittingType.NONE;
47 this.yPos = yPos;
48 45
49 window.addEventListener('scroll', this.updateViewport_.bind(this)); 46 window.addEventListener('scroll', this.updateViewport_.bind(this));
50 window.addEventListener('resize', this.resize_.bind(this)); 47 window.addEventListener('resize', this.resize_.bind(this));
51 } 48 }
52 49
53 /** 50 /**
54 * Enumeration of page fitting types. 51 * Enumeration of page fitting types.
55 * @enum {string} 52 * @enum {string}
56 */ 53 */
57 Viewport.FittingType = { 54 Viewport.FittingType = {
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
133 130
134 /** 131 /**
135 * @private 132 * @private
136 * Helper function called when the zoomed document size changes. 133 * Helper function called when the zoomed document size changes.
137 */ 134 */
138 contentSizeChanged_: function() { 135 contentSizeChanged_: function() {
139 if (this.documentDimensions_) { 136 if (this.documentDimensions_) {
140 this.sizer_.style.width = 137 this.sizer_.style.width =
141 this.documentDimensions_.width * this.zoom_ + 'px'; 138 this.documentDimensions_.width * this.zoom_ + 'px';
142 this.sizer_.style.height = 139 this.sizer_.style.height =
143 this.documentDimensions_.height * this.zoom_ + this.yPos + 'px'; 140 this.documentDimensions_.height * this.zoom_ + 'px';
144 } 141 }
145 }, 142 },
146 143
147 /** 144 /**
148 * @private 145 * @private
149 * Called when the viewport should be updated. 146 * Called when the viewport should be updated.
150 */ 147 */
151 updateViewport_: function() { 148 updateViewport_: function() {
152 this.viewportChangedCallback_(); 149 this.viewportChangedCallback_();
153 }, 150 },
(...skipping 390 matching lines...) Expand 10 before | Expand all | Expand 10 after
544 spaceOnLeft = Math.max(spaceOnLeft, 0); 541 spaceOnLeft = Math.max(spaceOnLeft, 0);
545 542
546 return { 543 return {
547 x: x * this.zoom_ + spaceOnLeft - this.window_.pageXOffset, 544 x: x * this.zoom_ + spaceOnLeft - this.window_.pageXOffset,
548 y: insetDimensions.y * this.zoom_ - this.window_.pageYOffset, 545 y: insetDimensions.y * this.zoom_ - this.window_.pageYOffset,
549 width: insetDimensions.width * this.zoom_, 546 width: insetDimensions.width * this.zoom_,
550 height: insetDimensions.height * this.zoom_ 547 height: insetDimensions.height * this.zoom_
551 }; 548 };
552 } 549 }
553 }; 550 };
OLDNEW
« no previous file with comments | « chrome/browser/resources/pdf/pdf.js ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698