| 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 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 68 activeElement.tagName == 'TEXTAREA'); | 68 activeElement.tagName == 'TEXTAREA'); |
| 69 } | 69 } |
| 70 | 70 |
| 71 /** | 71 /** |
| 72 * The minimum number of pixels to offset the toolbar by from the bottom and | 72 * The minimum number of pixels to offset the toolbar by from the bottom and |
| 73 * right side of the screen. | 73 * right side of the screen. |
| 74 */ | 74 */ |
| 75 PDFViewer.MIN_TOOLBAR_OFFSET = 15; | 75 PDFViewer.MIN_TOOLBAR_OFFSET = 15; |
| 76 | 76 |
| 77 /** | 77 /** |
| 78 * The height of the toolbar along the top of the page. The document will be | |
| 79 * shifted down by this much in the viewport. | |
| 80 */ | |
| 81 PDFViewer.MATERIAL_TOOLBAR_HEIGHT = 64; | |
| 82 | |
| 83 /** | |
| 84 * Creates a new PDFViewer. There should only be one of these objects per | 78 * Creates a new PDFViewer. There should only be one of these objects per |
| 85 * document. | 79 * document. |
| 86 * @constructor | 80 * @constructor |
| 87 * @param {!BrowserApi} browserApi An object providing an API to the browser. | 81 * @param {!BrowserApi} browserApi An object providing an API to the browser. |
| 88 */ | 82 */ |
| 89 function PDFViewer(browserApi) { | 83 function PDFViewer(browserApi) { |
| 90 this.browserApi_ = browserApi; | 84 this.browserApi_ = browserApi; |
| 91 this.loadState_ = LoadState.LOADING; | 85 this.loadState_ = LoadState.LOADING; |
| 92 this.parentWindow_ = null; | 86 this.parentWindow_ = null; |
| 93 | 87 |
| 94 this.delayedScriptingMessages_ = []; | 88 this.delayedScriptingMessages_ = []; |
| 95 | 89 |
| 96 this.isPrintPreview_ = this.browserApi_.getStreamInfo().originalUrl.indexOf( | 90 this.isPrintPreview_ = this.browserApi_.getStreamInfo().originalUrl.indexOf( |
| 97 'chrome://print') == 0; | 91 'chrome://print') == 0; |
| 98 this.isMaterial_ = location.pathname.substring(1) === 'index-material.html'; | 92 this.isMaterial_ = location.pathname.substring(1) === 'index-material.html'; |
| 99 | 93 |
| 100 // The sizer element is placed behind the plugin element to cause scrollbars | 94 // The sizer element is placed behind the plugin element to cause scrollbars |
| 101 // to be displayed in the window. It is sized according to the document size | 95 // to be displayed in the window. It is sized according to the document size |
| 102 // of the pdf and zoom level. | 96 // of the pdf and zoom level. |
| 103 this.sizer_ = $('sizer'); | 97 this.sizer_ = $('sizer'); |
| 104 this.toolbar_ = $('toolbar'); | 98 this.toolbar_ = $('toolbar'); |
| 105 this.pageIndicator_ = $('page-indicator'); | 99 this.pageIndicator_ = $('page-indicator'); |
| 106 this.progressBar_ = $('progress-bar'); | 100 this.progressBar_ = $('progress-bar'); |
| 107 this.passwordScreen_ = $('password-screen'); | 101 this.passwordScreen_ = $('password-screen'); |
| 108 this.passwordScreen_.addEventListener('password-submitted', | 102 this.passwordScreen_.addEventListener('password-submitted', |
| 109 this.onPasswordSubmitted_.bind(this)); | 103 this.onPasswordSubmitted_.bind(this)); |
| 110 this.errorScreen_ = $('error-screen'); | 104 this.errorScreen_ = $('error-screen'); |
| 111 | 105 |
| 112 // Create the viewport. | 106 // Create the viewport. |
| 113 var topToolbarHeight = | |
| 114 this.isMaterial_ ? PDFViewer.MATERIAL_TOOLBAR_HEIGHT : 0; | |
| 115 this.viewport_ = new Viewport(window, | 107 this.viewport_ = new Viewport(window, |
| 116 this.sizer_, | 108 this.sizer_, |
| 117 this.viewportChanged_.bind(this), | 109 this.viewportChanged_.bind(this), |
| 118 this.beforeZoom_.bind(this), | 110 this.beforeZoom_.bind(this), |
| 119 this.afterZoom_.bind(this), | 111 this.afterZoom_.bind(this), |
| 120 getScrollbarWidth(), | 112 getScrollbarWidth(), |
| 121 this.browserApi_.getDefaultZoom(), | 113 this.browserApi_.getDefaultZoom()); |
| 122 topToolbarHeight); | |
| 123 | 114 |
| 124 // Create the plugin object dynamically so we can set its src. The plugin | 115 // Create the plugin object dynamically so we can set its src. The plugin |
| 125 // element is sized to fill the entire window and is set to be fixed | 116 // element is sized to fill the entire window and is set to be fixed |
| 126 // positioning, acting as a viewport. The plugin renders into this viewport | 117 // positioning, acting as a viewport. The plugin renders into this viewport |
| 127 // according to the scroll position of the window. | 118 // according to the scroll position of the window. |
| 128 this.plugin_ = document.createElement('embed'); | 119 this.plugin_ = document.createElement('embed'); |
| 129 // NOTE: The plugin's 'id' field must be set to 'plugin' since | 120 // NOTE: The plugin's 'id' field must be set to 'plugin' since |
| 130 // chrome/renderer/printing/print_web_view_helper.cc actually references it. | 121 // chrome/renderer/printing/print_web_view_helper.cc actually references it. |
| 131 this.plugin_.id = 'plugin'; | 122 this.plugin_.id = 'plugin'; |
| 132 this.plugin_.type = 'application/x-google-chrome-pdf'; | 123 this.plugin_.type = 'application/x-google-chrome-pdf'; |
| (...skipping 12 matching lines...) Expand all Loading... |
| 145 this.browserApi_.getStreamInfo().originalUrl); | 136 this.browserApi_.getStreamInfo().originalUrl); |
| 146 this.plugin_.setAttribute('stream-url', | 137 this.plugin_.setAttribute('stream-url', |
| 147 this.browserApi_.getStreamInfo().streamUrl); | 138 this.browserApi_.getStreamInfo().streamUrl); |
| 148 var headers = ''; | 139 var headers = ''; |
| 149 for (var header in this.browserApi_.getStreamInfo().responseHeaders) { | 140 for (var header in this.browserApi_.getStreamInfo().responseHeaders) { |
| 150 headers += header + ': ' + | 141 headers += header + ': ' + |
| 151 this.browserApi_.getStreamInfo().responseHeaders[header] + '\n'; | 142 this.browserApi_.getStreamInfo().responseHeaders[header] + '\n'; |
| 152 } | 143 } |
| 153 this.plugin_.setAttribute('headers', headers); | 144 this.plugin_.setAttribute('headers', headers); |
| 154 | 145 |
| 155 if (this.isMaterial_) { | 146 if (this.isMaterial_) |
| 156 this.plugin_.setAttribute('is-material', ''); | 147 this.plugin_.setAttribute('is-material', ''); |
| 157 this.plugin_.setAttribute('top-toolbar-height', | |
| 158 PDFViewer.MATERIAL_TOOLBAR_HEIGHT); | |
| 159 } | |
| 160 | 148 |
| 161 if (!this.browserApi_.getStreamInfo().embedded) | 149 if (!this.browserApi_.getStreamInfo().embedded) |
| 162 this.plugin_.setAttribute('full-frame', ''); | 150 this.plugin_.setAttribute('full-frame', ''); |
| 163 document.body.appendChild(this.plugin_); | 151 document.body.appendChild(this.plugin_); |
| 164 | 152 |
| 165 // Setup the button event listeners. | 153 // Setup the button event listeners. |
| 166 if (!this.isMaterial_) { | 154 if (!this.isMaterial_) { |
| 167 $('fit-to-width-button').addEventListener('click', | 155 $('fit-to-width-button').addEventListener('click', |
| 168 this.viewport_.fitToWidth.bind(this.viewport_)); | 156 this.viewport_.fitToWidth.bind(this.viewport_)); |
| 169 $('fit-to-page-button').addEventListener('click', | 157 $('fit-to-page-button').addEventListener('click', |
| (...skipping 647 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 817 * Each bookmark is an Object containing a: | 805 * Each bookmark is an Object containing a: |
| 818 * - title | 806 * - title |
| 819 * - page (optional) | 807 * - page (optional) |
| 820 * - array of children (themselves bookmarks) | 808 * - array of children (themselves bookmarks) |
| 821 * @type {Array} the top-level bookmarks of the PDF. | 809 * @type {Array} the top-level bookmarks of the PDF. |
| 822 */ | 810 */ |
| 823 get bookmarks() { | 811 get bookmarks() { |
| 824 return this.bookmarks_; | 812 return this.bookmarks_; |
| 825 } | 813 } |
| 826 }; | 814 }; |
| OLD | NEW |