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 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
44 * an editable element has focus, to allow for proper editing controls. | 44 * an editable element has focus, to allow for proper editing controls. |
45 * @param {HTMLElement} activeElement The currently selected DOM node. | 45 * @param {HTMLElement} activeElement The currently selected DOM node. |
46 * @return {boolean} True if keydown events should be ignored. | 46 * @return {boolean} True if keydown events should be ignored. |
47 */ | 47 */ |
48 function shouldIgnoreKeyEvents(activeElement) { | 48 function shouldIgnoreKeyEvents(activeElement) { |
49 while (activeElement.shadowRoot != null && | 49 while (activeElement.shadowRoot != null && |
50 activeElement.shadowRoot.activeElement != null) { | 50 activeElement.shadowRoot.activeElement != null) { |
51 activeElement = activeElement.shadowRoot.activeElement; | 51 activeElement = activeElement.shadowRoot.activeElement; |
52 } | 52 } |
53 | 53 |
54 return (activeElement.isContentEditable || | 54 return ( |
55 activeElement.tagName == 'INPUT' || | 55 activeElement.isContentEditable || activeElement.tagName == 'INPUT' || |
56 activeElement.tagName == 'TEXTAREA'); | 56 activeElement.tagName == 'TEXTAREA'); |
57 } | 57 } |
58 | 58 |
59 /** | 59 /** |
60 * The minimum number of pixels to offset the toolbar by from the bottom and | 60 * The minimum number of pixels to offset the toolbar by from the bottom and |
61 * right side of the screen. | 61 * right side of the screen. |
62 */ | 62 */ |
63 PDFViewer.MIN_TOOLBAR_OFFSET = 15; | 63 PDFViewer.MIN_TOOLBAR_OFFSET = 15; |
64 | 64 |
65 /** | 65 /** |
66 * The height of the toolbar along the top of the page. The document will be | 66 * The height of the toolbar along the top of the page. The document will be |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
110 this.paramsParser_.getUiUrlParams(this.originalUrl_).toolbar && | 110 this.paramsParser_.getUiUrlParams(this.originalUrl_).toolbar && |
111 !this.isPrintPreview_; | 111 !this.isPrintPreview_; |
112 | 112 |
113 // The sizer element is placed behind the plugin element to cause scrollbars | 113 // The sizer element is placed behind the plugin element to cause scrollbars |
114 // to be displayed in the window. It is sized according to the document size | 114 // to be displayed in the window. It is sized according to the document size |
115 // of the pdf and zoom level. | 115 // of the pdf and zoom level. |
116 this.sizer_ = $('sizer'); | 116 this.sizer_ = $('sizer'); |
117 if (this.isPrintPreview_) | 117 if (this.isPrintPreview_) |
118 this.pageIndicator_ = $('page-indicator'); | 118 this.pageIndicator_ = $('page-indicator'); |
119 this.passwordScreen_ = $('password-screen'); | 119 this.passwordScreen_ = $('password-screen'); |
120 this.passwordScreen_.addEventListener('password-submitted', | 120 this.passwordScreen_.addEventListener( |
121 this.onPasswordSubmitted_.bind(this)); | 121 'password-submitted', this.onPasswordSubmitted_.bind(this)); |
122 this.errorScreen_ = $('error-screen'); | 122 this.errorScreen_ = $('error-screen'); |
123 // Can only reload if we are in a normal tab. | 123 // Can only reload if we are in a normal tab. |
124 if (chrome.tabs && this.browserApi_.getStreamInfo().tabId != -1) { | 124 if (chrome.tabs && this.browserApi_.getStreamInfo().tabId != -1) { |
125 this.errorScreen_.reloadFn = function() { | 125 this.errorScreen_.reloadFn = function() { |
126 chrome.tabs.reload(this.browserApi_.getStreamInfo().tabId); | 126 chrome.tabs.reload(this.browserApi_.getStreamInfo().tabId); |
127 }.bind(this); | 127 }.bind(this); |
128 } | 128 } |
129 | 129 |
130 // Create the viewport. | 130 // Create the viewport. |
131 var shortWindow = window.innerHeight < PDFViewer.TOOLBAR_WINDOW_MIN_HEIGHT; | 131 var shortWindow = window.innerHeight < PDFViewer.TOOLBAR_WINDOW_MIN_HEIGHT; |
132 var topToolbarHeight = | 132 var topToolbarHeight = |
133 (toolbarEnabled) ? PDFViewer.MATERIAL_TOOLBAR_HEIGHT : 0; | 133 (toolbarEnabled) ? PDFViewer.MATERIAL_TOOLBAR_HEIGHT : 0; |
134 var defaultZoom = | 134 var defaultZoom = |
135 this.browserApi_.getZoomBehavior() == BrowserApi.ZoomBehavior.MANAGE ? | 135 this.browserApi_.getZoomBehavior() == BrowserApi.ZoomBehavior.MANAGE ? |
136 this.browserApi_.getDefaultZoom() : 1.0; | 136 this.browserApi_.getDefaultZoom() : |
137 this.viewport_ = new Viewport(window, | 137 1.0; |
138 this.sizer_, | 138 this.viewport_ = new Viewport( |
139 this.viewportChanged_.bind(this), | 139 window, this.sizer_, this.viewportChanged_.bind(this), |
140 this.beforeZoom_.bind(this), | 140 this.beforeZoom_.bind(this), this.afterZoom_.bind(this), |
141 this.afterZoom_.bind(this), | 141 getScrollbarWidth(), defaultZoom, topToolbarHeight); |
142 getScrollbarWidth(), | |
143 defaultZoom, | |
144 topToolbarHeight); | |
145 | 142 |
146 // Create the plugin object dynamically so we can set its src. The plugin | 143 // Create the plugin object dynamically so we can set its src. The plugin |
147 // element is sized to fill the entire window and is set to be fixed | 144 // element is sized to fill the entire window and is set to be fixed |
148 // positioning, acting as a viewport. The plugin renders into this viewport | 145 // positioning, acting as a viewport. The plugin renders into this viewport |
149 // according to the scroll position of the window. | 146 // according to the scroll position of the window. |
150 this.plugin_ = document.createElement('embed'); | 147 this.plugin_ = document.createElement('embed'); |
151 // NOTE: The plugin's 'id' field must be set to 'plugin' since | 148 // NOTE: The plugin's 'id' field must be set to 'plugin' since |
152 // chrome/renderer/printing/print_web_view_helper.cc actually references it. | 149 // chrome/renderer/printing/print_web_view_helper.cc actually references it. |
153 this.plugin_.id = 'plugin'; | 150 this.plugin_.id = 'plugin'; |
154 this.plugin_.type = 'application/x-google-chrome-pdf'; | 151 this.plugin_.type = 'application/x-google-chrome-pdf'; |
155 this.plugin_.addEventListener('message', this.handlePluginMessage_.bind(this), | 152 this.plugin_.addEventListener( |
156 false); | 153 'message', this.handlePluginMessage_.bind(this), false); |
157 | 154 |
158 // Handle scripting messages from outside the extension that wish to interact | 155 // Handle scripting messages from outside the extension that wish to interact |
159 // with it. We also send a message indicating that extension has loaded and | 156 // with it. We also send a message indicating that extension has loaded and |
160 // is ready to receive messages. | 157 // is ready to receive messages. |
161 window.addEventListener('message', this.handleScriptingMessage.bind(this), | 158 window.addEventListener( |
162 false); | 159 'message', this.handleScriptingMessage.bind(this), false); |
163 | 160 |
164 this.plugin_.setAttribute('src', this.originalUrl_); | 161 this.plugin_.setAttribute('src', this.originalUrl_); |
165 this.plugin_.setAttribute('stream-url', | 162 this.plugin_.setAttribute( |
166 this.browserApi_.getStreamInfo().streamUrl); | 163 'stream-url', this.browserApi_.getStreamInfo().streamUrl); |
167 var headers = ''; | 164 var headers = ''; |
168 for (var header in this.browserApi_.getStreamInfo().responseHeaders) { | 165 for (var header in this.browserApi_.getStreamInfo().responseHeaders) { |
169 headers += header + ': ' + | 166 headers += header + ': ' + |
170 this.browserApi_.getStreamInfo().responseHeaders[header] + '\n'; | 167 this.browserApi_.getStreamInfo().responseHeaders[header] + '\n'; |
171 } | 168 } |
172 this.plugin_.setAttribute('headers', headers); | 169 this.plugin_.setAttribute('headers', headers); |
173 | 170 |
174 var backgroundColor = PDFViewer.DARK_BACKGROUND_COLOR; | 171 var backgroundColor = PDFViewer.DARK_BACKGROUND_COLOR; |
175 this.plugin_.setAttribute('background-color', backgroundColor); | 172 this.plugin_.setAttribute('background-color', backgroundColor); |
176 this.plugin_.setAttribute('top-toolbar-height', topToolbarHeight); | 173 this.plugin_.setAttribute('top-toolbar-height', topToolbarHeight); |
177 | 174 |
178 if (this.browserApi_.getStreamInfo().embedded) { | 175 if (this.browserApi_.getStreamInfo().embedded) { |
179 this.plugin_.setAttribute('top-level-url', | 176 this.plugin_.setAttribute( |
180 this.browserApi_.getStreamInfo().tabUrl); | 177 'top-level-url', this.browserApi_.getStreamInfo().tabUrl); |
181 } else { | 178 } else { |
182 this.plugin_.setAttribute('full-frame', ''); | 179 this.plugin_.setAttribute('full-frame', ''); |
183 } | 180 } |
184 document.body.appendChild(this.plugin_); | 181 document.body.appendChild(this.plugin_); |
185 | 182 |
186 // Setup the button event listeners. | 183 // Setup the button event listeners. |
187 this.zoomToolbar_ = $('zoom-toolbar'); | 184 this.zoomToolbar_ = $('zoom-toolbar'); |
188 this.zoomToolbar_.addEventListener('fit-to-width', | 185 this.zoomToolbar_.addEventListener( |
189 this.viewport_.fitToWidth.bind(this.viewport_)); | 186 'fit-to-width', this.viewport_.fitToWidth.bind(this.viewport_)); |
190 this.zoomToolbar_.addEventListener('fit-to-page', | 187 this.zoomToolbar_.addEventListener('fit-to-page', this.fitToPage_.bind(this)); |
191 this.fitToPage_.bind(this)); | 188 this.zoomToolbar_.addEventListener( |
192 this.zoomToolbar_.addEventListener('zoom-in', | 189 'zoom-in', this.viewport_.zoomIn.bind(this.viewport_)); |
193 this.viewport_.zoomIn.bind(this.viewport_)); | 190 this.zoomToolbar_.addEventListener( |
194 this.zoomToolbar_.addEventListener('zoom-out', | 191 'zoom-out', this.viewport_.zoomOut.bind(this.viewport_)); |
195 this.viewport_.zoomOut.bind(this.viewport_)); | |
196 | 192 |
197 this.gestureDetector_ = new GestureDetector(this.plugin_); | 193 this.gestureDetector_ = new GestureDetector(this.plugin_); |
198 this.gestureDetector_.addEventListener( | 194 this.gestureDetector_.addEventListener( |
199 'pinchstart', this.viewport_.pinchZoomStart.bind(this.viewport_)); | 195 'pinchstart', this.viewport_.pinchZoomStart.bind(this.viewport_)); |
200 this.sentPinchEvent_ = false; | 196 this.sentPinchEvent_ = false; |
201 this.gestureDetector_.addEventListener( | 197 this.gestureDetector_.addEventListener( |
202 'pinchupdate', this.onPinchUpdate_.bind(this)); | 198 'pinchupdate', this.onPinchUpdate_.bind(this)); |
203 this.gestureDetector_.addEventListener( | 199 this.gestureDetector_.addEventListener( |
204 'pinchend', this.onPinchEnd_.bind(this)); | 200 'pinchend', this.onPinchEnd_.bind(this)); |
205 | 201 |
206 if (toolbarEnabled) { | 202 if (toolbarEnabled) { |
207 this.toolbar_ = $('toolbar'); | 203 this.toolbar_ = $('toolbar'); |
208 this.toolbar_.hidden = false; | 204 this.toolbar_.hidden = false; |
209 this.toolbar_.addEventListener('save', this.save_.bind(this)); | 205 this.toolbar_.addEventListener('save', this.save_.bind(this)); |
210 this.toolbar_.addEventListener('print', this.print_.bind(this)); | 206 this.toolbar_.addEventListener('print', this.print_.bind(this)); |
211 this.toolbar_.addEventListener('rotate-right', | 207 this.toolbar_.addEventListener( |
212 this.rotateClockwise_.bind(this)); | 208 'rotate-right', this.rotateClockwise_.bind(this)); |
213 // Must attach to mouseup on the plugin element, since it eats mousedown | 209 // Must attach to mouseup on the plugin element, since it eats mousedown |
214 // and click events. | 210 // and click events. |
215 this.plugin_.addEventListener('mouseup', | 211 this.plugin_.addEventListener( |
216 this.toolbar_.hideDropdowns.bind(this.toolbar_)); | 212 'mouseup', this.toolbar_.hideDropdowns.bind(this.toolbar_)); |
217 | 213 |
218 this.toolbar_.docTitle = getFilenameFromURL(this.originalUrl_); | 214 this.toolbar_.docTitle = getFilenameFromURL(this.originalUrl_); |
219 } | 215 } |
220 | 216 |
221 document.body.addEventListener('change-page', function(e) { | 217 document.body.addEventListener('change-page', function(e) { |
222 this.viewport_.goToPage(e.detail.page); | 218 this.viewport_.goToPage(e.detail.page); |
223 }.bind(this)); | 219 }.bind(this)); |
224 | 220 |
225 document.body.addEventListener('navigate', function(e) { | 221 document.body.addEventListener('navigate', function(e) { |
226 var disposition = | 222 var disposition = e.detail.newtab ? |
227 e.detail.newtab ? Navigator.WindowOpenDisposition.NEW_BACKGROUND_TAB : | 223 Navigator.WindowOpenDisposition.NEW_BACKGROUND_TAB : |
228 Navigator.WindowOpenDisposition.CURRENT_TAB; | 224 Navigator.WindowOpenDisposition.CURRENT_TAB; |
229 this.navigator_.navigate(e.detail.uri, disposition); | 225 this.navigator_.navigate(e.detail.uri, disposition); |
230 }.bind(this)); | 226 }.bind(this)); |
231 | 227 |
232 this.toolbarManager_ = | 228 this.toolbarManager_ = |
233 new ToolbarManager(window, this.toolbar_, this.zoomToolbar_); | 229 new ToolbarManager(window, this.toolbar_, this.zoomToolbar_); |
234 | 230 |
235 // Set up the ZoomManager. | 231 // Set up the ZoomManager. |
236 this.zoomManager_ = ZoomManager.create( | 232 this.zoomManager_ = ZoomManager.create( |
237 this.browserApi_.getZoomBehavior(), this.viewport_, | 233 this.browserApi_.getZoomBehavior(), this.viewport_, |
238 this.browserApi_.setZoom.bind(this.browserApi_), | 234 this.browserApi_.setZoom.bind(this.browserApi_), |
239 this.browserApi_.getInitialZoom()); | 235 this.browserApi_.getInitialZoom()); |
240 this.viewport_.zoomManager = this.zoomManager_; | 236 this.viewport_.zoomManager = this.zoomManager_; |
241 this.browserApi_.addZoomEventListener( | 237 this.browserApi_.addZoomEventListener( |
242 this.zoomManager_.onBrowserZoomChange.bind(this.zoomManager_)); | 238 this.zoomManager_.onBrowserZoomChange.bind(this.zoomManager_)); |
243 | 239 |
244 // Setup the keyboard event listener. | 240 // Setup the keyboard event listener. |
245 document.addEventListener('keydown', this.handleKeyEvent_.bind(this)); | 241 document.addEventListener('keydown', this.handleKeyEvent_.bind(this)); |
246 document.addEventListener('mousemove', this.handleMouseEvent_.bind(this)); | 242 document.addEventListener('mousemove', this.handleMouseEvent_.bind(this)); |
247 document.addEventListener('mouseout', this.handleMouseEvent_.bind(this)); | 243 document.addEventListener('mouseout', this.handleMouseEvent_.bind(this)); |
248 document.addEventListener('contextmenu', | 244 document.addEventListener( |
249 this.handleContextMenuEvent_.bind(this)); | 245 'contextmenu', this.handleContextMenuEvent_.bind(this)); |
250 | 246 |
251 var tabId = this.browserApi_.getStreamInfo().tabId; | 247 var tabId = this.browserApi_.getStreamInfo().tabId; |
252 this.navigator_ = new Navigator( | 248 this.navigator_ = new Navigator( |
253 this.originalUrl_, this.viewport_, this.paramsParser_, | 249 this.originalUrl_, this.viewport_, this.paramsParser_, |
254 new NavigatorDelegate(tabId)); | 250 new NavigatorDelegate(tabId)); |
255 this.viewportScroller_ = | 251 this.viewportScroller_ = |
256 new ViewportScroller(this.viewport_, this.plugin_, window); | 252 new ViewportScroller(this.viewport_, this.plugin_, window); |
257 | 253 |
258 // Request translated strings. | 254 // Request translated strings. |
259 chrome.resourcesPrivate.getStrings('pdf', this.handleStrings_.bind(this)); | 255 chrome.resourcesPrivate.getStrings('pdf', this.handleStrings_.bind(this)); |
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
358 } | 354 } |
359 return; | 355 return; |
360 case 40: // Down arrow key. | 356 case 40: // Down arrow key. |
361 if (fromScriptingAPI) { | 357 if (fromScriptingAPI) { |
362 position.y += Viewport.SCROLL_INCREMENT; | 358 position.y += Viewport.SCROLL_INCREMENT; |
363 this.viewport.position = position; | 359 this.viewport.position = position; |
364 } | 360 } |
365 return; | 361 return; |
366 case 65: // 'a' key. | 362 case 65: // 'a' key. |
367 if (e.ctrlKey || e.metaKey) { | 363 if (e.ctrlKey || e.metaKey) { |
368 this.plugin_.postMessage({ | 364 this.plugin_.postMessage({type: 'selectAll'}); |
369 type: 'selectAll' | |
370 }); | |
371 // Since we do selection ourselves. | 365 // Since we do selection ourselves. |
372 e.preventDefault(); | 366 e.preventDefault(); |
373 } | 367 } |
374 return; | 368 return; |
375 case 71: // 'g' key. | 369 case 71: // 'g' key. |
376 if (this.toolbar_ && (e.ctrlKey || e.metaKey) && e.altKey) { | 370 if (this.toolbar_ && (e.ctrlKey || e.metaKey) && e.altKey) { |
377 this.toolbarManager_.showToolbars(); | 371 this.toolbarManager_.showToolbars(); |
378 this.toolbar_.selectPageNumber(); | 372 this.toolbar_.selectPageNumber(); |
379 } | 373 } |
380 return; | 374 return; |
381 case 219: // Left bracket key. | 375 case 219: // Left bracket key. |
382 if (e.ctrlKey) | 376 if (e.ctrlKey) |
383 this.rotateCounterClockwise_(); | 377 this.rotateCounterClockwise_(); |
384 return; | 378 return; |
385 case 220: // Backslash key. | 379 case 220: // Backslash key. |
386 if (e.ctrlKey) | 380 if (e.ctrlKey) |
387 this.zoomToolbar_.fitToggleFromHotKey(); | 381 this.zoomToolbar_.fitToggleFromHotKey(); |
388 return; | 382 return; |
389 case 221: // Right bracket key. | 383 case 221: // Right bracket key. |
390 if (e.ctrlKey) | 384 if (e.ctrlKey) |
391 this.rotateClockwise_(); | 385 this.rotateClockwise_(); |
392 return; | 386 return; |
393 } | 387 } |
394 | 388 |
395 // Give print preview a chance to handle the key event. | 389 // Give print preview a chance to handle the key event. |
396 if (!fromScriptingAPI && this.isPrintPreview_) { | 390 if (!fromScriptingAPI && this.isPrintPreview_) { |
397 this.sendScriptingMessage_({ | 391 this.sendScriptingMessage_( |
398 type: 'sendKeyEvent', | 392 {type: 'sendKeyEvent', keyEvent: SerializeKeyEvent(e)}); |
399 keyEvent: SerializeKeyEvent(e) | |
400 }); | |
401 } else { | 393 } else { |
402 // Show toolbars as a fallback. | 394 // Show toolbars as a fallback. |
403 if (!(e.shiftKey || e.ctrlKey || e.altKey)) | 395 if (!(e.shiftKey || e.ctrlKey || e.altKey)) |
404 this.toolbarManager_.showToolbars(); | 396 this.toolbarManager_.showToolbars(); |
405 } | 397 } |
406 }, | 398 }, |
407 | 399 |
408 handleMouseEvent_: function(e) { | 400 handleMouseEvent_: function(e) { |
409 if (e.type == 'mousemove') | 401 if (e.type == 'mousemove') |
410 this.toolbarManager_.handleMouseMove(e); | 402 this.toolbarManager_.handleMouseMove(e); |
(...skipping 10 matching lines...) Expand all Loading... |
421 !this.gestureDetector_.wasTwoFingerTouch()) { | 413 !this.gestureDetector_.wasTwoFingerTouch()) { |
422 e.preventDefault(); | 414 e.preventDefault(); |
423 } | 415 } |
424 }, | 416 }, |
425 | 417 |
426 /** | 418 /** |
427 * @private | 419 * @private |
428 * Rotate the plugin clockwise. | 420 * Rotate the plugin clockwise. |
429 */ | 421 */ |
430 rotateClockwise_: function() { | 422 rotateClockwise_: function() { |
431 this.plugin_.postMessage({ | 423 this.plugin_.postMessage({type: 'rotateClockwise'}); |
432 type: 'rotateClockwise' | |
433 }); | |
434 }, | 424 }, |
435 | 425 |
436 /** | 426 /** |
437 * @private | 427 * @private |
438 * Rotate the plugin counter-clockwise. | 428 * Rotate the plugin counter-clockwise. |
439 */ | 429 */ |
440 rotateCounterClockwise_: function() { | 430 rotateCounterClockwise_: function() { |
441 this.plugin_.postMessage({ | 431 this.plugin_.postMessage({type: 'rotateCounterclockwise'}); |
442 type: 'rotateCounterclockwise' | |
443 }); | |
444 }, | 432 }, |
445 | 433 |
446 /** | 434 /** |
447 * @private | 435 * @private |
448 * Set zoom to "fit to page". | 436 * Set zoom to "fit to page". |
449 */ | 437 */ |
450 fitToPage_: function() { | 438 fitToPage_: function() { |
451 this.viewport_.fitToPage(); | 439 this.viewport_.fitToPage(); |
452 this.toolbarManager_.forceHideTopToolbar(); | 440 this.toolbarManager_.forceHideTopToolbar(); |
453 }, | 441 }, |
454 | 442 |
455 /** | 443 /** |
456 * @private | 444 * @private |
457 * Notify the plugin to print. | 445 * Notify the plugin to print. |
458 */ | 446 */ |
459 print_: function() { | 447 print_: function() { |
460 this.plugin_.postMessage({ | 448 this.plugin_.postMessage({type: 'print'}); |
461 type: 'print' | |
462 }); | |
463 }, | 449 }, |
464 | 450 |
465 /** | 451 /** |
466 * @private | 452 * @private |
467 * Notify the plugin to save. | 453 * Notify the plugin to save. |
468 */ | 454 */ |
469 save_: function() { | 455 save_: function() { |
470 this.plugin_.postMessage({ | 456 this.plugin_.postMessage({type: 'save'}); |
471 type: 'save' | |
472 }); | |
473 }, | 457 }, |
474 | 458 |
475 /** | 459 /** |
476 * Fetches the page number corresponding to the given named destination from | 460 * Fetches the page number corresponding to the given named destination from |
477 * the plugin. | 461 * the plugin. |
478 * @param {string} name The namedDestination to fetch page number from plugin. | 462 * @param {string} name The namedDestination to fetch page number from plugin. |
479 */ | 463 */ |
480 getNamedDestination_: function(name) { | 464 getNamedDestination_: function(name) { |
481 this.plugin_.postMessage({ | 465 this.plugin_.postMessage( |
482 type: 'getNamedDestination', | 466 {type: 'getNamedDestination', namedDestination: name}); |
483 namedDestination: name | |
484 }); | |
485 }, | 467 }, |
486 | 468 |
487 /** | 469 /** |
488 * @private | 470 * @private |
489 * Sends a 'documentLoaded' message to the PDFScriptingAPI if the document has | 471 * Sends a 'documentLoaded' message to the PDFScriptingAPI if the document has |
490 * finished loading. | 472 * finished loading. |
491 */ | 473 */ |
492 sendDocumentLoadedMessage_: function() { | 474 sendDocumentLoadedMessage_: function() { |
493 if (this.loadState_ == LoadState.LOADING) | 475 if (this.loadState_ == LoadState.LOADING) |
494 return; | 476 return; |
495 this.sendScriptingMessage_({ | 477 this.sendScriptingMessage_( |
496 type: 'documentLoaded', | 478 {type: 'documentLoaded', load_state: this.loadState_}); |
497 load_state: this.loadState_ | |
498 }); | |
499 }, | 479 }, |
500 | 480 |
501 /** | 481 /** |
502 * @private | 482 * @private |
503 * Handle open pdf parameters. This function updates the viewport as per | 483 * Handle open pdf parameters. This function updates the viewport as per |
504 * the parameters mentioned in the url while opening pdf. The order is | 484 * the parameters mentioned in the url while opening pdf. The order is |
505 * important as later actions can override the effects of previous actions. | 485 * important as later actions can override the effects of previous actions. |
506 * @param {Object} viewportPosition The initial position of the viewport to be | 486 * @param {Object} viewportPosition The initial position of the viewport to be |
507 * displayed. | 487 * displayed. |
508 */ | 488 */ |
(...skipping 29 matching lines...) Expand all Loading... |
538 this.passwordScreen_.deny(); | 518 this.passwordScreen_.deny(); |
539 this.passwordScreen_.close(); | 519 this.passwordScreen_.close(); |
540 } | 520 } |
541 this.loadState_ = LoadState.FAILED; | 521 this.loadState_ = LoadState.FAILED; |
542 this.sendDocumentLoadedMessage_(); | 522 this.sendDocumentLoadedMessage_(); |
543 } else if (progress == 100) { | 523 } else if (progress == 100) { |
544 // Document load complete. | 524 // Document load complete. |
545 if (this.lastViewportPosition_) | 525 if (this.lastViewportPosition_) |
546 this.viewport_.position = this.lastViewportPosition_; | 526 this.viewport_.position = this.lastViewportPosition_; |
547 this.paramsParser_.getViewportFromUrlParams( | 527 this.paramsParser_.getViewportFromUrlParams( |
548 this.originalUrl_, | 528 this.originalUrl_, this.handleURLParams_.bind(this)); |
549 this.handleURLParams_.bind(this)); | |
550 this.loadState_ = LoadState.SUCCESS; | 529 this.loadState_ = LoadState.SUCCESS; |
551 this.sendDocumentLoadedMessage_(); | 530 this.sendDocumentLoadedMessage_(); |
552 while (this.delayedScriptingMessages_.length > 0) | 531 while (this.delayedScriptingMessages_.length > 0) |
553 this.handleScriptingMessage(this.delayedScriptingMessages_.shift()); | 532 this.handleScriptingMessage(this.delayedScriptingMessages_.shift()); |
554 | 533 |
555 this.toolbarManager_.hideToolbarsAfterTimeout(); | 534 this.toolbarManager_.hideToolbarsAfterTimeout(); |
556 } | 535 } |
557 }, | 536 }, |
558 | 537 |
559 /** | 538 /** |
(...skipping 12 matching lines...) Expand all Loading... |
572 $('error-screen').strings = strings; | 551 $('error-screen').strings = strings; |
573 }, | 552 }, |
574 | 553 |
575 /** | 554 /** |
576 * @private | 555 * @private |
577 * An event handler for handling password-submitted events. These are fired | 556 * An event handler for handling password-submitted events. These are fired |
578 * when an event is entered into the password screen. | 557 * when an event is entered into the password screen. |
579 * @param {Object} event a password-submitted event. | 558 * @param {Object} event a password-submitted event. |
580 */ | 559 */ |
581 onPasswordSubmitted_: function(event) { | 560 onPasswordSubmitted_: function(event) { |
582 this.plugin_.postMessage({ | 561 this.plugin_.postMessage( |
583 type: 'getPasswordComplete', | 562 {type: 'getPasswordComplete', password: event.detail.password}); |
584 password: event.detail.password | |
585 }); | |
586 }, | 563 }, |
587 | 564 |
588 /** | 565 /** |
589 * @private | 566 * @private |
590 * An event handler for handling message events received from the plugin. | 567 * An event handler for handling message events received from the plugin. |
591 * @param {MessageObject} message a message event. | 568 * @param {MessageObject} message a message event. |
592 */ | 569 */ |
593 handlePluginMessage_: function(message) { | 570 handlePluginMessage_: function(message) { |
594 switch (message.data.type.toString()) { | 571 switch (message.data.type.toString()) { |
595 case 'documentDimensions': | 572 case 'documentDimensions': |
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
675 break; | 652 break; |
676 } | 653 } |
677 }, | 654 }, |
678 | 655 |
679 /** | 656 /** |
680 * @private | 657 * @private |
681 * A callback that's called before the zoom changes. Notify the plugin to stop | 658 * A callback that's called before the zoom changes. Notify the plugin to stop |
682 * reacting to scroll events while zoom is taking place to avoid flickering. | 659 * reacting to scroll events while zoom is taking place to avoid flickering. |
683 */ | 660 */ |
684 beforeZoom_: function() { | 661 beforeZoom_: function() { |
685 this.plugin_.postMessage({ | 662 this.plugin_.postMessage({type: 'stopScrolling'}); |
686 type: 'stopScrolling' | |
687 }); | |
688 | 663 |
689 if (this.viewport_.pinchPhase == Viewport.PinchPhase.PINCH_START) { | 664 if (this.viewport_.pinchPhase == Viewport.PinchPhase.PINCH_START) { |
690 var position = this.viewport_.position; | 665 var position = this.viewport_.position; |
691 var zoom = this.viewport_.zoom; | 666 var zoom = this.viewport_.zoom; |
692 var pinchPhase = this.viewport_.pinchPhase; | 667 var pinchPhase = this.viewport_.pinchPhase; |
693 this.plugin_.postMessage({ | 668 this.plugin_.postMessage({ |
694 type: 'viewport', | 669 type: 'viewport', |
695 zoom: zoom, | 670 zoom: zoom, |
696 xOffset: position.x, | 671 xOffset: position.x, |
697 yOffset: position.y, | 672 yOffset: position.y, |
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
770 var horizontalScrollbarWidth = | 745 var horizontalScrollbarWidth = |
771 hasScrollbars.horizontal ? scrollbarWidth : 0; | 746 hasScrollbars.horizontal ? scrollbarWidth : 0; |
772 | 747 |
773 // Shift the zoom toolbar to the left by half a scrollbar width. This | 748 // Shift the zoom toolbar to the left by half a scrollbar width. This |
774 // gives a compromise: if there is no scrollbar visible then the toolbar | 749 // gives a compromise: if there is no scrollbar visible then the toolbar |
775 // will be half a scrollbar width further left than the spec but if there | 750 // will be half a scrollbar width further left than the spec but if there |
776 // is a scrollbar visible it will be half a scrollbar width further right | 751 // is a scrollbar visible it will be half a scrollbar width further right |
777 // than the spec. In RTL layout, the zoom toolbar is on the left side, but | 752 // than the spec. In RTL layout, the zoom toolbar is on the left side, but |
778 // the scrollbar is still on the right, so this is not necessary. | 753 // the scrollbar is still on the right, so this is not necessary. |
779 if (!isRTL()) { | 754 if (!isRTL()) { |
780 this.zoomToolbar_.style.right = -verticalScrollbarWidth + | 755 this.zoomToolbar_.style.right = |
781 (scrollbarWidth / 2) + 'px'; | 756 -verticalScrollbarWidth + (scrollbarWidth / 2) + 'px'; |
782 } | 757 } |
783 // Having a horizontal scrollbar is much rarer so we don't offset the | 758 // Having a horizontal scrollbar is much rarer so we don't offset the |
784 // toolbar from the bottom any more than what the spec says. This means | 759 // toolbar from the bottom any more than what the spec says. This means |
785 // that when there is a scrollbar visible, it will be a full scrollbar | 760 // that when there is a scrollbar visible, it will be a full scrollbar |
786 // width closer to the bottom of the screen than usual, but this is ok. | 761 // width closer to the bottom of the screen than usual, but this is ok. |
787 this.zoomToolbar_.style.bottom = -horizontalScrollbarWidth + 'px'; | 762 this.zoomToolbar_.style.bottom = -horizontalScrollbarWidth + 'px'; |
788 | 763 |
789 // Update the page indicator. | 764 // Update the page indicator. |
790 var visiblePage = this.viewport_.getMostVisiblePage(); | 765 var visiblePage = this.viewport_.getMostVisiblePage(); |
791 | 766 |
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
883 saveButton.parentNode.removeChild(saveButton); | 858 saveButton.parentNode.removeChild(saveButton); |
884 | 859 |
885 this.pageIndicator_.pageLabels = message.data.pageNumbers; | 860 this.pageIndicator_.pageLabels = message.data.pageNumbers; |
886 | 861 |
887 this.plugin_.postMessage({ | 862 this.plugin_.postMessage({ |
888 type: 'resetPrintPreviewMode', | 863 type: 'resetPrintPreviewMode', |
889 url: message.data.url, | 864 url: message.data.url, |
890 grayscale: message.data.grayscale, | 865 grayscale: message.data.grayscale, |
891 // If the PDF isn't modifiable we send 0 as the page count so that no | 866 // If the PDF isn't modifiable we send 0 as the page count so that no |
892 // blank placeholder pages get appended to the PDF. | 867 // blank placeholder pages get appended to the PDF. |
893 pageCount: (message.data.modifiable ? | 868 pageCount: |
894 message.data.pageNumbers.length : 0) | 869 (message.data.modifiable ? message.data.pageNumbers.length : 0) |
895 }); | 870 }); |
896 return true; | 871 return true; |
897 case 'sendKeyEvent': | 872 case 'sendKeyEvent': |
898 this.handleKeyEvent_(DeserializeKeyEvent(message.data.keyEvent)); | 873 this.handleKeyEvent_(DeserializeKeyEvent(message.data.keyEvent)); |
899 return true; | 874 return true; |
900 } | 875 } |
901 | 876 |
902 return false; | 877 return false; |
903 }, | 878 }, |
904 | 879 |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
936 * Each bookmark is an Object containing a: | 911 * Each bookmark is an Object containing a: |
937 * - title | 912 * - title |
938 * - page (optional) | 913 * - page (optional) |
939 * - array of children (themselves bookmarks) | 914 * - array of children (themselves bookmarks) |
940 * @type {Array} the top-level bookmarks of the PDF. | 915 * @type {Array} the top-level bookmarks of the PDF. |
941 */ | 916 */ |
942 get bookmarks() { | 917 get bookmarks() { |
943 return this.bookmarks_; | 918 return this.bookmarks_; |
944 } | 919 } |
945 }; | 920 }; |
OLD | NEW |