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 * @param {print_preview.CollateCapability} collateCapability Print |
| 11 * destination collate capability. |
| 12 * @param {print_preview.ColorCapability} colorCapability Print destination |
| 13 * color capability. |
| 14 * @param {print_preview.CopiesCapability} copiesCapability Print destination |
| 15 * copies capability. |
| 16 * @param {print_preview.DuplexCapability} duplexCapability Print destination |
| 17 * duplexing capability. |
| 18 * @constructor |
| 19 * @extends {print_preview.ChromiumCapabilities} |
| 20 */ |
| 21 function CloudCapabilities( |
| 22 collateCapability, colorCapability, copiesCapability, duplexCapability) { |
| 23 print_preview.ChromiumCapabilities.call( |
| 24 this, |
| 25 !!copiesCapability, |
| 26 '1' /*defaultCopiesStr*/, |
| 27 !!collateCapability, |
| 28 !!collateCapability && collateCapability.isCollateDefault, |
| 29 !!duplexCapability, |
| 30 !!duplexCapability && duplexCapability.isDuplexDefault, |
| 31 true /*hasOrientationCapability*/, |
| 32 false /*defaultIsLandscapeEnabled*/, |
| 33 !!colorCapability, |
| 34 !!colorCapability && colorCapability.isColorDefault); |
| 35 |
| 36 /** |
| 37 * Print destination collate capability. |
| 38 * @type {print_preview.CollateCapability} |
| 39 * @private |
| 40 */ |
| 41 this.collateCapability_ = collateCapability; |
| 42 |
| 43 /** |
| 44 * Print destination color capability. |
| 45 * @type {print_preview.ColorCapability} |
| 46 * @private |
| 47 */ |
| 48 this.colorCapability_ = colorCapability; |
| 49 |
| 50 /** |
| 51 * Print destination copies capability. |
| 52 * @type {print_preview.CopiesCapability} |
| 53 * @private |
| 54 */ |
| 55 this.copiesCapability_ = copiesCapability; |
| 56 |
| 57 /** |
| 58 * Print destination duplexing capability. |
| 59 * @type {print_preview.DuplexCapability} |
| 60 * @private |
| 61 */ |
| 62 this.duplexCapability_ = duplexCapability; |
| 63 }; |
| 64 |
| 65 /** |
| 66 * Enumeration of the capability formats of cloud-based print destinations. |
| 67 * @enum {string} |
| 68 */ |
| 69 CloudCapabilities.Format = { |
| 70 HP: 'hp', |
| 71 PPD: 'ppd', |
| 72 XPS: 'xps' |
| 73 }; |
| 74 |
| 75 CloudCapabilities.prototype = { |
| 76 __proto__: print_preview.ChromiumCapabilities.prototype, |
| 77 |
| 78 /** |
| 79 * @return {print_preview.CollateCapability} The print destination's collate |
| 80 * capability. |
| 81 */ |
| 82 get collateCapability() { |
| 83 return this.collateCapability_; |
| 84 }, |
| 85 |
| 86 /** |
| 87 * @return {print_preview.CollateCapability} The print destination's color |
| 88 * capability. |
| 89 */ |
| 90 get colorCapability() { |
| 91 return this.colorCapability_; |
| 92 }, |
| 93 |
| 94 /** |
| 95 * @return {print_preview.CollateCapability} The print destination's copies |
| 96 * capability. |
| 97 */ |
| 98 get copiesCapability() { |
| 99 return this.copiesCapability_; |
| 100 }, |
| 101 |
| 102 /** |
| 103 * @return {print_preview.CollateCapability} The print destination's |
| 104 * duplexing capability. |
| 105 */ |
| 106 get duplexCapability() { |
| 107 return this.duplexCapability_; |
| 108 } |
| 109 }; |
| 110 |
| 111 /** |
| 112 * A single print capability of a cloud-based print destination. |
| 113 * @param {string} id Identifier of the capability. |
| 114 * @param {print_preview.CloudCapability.Type} type Type of the capability. |
| 115 * @constructor |
| 116 */ |
| 117 function CloudCapability(id, type) { |
| 118 /** |
| 119 * Identifier of the capability. |
| 120 * @type {string} |
| 121 * @private |
| 122 */ |
| 123 this.id_ = id; |
| 124 |
| 125 /** |
| 126 * Type of the capability. |
| 127 * @type {print_preview.CloudCapability.Type} |
| 128 * @private |
| 129 */ |
| 130 this.type_ = type; |
| 131 }; |
| 132 |
| 133 /** |
| 134 * Enumeration of the types of cloud-based print capabilities. |
| 135 * @enum {string} |
| 136 */ |
| 137 CloudCapability.Type = { |
| 138 FEATURE: 'Feature', |
| 139 PARAMETER_DEF: 'ParameterDef' |
| 140 }; |
| 141 |
| 142 CloudCapability.prototype = { |
| 143 /** @return {string} Identifier of the capability. */ |
| 144 get id() { |
| 145 return this.id_; |
| 146 }, |
| 147 |
| 148 /** @return {print_preview.CloudCapability.Type} Type of the capability. */ |
| 149 get type() { |
| 150 return this.type_; |
| 151 } |
| 152 }; |
| 153 |
| 154 /** |
| 155 * Cloud-based collate capability. |
| 156 * @param {string} id Identifier of the collate capability. |
| 157 * @param {string} collateOption Identifier of the option that enables |
| 158 * collation. |
| 159 * @param {string} noCollateOption Identifier of the option that disables |
| 160 * collation. |
| 161 * @param {boolean} isCollateDefault Whether collation is enabled by default. |
| 162 * @constructor |
| 163 * @extends {print_preview.CloudCapability} |
| 164 */ |
| 165 function CollateCapability( |
| 166 id, collateOption, noCollateOption, isCollateDefault) { |
| 167 CloudCapability.call(this, id, CloudCapability.Type.FEATURE); |
| 168 |
| 169 /** |
| 170 * Identifier of the option that enables collation. |
| 171 * @type {string} |
| 172 * @private |
| 173 */ |
| 174 this.collateOption_ = collateOption; |
| 175 |
| 176 /** |
| 177 * Identifier of the option that disables collation. |
| 178 * @type {string} |
| 179 * @private |
| 180 */ |
| 181 this.noCollateOption_ = noCollateOption; |
| 182 |
| 183 /** |
| 184 * Whether collation is enabled by default. |
| 185 * @type {boolean} |
| 186 * @private |
| 187 */ |
| 188 this.isCollateDefault_ = isCollateDefault; |
| 189 }; |
| 190 |
| 191 /** |
| 192 * Mapping of capability formats to an identifier of the collate capability. |
| 193 * @type {object<CloudCapabilities.Format, string>} |
| 194 */ |
| 195 CollateCapability.Id = {}; |
| 196 CollateCapability.Id[CloudCapabilities.Format.PPD] = 'Collate'; |
| 197 CollateCapability.Id[CloudCapabilities.Format.XPS] = 'psk:DocumentCollate'; |
| 198 |
| 199 /** |
| 200 * Regular expression that matches a collate option. |
| 201 * @type {!RegExp} |
| 202 * @const |
| 203 */ |
| 204 CollateCapability.COLLATE_REGEX = /(.*:collated.*|true)/i; |
| 205 |
| 206 /** |
| 207 * Regular expression that matches a no-collate option. |
| 208 * @type {!RegExp} |
| 209 * @const |
| 210 */ |
| 211 CollateCapability.NO_COLLATE_REGEX = /(.*:uncollated.*|false)/i; |
| 212 |
| 213 CollateCapability.prototype = { |
| 214 __proto__: CloudCapability.prototype, |
| 215 |
| 216 /** @return {string} Identifier of the option that enables collation. */ |
| 217 get collateOption() { |
| 218 return this.collateOption_; |
| 219 }, |
| 220 |
| 221 /** @return {string} Identifier of the option that disables collation. */ |
| 222 get noCollateOption() { |
| 223 return this.noCollateOption_; |
| 224 }, |
| 225 |
| 226 /** @return {boolean} Whether collation is enabled by default. */ |
| 227 get isCollateDefault() { |
| 228 return this.isCollateDefault_; |
| 229 } |
| 230 }; |
| 231 |
| 232 /** |
| 233 * Cloud-based color print capability. |
| 234 * @param {string} id Identifier of the color capability. |
| 235 * @param {string} colorOption Identifier of the color option. |
| 236 * @param {string} bwOption Identifier of the black-white option. |
| 237 * @param {boolean} Whether color printing is enabled by default. |
| 238 * @constructor |
| 239 */ |
| 240 function ColorCapability(id, colorOption, bwOption, isColorDefault) { |
| 241 CloudCapability.call(this, id, CloudCapability.Type.FEATURE); |
| 242 |
| 243 /** |
| 244 * Identifier of the color option. |
| 245 * @type {string} |
| 246 * @private |
| 247 */ |
| 248 this.colorOption_ = colorOption; |
| 249 |
| 250 /** |
| 251 * Identifier of the black-white option. |
| 252 * @type {string} |
| 253 * @private |
| 254 */ |
| 255 this.bwOption_ = bwOption; |
| 256 |
| 257 /** |
| 258 * Whether to print in color by default. |
| 259 * @type {boolean} |
| 260 * @private |
| 261 */ |
| 262 this.isColorDefault_ = isColorDefault; |
| 263 }; |
| 264 |
| 265 /** |
| 266 * Mapping of capability formats to an identifier of the color capability. |
| 267 * @type {object<CloudCapabilities.Format, string>} |
| 268 */ |
| 269 ColorCapability.Id = {}; |
| 270 ColorCapability.Id[CloudCapabilities.Format.HP] = 'ns1:Colors'; |
| 271 ColorCapability.Id[CloudCapabilities.Format.PPD] = 'ColorModel'; |
| 272 ColorCapability.Id[CloudCapabilities.Format.XPS] = 'psk:PageOutputColor'; |
| 273 |
| 274 /** |
| 275 * Regular expression that matches a color option. |
| 276 * @type {!RegExp} |
| 277 * @const |
| 278 */ |
| 279 ColorCapability.COLOR_REGEX = /(.*color.*|.*rgb.*|.*cmy.*|true)/i; |
| 280 |
| 281 /** |
| 282 * Regular expression that matches a black-white option. |
| 283 * @type {!RegExp} |
| 284 * @const |
| 285 */ |
| 286 ColorCapability.BW_REGEX = /(.*gray.*|.*mono.*|.*black.*|false)/i; |
| 287 |
| 288 ColorCapability.prototype = { |
| 289 __proto__: CloudCapability.prototype, |
| 290 |
| 291 /** @return {string} Identifier of the color option. */ |
| 292 get colorOption() { |
| 293 return this.colorOption_; |
| 294 }, |
| 295 |
| 296 /** @return {string} Identifier of the black-white option. */ |
| 297 get bwOption() { |
| 298 return this.bwOption_; |
| 299 }, |
| 300 |
| 301 /** @return {boolean} Whether to print in color by default. */ |
| 302 get isColorDefault() { |
| 303 return this.isColorDefault_; |
| 304 } |
| 305 }; |
| 306 |
| 307 /** |
| 308 * Cloud-based copies print capability. |
| 309 * @param {string} id Identifier of the copies capability. |
| 310 * @constructor |
| 311 */ |
| 312 function CopiesCapability(id) { |
| 313 CloudCapability.call(this, id, CloudCapability.Type.PARAMETER_DEF); |
| 314 }; |
| 315 |
| 316 CopiesCapability.prototype = { |
| 317 __proto__: CloudCapability.prototype |
| 318 }; |
| 319 |
| 320 /** |
| 321 * Mapping of capability formats to an identifier of the copies capability. |
| 322 * @type {object<CloudCapabilities.Format, string>} |
| 323 */ |
| 324 CopiesCapability.Id = {}; |
| 325 CopiesCapability.Id[CloudCapabilities.Format.XPS] = |
| 326 'psk:JobCopiesAllDocuments'; |
| 327 |
| 328 /** |
| 329 * Cloud-based duplex print capability. |
| 330 * @param {string} id Identifier of the duplex capability. |
| 331 * @param {string} simplexOption Identifier of the no-duplexing option. |
| 332 * @param {string} longEdgeOption Identifier of the duplex on long edge |
| 333 * option. |
| 334 * @param {boolean} Whether duplexing is enabled by default. |
| 335 * @constructor |
| 336 */ |
| 337 function DuplexCapability( |
| 338 id, simplexOption, longEdgeOption, isDuplexDefault) { |
| 339 CloudCapability.call(this, id, CloudCapability.Type.FEATURE); |
| 340 |
| 341 /** |
| 342 * Identifier of the no-duplexing option. |
| 343 * @type {string} |
| 344 * @private |
| 345 */ |
| 346 this.simplexOption_ = simplexOption; |
| 347 |
| 348 /** |
| 349 * Identifier of the duplex on long edge option. |
| 350 * @type {string} |
| 351 * @private |
| 352 */ |
| 353 this.longEdgeOption_ = longEdgeOption; |
| 354 |
| 355 /** |
| 356 * Whether duplexing is enabled by default. |
| 357 * @type {boolean} |
| 358 * @private |
| 359 */ |
| 360 this.isDuplexDefault_ = isDuplexDefault; |
| 361 }; |
| 362 |
| 363 /** |
| 364 * Mapping of capability formats to an identifier of the duplex capability. |
| 365 * @type {object<CloudCapabilities.Format, string>} |
| 366 */ |
| 367 DuplexCapability.Id = {}; |
| 368 DuplexCapability.Id[CloudCapabilities.Format.PPD] = 'Duplex'; |
| 369 DuplexCapability.Id[CloudCapabilities.Format.XPS] = |
| 370 'psk:JobDuplexAllDocumentsContiguously'; |
| 371 |
| 372 /** |
| 373 * Regular expression that matches a no-duplexing option. |
| 374 * @type {!RegExp} |
| 375 * @const |
| 376 */ |
| 377 DuplexCapability.SIMPLEX_REGEX = /(.*onesided.*|.*none.*)/i; |
| 378 |
| 379 /** |
| 380 * Regular expression that matches a duplex on long edge option. |
| 381 * @type {!RegExp} |
| 382 * @const |
| 383 */ |
| 384 DuplexCapability.LONG_EDGE_REGEX = /(.*longedge.*|duplexNoTumble)/i; |
| 385 |
| 386 DuplexCapability.prototype = { |
| 387 __proto__: CloudCapability.prototype, |
| 388 |
| 389 /** @return {string} Identifier of the no-duplexing option. */ |
| 390 get simplexOption() { |
| 391 return this.simplexOption_; |
| 392 }, |
| 393 |
| 394 /** @return {string} Identifier of the duplex on long edge option. */ |
| 395 get longEdgeOption() { |
| 396 return this.longEdgeOption_; |
| 397 }, |
| 398 |
| 399 /** @return {boolean} Whether duplexing is enabled by default. */ |
| 400 get isDuplexDefault() { |
| 401 return this.isDuplexDefault_; |
| 402 } |
| 403 }; |
| 404 |
| 405 // Export |
| 406 return { |
| 407 CloudCapabilities: CloudCapabilities, |
| 408 CollateCapability: CollateCapability, |
| 409 ColorCapability: ColorCapability, |
| 410 CopiesCapability: CopiesCapability, |
| 411 DuplexCapability: DuplexCapability |
| 412 }; |
| 413 }); |
OLD | NEW |