OLD | NEW |
(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 * Capabilities of a cloud-based print destination. |
| 10 * |
| 11 * @param {print_preview.CollateCapability} collateCapability Print |
| 12 * destination collate capability. |
| 13 * @param {print_preview.ColorCapability} colorCapability Print destination |
| 14 * color capability. |
| 15 * @param {print_preview.CopiesCapability} copiesCapability Print destination |
| 16 * copies capability. |
| 17 * @param {print_preview.DuplexCapability} duplexCapability Print destination |
| 18 * duplexing capability. |
| 19 * @constructor |
| 20 * @extends {print_preview.ChromiumCapabilities} |
| 21 */ |
| 22 function CloudCapabilities( |
| 23 collateCapability, colorCapability, copiesCapability, duplexCapability) { |
| 24 print_preview.ChromiumCapabilities.call( |
| 25 this, |
| 26 !!copiesCapability, |
| 27 '1' /*defaultCopiesStr*/, |
| 28 !!collateCapability, |
| 29 !!collateCapability && collateCapability.isCollateDefault, |
| 30 !!duplexCapability, |
| 31 !!duplexCapability && duplexCapability.isDuplexDefault, |
| 32 true /*hasOrientationCapability*/, |
| 33 false /*defaultIsLandscapeEnabled*/, |
| 34 !!colorCapability, |
| 35 !!colorCapability && colorCapability.isColorDefault); |
| 36 |
| 37 /** |
| 38 * Print destination collate capability. |
| 39 * @type {print_preview.CollateCapability} |
| 40 * @private |
| 41 */ |
| 42 this.collateCapability_ = collateCapability; |
| 43 |
| 44 /** |
| 45 * Print destination color capability. |
| 46 * @type {print_preview.ColorCapability} |
| 47 * @private |
| 48 */ |
| 49 this.colorCapability_ = colorCapability; |
| 50 |
| 51 /** |
| 52 * Print destination copies capability. |
| 53 * @type {print_preview.CopiesCapability} |
| 54 * @private |
| 55 */ |
| 56 this.copiesCapability_ = copiesCapability; |
| 57 |
| 58 /** |
| 59 * Print destination duplexing capability. |
| 60 * @type {print_preview.DuplexCapability} |
| 61 * @private |
| 62 */ |
| 63 this.duplexCapability_ = duplexCapability; |
| 64 }; |
| 65 |
| 66 /** |
| 67 * Enumeration of the capability formats of cloud-based print destinations. |
| 68 * @enum {string} |
| 69 */ |
| 70 CloudCapabilities.Format = { |
| 71 HP: 'hp', |
| 72 PPD: 'ppd', |
| 73 XPS: 'xps' |
| 74 }; |
| 75 |
| 76 CloudCapabilities.prototype = { |
| 77 __proto__: print_preview.ChromiumCapabilities.prototype, |
| 78 |
| 79 /** |
| 80 * @return {print_preview.CollateCapability} The print destination's collate |
| 81 * capability. |
| 82 */ |
| 83 get collateCapability() { |
| 84 return this.collateCapability_; |
| 85 }, |
| 86 |
| 87 /** |
| 88 * @return {print_preview.CollateCapability} The print destination's color |
| 89 * capability. |
| 90 */ |
| 91 get colorCapability() { |
| 92 return this.colorCapability_; |
| 93 }, |
| 94 |
| 95 /** |
| 96 * @return {print_preview.CollateCapability} The print destination's copies |
| 97 * capability. |
| 98 */ |
| 99 get copiesCapability() { |
| 100 return this.copiesCapability_; |
| 101 }, |
| 102 |
| 103 /** |
| 104 * @return {print_preview.CollateCapability} The print destination's |
| 105 * duplexing capability. |
| 106 */ |
| 107 get duplexCapability() { |
| 108 return this.duplexCapability_; |
| 109 } |
| 110 }; |
| 111 |
| 112 /** |
| 113 * A single print capability of a cloud-based print destination. |
| 114 * |
| 115 * @param {string} id Identifier of the capability. |
| 116 * @param {print_preview.CloudCapability.Type} type Type of the capability. |
| 117 * @constructor |
| 118 */ |
| 119 function CloudCapability(id, type) { |
| 120 /** |
| 121 * Identifier of the capability. |
| 122 * @type {string} |
| 123 * @private |
| 124 */ |
| 125 this.id_ = id; |
| 126 |
| 127 /** |
| 128 * Type of the capability. |
| 129 * @type {print_preview.CloudCapability.Type} |
| 130 * @private |
| 131 */ |
| 132 this.type_ = type; |
| 133 }; |
| 134 |
| 135 /** |
| 136 * Enumeration of the types of cloud-based print capabilities. |
| 137 * @enum {string} |
| 138 */ |
| 139 CloudCapability.Type = { |
| 140 FEATURE: 'Feature', |
| 141 PARAMETER_DEF: 'ParameterDef' |
| 142 }; |
| 143 |
| 144 CloudCapability.prototype = { |
| 145 /** @return {string} Identifier of the capability. */ |
| 146 get id() { |
| 147 return this.id_; |
| 148 }, |
| 149 |
| 150 /** @return {print_preview.CloudCapability.Type} Type of the capability. */ |
| 151 get type() { |
| 152 return this.type_; |
| 153 } |
| 154 }; |
| 155 |
| 156 /** |
| 157 * Cloud-based collate capability. |
| 158 * |
| 159 * @param {string} id Identifier of the collate capability. |
| 160 * @param {string} collateOption Identifier of the option that enables |
| 161 * collation. |
| 162 * @param {string} noCollateOption Identifier of the option that disables |
| 163 * collation. |
| 164 * @param {boolean} isCollateDefault Whether collation is enabled by default. |
| 165 * @constructor |
| 166 * @extends {print_preview.CloudCapability} |
| 167 */ |
| 168 function CollateCapability( |
| 169 id, collateOption, noCollateOption, isCollateDefault) { |
| 170 CloudCapability.call(this, id, CloudCapability.Type.FEATURE); |
| 171 |
| 172 /** |
| 173 * Identifier of the option that enables collation. |
| 174 * @type {string} |
| 175 * @private |
| 176 */ |
| 177 this.collateOption_ = collateOption; |
| 178 |
| 179 /** |
| 180 * Identifier of the option that disables collation. |
| 181 * @type {string} |
| 182 * @private |
| 183 */ |
| 184 this.noCollateOption_ = noCollateOption; |
| 185 |
| 186 /** |
| 187 * Whether collation is enabled by default. |
| 188 * @type {boolean} |
| 189 * @private |
| 190 */ |
| 191 this.isCollateDefault_ = isCollateDefault; |
| 192 }; |
| 193 |
| 194 /** |
| 195 * Mapping of capability formats to an identifier of the collate capability. |
| 196 * @type {object<CloudCapabilities.Format, string>} |
| 197 */ |
| 198 CollateCapability.Id = {}; |
| 199 CollateCapability.Id[CloudCapabilities.Format.PPD] = 'Collate'; |
| 200 CollateCapability.Id[CloudCapabilities.Format.XPS] = 'psk:DocumentCollate'; |
| 201 |
| 202 /** |
| 203 * @type {RegExp} |
| 204 */ |
| 205 CollateCapability.COLLATE_REGEX = /(.*:collated.*|true)/i; |
| 206 |
| 207 CollateCapability.NO_COLLATE_REGEX = /(.*:uncollated.*|false)/i; |
| 208 |
| 209 CollateCapability.prototype = { |
| 210 __proto__: CloudCapability.prototype, |
| 211 |
| 212 get collateOption() { |
| 213 return this.collateOption_; |
| 214 }, |
| 215 |
| 216 get noCollateOption() { |
| 217 return this.noCollateOption_; |
| 218 }, |
| 219 |
| 220 get isCollateDefault() { |
| 221 return this.isCollateDefault_; |
| 222 } |
| 223 }; |
| 224 |
| 225 function ColorCapability(id, colorOption, bwOption, isColorDefault) { |
| 226 CloudCapability.call(this, id, CloudCapability.Type.FEATURE); |
| 227 this.colorOption_ = colorOption; |
| 228 this.bwOption_ = bwOption; |
| 229 this.isColorDefault_ = isColorDefault; |
| 230 }; |
| 231 |
| 232 ColorCapability.Id = {}; |
| 233 ColorCapability.Id[CloudCapabilities.Format.HP] = 'ns1:Colors'; |
| 234 ColorCapability.Id[CloudCapabilities.Format.PPD] = 'ColorModel'; |
| 235 ColorCapability.Id[CloudCapabilities.Format.XPS] = 'psk:PageOutputColor'; |
| 236 |
| 237 ColorCapability.COLOR_REGEX = /(.*color.*|.*rgb.*|.*cmy.*|true)/i; |
| 238 |
| 239 ColorCapability.BW_REGEX = /(.*gray.*|.*mono.*|.*black.*|false)/i; |
| 240 |
| 241 ColorCapability.prototype = { |
| 242 __proto__: CloudCapability.prototype, |
| 243 |
| 244 get colorOption() { |
| 245 return this.colorOption_; |
| 246 }, |
| 247 |
| 248 get bwOption() { |
| 249 return this.bwOption_; |
| 250 }, |
| 251 |
| 252 get isColorDefault() { |
| 253 return this.isColorDefault_; |
| 254 } |
| 255 }; |
| 256 |
| 257 function CopiesCapability(id) { |
| 258 CloudCapability.call(this, id, CloudCapability.Type.PARAMETER_DEF); |
| 259 }; |
| 260 |
| 261 CopiesCapability.prototype = { |
| 262 __proto__: CloudCapability.prototype |
| 263 }; |
| 264 |
| 265 CopiesCapability.Id = {}; |
| 266 CopiesCapability.Id[CloudCapabilities.Format.XPS] = |
| 267 'psk:JobCopiesAllDocuments'; |
| 268 |
| 269 function DuplexCapability( |
| 270 id, simplexOption, longEdgeOption, isDuplexDefault) { |
| 271 CloudCapability.call(this, id, CloudCapability.Type.FEATURE); |
| 272 this.simplexOption_ = simplexOption; |
| 273 this.longEdgeOption_ = longEdgeOption; |
| 274 this.isDuplexDefault_ = isDuplexDefault; |
| 275 }; |
| 276 |
| 277 DuplexCapability.Id = {}; |
| 278 DuplexCapability.Id[CloudCapabilities.Format.PPD] = 'Duplex'; |
| 279 DuplexCapability.Id[CloudCapabilities.Format.XPS] = |
| 280 'psk:JobDuplexAllDocumentsContiguously'; |
| 281 |
| 282 DuplexCapability.SIMPLEX_REGEX = /(.*onesided.*|.*none.*)/i; |
| 283 |
| 284 DuplexCapability.LONG_EDGE_REGEX = /(.*longedge.*|duplexNoTumble)/i; |
| 285 |
| 286 DuplexCapability.prototype = { |
| 287 __proto__: CloudCapability.prototype, |
| 288 |
| 289 get simplexOption() { |
| 290 return this.simplexOption_; |
| 291 }, |
| 292 |
| 293 get longEdgeOption() { |
| 294 return this.longEdgeOption_; |
| 295 }, |
| 296 |
| 297 get isDuplexDefault() { |
| 298 return this.isDuplexDefault_; |
| 299 } |
| 300 }; |
| 301 |
| 302 // Export |
| 303 return { |
| 304 CloudCapabilities: CloudCapabilities, |
| 305 CollateCapability: CollateCapability, |
| 306 ColorCapability: ColorCapability, |
| 307 CopiesCapability: CopiesCapability, |
| 308 DuplexCapability: DuplexCapability |
| 309 }; |
| 310 }); |
OLD | NEW |