OLD | NEW |
---|---|
(Empty) | |
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 | |
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 } | |
18 | |
19 cr.addSingletonGetter(LayoutSettings); | |
20 | |
21 LayoutSettings.prototype = { | |
22 /** | |
23 * The radio button corresponding to the portrait option. | |
24 * @type {HTMLInputElement} | |
25 */ | |
26 get portraitRadioButton() { | |
27 return this.portraitRadioButton_; | |
28 }, | |
29 | |
30 /** | |
31 * The radio button corresponding to the landscape option. | |
32 * @type {HTMLInputElement} | |
33 */ | |
34 get landscapeRadioButton() { | |
35 return this.landscapeRadioButton_; | |
36 }, | |
37 | |
38 /** | |
39 * @return {boolean} true if |this.landscapeRadioButton_| is checked, false | |
40 * if not. | |
41 */ | |
42 isLandscape: function() { | |
43 return this.landscapeRadioButton_.checked; | |
44 }, | |
45 | |
46 /** | |
47 * Adding listeners to all layout related controls. The listeners take care | |
48 * of altering their behavior depending on |hasPendingPreviewRequest|. | |
49 */ | |
50 addEventListeners: function() { | |
51 this.landscapeRadioButton_.onclick = function() { | |
52 if (!hasPendingPreviewRequest) | |
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)); | |
60 document.addEventListener('printerCapabilitiesUpdated', | |
61 this.onPrinterCapabilitiesUpdated_.bind(this)); | |
62 }, | |
63 | |
64 /** | |
65 * Listener triggered when a printerCapabilitiesUpdated event occurs. | |
66 * @private | |
67 */ | |
68 onPrinterCapabilitiesUpdated_: function(e) { | |
69 this.fadeInOut(e.printerCapabilities.disableLandscapeOption); | |
70 }, | |
71 | |
72 /** | |
73 * Listener executing when |this.landscapeRadioButton_| or | |
74 * |this.portraitRadioButton_| is clicked. | |
75 * @private | |
76 */ | |
77 onLayoutButtonClick_: function() { | |
78 // If the chosen layout is same as before, nothing needs to be done. | |
79 if (printSettings.isLandscape == this.isLandscape()) | |
80 return; | |
81 setDefaultValuesAndRegeneratePreview(); | |
82 }, | |
83 | |
84 onPDFLoaded_: function() { | |
Evan Stade
2011/07/15 19:47:21
comment
| |
85 if (!previewModifiable) | |
86 fadeOutElement(this.layoutOption_); | |
87 }, | |
88 | |
89 /** | |
90 * @param {boolean} fadeOut True if |this.layoutOption_| should be faded | |
91 * out, false if it should be faded in. | |
92 */ | |
93 fadeInOut: function(fadeOut) { | |
94 fadeOut ? fadeOutElement(this.layoutOption_) : | |
95 fadeInElement(this.layoutOption_); | |
96 } | |
97 }; | |
98 | |
99 return { | |
100 LayoutSettings: LayoutSettings, | |
101 }; | |
102 }); | |
OLD | NEW |