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="pdf_open_params_parser.js"> | |
raymes
2014/08/27 01:02:24
nit: can we call this file open_pdf_params_parser.
Nikhil
2014/08/27 10:16:09
Done.
| |
8 <include src="pdf_scripting_api.js"> | 9 <include src="pdf_scripting_api.js"> |
9 <include src="viewport.js"> | 10 <include src="viewport.js"> |
10 | 11 |
11 /** | 12 /** |
12 * @return {number} Width of a scrollbar in pixels | 13 * @return {number} Width of a scrollbar in pixels |
13 */ | 14 */ |
14 function getScrollbarWidth() { | 15 function getScrollbarWidth() { |
15 var div = document.createElement('div'); | 16 var div = document.createElement('div'); |
16 div.style.visibility = 'hidden'; | 17 div.style.visibility = 'hidden'; |
17 div.style.overflow = 'scroll'; | 18 div.style.overflow = 'scroll'; |
(...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
143 // 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 |
144 // 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 |
145 // due to floating point error. | 146 // due to floating point error. |
146 var MIN_ZOOM_DELTA = 0.01; | 147 var MIN_ZOOM_DELTA = 0.01; |
147 var zoomDelta = Math.abs(this.viewport_.zoom - | 148 var zoomDelta = Math.abs(this.viewport_.zoom - |
148 zoomChangeInfo.newZoomFactor); | 149 zoomChangeInfo.newZoomFactor); |
149 if (zoomDelta > MIN_ZOOM_DELTA) | 150 if (zoomDelta > MIN_ZOOM_DELTA) |
150 this.viewport_.setZoom(zoomChangeInfo.newZoomFactor); | 151 this.viewport_.setZoom(zoomChangeInfo.newZoomFactor); |
151 }.bind(this)); | 152 }.bind(this)); |
152 } | 153 } |
154 | |
155 // Handle open pdf parameters. | |
156 var paramsParser = new OpenPDFParamsParser(this.streamDetails.originalUrl); | |
157 this.viewport_.initialViewportSettings = paramsParser.viewportSettings; | |
153 } | 158 } |
154 | 159 |
155 PDFViewer.prototype = { | 160 PDFViewer.prototype = { |
156 /** | 161 /** |
157 * @private | 162 * @private |
158 * Handle key events. These may come from the user directly or via the | 163 * Handle key events. These may come from the user directly or via the |
159 * scripting API. | 164 * scripting API. |
160 * @param {KeyboardEvent} e the event to handle. | 165 * @param {KeyboardEvent} e the event to handle. |
161 */ | 166 */ |
162 handleKeyEvent_: function(e) { | 167 handleKeyEvent_: function(e) { |
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
258 * Notify the plugin to print. | 263 * Notify the plugin to print. |
259 */ | 264 */ |
260 print_: function() { | 265 print_: function() { |
261 this.plugin_.postMessage({ | 266 this.plugin_.postMessage({ |
262 type: 'print', | 267 type: 'print', |
263 }); | 268 }); |
264 }, | 269 }, |
265 | 270 |
266 /** | 271 /** |
267 * @private | 272 * @private |
268 * Handle open PDF parameters. These parameters are mentioned in the URL | |
269 * and specify actions to be performed when opening PDF files. | |
270 * See http://crbug.com/64309 for details. | |
271 */ | |
272 handleOpenPDFParams_: function() { | |
273 var originalUrl = this.streamDetails.originalUrl; | |
274 var paramIndex = originalUrl.search('#'); | |
275 if (paramIndex == -1) | |
276 return; | |
277 | |
278 var paramTokens = originalUrl.substring(paramIndex + 1).split('&'); | |
279 var paramsDictionary = {}; | |
280 for (var i = 0; i < paramTokens.length; ++i) { | |
281 var keyValueSplit = paramTokens[i].split('='); | |
282 if (keyValueSplit.length != 2) | |
283 continue; | |
284 paramsDictionary[keyValueSplit[0]] = keyValueSplit[1]; | |
285 } | |
286 | |
287 // Order is important as later actions can override the effects | |
288 // of previous actions. | |
289 if ('page' in paramsDictionary) { | |
290 // |pageNumber| is 1-based, but goToPage() take a zero-based page number. | |
291 var pageNumber = parseInt(paramsDictionary['page']); | |
292 if (!isNaN(pageNumber)) | |
293 this.viewport_.goToPage(pageNumber - 1); | |
294 } | |
295 }, | |
296 | |
297 /** | |
298 * @private | |
299 * Update the loading progress of the document in response to a progress | 273 * Update the loading progress of the document in response to a progress |
300 * message being received from the plugin. | 274 * message being received from the plugin. |
301 * @param {number} progress the progress as a percentage. | 275 * @param {number} progress the progress as a percentage. |
302 */ | 276 */ |
303 updateProgress_: function(progress) { | 277 updateProgress_: function(progress) { |
304 this.progressBar_.progress = progress; | 278 this.progressBar_.progress = progress; |
305 if (progress == -1) { | 279 if (progress == -1) { |
306 // Document load failed. | 280 // Document load failed. |
307 this.errorScreen_.style.visibility = 'visible'; | 281 this.errorScreen_.style.visibility = 'visible'; |
308 this.sizer_.style.display = 'none'; | 282 this.sizer_.style.display = 'none'; |
309 this.toolbar_.style.visibility = 'hidden'; | 283 this.toolbar_.style.visibility = 'hidden'; |
310 if (this.passwordScreen_.active) { | 284 if (this.passwordScreen_.active) { |
311 this.passwordScreen_.deny(); | 285 this.passwordScreen_.deny(); |
312 this.passwordScreen_.active = false; | 286 this.passwordScreen_.active = false; |
313 } | 287 } |
314 } else if (progress == 100) { | 288 } else if (progress == 100) { |
315 // Document load complete. | 289 // Document load complete. |
316 this.handleOpenPDFParams_(); | |
317 this.loaded = true; | 290 this.loaded = true; |
318 var loadEvent = new Event('pdfload'); | 291 var loadEvent = new Event('pdfload'); |
319 window.dispatchEvent(loadEvent); | 292 window.dispatchEvent(loadEvent); |
320 this.sendScriptingMessage_({ | 293 this.sendScriptingMessage_({ |
321 type: 'documentLoaded' | 294 type: 'documentLoaded' |
322 }); | 295 }); |
323 if (this.lastViewportPosition_) | 296 if (this.lastViewportPosition_) |
324 this.viewport_.position = this.lastViewportPosition_; | 297 this.viewport_.position = this.lastViewportPosition_; |
325 } | 298 } |
326 }, | 299 }, |
(...skipping 244 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
571 | 544 |
572 /** | 545 /** |
573 * @type {Viewport} the viewport of the PDF viewer. | 546 * @type {Viewport} the viewport of the PDF viewer. |
574 */ | 547 */ |
575 get viewport() { | 548 get viewport() { |
576 return this.viewport_; | 549 return this.viewport_; |
577 } | 550 } |
578 }; | 551 }; |
579 | 552 |
580 var viewer = new PDFViewer(); | 553 var viewer = new PDFViewer(); |
OLD | NEW |