| 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 // <include ../../pdf/pdf_scripting_api.js> |
| 6 |
| 7 cr.exportPath('print_preview'); |
| 8 |
| 9 /** |
| 10 * Enumeration of IDs shown in the preview area. |
| 11 * @enum {string} |
| 12 * @private |
| 13 */ |
| 14 print_preview.PreviewAreaMessageId_ = { |
| 15 CUSTOM: 'custom', |
| 16 LOADING: 'loading', |
| 17 PREVIEW_FAILED: 'preview-failed' |
| 18 }; |
| 19 |
| 5 /** | 20 /** |
| 6 * @typedef {{accessibility: Function, | 21 * @typedef {{accessibility: Function, |
| 7 * documentLoadComplete: Function, | 22 * documentLoadComplete: Function, |
| 8 * getHeight: Function, | 23 * getHeight: Function, |
| 9 * getHorizontalScrollbarThickness: Function, | 24 * getHorizontalScrollbarThickness: Function, |
| 10 * getPageLocationNormalized: Function, | 25 * getPageLocationNormalized: Function, |
| 11 * getVerticalScrollbarThickness: Function, | 26 * getVerticalScrollbarThickness: Function, |
| 12 * getWidth: Function, | 27 * getWidth: Function, |
| 13 * getZoomLevel: Function, | 28 * getZoomLevel: Function, |
| 14 * goToPage: Function, | 29 * goToPage: Function, |
| 15 * grayscale: Function, | 30 * grayscale: Function, |
| 16 * loadPreviewPage: Function, | 31 * loadPreviewPage: Function, |
| 17 * onload: Function, | 32 * onload: Function, |
| 18 * onPluginSizeChanged: Function, | 33 * onPluginSizeChanged: Function, |
| 19 * onScroll: Function, | 34 * onScroll: Function, |
| 20 * pageXOffset: Function, | 35 * pageXOffset: Function, |
| 21 * pageYOffset: Function, | 36 * pageYOffset: Function, |
| 22 * printPreviewPageCount: Function, | |
| 23 * reload: Function, | 37 * reload: Function, |
| 24 * removePrintButton: Function, | 38 * resetPrintPreviewMode: Function, |
| 25 * resetPrintPreviewUrl: Function, | |
| 26 * sendKeyEvent: Function, | 39 * sendKeyEvent: Function, |
| 27 * setPageNumbers: Function, | 40 * setPageNumbers: Function, |
| 28 * setPageXOffset: Function, | 41 * setPageXOffset: Function, |
| 29 * setPageYOffset: Function, | 42 * setPageYOffset: Function, |
| 30 * setZoomLevel: Function, | 43 * setZoomLevel: Function, |
| 31 * fitToHeight: Function, | 44 * fitToHeight: Function, |
| 32 * fitToWidth: Function, | 45 * fitToWidth: Function, |
| 33 * zoomIn: Function, | 46 * zoomIn: Function, |
| 34 * zoomOut: Function}} | 47 * zoomOut: Function}} |
| 35 */ | 48 */ |
| (...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 154 * @private | 167 * @private |
| 155 */ | 168 */ |
| 156 this.overlayEl_ = null; | 169 this.overlayEl_ = null; |
| 157 | 170 |
| 158 /** | 171 /** |
| 159 * The "Open system dialog" button. | 172 * The "Open system dialog" button. |
| 160 * @type {HTMLButtonElement} | 173 * @type {HTMLButtonElement} |
| 161 * @private | 174 * @private |
| 162 */ | 175 */ |
| 163 this.openSystemDialogButton_ = null; | 176 this.openSystemDialogButton_ = null; |
| 164 }; | 177 } |
| 165 | 178 |
| 166 /** | 179 /** |
| 167 * Event types dispatched by the preview area. | 180 * Event types dispatched by the preview area. |
| 168 * @enum {string} | 181 * @enum {string} |
| 169 */ | 182 */ |
| 170 PreviewArea.EventType = { | 183 PreviewArea.EventType = { |
| 171 // Dispatched when the "Open system dialog" button is clicked. | 184 // Dispatched when the "Open system dialog" button is clicked. |
| 172 OPEN_SYSTEM_DIALOG_CLICK: | 185 OPEN_SYSTEM_DIALOG_CLICK: |
| 173 'print_preview.PreviewArea.OPEN_SYSTEM_DIALOG_CLICK', | 186 'print_preview.PreviewArea.OPEN_SYSTEM_DIALOG_CLICK', |
| 174 | 187 |
| (...skipping 23 matching lines...) Expand all Loading... |
| 198 INVISIBLE: 'invisible', | 211 INVISIBLE: 'invisible', |
| 199 OPEN_SYSTEM_DIALOG_BUTTON: 'preview-area-open-system-dialog-button', | 212 OPEN_SYSTEM_DIALOG_BUTTON: 'preview-area-open-system-dialog-button', |
| 200 OPEN_SYSTEM_DIALOG_BUTTON_THROBBER: | 213 OPEN_SYSTEM_DIALOG_BUTTON_THROBBER: |
| 201 'preview-area-open-system-dialog-button-throbber', | 214 'preview-area-open-system-dialog-button-throbber', |
| 202 OVERLAY: 'preview-area-overlay-layer', | 215 OVERLAY: 'preview-area-overlay-layer', |
| 203 MARGIN_CONTROL: 'margin-control', | 216 MARGIN_CONTROL: 'margin-control', |
| 204 PREVIEW_AREA: 'preview-area-plugin-wrapper' | 217 PREVIEW_AREA: 'preview-area-plugin-wrapper' |
| 205 }; | 218 }; |
| 206 | 219 |
| 207 /** | 220 /** |
| 208 * Enumeration of IDs shown in the preview area. | |
| 209 * @enum {string} | |
| 210 * @private | |
| 211 */ | |
| 212 PreviewArea.MessageId_ = { | |
| 213 CUSTOM: 'custom', | |
| 214 LOADING: 'loading', | |
| 215 PREVIEW_FAILED: 'preview-failed' | |
| 216 }; | |
| 217 | |
| 218 /** | |
| 219 * Maps message IDs to the CSS class that contains them. | 221 * Maps message IDs to the CSS class that contains them. |
| 220 * @type {Object<print_preview.PreviewArea.MessageId_, string>} | 222 * @type {Object<print_preview.PreviewAreaMessageId_, string>} |
| 221 * @private | 223 * @private |
| 222 */ | 224 */ |
| 223 PreviewArea.MessageIdClassMap_ = {}; | 225 PreviewArea.MessageIdClassMap_ = {}; |
| 224 PreviewArea.MessageIdClassMap_[PreviewArea.MessageId_.CUSTOM] = | 226 PreviewArea.MessageIdClassMap_[print_preview.PreviewAreaMessageId_.CUSTOM] = |
| 225 'preview-area-custom-message'; | 227 'preview-area-custom-message'; |
| 226 PreviewArea.MessageIdClassMap_[PreviewArea.MessageId_.LOADING] = | 228 PreviewArea.MessageIdClassMap_[print_preview.PreviewAreaMessageId_.LOADING] = |
| 227 'preview-area-loading-message'; | 229 'preview-area-loading-message'; |
| 228 PreviewArea.MessageIdClassMap_[PreviewArea.MessageId_.PREVIEW_FAILED] = | 230 PreviewArea.MessageIdClassMap_[ |
| 231 print_preview.PreviewAreaMessageId_.PREVIEW_FAILED] = |
| 229 'preview-area-preview-failed-message'; | 232 'preview-area-preview-failed-message'; |
| 230 | 233 |
| 231 /** | 234 /** |
| 232 * Amount of time in milliseconds to wait after issueing a new preview before | 235 * Amount of time in milliseconds to wait after issueing a new preview before |
| 233 * the loading message is shown. | 236 * the loading message is shown. |
| 234 * @type {number} | 237 * @type {number} |
| 235 * @const | 238 * @const |
| 236 * @private | 239 * @private |
| 237 */ | 240 */ |
| 238 PreviewArea.LOADING_TIMEOUT_ = 200; | 241 PreviewArea.LOADING_TIMEOUT_ = 200; |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 298 */ | 301 */ |
| 299 setPluginKeyEventCallback: function(callback) { | 302 setPluginKeyEventCallback: function(callback) { |
| 300 this.keyEventCallback_ = callback; | 303 this.keyEventCallback_ = callback; |
| 301 }, | 304 }, |
| 302 | 305 |
| 303 /** | 306 /** |
| 304 * Shows a custom message on the preview area's overlay. | 307 * Shows a custom message on the preview area's overlay. |
| 305 * @param {string} message Custom message to show. | 308 * @param {string} message Custom message to show. |
| 306 */ | 309 */ |
| 307 showCustomMessage: function(message) { | 310 showCustomMessage: function(message) { |
| 308 this.showMessage_(PreviewArea.MessageId_.CUSTOM, message); | 311 this.showMessage_(print_preview.PreviewAreaMessageId_.CUSTOM, message); |
| 309 }, | 312 }, |
| 310 | 313 |
| 311 /** @override */ | 314 /** @override */ |
| 312 enterDocument: function() { | 315 enterDocument: function() { |
| 313 print_preview.Component.prototype.enterDocument.call(this); | 316 print_preview.Component.prototype.enterDocument.call(this); |
| 314 | 317 |
| 315 this.tracker.add( | 318 this.tracker.add( |
| 316 assert(this.openSystemDialogButton_), | 319 assert(this.openSystemDialogButton_), |
| 317 'click', | 320 'click', |
| 318 this.onOpenSystemDialogButtonClick_.bind(this)); | 321 this.onOpenSystemDialogButtonClick_.bind(this)); |
| (...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 407 var oopCompatObj = this.getElement().getElementsByClassName( | 410 var oopCompatObj = this.getElement().getElementsByClassName( |
| 408 PreviewArea.Classes_.OUT_OF_PROCESS_COMPATIBILITY_OBJECT)[0]; | 411 PreviewArea.Classes_.OUT_OF_PROCESS_COMPATIBILITY_OBJECT)[0]; |
| 409 var isOOPCompatible = oopCompatObj.postMessage; | 412 var isOOPCompatible = oopCompatObj.postMessage; |
| 410 oopCompatObj.parentElement.removeChild(oopCompatObj); | 413 oopCompatObj.parentElement.removeChild(oopCompatObj); |
| 411 | 414 |
| 412 return isOOPCompatible; | 415 return isOOPCompatible; |
| 413 }, | 416 }, |
| 414 | 417 |
| 415 /** | 418 /** |
| 416 * Shows a given message on the overlay. | 419 * Shows a given message on the overlay. |
| 417 * @param {!print_preview.PreviewArea.MessageId_} messageId ID of the | 420 * @param {!print_preview.PreviewAreaMessageId_} messageId ID of the |
| 418 * message to show. | 421 * message to show. |
| 419 * @param {string=} opt_message Optional message to show that can be used | 422 * @param {string=} opt_message Optional message to show that can be used |
| 420 * by some message IDs. | 423 * by some message IDs. |
| 421 * @private | 424 * @private |
| 422 */ | 425 */ |
| 423 showMessage_: function(messageId, opt_message) { | 426 showMessage_: function(messageId, opt_message) { |
| 424 // Hide all messages. | 427 // Hide all messages. |
| 425 var messageEls = this.getElement().getElementsByClassName( | 428 var messageEls = this.getElement().getElementsByClassName( |
| 426 PreviewArea.Classes_.MESSAGE); | 429 PreviewArea.Classes_.MESSAGE); |
| 427 for (var i = 0, messageEl; messageEl = messageEls[i]; i++) { | 430 for (var i = 0, messageEl; (messageEl = messageEls[i]); i++) { |
| 428 setIsVisible(messageEl, false); | 431 setIsVisible(messageEl, false); |
| 429 } | 432 } |
| 430 // Disable jumping animation to conserve cycles. | 433 // Disable jumping animation to conserve cycles. |
| 431 var jumpingDotsEl = this.getElement().querySelector( | 434 var jumpingDotsEl = this.getElement().querySelector( |
| 432 '.preview-area-loading-message-jumping-dots'); | 435 '.preview-area-loading-message-jumping-dots'); |
| 433 jumpingDotsEl.classList.remove('jumping-dots'); | 436 jumpingDotsEl.classList.remove('jumping-dots'); |
| 434 | 437 |
| 435 // Show specific message. | 438 // Show specific message. |
| 436 if (messageId == PreviewArea.MessageId_.CUSTOM) { | 439 if (messageId == print_preview.PreviewAreaMessageId_.CUSTOM) { |
| 437 var customMessageTextEl = this.getElement().getElementsByClassName( | 440 var customMessageTextEl = this.getElement().getElementsByClassName( |
| 438 PreviewArea.Classes_.CUSTOM_MESSAGE_TEXT)[0]; | 441 PreviewArea.Classes_.CUSTOM_MESSAGE_TEXT)[0]; |
| 439 customMessageTextEl.textContent = opt_message; | 442 customMessageTextEl.textContent = opt_message; |
| 440 } else if (messageId == PreviewArea.MessageId_.LOADING) { | 443 } else if (messageId == print_preview.PreviewAreaMessageId_.LOADING) { |
| 441 jumpingDotsEl.classList.add('jumping-dots'); | 444 jumpingDotsEl.classList.add('jumping-dots'); |
| 442 } | 445 } |
| 443 var messageEl = this.getElement().getElementsByClassName( | 446 var messageEl = this.getElement().getElementsByClassName( |
| 444 PreviewArea.MessageIdClassMap_[messageId])[0]; | 447 PreviewArea.MessageIdClassMap_[messageId])[0]; |
| 445 setIsVisible(messageEl, true); | 448 setIsVisible(messageEl, true); |
| 446 | 449 |
| 447 this.setOverlayVisible_(true); | 450 this.setOverlayVisible_(true); |
| 448 }, | 451 }, |
| 449 | 452 |
| 450 /** | 453 /** |
| (...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 534 /** | 537 /** |
| 535 * Called when the print ticket changes. Updates the preview. | 538 * Called when the print ticket changes. Updates the preview. |
| 536 * @private | 539 * @private |
| 537 */ | 540 */ |
| 538 onTicketChange_: function() { | 541 onTicketChange_: function() { |
| 539 if (this.previewGenerator_ && this.previewGenerator_.requestPreview()) { | 542 if (this.previewGenerator_ && this.previewGenerator_.requestPreview()) { |
| 540 cr.dispatchSimpleEvent( | 543 cr.dispatchSimpleEvent( |
| 541 this, PreviewArea.EventType.PREVIEW_GENERATION_IN_PROGRESS); | 544 this, PreviewArea.EventType.PREVIEW_GENERATION_IN_PROGRESS); |
| 542 if (this.loadingTimeout_ == null) { | 545 if (this.loadingTimeout_ == null) { |
| 543 this.loadingTimeout_ = setTimeout( | 546 this.loadingTimeout_ = setTimeout( |
| 544 this.showMessage_.bind(this, PreviewArea.MessageId_.LOADING), | 547 this.showMessage_.bind(this, |
| 548 print_preview.PreviewAreaMessageId_.LOADING), |
| 545 PreviewArea.LOADING_TIMEOUT_); | 549 PreviewArea.LOADING_TIMEOUT_); |
| 546 } | 550 } |
| 547 } else { | 551 } else { |
| 548 this.marginControlContainer_.showMarginControlsIfNeeded(); | 552 this.marginControlContainer_.showMarginControlsIfNeeded(); |
| 549 } | 553 } |
| 550 }, | 554 }, |
| 551 | 555 |
| 552 /** | 556 /** |
| 553 * Called when the preview generator begins loading the preview. | 557 * Called when the preview generator begins loading the preview. |
| 554 * @param {Event} event Contains the URL to initialize the plugin to. | 558 * @param {Event} event Contains the URL to initialize the plugin to. |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 599 this.loadingTimeout_ = null; | 603 this.loadingTimeout_ = null; |
| 600 } | 604 } |
| 601 }, | 605 }, |
| 602 | 606 |
| 603 /** | 607 /** |
| 604 * Called when the generation of a preview fails. Shows an error message. | 608 * Called when the generation of a preview fails. Shows an error message. |
| 605 * @private | 609 * @private |
| 606 */ | 610 */ |
| 607 onPreviewGenerationFail_: function() { | 611 onPreviewGenerationFail_: function() { |
| 608 this.cancelTimeout(); | 612 this.cancelTimeout(); |
| 609 this.showMessage_(PreviewArea.MessageId_.PREVIEW_FAILED); | 613 this.showMessage_(print_preview.PreviewAreaMessageId_.PREVIEW_FAILED); |
| 610 cr.dispatchSimpleEvent( | 614 cr.dispatchSimpleEvent( |
| 611 this, PreviewArea.EventType.PREVIEW_GENERATION_FAIL); | 615 this, PreviewArea.EventType.PREVIEW_GENERATION_FAIL); |
| 612 }, | 616 }, |
| 613 | 617 |
| 614 /** | 618 /** |
| 615 * Called when the plugin loads. This is a consequence of calling | 619 * Called when the plugin loads. This is a consequence of calling |
| 616 * plugin.reload(). Certain plugin state can only be set after the plugin | 620 * plugin.reload(). Certain plugin state can only be set after the plugin |
| 617 * has loaded. | 621 * has loaded. |
| 618 * @private | 622 * @private |
| 619 */ | 623 */ |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 658 // being draggable. | 662 // being draggable. |
| 659 this.plugin_.style.pointerEvents = isDragging ? 'none' : 'auto'; | 663 this.plugin_.style.pointerEvents = isDragging ? 'none' : 'auto'; |
| 660 } | 664 } |
| 661 }; | 665 }; |
| 662 | 666 |
| 663 // Export | 667 // Export |
| 664 return { | 668 return { |
| 665 PreviewArea: PreviewArea | 669 PreviewArea: PreviewArea |
| 666 }; | 670 }; |
| 667 }); | 671 }); |
| OLD | NEW |