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)); | |
raymes
2015/02/16 02:02:31
There is some refactoring that would be really nic
Deepak
2015/02/16 06:45:38
I agree with you, will do it in-separate CL.
Thank
| |
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 * Callback to fetch namedDestination from plugin. | |
raymes
2015/02/16 02:02:31
nit: Fetches the page number corresponding to the
Deepak
2015/02/16 06:45:38
Done.
| |
372 * @param {string} name The namedDestination to fetch page number from plugin. | |
373 */ | |
374 getNamedDestination_: function(name) { | |
375 this.plugin_.postMessage({ | |
376 type: 'getNamedDestination', | |
377 namedDestination: name | |
378 }); | |
379 }, | |
360 | 380 |
361 /** | 381 /** |
362 * @private | 382 * @private |
363 * Handle open pdf parameters. This function updates the viewport as per | 383 * Handle open pdf parameters. This function updates the viewport as per |
364 * the parameters mentioned in the url while opening pdf. The order is | 384 * the parameters mentioned in the url while opening pdf. The order is |
365 * important as later actions can override the effects of previous actions. | 385 * important as later actions can override the effects of previous actions. |
366 */ | 386 */ |
367 handleURLParams_: function() { | 387 handleURLParams_: function() { |
368 var urlParams = | 388 this.paramsParser_.getViewportFromUrlParams( |
369 this.paramsParser_.getViewportFromUrlParams( | 389 this.streamDetails_.originalUrl, function(initialViewport) { |
raymes
2015/02/16 02:02:31
nit: viewportPosition
Deepak
2015/02/16 06:45:38
Done.
| |
370 this.streamDetails_.originalUrl); | 390 if (initialViewport.page != undefined) |
371 if (urlParams.page) | 391 this.viewport_.goToPage(initialViewport.page); |
372 this.viewport_.goToPage(urlParams.page); | 392 if (initialViewport.position) { |
373 if (urlParams.position) { | 393 // Make sure we don't cancel effect of page parameter. |
374 // Make sure we don't cancel effect of page parameter. | 394 this.viewport_.position = { |
375 this.viewport_.position = { | 395 x: this.viewport_.position.x + initialViewport.position.x, |
376 x: this.viewport_.position.x + urlParams.position.x, | 396 y: this.viewport_.position.y + initialViewport.position.y |
377 y: this.viewport_.position.y + urlParams.position.y | 397 }; |
378 }; | 398 } |
379 } | 399 if (initialViewport.zoom) |
380 if (urlParams.zoom) | 400 this.viewport_.setZoom(initialViewport.zoom); |
381 this.viewport_.setZoom(urlParams.zoom); | 401 }.bind(this)); |
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.handleURLParams_(); |
raymes
2015/02/16 02:02:31
nit: Let's call this instead:
this.paramsParser_.
Deepak
2015/02/16 06:45:38
Done.
| |
410 this.loaded_ = true; | 430 this.loaded_ = true; |
411 this.sendScriptingMessage_({ | 431 this.sendScriptingMessage_({ |
412 type: 'documentLoaded' | 432 type: 'documentLoaded' |
413 }); | 433 }); |
414 while (this.delayedScriptingMessages_.length > 0) | 434 while (this.delayedScriptingMessages_.length > 0) |
415 this.handleScriptingMessage(this.delayedScriptingMessages_.shift()); | 435 this.handleScriptingMessage(this.delayedScriptingMessages_.shift()); |
416 } | 436 } |
417 }, | 437 }, |
418 | 438 |
419 /** | 439 /** |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
479 case 'loadProgress': | 499 case 'loadProgress': |
480 this.updateProgress_(message.data.progress); | 500 this.updateProgress_(message.data.progress); |
481 break; | 501 break; |
482 case 'navigate': | 502 case 'navigate': |
483 // If in print preview, always open a new tab. | 503 // If in print preview, always open a new tab. |
484 if (this.isPrintPreview_) | 504 if (this.isPrintPreview_) |
485 this.navigator_.navigate(message.data.url, true); | 505 this.navigator_.navigate(message.data.url, true); |
486 else | 506 else |
487 this.navigator_.navigate(message.data.url, message.data.newTab); | 507 this.navigator_.navigate(message.data.url, message.data.newTab); |
488 break; | 508 break; |
489 case 'setNamedDestinations': | |
490 this.paramsParser_.namedDestinations = message.data.namedDestinations; | |
491 break; | |
492 case 'setScrollPosition': | 509 case 'setScrollPosition': |
493 var position = this.viewport_.position; | 510 var position = this.viewport_.position; |
494 if (message.data.x !== undefined) | 511 if (message.data.x !== undefined) |
495 position.x = message.data.x; | 512 position.x = message.data.x; |
496 if (message.data.y !== undefined) | 513 if (message.data.y !== undefined) |
497 position.y = message.data.y; | 514 position.y = message.data.y; |
498 this.viewport_.position = position; | 515 this.viewport_.position = position; |
499 break; | 516 break; |
500 case 'setTranslatedStrings': | 517 case 'setTranslatedStrings': |
501 this.passwordScreen_.text = message.data.getPasswordString; | 518 this.passwordScreen_.text = message.data.getPasswordString; |
(...skipping 10 matching lines...) Expand all Loading... | |
512 case 'bookmarks': | 529 case 'bookmarks': |
513 this.bookmarks_ = message.data.bookmarks; | 530 this.bookmarks_ = message.data.bookmarks; |
514 if (this.isMaterial_ && this.bookmarks_.length !== 0) { | 531 if (this.isMaterial_ && this.bookmarks_.length !== 0) { |
515 $('bookmarks-container').bookmarks = this.bookmarks; | 532 $('bookmarks-container').bookmarks = this.bookmarks; |
516 this.materialToolbar_.hasBookmarks = true; | 533 this.materialToolbar_.hasBookmarks = true; |
517 } | 534 } |
518 break; | 535 break; |
519 case 'setIsSelecting': | 536 case 'setIsSelecting': |
520 this.viewportScroller_.setEnableScrolling(message.data.isSelecting); | 537 this.viewportScroller_.setEnableScrolling(message.data.isSelecting); |
521 break; | 538 break; |
539 case 'getNamedDestinationReply': | |
540 this.paramsParser_.onNamedDestinationReceived( | |
541 message.data.namedDestinationPageNumber); | |
542 break; | |
522 } | 543 } |
523 }, | 544 }, |
524 | 545 |
525 /** | 546 /** |
526 * @private | 547 * @private |
527 * A callback that's called before the zoom changes. Notify the plugin to stop | 548 * 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. | 549 * reacting to scroll events while zoom is taking place to avoid flickering. |
529 */ | 550 */ |
530 beforeZoom_: function() { | 551 beforeZoom_: function() { |
531 this.plugin_.postMessage({ | 552 this.plugin_.postMessage({ |
(...skipping 226 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
758 * Each bookmark is an Object containing a: | 779 * Each bookmark is an Object containing a: |
759 * - title | 780 * - title |
760 * - page (optional) | 781 * - page (optional) |
761 * - array of children (themselves bookmarks) | 782 * - array of children (themselves bookmarks) |
762 * @type {Array} the top-level bookmarks of the PDF. | 783 * @type {Array} the top-level bookmarks of the PDF. |
763 */ | 784 */ |
764 get bookmarks() { | 785 get bookmarks() { |
765 return this.bookmarks_; | 786 return this.bookmarks_; |
766 } | 787 } |
767 }; | 788 }; |
OLD | NEW |