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..b1223b87d66ae25f0528e987769445d61f957793 |
--- /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() { |
+ 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.setVisible_(this.fitToPageApplies_); |
+ }, |
+ |
+ /** |
+ * 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.setVisible_(this.fitToPageApplies_); |
+ }, |
+ |
+ /** |
+ * Hides or shows |this.fitToPageOption_|. |
+ * @{param} visible True if |this.fitToPageOption_| should be shown. |
+ * @private |
+ */ |
+ setVisible_: function(visible) { |
dpapad
2012/04/19 18:38:39
This is always invoked with this.fitToPageApplies_
kmadhusu
2012/04/19 20:44:54
setVisible_ -> updateVisibility. Removed the param
|
+ this.fitToPageOption_.style.display = visible ? 'block' : 'none'; |
+ } |
+ }; |
+ |
+ return { |
+ FitToPageSettings: FitToPageSettings |
+ }; |
+}); |