Elim cr-checkbox
[chromium-blink-merge.git] / chrome / browser / resources / print_preview / data / ticket_items / header_footer.js
blob4f0840693f62d6b158a34c963dcd69f2ce165b0b
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.
5 cr.define('print_preview.ticket_items', function() {
6 'use strict';
8 /**
9 * Header-footer ticket item whose value is a {@code boolean} that indicates
10 * whether the document should be printed with headers and footers.
11 * @param {!print_preview.AppState} appState App state used to persist whether
12 * header-footer is enabled.
13 * @param {!print_preview.DocumentInfo} documentInfo Information about the
14 * document to print.
15 * @param {!print_preview.ticket_items.MarginsType} marginsType Ticket item
16 * that stores which predefined margins to print with.
17 * @param {!print_preview.ticket_items.CustomMargins} customMargins Ticket
18 * item that stores custom margin values.
19 * @constructor
20 * @extends {print_preview.ticket_items.TicketItem}
22 function HeaderFooter(appState, documentInfo, marginsType, customMargins) {
23 print_preview.ticket_items.TicketItem.call(
24 this,
25 appState,
26 print_preview.AppState.Field.IS_HEADER_FOOTER_ENABLED,
27 null /*destinationStore*/,
28 documentInfo);
30 /**
31 * Ticket item that stores which predefined margins to print with.
32 * @type {!print_preview.ticket_items.MarginsType}
33 * @private
35 this.marginsType_ = marginsType;
37 /**
38 * Ticket item that stores custom margin values.
39 * @type {!print_preview.ticket_items.CustomMargins}
40 * @private
42 this.customMargins_ = customMargins;
44 this.addEventListeners_();
47 HeaderFooter.prototype = {
48 __proto__: print_preview.ticket_items.TicketItem.prototype,
50 /** @override */
51 wouldValueBeValid: function(value) {
52 return true;
55 /** @override */
56 isCapabilityAvailable: function() {
57 if (!this.getDocumentInfoInternal().isModifiable) {
58 return false;
59 } else if (this.marginsType_.getValue() ==
60 print_preview.ticket_items.MarginsType.Value.NO_MARGINS) {
61 return false;
62 } else if (this.marginsType_.getValue() ==
63 print_preview.ticket_items.MarginsType.Value.MINIMUM) {
64 return true;
66 var margins;
67 if (this.marginsType_.getValue() ==
68 print_preview.ticket_items.MarginsType.Value.CUSTOM) {
69 if (!this.customMargins_.isValid()) {
70 return false;
72 margins = this.customMargins_.getValue();
73 } else {
74 margins = this.getDocumentInfoInternal().margins;
76 var orientEnum = print_preview.ticket_items.CustomMargins.Orientation;
77 return margins == null ||
78 margins.get(orientEnum.TOP) > 0 ||
79 margins.get(orientEnum.BOTTOM) > 0;
82 /** @override */
83 getDefaultValueInternal: function() {
84 return true;
87 /** @override */
88 getCapabilityNotAvailableValueInternal: function() {
89 return false;
92 /**
93 * Adds CHANGE listeners to dependent ticket items.
94 * @private
96 addEventListeners_: function() {
97 this.getTrackerInternal().add(
98 this.marginsType_,
99 print_preview.ticket_items.TicketItem.EventType.CHANGE,
100 this.dispatchChangeEventInternal.bind(this));
101 this.getTrackerInternal().add(
102 this.customMargins_,
103 print_preview.ticket_items.TicketItem.EventType.CHANGE,
104 this.dispatchChangeEventInternal.bind(this));
108 // Export
109 return {
110 HeaderFooter: HeaderFooter