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 if (this.isMaterial_) { | |
132 $('bookmarks-button').addEventListener('click', function() { | |
133 this.bookmarksPane.toggle(); | |
134 }.bind(this)); | |
135 } | |
126 | 136 |
127 // Setup the keyboard event listener. | 137 // Setup the keyboard event listener. |
128 document.onkeydown = this.handleKeyEvent_.bind(this); | 138 document.onkeydown = this.handleKeyEvent_.bind(this); |
129 | 139 |
130 // Set up the zoom API. | 140 // Set up the zoom API. |
131 if (this.shouldManageZoom_()) { | 141 if (this.shouldManageZoom_()) { |
132 chrome.tabs.setZoomSettings(this.streamDetails_.tabId, | 142 chrome.tabs.setZoomSettings(this.streamDetails_.tabId, |
133 {mode: 'manual', scope: 'per-tab'}, | 143 {mode: 'manual', scope: 'per-tab'}, |
134 this.afterZoom_.bind(this)); | 144 this.afterZoom_.bind(this)); |
135 chrome.tabs.onZoomChange.addListener(function(zoomChangeInfo) { | 145 chrome.tabs.onZoomChange.addListener(function(zoomChangeInfo) { |
(...skipping 235 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
371 handlePluginMessage_: function(message) { | 381 handlePluginMessage_: function(message) { |
372 switch (message.data.type.toString()) { | 382 switch (message.data.type.toString()) { |
373 case 'documentDimensions': | 383 case 'documentDimensions': |
374 this.documentDimensions_ = message.data; | 384 this.documentDimensions_ = message.data; |
375 this.viewport_.setDocumentDimensions(this.documentDimensions_); | 385 this.viewport_.setDocumentDimensions(this.documentDimensions_); |
376 // If we received the document dimensions, the password was good so we | 386 // If we received the document dimensions, the password was good so we |
377 // can dismiss the password screen. | 387 // can dismiss the password screen. |
378 if (this.passwordScreen_.active) | 388 if (this.passwordScreen_.active) |
379 this.passwordScreen_.accept(); | 389 this.passwordScreen_.accept(); |
380 | 390 |
381 this.pageIndicator_.initialFadeIn(); | 391 if (!this.isMaterial_) { |
382 this.toolbar_.initialFadeIn(); | 392 this.pageIndicator_.initialFadeIn(); |
393 this.toolbar_.initialFadeIn(); | |
Sam McNally
2015/01/30 06:30:04
Isn't the old toolbar still used for zoom?
Alexandre Carlton
2015/02/02 01:41:03
Done.
| |
394 } | |
383 break; | 395 break; |
384 case 'email': | 396 case 'email': |
385 var href = 'mailto:' + message.data.to + '?cc=' + message.data.cc + | 397 var href = 'mailto:' + message.data.to + '?cc=' + message.data.cc + |
386 '&bcc=' + message.data.bcc + '&subject=' + message.data.subject + | 398 '&bcc=' + message.data.bcc + '&subject=' + message.data.subject + |
387 '&body=' + message.data.body; | 399 '&body=' + message.data.body; |
388 window.location.href = href; | 400 window.location.href = href; |
389 break; | 401 break; |
390 case 'getAccessibilityJSONReply': | 402 case 'getAccessibilityJSONReply': |
391 this.sendScriptingMessage_(message.data); | 403 this.sendScriptingMessage_(message.data); |
392 break; | 404 break; |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
430 this.progressBar_.text = message.data.loadingString; | 442 this.progressBar_.text = message.data.loadingString; |
431 if (!this.isPrintPreview_) | 443 if (!this.isPrintPreview_) |
432 this.progressBar_.style.visibility = 'visible'; | 444 this.progressBar_.style.visibility = 'visible'; |
433 this.errorScreen_.text = message.data.loadFailedString; | 445 this.errorScreen_.text = message.data.loadFailedString; |
434 break; | 446 break; |
435 case 'cancelStreamUrl': | 447 case 'cancelStreamUrl': |
436 chrome.mimeHandlerPrivate.abortStream(); | 448 chrome.mimeHandlerPrivate.abortStream(); |
437 break; | 449 break; |
438 case 'bookmarks': | 450 case 'bookmarks': |
439 this.bookmarks_ = message.data.bookmarks; | 451 this.bookmarks_ = message.data.bookmarks; |
452 this.bookmarksPane.bookmarks = message.data.bookmarks; | |
440 break; | 453 break; |
441 } | 454 } |
442 }, | 455 }, |
443 | 456 |
444 /** | 457 /** |
445 * @private | 458 * @private |
446 * A callback that's called before the zoom changes. Notify the plugin to stop | 459 * 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. | 460 * reacting to scroll events while zoom is taking place to avoid flickering. |
448 */ | 461 */ |
449 beforeZoom_: function() { | 462 beforeZoom_: function() { |
(...skipping 230 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
680 * Each bookmark is an Object containing a: | 693 * Each bookmark is an Object containing a: |
681 * - title | 694 * - title |
682 * - page (optional) | 695 * - page (optional) |
683 * - array of children (themselves bookmarks) | 696 * - array of children (themselves bookmarks) |
684 * @type {Array} the top-level bookmarks of the PDF. | 697 * @type {Array} the top-level bookmarks of the PDF. |
685 */ | 698 */ |
686 get bookmarks() { | 699 get bookmarks() { |
687 return this.bookmarks_; | 700 return this.bookmarks_; |
688 } | 701 } |
689 }; | 702 }; |
OLD | NEW |