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