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. |
366 */ | 387 */ |
367 handleURLParams_: function() { | 388 handleURLParams_: function(viewportPosition) { |
368 var urlParams = | 389 if (viewportPosition.page != undefined) |
369 this.paramsParser_.getViewportFromUrlParams( | 390 this.viewport_.goToPage(viewportPosition.page); |
370 this.streamDetails_.originalUrl); | 391 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. | 392 // Make sure we don't cancel effect of page parameter. |
375 this.viewport_.position = { | 393 this.viewport_.position = { |
376 x: this.viewport_.position.x + urlParams.position.x, | 394 x: this.viewport_.position.x + viewportPosition.position.x, |
377 y: this.viewport_.position.y + urlParams.position.y | 395 y: this.viewport_.position.y + viewportPosition.position.y |
378 }; | 396 }; |
379 } | 397 } |
380 if (urlParams.zoom) | 398 if (viewportPosition.zoom) |
381 this.viewport_.setZoom(urlParams.zoom); | 399 this.viewport_.setZoom(viewportPosition.zoom); |
382 }, | 400 }, |
383 | 401 |
384 /** | 402 /** |
385 * @private | 403 * @private |
386 * Update the loading progress of the document in response to a progress | 404 * Update the loading progress of the document in response to a progress |
387 * message being received from the plugin. | 405 * message being received from the plugin. |
388 * @param {number} progress the progress as a percentage. | 406 * @param {number} progress the progress as a percentage. |
389 */ | 407 */ |
390 updateProgress_: function(progress) { | 408 updateProgress_: function(progress) { |
391 if (this.isMaterial_) | 409 if (this.isMaterial_) |
392 this.materialToolbar_.loadProgress = progress; | 410 this.materialToolbar_.loadProgress = progress; |
393 else | 411 else |
394 this.progressBar_.progress = progress; | 412 this.progressBar_.progress = progress; |
395 | 413 |
396 if (progress == -1) { | 414 if (progress == -1) { |
397 // Document load failed. | 415 // Document load failed. |
398 this.errorScreen_.style.visibility = 'visible'; | 416 this.errorScreen_.style.visibility = 'visible'; |
399 this.sizer_.style.display = 'none'; | 417 this.sizer_.style.display = 'none'; |
400 this.toolbar_.style.visibility = 'hidden'; | 418 this.toolbar_.style.visibility = 'hidden'; |
401 if (this.passwordScreen_.active) { | 419 if (this.passwordScreen_.active) { |
402 this.passwordScreen_.deny(); | 420 this.passwordScreen_.deny(); |
403 this.passwordScreen_.active = false; | 421 this.passwordScreen_.active = false; |
404 } | 422 } |
405 } else if (progress == 100) { | 423 } else if (progress == 100) { |
406 // Document load complete. | 424 // Document load complete. |
407 if (this.lastViewportPosition_) | 425 if (this.lastViewportPosition_) |
408 this.viewport_.position = this.lastViewportPosition_; | 426 this.viewport_.position = this.lastViewportPosition_; |
409 this.handleURLParams_(); | 427 this.paramsParser_.getViewportFromUrlParams( |
428 this.streamDetails_.originalUrl, this.handleURLParams_.bind(this)); | |
raymes
2015/02/16 22:44:04
nit: 4 space indent
Deepak
2015/02/17 07:12:12
Done.
| |
410 this.loaded_ = true; | 429 this.loaded_ = true; |
411 this.sendScriptingMessage_({ | 430 this.sendScriptingMessage_({ |
412 type: 'documentLoaded' | 431 type: 'documentLoaded' |
413 }); | 432 }); |
414 while (this.delayedScriptingMessages_.length > 0) | 433 while (this.delayedScriptingMessages_.length > 0) |
415 this.handleScriptingMessage(this.delayedScriptingMessages_.shift()); | 434 this.handleScriptingMessage(this.delayedScriptingMessages_.shift()); |
416 } | 435 } |
417 }, | 436 }, |
418 | 437 |
419 /** | 438 /** |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
479 case 'loadProgress': | 498 case 'loadProgress': |
480 this.updateProgress_(message.data.progress); | 499 this.updateProgress_(message.data.progress); |
481 break; | 500 break; |
482 case 'navigate': | 501 case 'navigate': |
483 // If in print preview, always open a new tab. | 502 // If in print preview, always open a new tab. |
484 if (this.isPrintPreview_) | 503 if (this.isPrintPreview_) |
485 this.navigator_.navigate(message.data.url, true); | 504 this.navigator_.navigate(message.data.url, true); |
486 else | 505 else |
487 this.navigator_.navigate(message.data.url, message.data.newTab); | 506 this.navigator_.navigate(message.data.url, message.data.newTab); |
488 break; | 507 break; |
489 case 'setNamedDestinations': | |
490 this.paramsParser_.namedDestinations = message.data.namedDestinations; | |
491 break; | |
492 case 'setScrollPosition': | 508 case 'setScrollPosition': |
493 var position = this.viewport_.position; | 509 var position = this.viewport_.position; |
494 if (message.data.x !== undefined) | 510 if (message.data.x !== undefined) |
495 position.x = message.data.x; | 511 position.x = message.data.x; |
496 if (message.data.y !== undefined) | 512 if (message.data.y !== undefined) |
497 position.y = message.data.y; | 513 position.y = message.data.y; |
498 this.viewport_.position = position; | 514 this.viewport_.position = position; |
499 break; | 515 break; |
500 case 'setTranslatedStrings': | 516 case 'setTranslatedStrings': |
501 this.passwordScreen_.text = message.data.getPasswordString; | 517 this.passwordScreen_.text = message.data.getPasswordString; |
(...skipping 10 matching lines...) Expand all Loading... | |
512 case 'bookmarks': | 528 case 'bookmarks': |
513 this.bookmarks_ = message.data.bookmarks; | 529 this.bookmarks_ = message.data.bookmarks; |
514 if (this.isMaterial_ && this.bookmarks_.length !== 0) { | 530 if (this.isMaterial_ && this.bookmarks_.length !== 0) { |
515 $('bookmarks-container').bookmarks = this.bookmarks; | 531 $('bookmarks-container').bookmarks = this.bookmarks; |
516 this.materialToolbar_.hasBookmarks = true; | 532 this.materialToolbar_.hasBookmarks = true; |
517 } | 533 } |
518 break; | 534 break; |
519 case 'setIsSelecting': | 535 case 'setIsSelecting': |
520 this.viewportScroller_.setEnableScrolling(message.data.isSelecting); | 536 this.viewportScroller_.setEnableScrolling(message.data.isSelecting); |
521 break; | 537 break; |
538 case 'getNamedDestinationReply': | |
539 this.paramsParser_.onNamedDestinationReceived( | |
540 message.data.namedDestinationPageNumber); | |
541 break; | |
522 } | 542 } |
523 }, | 543 }, |
524 | 544 |
525 /** | 545 /** |
526 * @private | 546 * @private |
527 * A callback that's called before the zoom changes. Notify the plugin to stop | 547 * 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. | 548 * reacting to scroll events while zoom is taking place to avoid flickering. |
529 */ | 549 */ |
530 beforeZoom_: function() { | 550 beforeZoom_: function() { |
531 this.plugin_.postMessage({ | 551 this.plugin_.postMessage({ |
(...skipping 226 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
758 * Each bookmark is an Object containing a: | 778 * Each bookmark is an Object containing a: |
759 * - title | 779 * - title |
760 * - page (optional) | 780 * - page (optional) |
761 * - array of children (themselves bookmarks) | 781 * - array of children (themselves bookmarks) |
762 * @type {Array} the top-level bookmarks of the PDF. | 782 * @type {Array} the top-level bookmarks of the PDF. |
763 */ | 783 */ |
764 get bookmarks() { | 784 get bookmarks() { |
765 return this.bookmarks_; | 785 return this.bookmarks_; |
766 } | 786 } |
767 }; | 787 }; |
OLD | NEW |