OLD | NEW |
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 <include src="../../../../ui/webui/resources/js/util.js"> | 7 <include src="../../../../ui/webui/resources/js/util.js"> |
8 <include src="open_pdf_params_parser.js"> | 8 <include src="open_pdf_params_parser.js"> |
9 <include src="pdf_scripting_api.js"> | 9 <include src="pdf_scripting_api.js"> |
10 <include src="viewport.js"> | 10 <include src="viewport.js"> |
(...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
140 if (chrome.tabs) { | 140 if (chrome.tabs) { |
141 chrome.tabs.setZoomSettings({mode: 'manual', scope: 'per-tab'}, | 141 chrome.tabs.setZoomSettings({mode: 'manual', scope: 'per-tab'}, |
142 this.afterZoom_.bind(this)); | 142 this.afterZoom_.bind(this)); |
143 chrome.tabs.onZoomChange.addListener(function(zoomChangeInfo) { | 143 chrome.tabs.onZoomChange.addListener(function(zoomChangeInfo) { |
144 // If the zoom level is close enough to the current zoom level, don't | 144 // If the zoom level is close enough to the current zoom level, don't |
145 // change it. This avoids us getting into an infinite loop of zoom changes | 145 // change it. This avoids us getting into an infinite loop of zoom changes |
146 // due to floating point error. | 146 // due to floating point error. |
147 var MIN_ZOOM_DELTA = 0.01; | 147 var MIN_ZOOM_DELTA = 0.01; |
148 var zoomDelta = Math.abs(this.viewport_.zoom - | 148 var zoomDelta = Math.abs(this.viewport_.zoom - |
149 zoomChangeInfo.newZoomFactor); | 149 zoomChangeInfo.newZoomFactor); |
150 if (zoomDelta > MIN_ZOOM_DELTA) | 150 // We should not change zoom level when we are responsible for initiating |
| 151 // the zoom. onZoomChange() is called before setZoomComplete() callback |
| 152 // when we initiate the zoom. |
| 153 if ((zoomDelta > MIN_ZOOM_DELTA) && !this.setZoomInProgress_) |
151 this.viewport_.setZoom(zoomChangeInfo.newZoomFactor); | 154 this.viewport_.setZoom(zoomChangeInfo.newZoomFactor); |
152 }.bind(this)); | 155 }.bind(this)); |
153 } | 156 } |
154 | 157 |
155 // Parse open pdf parameters. | 158 // Parse open pdf parameters. |
156 var paramsParser = new OpenPDFParamsParser(this.streamDetails.originalUrl); | 159 var paramsParser = new OpenPDFParamsParser(this.streamDetails.originalUrl); |
157 this.urlParams_ = paramsParser.urlParams; | 160 this.urlParams_ = paramsParser.urlParams; |
158 } | 161 } |
159 | 162 |
160 PDFViewer.prototype = { | 163 PDFViewer.prototype = { |
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
263 * Notify the plugin to print. | 266 * Notify the plugin to print. |
264 */ | 267 */ |
265 print_: function() { | 268 print_: function() { |
266 this.plugin_.postMessage({ | 269 this.plugin_.postMessage({ |
267 type: 'print', | 270 type: 'print', |
268 }); | 271 }); |
269 }, | 272 }, |
270 | 273 |
271 /** | 274 /** |
272 * @private | 275 * @private |
| 276 * Handle open pdf parameters. This function updates the viewport as per |
| 277 * the parameters mentioned in the url while opening pdf. The order is |
| 278 * important as later actions can override the effects of previous actions. |
| 279 */ |
| 280 handleURLParams_: function() { |
| 281 if (this.urlParams_.page) |
| 282 this.viewport_.goToPage(this.urlParams_.page); |
| 283 if (this.urlParams_.position) { |
| 284 // Make sure we don't cancel effect of page parameter. |
| 285 this.viewport_.position = { |
| 286 x: this.viewport_.position.x + this.urlParams_.position.x, |
| 287 y: this.viewport_.position.y + this.urlParams_.position.y |
| 288 }; |
| 289 } |
| 290 if (this.urlParams_.zoom) |
| 291 this.viewport_.setZoom(this.urlParams_.zoom); |
| 292 }, |
| 293 |
| 294 /** |
| 295 * @private |
273 * Update the loading progress of the document in response to a progress | 296 * Update the loading progress of the document in response to a progress |
274 * message being received from the plugin. | 297 * message being received from the plugin. |
275 * @param {number} progress the progress as a percentage. | 298 * @param {number} progress the progress as a percentage. |
276 */ | 299 */ |
277 updateProgress_: function(progress) { | 300 updateProgress_: function(progress) { |
278 this.progressBar_.progress = progress; | 301 this.progressBar_.progress = progress; |
279 if (progress == -1) { | 302 if (progress == -1) { |
280 // Document load failed. | 303 // Document load failed. |
281 this.errorScreen_.style.visibility = 'visible'; | 304 this.errorScreen_.style.visibility = 'visible'; |
282 this.sizer_.style.display = 'none'; | 305 this.sizer_.style.display = 'none'; |
283 this.toolbar_.style.visibility = 'hidden'; | 306 this.toolbar_.style.visibility = 'hidden'; |
284 if (this.passwordScreen_.active) { | 307 if (this.passwordScreen_.active) { |
285 this.passwordScreen_.deny(); | 308 this.passwordScreen_.deny(); |
286 this.passwordScreen_.active = false; | 309 this.passwordScreen_.active = false; |
287 } | 310 } |
288 } else if (progress == 100) { | 311 } else if (progress == 100) { |
289 // Document load complete. | 312 // Document load complete. |
| 313 if (this.lastViewportPosition_) |
| 314 this.viewport_.position = this.lastViewportPosition_; |
| 315 this.handleURLParams_(); |
290 this.loaded = true; | 316 this.loaded = true; |
291 var loadEvent = new Event('pdfload'); | 317 var loadEvent = new Event('pdfload'); |
292 window.dispatchEvent(loadEvent); | 318 window.dispatchEvent(loadEvent); |
293 this.sendScriptingMessage_({ | 319 this.sendScriptingMessage_({ |
294 type: 'documentLoaded' | 320 type: 'documentLoaded' |
295 }); | 321 }); |
296 if (this.lastViewportPosition_) | |
297 this.viewport_.position = this.lastViewportPosition_; | |
298 | |
299 // Handle open pdf params. Order is important as later actions can | |
300 // override the effects of previous actions. | |
301 if (this.urlParams_.page) | |
302 this.viewport_.goToPage(this.urlParams_.page); | |
303 } | 322 } |
304 }, | 323 }, |
305 | 324 |
306 /** | 325 /** |
307 * @private | 326 * @private |
308 * An event handler for handling password-submitted events. These are fired | 327 * An event handler for handling password-submitted events. These are fired |
309 * when an event is entered into the password screen. | 328 * when an event is entered into the password screen. |
310 * @param {Object} event a password-submitted event. | 329 * @param {Object} event a password-submitted event. |
311 */ | 330 */ |
312 onPasswordSubmitted_: function(event) { | 331 onPasswordSubmitted_: function(event) { |
(...skipping 236 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
549 | 568 |
550 /** | 569 /** |
551 * @type {Viewport} the viewport of the PDF viewer. | 570 * @type {Viewport} the viewport of the PDF viewer. |
552 */ | 571 */ |
553 get viewport() { | 572 get viewport() { |
554 return this.viewport_; | 573 return this.viewport_; |
555 } | 574 } |
556 }; | 575 }; |
557 | 576 |
558 var viewer = new PDFViewer(); | 577 var viewer = new PDFViewer(); |
OLD | NEW |