Chromium Code Reviews| Index: chrome/browser/resources/print_preview/fit_to_page_settings.js |
| diff --git a/chrome/browser/resources/print_preview/fit_to_page_settings.js b/chrome/browser/resources/print_preview/fit_to_page_settings.js |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..588011fc7875bebc64129a5923289e216121a944 |
| --- /dev/null |
| +++ b/chrome/browser/resources/print_preview/fit_to_page_settings.js |
| @@ -0,0 +1,114 @@ |
| +// Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| +cr.define('print_preview', function() { |
| + 'use strict'; |
| + |
| + /** |
| + * Creates a |FitToPageSettings| object. This object encapsulates all |
| + * settings and logic related to the fit to page checkbox. |
| + * @constructor |
| + */ |
| + function FitToPageSettings() { |
| + // @type {HTMLDivElement} This represents fit to page div element. |
| + this.fitToPageOption_ = $('fit-to-page-option'); |
| + |
| + // @type {HTMLInputElement} This represents fit to page input element. |
| + this.fitToPageCheckbox_ = $('fit-to-page'); |
| + |
| + // @type {boolean} True if fit to page option applies for the selected |
| + // user options. Fit to Page options applies only if we are previewing |
| + // a PDF and the current destination printer is actually a physcial |
| + // printer. |
| + this.fitToPageApplies_ = true; |
| + |
| + this.addEventListeners_(); |
| + } |
| + |
| + cr.addSingletonGetter(FitToPageSettings); |
| + |
| + FitToPageSettings.prototype = { |
| + /** |
| + * Checks whether the fit to page checkbox is checked or not. |
| + * @return {boolean} true if Fit to page is checked. |
| + */ |
| + hasFitToPage: function() { |
| + return !previewModifiable && this.fitToPageCheckbox_.checked; |
| + }, |
| + |
| + /** |
| + * Updates |this.fitToPageApplies_| depending on the selected printer and |
| + * preview data source type. |
| + * @param {!string} printerName Selected printer name. |
| + * @private |
| + */ |
| + resetState_: function(printerName) { |
| + if (!previewModifiable) |
| + isPrintReadyMetafileReady = false; |
| + var printToPDF = printerName == PRINT_TO_PDF; |
| + this.fitToPageApplies_ = !previewModifiable && !printToPDF; |
| + }, |
| + |
| + /** |
| + * Uncheck the fit to page option when print scaling is disabled for the |
| + * preview source plugin. |
| + */ |
| + 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().
|
| + this.fitToPageCheckbox_.checked = false; |
| + }, |
| + |
| + /** |
| + * Adding listeners to fit to page control. |
| + * @private |
| + */ |
| + addEventListeners_: function() { |
| + this.fitToPageCheckbox_.onclick = |
| + this.onFitToPageCheckboxClicked_.bind(this); |
| + document.addEventListener(customEvents.PDF_LOADED, |
| + this.onPDFLoaded_.bind(this)); |
| + document.addEventListener(customEvents.PRINTER_SELECTION_CHANGED, |
| + this.onPrinterSelectionChanged_.bind(this)); |
| + }, |
| + |
| + /** |
| + * Listener executing when a |customEvents.PRINTER_SELECTION_CHANGED| event |
| + * occurs. |
| + * @param {cr.Event} event The event that triggered this listener. |
| + * @private |
| + */ |
| + onPrinterSelectionChanged_: function(event) { |
| + this.resetState_(event.selectedPrinter); |
| + this.updateVisibility_(); |
| + }, |
| + |
| + /** |
| + * Listener executing when the user selects or de-selects the fit to page |
| + * option. |
| + * @private |
| + */ |
| + onFitToPageCheckboxClicked_: function() { |
| + requestPrintPreview(); |
| + }, |
| + |
| + /** |
| + * Listener executing when a |customEvents.PDF_LOADED| event occurs. |
| + * @private |
| + */ |
| + onPDFLoaded_: function() { |
| + this.updateVisibility_(); |
| + }, |
| + |
| + /** |
| + * Hides or shows |this.fitToPageOption_|. |
| + * @private |
| + */ |
| + updateVisibility_: function() { |
| + this.fitToPageOption_.style.display = this.fitToPageApplies_ ? 'block' : |
| + '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.
|
| + } |
| + }; |
| + |
| + return { |
| + FitToPageSettings: FitToPageSettings |
| + }; |
| +}); |