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_) | |
Nikhil
2014/08/29 10:31:47
Should this be a part of this CL or a separate one
raymes
2014/09/01 01:04:58
It's fine to keep it here.
Nikhil
2014/09/01 09:11:44
Acknowledged.
| |
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 var currentPosition = this.viewport_.position; | |
286 var destinationPosition = {}; | |
287 destinationPosition['x'] = currentPosition.x + this.urlParams_.position.x; | |
288 destinationPosition['y'] = currentPosition.y + this.urlParams_.position.y; | |
raymes
2014/09/01 01:04:58
Is this the way that adobe reader works (does it a
Nikhil
2014/09/01 09:11:44
Please consider the following use case -
example.c
raymes
2014/09/02 03:27:36
The way you have written it looks fine. But I thin
| |
289 this.viewport_.position = destinationPosition; | |
290 } | |
291 if (this.urlParams_.zoom) | |
292 this.viewport_.setZoom(this.urlParams_.zoom); | |
293 }, | |
294 | |
295 /** | |
296 * @private | |
273 * Update the loading progress of the document in response to a progress | 297 * Update the loading progress of the document in response to a progress |
274 * message being received from the plugin. | 298 * message being received from the plugin. |
275 * @param {number} progress the progress as a percentage. | 299 * @param {number} progress the progress as a percentage. |
276 */ | 300 */ |
277 updateProgress_: function(progress) { | 301 updateProgress_: function(progress) { |
278 this.progressBar_.progress = progress; | 302 this.progressBar_.progress = progress; |
279 if (progress == -1) { | 303 if (progress == -1) { |
280 // Document load failed. | 304 // Document load failed. |
281 this.errorScreen_.style.visibility = 'visible'; | 305 this.errorScreen_.style.visibility = 'visible'; |
282 this.sizer_.style.display = 'none'; | 306 this.sizer_.style.display = 'none'; |
283 this.toolbar_.style.visibility = 'hidden'; | 307 this.toolbar_.style.visibility = 'hidden'; |
284 if (this.passwordScreen_.active) { | 308 if (this.passwordScreen_.active) { |
285 this.passwordScreen_.deny(); | 309 this.passwordScreen_.deny(); |
286 this.passwordScreen_.active = false; | 310 this.passwordScreen_.active = false; |
287 } | 311 } |
288 } else if (progress == 100) { | 312 } else if (progress == 100) { |
289 // Document load complete. | 313 // Document load complete. |
314 if (this.lastViewportPosition_) | |
315 this.viewport_.position = this.lastViewportPosition_; | |
316 this.handleURLParams_(); | |
290 this.loaded = true; | 317 this.loaded = true; |
291 var loadEvent = new Event('pdfload'); | 318 var loadEvent = new Event('pdfload'); |
292 window.dispatchEvent(loadEvent); | 319 window.dispatchEvent(loadEvent); |
293 this.sendScriptingMessage_({ | 320 this.sendScriptingMessage_({ |
294 type: 'documentLoaded' | 321 type: 'documentLoaded' |
295 }); | 322 }); |
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 } | 323 } |
304 }, | 324 }, |
305 | 325 |
306 /** | 326 /** |
307 * @private | 327 * @private |
308 * An event handler for handling password-submitted events. These are fired | 328 * An event handler for handling password-submitted events. These are fired |
309 * when an event is entered into the password screen. | 329 * when an event is entered into the password screen. |
310 * @param {Object} event a password-submitted event. | 330 * @param {Object} event a password-submitted event. |
311 */ | 331 */ |
312 onPasswordSubmitted_: function(event) { | 332 onPasswordSubmitted_: function(event) { |
(...skipping 236 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
549 | 569 |
550 /** | 570 /** |
551 * @type {Viewport} the viewport of the PDF viewer. | 571 * @type {Viewport} the viewport of the PDF viewer. |
552 */ | 572 */ |
553 get viewport() { | 573 get viewport() { |
554 return this.viewport_; | 574 return this.viewport_; |
555 } | 575 } |
556 }; | 576 }; |
557 | 577 |
558 var viewer = new PDFViewer(); | 578 var viewer = new PDFViewer(); |
OLD | NEW |