OLD | NEW |
---|---|
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 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 HeaderFooterSettings object. This object encapsulates all | 9 * Creates a HeaderFooterSettings object. This object encapsulates all |
10 * settings and logic related to the headers and footers checkbox. | 10 * settings and logic related to the headers and footers checkbox. |
11 * @constructor | 11 * @constructor |
12 */ | 12 */ |
13 function HeaderFooterSettings() { | 13 function HeaderFooterSettings() { |
14 this.headerFooterOption_ = $('header-footer-option'); | 14 this.headerFooterOption_ = $('header-footer-option'); |
15 this.headerFooterCheckbox_ = $('header-footer'); | 15 this.headerFooterCheckbox_ = $('header-footer'); |
16 this.headerFooterApplies_ = false; | |
17 this.addEventListeners_(); | 16 this.addEventListeners_(); |
18 } | 17 } |
19 | 18 |
20 cr.addSingletonGetter(HeaderFooterSettings); | 19 cr.addSingletonGetter(HeaderFooterSettings); |
21 | 20 |
22 HeaderFooterSettings.prototype = { | 21 HeaderFooterSettings.prototype = { |
23 /** | 22 /** |
24 * The checkbox corresponding to the headers and footers option. | 23 * The checkbox corresponding to the headers and footers option. |
25 * @type {HTMLInputElement} | 24 * @type {HTMLInputElement} |
26 */ | 25 */ |
27 get headerFooterCheckbox() { | 26 get headerFooterCheckbox() { |
28 return this.headerFooterCheckbox_; | 27 return this.headerFooterCheckbox_; |
29 }, | 28 }, |
30 | 29 |
31 /** | 30 /** |
32 * Checks whether the Headers and Footers checkbox is checked or not. | 31 * Checks whether the Headers and Footers checkbox is checked or not. |
33 * @return {boolean} true if Headers and Footers are checked. | 32 * @return {boolean} true if Headers and Footers are checked. |
34 */ | 33 */ |
35 hasHeaderFooter: function() { | 34 hasHeaderFooter: function() { |
36 return this.headerFooterApplies_ && this.headerFooterCheckbox_.checked; | 35 return previewModifiable && this.headerFooterCheckbox_.checked; |
37 }, | 36 }, |
38 | 37 |
39 /** | 38 /** |
40 * Sets the state of the headers footers checkbox. | 39 * Sets the state of the headers footers checkbox. |
41 * @param {boolean} checked True if the headers footers checkbox shoule be | 40 * @param {boolean} checked True if the headers footers checkbox shoule be |
42 * checked, false if not. | 41 * checked, false if not. |
43 */ | 42 */ |
44 setChecked: function(checked) { | 43 setChecked: function(checked) { |
45 this.headerFooterCheckbox_.checked = checked; | 44 this.headerFooterCheckbox_.checked = checked; |
46 }, | 45 }, |
47 | 46 |
48 /** | 47 /** |
48 * Checks the printable area and updates the visibility of header footer | |
49 * option based on the selected margins. | |
50 * @param {printing::PageSizeMargins} pageLayout The default layout of the | |
dpapad
2012/03/17 00:36:41
Fix comment.
kmadhusu
2012/03/19 18:45:31
Done.
| |
51 * in poitns. | |
52 * @param {{x: number, y: number, width: number, height: number}} | |
53 * printableArea Specifies the printable area details. | |
54 * @param {number} marginsType Specifies the selected margins type value. | |
55 */ | |
56 checkAndHideHeaderFooterOption: function(pageLayout, printableArea, | |
57 marginsType) { | |
58 var headerFooterApplies = true; | |
59 if (marginsType == | |
60 print_preview.MarginSettings.MARGINS_VALUE_NO_MARGINS || | |
61 !previewModifiable) { | |
62 headerFooterApplies = false; | |
63 } else if (marginsType != | |
64 print_preview.MarginSettings.MARGINS_VALUE_MINIMUM) { | |
65 if (cr.isLinux || cr.isChromeOS) { | |
66 headerFooterApplies = pageLayout.marginTop > 0 || | |
67 pageLayout.marginBottom > 0; | |
68 } else { | |
69 var pageHeight = pageLayout.marginTop + pageLayout.marginBottom + | |
70 pageLayout.contentHeight; | |
71 headerFooterApplies = | |
72 (pageLayout.marginTop > printableArea.y) || | |
73 (pageLayout.marginBottom > | |
74 (pageHeight - printableArea.y - printableArea.height)); | |
75 } | |
76 } | |
77 this.setVisible_(headerFooterApplies); | |
78 }, | |
79 | |
80 /** | |
49 * Adding listeners to header footer related controls. | 81 * Adding listeners to header footer related controls. |
50 * @private | 82 * @private |
51 */ | 83 */ |
52 addEventListeners_: function() { | 84 addEventListeners_: function() { |
53 this.headerFooterCheckbox_.onclick = | 85 this.headerFooterCheckbox_.onclick = |
54 this.onHeaderFooterChanged_.bind(this); | 86 this.onHeaderFooterChanged_.bind(this); |
55 document.addEventListener(customEvents.PDF_LOADED, | 87 document.addEventListener(customEvents.PDF_LOADED, |
56 this.onPDFLoaded_.bind(this)); | 88 this.onPDFLoaded_.bind(this)); |
57 document.addEventListener(customEvents.MARGINS_SELECTION_CHANGED, | |
58 this.onMarginsSelectionChanged_.bind(this)); | |
59 }, | |
60 | |
61 onMarginsSelectionChanged_: function(event) { | |
62 this.headerFooterApplies_ = event.selectedMargins != | |
63 print_preview.MarginSettings.MARGINS_VALUE_NO_MARGINS; | |
64 this.setVisible_(this.headerFooterApplies_); | |
65 }, | 89 }, |
66 | 90 |
67 /** | 91 /** |
68 * Listener executing when the user selects or de-selects the headers | 92 * Listener executing when the user selects or de-selects the headers |
69 * and footers option. | 93 * and footers option. |
70 * @private | 94 * @private |
71 */ | 95 */ |
72 onHeaderFooterChanged_: function() { | 96 onHeaderFooterChanged_: function() { |
73 requestPrintPreview(); | 97 requestPrintPreview(); |
74 }, | 98 }, |
(...skipping 18 matching lines...) Expand all Loading... | |
93 fadeInOption(this.headerFooterOption_); | 117 fadeInOption(this.headerFooterOption_); |
94 else | 118 else |
95 fadeOutOption(this.headerFooterOption_); | 119 fadeOutOption(this.headerFooterOption_); |
96 } | 120 } |
97 }; | 121 }; |
98 | 122 |
99 return { | 123 return { |
100 HeaderFooterSettings: HeaderFooterSettings | 124 HeaderFooterSettings: HeaderFooterSettings |
101 }; | 125 }; |
102 }); | 126 }); |
OLD | NEW |