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..88a1775d832823f43117ce3314475b5b839c15d8 |
--- /dev/null |
+++ b/chrome/browser/resources/print_preview/data/chromium_capabilities.js |
@@ -0,0 +1,186 @@ |
+// 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) { |
+ this.capabilities_ = capabilities; |
+ this.pageRangeStr_ = null; |
+ this.copiesStr_ = null; |
+ this.isCollateEnabled_ = null; |
+ this.isDuplexEnabled_ = null; |
+ this.isLandscapeEnabled_ = null; |
+ this.isColorEnabled_ = null; |
+ this.marginType_ = 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 marginType() { |
+ return this.getValue_( |
+ this.capabilities_.hasMarginsCapability, |
+ this.marginType_, |
+ this.capabilities_.defaultMarginType, |
+ print_preview.Margins.Type.DEFAULT); |
+ }, |
+ |
+ set marginType(marginType) { |
+ this.marginType_ = marginType; |
+ }, |
+ |
+ 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.defaultMarginType = print_preview.Margins.Type.DEFAULT; |
+ this.hasHeaderFooterCapability = false; |
+ this.defaultHeaderFooterCapability = 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 |
+ }; |
+}); |