OLD | NEW |
(Empty) | |
| 1 // Copyright (c) 2011 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 * List of capabilities of a print destination. |
| 10 * @constructor |
| 11 */ |
| 12 function CapabilityList() { |
| 13 /** |
| 14 * Internal list of Capability objects. |
| 15 * @type {Array.<Capability>} |
| 16 */ |
| 17 this.capabilities = []; |
| 18 }; |
| 19 |
| 20 CapabilityList.prototype = { |
| 21 /** |
| 22 * @param {string} semanticId Semantic ID of the capability to get. |
| 23 * @return {print_preview.Capability?} The capability identified by the |
| 24 * given semantic ID or null if not in the list. |
| 25 */ |
| 26 getCapability: function(semanticId) { |
| 27 for (var cap, i = 0; cap = this.capabilities[i]; i++) { |
| 28 if (cap.semanticInfo && cap.semanticInfo.id == semanticId) { |
| 29 return cap; |
| 30 } |
| 31 } |
| 32 return null; |
| 33 }, |
| 34 |
| 35 getNativeCapability: function(nativeId) { |
| 36 for (var cap, i = 0; cap = this.capabilities[i]; i++) { |
| 37 if (cap.nativeInfo && cap.nativeInfo.id == nativeId) { |
| 38 return cap; |
| 39 } |
| 40 } |
| 41 return null; |
| 42 }, |
| 43 |
| 44 addCapability: function(cap) { |
| 45 this.capabilities.push(cap); |
| 46 } |
| 47 }; |
| 48 |
| 49 /** |
| 50 * A capability of a print destination. |
| 51 * @constructor |
| 52 */ |
| 53 function Capability() { |
| 54 this.semanticInfo = null; |
| 55 this.nativeInfo = null; |
| 56 this.type = null; |
| 57 this.valueType = null; |
| 58 this.singleValueInfo = null; |
| 59 this.selectInfo = null; |
| 60 this.rangeInfo = null; |
| 61 }; |
| 62 |
| 63 Capability.Type = { |
| 64 RANGE: 1, |
| 65 SELECT: 2, |
| 66 SINGLE_VALUE: 3 |
| 67 }; |
| 68 |
| 69 Capability.ValueType = { |
| 70 BOOLEAN: 1, |
| 71 FLOAT: 2, |
| 72 INTEGER: 3, |
| 73 MAP: 4, |
| 74 STRING: 5 |
| 75 }; |
| 76 |
| 77 Capability.SemanticId = { |
| 78 COLOR: 1, |
| 79 DUPLEX: 2, |
| 80 ORIENTATION: 3, |
| 81 COPIES: 4, |
| 82 MARGIN: 5, |
| 83 DPI: 6, |
| 84 FIT_TO_PAGE: 7, |
| 85 PAGE_RANGE: 8, |
| 86 MEDIA_TYPE: 9, |
| 87 MEDIA_SIZE: 10, |
| 88 COLLATE: 11 |
| 89 }; |
| 90 |
| 91 Capability.ColorOption = { |
| 92 COLOR: 1, |
| 93 BLACK_WHITE: 2 |
| 94 }; |
| 95 |
| 96 Capability.DuplexOption = { |
| 97 NO_DUPLEX: 1, |
| 98 LONG_EDGE: 2, |
| 99 SHORT_EDGE: 3 |
| 100 }; |
| 101 |
| 102 Capability.OrientationOption = { |
| 103 PORTRAIT: 1, |
| 104 LANDSCAPE: 2, |
| 105 REVERSE_LANDSCAPE: 3 |
| 106 }; |
| 107 |
| 108 function NativeCapabilityInfo(id, displayName) { |
| 109 this.id = id; |
| 110 this.displayName = displayName; |
| 111 }; |
| 112 |
| 113 function SemanticCapabilityInfo(id, displayName) { |
| 114 this.id = id; |
| 115 this.displayName = displayName; |
| 116 }; |
| 117 |
| 118 function RangeInfo(defaultValue, minValue, maxValue) { |
| 119 this.defaultValue = defaultValue; |
| 120 this.minValue = minValue; |
| 121 this.maxValue = maxValue; |
| 122 }; |
| 123 |
| 124 function SelectInfo(defaultOption) { |
| 125 this.defaultOption = defaultOption; |
| 126 |
| 127 // TODO Make private |
| 128 this.options = []; |
| 129 }; |
| 130 |
| 131 SelectInfo.prototype = { |
| 132 /** @param {string} semanticId Semantic ID of the option to get. */ |
| 133 getOption: function(semanticId) { |
| 134 for (var op, i = 0; op = this.options[i]; i++) { |
| 135 if (op.semanticInfo.id == semanticId) { |
| 136 return op; |
| 137 } |
| 138 } |
| 139 return null; |
| 140 }, |
| 141 |
| 142 /** |
| 143 * @param {print_preview.Option} option Option to add to the select |
| 144 * capability info object. |
| 145 */ |
| 146 addOption: function(option) { |
| 147 this.options.push(option); |
| 148 } |
| 149 }; |
| 150 |
| 151 function Option(semanticInfo, nativeInfo) { |
| 152 this.semanticInfo = semanticInfo; |
| 153 this.nativeInfo = nativeInfo; |
| 154 }; |
| 155 |
| 156 function SemanticOptionInfo(id, displayName) { |
| 157 this.id = id; |
| 158 this.displayName = displayName; |
| 159 }; |
| 160 |
| 161 function NativeOptionInfo(id, displayName, value) { |
| 162 this.id = id; |
| 163 this.displayName = displayName; |
| 164 this.value = value; |
| 165 }; |
| 166 |
| 167 function SingleValueInfo(defaultValue) { |
| 168 this.defaultValue = defaultValue; |
| 169 }; |
| 170 |
| 171 function Ticket() { |
| 172 this.ticketItems_ = []; |
| 173 }; |
| 174 |
| 175 Ticket.prototype = { |
| 176 getItem: function(semanticId) { |
| 177 for (var item, i = 0; item = this.ticketItems_[i]; i++) { |
| 178 if (item.semanticInfo.id == semanticId) { |
| 179 return item; |
| 180 } |
| 181 } |
| 182 return null; |
| 183 }, |
| 184 |
| 185 addItem: function(item) { |
| 186 this.ticketItems_.push(item); |
| 187 } |
| 188 }; |
| 189 |
| 190 function TicketItem(semanticInfo, nativeInfo) { |
| 191 this.semanticInfo = semanticInfo; |
| 192 this.nativeInfo = nativeInfo; |
| 193 }; |
| 194 |
| 195 function SemanticTicketItemInfo(id, value) { |
| 196 this.id = id; |
| 197 this.value = value; |
| 198 }; |
| 199 |
| 200 function NativeTicketItemInfo(id, value) { |
| 201 this.id = id; |
| 202 this.value = value; |
| 203 }; |
| 204 |
| 205 // Export |
| 206 return { |
| 207 CapabilityList: CapabilityList, |
| 208 Capability: Capability, |
| 209 NativeCapabilityInfo: NativeCapabilityInfo, |
| 210 SemanticCapabilityInfo: SemanticCapabilityInfo, |
| 211 RangeInfo: RangeInfo, |
| 212 SelectInfo: SelectInfo, |
| 213 SingleValueInfo: SingleValueInfo, |
| 214 Option: Option, |
| 215 SemanticOptionInfo: SemanticOptionInfo, |
| 216 NativeOptionInfo: NativeOptionInfo, |
| 217 Ticket: Ticket, |
| 218 TicketItem: TicketItem, |
| 219 SemanticTicketItemInfo: SemanticTicketItemInfo, |
| 220 NativeTicketItemInfo: NativeTicketItemInfo |
| 221 }; |
| 222 }); |
OLD | NEW |