| 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 {{contentWidth: number, contentHeight: number, marginLeft: number, |
| 51 * marginRight: number, marginTop: number, marginBottom: number, |
| 52 * printableAreaX: number, printableAreaY: number, |
| 53 * printableAreaWidth: number, printableAreaHeight: number}} |
| 54 * pageLayout Specifies default page layout details in points. |
| 55 * @param {number} marginsType Specifies the selected margins type value. |
| 56 */ |
| 57 checkAndHideHeaderFooterOption: function(pageLayout, 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 > pageLayout.printableAreaY) || |
| 73 (pageLayout.marginBottom > |
| 74 (pageHeight - pageLayout.printableAreaY - |
| 75 pageLayout.printableAreaHeight)); |
| 76 } |
| 77 } |
| 78 this.setVisible_(headerFooterApplies); |
| 79 }, |
| 80 |
| 81 /** |
| 49 * Adding listeners to header footer related controls. | 82 * Adding listeners to header footer related controls. |
| 50 * @private | 83 * @private |
| 51 */ | 84 */ |
| 52 addEventListeners_: function() { | 85 addEventListeners_: function() { |
| 53 this.headerFooterCheckbox_.onclick = | 86 this.headerFooterCheckbox_.onclick = |
| 54 this.onHeaderFooterChanged_.bind(this); | 87 this.onHeaderFooterChanged_.bind(this); |
| 55 document.addEventListener(customEvents.PDF_LOADED, | 88 document.addEventListener(customEvents.PDF_LOADED, |
| 56 this.onPDFLoaded_.bind(this)); | 89 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 }, | 90 }, |
| 66 | 91 |
| 67 /** | 92 /** |
| 68 * Listener executing when the user selects or de-selects the headers | 93 * Listener executing when the user selects or de-selects the headers |
| 69 * and footers option. | 94 * and footers option. |
| 70 * @private | 95 * @private |
| 71 */ | 96 */ |
| 72 onHeaderFooterChanged_: function() { | 97 onHeaderFooterChanged_: function() { |
| 73 requestPrintPreview(); | 98 requestPrintPreview(); |
| 74 }, | 99 }, |
| (...skipping 18 matching lines...) Expand all Loading... |
| 93 fadeInOption(this.headerFooterOption_); | 118 fadeInOption(this.headerFooterOption_); |
| 94 else | 119 else |
| 95 fadeOutOption(this.headerFooterOption_); | 120 fadeOutOption(this.headerFooterOption_); |
| 96 } | 121 } |
| 97 }; | 122 }; |
| 98 | 123 |
| 99 return { | 124 return { |
| 100 HeaderFooterSettings: HeaderFooterSettings | 125 HeaderFooterSettings: HeaderFooterSettings |
| 101 }; | 126 }; |
| 102 }); | 127 }); |
| OLD | NEW |