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'); | 5 cr.exportPath('print_preview'); |
6 | 6 |
7 /** | 7 /** |
8 * Enumeration of IDs shown in the preview area. | 8 * Enumeration of IDs shown in the preview area. |
9 * @enum {string} | 9 * @enum {string} |
10 * @private | 10 * @private |
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
109 * @private | 109 * @private |
110 */ | 110 */ |
111 this.plugin_ = null; | 111 this.plugin_ = null; |
112 | 112 |
113 /** | 113 /** |
114 * Custom margins component superimposed on the preview plugin. | 114 * Custom margins component superimposed on the preview plugin. |
115 * @type {!print_preview.MarginControlContainer} | 115 * @type {!print_preview.MarginControlContainer} |
116 * @private | 116 * @private |
117 */ | 117 */ |
118 this.marginControlContainer_ = new print_preview.MarginControlContainer( | 118 this.marginControlContainer_ = new print_preview.MarginControlContainer( |
119 this.documentInfo_, | 119 this.documentInfo_, this.printTicketStore_.marginsType, |
120 this.printTicketStore_.marginsType, | |
121 this.printTicketStore_.customMargins, | 120 this.printTicketStore_.customMargins, |
122 this.printTicketStore_.measurementSystem, | 121 this.printTicketStore_.measurementSystem, |
123 this.onMarginDragChanged_.bind(this)); | 122 this.onMarginDragChanged_.bind(this)); |
124 this.addChild(this.marginControlContainer_); | 123 this.addChild(this.marginControlContainer_); |
125 | 124 |
126 /** | 125 /** |
127 * Current zoom level as a percentage. | 126 * Current zoom level as a percentage. |
128 * @type {?number} | 127 * @type {?number} |
129 * @private | 128 * @private |
130 */ | 129 */ |
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
218 /** | 217 /** |
219 * Maps message IDs to the CSS class that contains them. | 218 * Maps message IDs to the CSS class that contains them. |
220 * @type {Object<print_preview.PreviewAreaMessageId_, string>} | 219 * @type {Object<print_preview.PreviewAreaMessageId_, string>} |
221 * @private | 220 * @private |
222 */ | 221 */ |
223 PreviewArea.MessageIdClassMap_ = {}; | 222 PreviewArea.MessageIdClassMap_ = {}; |
224 PreviewArea.MessageIdClassMap_[print_preview.PreviewAreaMessageId_.CUSTOM] = | 223 PreviewArea.MessageIdClassMap_[print_preview.PreviewAreaMessageId_.CUSTOM] = |
225 'preview-area-custom-message'; | 224 'preview-area-custom-message'; |
226 PreviewArea.MessageIdClassMap_[print_preview.PreviewAreaMessageId_.LOADING] = | 225 PreviewArea.MessageIdClassMap_[print_preview.PreviewAreaMessageId_.LOADING] = |
227 'preview-area-loading-message'; | 226 'preview-area-loading-message'; |
228 PreviewArea.MessageIdClassMap_[ | 227 PreviewArea |
229 print_preview.PreviewAreaMessageId_.PREVIEW_FAILED] = | 228 .MessageIdClassMap_[print_preview.PreviewAreaMessageId_.PREVIEW_FAILED] = |
230 'preview-area-preview-failed-message'; | 229 'preview-area-preview-failed-message'; |
231 | 230 |
232 /** | 231 /** |
233 * Amount of time in milliseconds to wait after issueing a new preview before | 232 * Amount of time in milliseconds to wait after issueing a new preview before |
234 * the loading message is shown. | 233 * the loading message is shown. |
235 * @type {number} | 234 * @type {number} |
236 * @const | 235 * @const |
237 * @private | 236 * @private |
238 */ | 237 */ |
239 PreviewArea.LOADING_TIMEOUT_ = 200; | 238 PreviewArea.LOADING_TIMEOUT_ = 200; |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
307 */ | 306 */ |
308 showCustomMessage: function(message) { | 307 showCustomMessage: function(message) { |
309 this.showMessage_(print_preview.PreviewAreaMessageId_.CUSTOM, message); | 308 this.showMessage_(print_preview.PreviewAreaMessageId_.CUSTOM, message); |
310 }, | 309 }, |
311 | 310 |
312 /** @override */ | 311 /** @override */ |
313 enterDocument: function() { | 312 enterDocument: function() { |
314 print_preview.Component.prototype.enterDocument.call(this); | 313 print_preview.Component.prototype.enterDocument.call(this); |
315 | 314 |
316 this.tracker.add( | 315 this.tracker.add( |
317 assert(this.openSystemDialogButton_), | 316 assert(this.openSystemDialogButton_), 'click', |
318 'click', | |
319 this.onOpenSystemDialogButtonClick_.bind(this)); | 317 this.onOpenSystemDialogButtonClick_.bind(this)); |
320 | 318 |
321 var TicketStoreEvent = print_preview.PrintTicketStore.EventType; | 319 var TicketStoreEvent = print_preview.PrintTicketStore.EventType; |
322 [ | 320 [TicketStoreEvent.INITIALIZE, TicketStoreEvent.TICKET_CHANGE, |
323 TicketStoreEvent.INITIALIZE, | 321 TicketStoreEvent.CAPABILITIES_CHANGE, TicketStoreEvent.DOCUMENT_CHANGE] |
324 TicketStoreEvent.TICKET_CHANGE, | 322 .forEach(function(eventType) { |
325 TicketStoreEvent.CAPABILITIES_CHANGE, | 323 this.tracker.add( |
326 TicketStoreEvent.DOCUMENT_CHANGE | 324 this.printTicketStore_, eventType, |
327 ].forEach(function(eventType) { | 325 this.onTicketChange_.bind(this)); |
328 this.tracker.add(this.printTicketStore_, eventType, | 326 }.bind(this)); |
329 this.onTicketChange_.bind(this)); | |
330 }.bind(this)); | |
331 | 327 |
332 [ | 328 [this.printTicketStore_.color, this.printTicketStore_.cssBackground, |
333 this.printTicketStore_.color, | 329 this.printTicketStore_.customMargins, this.printTicketStore_.fitToPage, |
334 this.printTicketStore_.cssBackground, | 330 this.printTicketStore_.headerFooter, this.printTicketStore_.landscape, |
335 this.printTicketStore_.customMargins, | 331 this.printTicketStore_.marginsType, this.printTicketStore_.pageRange, |
336 this.printTicketStore_.fitToPage, | 332 this.printTicketStore_.rasterize, this.printTicketStore_.selectionOnly, |
337 this.printTicketStore_.headerFooter, | 333 this.printTicketStore_.scaling] |
338 this.printTicketStore_.landscape, | 334 .forEach(function(setting) { |
339 this.printTicketStore_.marginsType, | 335 this.tracker.add( |
340 this.printTicketStore_.pageRange, | 336 setting, print_preview.ticket_items.TicketItem.EventType.CHANGE, |
341 this.printTicketStore_.rasterize, | 337 this.onTicketChange_.bind(this)); |
342 this.printTicketStore_.selectionOnly, | 338 }.bind(this)); |
343 this.printTicketStore_.scaling | |
344 ].forEach(function(setting) { | |
345 this.tracker.add( | |
346 setting, | |
347 print_preview.ticket_items.TicketItem.EventType.CHANGE, | |
348 this.onTicketChange_.bind(this)); | |
349 }.bind(this)); | |
350 | 339 |
351 if (this.checkPluginCompatibility_()) { | 340 if (this.checkPluginCompatibility_()) { |
352 this.previewGenerator_ = new print_preview.PreviewGenerator( | 341 this.previewGenerator_ = new print_preview.PreviewGenerator( |
353 this.destinationStore_, | 342 this.destinationStore_, this.printTicketStore_, this.nativeLayer_, |
354 this.printTicketStore_, | |
355 this.nativeLayer_, | |
356 this.documentInfo_); | 343 this.documentInfo_); |
357 this.tracker.add( | 344 this.tracker.add( |
358 this.previewGenerator_, | 345 this.previewGenerator_, |
359 print_preview.PreviewGenerator.EventType.PREVIEW_START, | 346 print_preview.PreviewGenerator.EventType.PREVIEW_START, |
360 this.onPreviewStart_.bind(this)); | 347 this.onPreviewStart_.bind(this)); |
361 this.tracker.add( | 348 this.tracker.add( |
362 this.previewGenerator_, | 349 this.previewGenerator_, |
363 print_preview.PreviewGenerator.EventType.PAGE_READY, | 350 print_preview.PreviewGenerator.EventType.PAGE_READY, |
364 this.onPagePreviewReady_.bind(this)); | 351 this.onPagePreviewReady_.bind(this)); |
365 this.tracker.add( | 352 this.tracker.add( |
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
435 | 422 |
436 // Show specific message. | 423 // Show specific message. |
437 if (messageId == print_preview.PreviewAreaMessageId_.CUSTOM) { | 424 if (messageId == print_preview.PreviewAreaMessageId_.CUSTOM) { |
438 var customMessageTextEl = this.getElement().getElementsByClassName( | 425 var customMessageTextEl = this.getElement().getElementsByClassName( |
439 PreviewArea.Classes_.CUSTOM_MESSAGE_TEXT)[0]; | 426 PreviewArea.Classes_.CUSTOM_MESSAGE_TEXT)[0]; |
440 customMessageTextEl.textContent = opt_message; | 427 customMessageTextEl.textContent = opt_message; |
441 } else if (messageId == print_preview.PreviewAreaMessageId_.LOADING) { | 428 } else if (messageId == print_preview.PreviewAreaMessageId_.LOADING) { |
442 jumpingDotsEl.classList.add('jumping-dots'); | 429 jumpingDotsEl.classList.add('jumping-dots'); |
443 } | 430 } |
444 var messageEl = this.getElement().getElementsByClassName( | 431 var messageEl = this.getElement().getElementsByClassName( |
445 PreviewArea.MessageIdClassMap_[messageId])[0]; | 432 PreviewArea.MessageIdClassMap_[messageId])[0]; |
446 setIsVisible(messageEl, true); | 433 setIsVisible(messageEl, true); |
447 | 434 |
448 this.setOverlayVisible_(true); | 435 this.setOverlayVisible_(true); |
449 }, | 436 }, |
450 | 437 |
451 /** | 438 /** |
452 * Set the visibility of the message overlay. | 439 * Set the visibility of the message overlay. |
453 * @param {boolean} visible Whether to make the overlay visible or not | 440 * @param {boolean} visible Whether to make the overlay visible or not |
454 * @private | 441 * @private |
455 */ | 442 */ |
456 setOverlayVisible_: function(visible) { | 443 setOverlayVisible_: function(visible) { |
457 this.overlayEl_.classList.toggle( | 444 this.overlayEl_.classList.toggle( |
458 PreviewArea.Classes_.INVISIBLE, | 445 PreviewArea.Classes_.INVISIBLE, !visible); |
459 !visible); | |
460 this.overlayEl_.setAttribute('aria-hidden', !visible); | 446 this.overlayEl_.setAttribute('aria-hidden', !visible); |
461 | 447 |
462 // Hide/show all controls that will overlap when the overlay is visible. | 448 // Hide/show all controls that will overlap when the overlay is visible. |
463 var marginControls = this.getElement().getElementsByClassName( | 449 var marginControls = this.getElement().getElementsByClassName( |
464 PreviewArea.Classes_.MARGIN_CONTROL); | 450 PreviewArea.Classes_.MARGIN_CONTROL); |
465 for (var i = 0; i < marginControls.length; ++i) { | 451 for (var i = 0; i < marginControls.length; ++i) { |
466 marginControls[i].setAttribute('aria-hidden', visible); | 452 marginControls[i].setAttribute('aria-hidden', visible); |
467 } | 453 } |
468 var previewAreaControls = this.getElement().getElementsByClassName( | 454 var previewAreaControls = this.getElement().getElementsByClassName( |
469 PreviewArea.Classes_.PREVIEW_AREA); | 455 PreviewArea.Classes_.PREVIEW_AREA); |
470 for (var i = 0; i < previewAreaControls.length; ++i) { | 456 for (var i = 0; i < previewAreaControls.length; ++i) { |
471 previewAreaControls[i].setAttribute('aria-hidden', visible); | 457 previewAreaControls[i].setAttribute('aria-hidden', visible); |
472 } | 458 } |
473 | 459 |
474 if (!visible) { | 460 if (!visible) { |
475 // Disable jumping animation to conserve cycles. | 461 // Disable jumping animation to conserve cycles. |
476 var jumpingDotsEl = this.getElement().querySelector( | 462 var jumpingDotsEl = this.getElement().querySelector( |
477 '.preview-area-loading-message-jumping-dots'); | 463 '.preview-area-loading-message-jumping-dots'); |
478 jumpingDotsEl.classList.remove('jumping-dots'); | 464 jumpingDotsEl.classList.remove('jumping-dots'); |
479 } | 465 } |
480 }, | 466 }, |
481 | 467 |
482 /** | 468 /** |
483 * Creates a preview plugin and adds it to the DOM. | 469 * Creates a preview plugin and adds it to the DOM. |
484 * @param {string} srcUrl Initial URL of the plugin. | 470 * @param {string} srcUrl Initial URL of the plugin. |
485 * @private | 471 * @private |
486 */ | 472 */ |
487 createPlugin_: function(srcUrl) { | 473 createPlugin_: function(srcUrl) { |
488 assert(!this.plugin_); | 474 assert(!this.plugin_); |
489 this.plugin_ = /** @type {print_preview.PDFPlugin} */( | 475 this.plugin_ = /** @type {print_preview.PDFPlugin} */ ( |
490 PDFCreateOutOfProcessPlugin(srcUrl)); | 476 PDFCreateOutOfProcessPlugin(srcUrl)); |
491 this.plugin_.setKeyEventCallback(this.keyEventCallback_); | 477 this.plugin_.setKeyEventCallback(this.keyEventCallback_); |
492 | 478 |
493 this.plugin_.setAttribute('class', 'preview-area-plugin'); | 479 this.plugin_.setAttribute('class', 'preview-area-plugin'); |
494 this.plugin_.setAttribute('aria-live', 'polite'); | 480 this.plugin_.setAttribute('aria-live', 'polite'); |
495 this.plugin_.setAttribute('aria-atomic', 'true'); | 481 this.plugin_.setAttribute('aria-atomic', 'true'); |
496 // NOTE: The plugin's 'id' field must be set to 'pdf-viewer' since | 482 // NOTE: The plugin's 'id' field must be set to 'pdf-viewer' since |
497 // chrome/renderer/printing/print_web_view_helper.cc actually references | 483 // chrome/renderer/printing/print_web_view_helper.cc actually references |
498 // it. | 484 // it. |
499 this.plugin_.setAttribute('id', 'pdf-viewer'); | 485 this.plugin_.setAttribute('id', 'pdf-viewer'); |
500 this.getChildElement('.preview-area-plugin-wrapper'). | 486 this.getChildElement('.preview-area-plugin-wrapper') |
501 appendChild(/** @type {Node} */(this.plugin_)); | 487 .appendChild(/** @type {Node} */ (this.plugin_)); |
502 | 488 |
503 this.plugin_.setLoadCallback(this.onPluginLoad_.bind(this)); | 489 this.plugin_.setLoadCallback(this.onPluginLoad_.bind(this)); |
504 this.plugin_.setViewportChangedCallback( | 490 this.plugin_.setViewportChangedCallback( |
505 this.onPreviewVisualStateChange_.bind(this)); | 491 this.onPreviewVisualStateChange_.bind(this)); |
506 }, | 492 }, |
507 | 493 |
508 /** | 494 /** |
509 * Dispatches a PREVIEW_GENERATION_DONE event if all conditions are met. | 495 * Dispatches a PREVIEW_GENERATION_DONE event if all conditions are met. |
510 * @private | 496 * @private |
511 */ | 497 */ |
(...skipping 23 matching lines...) Expand all Loading... |
535 /** | 521 /** |
536 * Called when the print ticket changes. Updates the preview. | 522 * Called when the print ticket changes. Updates the preview. |
537 * @private | 523 * @private |
538 */ | 524 */ |
539 onTicketChange_: function() { | 525 onTicketChange_: function() { |
540 if (this.previewGenerator_ && this.previewGenerator_.requestPreview()) { | 526 if (this.previewGenerator_ && this.previewGenerator_.requestPreview()) { |
541 cr.dispatchSimpleEvent( | 527 cr.dispatchSimpleEvent( |
542 this, PreviewArea.EventType.PREVIEW_GENERATION_IN_PROGRESS); | 528 this, PreviewArea.EventType.PREVIEW_GENERATION_IN_PROGRESS); |
543 if (this.loadingTimeout_ == null) { | 529 if (this.loadingTimeout_ == null) { |
544 this.loadingTimeout_ = setTimeout( | 530 this.loadingTimeout_ = setTimeout( |
545 this.showMessage_.bind(this, | 531 this.showMessage_.bind( |
546 print_preview.PreviewAreaMessageId_.LOADING), | 532 this, print_preview.PreviewAreaMessageId_.LOADING), |
547 PreviewArea.LOADING_TIMEOUT_); | 533 PreviewArea.LOADING_TIMEOUT_); |
548 } | 534 } |
549 } else { | 535 } else { |
550 this.marginControlContainer_.showMarginControlsIfNeeded(); | 536 this.marginControlContainer_.showMarginControlsIfNeeded(); |
551 } | 537 } |
552 }, | 538 }, |
553 | 539 |
554 /** | 540 /** |
555 * Called when the preview generator begins loading the preview. | 541 * Called when the preview generator begins loading the preview. |
556 * @param {Event} event Contains the URL to initialize the plugin to. | 542 * @param {Event} event Contains the URL to initialize the plugin to. |
557 * @private | 543 * @private |
558 */ | 544 */ |
559 onPreviewStart_: function(event) { | 545 onPreviewStart_: function(event) { |
560 this.isDocumentReady_ = false; | 546 this.isDocumentReady_ = false; |
561 this.isPluginReloaded_ = false; | 547 this.isPluginReloaded_ = false; |
562 if (!this.plugin_) { | 548 if (!this.plugin_) { |
563 this.createPlugin_(event.previewUrl); | 549 this.createPlugin_(event.previewUrl); |
564 } | 550 } |
565 this.plugin_.resetPrintPreviewMode( | 551 this.plugin_.resetPrintPreviewMode( |
566 event.previewUrl, | 552 event.previewUrl, !this.printTicketStore_.color.getValue(), |
567 !this.printTicketStore_.color.getValue(), | |
568 this.printTicketStore_.pageRange.getPageNumberSet().asArray(), | 553 this.printTicketStore_.pageRange.getPageNumberSet().asArray(), |
569 this.documentInfo_.isModifiable); | 554 this.documentInfo_.isModifiable); |
570 | 555 |
571 cr.dispatchSimpleEvent( | 556 cr.dispatchSimpleEvent( |
572 this, PreviewArea.EventType.PREVIEW_GENERATION_IN_PROGRESS); | 557 this, PreviewArea.EventType.PREVIEW_GENERATION_IN_PROGRESS); |
573 }, | 558 }, |
574 | 559 |
575 /** | 560 /** |
576 * Called when a page preview has been generated. Updates the plugin with | 561 * Called when a page preview has been generated. Updates the plugin with |
577 * the new page. | 562 * the new page. |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
625 this.isPluginReloaded_ = true; | 610 this.isPluginReloaded_ = true; |
626 this.dispatchPreviewGenerationDoneIfReady_(); | 611 this.dispatchPreviewGenerationDoneIfReady_(); |
627 }, | 612 }, |
628 | 613 |
629 /** | 614 /** |
630 * Called when the preview plugin's visual state has changed. This is a | 615 * Called when the preview plugin's visual state has changed. This is a |
631 * consequence of scrolling or zooming the plugin. Updates the custom | 616 * consequence of scrolling or zooming the plugin. Updates the custom |
632 * margins component if shown. | 617 * margins component if shown. |
633 * @private | 618 * @private |
634 */ | 619 */ |
635 onPreviewVisualStateChange_: function(pageX, | 620 onPreviewVisualStateChange_: function( |
636 pageY, | 621 pageX, pageY, pageWidth, viewportWidth, viewportHeight) { |
637 pageWidth, | |
638 viewportWidth, | |
639 viewportHeight) { | |
640 this.marginControlContainer_.updateTranslationTransform( | 622 this.marginControlContainer_.updateTranslationTransform( |
641 new print_preview.Coordinate2d(pageX, pageY)); | 623 new print_preview.Coordinate2d(pageX, pageY)); |
642 this.marginControlContainer_.updateScaleTransform( | 624 this.marginControlContainer_.updateScaleTransform( |
643 pageWidth / this.documentInfo_.pageSize.width); | 625 pageWidth / this.documentInfo_.pageSize.width); |
644 this.marginControlContainer_.updateClippingMask( | 626 this.marginControlContainer_.updateClippingMask( |
645 new print_preview.Size(viewportWidth, viewportHeight)); | 627 new print_preview.Size(viewportWidth, viewportHeight)); |
646 }, | 628 }, |
647 | 629 |
648 /** | 630 /** |
649 * Called when dragging margins starts or stops. | 631 * Called when dragging margins starts or stops. |
650 * @param {boolean} isDragging True if the margin is currently being dragged | 632 * @param {boolean} isDragging True if the margin is currently being dragged |
651 * and false otherwise. | 633 * and false otherwise. |
652 */ | 634 */ |
653 onMarginDragChanged_: function(isDragging) { | 635 onMarginDragChanged_: function(isDragging) { |
654 if (!this.plugin_) | 636 if (!this.plugin_) |
655 return; | 637 return; |
656 | 638 |
657 // When hovering over the plugin (which may be in a separate iframe) | 639 // When hovering over the plugin (which may be in a separate iframe) |
658 // pointer events will be sent to the frame. When dragging the margins, | 640 // pointer events will be sent to the frame. When dragging the margins, |
659 // we don't want this to happen as it can cause the margin to stop | 641 // we don't want this to happen as it can cause the margin to stop |
660 // being draggable. | 642 // being draggable. |
661 this.plugin_.style.pointerEvents = isDragging ? 'none' : 'auto'; | 643 this.plugin_.style.pointerEvents = isDragging ? 'none' : 'auto'; |
662 } | 644 } |
663 }; | 645 }; |
664 | 646 |
665 // Export | 647 // Export |
666 return { | 648 return {PreviewArea: PreviewArea}; |
667 PreviewArea: PreviewArea | |
668 }; | |
669 }); | 649 }); |
OLD | NEW |