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

Unified 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 side-by-side diff with in-line comments
Download patch
« 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 »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/resources/pdf/pdf.js
diff --git a/chrome/browser/resources/pdf/pdf.js b/chrome/browser/resources/pdf/pdf.js
index 4fae2314f21249cabd43d70200848ed67a8c3011..47baecdd3ed758d40d255f38ea9bca3d326b592a 100644
--- a/chrome/browser/resources/pdf/pdf.js
+++ b/chrome/browser/resources/pdf/pdf.js
@@ -176,31 +176,23 @@ function PDFViewer(streamDetails) {
[this.bookmarksPane_]);
}
- // Setup the keyboard event listener.
- document.onkeydown = this.handleKeyEvent_.bind(this);
-
// Set up the zoom API.
if (this.shouldManageZoom_()) {
chrome.tabs.setZoomSettings(this.streamDetails_.tabId,
- {mode: 'manual', scope: 'per-tab'},
- this.afterZoom_.bind(this));
- chrome.tabs.onZoomChange.addListener(function(zoomChangeInfo) {
- if (zoomChangeInfo.tabId != this.streamDetails_.tabId)
- return;
- // If the zoom level is close enough to the current zoom level, don't
- // change it. This avoids us getting into an infinite loop of zoom changes
- // due to floating point error.
- var MIN_ZOOM_DELTA = 0.01;
- var zoomDelta = Math.abs(this.viewport_.zoom -
- zoomChangeInfo.newZoomFactor);
- // We should not change zoom level when we are responsible for initiating
- // the zoom. onZoomChange() is called before setZoomComplete() callback
- // when we initiate the zoom.
- if ((zoomDelta > MIN_ZOOM_DELTA) && !this.setZoomInProgress_)
- this.viewport_.setZoom(zoomChangeInfo.newZoomFactor);
+ {mode: 'manual', scope: 'per-tab'}, function() {
+ this.zoomManager_ =
+ new ZoomManager(this.viewport_, this.setZoom_.bind(this));
+ chrome.tabs.onZoomChange.addListener(function(zoomChangeInfo) {
+ if (zoomChangeInfo.tabId != this.streamDetails_.tabId)
+ return;
+ this.zoomManager_.onBrowserZoomChange(zoomChangeInfo.newZoomFactor);
+ }.bind(this));
}.bind(this));
}
+ // Setup the keyboard event listener.
+ document.onkeydown = this.handleKeyEvent_.bind(this);
+
// Parse open pdf parameters.
this.paramsParser_ =
new OpenPDFParamsParser(this.getNamedDestination_.bind(this));
@@ -481,7 +473,6 @@ PDFViewer.prototype = {
this.pageIndicator_.initialFadeIn();
this.toolbar_.initialFadeIn();
}
-
break;
case 'email':
var href = 'mailto:' + message.data.to + '?cc=' + message.data.cc +
@@ -574,35 +565,20 @@ PDFViewer.prototype = {
var zoom = this.viewport_.zoom;
if (this.isMaterial_)
this.zoomSelector_.zoomValue = 100 * zoom;
- if (this.shouldManageZoom_() && !this.setZoomInProgress_) {
- this.setZoomInProgress_ = true;
- chrome.tabs.setZoom(this.streamDetails_.tabId, zoom,
- this.setZoomComplete_.bind(this, zoom));
- }
this.plugin_.postMessage({
type: 'viewport',
zoom: zoom,
xOffset: position.x,
yOffset: position.y
});
+ if (this.zoomManager_)
+ this.zoomManager_.onPdfZoomChange();
},
- /**
- * @private
- * A callback that's called after chrome.tabs.setZoom is complete. This will
- * call chrome.tabs.setZoom again if the zoom level has changed since it was
- * last called.
- * @param {number} lastZoom the zoom level that chrome.tabs.setZoom was called
- * with.
- */
- setZoomComplete_: function(lastZoom) {
- var zoom = this.viewport_.zoom;
- if (zoom !== lastZoom) {
- chrome.tabs.setZoom(this.streamDetails_.tabId, zoom,
- this.setZoomComplete_.bind(this, zoom));
- } else {
- this.setZoomInProgress_ = false;
- }
+ setZoom_: function(zoom) {
+ return new Promise(function(resolve, reject) {
+ chrome.tabs.setZoom(this.streamDetails_.tabId, zoom, resolve);
+ }.bind(this));
},
/**
« 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