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 173 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
184 PREVIEW_GENERATION_IN_PROGRESS: | 184 PREVIEW_GENERATION_IN_PROGRESS: |
185 'print_preview.PreviewArea.PREVIEW_GENERATION_IN_PROGRESS' | 185 'print_preview.PreviewArea.PREVIEW_GENERATION_IN_PROGRESS' |
186 }; | 186 }; |
187 | 187 |
188 /** | 188 /** |
189 * CSS classes used by the preview area. | 189 * CSS classes used by the preview area. |
190 * @enum {string} | 190 * @enum {string} |
191 * @private | 191 * @private |
192 */ | 192 */ |
193 PreviewArea.Classes_ = { | 193 PreviewArea.Classes_ = { |
194 COMPATIBILITY_OBJECT: 'preview-area-compatibility-object', | |
195 OUT_OF_PROCESS_COMPATIBILITY_OBJECT: | 194 OUT_OF_PROCESS_COMPATIBILITY_OBJECT: |
196 'preview-area-compatibility-object-out-of-process', | 195 'preview-area-compatibility-object-out-of-process', |
197 CUSTOM_MESSAGE_TEXT: 'preview-area-custom-message-text', | 196 CUSTOM_MESSAGE_TEXT: 'preview-area-custom-message-text', |
198 MESSAGE: 'preview-area-message', | 197 MESSAGE: 'preview-area-message', |
199 INVISIBLE: 'invisible', | 198 INVISIBLE: 'invisible', |
200 OPEN_SYSTEM_DIALOG_BUTTON: 'preview-area-open-system-dialog-button', | 199 OPEN_SYSTEM_DIALOG_BUTTON: 'preview-area-open-system-dialog-button', |
201 OPEN_SYSTEM_DIALOG_BUTTON_THROBBER: | 200 OPEN_SYSTEM_DIALOG_BUTTON_THROBBER: |
202 'preview-area-open-system-dialog-button-throbber', | 201 'preview-area-open-system-dialog-button-throbber', |
203 OVERLAY: 'preview-area-overlay-layer', | 202 OVERLAY: 'preview-area-overlay-layer', |
204 MARGIN_CONTROL: 'margin-control', | 203 MARGIN_CONTROL: 'margin-control', |
205 PREVIEW_AREA: 'preview-area-plugin-wrapper' | 204 PREVIEW_AREA: 'preview-area-plugin-wrapper' |
206 }; | 205 }; |
207 | 206 |
208 /** | 207 /** |
209 * Enumeration of IDs shown in the preview area. | 208 * Enumeration of IDs shown in the preview area. |
210 * @enum {string} | 209 * @enum {string} |
211 * @private | 210 * @private |
212 */ | 211 */ |
213 PreviewArea.MessageId_ = { | 212 PreviewArea.MessageId_ = { |
214 CUSTOM: 'custom', | 213 CUSTOM: 'custom', |
215 LOADING: 'loading', | 214 LOADING: 'loading', |
216 PREVIEW_FAILED: 'preview-failed' | 215 PREVIEW_FAILED: 'preview-failed' |
217 }; | 216 }; |
218 | 217 |
219 /** | 218 /** |
220 * Enumeration of PDF plugin types for print preview. | |
221 * @enum {string} | |
222 * @private | |
223 */ | |
224 PreviewArea.PluginType_ = { | |
225 // TODO(raymes): Remove all references to the IN_PROCESS plugin once it is | |
226 // removed. | |
227 IN_PROCESS: 'in-process', | |
228 OUT_OF_PROCESS: 'out-of-process', | |
229 NONE: 'none' | |
230 }; | |
231 | |
232 /** | |
233 * Maps message IDs to the CSS class that contains them. | 219 * Maps message IDs to the CSS class that contains them. |
234 * @type {Object<print_preview.PreviewArea.MessageId_, string>} | 220 * @type {Object<print_preview.PreviewArea.MessageId_, string>} |
235 * @private | 221 * @private |
236 */ | 222 */ |
237 PreviewArea.MessageIdClassMap_ = {}; | 223 PreviewArea.MessageIdClassMap_ = {}; |
238 PreviewArea.MessageIdClassMap_[PreviewArea.MessageId_.CUSTOM] = | 224 PreviewArea.MessageIdClassMap_[PreviewArea.MessageId_.CUSTOM] = |
239 'preview-area-custom-message'; | 225 'preview-area-custom-message'; |
240 PreviewArea.MessageIdClassMap_[PreviewArea.MessageId_.LOADING] = | 226 PreviewArea.MessageIdClassMap_[PreviewArea.MessageId_.LOADING] = |
241 'preview-area-loading-message'; | 227 'preview-area-loading-message'; |
242 PreviewArea.MessageIdClassMap_[PreviewArea.MessageId_.PREVIEW_FAILED] = | 228 PreviewArea.MessageIdClassMap_[PreviewArea.MessageId_.PREVIEW_FAILED] = |
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
377 this.onTicketChange_.bind(this)); | 363 this.onTicketChange_.bind(this)); |
378 this.tracker.add( | 364 this.tracker.add( |
379 this.printTicketStore_.pageRange, | 365 this.printTicketStore_.pageRange, |
380 print_preview.ticket_items.TicketItem.EventType.CHANGE, | 366 print_preview.ticket_items.TicketItem.EventType.CHANGE, |
381 this.onTicketChange_.bind(this)); | 367 this.onTicketChange_.bind(this)); |
382 this.tracker.add( | 368 this.tracker.add( |
383 this.printTicketStore_.selectionOnly, | 369 this.printTicketStore_.selectionOnly, |
384 print_preview.ticket_items.TicketItem.EventType.CHANGE, | 370 print_preview.ticket_items.TicketItem.EventType.CHANGE, |
385 this.onTicketChange_.bind(this)); | 371 this.onTicketChange_.bind(this)); |
386 | 372 |
387 this.pluginType_ = this.getPluginType_(); | 373 if (this.checkPluginCompatibility_()) { |
388 if (this.pluginType_ != PreviewArea.PluginType_.NONE) { | |
389 this.previewGenerator_ = new print_preview.PreviewGenerator( | 374 this.previewGenerator_ = new print_preview.PreviewGenerator( |
390 this.destinationStore_, | 375 this.destinationStore_, |
391 this.printTicketStore_, | 376 this.printTicketStore_, |
392 this.nativeLayer_, | 377 this.nativeLayer_, |
393 this.documentInfo_); | 378 this.documentInfo_); |
394 this.tracker.add( | 379 this.tracker.add( |
395 this.previewGenerator_, | 380 this.previewGenerator_, |
396 print_preview.PreviewGenerator.EventType.PREVIEW_START, | 381 print_preview.PreviewGenerator.EventType.PREVIEW_START, |
397 this.onPreviewStart_.bind(this)); | 382 this.onPreviewStart_.bind(this)); |
398 this.tracker.add( | 383 this.tracker.add( |
(...skipping 28 matching lines...) Expand all Loading... |
427 this.marginControlContainer_.decorate(this.getElement()); | 412 this.marginControlContainer_.decorate(this.getElement()); |
428 this.overlayEl_ = this.getElement().getElementsByClassName( | 413 this.overlayEl_ = this.getElement().getElementsByClassName( |
429 PreviewArea.Classes_.OVERLAY)[0]; | 414 PreviewArea.Classes_.OVERLAY)[0]; |
430 this.openSystemDialogButton_ = this.getElement().getElementsByClassName( | 415 this.openSystemDialogButton_ = this.getElement().getElementsByClassName( |
431 PreviewArea.Classes_.OPEN_SYSTEM_DIALOG_BUTTON)[0]; | 416 PreviewArea.Classes_.OPEN_SYSTEM_DIALOG_BUTTON)[0]; |
432 }, | 417 }, |
433 | 418 |
434 /** | 419 /** |
435 * Checks to see if a suitable plugin for rendering the preview exists. If | 420 * Checks to see if a suitable plugin for rendering the preview exists. If |
436 * one does not exist, then an error message will be displayed. | 421 * one does not exist, then an error message will be displayed. |
437 * @return {string} A string constant indicating whether Chromium has a | 422 * @return {boolean} true if Chromium has a plugin for rendering the |
438 * plugin for rendering the preview. | 423 * the preview. |
439 * PreviewArea.PluginType_.IN_PROCESS for an in-process plugin | |
440 * PreviewArea.PluginType_.OUT_OF_PROCESS for an out-of-process plugin | |
441 * PreviewArea.PluginType_.NONE if no plugin is available. | |
442 * @private | 424 * @private |
443 */ | 425 */ |
444 getPluginType_: function() { | 426 checkPluginCompatibility_: function() { |
445 // TODO(raymes): Remove the in-process check after we remove the | |
446 // in-process plugin. Change this function back to | |
447 // checkPluginCompatibility_(). | |
448 /** @type {print_preview.PDFPlugin} */ | |
449 var compatObj = this.getElement().getElementsByClassName( | |
450 PreviewArea.Classes_.COMPATIBILITY_OBJECT)[0]; | |
451 var isCompatible = | |
452 compatObj.onload && | |
453 compatObj.goToPage && | |
454 compatObj.removePrintButton && | |
455 compatObj.loadPreviewPage && | |
456 compatObj.printPreviewPageCount && | |
457 compatObj.resetPrintPreviewUrl && | |
458 compatObj.onPluginSizeChanged && | |
459 compatObj.onScroll && | |
460 compatObj.pageXOffset && | |
461 compatObj.pageYOffset && | |
462 compatObj.setZoomLevel && | |
463 compatObj.setPageNumbers && | |
464 compatObj.setPageXOffset && | |
465 compatObj.setPageYOffset && | |
466 compatObj.getHorizontalScrollbarThickness && | |
467 compatObj.getVerticalScrollbarThickness && | |
468 compatObj.getPageLocationNormalized && | |
469 compatObj.getHeight && | |
470 compatObj.getWidth; | |
471 compatObj.parentElement.removeChild(compatObj); | |
472 | |
473 // TODO(raymes): It's harder to test compatibility of the out of process | 427 // TODO(raymes): It's harder to test compatibility of the out of process |
474 // plugin because it's asynchronous. We could do a better job at some | 428 // plugin because it's asynchronous. We could do a better job at some |
475 // point. | 429 // point. |
476 var oopCompatObj = this.getElement().getElementsByClassName( | 430 var oopCompatObj = this.getElement().getElementsByClassName( |
477 PreviewArea.Classes_.OUT_OF_PROCESS_COMPATIBILITY_OBJECT)[0]; | 431 PreviewArea.Classes_.OUT_OF_PROCESS_COMPATIBILITY_OBJECT)[0]; |
478 var isOOPCompatible = oopCompatObj.postMessage; | 432 var isOOPCompatible = oopCompatObj.postMessage; |
479 oopCompatObj.parentElement.removeChild(oopCompatObj); | 433 oopCompatObj.parentElement.removeChild(oopCompatObj); |
480 | 434 |
481 if (isCompatible) | 435 return isOOPCompatible; |
482 return PreviewArea.PluginType_.IN_PROCESS; | |
483 if (isOOPCompatible) | |
484 return PreviewArea.PluginType_.OUT_OF_PROCESS; | |
485 return PreviewArea.PluginType_.NONE; | |
486 }, | 436 }, |
487 | 437 |
488 /** | 438 /** |
489 * Shows a given message on the overlay. | 439 * Shows a given message on the overlay. |
490 * @param {!print_preview.PreviewArea.MessageId_} messageId ID of the | 440 * @param {!print_preview.PreviewArea.MessageId_} messageId ID of the |
491 * message to show. | 441 * message to show. |
492 * @param {string=} opt_message Optional message to show that can be used | 442 * @param {string=} opt_message Optional message to show that can be used |
493 * by some message IDs. | 443 * by some message IDs. |
494 * @private | 444 * @private |
495 */ | 445 */ |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
555 * Creates a preview plugin and adds it to the DOM. | 505 * Creates a preview plugin and adds it to the DOM. |
556 * @param {string} srcUrl Initial URL of the plugin. | 506 * @param {string} srcUrl Initial URL of the plugin. |
557 * @private | 507 * @private |
558 */ | 508 */ |
559 createPlugin_: function(srcUrl) { | 509 createPlugin_: function(srcUrl) { |
560 if (this.plugin_) { | 510 if (this.plugin_) { |
561 console.warn('Pdf preview plugin already created'); | 511 console.warn('Pdf preview plugin already created'); |
562 return; | 512 return; |
563 } | 513 } |
564 | 514 |
565 if (this.pluginType_ == PreviewArea.PluginType_.IN_PROCESS) { | 515 this.plugin_ = /** @type {print_preview.PDFPlugin} */( |
566 this.plugin_ = assertInstanceof(document.createElement('embed'), | 516 PDFCreateOutOfProcessPlugin(srcUrl)); |
567 HTMLEmbedElement); | 517 this.plugin_.setKeyEventCallback(this.keyEventCallback_); |
568 this.plugin_.setAttribute( | |
569 'type', 'application/x-google-chrome-print-preview-pdf'); | |
570 this.plugin_.setAttribute('src', srcUrl); | |
571 } else { | |
572 this.plugin_ = /** @type {print_preview.PDFPlugin} */( | |
573 PDFCreateOutOfProcessPlugin(srcUrl)); | |
574 this.plugin_.setKeyEventCallback(this.keyEventCallback_); | |
575 } | |
576 | 518 |
577 this.plugin_.setAttribute('class', 'preview-area-plugin'); | 519 this.plugin_.setAttribute('class', 'preview-area-plugin'); |
578 this.plugin_.setAttribute('aria-live', 'polite'); | 520 this.plugin_.setAttribute('aria-live', 'polite'); |
579 this.plugin_.setAttribute('aria-atomic', 'true'); | 521 this.plugin_.setAttribute('aria-atomic', 'true'); |
580 // NOTE: The plugin's 'id' field must be set to 'pdf-viewer' since | 522 // NOTE: The plugin's 'id' field must be set to 'pdf-viewer' since |
581 // chrome/renderer/printing/print_web_view_helper.cc actually references | 523 // chrome/renderer/printing/print_web_view_helper.cc actually references |
582 // it. | 524 // it. |
583 this.plugin_.setAttribute('id', 'pdf-viewer'); | 525 this.plugin_.setAttribute('id', 'pdf-viewer'); |
584 this.getChildElement('.preview-area-plugin-wrapper'). | 526 this.getChildElement('.preview-area-plugin-wrapper'). |
585 appendChild(/** @type {Node} */(this.plugin_)); | 527 appendChild(/** @type {Node} */(this.plugin_)); |
586 | 528 |
587 | 529 |
588 if (this.pluginType_ == PreviewArea.PluginType_.OUT_OF_PROCESS) { | 530 var pageNumbers = |
589 var pageNumbers = | 531 this.printTicketStore_.pageRange.getPageNumberSet().asArray(); |
590 this.printTicketStore_.pageRange.getPageNumberSet().asArray(); | 532 var grayscale = !this.printTicketStore_.color.getValue(); |
591 var grayscale = !this.printTicketStore_.color.getValue(); | 533 this.plugin_.setLoadCallback(this.onPluginLoad_.bind(this)); |
592 this.plugin_.setLoadCallback(this.onPluginLoad_.bind(this)); | 534 this.plugin_.setViewportChangedCallback( |
593 this.plugin_.setViewportChangedCallback( | 535 this.onPreviewVisualStateChange_.bind(this)); |
594 this.onPreviewVisualStateChange_.bind(this)); | 536 this.plugin_.resetPrintPreviewMode(srcUrl, grayscale, pageNumbers, |
595 this.plugin_.resetPrintPreviewMode(srcUrl, grayscale, pageNumbers, | 537 this.documentInfo_.isModifiable); |
596 this.documentInfo_.isModifiable); | |
597 } else { | |
598 global['onPreviewPluginLoad'] = this.onPluginLoad_.bind(this); | |
599 (/** @type {print_preview.PDFPlugin} */(this.plugin_)). | |
600 onload('onPreviewPluginLoad()'); | |
601 | |
602 global['onPreviewPluginVisualStateChange'] = | |
603 this.onPreviewVisualStateChange_.bind(this); | |
604 this.plugin_.onScroll('onPreviewPluginVisualStateChange()'); | |
605 this.plugin_.onPluginSizeChanged('onPreviewPluginVisualStateChange()'); | |
606 | |
607 this.plugin_.removePrintButton(); | |
608 this.plugin_.grayscale(!this.printTicketStore_.color.getValue()); | |
609 } | |
610 }, | 538 }, |
611 | 539 |
612 /** | 540 /** |
613 * Dispatches a PREVIEW_GENERATION_DONE event if all conditions are met. | 541 * Dispatches a PREVIEW_GENERATION_DONE event if all conditions are met. |
614 * @private | 542 * @private |
615 */ | 543 */ |
616 dispatchPreviewGenerationDoneIfReady_: function() { | 544 dispatchPreviewGenerationDoneIfReady_: function() { |
617 if (this.isDocumentReady_ && this.isPluginReloaded_) { | 545 if (this.isDocumentReady_ && this.isPluginReloaded_) { |
618 cr.dispatchSimpleEvent( | 546 cr.dispatchSimpleEvent( |
619 this, PreviewArea.EventType.PREVIEW_GENERATION_DONE); | 547 this, PreviewArea.EventType.PREVIEW_GENERATION_DONE); |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
658 * Called when the preview generator begins loading the preview. | 586 * Called when the preview generator begins loading the preview. |
659 * @param {Event} event Contains the URL to initialize the plugin to. | 587 * @param {Event} event Contains the URL to initialize the plugin to. |
660 * @private | 588 * @private |
661 */ | 589 */ |
662 onPreviewStart_: function(event) { | 590 onPreviewStart_: function(event) { |
663 this.isDocumentReady_ = false; | 591 this.isDocumentReady_ = false; |
664 this.isPluginReloaded_ = false; | 592 this.isPluginReloaded_ = false; |
665 if (!this.plugin_) { | 593 if (!this.plugin_) { |
666 this.createPlugin_(event.previewUrl); | 594 this.createPlugin_(event.previewUrl); |
667 } else { | 595 } else { |
668 if (this.pluginType_ == PreviewArea.PluginType_.OUT_OF_PROCESS) { | 596 var grayscale = !this.printTicketStore_.color.getValue(); |
669 var grayscale = !this.printTicketStore_.color.getValue(); | 597 var pageNumbers = |
670 var pageNumbers = | 598 this.printTicketStore_.pageRange.getPageNumberSet().asArray(); |
671 this.printTicketStore_.pageRange.getPageNumberSet().asArray(); | 599 var url = event.previewUrl; |
672 var url = event.previewUrl; | 600 this.plugin_.resetPrintPreviewMode(url, grayscale, pageNumbers, |
673 this.plugin_.resetPrintPreviewMode(url, grayscale, pageNumbers, | 601 this.documentInfo_.isModifiable); |
674 this.documentInfo_.isModifiable); | |
675 } else if (this.pluginType_ == PreviewArea.PluginType_.IN_PROCESS) { | |
676 this.plugin_.goToPage('0'); | |
677 this.plugin_.resetPrintPreviewUrl(event.previewUrl); | |
678 this.plugin_.reload(); | |
679 this.plugin_.grayscale(!this.printTicketStore_.color.getValue()); | |
680 } | |
681 } | 602 } |
682 cr.dispatchSimpleEvent( | 603 cr.dispatchSimpleEvent( |
683 this, PreviewArea.EventType.PREVIEW_GENERATION_IN_PROGRESS); | 604 this, PreviewArea.EventType.PREVIEW_GENERATION_IN_PROGRESS); |
684 }, | 605 }, |
685 | 606 |
686 /** | 607 /** |
687 * Called when a page preview has been generated. Updates the plugin with | 608 * Called when a page preview has been generated. Updates the plugin with |
688 * the new page. | 609 * the new page. |
689 * @param {Event} event Contains information about the page preview. | 610 * @param {Event} event Contains information about the page preview. |
690 * @private | 611 * @private |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
722 * plugin.reload(). Certain plugin state can only be set after the plugin | 643 * plugin.reload(). Certain plugin state can only be set after the plugin |
723 * has loaded. | 644 * has loaded. |
724 * @private | 645 * @private |
725 */ | 646 */ |
726 onPluginLoad_: function() { | 647 onPluginLoad_: function() { |
727 if (this.loadingTimeout_) { | 648 if (this.loadingTimeout_) { |
728 clearTimeout(this.loadingTimeout_); | 649 clearTimeout(this.loadingTimeout_); |
729 this.loadingTimeout_ = null; | 650 this.loadingTimeout_ = null; |
730 } | 651 } |
731 | 652 |
732 if (this.pluginType_ == PreviewArea.PluginType_.IN_PROCESS) { | |
733 // Setting the plugin's page count can only be called after the plugin | |
734 // is loaded and the document must be modifiable. | |
735 if (this.documentInfo_.isModifiable) { | |
736 this.plugin_.printPreviewPageCount( | |
737 this.printTicketStore_.pageRange.getPageNumberSet().size); | |
738 } | |
739 this.plugin_.setPageNumbers(JSON.stringify( | |
740 this.printTicketStore_.pageRange.getPageNumberSet().asArray())); | |
741 if (this.zoomLevel_ != null && this.pageOffset_ != null) { | |
742 this.plugin_.setZoomLevel(this.zoomLevel_); | |
743 this.plugin_.setPageXOffset(this.pageOffset_.x); | |
744 this.plugin_.setPageYOffset(this.pageOffset_.y); | |
745 } else { | |
746 this.plugin_.fitToHeight(); | |
747 } | |
748 } | |
749 this.setOverlayVisible_(false); | 653 this.setOverlayVisible_(false); |
750 this.isPluginReloaded_ = true; | 654 this.isPluginReloaded_ = true; |
751 this.dispatchPreviewGenerationDoneIfReady_(); | 655 this.dispatchPreviewGenerationDoneIfReady_(); |
752 }, | 656 }, |
753 | 657 |
754 /** | 658 /** |
755 * Called when the preview plugin's visual state has changed. This is a | 659 * Called when the preview plugin's visual state has changed. This is a |
756 * consequence of scrolling or zooming the plugin. Updates the custom | 660 * consequence of scrolling or zooming the plugin. Updates the custom |
757 * margins component if shown. | 661 * margins component if shown. |
758 * @private | 662 * @private |
759 */ | 663 */ |
760 onPreviewVisualStateChange_: function(pageX, | 664 onPreviewVisualStateChange_: function(pageX, |
761 pageY, | 665 pageY, |
762 pageWidth, | 666 pageWidth, |
763 viewportWidth, | 667 viewportWidth, |
764 viewportHeight) { | 668 viewportHeight) { |
765 if (this.pluginType_ == PreviewArea.PluginType_.IN_PROCESS) { | 669 this.marginControlContainer_.updateTranslationTransform( |
766 if (this.isPluginReloaded_) { | 670 new print_preview.Coordinate2d(pageX, pageY)); |
767 this.zoomLevel_ = this.plugin_.getZoomLevel(); | 671 this.marginControlContainer_.updateScaleTransform( |
768 this.pageOffset_ = new print_preview.Coordinate2d( | 672 pageWidth / this.documentInfo_.pageSize.width); |
769 this.plugin_.pageXOffset(), this.plugin_.pageYOffset()); | 673 this.marginControlContainer_.updateClippingMask( |
770 } | 674 new print_preview.Size(viewportWidth, viewportHeight)); |
771 | |
772 var pageLocationNormalizedStr = | |
773 this.plugin_.getPageLocationNormalized(); | |
774 if (!pageLocationNormalizedStr) { | |
775 return; | |
776 } | |
777 var normalized = pageLocationNormalizedStr.split(';'); | |
778 var pluginWidth = this.plugin_.getWidth(); | |
779 var pluginHeight = this.plugin_.getHeight(); | |
780 var verticalScrollbarThickness = | |
781 this.plugin_.getVerticalScrollbarThickness(); | |
782 var horizontalScrollbarThickness = | |
783 this.plugin_.getHorizontalScrollbarThickness(); | |
784 | |
785 var translationTransform = new print_preview.Coordinate2d( | |
786 parseFloat(normalized[0]) * pluginWidth, | |
787 parseFloat(normalized[1]) * pluginHeight); | |
788 this.marginControlContainer_.updateTranslationTransform( | |
789 translationTransform); | |
790 var pageWidthInPixels = parseFloat(normalized[2]) * pluginWidth; | |
791 this.marginControlContainer_.updateScaleTransform( | |
792 pageWidthInPixels / this.documentInfo_.pageSize.width); | |
793 this.marginControlContainer_.updateClippingMask( | |
794 new print_preview.Size( | |
795 pluginWidth - verticalScrollbarThickness, | |
796 pluginHeight - horizontalScrollbarThickness)); | |
797 } else if (this.pluginType_ == PreviewArea.PluginType_.OUT_OF_PROCESS) { | |
798 this.marginControlContainer_.updateTranslationTransform( | |
799 new print_preview.Coordinate2d(pageX, pageY)); | |
800 this.marginControlContainer_.updateScaleTransform( | |
801 pageWidth / this.documentInfo_.pageSize.width); | |
802 this.marginControlContainer_.updateClippingMask( | |
803 new print_preview.Size(viewportWidth, viewportHeight)); | |
804 } | |
805 }, | 675 }, |
806 | 676 |
807 /** | 677 /** |
808 * Called when dragging margins starts or stops. | 678 * Called when dragging margins starts or stops. |
809 * @param {boolean} isDragging True if the margin is currently being dragged | 679 * @param {boolean} isDragging True if the margin is currently being dragged |
810 * and false otherwise. | 680 * and false otherwise. |
811 */ | 681 */ |
812 onMarginDragChanged_: function(isDragging) { | 682 onMarginDragChanged_: function(isDragging) { |
813 if (!this.plugin_) | 683 if (!this.plugin_) |
814 return; | 684 return; |
815 | 685 |
816 // When hovering over the plugin (which may be in a separate iframe) | 686 // When hovering over the plugin (which may be in a separate iframe) |
817 // pointer events will be sent to the frame. When dragging the margins, | 687 // pointer events will be sent to the frame. When dragging the margins, |
818 // we don't want this to happen as it can cause the margin to stop | 688 // we don't want this to happen as it can cause the margin to stop |
819 // being draggable. | 689 // being draggable. |
820 this.plugin_.style.pointerEvents = isDragging ? 'none' : 'auto'; | 690 this.plugin_.style.pointerEvents = isDragging ? 'none' : 'auto'; |
821 } | 691 } |
822 }; | 692 }; |
823 | 693 |
824 // Export | 694 // Export |
825 return { | 695 return { |
826 PreviewArea: PreviewArea | 696 PreviewArea: PreviewArea |
827 }; | 697 }; |
828 }); | 698 }); |
OLD | NEW |