| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 /** |
| 6 * @typedef {{accessibility: Function, |
| 7 * documentLoadComplete: Function, |
| 8 * getHeight: Function, |
| 9 * getHorizontalScrollbarThickness: Function, |
| 10 * getPageLocationNormalized: Function, |
| 11 * getVerticalScrollbarThickness: Function, |
| 12 * getWidth: Function, |
| 13 * getZoomLevel: Function, |
| 14 * goToPage: Function, |
| 15 * grayscale: Function, |
| 16 * loadPreviewPage: Function, |
| 17 * onload: Function, |
| 18 * onPluginSizeChanged: Function, |
| 19 * onScroll: Function, |
| 20 * pageXOffset: Function, |
| 21 * pageYOffset: Function, |
| 22 * printPreviewPageCount: Function, |
| 23 * reload: Function, |
| 24 * removePrintButton: Function, |
| 25 * resetPrintPreviewUrl: Function, |
| 26 * sendKeyEvent: Function, |
| 27 * setPageNumbers: Function, |
| 28 * setPageXOffset: Function, |
| 29 * setPageYOffset: Function, |
| 30 * setZoomLevel: Function, |
| 31 * fitToHeight: Function, |
| 32 * fitToWidth: Function, |
| 33 * zoomIn: Function, |
| 34 * zoomOut: Function}} |
| 35 */ |
| 36 print_preview.PDFPlugin; |
| 37 |
| 5 cr.define('print_preview', function() { | 38 cr.define('print_preview', function() { |
| 6 'use strict'; | 39 'use strict'; |
| 7 | 40 |
| 8 /** | 41 /** |
| 9 * Creates a PreviewArea object. It represents the area where the preview | 42 * Creates a PreviewArea object. It represents the area where the preview |
| 10 * document is displayed. | 43 * document is displayed. |
| 11 * @param {!print_preview.DestinationStore} destinationStore Used to get the | 44 * @param {!print_preview.DestinationStore} destinationStore Used to get the |
| 12 * currently selected destination. | 45 * currently selected destination. |
| 13 * @param {!print_preview.PrintTicketStore} printTicketStore Used to get | 46 * @param {!print_preview.PrintTicketStore} printTicketStore Used to get |
| 14 * information about how the preview should be displayed. | 47 * information about how the preview should be displayed. |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 54 | 87 |
| 55 /** | 88 /** |
| 56 * Used to read generated page previews. | 89 * Used to read generated page previews. |
| 57 * @type {print_preview.PreviewGenerator} | 90 * @type {print_preview.PreviewGenerator} |
| 58 * @private | 91 * @private |
| 59 */ | 92 */ |
| 60 this.previewGenerator_ = null; | 93 this.previewGenerator_ = null; |
| 61 | 94 |
| 62 /** | 95 /** |
| 63 * The embedded pdf plugin object. It's value is null if not yet loaded. | 96 * The embedded pdf plugin object. It's value is null if not yet loaded. |
| 64 * @type {HTMLEmbedElement} | 97 * @type {HTMLEmbedElement|print_preview.PDFPlugin} |
| 65 * @private | 98 * @private |
| 66 */ | 99 */ |
| 67 this.plugin_ = null; | 100 this.plugin_ = null; |
| 68 | 101 |
| 69 /** | 102 /** |
| 70 * Custom margins component superimposed on the preview plugin. | 103 * Custom margins component superimposed on the preview plugin. |
| 71 * @type {!print_preview.MarginControlContainer} | 104 * @type {!print_preview.MarginControlContainer} |
| 72 * @private | 105 * @private |
| 73 */ | 106 */ |
| 74 this.marginControlContainer_ = new print_preview.MarginControlContainer( | 107 this.marginControlContainer_ = new print_preview.MarginControlContainer( |
| (...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 188 PreviewArea.PluginType_ = { | 221 PreviewArea.PluginType_ = { |
| 189 // TODO(raymes): Remove all references to the IN_PROCESS plugin once it is | 222 // TODO(raymes): Remove all references to the IN_PROCESS plugin once it is |
| 190 // removed. | 223 // removed. |
| 191 IN_PROCESS: 'in-process', | 224 IN_PROCESS: 'in-process', |
| 192 OUT_OF_PROCESS: 'out-of-process', | 225 OUT_OF_PROCESS: 'out-of-process', |
| 193 NONE: 'none' | 226 NONE: 'none' |
| 194 }; | 227 }; |
| 195 | 228 |
| 196 /** | 229 /** |
| 197 * Maps message IDs to the CSS class that contains them. | 230 * Maps message IDs to the CSS class that contains them. |
| 198 * @type {object.<PreviewArea.MessageId_, string>} | 231 * @type {Object.<print_preview.PreviewArea.MessageId_, string>} |
| 199 * @private | 232 * @private |
| 200 */ | 233 */ |
| 201 PreviewArea.MessageIdClassMap_ = {}; | 234 PreviewArea.MessageIdClassMap_ = {}; |
| 202 PreviewArea.MessageIdClassMap_[PreviewArea.MessageId_.CUSTOM] = | 235 PreviewArea.MessageIdClassMap_[PreviewArea.MessageId_.CUSTOM] = |
| 203 'preview-area-custom-message'; | 236 'preview-area-custom-message'; |
| 204 PreviewArea.MessageIdClassMap_[PreviewArea.MessageId_.LOADING] = | 237 PreviewArea.MessageIdClassMap_[PreviewArea.MessageId_.LOADING] = |
| 205 'preview-area-loading-message'; | 238 'preview-area-loading-message'; |
| 206 PreviewArea.MessageIdClassMap_[PreviewArea.MessageId_.PREVIEW_FAILED] = | 239 PreviewArea.MessageIdClassMap_[PreviewArea.MessageId_.PREVIEW_FAILED] = |
| 207 'preview-area-preview-failed-message'; | 240 'preview-area-preview-failed-message'; |
| 208 | 241 |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 273 * @param {string} message Custom message to show. | 306 * @param {string} message Custom message to show. |
| 274 */ | 307 */ |
| 275 showCustomMessage: function(message) { | 308 showCustomMessage: function(message) { |
| 276 this.showMessage_(PreviewArea.MessageId_.CUSTOM, message); | 309 this.showMessage_(PreviewArea.MessageId_.CUSTOM, message); |
| 277 }, | 310 }, |
| 278 | 311 |
| 279 /** @override */ | 312 /** @override */ |
| 280 enterDocument: function() { | 313 enterDocument: function() { |
| 281 print_preview.Component.prototype.enterDocument.call(this); | 314 print_preview.Component.prototype.enterDocument.call(this); |
| 282 this.tracker.add( | 315 this.tracker.add( |
| 283 this.openSystemDialogButton_, | 316 assert(this.openSystemDialogButton_), |
| 284 'click', | 317 'click', |
| 285 this.onOpenSystemDialogButtonClick_.bind(this)); | 318 this.onOpenSystemDialogButtonClick_.bind(this)); |
| 286 | 319 |
| 287 this.tracker.add( | 320 this.tracker.add( |
| 288 this.printTicketStore_, | 321 this.printTicketStore_, |
| 289 print_preview.PrintTicketStore.EventType.INITIALIZE, | 322 print_preview.PrintTicketStore.EventType.INITIALIZE, |
| 290 this.onTicketChange_.bind(this)); | 323 this.onTicketChange_.bind(this)); |
| 291 this.tracker.add( | 324 this.tracker.add( |
| 292 this.printTicketStore_, | 325 this.printTicketStore_, |
| 293 print_preview.PrintTicketStore.EventType.TICKET_CHANGE, | 326 print_preview.PrintTicketStore.EventType.TICKET_CHANGE, |
| (...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 392 * plugin for rendering the preview. | 425 * plugin for rendering the preview. |
| 393 * PreviewArea.PluginType_.IN_PROCESS for an in-process plugin | 426 * PreviewArea.PluginType_.IN_PROCESS for an in-process plugin |
| 394 * PreviewArea.PluginType_.OUT_OF_PROCESS for an out-of-process plugin | 427 * PreviewArea.PluginType_.OUT_OF_PROCESS for an out-of-process plugin |
| 395 * PreviewArea.PluginType_.NONE if no plugin is available. | 428 * PreviewArea.PluginType_.NONE if no plugin is available. |
| 396 * @private | 429 * @private |
| 397 */ | 430 */ |
| 398 getPluginType_: function() { | 431 getPluginType_: function() { |
| 399 // TODO(raymes): Remove the in-process check after we remove the | 432 // TODO(raymes): Remove the in-process check after we remove the |
| 400 // in-process plugin. Change this function back to | 433 // in-process plugin. Change this function back to |
| 401 // checkPluginCompatibility_(). | 434 // checkPluginCompatibility_(). |
| 435 /** @type {print_preview.PDFPlugin} */ |
| 402 var compatObj = this.getElement().getElementsByClassName( | 436 var compatObj = this.getElement().getElementsByClassName( |
| 403 PreviewArea.Classes_.COMPATIBILITY_OBJECT)[0]; | 437 PreviewArea.Classes_.COMPATIBILITY_OBJECT)[0]; |
| 404 var isCompatible = | 438 var isCompatible = |
| 405 compatObj.onload && | 439 compatObj.onload && |
| 406 compatObj.goToPage && | 440 compatObj.goToPage && |
| 407 compatObj.removePrintButton && | 441 compatObj.removePrintButton && |
| 408 compatObj.loadPreviewPage && | 442 compatObj.loadPreviewPage && |
| 409 compatObj.printPreviewPageCount && | 443 compatObj.printPreviewPageCount && |
| 410 compatObj.resetPrintPreviewUrl && | 444 compatObj.resetPrintPreviewUrl && |
| 411 compatObj.onPluginSizeChanged && | 445 compatObj.onPluginSizeChanged && |
| (...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 491 * @param {string} srcUrl Initial URL of the plugin. | 525 * @param {string} srcUrl Initial URL of the plugin. |
| 492 * @private | 526 * @private |
| 493 */ | 527 */ |
| 494 createPlugin_: function(srcUrl) { | 528 createPlugin_: function(srcUrl) { |
| 495 if (this.plugin_) { | 529 if (this.plugin_) { |
| 496 console.warn('Pdf preview plugin already created'); | 530 console.warn('Pdf preview plugin already created'); |
| 497 return; | 531 return; |
| 498 } | 532 } |
| 499 | 533 |
| 500 if (this.pluginType_ == PreviewArea.PluginType_.IN_PROCESS) { | 534 if (this.pluginType_ == PreviewArea.PluginType_.IN_PROCESS) { |
| 501 this.plugin_ = document.createElement('embed'); | 535 this.plugin_ = assertInstanceof(document.createElement('embed'), |
| 536 HTMLEmbedElement); |
| 502 this.plugin_.setAttribute( | 537 this.plugin_.setAttribute( |
| 503 'type', 'application/x-google-chrome-print-preview-pdf'); | 538 'type', 'application/x-google-chrome-print-preview-pdf'); |
| 504 this.plugin_.setAttribute('src', srcUrl); | 539 this.plugin_.setAttribute('src', srcUrl); |
| 505 } else { | 540 } else { |
| 506 this.plugin_ = PDFCreateOutOfProcessPlugin(srcUrl); | 541 this.plugin_ = /** @type {print_preview.PDFPlugin} */( |
| 542 PDFCreateOutOfProcessPlugin(srcUrl)); |
| 507 } | 543 } |
| 508 | 544 |
| 509 this.plugin_.setAttribute('class', 'preview-area-plugin'); | 545 this.plugin_.setAttribute('class', 'preview-area-plugin'); |
| 510 this.plugin_.setAttribute('aria-live', 'polite'); | 546 this.plugin_.setAttribute('aria-live', 'polite'); |
| 511 this.plugin_.setAttribute('aria-atomic', 'true'); | 547 this.plugin_.setAttribute('aria-atomic', 'true'); |
| 512 // NOTE: The plugin's 'id' field must be set to 'pdf-viewer' since | 548 // NOTE: The plugin's 'id' field must be set to 'pdf-viewer' since |
| 513 // chrome/renderer/printing/print_web_view_helper.cc actually references | 549 // chrome/renderer/printing/print_web_view_helper.cc actually references |
| 514 // it. | 550 // it. |
| 515 this.plugin_.setAttribute('id', 'pdf-viewer'); | 551 this.plugin_.setAttribute('id', 'pdf-viewer'); |
| 516 this.getChildElement('.preview-area-plugin-wrapper'). | 552 this.getChildElement('.preview-area-plugin-wrapper'). |
| 517 appendChild(this.plugin_); | 553 appendChild(/** @type {Node} */(this.plugin_)); |
| 518 | 554 |
| 519 | 555 |
| 520 if (this.pluginType_ == PreviewArea.PluginType_.OUT_OF_PROCESS) { | 556 if (this.pluginType_ == PreviewArea.PluginType_.OUT_OF_PROCESS) { |
| 521 var pageNumbers = | 557 var pageNumbers = |
| 522 this.printTicketStore_.pageRange.getPageNumberSet().asArray(); | 558 this.printTicketStore_.pageRange.getPageNumberSet().asArray(); |
| 523 var grayscale = !this.printTicketStore_.color.getValue(); | 559 var grayscale = !this.printTicketStore_.color.getValue(); |
| 524 this.plugin_.setLoadCallback(this.onPluginLoad_.bind(this)); | 560 this.plugin_.setLoadCallback(this.onPluginLoad_.bind(this)); |
| 525 this.plugin_.setViewportChangedCallback( | 561 this.plugin_.setViewportChangedCallback( |
| 526 this.onPreviewVisualStateChange_.bind(this)); | 562 this.onPreviewVisualStateChange_.bind(this)); |
| 527 this.plugin_.resetPrintPreviewMode(srcUrl, grayscale, pageNumbers, | 563 this.plugin_.resetPrintPreviewMode(srcUrl, grayscale, pageNumbers, |
| 528 this.documentInfo_.isModifiable); | 564 this.documentInfo_.isModifiable); |
| 529 } else { | 565 } else { |
| 530 global['onPreviewPluginLoad'] = this.onPluginLoad_.bind(this); | 566 global['onPreviewPluginLoad'] = this.onPluginLoad_.bind(this); |
| 531 this.plugin_.onload('onPreviewPluginLoad()'); | 567 (/** @type {print_preview.PDFPlugin} */(this.plugin_)). |
| 568 onload('onPreviewPluginLoad()'); |
| 532 | 569 |
| 533 global['onPreviewPluginVisualStateChange'] = | 570 global['onPreviewPluginVisualStateChange'] = |
| 534 this.onPreviewVisualStateChange_.bind(this); | 571 this.onPreviewVisualStateChange_.bind(this); |
| 535 this.plugin_.onScroll('onPreviewPluginVisualStateChange()'); | 572 this.plugin_.onScroll('onPreviewPluginVisualStateChange()'); |
| 536 this.plugin_.onPluginSizeChanged('onPreviewPluginVisualStateChange()'); | 573 this.plugin_.onPluginSizeChanged('onPreviewPluginVisualStateChange()'); |
| 537 | 574 |
| 538 this.plugin_.removePrintButton(); | 575 this.plugin_.removePrintButton(); |
| 539 this.plugin_.grayscale(!this.printTicketStore_.color.getValue()); | 576 this.plugin_.grayscale(!this.printTicketStore_.color.getValue()); |
| 540 } | 577 } |
| 541 }, | 578 }, |
| (...skipping 192 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 734 new print_preview.Size(viewportWidth, viewportHeight)); | 771 new print_preview.Size(viewportWidth, viewportHeight)); |
| 735 } | 772 } |
| 736 } | 773 } |
| 737 }; | 774 }; |
| 738 | 775 |
| 739 // Export | 776 // Export |
| 740 return { | 777 return { |
| 741 PreviewArea: PreviewArea | 778 PreviewArea: PreviewArea |
| 742 }; | 779 }; |
| 743 }); | 780 }); |
| OLD | NEW |