Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 cr.define('print_preview', function() { | |
| 5 'use strict'; | |
| 6 | |
| 7 /** | |
| 8 * Creates a |FitToPageSettings| object. This object encapsulates all | |
| 9 * settings and logic related to the fit to page checkbox. | |
| 10 * @constructor | |
| 11 */ | |
| 12 function FitToPageSettings() { | |
| 13 // @type {HTMLDivElement} This represents fit to page div element. | |
| 14 this.fitToPageOption_ = $('fit-to-page-option'); | |
| 15 | |
| 16 // @type {HTMLInputElement} This represents fit to page input element. | |
| 17 this.fitToPageCheckbox_ = $('fit-to-page'); | |
| 18 | |
| 19 // @type {boolean} True if fit to page option applies for the selected | |
| 20 // user options. Fit to Page options applies only if we are previewing | |
| 21 // a PDF and the current destination printer is actually a physcial | |
| 22 // printer. | |
| 23 this.fitToPageApplies_ = true; | |
| 24 | |
| 25 this.addEventListeners_(); | |
| 26 } | |
| 27 | |
| 28 cr.addSingletonGetter(FitToPageSettings); | |
| 29 | |
| 30 FitToPageSettings.prototype = { | |
| 31 /** | |
| 32 * Checks whether the fit to page checkbox is checked or not. | |
| 33 * @return {boolean} true if Fit to page is checked. | |
| 34 */ | |
| 35 hasFitToPage: function() { | |
| 36 return !previewModifiable && this.fitToPageCheckbox_.checked; | |
| 37 }, | |
| 38 | |
| 39 /** | |
| 40 * Updates |this.fitToPageApplies_| depending on the selected printer and | |
| 41 * preview data source type. | |
| 42 * @param {!string} printerName Selected printer name. | |
| 43 * @private | |
| 44 */ | |
| 45 resetState_: function(printerName) { | |
| 46 if (!previewModifiable) | |
| 47 isPrintReadyMetafileReady = false; | |
| 48 var printToPDF = printerName == PRINT_TO_PDF; | |
| 49 this.fitToPageApplies_ = !previewModifiable && !printToPDF; | |
| 50 }, | |
| 51 | |
| 52 /** | |
| 53 * Uncheck the fit to page option when print scaling is disabled for the | |
| 54 * preview source plugin. | |
| 55 */ | |
| 56 printScalingDisabledUpdateState: function() { | |
|
dpapad
2012/04/19 21:11:29
Nit:
The naming of this function describes why it
kmadhusu
2012/04/20 23:03:42
+1 for onPrintScalingDisabled().
| |
| 57 this.fitToPageCheckbox_.checked = false; | |
| 58 }, | |
| 59 | |
| 60 /** | |
| 61 * Adding listeners to fit to page control. | |
| 62 * @private | |
| 63 */ | |
| 64 addEventListeners_: function() { | |
| 65 this.fitToPageCheckbox_.onclick = | |
| 66 this.onFitToPageCheckboxClicked_.bind(this); | |
| 67 document.addEventListener(customEvents.PDF_LOADED, | |
| 68 this.onPDFLoaded_.bind(this)); | |
| 69 document.addEventListener(customEvents.PRINTER_SELECTION_CHANGED, | |
| 70 this.onPrinterSelectionChanged_.bind(this)); | |
| 71 }, | |
| 72 | |
| 73 /** | |
| 74 * Listener executing when a |customEvents.PRINTER_SELECTION_CHANGED| event | |
| 75 * occurs. | |
| 76 * @param {cr.Event} event The event that triggered this listener. | |
| 77 * @private | |
| 78 */ | |
| 79 onPrinterSelectionChanged_: function(event) { | |
| 80 this.resetState_(event.selectedPrinter); | |
| 81 this.updateVisibility_(); | |
| 82 }, | |
| 83 | |
| 84 /** | |
| 85 * Listener executing when the user selects or de-selects the fit to page | |
| 86 * option. | |
| 87 * @private | |
| 88 */ | |
| 89 onFitToPageCheckboxClicked_: function() { | |
| 90 requestPrintPreview(); | |
| 91 }, | |
| 92 | |
| 93 /** | |
| 94 * Listener executing when a |customEvents.PDF_LOADED| event occurs. | |
| 95 * @private | |
| 96 */ | |
| 97 onPDFLoaded_: function() { | |
| 98 this.updateVisibility_(); | |
| 99 }, | |
| 100 | |
| 101 /** | |
| 102 * Hides or shows |this.fitToPageOption_|. | |
| 103 * @private | |
| 104 */ | |
| 105 updateVisibility_: function() { | |
| 106 this.fitToPageOption_.style.display = this.fitToPageApplies_ ? 'block' : | |
| 107 'none'; | |
|
dpapad
2012/04/19 21:11:29
Nit: I believe it is more readable as follows.
th
kmadhusu
2012/04/20 23:03:42
Done.
| |
| 108 } | |
| 109 }; | |
| 110 | |
| 111 return { | |
| 112 FitToPageSettings: FitToPageSettings | |
| 113 }; | |
| 114 }); | |
| OLD | NEW |