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