OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 cr.define('print_preview', function() { | 5 cr.define('print_preview', function() { |
6 'use strict'; | 6 'use strict'; |
7 | 7 |
8 /** | 8 /** |
9 * Creates a LayoutSettings object. This object encapsulates all settings and | 9 * Creates a LayoutSettings object. This object encapsulates all settings and |
10 * logic related to layout mode (portrait/landscape). | 10 * logic related to layout mode (portrait/landscape). |
11 * @constructor | 11 * @constructor |
12 */ | 12 */ |
13 function LayoutSettings() { | 13 function LayoutSettings() { |
14 this.layoutOption_ = $('layout-option'); | 14 this.layoutOption_ = $('layout-option'); |
15 this.portraitRadioButton_ = $('portrait'); | 15 this.portraitRadioButton_ = $('portrait'); |
16 this.landscapeRadioButton_ = $('landscape'); | 16 this.landscapeRadioButton_ = $('landscape'); |
| 17 this.wasLandscape_ = false; |
| 18 this.updateState(); |
17 } | 19 } |
18 | 20 |
19 cr.addSingletonGetter(LayoutSettings); | 21 cr.addSingletonGetter(LayoutSettings); |
20 | 22 |
21 LayoutSettings.prototype = { | 23 LayoutSettings.prototype = { |
22 /** | 24 /** |
23 * The radio button corresponding to the portrait option. | 25 * The radio button corresponding to the portrait option. |
24 * @type {HTMLInputElement} | 26 * @type {HTMLInputElement} |
25 */ | 27 */ |
26 get portraitRadioButton() { | 28 get portraitRadioButton() { |
(...skipping 10 matching lines...) Expand all Loading... |
37 | 39 |
38 /** | 40 /** |
39 * @return {boolean} true if |this.landscapeRadioButton_| is checked, false | 41 * @return {boolean} true if |this.landscapeRadioButton_| is checked, false |
40 * if not. | 42 * if not. |
41 */ | 43 */ |
42 isLandscape: function() { | 44 isLandscape: function() { |
43 return this.landscapeRadioButton_.checked; | 45 return this.landscapeRadioButton_.checked; |
44 }, | 46 }, |
45 | 47 |
46 /** | 48 /** |
| 49 * @return {boolean} true if the chosen layout mode has changed since last |
| 50 * time the state was updated. |
| 51 */ |
| 52 hasChanged_ : function() { |
| 53 return this.isLandscape() != this.wasLandscape_; |
| 54 }, |
| 55 |
| 56 /** |
| 57 * Saves the currently selected layout mode. Used in |this.hasChanged_|. |
| 58 */ |
| 59 updateState : function() { |
| 60 this.wasLandscape_ = this.isLandscape(); |
| 61 }, |
| 62 |
| 63 /** |
47 * Adding listeners to all layout related controls. The listeners take care | 64 * Adding listeners to all layout related controls. The listeners take care |
48 * of altering their behavior depending on |hasPendingPreviewRequest|. | 65 * of altering their behavior depending on |hasPendingPreviewRequest|. |
49 */ | 66 */ |
50 addEventListeners: function() { | 67 addEventListeners: function() { |
51 this.landscapeRadioButton_.onclick = function() { | 68 this.landscapeRadioButton_.onclick = this.onLayoutButtonClick_.bind(this); |
52 if (!hasPendingPreviewRequest) | 69 this.portraitRadioButton_.onclick = this.onLayoutButtonClick_.bind(this); |
53 this.onLayoutButtonClick_(); | |
54 }.bind(this); | |
55 this.portraitRadioButton_.onclick = function() { | |
56 if (!hasPendingPreviewRequest) | |
57 this.onLayoutButtonClick_(); | |
58 }.bind(this); | |
59 document.addEventListener('PDFLoaded', this.onPDFLoaded_.bind(this)); | 70 document.addEventListener('PDFLoaded', this.onPDFLoaded_.bind(this)); |
60 document.addEventListener('printerCapabilitiesUpdated', | 71 document.addEventListener('printerCapabilitiesUpdated', |
61 this.onPrinterCapabilitiesUpdated_.bind(this)); | 72 this.onPrinterCapabilitiesUpdated_.bind(this)); |
62 }, | 73 }, |
63 | 74 |
64 /** | 75 /** |
65 * Listener triggered when a printerCapabilitiesUpdated event occurs. | 76 * Listener triggered when a printerCapabilitiesUpdated event occurs. |
66 * @private | 77 * @private |
67 */ | 78 */ |
68 onPrinterCapabilitiesUpdated_: function(e) { | 79 onPrinterCapabilitiesUpdated_: function(e) { |
69 if (e.printerCapabilities.disableLandscapeOption) | 80 if (e.printerCapabilities.disableLandscapeOption) |
70 this.fadeInOut_(e.printerCapabilities.disableLandscapeOption); | 81 this.fadeInOut_(e.printerCapabilities.disableLandscapeOption); |
71 }, | 82 }, |
72 | 83 |
73 /** | 84 /** |
74 * Listener executing when |this.landscapeRadioButton_| or | 85 * Listener executing when |this.landscapeRadioButton_| or |
75 * |this.portraitRadioButton_| is clicked. | 86 * |this.portraitRadioButton_| is clicked. |
76 * @private | 87 * @private |
77 */ | 88 */ |
78 onLayoutButtonClick_: function() { | 89 onLayoutButtonClick_: function() { |
79 // If the chosen layout is same as before, nothing needs to be done. | 90 // If the chosen layout is same as before, nothing needs to be done. |
80 if (printSettings.isLandscape == this.isLandscape()) | 91 if (this.hasChanged_()) |
81 return; | 92 setDefaultValuesAndRegeneratePreview(); |
82 setDefaultValuesAndRegeneratePreview(); | |
83 }, | 93 }, |
84 | 94 |
85 /** | 95 /** |
86 * Listener executing when a PDFLoaded event occurs. | 96 * Listener executing when a PDFLoaded event occurs. |
87 * @private | 97 * @private |
88 */ | 98 */ |
89 onPDFLoaded_: function() { | 99 onPDFLoaded_: function() { |
90 if (!previewModifiable) | 100 this.fadeInOut_(!previewModifiable); |
91 fadeOutElement(this.layoutOption_); | |
92 }, | 101 }, |
93 | 102 |
94 /** | 103 /** |
95 * @param {boolean} fadeOut True if |this.layoutOption_| should be faded | 104 * @param {boolean} fadeOut True if |this.layoutOption_| should be faded |
96 * out, false if it should be faded in. | 105 * out, false if it should be faded in. |
97 * @private | 106 * @private |
98 */ | 107 */ |
99 fadeInOut_: function(fadeOut) { | 108 fadeInOut_: function(fadeOut) { |
100 fadeOut ? fadeOutElement(this.layoutOption_) : | 109 fadeOut ? fadeOutElement(this.layoutOption_) : |
101 fadeInElement(this.layoutOption_); | 110 fadeInElement(this.layoutOption_); |
102 } | 111 } |
103 }; | 112 }; |
104 | 113 |
105 return { | 114 return { |
106 LayoutSettings: LayoutSettings, | 115 LayoutSettings: LayoutSettings, |
107 }; | 116 }; |
108 }); | 117 }); |
OLD | NEW |