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() {
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
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.
20 * @extends {print_preview.ticket_items.TicketItem}
22 function HeaderFooter(appState, documentInfo, marginsType, customMargins) {
23 print_preview.ticket_items.TicketItem.call(
26 print_preview.AppState.Field.IS_HEADER_FOOTER_ENABLED,
27 null /*destinationStore*/,
31 * Ticket item that stores which predefined margins to print with.
32 * @type {!print_preview.ticket_items.MarginsType}
35 this.marginsType_ = marginsType;
38 * Ticket item that stores custom margin values.
39 * @type {!print_preview.ticket_items.CustomMargins}
42 this.customMargins_ = customMargins;
44 this.addEventListeners_();
47 HeaderFooter.prototype = {
48 __proto__: print_preview.ticket_items.TicketItem.prototype,
51 wouldValueBeValid: function(value) {
56 isCapabilityAvailable: function() {
57 if (!this.getDocumentInfoInternal().isModifiable) {
59 } else if (this.marginsType_.getValue() ==
60 print_preview.ticket_items.MarginsType.Value.NO_MARGINS) {
62 } else if (this.marginsType_.getValue() ==
63 print_preview.ticket_items.MarginsType.Value.MINIMUM) {
67 if (this.marginsType_.getValue() ==
68 print_preview.ticket_items.MarginsType.Value.CUSTOM) {
69 if (!this.customMargins_.isValid()) {
72 margins = this.customMargins_.getValue();
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;
83 getDefaultValueInternal: function() {
88 getCapabilityNotAvailableValueInternal: function() {
93 * Adds CHANGE listeners to dependent ticket items.
96 addEventListeners_: function() {
97 this.getTrackerInternal().add(
99 print_preview.ticket_items.TicketItem.EventType.CHANGE,
100 this.dispatchChangeEventInternal.bind(this));
101 this.getTrackerInternal().add(
103 print_preview.ticket_items.TicketItem.EventType.CHANGE,
104 this.dispatchChangeEventInternal.bind(this));
110 HeaderFooter: HeaderFooter