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

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: Remove extra files Created 8 years, 8 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 },
80
81 /**
82 * Adding listeners to header footer related controls.
83 * @private
84 */
85 addEventListeners_: function() {
86 this.headerFooterCheckbox_.onclick =
87 this.onHeaderFooterChanged_.bind(this);
88 document.addEventListener(customEvents.PDF_LOADED,
89 this.onPDFLoaded_.bind(this));
90 },
91
92 /**
93 * Listener executing when the user selects or de-selects the headers
94 * and footers option.
95 * @private
96 */
97 onHeaderFooterChanged_: function() {
98 requestPrintPreview();
99 },
100
101 /**
102 * Listener executing when a |customEvents.PDF_LOADED| event occurs.
103 * @private
104 */
105 onPDFLoaded_: function() {
106 if (!previewModifiable)
107 this.setVisible_(false);
108 },
109
110 /**
111 * Hides or shows |this.headerFooterOption|.
112 * @param {boolean} visible True if |this.headerFooterOption| should be
113 * shown.
114 * @private
115 */
116 setVisible_: function(visible) {
117 if (visible)
118 fadeInOption(this.headerFooterOption_);
119 else
120 fadeOutOption(this.headerFooterOption_);
121 }
122 };
123
124 return {
125 HeaderFooterSettings: HeaderFooterSettings
126 };
127 });
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698