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..d66132003ee53a8d0e9733736f8197937742a170 |
--- /dev/null |
+++ b/chrome/browser/resources/print_preview/data/chromium_capabilities.js |
@@ -0,0 +1,446 @@ |
+// 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'; |
+ |
+ /** |
+ * A print ticket defines how the document should be rendered and printed. |
+ * |
dpapad
2012/04/24 01:24:56
Nit: Unnecessary blank line.
Robert Toscano
2012/04/24 22:29:56
Done.
|
+ * @param {!print_preview.ChromiumCapabilities} capabilities Printing |
+ * capabilities of the print destination. |
+ * @constructor |
+ */ |
+ function ChromiumPrintTicket(capabilities) { |
+ /** |
+ * Printing capabilities of the print destination. Contains default values |
+ * for each of the print ticket fields. |
+ * @type {!print_preview.ChromiumCapabilities} |
+ * @private |
+ */ |
+ this.capabilities_ = capabilities; |
+ |
+ /** |
+ * String describing which pages to print. E.g. "1-5,9". {@code null} if the |
+ * user has not specified a page range string. |
+ * @type {?string} |
+ * @private |
+ */ |
+ this.pageRangeStr_ = null; |
+ |
+ /** |
+ * String representing the number of copies of the document to print. |
+ * {@code null} if the user has not specified a copies string. |
+ * @type {?string} |
+ * @private |
+ */ |
+ this.copiesStr_ = null; |
+ |
+ /** |
+ * Whether the document should be collated when printed. {@code null} if the |
+ * user has not specified. |
+ * @type {?boolean} |
+ * @private |
+ */ |
+ this.isCollateEnabled_ = null; |
+ |
+ /** |
+ * Whether the document should be duplexed. {@code null} if not specified. |
+ * @type {?boolean} |
+ * @private |
+ */ |
+ this.isDuplexEnabled_ = null; |
+ |
+ /** |
+ * Whether the document should be printed in landscape. {@code null} if not |
+ * specified. |
+ * @type {?boolean} |
+ * @private |
+ */ |
+ this.isLandscapeEnabled_ = null; |
+ |
+ /** |
+ * Whether the document should be printed in color. {@code null} if not |
+ * specified. |
+ * @type {?boolean} |
+ * @private |
+ */ |
+ this.isColorEnabled_ = null; |
+ |
+ /** |
+ * Type of margins of the document. {@code null} if user has not specified. |
+ * @type {?print_preview.Margins.Type} |
dpapad
2012/04/24 01:24:56
I think that "?" makes sense only for primitives.
Robert Toscano
2012/04/24 22:29:56
It's not explicitly mentioned in the js doc whethe
dpapad
2012/04/24 22:50:19
Hm, I guess I never think of this as a typedef, bu
Robert Toscano
2012/04/28 01:41:37
I'm pretty sure the closure compiler will treat th
dpapad
2012/04/30 16:19:26
Sg.
|
+ * @private |
+ */ |
+ this.marginsType_ = null; |
+ |
+ /** |
+ * Custom margins of the document. {@code null} if not specified. |
+ * @type {print_preview.Margins} |
+ * @private |
+ */ |
+ this.customMargins_ = null; |
+ |
+ /** |
+ * Whether a header and footer should be added to the document. {@code null} |
+ * if not specified. |
+ * @type {?boolean} |
+ * @private |
+ */ |
+ this.isHeaderFooterEnabled_ = null; |
+ }; |
+ |
+ ChromiumPrintTicket.prototype = { |
+ /** |
+ * @param {!print_preview.ChromiumCapabilities} capabilities New print |
+ * destination capabilities to set. |
+ */ |
+ set capabilities(capabilities) { |
+ this.capabilities_ = capabilities; |
+ }, |
+ |
+ /** @return {string} Page range string specification. */ |
+ get pageRangeStr() { |
+ return this.pageRangeStr_ || ''; |
+ }, |
+ |
+ /** @param {string} pageRangeStr Page range string specification to set. */ |
+ set pageRangeStr(pageRangeStr) { |
+ this.pageRangeStr_ = pageRangeStr; |
+ }, |
+ |
+ /** @return {string} Number of copies to print in string form. */ |
+ get copiesStr() { |
+ return this.getValue_( |
+ this.capabilities_.hasCopiesCapability, |
+ this.copiesStr_, |
+ this.capabilities_.defaultCopiesStr, |
+ '1'); |
+ }, |
+ |
+ /** @param {string} copiesStr String form of number of copies to print. */ |
+ set copiesStr(copiesStr) { |
+ this.copiesStr_ = copiesStr; |
+ }, |
+ |
+ /** @return {boolean} Whether the document should be collated. */ |
+ get isCollateEnabled() { |
+ return this.getValue_( |
+ this.capabilities_.hasCollateCapability, |
+ this.isCollateEnabled_, |
+ this.capabilities_.defaultIsCollateEnabled, |
+ true); |
+ }, |
+ |
+ /** |
+ * @param {boolean} isCollateEnabled Whether the document should be |
+ * collated. |
+ */ |
+ set isCollateEnabled(isCollateEnabled) { |
+ this.isCollateEnabled_ = isCollateEnabled; |
+ }, |
+ |
+ /** @return {boolean} Whether the document should be duplexed. */ |
+ get isDuplexEnabled() { |
+ return this.getValue_( |
+ this.capabilities_.hasDuplexCapability, |
+ this.isDuplexEnabled_, |
+ this.capabilities_.defaultIsDuplexEnabled, |
+ true); |
+ }, |
+ |
+ /** |
+ * @param {boolean} isDuplexEnabled Whether the document should be duplexed. |
+ */ |
+ set isDuplexEnabled(isDuplexEnabled) { |
+ this.isDuplexEnabled_ = isDuplexEnabled; |
+ }, |
+ |
+ /** |
+ * @return {boolean} Whether the document should be printed in landscape. |
+ */ |
+ get isLandscapeEnabled() { |
+ return this.getValue_( |
+ this.capabilities_.hasOrientationCapability, |
+ this.isLandscapeEnabled_, |
+ this.capabilities_.defaultIsLandscapeEnabled, |
+ false); |
+ }, |
+ |
+ /** |
+ * @param {boolean} isLandscapeEnabled Whether the document should be |
+ * printed in landscape. |
+ */ |
+ set isLandscapeEnabled(isLandscapeEnabled) { |
+ this.isLandscapeEnabled_ = isLandscapeEnabled; |
+ }, |
+ |
+ /** @return {boolean} Whether the document should be printed in color. */ |
+ get isColorEnabled() { |
+ return this.getValue_( |
+ this.capabilities_.hasColorCapability, |
+ this.isColorEnabled_, |
+ this.capabilities_.defaultIsColorEnabled, |
+ false); |
+ }, |
+ |
+ /** |
+ * @param {boolean} isColorEnabled Whether the document should be printed in |
+ * color. |
+ */ |
+ set isColorEnabled(isColorEnabled) { |
+ this.isColorEnabled_ = isColorEnabled; |
+ }, |
+ |
+ /** |
+ * @return {print_preview.Margins.Type} The document's predefined margins |
+ * type. |
+ */ |
+ get marginsType() { |
+ return this.marginsType_ || print_preview.Margins.Type.DEFAULT; |
+ }, |
+ |
+ /** |
+ * @param {print_preview.Margins.Type} marginsType The document's predefined |
+ * margins type. |
+ */ |
+ set marginsType(marginsType) { |
+ this.marginsType_ = marginsType; |
+ }, |
+ |
+ /** |
+ * @return {print_preview.Margins} Custom margins of the print document. |
+ */ |
+ get customMargins() { |
+ return this.customMargins_; |
+ }, |
+ |
+ /** |
+ * @param {print_preview.Margins} customMargins Custom margins of the |
+ * print document. |
+ */ |
+ set customMargins(customMargins) { |
+ this.customMargins_ = customMargins; |
+ }, |
+ |
+ /** |
+ * @return {boolean} Whether a header footer should be superimposed on the |
+ * document. |
+ */ |
+ get isHeaderFooterEnabled() { |
+ if (this.isHeaderFooterEnabled_ == null) { |
+ return true; |
+ } else { |
+ return this.isHeaderFooterEnabled_; |
+ } |
+ }, |
+ |
+ /** |
+ * @param {boolean} isHeaderFooterEnabled Whether a header footer should be |
+ * superimposed on the document. |
+ */ |
+ set isHeaderFooterEnabled(isHeaderFooterEnabled) { |
+ this.isHeaderFooterEnabled_ = isHeaderFooterEnabled; |
+ }, |
+ |
+ /** |
+ * Gets the value of a capability of a renderer or print destination. |
+ * @param {boolean} hasCap Whether the renderer or print destination has the |
+ * given capability. |
+ * @param {Object} userVal Value specified by the user. |
+ * @param {Object} defaultCapVal Value specified as the default value of the |
+ * given capability. |
+ * @param {Object} defaultChromiumVal Value specified if the renderer or |
+ * print destination does not have the given capability. |
+ * @return {Object} User value if specified, then default capability value |
+ * if capability is available, and finally default chromium value if |
+ * capability not available. |
+ * @private |
+ */ |
+ getValue_: function(hasCap, userVal, defaultCapVal, defaultChromiumVal) { |
+ if (hasCap && userVal != null) { |
+ return userVal; |
+ } else if (hasCap && defaultCapVal != null) { |
+ return defaultCapVal; |
+ } else { |
+ return defaultChromiumVal; |
+ } |
+ } |
+ }; |
+ |
+ /** |
+ * Capabilities of a print destination not including the capabilities of the |
+ * document renderer. |
+ * |
+ * @param {boolean} hasCopiesCapability Whether the print destination has a |
+ * copies capability. |
+ * @param {string} defaultCopiesStr Default string representation of the |
+ * copies value. |
+ * @param {boolean} hasCollateCapability Whether the print destination has |
+ * collation capability. |
+ * @param {boolean} defaultIsCollateEnabled Whether collate is enabled by |
+ * default. |
+ * @param {boolean} hasDuplexCapability Whether the print destination has |
+ * duplexing capability. |
+ * @param {boolean} defaultIsDuplexEnabled Whether duplexing is enabled by |
+ * default. |
+ * @param {boolean} hasOrientationCapability Whether the print destination has |
+ * orientation capability. |
+ * @param {boolean} defaultIsLandscapeEnabled Whether the document should be |
+ * printed in landscape by default. |
+ * @param {boolean} hasColorCapability Whether the print destination has |
+ * color printing capability. |
+ * @param {boolean} defaultIsColorEnabled Whether the document should be |
+ * printed in color by default. |
+ * @constructor |
+ */ |
+ function ChromiumCapabilities( |
+ hasCopiesCapability, |
+ defaultCopiesStr, |
+ hasCollateCapability, |
+ defaultIsCollateEnabled, |
+ hasDuplexCapability, |
+ defaultIsDuplexEnabled, |
+ hasOrientationCapability, |
+ defaultIsLandscapeEnabled, |
+ hasColorCapability, |
+ defaultIsColorEnabled) { |
+ /** |
+ * Whether the print destination has a copies capability. |
+ * @type {boolean} |
+ * @private |
+ */ |
+ this.hasCopiesCapability_ = hasCopiesCapability; |
+ |
+ /** |
+ * Default string representation of the copies value. |
+ * @type {string} |
+ * @private |
+ */ |
+ this.defaultCopiesStr_ = defaultCopiesStr; |
+ |
+ /** |
+ * Whether the print destination has collation capability. |
+ * @type {boolean} |
+ * @private |
+ */ |
+ this.hasCollateCapability_ = hasCollateCapability; |
+ |
+ /** |
+ * Whether collate is enabled by default. |
+ * @type {boolean} |
+ * @private |
+ */ |
+ this.defaultIsCollateEnabled_ = defaultIsCollateEnabled; |
+ |
+ /** |
+ * Whether the print destination has duplexing capability. |
+ * @type {boolean} |
+ * @private |
+ */ |
+ this.hasDuplexCapability_ = hasDuplexCapability; |
+ |
+ /** |
+ * Whether duplex is enabled by default. |
+ * @type {boolean} |
+ * @private |
+ */ |
+ this.defaultIsDuplexEnabled_ = defaultIsDuplexEnabled; |
+ |
+ /** |
+ * Whether the print destination has orientation capability. |
+ * @type {boolean} |
+ * @private |
+ */ |
+ this.hasOrientationCapability_ = hasOrientationCapability; |
+ |
+ /** |
+ * Whether the document should be printed in landscape by default. |
+ * @type {boolean} |
+ * @private |
+ */ |
+ this.defaultIsLandscapeEnabled_ = defaultIsLandscapeEnabled; |
+ |
+ /** |
+ * Whether the print destination has color printing capability. |
+ * @type {boolean} |
+ * @private |
+ */ |
+ this.hasColorCapability_ = hasColorCapability; |
+ |
+ /** |
+ * Whether the document should be printed in color. |
+ * @type {boolean} |
+ * @private |
+ */ |
+ this.defaultIsColorEnabled_ = defaultIsColorEnabled; |
+ }; |
+ |
+ ChromiumCapabilities.prototype = { |
+ /** @return {boolean} Whether the destination has the copies capability. */ |
+ get hasCopiesCapability() { |
+ return this.hasCopiesCapability_; |
+ }, |
+ |
+ /** @return {string} Default number of copies in string format. */ |
+ get defaultCopiesStr() { |
+ return this.defaultCopiesStr_; |
+ }, |
+ |
+ /** @return {boolean} Whether the destination has collation capability. */ |
+ get hasCollateCapability() { |
+ return this.hasCollateCapability_; |
+ }, |
+ |
+ /** @return {boolean} Whether collation is enabled by default. */ |
+ get defaultIsCollateEnabled() { |
+ return this.defaultIsCollateEnabled_; |
+ }, |
+ |
+ /** @return {boolean} Whether the destination has the duplex capability. */ |
+ get hasDuplexCapability() { |
+ return this.hasDuplexCapability_; |
+ }, |
+ |
+ /** @return {boolean} Whether duplexing is enabled by default. */ |
+ get defaultIsDuplexEnabled() { |
+ return this.defaultIsDuplexEnabled_; |
+ }, |
+ |
+ /** |
+ * @return {boolean} Whether the destination has the orientation capability. |
+ */ |
+ get hasOrientationCapability() { |
+ return this.hasOrientationCapability_; |
+ }, |
+ |
+ /** |
+ * @return {boolean} Whether document should be printed in landscape by |
+ * default. |
+ */ |
+ get defaultIsLandscapeEnabled() { |
+ return this.defaultIsLandscapeEnabled_; |
+ }, |
+ |
+ /** |
+ * @return {boolean} Whether the destination has color printing capability. |
+ */ |
+ get hasColorCapability() { |
+ return this.hasColorCapability_; |
+ }, |
+ |
+ /** |
+ * @return {boolean} Whether document should be printed in color by default. |
+ */ |
+ get defaultIsColorEnabled() { |
+ return this.defaultIsColorEnabled_; |
+ } |
+ }; |
+ |
+ // Export |
+ return { |
+ ChromiumCapabilities: ChromiumCapabilities, |
+ ChromiumPrintTicket: ChromiumPrintTicket |
+ }; |
+}); |