Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(156)

Unified Diff: chrome/browser/resources/print_preview/fit_to_page_settings.js

Issue 10083060: [Print Preview]: Added code to support pdf fit to page functionality. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: '' Created 8 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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
+ };
+});

Powered by Google App Engine
This is Rietveld 408576698