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 /** | 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 172 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
183 zoomChangeInfo.newZoomFactor); | 183 zoomChangeInfo.newZoomFactor); |
184 // We should not change zoom level when we are responsible for initiating | 184 // We should not change zoom level when we are responsible for initiating |
185 // the zoom. onZoomChange() is called before setZoomComplete() callback | 185 // the zoom. onZoomChange() is called before setZoomComplete() callback |
186 // when we initiate the zoom. | 186 // when we initiate the zoom. |
187 if ((zoomDelta > MIN_ZOOM_DELTA) && !this.setZoomInProgress_) | 187 if ((zoomDelta > MIN_ZOOM_DELTA) && !this.setZoomInProgress_) |
188 this.viewport_.setZoom(zoomChangeInfo.newZoomFactor); | 188 this.viewport_.setZoom(zoomChangeInfo.newZoomFactor); |
189 }.bind(this)); | 189 }.bind(this)); |
190 } | 190 } |
191 | 191 |
192 // Parse open pdf parameters. | 192 // Parse open pdf parameters. |
193 this.paramsParser_ = new OpenPDFParamsParser(); | 193 this.paramsParser_ = |
| 194 new OpenPDFParamsParser(this.getNamedDestination_.bind(this)); |
194 this.navigator_ = new Navigator(this.streamDetails_.originalUrl, | 195 this.navigator_ = new Navigator(this.streamDetails_.originalUrl, |
195 this.viewport_, this.paramsParser_, onNavigateInCurrentTab, | 196 this.viewport_, this.paramsParser_, |
196 onNavigateInNewTab); | 197 onNavigateInCurrentTab, onNavigateInNewTab); |
197 this.viewportScroller_ = | 198 this.viewportScroller_ = |
198 new ViewportScroller(this.viewport_, this.plugin_, window); | 199 new ViewportScroller(this.viewport_, this.plugin_, window); |
199 } | 200 } |
200 | 201 |
201 PDFViewer.prototype = { | 202 PDFViewer.prototype = { |
202 /** | 203 /** |
203 * @private | 204 * @private |
204 * Handle key events. These may come from the user directly or via the | 205 * Handle key events. These may come from the user directly or via the |
205 * scripting API. | 206 * scripting API. |
206 * @param {KeyboardEvent} e the event to handle. | 207 * @param {KeyboardEvent} e the event to handle. |
(...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
343 rotateCounterClockwise_: function() { | 344 rotateCounterClockwise_: function() { |
344 this.plugin_.postMessage({ | 345 this.plugin_.postMessage({ |
345 type: 'rotateCounterclockwise' | 346 type: 'rotateCounterclockwise' |
346 }); | 347 }); |
347 }, | 348 }, |
348 | 349 |
349 /** | 350 /** |
350 * @private | 351 * @private |
351 * Notify the plugin to print. | 352 * Notify the plugin to print. |
352 */ | 353 */ |
353 print_: function() { this.plugin_.postMessage({type: 'print'}); }, | 354 print_: function() { |
| 355 this.plugin_.postMessage({ |
| 356 type: 'print' |
| 357 }); |
| 358 }, |
354 | 359 |
355 /** | 360 /** |
356 * @private | 361 * @private |
357 * Notify the plugin to save. | 362 * Notify the plugin to save. |
358 */ | 363 */ |
359 save_: function() { this.plugin_.postMessage({type: 'save'}); }, | 364 save_: function() { |
| 365 this.plugin_.postMessage({ |
| 366 type: 'save' |
| 367 }); |
| 368 }, |
| 369 |
| 370 /** |
| 371 * Fetches the page number corresponding to the given named destination from |
| 372 * the plugin. |
| 373 * @param {string} name The namedDestination to fetch page number from plugin. |
| 374 */ |
| 375 getNamedDestination_: function(name) { |
| 376 this.plugin_.postMessage({ |
| 377 type: 'getNamedDestination', |
| 378 namedDestination: name |
| 379 }); |
| 380 }, |
360 | 381 |
361 /** | 382 /** |
362 * @private | 383 * @private |
363 * Handle open pdf parameters. This function updates the viewport as per | 384 * Handle open pdf parameters. This function updates the viewport as per |
364 * the parameters mentioned in the url while opening pdf. The order is | 385 * the parameters mentioned in the url while opening pdf. The order is |
365 * important as later actions can override the effects of previous actions. | 386 * important as later actions can override the effects of previous actions. |
| 387 * @param {Object} viewportPosition The initial position of the viewport to be |
| 388 * displayed. |
366 */ | 389 */ |
367 handleURLParams_: function() { | 390 handleURLParams_: function(viewportPosition) { |
368 var urlParams = | 391 if (viewportPosition.page != undefined) |
369 this.paramsParser_.getViewportFromUrlParams( | 392 this.viewport_.goToPage(viewportPosition.page); |
370 this.streamDetails_.originalUrl); | 393 if (viewportPosition.position) { |
371 if (urlParams.page) | |
372 this.viewport_.goToPage(urlParams.page); | |
373 if (urlParams.position) { | |
374 // Make sure we don't cancel effect of page parameter. | 394 // Make sure we don't cancel effect of page parameter. |
375 this.viewport_.position = { | 395 this.viewport_.position = { |
376 x: this.viewport_.position.x + urlParams.position.x, | 396 x: this.viewport_.position.x + viewportPosition.position.x, |
377 y: this.viewport_.position.y + urlParams.position.y | 397 y: this.viewport_.position.y + viewportPosition.position.y |
378 }; | 398 }; |
379 } | 399 } |
380 if (urlParams.zoom) | 400 if (viewportPosition.zoom) |
381 this.viewport_.setZoom(urlParams.zoom); | 401 this.viewport_.setZoom(viewportPosition.zoom); |
382 }, | 402 }, |
383 | 403 |
384 /** | 404 /** |
385 * @private | 405 * @private |
386 * Update the loading progress of the document in response to a progress | 406 * Update the loading progress of the document in response to a progress |
387 * message being received from the plugin. | 407 * message being received from the plugin. |
388 * @param {number} progress the progress as a percentage. | 408 * @param {number} progress the progress as a percentage. |
389 */ | 409 */ |
390 updateProgress_: function(progress) { | 410 updateProgress_: function(progress) { |
391 if (this.isMaterial_) | 411 if (this.isMaterial_) |
392 this.materialToolbar_.loadProgress = progress; | 412 this.materialToolbar_.loadProgress = progress; |
393 else | 413 else |
394 this.progressBar_.progress = progress; | 414 this.progressBar_.progress = progress; |
395 | 415 |
396 if (progress == -1) { | 416 if (progress == -1) { |
397 // Document load failed. | 417 // Document load failed. |
398 this.errorScreen_.style.visibility = 'visible'; | 418 this.errorScreen_.style.visibility = 'visible'; |
399 this.sizer_.style.display = 'none'; | 419 this.sizer_.style.display = 'none'; |
400 this.toolbar_.style.visibility = 'hidden'; | 420 this.toolbar_.style.visibility = 'hidden'; |
401 if (this.passwordScreen_.active) { | 421 if (this.passwordScreen_.active) { |
402 this.passwordScreen_.deny(); | 422 this.passwordScreen_.deny(); |
403 this.passwordScreen_.active = false; | 423 this.passwordScreen_.active = false; |
404 } | 424 } |
405 } else if (progress == 100) { | 425 } else if (progress == 100) { |
406 // Document load complete. | 426 // Document load complete. |
407 if (this.lastViewportPosition_) | 427 if (this.lastViewportPosition_) |
408 this.viewport_.position = this.lastViewportPosition_; | 428 this.viewport_.position = this.lastViewportPosition_; |
409 this.handleURLParams_(); | 429 this.paramsParser_.getViewportFromUrlParams( |
| 430 this.streamDetails_.originalUrl, this.handleURLParams_.bind(this)); |
410 this.loaded_ = true; | 431 this.loaded_ = true; |
411 this.sendScriptingMessage_({ | 432 this.sendScriptingMessage_({ |
412 type: 'documentLoaded' | 433 type: 'documentLoaded' |
413 }); | 434 }); |
414 while (this.delayedScriptingMessages_.length > 0) | 435 while (this.delayedScriptingMessages_.length > 0) |
415 this.handleScriptingMessage(this.delayedScriptingMessages_.shift()); | 436 this.handleScriptingMessage(this.delayedScriptingMessages_.shift()); |
416 } | 437 } |
417 }, | 438 }, |
418 | 439 |
419 /** | 440 /** |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
479 case 'loadProgress': | 500 case 'loadProgress': |
480 this.updateProgress_(message.data.progress); | 501 this.updateProgress_(message.data.progress); |
481 break; | 502 break; |
482 case 'navigate': | 503 case 'navigate': |
483 // If in print preview, always open a new tab. | 504 // If in print preview, always open a new tab. |
484 if (this.isPrintPreview_) | 505 if (this.isPrintPreview_) |
485 this.navigator_.navigate(message.data.url, true); | 506 this.navigator_.navigate(message.data.url, true); |
486 else | 507 else |
487 this.navigator_.navigate(message.data.url, message.data.newTab); | 508 this.navigator_.navigate(message.data.url, message.data.newTab); |
488 break; | 509 break; |
489 case 'setNamedDestinations': | |
490 this.paramsParser_.namedDestinations = message.data.namedDestinations; | |
491 break; | |
492 case 'setScrollPosition': | 510 case 'setScrollPosition': |
493 var position = this.viewport_.position; | 511 var position = this.viewport_.position; |
494 if (message.data.x !== undefined) | 512 if (message.data.x !== undefined) |
495 position.x = message.data.x; | 513 position.x = message.data.x; |
496 if (message.data.y !== undefined) | 514 if (message.data.y !== undefined) |
497 position.y = message.data.y; | 515 position.y = message.data.y; |
498 this.viewport_.position = position; | 516 this.viewport_.position = position; |
499 break; | 517 break; |
500 case 'setTranslatedStrings': | 518 case 'setTranslatedStrings': |
501 this.passwordScreen_.text = message.data.getPasswordString; | 519 this.passwordScreen_.text = message.data.getPasswordString; |
(...skipping 10 matching lines...) Expand all Loading... |
512 case 'bookmarks': | 530 case 'bookmarks': |
513 this.bookmarks_ = message.data.bookmarks; | 531 this.bookmarks_ = message.data.bookmarks; |
514 if (this.isMaterial_ && this.bookmarks_.length !== 0) { | 532 if (this.isMaterial_ && this.bookmarks_.length !== 0) { |
515 $('bookmarks-container').bookmarks = this.bookmarks; | 533 $('bookmarks-container').bookmarks = this.bookmarks; |
516 this.materialToolbar_.hasBookmarks = true; | 534 this.materialToolbar_.hasBookmarks = true; |
517 } | 535 } |
518 break; | 536 break; |
519 case 'setIsSelecting': | 537 case 'setIsSelecting': |
520 this.viewportScroller_.setEnableScrolling(message.data.isSelecting); | 538 this.viewportScroller_.setEnableScrolling(message.data.isSelecting); |
521 break; | 539 break; |
| 540 case 'getNamedDestinationReply': |
| 541 this.paramsParser_.onNamedDestinationReceived( |
| 542 message.data.pageNumber); |
| 543 break; |
522 } | 544 } |
523 }, | 545 }, |
524 | 546 |
525 /** | 547 /** |
526 * @private | 548 * @private |
527 * A callback that's called before the zoom changes. Notify the plugin to stop | 549 * A callback that's called before the zoom changes. Notify the plugin to stop |
528 * reacting to scroll events while zoom is taking place to avoid flickering. | 550 * reacting to scroll events while zoom is taking place to avoid flickering. |
529 */ | 551 */ |
530 beforeZoom_: function() { | 552 beforeZoom_: function() { |
531 this.plugin_.postMessage({ | 553 this.plugin_.postMessage({ |
(...skipping 226 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
758 * Each bookmark is an Object containing a: | 780 * Each bookmark is an Object containing a: |
759 * - title | 781 * - title |
760 * - page (optional) | 782 * - page (optional) |
761 * - array of children (themselves bookmarks) | 783 * - array of children (themselves bookmarks) |
762 * @type {Array} the top-level bookmarks of the PDF. | 784 * @type {Array} the top-level bookmarks of the PDF. |
763 */ | 785 */ |
764 get bookmarks() { | 786 get bookmarks() { |
765 return this.bookmarks_; | 787 return this.bookmarks_; |
766 } | 788 } |
767 }; | 789 }; |
OLD | NEW |