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

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

Issue 1026223002: OOP PDF: Do not call setZoom in response to an onZoomChange event. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 8 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
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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 'use strict'; 5 'use strict';
6 6
7 /** 7 /**
8 * @return {number} Width of a scrollbar in pixels 8 * @return {number} Width of a scrollbar in pixels
9 */ 9 */
10 function getScrollbarWidth() { 10 function getScrollbarWidth() {
(...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after
169 }.bind(this)); 169 }.bind(this));
170 170
171 document.body.addEventListener('change-page', function(e) { 171 document.body.addEventListener('change-page', function(e) {
172 this.viewport_.goToPage(e.detail.page); 172 this.viewport_.goToPage(e.detail.page);
173 }.bind(this)); 173 }.bind(this));
174 174
175 this.uiManager_ = new UiManager(window, this.materialToolbar_, 175 this.uiManager_ = new UiManager(window, this.materialToolbar_,
176 [this.bookmarksPane_]); 176 [this.bookmarksPane_]);
177 } 177 }
178 178
179 // Set up the zoom API.
180 if (this.shouldManageZoom_()) {
181 chrome.tabs.setZoomSettings(this.streamDetails_.tabId,
182 {mode: 'manual', scope: 'per-tab'}, function() {
183 this.zoomManager_ =
184 new ZoomManager(this.viewport_, this.setZoom_.bind(this));
185 chrome.tabs.onZoomChange.addListener(function(zoomChangeInfo) {
186 if (zoomChangeInfo.tabId != this.streamDetails_.tabId)
187 return;
188 this.zoomManager_.onBrowserZoomChange(zoomChangeInfo.newZoomFactor);
189 }.bind(this));
190 }.bind(this));
191 }
192
179 // Setup the keyboard event listener. 193 // Setup the keyboard event listener.
180 document.onkeydown = this.handleKeyEvent_.bind(this); 194 document.onkeydown = this.handleKeyEvent_.bind(this);
181 195
182 // Set up the zoom API.
183 if (this.shouldManageZoom_()) {
184 chrome.tabs.setZoomSettings(this.streamDetails_.tabId,
185 {mode: 'manual', scope: 'per-tab'},
186 this.afterZoom_.bind(this));
187 chrome.tabs.onZoomChange.addListener(function(zoomChangeInfo) {
188 if (zoomChangeInfo.tabId != this.streamDetails_.tabId)
189 return;
190 // If the zoom level is close enough to the current zoom level, don't
191 // change it. This avoids us getting into an infinite loop of zoom changes
192 // due to floating point error.
193 var MIN_ZOOM_DELTA = 0.01;
194 var zoomDelta = Math.abs(this.viewport_.zoom -
195 zoomChangeInfo.newZoomFactor);
196 // We should not change zoom level when we are responsible for initiating
197 // the zoom. onZoomChange() is called before setZoomComplete() callback
198 // when we initiate the zoom.
199 if ((zoomDelta > MIN_ZOOM_DELTA) && !this.setZoomInProgress_)
200 this.viewport_.setZoom(zoomChangeInfo.newZoomFactor);
201 }.bind(this));
202 }
203
204 // Parse open pdf parameters. 196 // Parse open pdf parameters.
205 this.paramsParser_ = 197 this.paramsParser_ =
206 new OpenPDFParamsParser(this.getNamedDestination_.bind(this)); 198 new OpenPDFParamsParser(this.getNamedDestination_.bind(this));
207 this.navigator_ = new Navigator(this.streamDetails_.originalUrl, 199 this.navigator_ = new Navigator(this.streamDetails_.originalUrl,
208 this.viewport_, this.paramsParser_, 200 this.viewport_, this.paramsParser_,
209 onNavigateInCurrentTab, onNavigateInNewTab); 201 onNavigateInCurrentTab, onNavigateInNewTab);
210 this.viewportScroller_ = 202 this.viewportScroller_ =
211 new ViewportScroller(this.viewport_, this.plugin_, window); 203 new ViewportScroller(this.viewport_, this.plugin_, window);
212 } 204 }
213 205
(...skipping 260 matching lines...) Expand 10 before | Expand all | Expand 10 after
474 if (this.passwordScreen_.active) 466 if (this.passwordScreen_.active)
475 this.passwordScreen_.accept(); 467 this.passwordScreen_.accept();
476 468
477 if (this.isMaterial_) { 469 if (this.isMaterial_) {
478 this.materialToolbar_.docLength = 470 this.materialToolbar_.docLength =
479 this.documentDimensions_.pageDimensions.length; 471 this.documentDimensions_.pageDimensions.length;
480 } else { 472 } else {
481 this.pageIndicator_.initialFadeIn(); 473 this.pageIndicator_.initialFadeIn();
482 this.toolbar_.initialFadeIn(); 474 this.toolbar_.initialFadeIn();
483 } 475 }
484
485 break; 476 break;
486 case 'email': 477 case 'email':
487 var href = 'mailto:' + message.data.to + '?cc=' + message.data.cc + 478 var href = 'mailto:' + message.data.to + '?cc=' + message.data.cc +
488 '&bcc=' + message.data.bcc + '&subject=' + message.data.subject + 479 '&bcc=' + message.data.bcc + '&subject=' + message.data.subject +
489 '&body=' + message.data.body; 480 '&body=' + message.data.body;
490 window.location.href = href; 481 window.location.href = href;
491 break; 482 break;
492 case 'getAccessibilityJSONReply': 483 case 'getAccessibilityJSONReply':
493 this.sendScriptingMessage_(message.data); 484 this.sendScriptingMessage_(message.data);
494 break; 485 break;
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
567 /** 558 /**
568 * @private 559 * @private
569 * A callback that's called after the zoom changes. Notify the plugin of the 560 * A callback that's called after the zoom changes. Notify the plugin of the
570 * zoom change and to continue reacting to scroll events. 561 * zoom change and to continue reacting to scroll events.
571 */ 562 */
572 afterZoom_: function() { 563 afterZoom_: function() {
573 var position = this.viewport_.position; 564 var position = this.viewport_.position;
574 var zoom = this.viewport_.zoom; 565 var zoom = this.viewport_.zoom;
575 if (this.isMaterial_) 566 if (this.isMaterial_)
576 this.zoomSelector_.zoomValue = 100 * zoom; 567 this.zoomSelector_.zoomValue = 100 * zoom;
577 if (this.shouldManageZoom_() && !this.setZoomInProgress_) {
578 this.setZoomInProgress_ = true;
579 chrome.tabs.setZoom(this.streamDetails_.tabId, zoom,
580 this.setZoomComplete_.bind(this, zoom));
581 }
582 this.plugin_.postMessage({ 568 this.plugin_.postMessage({
583 type: 'viewport', 569 type: 'viewport',
584 zoom: zoom, 570 zoom: zoom,
585 xOffset: position.x, 571 xOffset: position.x,
586 yOffset: position.y 572 yOffset: position.y
587 }); 573 });
574 if (this.zoomManager_)
575 this.zoomManager_.onPdfZoomChange();
576 },
577
578 setZoom_: function(zoom) {
579 return new Promise(function(resolve, reject) {
580 chrome.tabs.setZoom(this.streamDetails_.tabId, zoom, resolve);
581 }.bind(this));
588 }, 582 },
589 583
590 /** 584 /**
591 * @private
592 * A callback that's called after chrome.tabs.setZoom is complete. This will
593 * call chrome.tabs.setZoom again if the zoom level has changed since it was
594 * last called.
595 * @param {number} lastZoom the zoom level that chrome.tabs.setZoom was called
596 * with.
597 */
598 setZoomComplete_: function(lastZoom) {
599 var zoom = this.viewport_.zoom;
600 if (zoom !== lastZoom) {
601 chrome.tabs.setZoom(this.streamDetails_.tabId, zoom,
602 this.setZoomComplete_.bind(this, zoom));
603 } else {
604 this.setZoomInProgress_ = false;
605 }
606 },
607
608 /**
609 * @private 585 * @private
610 * A callback that's called after the viewport changes. 586 * A callback that's called after the viewport changes.
611 */ 587 */
612 viewportChanged_: function() { 588 viewportChanged_: function() {
613 if (!this.documentDimensions_) 589 if (!this.documentDimensions_)
614 return; 590 return;
615 591
616 // Update the buttons selected. 592 // Update the buttons selected.
617 if (!this.isMaterial_) { 593 if (!this.isMaterial_) {
618 $('fit-to-page-button').classList.remove('polymer-selected'); 594 $('fit-to-page-button').classList.remove('polymer-selected');
(...skipping 176 matching lines...) Expand 10 before | Expand all | Expand 10 after
795 * Each bookmark is an Object containing a: 771 * Each bookmark is an Object containing a:
796 * - title 772 * - title
797 * - page (optional) 773 * - page (optional)
798 * - array of children (themselves bookmarks) 774 * - array of children (themselves bookmarks)
799 * @type {Array} the top-level bookmarks of the PDF. 775 * @type {Array} the top-level bookmarks of the PDF.
800 */ 776 */
801 get bookmarks() { 777 get bookmarks() {
802 return this.bookmarks_; 778 return this.bookmarks_;
803 } 779 }
804 }; 780 };
OLDNEW
« no previous file with comments | « chrome/browser/resources/pdf/index-material.html ('k') | chrome/browser/resources/pdf/zoom_manager.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698