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

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

Issue 7358002: Print Preview: Refactoring layout mode related logic to LayoutSettings class. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Moving function within CopiesSettings Created 9 years, 5 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/layout_settings.js
diff --git a/chrome/browser/resources/print_preview/layout_settings.js b/chrome/browser/resources/print_preview/layout_settings.js
new file mode 100644
index 0000000000000000000000000000000000000000..293fef188cb2d5d50038d703ac6655579b849ff6
--- /dev/null
+++ b/chrome/browser/resources/print_preview/layout_settings.js
@@ -0,0 +1,91 @@
+// Copyright (c) 2011 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 LayoutSettings object. This object encapsulates all settings and
+ * logic related to layout mode (portrait/landscape).
+ * @constructor
+ */
+ function LayoutSettings() {
+ this.layoutOption_ = $('layout-option');
+ this.portraitRadioButton_ = $('portrait');
+ this.landscapeRadioButton_ = $('landscape');
+ }
+
+ cr.addSingletonGetter(LayoutSettings);
+
+ LayoutSettings.prototype = {
+ /**
+ * The radio button corresponding to the portrait option.
+ * @type {HTMLInputElement}
+ */
+ get portraitRadioButton() {
+ return this.portraitRadioButton_;
+ },
+
+ /**
+ * The radio button corresponding to the landscape option.
+ * @type {HTMLInputElement}
+ */
+ get landscapeRadioButton() {
+ return this.landscapeRadioButton_;
+ },
+
+ /**
+ * @return {boolean} true if |this.landscapeRadioButton_| is checked, false
+ * if not.
+ */
+ isLandscape: function() {
+ return this.landscapeRadioButton_.checked;
+ },
+
+ /**
+ * Adding listeners to all layout related controls. The listeners take care
+ * of altering their behavior depending on |hasPendingPreviewRequest|.
+ */
+ addEventListeners: function() {
+ this.landscapeRadioButton_.onclick = function() {
+ if (!hasPendingPreviewRequest)
+ this.onLayoutButtonClick();
+ }.bind(this);
+ this.portraitRadioButton_.onclick = function() {
+ if (!hasPendingPreviewRequest)
+ this.onLayoutButtonClick();
+ }.bind(this);
+ document.addEventListener('PDFLoaded', this.onPDFLoaded_.bind(this));
+ },
+
+ /**
+ * Listener executing when |this.landscapeRadioButton_| or
+ * |this.portraitRadioButton_| is clicked.
+ */
+ onLayoutButtonClick: function() {
+ // If the chosen layout is same as before, nothing needs to be done.
+ if (printSettings.isLandscape == this.isLandscape())
+ return;
+ setDefaultValuesAndRegeneratePreview();
+ },
+
+ onPDFLoaded_: function() {
+ if (!previewModifiable)
+ fadeOutElement(this.layoutOption);
+ },
+
+ /**
+ * @param {boolean} fadeOut True if |this.layoutOption_| should be faded
+ * out, false if it should be faded in.
+ */
+ fadeInOut: function(fadeOut) {
+ fadeOut ? fadeOutElement(this.layoutOption_) :
+ fadeInElement(this.layoutOption_);
+ }
+ };
+
+ return {
+ LayoutSettings: LayoutSettings,
+ };
+});

Powered by Google App Engine
This is Rietveld 408576698