Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(472)

Side by Side Diff: chrome/browser/resources/print_preview/header_footer_settings.js

Issue 10108001: Refactor print preview web ui (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Resolve conflicts Created 8 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 cr.define('print_preview', function() {
6 'use strict';
7
8 /**
9 * Creates a HeaderFooterSettings object. This object encapsulates all
10 * settings and logic related to the headers and footers checkbox.
11 * @constructor
12 */
13 function HeaderFooterSettings() {
14 this.headerFooterOption_ = $('header-footer-option');
15 this.headerFooterCheckbox_ = $('header-footer');
16 this.addEventListeners_();
17 }
18
19 cr.addSingletonGetter(HeaderFooterSettings);
20
21 HeaderFooterSettings.prototype = {
22 /**
23 * The checkbox corresponding to the headers and footers option.
24 * @type {HTMLInputElement}
25 */
26 get headerFooterCheckbox() {
27 return this.headerFooterCheckbox_;
28 },
29
30 /**
31 * Checks whether the Headers and Footers checkbox is checked or not.
32 * @return {boolean} true if Headers and Footers are checked.
33 */
34 hasHeaderFooter: function() {
35 return previewModifiable && this.headerFooterCheckbox_.checked;
36 },
37
38 /**
39 * Sets the state of the headers footers checkbox.
40 * @param {boolean} checked True if the headers footers checkbox shoule be
41 * checked, false if not.
42 */
43 setChecked: function(checked) {
44 this.headerFooterCheckbox_.checked = checked;
45 },
46
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 var headerFooterEvent = new cr.Event(
80 customEvents.HEADER_FOOTER_VISIBILITY_CHANGED);
81 headerFooterEvent.headerFooterApplies = headerFooterApplies;
82 document.dispatchEvent(headerFooterEvent);
83 },
84
85 /**
86 * Adding listeners to header footer related controls.
87 * @private
88 */
89 addEventListeners_: function() {
90 this.headerFooterCheckbox_.onclick =
91 this.onHeaderFooterChanged_.bind(this);
92 document.addEventListener(customEvents.PDF_LOADED,
93 this.onPDFLoaded_.bind(this));
94 },
95
96 /**
97 * Listener executing when the user selects or de-selects the headers
98 * and footers option.
99 * @private
100 */
101 onHeaderFooterChanged_: function() {
102 requestPrintPreview();
103 },
104
105 /**
106 * Listener executing when a |customEvents.PDF_LOADED| event occurs.
107 * @private
108 */
109 onPDFLoaded_: function() {
110 if (!previewModifiable)
111 this.setVisible_(false);
112 },
113
114 /**
115 * Hides or shows |this.headerFooterOption_|.
116 * @param {boolean} visible True if |this.headerFooterOption_| should be
117 * shown.
118 * @private
119 */
120 setVisible_: function(visible) {
121 this.headerFooterOption_.style.display = visible ? 'block' : 'none';
122 },
123 };
124
125 return {
126 HeaderFooterSettings: HeaderFooterSettings
127 };
128 });
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698