Chromium Code Reviews| 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 /** |
| 49 * Adding listeners to header footer related controls. | 48 * Adding listeners to header footer related controls. |
| 50 * @private | 49 * @private |
| 51 */ | 50 */ |
| 52 addEventListeners_: function() { | 51 addEventListeners_: function() { |
| 53 this.headerFooterCheckbox_.onclick = | 52 this.headerFooterCheckbox_.onclick = |
| 54 this.onHeaderFooterChanged_.bind(this); | 53 this.onHeaderFooterChanged_.bind(this); |
| 55 document.addEventListener(customEvents.PDF_LOADED, | 54 document.addEventListener(customEvents.PDF_LOADED, |
| 56 this.onPDFLoaded_.bind(this)); | 55 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 }, | 56 }, |
| 66 | 57 |
| 67 /** | 58 /** |
| 59 * Sets the visibility of header footer option. | |
| 60 * @param {boolean} headerFooterApplies True if the headers footers | |
| 61 * checkbox shoud be hidden, else false. | |
| 62 */ | |
| 63 setVisibility: function(headerFooterApplies) { | |
|
dpapad
2012/03/14 23:16:25
There is already a method setVisible_ in this clas
kmadhusu
2012/03/15 00:19:15
Done.
| |
| 64 this.setVisible_(headerFooterApplies); | |
| 65 }, | |
| 66 | |
| 67 /** | |
| 68 * Listener executing when the user selects or de-selects the headers | 68 * Listener executing when the user selects or de-selects the headers |
| 69 * and footers option. | 69 * and footers option. |
| 70 * @private | 70 * @private |
| 71 */ | 71 */ |
| 72 onHeaderFooterChanged_: function() { | 72 onHeaderFooterChanged_: function() { |
| 73 requestPrintPreview(); | 73 requestPrintPreview(); |
| 74 }, | 74 }, |
| 75 | 75 |
| 76 /** | 76 /** |
| 77 * Listener executing when a |customEvents.PDF_LOADED| event occurs. | 77 * Listener executing when a |customEvents.PDF_LOADED| event occurs. |
| (...skipping 15 matching lines...) Expand all Loading... | |
| 93 fadeInOption(this.headerFooterOption_); | 93 fadeInOption(this.headerFooterOption_); |
| 94 else | 94 else |
| 95 fadeOutOption(this.headerFooterOption_); | 95 fadeOutOption(this.headerFooterOption_); |
| 96 } | 96 } |
| 97 }; | 97 }; |
| 98 | 98 |
| 99 return { | 99 return { |
| 100 HeaderFooterSettings: HeaderFooterSettings | 100 HeaderFooterSettings: HeaderFooterSettings |
| 101 }; | 101 }; |
| 102 }); | 102 }); |
| OLD | NEW |