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