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

Side by Side Diff: chrome/browser/resources/print_preview/data/chromium_capabilities.js

Issue 10108001: Refactor print preview web ui (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: 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 function ChromiumPrintTicket(capabilities) {
9 this.capabilities_ = capabilities;
10 this.pageRangeStr_ = null;
11 this.copiesStr_ = null;
12 this.isCollateEnabled_ = null;
13 this.isDuplexEnabled_ = null;
14 this.isLandscapeEnabled_ = null;
15 this.isColorEnabled_ = null;
16 this.marginType_ = null;
17 this.customMargins_ = null;
18 this.isHeaderFooterEnabled_ = null;
19 };
20
21 ChromiumPrintTicket.prototype = {
22 get pageRangeStr() {
23 return this.getValue_(
24 this.capabilities_.hasPageRangeCapability,
25 this.pageRangeStr_,
26 this.capabilities_.defaultPageRangeStr,
27 '');
28 },
29
30 set pageRangeStr(pageRangeStr) {
31 this.pageRangeStr_ = pageRangeStr;
32 },
33
34 get copiesStr() {
35 return this.getValue_(
36 this.capabilities_.hasCopiesCapability,
37 this.copiesStr_,
38 this.capabilities_.defaultCopiesStr,
39 '1');
40 },
41
42 set copiesStr(copiesStr) {
43 this.copiesStr_ = copiesStr;
44 },
45
46 get isCollateEnabled() {
47 return this.getValue_(
48 this.capabilities_.hasCollateCapability,
49 this.isCollateEnabled_,
50 this.capabilities_.defaultIsCollateEnabled,
51 true);
52 },
53
54 set isCollateEnabled(isCollateEnabled) {
55 this.isCollateEnabled_ = isCollateEnabled;
56 },
57
58 get isDuplexEnabled() {
59 return this.getValue_(
60 this.capabilities_.hasDuplexCapability,
61 this.isDuplexEnabled_,
62 this.capabilities_.defaultIsDuplexEnabled,
63 true);
64 },
65
66 set isDuplexEnabled(isDuplexEnabled) {
67 this.isDuplexEnabled_ = isDuplexEnabled;
68 },
69
70 get duplexMode() {
71 return this.isDuplexEnabled ?
72 ChromiumCapabilities.DuplexMode.LONG_EDGE :
73 ChromiumCapabilities.DuplexMode.SIMPLEX;
74 },
75
76 get isLandscapeEnabled() {
77 return this.getValue_(
78 this.capabilities_.hasOrientationCapability,
79 this.isLandscapeEnabled_,
80 this.capabilities_.defaultIsLandscapeEnabled,
81 false);
82 },
83
84 set isLandscapeEnabled(isLandscapeEnabled) {
85 this.isLandscapeEnabled_ = isLandscapeEnabled;
86 },
87
88 get isColorEnabled() {
89 return this.getValue_(
90 this.capabilities_.hasColorCapability,
91 this.isColorEnabled_,
92 this.capabilities_.defaultIsColorEnabled,
93 false);
94 },
95
96 get colorMode() {
97 return this.isColorEnabled ?
98 ChromiumCapabilities.ColorMode.COLOR :
99 ChromiumCapabilities.ColorMode.GRAY;
100 },
101
102 set isColorEnabled(isColorEnabled) {
103 this.isColorEnabled_ = isColorEnabled;
104 },
105
106 get marginType() {
107 return this.getValue_(
108 this.capabilities_.hasMarginsCapability,
109 this.marginType_,
110 this.capabilities_.defaultMarginType,
111 print_preview.Margins.Type.DEFAULT);
112 },
113
114 set marginType(marginType) {
115 this.marginType_ = marginType;
116 },
117
118 get isHeaderFooterEnabled() {
119 return this.getValue_(
120 this.capabilities_.hasHeaderFooterCapability,
121 this.isHeaderFooterEnabled_,
122 this.capabilities_.defaultIsHeaderFooterEnabled,
123 true);
124 },
125
126 set isHeaderFooterEnabled(isHeaderFooterEnabled) {
127 this.isHeaderFooterEnabled_ = isHeaderFooterEnabled;
128 },
129
130 getValue_: function(hasCap, userVal, defaultCapVal, defaultChromiumVal) {
131 if (hasCap && userVal != null) {
132 return userVal;
133 } else if (hasCap && defaultCapVal != null) {
134 return defaultCapVal;
135 } else {
136 return defaultChromiumVal;
137 }
138 }
139 };
140
141 function ChromiumCapabilities() {
142 this.hasPageRangeCapability = false;
143 this.defaultPageRangeStr = '';
144 this.hasCopiesCapability = false;
145 this.defaultCopiesStr = '1';
146 this.hasCollateCapability = false;
147 this.defaultIsCollateEnabled = false;
148 this.hasDuplexCapability = false;
149 this.defaultIsDuplexEnabled = false;
150 this.hasOrientationCapability = false;
151 this.defaultIsLandscapeEnabled = false;
152 this.hasColorCapability = false;
153 this.defaultIsColorEnabled = false;
154 this.hasMarginsCapability = false;
155 this.defaultMarginType = print_preview.Margins.Type.DEFAULT;
156 this.hasHeaderFooterCapability = false;
157 this.defaultHeaderFooterCapability = true;
158 };
159
160 /**
161 * Constant values matching printing::DuplexMode enum.
162 * @enum {number}
163 * @private
164 */
165 ChromiumCapabilities.DuplexMode = {
166 SIMPLEX: 0,
167 LONG_EDGE: 1,
168 UNKNOWN_DUPLEX_MODE: -1
169 };
170
171 /**
172 * Enumeration of color modes used by Chromium.
173 * @enum {number}
174 * @private
175 */
176 ChromiumCapabilities.ColorMode = {
177 GRAY: 1,
178 COLOR: 2
179 };
180
181 // Export
182 return {
183 ChromiumCapabilities: ChromiumCapabilities,
184 ChromiumPrintTicket: ChromiumPrintTicket
185 };
186 });
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698