| 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 /** | 5 /** |
| 6 * @typedef {{accessibility: Function, | 6 * @typedef {{accessibility: Function, |
| 7 * documentLoadComplete: Function, | 7 * documentLoadComplete: Function, |
| 8 * getHeight: Function, | 8 * getHeight: Function, |
| 9 * getHorizontalScrollbarThickness: Function, | 9 * getHorizontalScrollbarThickness: Function, |
| 10 * getPageLocationNormalized: Function, | 10 * getPageLocationNormalized: Function, |
| (...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 98 * @private | 98 * @private |
| 99 */ | 99 */ |
| 100 this.plugin_ = null; | 100 this.plugin_ = null; |
| 101 | 101 |
| 102 /** | 102 /** |
| 103 * Custom margins component superimposed on the preview plugin. | 103 * Custom margins component superimposed on the preview plugin. |
| 104 * @type {!print_preview.MarginControlContainer} | 104 * @type {!print_preview.MarginControlContainer} |
| 105 * @private | 105 * @private |
| 106 */ | 106 */ |
| 107 this.marginControlContainer_ = new print_preview.MarginControlContainer( | 107 this.marginControlContainer_ = new print_preview.MarginControlContainer( |
| 108 this.documentInfo_, | 108 this.documentInfo_, this.printTicketStore_.marginsType, |
| 109 this.printTicketStore_.marginsType, | |
| 110 this.printTicketStore_.customMargins, | 109 this.printTicketStore_.customMargins, |
| 111 this.printTicketStore_.measurementSystem, | 110 this.printTicketStore_.measurementSystem, |
| 112 this.onMarginDragChanged_.bind(this)); | 111 this.onMarginDragChanged_.bind(this)); |
| 113 this.addChild(this.marginControlContainer_); | 112 this.addChild(this.marginControlContainer_); |
| 114 | 113 |
| 115 /** | 114 /** |
| 116 * Current zoom level as a percentage. | 115 * Current zoom level as a percentage. |
| 117 * @type {?number} | 116 * @type {?number} |
| 118 * @private | 117 * @private |
| 119 */ | 118 */ |
| (...skipping 186 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 306 */ | 305 */ |
| 307 showCustomMessage: function(message) { | 306 showCustomMessage: function(message) { |
| 308 this.showMessage_(PreviewArea.MessageId_.CUSTOM, message); | 307 this.showMessage_(PreviewArea.MessageId_.CUSTOM, message); |
| 309 }, | 308 }, |
| 310 | 309 |
| 311 /** @override */ | 310 /** @override */ |
| 312 enterDocument: function() { | 311 enterDocument: function() { |
| 313 print_preview.Component.prototype.enterDocument.call(this); | 312 print_preview.Component.prototype.enterDocument.call(this); |
| 314 | 313 |
| 315 this.tracker.add( | 314 this.tracker.add( |
| 316 assert(this.openSystemDialogButton_), | 315 assert(this.openSystemDialogButton_), 'click', |
| 317 'click', | |
| 318 this.onOpenSystemDialogButtonClick_.bind(this)); | 316 this.onOpenSystemDialogButtonClick_.bind(this)); |
| 319 | 317 |
| 320 var TicketStoreEvent = print_preview.PrintTicketStore.EventType; | 318 var TicketStoreEvent = print_preview.PrintTicketStore.EventType; |
| 321 [ | 319 [TicketStoreEvent.INITIALIZE, TicketStoreEvent.TICKET_CHANGE, |
| 322 TicketStoreEvent.INITIALIZE, | 320 TicketStoreEvent.CAPABILITIES_CHANGE, TicketStoreEvent.DOCUMENT_CHANGE] |
| 323 TicketStoreEvent.TICKET_CHANGE, | 321 .forEach(function(eventType) { |
| 324 TicketStoreEvent.CAPABILITIES_CHANGE, | 322 this.tracker.add( |
| 325 TicketStoreEvent.DOCUMENT_CHANGE | 323 this.printTicketStore_, eventType, |
| 326 ].forEach(function(eventType) { | 324 this.onTicketChange_.bind(this)); |
| 327 this.tracker.add(this.printTicketStore_, eventType, | 325 }.bind(this)); |
| 328 this.onTicketChange_.bind(this)); | |
| 329 }.bind(this)); | |
| 330 | 326 |
| 331 [ | 327 [this.printTicketStore_.color, this.printTicketStore_.cssBackground, |
| 332 this.printTicketStore_.color, | 328 this.printTicketStore_.customMargins, this.printTicketStore_.fitToPage, |
| 333 this.printTicketStore_.cssBackground, | 329 this.printTicketStore_.headerFooter, this.printTicketStore_.landscape, |
| 334 this.printTicketStore_.customMargins, | 330 this.printTicketStore_.marginsType, this.printTicketStore_.pageRange, |
| 335 this.printTicketStore_.fitToPage, | 331 this.printTicketStore_.rasterize, this.printTicketStore_.selectionOnly, |
| 336 this.printTicketStore_.headerFooter, | 332 this.printTicketStore_.scaling] |
| 337 this.printTicketStore_.landscape, | 333 .forEach(function(setting) { |
| 338 this.printTicketStore_.marginsType, | 334 this.tracker.add( |
| 339 this.printTicketStore_.pageRange, | 335 setting, print_preview.ticket_items.TicketItem.EventType.CHANGE, |
| 340 this.printTicketStore_.rasterize, | 336 this.onTicketChange_.bind(this)); |
| 341 this.printTicketStore_.selectionOnly, | 337 }.bind(this)); |
| 342 this.printTicketStore_.scaling | |
| 343 ].forEach(function(setting) { | |
| 344 this.tracker.add( | |
| 345 setting, | |
| 346 print_preview.ticket_items.TicketItem.EventType.CHANGE, | |
| 347 this.onTicketChange_.bind(this)); | |
| 348 }.bind(this)); | |
| 349 | 338 |
| 350 if (this.checkPluginCompatibility_()) { | 339 if (this.checkPluginCompatibility_()) { |
| 351 this.previewGenerator_ = new print_preview.PreviewGenerator( | 340 this.previewGenerator_ = new print_preview.PreviewGenerator( |
| 352 this.destinationStore_, | 341 this.destinationStore_, this.printTicketStore_, this.nativeLayer_, |
| 353 this.printTicketStore_, | |
| 354 this.nativeLayer_, | |
| 355 this.documentInfo_); | 342 this.documentInfo_); |
| 356 this.tracker.add( | 343 this.tracker.add( |
| 357 this.previewGenerator_, | 344 this.previewGenerator_, |
| 358 print_preview.PreviewGenerator.EventType.PREVIEW_START, | 345 print_preview.PreviewGenerator.EventType.PREVIEW_START, |
| 359 this.onPreviewStart_.bind(this)); | 346 this.onPreviewStart_.bind(this)); |
| 360 this.tracker.add( | 347 this.tracker.add( |
| 361 this.previewGenerator_, | 348 this.previewGenerator_, |
| 362 print_preview.PreviewGenerator.EventType.PAGE_READY, | 349 print_preview.PreviewGenerator.EventType.PAGE_READY, |
| 363 this.onPagePreviewReady_.bind(this)); | 350 this.onPagePreviewReady_.bind(this)); |
| 364 this.tracker.add( | 351 this.tracker.add( |
| (...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 434 | 421 |
| 435 // Show specific message. | 422 // Show specific message. |
| 436 if (messageId == PreviewArea.MessageId_.CUSTOM) { | 423 if (messageId == PreviewArea.MessageId_.CUSTOM) { |
| 437 var customMessageTextEl = this.getElement().getElementsByClassName( | 424 var customMessageTextEl = this.getElement().getElementsByClassName( |
| 438 PreviewArea.Classes_.CUSTOM_MESSAGE_TEXT)[0]; | 425 PreviewArea.Classes_.CUSTOM_MESSAGE_TEXT)[0]; |
| 439 customMessageTextEl.textContent = opt_message; | 426 customMessageTextEl.textContent = opt_message; |
| 440 } else if (messageId == PreviewArea.MessageId_.LOADING) { | 427 } else if (messageId == PreviewArea.MessageId_.LOADING) { |
| 441 jumpingDotsEl.classList.add('jumping-dots'); | 428 jumpingDotsEl.classList.add('jumping-dots'); |
| 442 } | 429 } |
| 443 var messageEl = this.getElement().getElementsByClassName( | 430 var messageEl = this.getElement().getElementsByClassName( |
| 444 PreviewArea.MessageIdClassMap_[messageId])[0]; | 431 PreviewArea.MessageIdClassMap_[messageId])[0]; |
| 445 setIsVisible(messageEl, true); | 432 setIsVisible(messageEl, true); |
| 446 | 433 |
| 447 this.setOverlayVisible_(true); | 434 this.setOverlayVisible_(true); |
| 448 }, | 435 }, |
| 449 | 436 |
| 450 /** | 437 /** |
| 451 * Set the visibility of the message overlay. | 438 * Set the visibility of the message overlay. |
| 452 * @param {boolean} visible Whether to make the overlay visible or not | 439 * @param {boolean} visible Whether to make the overlay visible or not |
| 453 * @private | 440 * @private |
| 454 */ | 441 */ |
| 455 setOverlayVisible_: function(visible) { | 442 setOverlayVisible_: function(visible) { |
| 456 this.overlayEl_.classList.toggle( | 443 this.overlayEl_.classList.toggle( |
| 457 PreviewArea.Classes_.INVISIBLE, | 444 PreviewArea.Classes_.INVISIBLE, !visible); |
| 458 !visible); | |
| 459 this.overlayEl_.setAttribute('aria-hidden', !visible); | 445 this.overlayEl_.setAttribute('aria-hidden', !visible); |
| 460 | 446 |
| 461 // Hide/show all controls that will overlap when the overlay is visible. | 447 // Hide/show all controls that will overlap when the overlay is visible. |
| 462 var marginControls = this.getElement().getElementsByClassName( | 448 var marginControls = this.getElement().getElementsByClassName( |
| 463 PreviewArea.Classes_.MARGIN_CONTROL); | 449 PreviewArea.Classes_.MARGIN_CONTROL); |
| 464 for (var i = 0; i < marginControls.length; ++i) { | 450 for (var i = 0; i < marginControls.length; ++i) { |
| 465 marginControls[i].setAttribute('aria-hidden', visible); | 451 marginControls[i].setAttribute('aria-hidden', visible); |
| 466 } | 452 } |
| 467 var previewAreaControls = this.getElement().getElementsByClassName( | 453 var previewAreaControls = this.getElement().getElementsByClassName( |
| 468 PreviewArea.Classes_.PREVIEW_AREA); | 454 PreviewArea.Classes_.PREVIEW_AREA); |
| (...skipping 13 matching lines...) Expand all Loading... |
| 482 * Creates a preview plugin and adds it to the DOM. | 468 * Creates a preview plugin and adds it to the DOM. |
| 483 * @param {string} srcUrl Initial URL of the plugin. | 469 * @param {string} srcUrl Initial URL of the plugin. |
| 484 * @private | 470 * @private |
| 485 */ | 471 */ |
| 486 createPlugin_: function(srcUrl) { | 472 createPlugin_: function(srcUrl) { |
| 487 if (this.plugin_) { | 473 if (this.plugin_) { |
| 488 console.warn('Pdf preview plugin already created'); | 474 console.warn('Pdf preview plugin already created'); |
| 489 return; | 475 return; |
| 490 } | 476 } |
| 491 | 477 |
| 492 this.plugin_ = /** @type {print_preview.PDFPlugin} */( | 478 this.plugin_ = /** @type {print_preview.PDFPlugin} */ ( |
| 493 PDFCreateOutOfProcessPlugin(srcUrl)); | 479 PDFCreateOutOfProcessPlugin(srcUrl)); |
| 494 this.plugin_.setKeyEventCallback(this.keyEventCallback_); | 480 this.plugin_.setKeyEventCallback(this.keyEventCallback_); |
| 495 | 481 |
| 496 this.plugin_.setAttribute('class', 'preview-area-plugin'); | 482 this.plugin_.setAttribute('class', 'preview-area-plugin'); |
| 497 this.plugin_.setAttribute('aria-live', 'polite'); | 483 this.plugin_.setAttribute('aria-live', 'polite'); |
| 498 this.plugin_.setAttribute('aria-atomic', 'true'); | 484 this.plugin_.setAttribute('aria-atomic', 'true'); |
| 499 // NOTE: The plugin's 'id' field must be set to 'pdf-viewer' since | 485 // NOTE: The plugin's 'id' field must be set to 'pdf-viewer' since |
| 500 // chrome/renderer/printing/print_web_view_helper.cc actually references | 486 // chrome/renderer/printing/print_web_view_helper.cc actually references |
| 501 // it. | 487 // it. |
| 502 this.plugin_.setAttribute('id', 'pdf-viewer'); | 488 this.plugin_.setAttribute('id', 'pdf-viewer'); |
| 503 this.getChildElement('.preview-area-plugin-wrapper'). | 489 this.getChildElement('.preview-area-plugin-wrapper') |
| 504 appendChild(/** @type {Node} */(this.plugin_)); | 490 .appendChild(/** @type {Node} */ (this.plugin_)); |
| 505 | 491 |
| 506 | 492 |
| 507 var pageNumbers = | 493 var pageNumbers = |
| 508 this.printTicketStore_.pageRange.getPageNumberSet().asArray(); | 494 this.printTicketStore_.pageRange.getPageNumberSet().asArray(); |
| 509 var grayscale = !this.printTicketStore_.color.getValue(); | 495 var grayscale = !this.printTicketStore_.color.getValue(); |
| 510 this.plugin_.setLoadCallback(this.onPluginLoad_.bind(this)); | 496 this.plugin_.setLoadCallback(this.onPluginLoad_.bind(this)); |
| 511 this.plugin_.setViewportChangedCallback( | 497 this.plugin_.setViewportChangedCallback( |
| 512 this.onPreviewVisualStateChange_.bind(this)); | 498 this.onPreviewVisualStateChange_.bind(this)); |
| 513 this.plugin_.resetPrintPreviewMode(srcUrl, grayscale, pageNumbers, | 499 this.plugin_.resetPrintPreviewMode( |
| 514 this.documentInfo_.isModifiable); | 500 srcUrl, grayscale, pageNumbers, this.documentInfo_.isModifiable); |
| 515 }, | 501 }, |
| 516 | 502 |
| 517 /** | 503 /** |
| 518 * Dispatches a PREVIEW_GENERATION_DONE event if all conditions are met. | 504 * Dispatches a PREVIEW_GENERATION_DONE event if all conditions are met. |
| 519 * @private | 505 * @private |
| 520 */ | 506 */ |
| 521 dispatchPreviewGenerationDoneIfReady_: function() { | 507 dispatchPreviewGenerationDoneIfReady_: function() { |
| 522 if (this.isDocumentReady_ && this.isPluginReloaded_) { | 508 if (this.isDocumentReady_ && this.isPluginReloaded_) { |
| 523 cr.dispatchSimpleEvent( | 509 cr.dispatchSimpleEvent( |
| 524 this, PreviewArea.EventType.PREVIEW_GENERATION_DONE); | 510 this, PreviewArea.EventType.PREVIEW_GENERATION_DONE); |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 567 onPreviewStart_: function(event) { | 553 onPreviewStart_: function(event) { |
| 568 this.isDocumentReady_ = false; | 554 this.isDocumentReady_ = false; |
| 569 this.isPluginReloaded_ = false; | 555 this.isPluginReloaded_ = false; |
| 570 if (!this.plugin_) { | 556 if (!this.plugin_) { |
| 571 this.createPlugin_(event.previewUrl); | 557 this.createPlugin_(event.previewUrl); |
| 572 } else { | 558 } else { |
| 573 var grayscale = !this.printTicketStore_.color.getValue(); | 559 var grayscale = !this.printTicketStore_.color.getValue(); |
| 574 var pageNumbers = | 560 var pageNumbers = |
| 575 this.printTicketStore_.pageRange.getPageNumberSet().asArray(); | 561 this.printTicketStore_.pageRange.getPageNumberSet().asArray(); |
| 576 var url = event.previewUrl; | 562 var url = event.previewUrl; |
| 577 this.plugin_.resetPrintPreviewMode(url, grayscale, pageNumbers, | 563 this.plugin_.resetPrintPreviewMode( |
| 578 this.documentInfo_.isModifiable); | 564 url, grayscale, pageNumbers, this.documentInfo_.isModifiable); |
| 579 } | 565 } |
| 580 cr.dispatchSimpleEvent( | 566 cr.dispatchSimpleEvent( |
| 581 this, PreviewArea.EventType.PREVIEW_GENERATION_IN_PROGRESS); | 567 this, PreviewArea.EventType.PREVIEW_GENERATION_IN_PROGRESS); |
| 582 }, | 568 }, |
| 583 | 569 |
| 584 /** | 570 /** |
| 585 * Called when a page preview has been generated. Updates the plugin with | 571 * Called when a page preview has been generated. Updates the plugin with |
| 586 * the new page. | 572 * the new page. |
| 587 * @param {Event} event Contains information about the page preview. | 573 * @param {Event} event Contains information about the page preview. |
| 588 * @private | 574 * @private |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 631 this.isPluginReloaded_ = true; | 617 this.isPluginReloaded_ = true; |
| 632 this.dispatchPreviewGenerationDoneIfReady_(); | 618 this.dispatchPreviewGenerationDoneIfReady_(); |
| 633 }, | 619 }, |
| 634 | 620 |
| 635 /** | 621 /** |
| 636 * Called when the preview plugin's visual state has changed. This is a | 622 * Called when the preview plugin's visual state has changed. This is a |
| 637 * consequence of scrolling or zooming the plugin. Updates the custom | 623 * consequence of scrolling or zooming the plugin. Updates the custom |
| 638 * margins component if shown. | 624 * margins component if shown. |
| 639 * @private | 625 * @private |
| 640 */ | 626 */ |
| 641 onPreviewVisualStateChange_: function(pageX, | 627 onPreviewVisualStateChange_: function( |
| 642 pageY, | 628 pageX, pageY, pageWidth, viewportWidth, viewportHeight) { |
| 643 pageWidth, | |
| 644 viewportWidth, | |
| 645 viewportHeight) { | |
| 646 this.marginControlContainer_.updateTranslationTransform( | 629 this.marginControlContainer_.updateTranslationTransform( |
| 647 new print_preview.Coordinate2d(pageX, pageY)); | 630 new print_preview.Coordinate2d(pageX, pageY)); |
| 648 this.marginControlContainer_.updateScaleTransform( | 631 this.marginControlContainer_.updateScaleTransform( |
| 649 pageWidth / this.documentInfo_.pageSize.width); | 632 pageWidth / this.documentInfo_.pageSize.width); |
| 650 this.marginControlContainer_.updateClippingMask( | 633 this.marginControlContainer_.updateClippingMask( |
| 651 new print_preview.Size(viewportWidth, viewportHeight)); | 634 new print_preview.Size(viewportWidth, viewportHeight)); |
| 652 }, | 635 }, |
| 653 | 636 |
| 654 /** | 637 /** |
| 655 * Called when dragging margins starts or stops. | 638 * Called when dragging margins starts or stops. |
| 656 * @param {boolean} isDragging True if the margin is currently being dragged | 639 * @param {boolean} isDragging True if the margin is currently being dragged |
| 657 * and false otherwise. | 640 * and false otherwise. |
| 658 */ | 641 */ |
| 659 onMarginDragChanged_: function(isDragging) { | 642 onMarginDragChanged_: function(isDragging) { |
| 660 if (!this.plugin_) | 643 if (!this.plugin_) |
| 661 return; | 644 return; |
| 662 | 645 |
| 663 // When hovering over the plugin (which may be in a separate iframe) | 646 // When hovering over the plugin (which may be in a separate iframe) |
| 664 // pointer events will be sent to the frame. When dragging the margins, | 647 // pointer events will be sent to the frame. When dragging the margins, |
| 665 // we don't want this to happen as it can cause the margin to stop | 648 // we don't want this to happen as it can cause the margin to stop |
| 666 // being draggable. | 649 // being draggable. |
| 667 this.plugin_.style.pointerEvents = isDragging ? 'none' : 'auto'; | 650 this.plugin_.style.pointerEvents = isDragging ? 'none' : 'auto'; |
| 668 } | 651 } |
| 669 }; | 652 }; |
| 670 | 653 |
| 671 // Export | 654 // Export |
| 672 return { | 655 return {PreviewArea: PreviewArea}; |
| 673 PreviewArea: PreviewArea | |
| 674 }; | |
| 675 }); | 656 }); |
| OLD | NEW |