- add sources.
[platform/framework/web/crosswalk.git] / src / chrome / browser / resources / print_preview / data / ticket_items / margins_type.js
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.ticket_items', function() {
6   'use strict';
7
8   /**
9    * Margins type ticket item whose value is a
10    * {@link print_preview.ticket_items.MarginsType.Value} that indicates what
11    * predefined margins type to use.
12    * @param {!print_preview.AppState} appState App state persistence object to
13    *     save the state of the margins type selection.
14    * @param {!print_preview.DocumentInfo} documentInfo Information about the
15    *     document to print.
16    * @param {!print_preview.CustomMargins} customMargins Custom margins ticket
17    *     item, used to write when margins type changes.
18    * @constructor
19    * @extends {print_preview.ticket_items.TicketItem}
20    */
21   function MarginsType(appState, documentInfo, customMargins) {
22     print_preview.ticket_items.TicketItem.call(
23         this,
24         appState,
25         print_preview.AppState.Field.MARGINS_TYPE,
26         null /*destinationStore*/,
27         documentInfo);
28
29     /**
30      * Custom margins ticket item, used to write when margins type changes.
31      * @type {!print_preview.ticket_items.CustomMargins}
32      * @private
33      */
34     this.customMargins_ = customMargins;
35   };
36
37   /**
38    * Enumeration of margin types. Matches enum MarginType in
39    * printing/print_job_constants.h.
40    * @enum {number}
41    */
42   MarginsType.Value = {
43     DEFAULT: 0,
44     NO_MARGINS: 1,
45     MINIMUM: 2,
46     CUSTOM: 3
47   };
48
49   MarginsType.prototype = {
50     __proto__: print_preview.ticket_items.TicketItem.prototype,
51
52     /** @override */
53     wouldValueBeValid: function(value) {
54       return true;
55     },
56
57     /** @override */
58     isCapabilityAvailable: function() {
59       return this.getDocumentInfoInternal().isModifiable;
60     },
61
62     /** @override */
63     getDefaultValueInternal: function() {
64       return MarginsType.Value.DEFAULT;
65     },
66
67     /** @override */
68     getCapabilityNotAvailableValueInternal: function() {
69       return MarginsType.Value.DEFAULT;
70     },
71
72     /** @override */
73     updateValueInternal: function(value) {
74       print_preview.ticket_items.TicketItem.prototype.updateValueInternal.call(
75           this, value);
76       if (this.isValueEqual(
77           print_preview.ticket_items.MarginsType.Value.CUSTOM)) {
78         // If CUSTOM, set the value of the custom margins so that it won't be
79         // overridden by the default value.
80         this.customMargins_.updateValue(this.customMargins_.getValue());
81       }
82     }
83   };
84
85   // Export
86   return {
87     MarginsType: MarginsType
88   };
89 });