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() { | |
Sam McNally
2015/01/28 03:04:30
if (this.isMaterial_) {
Alexandre Carlton
2015/01/28 07:16:52
Done.
| |
132 this.bookmarksPane.toggle(); | |
Sam McNally
2015/01/28 03:04:30
Indentation.
Alexandre Carlton
2015/01/28 07:16:52
Done.
| |
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 293 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
429 this.passwordScreen_.text = message.data.getPasswordString; | 437 this.passwordScreen_.text = message.data.getPasswordString; |
430 this.progressBar_.text = message.data.loadingString; | 438 this.progressBar_.text = message.data.loadingString; |
431 if (!this.isPrintPreview_) | 439 if (!this.isPrintPreview_) |
432 this.progressBar_.style.visibility = 'visible'; | 440 this.progressBar_.style.visibility = 'visible'; |
433 this.errorScreen_.text = message.data.loadFailedString; | 441 this.errorScreen_.text = message.data.loadFailedString; |
434 break; | 442 break; |
435 case 'cancelStreamUrl': | 443 case 'cancelStreamUrl': |
436 chrome.mimeHandlerPrivate.abortStream(); | 444 chrome.mimeHandlerPrivate.abortStream(); |
437 break; | 445 break; |
438 case 'bookmarks': | 446 case 'bookmarks': |
439 this.bookmarks_ = message.data.bookmarks; | 447 this.bookmarksPane.bookmarks = message.data.bookmarks; |
440 break; | 448 break; |
441 } | 449 } |
442 }, | 450 }, |
443 | 451 |
444 /** | 452 /** |
445 * @private | 453 * @private |
446 * A callback that's called before the zoom changes. Notify the plugin to stop | 454 * A callback that's called before the zoom changes. Notify the plugin to stop |
447 * reacting to scroll events while zoom is taking place to avoid flickering. | 455 * reacting to scroll events while zoom is taking place to avoid flickering. |
448 */ | 456 */ |
449 beforeZoom_: function() { | 457 beforeZoom_: function() { |
(...skipping 227 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
677 }, | 685 }, |
678 | 686 |
679 /** | 687 /** |
680 * Each bookmark is an Object containing a: | 688 * Each bookmark is an Object containing a: |
681 * - title | 689 * - title |
682 * - page (optional) | 690 * - page (optional) |
683 * - array of children (themselves bookmarks) | 691 * - array of children (themselves bookmarks) |
684 * @type {Array} the top-level bookmarks of the PDF. | 692 * @type {Array} the top-level bookmarks of the PDF. |
685 */ | 693 */ |
686 get bookmarks() { | 694 get bookmarks() { |
687 return this.bookmarks_; | 695 return this.bookmarksPane.bookmarks; |
Sam McNally
2015/01/28 03:04:30
Does this still work if !this.isMaterial_?
Alexandre Carlton
2015/01/28 07:16:52
Would it be best to return an empty list if !this.
| |
688 } | 696 } |
689 }; | 697 }; |
OLD | NEW |