| 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 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 59 // of the pdf and zoom level. | 59 // of the pdf and zoom level. |
| 60 this.sizer_ = $('sizer'); | 60 this.sizer_ = $('sizer'); |
| 61 this.toolbar_ = $('toolbar'); | 61 this.toolbar_ = $('toolbar'); |
| 62 this.pageIndicator_ = $('page-indicator'); | 62 this.pageIndicator_ = $('page-indicator'); |
| 63 this.progressBar_ = $('progress-bar'); | 63 this.progressBar_ = $('progress-bar'); |
| 64 this.passwordScreen_ = $('password-screen'); | 64 this.passwordScreen_ = $('password-screen'); |
| 65 this.passwordScreen_.addEventListener('password-submitted', | 65 this.passwordScreen_.addEventListener('password-submitted', |
| 66 this.onPasswordSubmitted_.bind(this)); | 66 this.onPasswordSubmitted_.bind(this)); |
| 67 this.errorScreen_ = $('error-screen'); | 67 this.errorScreen_ = $('error-screen'); |
| 68 this.toolbarHeight_ = this.isMaterial_ ? $('pdf-toolbar').clientHeight : 0; | 68 this.toolbarHeight_ = this.isMaterial_ ? $('pdf-toolbar').clientHeight : 0; |
| 69 this.bookmarksPane = $('bookmarks-pane'); |
| 69 | 70 |
| 70 // Create the viewport. | 71 // Create the viewport. |
| 71 this.viewport_ = new Viewport(window, | 72 this.viewport_ = new Viewport(window, |
| 72 this.sizer_, | 73 this.sizer_, |
| 73 this.viewportChanged_.bind(this), | 74 this.viewportChanged_.bind(this), |
| 74 this.beforeZoom_.bind(this), | 75 this.beforeZoom_.bind(this), |
| 75 this.afterZoom_.bind(this), | 76 this.afterZoom_.bind(this), |
| 76 getScrollbarWidth(), | 77 getScrollbarWidth(), |
| 77 this.toolbarHeight_); | 78 this.toolbarHeight_); |
| 78 // Create the plugin object dynamically so we can set its src. The plugin | 79 // Create the plugin object dynamically so we can set its src. The plugin |
| (...skipping 30 matching lines...) Expand all Loading... |
| 109 this.plugin_.setAttribute('headers', headers); | 110 this.plugin_.setAttribute('headers', headers); |
| 110 | 111 |
| 111 if (!this.streamDetails_.embedded) | 112 if (!this.streamDetails_.embedded) |
| 112 this.plugin_.setAttribute('full-frame', ''); | 113 this.plugin_.setAttribute('full-frame', ''); |
| 113 document.body.appendChild(this.plugin_); | 114 document.body.appendChild(this.plugin_); |
| 114 | 115 |
| 115 this.pageIndicator_.addEventListener('changePage', function(e) { | 116 this.pageIndicator_.addEventListener('changePage', function(e) { |
| 116 this.viewport_.goToPage(e.detail.page); | 117 this.viewport_.goToPage(e.detail.page); |
| 117 }.bind(this)); | 118 }.bind(this)); |
| 118 | 119 |
| 120 if (this.isMaterial_) { |
| 121 this.bookmarksPane.addEventListener('changePage', function(e) { |
| 122 this.viewport_.goToPage(e.detail.page); |
| 123 }.bind(this)); |
| 124 } |
| 125 |
| 119 // Setup the button event listeners. | 126 // Setup the button event listeners. |
| 120 $('fit-to-width-button').addEventListener('click', | 127 $('fit-to-width-button').addEventListener('click', |
| 121 this.viewport_.fitToWidth.bind(this.viewport_)); | 128 this.viewport_.fitToWidth.bind(this.viewport_)); |
| 122 $('fit-to-page-button').addEventListener('click', | 129 $('fit-to-page-button').addEventListener('click', |
| 123 this.viewport_.fitToPage.bind(this.viewport_)); | 130 this.viewport_.fitToPage.bind(this.viewport_)); |
| 124 $('zoom-in-button').addEventListener('click', | 131 $('zoom-in-button').addEventListener('click', |
| 125 this.viewport_.zoomIn.bind(this.viewport_)); | 132 this.viewport_.zoomIn.bind(this.viewport_)); |
| 126 $('zoom-out-button').addEventListener('click', | 133 $('zoom-out-button').addEventListener('click', |
| 127 this.viewport_.zoomOut.bind(this.viewport_)); | 134 this.viewport_.zoomOut.bind(this.viewport_)); |
| 128 $('save-button').addEventListener('click', this.save_.bind(this)); | 135 $('save-button').addEventListener('click', this.save_.bind(this)); |
| 129 $('print-button').addEventListener('click', this.print_.bind(this)); | 136 $('print-button').addEventListener('click', this.print_.bind(this)); |
| 137 if (this.isMaterial_) { |
| 138 $('bookmarks-button').addEventListener('click', function() { |
| 139 this.bookmarksPane.toggle(); |
| 140 }.bind(this)); |
| 141 } |
| 130 | 142 |
| 131 // Setup the keyboard event listener. | 143 // Setup the keyboard event listener. |
| 132 document.onkeydown = this.handleKeyEvent_.bind(this); | 144 document.onkeydown = this.handleKeyEvent_.bind(this); |
| 133 | 145 |
| 134 // Set up the zoom API. | 146 // Set up the zoom API. |
| 135 if (this.shouldManageZoom_()) { | 147 if (this.shouldManageZoom_()) { |
| 136 chrome.tabs.setZoomSettings(this.streamDetails_.tabId, | 148 chrome.tabs.setZoomSettings(this.streamDetails_.tabId, |
| 137 {mode: 'manual', scope: 'per-tab'}, | 149 {mode: 'manual', scope: 'per-tab'}, |
| 138 this.afterZoom_.bind(this)); | 150 this.afterZoom_.bind(this)); |
| 139 chrome.tabs.onZoomChange.addListener(function(zoomChangeInfo) { | 151 chrome.tabs.onZoomChange.addListener(function(zoomChangeInfo) { |
| (...skipping 302 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 442 this.progressBar_.text = message.data.loadingString; | 454 this.progressBar_.text = message.data.loadingString; |
| 443 if (!this.isPrintPreview_) | 455 if (!this.isPrintPreview_) |
| 444 this.progressBar_.style.visibility = 'visible'; | 456 this.progressBar_.style.visibility = 'visible'; |
| 445 this.errorScreen_.text = message.data.loadFailedString; | 457 this.errorScreen_.text = message.data.loadFailedString; |
| 446 break; | 458 break; |
| 447 case 'cancelStreamUrl': | 459 case 'cancelStreamUrl': |
| 448 chrome.mimeHandlerPrivate.abortStream(); | 460 chrome.mimeHandlerPrivate.abortStream(); |
| 449 break; | 461 break; |
| 450 case 'bookmarks': | 462 case 'bookmarks': |
| 451 this.bookmarks_ = message.data.bookmarks; | 463 this.bookmarks_ = message.data.bookmarks; |
| 464 if (this.isMaterial_) |
| 465 this.bookmarksPane.bookmarks = message.data.bookmarks; |
| 452 break; | 466 break; |
| 453 } | 467 } |
| 454 }, | 468 }, |
| 455 | 469 |
| 456 /** | 470 /** |
| 457 * @private | 471 * @private |
| 458 * A callback that's called before the zoom changes. Notify the plugin to stop | 472 * A callback that's called before the zoom changes. Notify the plugin to stop |
| 459 * reacting to scroll events while zoom is taking place to avoid flickering. | 473 * reacting to scroll events while zoom is taking place to avoid flickering. |
| 460 */ | 474 */ |
| 461 beforeZoom_: function() { | 475 beforeZoom_: function() { |
| (...skipping 232 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 694 * Each bookmark is an Object containing a: | 708 * Each bookmark is an Object containing a: |
| 695 * - title | 709 * - title |
| 696 * - page (optional) | 710 * - page (optional) |
| 697 * - array of children (themselves bookmarks) | 711 * - array of children (themselves bookmarks) |
| 698 * @type {Array} the top-level bookmarks of the PDF. | 712 * @type {Array} the top-level bookmarks of the PDF. |
| 699 */ | 713 */ |
| 700 get bookmarks() { | 714 get bookmarks() { |
| 701 return this.bookmarks_; | 715 return this.bookmarks_; |
| 702 } | 716 } |
| 703 }; | 717 }; |
| OLD | NEW |