Index: chrome/browser/resources/print_preview/data/chromium_capabilities.js |
diff --git a/chrome/browser/resources/print_preview/data/chromium_capabilities.js b/chrome/browser/resources/print_preview/data/chromium_capabilities.js |
new file mode 100644 |
index 0000000000000000000000000000000000000000..78a8c07b50209f2907348b7cfc5004b3a4e33b96 |
--- /dev/null |
+++ b/chrome/browser/resources/print_preview/data/chromium_capabilities.js |
@@ -0,0 +1,199 @@ |
+// Copyright (c) 2012 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'; |
+ |
+ function ChromiumPrintTicket(capabilities) { |
dpapad1
2012/04/19 22:45:01
Could you add documentation (@type,@param,@returs
Robert Toscano
2012/04/23 23:00:09
Done.
|
+ this.capabilities_ = capabilities; |
+ this.pageRangeStr_ = null; |
+ this.copiesStr_ = null; |
+ this.isCollateEnabled_ = null; |
+ this.isDuplexEnabled_ = null; |
+ this.isLandscapeEnabled_ = null; |
+ this.isColorEnabled_ = null; |
+ this.marginsType_ = null; |
+ this.customMargins_ = null; |
+ this.isHeaderFooterEnabled_ = null; |
+ }; |
+ |
+ ChromiumPrintTicket.prototype = { |
+ get pageRangeStr() { |
+ return this.getValue_( |
+ this.capabilities_.hasPageRangeCapability, |
+ this.pageRangeStr_, |
+ this.capabilities_.defaultPageRangeStr, |
+ ''); |
+ }, |
+ |
+ set pageRangeStr(pageRangeStr) { |
+ this.pageRangeStr_ = pageRangeStr; |
+ }, |
+ |
+ get copiesStr() { |
+ return this.getValue_( |
+ this.capabilities_.hasCopiesCapability, |
+ this.copiesStr_, |
+ this.capabilities_.defaultCopiesStr, |
+ '1'); |
+ }, |
+ |
+ set copiesStr(copiesStr) { |
+ this.copiesStr_ = copiesStr; |
+ }, |
+ |
+ get isCollateEnabled() { |
+ return this.getValue_( |
+ this.capabilities_.hasCollateCapability, |
+ this.isCollateEnabled_, |
+ this.capabilities_.defaultIsCollateEnabled, |
+ true); |
+ }, |
+ |
+ set isCollateEnabled(isCollateEnabled) { |
+ this.isCollateEnabled_ = isCollateEnabled; |
+ }, |
+ |
+ get isDuplexEnabled() { |
+ return this.getValue_( |
+ this.capabilities_.hasDuplexCapability, |
+ this.isDuplexEnabled_, |
+ this.capabilities_.defaultIsDuplexEnabled, |
+ true); |
+ }, |
+ |
+ set isDuplexEnabled(isDuplexEnabled) { |
+ this.isDuplexEnabled_ = isDuplexEnabled; |
+ }, |
+ |
+ get duplexMode() { |
+ return this.isDuplexEnabled ? |
+ ChromiumCapabilities.DuplexMode.LONG_EDGE : |
+ ChromiumCapabilities.DuplexMode.SIMPLEX; |
+ }, |
+ |
+ get isLandscapeEnabled() { |
+ return this.getValue_( |
+ this.capabilities_.hasOrientationCapability, |
+ this.isLandscapeEnabled_, |
+ this.capabilities_.defaultIsLandscapeEnabled, |
+ false); |
+ }, |
+ |
+ set isLandscapeEnabled(isLandscapeEnabled) { |
+ this.isLandscapeEnabled_ = isLandscapeEnabled; |
+ }, |
+ |
+ get isColorEnabled() { |
+ return this.getValue_( |
+ this.capabilities_.hasColorCapability, |
+ this.isColorEnabled_, |
+ this.capabilities_.defaultIsColorEnabled, |
+ false); |
+ }, |
+ |
+ get colorMode() { |
+ return this.isColorEnabled ? |
+ ChromiumCapabilities.ColorMode.COLOR : |
+ ChromiumCapabilities.ColorMode.GRAY; |
+ }, |
+ |
+ set isColorEnabled(isColorEnabled) { |
+ this.isColorEnabled_ = isColorEnabled; |
+ }, |
+ |
+ get marginsType() { |
+ return this.getValue_( |
+ this.capabilities_.hasMarginsCapability, |
+ this.marginsType_, |
+ this.capabilities_.defaultMarginsType, |
+ print_preview.Margins.Type.DEFAULT); |
+ }, |
+ |
+ set marginsType(marginsType) { |
+ this.marginsType_ = marginsType; |
+ }, |
+ |
+ get customMargins() { |
+ return this.getValue_( |
+ this.capabilities_.hasMarginsCapability, |
+ this.customMargins_, |
+ this.capabilities_.defaultCustomMargins, |
+ null); |
+ }, |
+ |
+ set customMargins(customMargins) { |
+ this.customMargins_ = customMargins; |
+ }, |
+ |
+ get isHeaderFooterEnabled() { |
+ return this.getValue_( |
+ this.capabilities_.hasHeaderFooterCapability, |
+ this.isHeaderFooterEnabled_, |
+ this.capabilities_.defaultIsHeaderFooterEnabled, |
+ true); |
+ }, |
+ |
+ set isHeaderFooterEnabled(isHeaderFooterEnabled) { |
+ this.isHeaderFooterEnabled_ = isHeaderFooterEnabled; |
+ }, |
+ |
+ getValue_: function(hasCap, userVal, defaultCapVal, defaultChromiumVal) { |
+ if (hasCap && userVal != null) { |
+ return userVal; |
+ } else if (hasCap && defaultCapVal != null) { |
+ return defaultCapVal; |
+ } else { |
+ return defaultChromiumVal; |
+ } |
+ } |
+ }; |
+ |
+ function ChromiumCapabilities() { |
+ this.hasPageRangeCapability = false; |
+ this.defaultPageRangeStr = ''; |
+ this.hasCopiesCapability = false; |
+ this.defaultCopiesStr = '1'; |
+ this.hasCollateCapability = false; |
+ this.defaultIsCollateEnabled = false; |
+ this.hasDuplexCapability = false; |
+ this.defaultIsDuplexEnabled = false; |
+ this.hasOrientationCapability = false; |
+ this.defaultIsLandscapeEnabled = false; |
+ this.hasColorCapability = false; |
+ this.defaultIsColorEnabled = false; |
+ this.hasMarginsCapability = false; |
+ this.defaultMarginsType = print_preview.Margins.Type.DEFAULT; |
+ this.defaultCustomMargins = new print_preview.Margins(72, 72, 72, 72); |
+ this.hasHeaderFooterCapability = false; |
+ this.defaultIsHeaderFooterEnabled = true; |
+ }; |
+ |
+ /** |
+ * Constant values matching printing::DuplexMode enum. |
+ * @enum {number} |
+ * @private |
+ */ |
+ ChromiumCapabilities.DuplexMode = { |
+ SIMPLEX: 0, |
+ LONG_EDGE: 1, |
+ UNKNOWN_DUPLEX_MODE: -1 |
+ }; |
+ |
+ /** |
+ * Enumeration of color modes used by Chromium. |
+ * @enum {number} |
+ * @private |
+ */ |
+ ChromiumCapabilities.ColorMode = { |
+ GRAY: 1, |
+ COLOR: 2 |
+ }; |
+ |
+ // Export |
+ return { |
+ ChromiumCapabilities: ChromiumCapabilities, |
+ ChromiumPrintTicket: ChromiumPrintTicket |
+ }; |
+}); |