Index: chrome/browser/resources/print_preview/data/capabilities.js |
diff --git a/chrome/browser/resources/print_preview/data/capabilities.js b/chrome/browser/resources/print_preview/data/capabilities.js |
new file mode 100644 |
index 0000000000000000000000000000000000000000..fd463499c5f2c2cbf685ea8f72aadfaf7f7f7beb |
--- /dev/null |
+++ b/chrome/browser/resources/print_preview/data/capabilities.js |
@@ -0,0 +1,222 @@ |
+// Copyright (c) 2011 The Chromium Authors. All rights reserved. |
+// Use of this source code is governed by a BSD-style license that can be |
+// found in the LICENSE file. |
+ |
+cr.define('print_preview', function() { |
+ 'use strict'; |
+ |
+ /** |
+ * List of capabilities of a print destination. |
+ * @constructor |
+ */ |
+ function CapabilityList() { |
+ /** |
+ * Internal list of Capability objects. |
+ * @type {Array.<Capability>} |
+ */ |
+ this.capabilities = []; |
+ }; |
+ |
+ CapabilityList.prototype = { |
+ /** |
+ * @param {string} semanticId Semantic ID of the capability to get. |
+ * @return {print_preview.Capability?} The capability identified by the |
+ * given semantic ID or null if not in the list. |
+ */ |
+ getCapability: function(semanticId) { |
+ for (var cap, i = 0; cap = this.capabilities[i]; i++) { |
+ if (cap.semanticInfo && cap.semanticInfo.id == semanticId) { |
+ return cap; |
+ } |
+ } |
+ return null; |
+ }, |
+ |
+ getNativeCapability: function(nativeId) { |
+ for (var cap, i = 0; cap = this.capabilities[i]; i++) { |
+ if (cap.nativeInfo && cap.nativeInfo.id == nativeId) { |
+ return cap; |
+ } |
+ } |
+ return null; |
+ }, |
+ |
+ addCapability: function(cap) { |
+ this.capabilities.push(cap); |
+ } |
+ }; |
+ |
+ /** |
+ * A capability of a print destination. |
+ * @constructor |
+ */ |
+ function Capability() { |
+ this.semanticInfo = null; |
+ this.nativeInfo = null; |
+ this.type = null; |
+ this.valueType = null; |
+ this.singleValueInfo = null; |
+ this.selectInfo = null; |
+ this.rangeInfo = null; |
+ }; |
+ |
+ Capability.Type = { |
+ RANGE: 1, |
+ SELECT: 2, |
+ SINGLE_VALUE: 3 |
+ }; |
+ |
+ Capability.ValueType = { |
+ BOOLEAN: 1, |
+ FLOAT: 2, |
+ INTEGER: 3, |
+ MAP: 4, |
+ STRING: 5 |
+ }; |
+ |
+ Capability.SemanticId = { |
+ COLOR: 1, |
+ DUPLEX: 2, |
+ ORIENTATION: 3, |
+ COPIES: 4, |
+ MARGIN: 5, |
+ DPI: 6, |
+ FIT_TO_PAGE: 7, |
+ PAGE_RANGE: 8, |
+ MEDIA_TYPE: 9, |
+ MEDIA_SIZE: 10, |
+ COLLATE: 11 |
+ }; |
+ |
+ Capability.ColorOption = { |
+ COLOR: 1, |
+ BLACK_WHITE: 2 |
+ }; |
+ |
+ Capability.DuplexOption = { |
+ NO_DUPLEX: 1, |
+ LONG_EDGE: 2, |
+ SHORT_EDGE: 3 |
+ }; |
+ |
+ Capability.OrientationOption = { |
+ PORTRAIT: 1, |
+ LANDSCAPE: 2, |
+ REVERSE_LANDSCAPE: 3 |
+ }; |
+ |
+ function NativeCapabilityInfo(id, displayName) { |
+ this.id = id; |
+ this.displayName = displayName; |
+ }; |
+ |
+ function SemanticCapabilityInfo(id, displayName) { |
+ this.id = id; |
+ this.displayName = displayName; |
+ }; |
+ |
+ function RangeInfo(defaultValue, minValue, maxValue) { |
+ this.defaultValue = defaultValue; |
+ this.minValue = minValue; |
+ this.maxValue = maxValue; |
+ }; |
+ |
+ function SelectInfo(defaultOption) { |
+ this.defaultOption = defaultOption; |
+ |
+ // TODO Make private |
+ this.options = []; |
+ }; |
+ |
+ SelectInfo.prototype = { |
+ /** @param {string} semanticId Semantic ID of the option to get. */ |
+ getOption: function(semanticId) { |
+ for (var op, i = 0; op = this.options[i]; i++) { |
+ if (op.semanticInfo.id == semanticId) { |
+ return op; |
+ } |
+ } |
+ return null; |
+ }, |
+ |
+ /** |
+ * @param {print_preview.Option} option Option to add to the select |
+ * capability info object. |
+ */ |
+ addOption: function(option) { |
+ this.options.push(option); |
+ } |
+ }; |
+ |
+ function Option(semanticInfo, nativeInfo) { |
+ this.semanticInfo = semanticInfo; |
+ this.nativeInfo = nativeInfo; |
+ }; |
+ |
+ function SemanticOptionInfo(id, displayName) { |
+ this.id = id; |
+ this.displayName = displayName; |
+ }; |
+ |
+ function NativeOptionInfo(id, displayName, value) { |
+ this.id = id; |
+ this.displayName = displayName; |
+ this.value = value; |
+ }; |
+ |
+ function SingleValueInfo(defaultValue) { |
+ this.defaultValue = defaultValue; |
+ }; |
+ |
+ function Ticket() { |
+ this.ticketItems_ = []; |
+ }; |
+ |
+ Ticket.prototype = { |
+ getItem: function(semanticId) { |
+ for (var item, i = 0; item = this.ticketItems_[i]; i++) { |
+ if (item.semanticInfo.id == semanticId) { |
+ return item; |
+ } |
+ } |
+ return null; |
+ }, |
+ |
+ addItem: function(item) { |
+ this.ticketItems_.push(item); |
+ } |
+ }; |
+ |
+ function TicketItem(semanticInfo, nativeInfo) { |
+ this.semanticInfo = semanticInfo; |
+ this.nativeInfo = nativeInfo; |
+ }; |
+ |
+ function SemanticTicketItemInfo(id, value) { |
+ this.id = id; |
+ this.value = value; |
+ }; |
+ |
+ function NativeTicketItemInfo(id, value) { |
+ this.id = id; |
+ this.value = value; |
+ }; |
+ |
+ // Export |
+ return { |
+ CapabilityList: CapabilityList, |
+ Capability: Capability, |
+ NativeCapabilityInfo: NativeCapabilityInfo, |
+ SemanticCapabilityInfo: SemanticCapabilityInfo, |
+ RangeInfo: RangeInfo, |
+ SelectInfo: SelectInfo, |
+ SingleValueInfo: SingleValueInfo, |
+ Option: Option, |
+ SemanticOptionInfo: SemanticOptionInfo, |
+ NativeOptionInfo: NativeOptionInfo, |
+ Ticket: Ticket, |
+ TicketItem: TicketItem, |
+ SemanticTicketItemInfo: SemanticTicketItemInfo, |
+ NativeTicketItemInfo: NativeTicketItemInfo |
+ }; |
+}); |