Chromium Code Reviews| 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 26 matching lines...) Expand all Loading... | |
| 105 for (var header in this.streamDetails_.responseHeaders) { | 106 for (var header in this.streamDetails_.responseHeaders) { |
| 106 headers += header + ': ' + | 107 headers += header + ': ' + |
| 107 this.streamDetails_.responseHeaders[header] + '\n'; | 108 this.streamDetails_.responseHeaders[header] + '\n'; |
| 108 } | 109 } |
| 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 |
| 116 this.bookmarksPane.addEventListener('changePage', function(e) { | |
| 117 this.viewport_.goToPage(e.detail.page); | |
| 118 }.bind(this)); | |
| 119 | |
| 115 // Setup the button event listeners. | 120 // Setup the button event listeners. |
| 116 $('fit-to-width-button').addEventListener('click', | 121 $('fit-to-width-button').addEventListener('click', |
| 117 this.viewport_.fitToWidth.bind(this.viewport_)); | 122 this.viewport_.fitToWidth.bind(this.viewport_)); |
| 118 $('fit-to-page-button').addEventListener('click', | 123 $('fit-to-page-button').addEventListener('click', |
| 119 this.viewport_.fitToPage.bind(this.viewport_)); | 124 this.viewport_.fitToPage.bind(this.viewport_)); |
| 120 $('zoom-in-button').addEventListener('click', | 125 $('zoom-in-button').addEventListener('click', |
| 121 this.viewport_.zoomIn.bind(this.viewport_)); | 126 this.viewport_.zoomIn.bind(this.viewport_)); |
| 122 $('zoom-out-button').addEventListener('click', | 127 $('zoom-out-button').addEventListener('click', |
| 123 this.viewport_.zoomOut.bind(this.viewport_)); | 128 this.viewport_.zoomOut.bind(this.viewport_)); |
| 124 $('save-button').addEventListener('click', this.save_.bind(this)); | 129 $('save-button').addEventListener('click', this.save_.bind(this)); |
| 125 $('print-button').addEventListener('click', this.print_.bind(this)); | 130 $('print-button').addEventListener('click', this.print_.bind(this)); |
| 131 $('bookmarks-button').addEventListener('click', function() { | |
| 132 this.bookmarksPane.toggle(); | |
| 133 }.bind(this)); | |
| 126 | 134 |
| 127 // Setup the keyboard event listener. | 135 // Setup the keyboard event listener. |
| 128 document.onkeydown = this.handleKeyEvent_.bind(this); | 136 document.onkeydown = this.handleKeyEvent_.bind(this); |
| 129 | 137 |
| 130 // Set up the zoom API. | 138 // Set up the zoom API. |
| 131 if (this.shouldManageZoom_()) { | 139 if (this.shouldManageZoom_()) { |
| 132 chrome.tabs.setZoomSettings(this.streamDetails_.tabId, | 140 chrome.tabs.setZoomSettings(this.streamDetails_.tabId, |
| 133 {mode: 'manual', scope: 'per-tab'}, | 141 {mode: 'manual', scope: 'per-tab'}, |
| 134 this.afterZoom_.bind(this)); | 142 this.afterZoom_.bind(this)); |
| 135 chrome.tabs.onZoomChange.addListener(function(zoomChangeInfo) { | 143 chrome.tabs.onZoomChange.addListener(function(zoomChangeInfo) { |
| (...skipping 291 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 427 this.progressBar_.text = message.data.loadingString; | 435 this.progressBar_.text = message.data.loadingString; |
| 428 if (!this.isPrintPreview_) | 436 if (!this.isPrintPreview_) |
| 429 this.progressBar_.style.visibility = 'visible'; | 437 this.progressBar_.style.visibility = 'visible'; |
| 430 this.errorScreen_.text = message.data.loadFailedString; | 438 this.errorScreen_.text = message.data.loadFailedString; |
| 431 break; | 439 break; |
| 432 case 'cancelStreamUrl': | 440 case 'cancelStreamUrl': |
| 433 chrome.mimeHandlerPrivate.abortStream(); | 441 chrome.mimeHandlerPrivate.abortStream(); |
| 434 break; | 442 break; |
| 435 case 'bookmarks': | 443 case 'bookmarks': |
| 436 this.bookmarks_ = message.data.bookmarks; | 444 this.bookmarks_ = message.data.bookmarks; |
| 445 this.bookmarksPane.bookmarks = message.data.bookmarks; | |
|
raymes
2015/01/27 09:10:54
Do we use "this.bookmarks_"? I think we just used
Alexandre Carlton
2015/01/28 00:22:47
Done.
| |
| 437 break; | 446 break; |
| 438 } | 447 } |
| 439 }, | 448 }, |
| 440 | 449 |
| 441 /** | 450 /** |
| 442 * @private | 451 * @private |
| 443 * A callback that's called before the zoom changes. Notify the plugin to stop | 452 * A callback that's called before the zoom changes. Notify the plugin to stop |
| 444 * reacting to scroll events while zoom is taking place to avoid flickering. | 453 * reacting to scroll events while zoom is taking place to avoid flickering. |
| 445 */ | 454 */ |
| 446 beforeZoom_: function() { | 455 beforeZoom_: function() { |
| (...skipping 218 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 665 this.streamDetails_.tabId != -1); | 674 this.streamDetails_.tabId != -1); |
| 666 }, | 675 }, |
| 667 | 676 |
| 668 /** | 677 /** |
| 669 * @type {Viewport} the viewport of the PDF viewer. | 678 * @type {Viewport} the viewport of the PDF viewer. |
| 670 */ | 679 */ |
| 671 get viewport() { | 680 get viewport() { |
| 672 return this.viewport_; | 681 return this.viewport_; |
| 673 } | 682 } |
| 674 }; | 683 }; |
| OLD | NEW |