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

Side by Side Diff: chrome/browser/resources/print_preview/layout_settings.js

Issue 10108001: Refactor print preview web ui (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Resolve conflicts Created 8 years, 7 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
(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
5 cr.define('print_preview', function() {
6 'use strict';
7
8 /**
9 * Creates a LayoutSettings object. This object encapsulates all settings and
10 * logic related to layout mode (portrait/landscape).
11 * @constructor
12 */
13 function LayoutSettings() {
14 this.layoutOption_ = $('layout-option');
15 this.portraitRadioButton_ = $('portrait');
16 this.landscapeRadioButton_ = $('landscape');
17 this.wasLandscape_ = false;
18 this.updateState();
19 this.addEventListeners_();
20 }
21
22 cr.addSingletonGetter(LayoutSettings);
23
24 LayoutSettings.prototype = {
25 /**
26 * The radio button corresponding to the portrait option.
27 * @type {HTMLInputElement}
28 */
29 get portraitRadioButton() {
30 return this.portraitRadioButton_;
31 },
32
33 /**
34 * The radio button corresponding to the landscape option.
35 * @type {HTMLInputElement}
36 */
37 get landscapeRadioButton() {
38 return this.landscapeRadioButton_;
39 },
40
41 /**
42 * @return {boolean} true if |this.landscapeRadioButton_| is checked, false
43 * if not.
44 */
45 isLandscape: function() {
46 return this.landscapeRadioButton_.checked;
47 },
48
49 /**
50 * @return {boolean} true if the chosen layout mode has changed since last
51 * time the state was updated.
52 */
53 hasChanged_: function() {
54 return this.isLandscape() != this.wasLandscape_;
55 },
56
57 /**
58 * Saves the currently selected layout mode. Used in |this.hasChanged_|.
59 */
60 updateState: function() {
61 this.wasLandscape_ = this.isLandscape();
62 },
63
64 /**
65 * Adding listeners to all layout related controls. The listeners take care
66 * of altering their behavior depending on |hasPendingPreviewRequest|.
67 * @private
68 */
69 addEventListeners_: function() {
70 this.landscapeRadioButton_.onclick = this.onLayoutButtonClick_.bind(this);
71 this.portraitRadioButton_.onclick = this.onLayoutButtonClick_.bind(this);
72 document.addEventListener(customEvents.PDF_LOADED,
73 this.onPDFLoaded_.bind(this));
74 document.addEventListener(customEvents.PRINTER_CAPABILITIES_UPDATED,
75 this.onPrinterCapabilitiesUpdated_.bind(this));
76 },
77
78 /**
79 * Executes when a |customEvents.PRINTER_CAPABILITIES_UPDATED| event occurs.
80 * @private
81 */
82 onPrinterCapabilitiesUpdated_: function(e) {
83 if (e.printerCapabilities.disableLandscapeOption)
84 this.fadeInOut_(e.printerCapabilities.disableLandscapeOption);
85 },
86
87 /**
88 * Listener executing when |this.landscapeRadioButton_| or
89 * |this.portraitRadioButton_| is clicked.
90 * @private
91 */
92 onLayoutButtonClick_: function() {
93 // If the chosen layout is same as before, nothing needs to be done.
94 if (this.hasChanged_())
95 setDefaultValuesAndRegeneratePreview(true);
96 },
97
98 /**
99 * Listener executing when a |customEvents.PDF_LOADED| event occurs.
100 * @private
101 */
102 onPDFLoaded_: function() {
103 this.fadeInOut_(!previewModifiable || hasPageSizeStyle);
104 },
105
106 /**
107 * @param {boolean} fadeOut True if |this.layoutOption_| should be faded
108 * out, false if it should be faded in.
109 * @private
110 */
111 fadeInOut_: function(fadeOut) {
112 fadeOut ? fadeOutOption(this.layoutOption_) :
113 fadeInOption(this.layoutOption_);
114 }
115 };
116
117 return {
118 LayoutSettings: LayoutSettings
119 };
120 });
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698