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

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

Issue 806633003: Implement basic toolbar with Material Design and loading progress. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Adjust viewport_test.js Created 5 years, 11 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') | chrome/test/data/pdf/viewport_test.js » ('j') | 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
27 */ 28 */
28 function Viewport(window, 29 function Viewport(window,
29 sizer, 30 sizer,
30 viewportChangedCallback, 31 viewportChangedCallback,
31 beforeZoomCallback, 32 beforeZoomCallback,
32 afterZoomCallback, 33 afterZoomCallback,
33 scrollbarWidth) { 34 scrollbarWidth,
35 yPos) {
34 this.window_ = window; 36 this.window_ = window;
35 this.sizer_ = sizer; 37 this.sizer_ = sizer;
36 this.viewportChangedCallback_ = viewportChangedCallback; 38 this.viewportChangedCallback_ = viewportChangedCallback;
37 this.beforeZoomCallback_ = beforeZoomCallback; 39 this.beforeZoomCallback_ = beforeZoomCallback;
38 this.afterZoomCallback_ = afterZoomCallback; 40 this.afterZoomCallback_ = afterZoomCallback;
39 this.allowedToChangeZoom_ = false; 41 this.allowedToChangeZoom_ = false;
40 this.zoom_ = 1; 42 this.zoom_ = 1;
41 this.documentDimensions_ = null; 43 this.documentDimensions_ = null;
42 this.pageDimensions_ = []; 44 this.pageDimensions_ = [];
43 this.scrollbarWidth_ = scrollbarWidth; 45 this.scrollbarWidth_ = scrollbarWidth;
44 this.fittingType_ = Viewport.FittingType.NONE; 46 this.fittingType_ = Viewport.FittingType.NONE;
47 this.yPos = yPos;
45 48
46 window.addEventListener('scroll', this.updateViewport_.bind(this)); 49 window.addEventListener('scroll', this.updateViewport_.bind(this));
47 window.addEventListener('resize', this.resize_.bind(this)); 50 window.addEventListener('resize', this.resize_.bind(this));
48 } 51 }
49 52
50 /** 53 /**
51 * Enumeration of page fitting types. 54 * Enumeration of page fitting types.
52 * @enum {string} 55 * @enum {string}
53 */ 56 */
54 Viewport.FittingType = { 57 Viewport.FittingType = {
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
130 133
131 /** 134 /**
132 * @private 135 * @private
133 * Helper function called when the zoomed document size changes. 136 * Helper function called when the zoomed document size changes.
134 */ 137 */
135 contentSizeChanged_: function() { 138 contentSizeChanged_: function() {
136 if (this.documentDimensions_) { 139 if (this.documentDimensions_) {
137 this.sizer_.style.width = 140 this.sizer_.style.width =
138 this.documentDimensions_.width * this.zoom_ + 'px'; 141 this.documentDimensions_.width * this.zoom_ + 'px';
139 this.sizer_.style.height = 142 this.sizer_.style.height =
140 this.documentDimensions_.height * this.zoom_ + 'px'; 143 this.documentDimensions_.height * this.zoom_ + this.yPos + 'px';
141 } 144 }
142 }, 145 },
143 146
144 /** 147 /**
145 * @private 148 * @private
146 * Called when the viewport should be updated. 149 * Called when the viewport should be updated.
147 */ 150 */
148 updateViewport_: function() { 151 updateViewport_: function() {
149 this.viewportChangedCallback_(); 152 this.viewportChangedCallback_();
150 }, 153 },
(...skipping 390 matching lines...) Expand 10 before | Expand all | Expand 10 after
541 spaceOnLeft = Math.max(spaceOnLeft, 0); 544 spaceOnLeft = Math.max(spaceOnLeft, 0);
542 545
543 return { 546 return {
544 x: x * this.zoom_ + spaceOnLeft - this.window_.pageXOffset, 547 x: x * this.zoom_ + spaceOnLeft - this.window_.pageXOffset,
545 y: insetDimensions.y * this.zoom_ - this.window_.pageYOffset, 548 y: insetDimensions.y * this.zoom_ - this.window_.pageYOffset,
546 width: insetDimensions.width * this.zoom_, 549 width: insetDimensions.width * this.zoom_,
547 height: insetDimensions.height * this.zoom_ 550 height: insetDimensions.height * this.zoom_
548 }; 551 };
549 } 552 }
550 }; 553 };
OLDNEW
« no previous file with comments | « chrome/browser/resources/pdf/pdf.js ('k') | chrome/test/data/pdf/viewport_test.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698