| 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 194 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 205 this.zoomToolbar_.addEventListener('fit-to-width', | 205 this.zoomToolbar_.addEventListener('fit-to-width', |
| 206 this.viewport_.fitToWidth.bind(this.viewport_)); | 206 this.viewport_.fitToWidth.bind(this.viewport_)); |
| 207 this.zoomToolbar_.addEventListener('fit-to-page', | 207 this.zoomToolbar_.addEventListener('fit-to-page', |
| 208 this.fitToPage_.bind(this)); | 208 this.fitToPage_.bind(this)); |
| 209 this.zoomToolbar_.addEventListener('zoom-in', | 209 this.zoomToolbar_.addEventListener('zoom-in', |
| 210 this.viewport_.zoomIn.bind(this.viewport_)); | 210 this.viewport_.zoomIn.bind(this.viewport_)); |
| 211 this.zoomToolbar_.addEventListener('zoom-out', | 211 this.zoomToolbar_.addEventListener('zoom-out', |
| 212 this.viewport_.zoomOut.bind(this.viewport_)); | 212 this.viewport_.zoomOut.bind(this.viewport_)); |
| 213 | 213 |
| 214 if (!this.isPrintPreview_) { | 214 if (!this.isPrintPreview_) { |
| 215 this.materialToolbar_ = $('material-toolbar'); | 215 this.toolbar_ = $('toolbar'); |
| 216 this.materialToolbar_.hidden = false; | 216 this.toolbar_.hidden = false; |
| 217 this.materialToolbar_.addEventListener('save', this.save_.bind(this)); | 217 this.toolbar_.addEventListener('save', this.save_.bind(this)); |
| 218 this.materialToolbar_.addEventListener('print', this.print_.bind(this)); | 218 this.toolbar_.addEventListener('print', this.print_.bind(this)); |
| 219 this.materialToolbar_.addEventListener('rotate-right', | 219 this.toolbar_.addEventListener('rotate-right', |
| 220 this.rotateClockwise_.bind(this)); | 220 this.rotateClockwise_.bind(this)); |
| 221 // Must attach to mouseup on the plugin element, since it eats mousedown | 221 // Must attach to mouseup on the plugin element, since it eats mousedown |
| 222 // and click events. | 222 // and click events. |
| 223 this.plugin_.addEventListener('mouseup', | 223 this.plugin_.addEventListener('mouseup', |
| 224 this.materialToolbar_.hideDropdowns.bind(this.materialToolbar_)); | 224 this.toolbar_.hideDropdowns.bind(this.toolbar_)); |
| 225 | 225 |
| 226 this.materialToolbar_.docTitle = | 226 this.toolbar_.docTitle = |
| 227 getFilenameFromURL(this.browserApi_.getStreamInfo().originalUrl); | 227 getFilenameFromURL(this.browserApi_.getStreamInfo().originalUrl); |
| 228 } | 228 } |
| 229 | 229 |
| 230 document.body.addEventListener('change-page', function(e) { | 230 document.body.addEventListener('change-page', function(e) { |
| 231 this.viewport_.goToPage(e.detail.page); | 231 this.viewport_.goToPage(e.detail.page); |
| 232 }.bind(this)); | 232 }.bind(this)); |
| 233 | 233 |
| 234 this.toolbarManager_ = | 234 this.toolbarManager_ = |
| 235 new ToolbarManager(window, this.materialToolbar_, this.zoomToolbar_); | 235 new ToolbarManager(window, this.toolbar_, this.zoomToolbar_); |
| 236 | 236 |
| 237 // Set up the ZoomManager. | 237 // Set up the ZoomManager. |
| 238 this.zoomManager_ = new ZoomManager( | 238 this.zoomManager_ = new ZoomManager( |
| 239 this.viewport_, this.browserApi_.setZoom.bind(this.browserApi_), | 239 this.viewport_, this.browserApi_.setZoom.bind(this.browserApi_), |
| 240 this.browserApi_.getInitialZoom()); | 240 this.browserApi_.getInitialZoom()); |
| 241 this.browserApi_.addZoomEventListener( | 241 this.browserApi_.addZoomEventListener( |
| 242 this.zoomManager_.onBrowserZoomChange.bind(this.zoomManager_)); | 242 this.zoomManager_.onBrowserZoomChange.bind(this.zoomManager_)); |
| 243 | 243 |
| 244 // Setup the keyboard event listener. | 244 // Setup the keyboard event listener. |
| 245 document.addEventListener('keydown', this.handleKeyEvent_.bind(this)); | 245 document.addEventListener('keydown', this.handleKeyEvent_.bind(this)); |
| (...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 373 case 65: // a key. | 373 case 65: // a key. |
| 374 if (e.ctrlKey || e.metaKey) { | 374 if (e.ctrlKey || e.metaKey) { |
| 375 this.plugin_.postMessage({ | 375 this.plugin_.postMessage({ |
| 376 type: 'selectAll' | 376 type: 'selectAll' |
| 377 }); | 377 }); |
| 378 // Since we do selection ourselves. | 378 // Since we do selection ourselves. |
| 379 e.preventDefault(); | 379 e.preventDefault(); |
| 380 } | 380 } |
| 381 return; | 381 return; |
| 382 case 71: // g key. | 382 case 71: // g key. |
| 383 if (this.materialToolbar_ && (e.ctrlKey || e.metaKey) && e.altKey) { | 383 if (this.toolbar_ && (e.ctrlKey || e.metaKey) && e.altKey) { |
| 384 this.toolbarManager_.showToolbars(); | 384 this.toolbarManager_.showToolbars(); |
| 385 this.materialToolbar_.selectPageNumber(); | 385 this.toolbar_.selectPageNumber(); |
| 386 } | 386 } |
| 387 return; | 387 return; |
| 388 case 219: // left bracket. | 388 case 219: // left bracket. |
| 389 if (e.ctrlKey) | 389 if (e.ctrlKey) |
| 390 this.rotateCounterClockwise_(); | 390 this.rotateCounterClockwise_(); |
| 391 return; | 391 return; |
| 392 case 221: // right bracket. | 392 case 221: // right bracket. |
| 393 if (e.ctrlKey) | 393 if (e.ctrlKey) |
| 394 this.rotateClockwise_(); | 394 this.rotateClockwise_(); |
| 395 return; | 395 return; |
| (...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 508 this.viewport_.setZoom(viewportPosition.zoom); | 508 this.viewport_.setZoom(viewportPosition.zoom); |
| 509 }, | 509 }, |
| 510 | 510 |
| 511 /** | 511 /** |
| 512 * @private | 512 * @private |
| 513 * Update the loading progress of the document in response to a progress | 513 * Update the loading progress of the document in response to a progress |
| 514 * message being received from the plugin. | 514 * message being received from the plugin. |
| 515 * @param {number} progress the progress as a percentage. | 515 * @param {number} progress the progress as a percentage. |
| 516 */ | 516 */ |
| 517 updateProgress_: function(progress) { | 517 updateProgress_: function(progress) { |
| 518 if (this.materialToolbar_) | 518 if (this.toolbar_) |
| 519 this.materialToolbar_.loadProgress = progress; | 519 this.toolbar_.loadProgress = progress; |
| 520 | 520 |
| 521 if (progress == -1) { | 521 if (progress == -1) { |
| 522 // Document load failed. | 522 // Document load failed. |
| 523 this.errorScreen_.show(); | 523 this.errorScreen_.show(); |
| 524 this.sizer_.style.display = 'none'; | 524 this.sizer_.style.display = 'none'; |
| 525 if (this.passwordScreen_.active) { | 525 if (this.passwordScreen_.active) { |
| 526 this.passwordScreen_.deny(); | 526 this.passwordScreen_.deny(); |
| 527 this.passwordScreen_.active = false; | 527 this.passwordScreen_.active = false; |
| 528 } | 528 } |
| 529 this.loadState_ = LoadState.FAILED; | 529 this.loadState_ = LoadState.FAILED; |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 580 this.documentDimensions_ = message.data; | 580 this.documentDimensions_ = message.data; |
| 581 this.viewport_.setDocumentDimensions(this.documentDimensions_); | 581 this.viewport_.setDocumentDimensions(this.documentDimensions_); |
| 582 // If we received the document dimensions, the password was good so we | 582 // If we received the document dimensions, the password was good so we |
| 583 // can dismiss the password screen. | 583 // can dismiss the password screen. |
| 584 if (this.passwordScreen_.active) | 584 if (this.passwordScreen_.active) |
| 585 this.passwordScreen_.accept(); | 585 this.passwordScreen_.accept(); |
| 586 | 586 |
| 587 if (this.pageIndicator_) | 587 if (this.pageIndicator_) |
| 588 this.pageIndicator_.initialFadeIn(); | 588 this.pageIndicator_.initialFadeIn(); |
| 589 | 589 |
| 590 if (this.materialToolbar_) { | 590 if (this.toolbar_) { |
| 591 this.materialToolbar_.docLength = | 591 this.toolbar_.docLength = |
| 592 this.documentDimensions_.pageDimensions.length; | 592 this.documentDimensions_.pageDimensions.length; |
| 593 } | 593 } |
| 594 break; | 594 break; |
| 595 case 'email': | 595 case 'email': |
| 596 var href = 'mailto:' + message.data.to + '?cc=' + message.data.cc + | 596 var href = 'mailto:' + message.data.to + '?cc=' + message.data.cc + |
| 597 '&bcc=' + message.data.bcc + '&subject=' + message.data.subject + | 597 '&bcc=' + message.data.bcc + '&subject=' + message.data.subject + |
| 598 '&body=' + message.data.body; | 598 '&body=' + message.data.body; |
| 599 window.location.href = href; | 599 window.location.href = href; |
| 600 break; | 600 break; |
| 601 case 'getAccessibilityJSONReply': | 601 case 'getAccessibilityJSONReply': |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 637 chrome.mimeHandlerPrivate.abortStream(); | 637 chrome.mimeHandlerPrivate.abortStream(); |
| 638 break; | 638 break; |
| 639 case 'metadata': | 639 case 'metadata': |
| 640 if (message.data.title) { | 640 if (message.data.title) { |
| 641 document.title = message.data.title; | 641 document.title = message.data.title; |
| 642 } else { | 642 } else { |
| 643 document.title = | 643 document.title = |
| 644 getFilenameFromURL(this.browserApi_.getStreamInfo().originalUrl); | 644 getFilenameFromURL(this.browserApi_.getStreamInfo().originalUrl); |
| 645 } | 645 } |
| 646 this.bookmarks_ = message.data.bookmarks; | 646 this.bookmarks_ = message.data.bookmarks; |
| 647 if (this.materialToolbar_) { | 647 if (this.toolbar_) { |
| 648 this.materialToolbar_.docTitle = document.title; | 648 this.toolbar_.docTitle = document.title; |
| 649 this.materialToolbar_.bookmarks = this.bookmarks; | 649 this.toolbar_.bookmarks = this.bookmarks; |
| 650 } | 650 } |
| 651 break; | 651 break; |
| 652 case 'setIsSelecting': | 652 case 'setIsSelecting': |
| 653 this.viewportScroller_.setEnableScrolling(message.data.isSelecting); | 653 this.viewportScroller_.setEnableScrolling(message.data.isSelecting); |
| 654 break; | 654 break; |
| 655 case 'getNamedDestinationReply': | 655 case 'getNamedDestinationReply': |
| 656 this.paramsParser_.onNamedDestinationReceived( | 656 this.paramsParser_.onNamedDestinationReceived( |
| 657 message.data.pageNumber); | 657 message.data.pageNumber); |
| 658 break; | 658 break; |
| 659 case 'formFocusChange': | 659 case 'formFocusChange': |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 717 } | 717 } |
| 718 // Having a horizontal scrollbar is much rarer so we don't offset the | 718 // Having a horizontal scrollbar is much rarer so we don't offset the |
| 719 // toolbar from the bottom any more than what the spec says. This means | 719 // toolbar from the bottom any more than what the spec says. This means |
| 720 // that when there is a scrollbar visible, it will be a full scrollbar | 720 // that when there is a scrollbar visible, it will be a full scrollbar |
| 721 // width closer to the bottom of the screen than usual, but this is ok. | 721 // width closer to the bottom of the screen than usual, but this is ok. |
| 722 this.zoomToolbar_.style.bottom = -horizontalScrollbarWidth + 'px'; | 722 this.zoomToolbar_.style.bottom = -horizontalScrollbarWidth + 'px'; |
| 723 | 723 |
| 724 // Update the page indicator. | 724 // Update the page indicator. |
| 725 var visiblePage = this.viewport_.getMostVisiblePage(); | 725 var visiblePage = this.viewport_.getMostVisiblePage(); |
| 726 | 726 |
| 727 if (this.materialToolbar_) | 727 if (this.toolbar_) |
| 728 this.materialToolbar_.pageNo = visiblePage + 1; | 728 this.toolbar_.pageNo = visiblePage + 1; |
| 729 | 729 |
| 730 // TODO(raymes): Give pageIndicator_ the same API as materialToolbar_. | 730 // TODO(raymes): Give pageIndicator_ the same API as toolbar_. |
| 731 if (this.pageIndicator_) { | 731 if (this.pageIndicator_) { |
| 732 this.pageIndicator_.index = visiblePage; | 732 this.pageIndicator_.index = visiblePage; |
| 733 if (this.documentDimensions_.pageDimensions.length > 1 && | 733 if (this.documentDimensions_.pageDimensions.length > 1 && |
| 734 hasScrollbars.vertical) { | 734 hasScrollbars.vertical) { |
| 735 this.pageIndicator_.style.visibility = 'visible'; | 735 this.pageIndicator_.style.visibility = 'visible'; |
| 736 } else { | 736 } else { |
| 737 this.pageIndicator_.style.visibility = 'hidden'; | 737 this.pageIndicator_.style.visibility = 'hidden'; |
| 738 } | 738 } |
| 739 } | 739 } |
| 740 | 740 |
| (...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 872 * Each bookmark is an Object containing a: | 872 * Each bookmark is an Object containing a: |
| 873 * - title | 873 * - title |
| 874 * - page (optional) | 874 * - page (optional) |
| 875 * - array of children (themselves bookmarks) | 875 * - array of children (themselves bookmarks) |
| 876 * @type {Array} the top-level bookmarks of the PDF. | 876 * @type {Array} the top-level bookmarks of the PDF. |
| 877 */ | 877 */ |
| 878 get bookmarks() { | 878 get bookmarks() { |
| 879 return this.bookmarks_; | 879 return this.bookmarks_; |
| 880 } | 880 } |
| 881 }; | 881 }; |
| OLD | NEW |