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

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

Issue 2503633002: Propagate browser zoom changes to embedded PDFs. (Closed)
Patch Set: Apply internal pdf zoom to browser zoom. Created 4 years, 1 month 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
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 */
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
47 /** 47 /**
48 * Create a new viewport. 48 * Create a new viewport.
49 * @constructor 49 * @constructor
50 * @param {Window} window the window 50 * @param {Window} window the window
51 * @param {Object} sizer is the element which represents the size of the 51 * @param {Object} sizer is the element which represents the size of the
52 * document in the viewport 52 * document in the viewport
53 * @param {Function} viewportChangedCallback is run when the viewport changes 53 * @param {Function} viewportChangedCallback is run when the viewport changes
54 * @param {Function} beforeZoomCallback is run before a change in zoom 54 * @param {Function} beforeZoomCallback is run before a change in zoom
55 * @param {Function} afterZoomCallback is run after a change in zoom 55 * @param {Function} afterZoomCallback is run after a change in zoom
56 * @param {number} scrollbarWidth the width of scrollbars on the page 56 * @param {number} scrollbarWidth the width of scrollbars on the page
57 * @param {number} defaultZoom The default zoom level. 57 * @param {number} initialZoom The zoom level when the pdf viewer is
58 * initialized.
58 * @param {number} topToolbarHeight The number of pixels that should initially 59 * @param {number} topToolbarHeight The number of pixels that should initially
59 * be left blank above the document for the toolbar. 60 * be left blank above the document for the toolbar.
60 */ 61 */
61 function Viewport(window, 62 function Viewport(window,
62 sizer, 63 sizer,
63 viewportChangedCallback, 64 viewportChangedCallback,
64 beforeZoomCallback, 65 beforeZoomCallback,
65 afterZoomCallback, 66 afterZoomCallback,
66 scrollbarWidth, 67 scrollbarWidth,
67 defaultZoom, 68 initialZoom,
68 topToolbarHeight) { 69 topToolbarHeight) {
69 this.window_ = window; 70 this.window_ = window;
70 this.sizer_ = sizer; 71 this.sizer_ = sizer;
71 this.viewportChangedCallback_ = viewportChangedCallback; 72 this.viewportChangedCallback_ = viewportChangedCallback;
72 this.beforeZoomCallback_ = beforeZoomCallback; 73 this.beforeZoomCallback_ = beforeZoomCallback;
73 this.afterZoomCallback_ = afterZoomCallback; 74 this.afterZoomCallback_ = afterZoomCallback;
74 this.allowedToChangeZoom_ = false; 75 this.allowedToChangeZoom_ = false;
75 this.zoom_ = 1; 76 this.zoom_ = 1;
76 this.documentDimensions_ = null; 77 this.documentDimensions_ = null;
77 this.pageDimensions_ = []; 78 this.pageDimensions_ = [];
78 this.scrollbarWidth_ = scrollbarWidth; 79 this.scrollbarWidth_ = scrollbarWidth;
79 this.fittingType_ = Viewport.FittingType.NONE; 80 this.fittingType_ = Viewport.FittingType.NONE;
80 this.defaultZoom_ = defaultZoom; 81 this.initialZoom_ = initialZoom;
81 this.topToolbarHeight_ = topToolbarHeight; 82 this.topToolbarHeight_ = topToolbarHeight;
82 this.prevScale_ = 1; 83 this.prevScale_ = 1;
83 this.pinchPhase_ = Viewport.PinchPhase.PINCH_NONE; 84 this.pinchPhase_ = Viewport.PinchPhase.PINCH_NONE;
84 this.pinchPanVector_ = null; 85 this.pinchPanVector_ = null;
85 this.pinchCenter_ = null; 86 this.pinchCenter_ = null;
86 this.firstPinchCenterInFrame_ = null; 87 this.firstPinchCenterInFrame_ = null;
87 88
88 window.addEventListener('scroll', this.updateViewport_.bind(this)); 89 window.addEventListener('scroll', this.updateViewport_.bind(this));
89 window.addEventListener('resize', this.resize_.bind(this)); 90 window.addEventListener('resize', this.resize_.bind(this));
90 } 91 }
(...skipping 630 matching lines...) Expand 10 before | Expand all | Expand 10 after
721 * Set the dimensions of the document. 722 * Set the dimensions of the document.
722 * @param {Object} documentDimensions the dimensions of the document 723 * @param {Object} documentDimensions the dimensions of the document
723 */ 724 */
724 setDocumentDimensions: function(documentDimensions) { 725 setDocumentDimensions: function(documentDimensions) {
725 this.mightZoom_(function() { 726 this.mightZoom_(function() {
726 var initialDimensions = !this.documentDimensions_; 727 var initialDimensions = !this.documentDimensions_;
727 this.documentDimensions_ = documentDimensions; 728 this.documentDimensions_ = documentDimensions;
728 this.pageDimensions_ = this.documentDimensions_.pageDimensions; 729 this.pageDimensions_ = this.documentDimensions_.pageDimensions;
729 if (initialDimensions) { 730 if (initialDimensions) {
730 this.setZoomInternal_( 731 this.setZoomInternal_(
731 Math.min(this.defaultZoom_, 732 Math.min(this.initialZoom_,
732 this.computeFittingZoom_(this.documentDimensions_, true))); 733 this.computeFittingZoom_(this.documentDimensions_, true)));
733 this.position = { 734 this.position = {
734 x: 0, 735 x: 0,
735 y: -this.topToolbarHeight_ 736 y: -this.topToolbarHeight_
736 }; 737 };
737 } 738 }
738 this.contentSizeChanged_(); 739 this.contentSizeChanged_();
739 this.resize_(); 740 this.resize_();
740 }.bind(this)); 741 }.bind(this));
741 }, 742 },
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
782 spaceOnLeft = Math.max(spaceOnLeft, 0); 783 spaceOnLeft = Math.max(spaceOnLeft, 0);
783 784
784 return { 785 return {
785 x: x * this.zoom_ + spaceOnLeft - this.window_.pageXOffset, 786 x: x * this.zoom_ + spaceOnLeft - this.window_.pageXOffset,
786 y: insetDimensions.y * this.zoom_ - this.window_.pageYOffset, 787 y: insetDimensions.y * this.zoom_ - this.window_.pageYOffset,
787 width: insetDimensions.width * this.zoom_, 788 width: insetDimensions.width * this.zoom_,
788 height: insetDimensions.height * this.zoom_ 789 height: insetDimensions.height * this.zoom_
789 }; 790 };
790 } 791 }
791 }; 792 };
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698