OLD | NEW |
(Empty) | |
| 1 // Copyright (c) 2012 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 function ChromiumPrintTicket(capabilities) { |
| 9 this.capabilities_ = capabilities; |
| 10 this.pageRangeStr_ = null; |
| 11 this.copiesStr_ = null; |
| 12 this.isCollateEnabled_ = null; |
| 13 this.isDuplexEnabled_ = null; |
| 14 this.isLandscapeEnabled_ = null; |
| 15 this.isColorEnabled_ = null; |
| 16 this.marginsType_ = null; |
| 17 this.customMargins_ = null; |
| 18 this.isHeaderFooterEnabled_ = null; |
| 19 }; |
| 20 |
| 21 ChromiumPrintTicket.prototype = { |
| 22 get pageRangeStr() { |
| 23 return this.getValue_( |
| 24 this.capabilities_.hasPageRangeCapability, |
| 25 this.pageRangeStr_, |
| 26 this.capabilities_.defaultPageRangeStr, |
| 27 ''); |
| 28 }, |
| 29 |
| 30 set pageRangeStr(pageRangeStr) { |
| 31 this.pageRangeStr_ = pageRangeStr; |
| 32 }, |
| 33 |
| 34 get copiesStr() { |
| 35 return this.getValue_( |
| 36 this.capabilities_.hasCopiesCapability, |
| 37 this.copiesStr_, |
| 38 this.capabilities_.defaultCopiesStr, |
| 39 '1'); |
| 40 }, |
| 41 |
| 42 set copiesStr(copiesStr) { |
| 43 this.copiesStr_ = copiesStr; |
| 44 }, |
| 45 |
| 46 get isCollateEnabled() { |
| 47 return this.getValue_( |
| 48 this.capabilities_.hasCollateCapability, |
| 49 this.isCollateEnabled_, |
| 50 this.capabilities_.defaultIsCollateEnabled, |
| 51 true); |
| 52 }, |
| 53 |
| 54 set isCollateEnabled(isCollateEnabled) { |
| 55 this.isCollateEnabled_ = isCollateEnabled; |
| 56 }, |
| 57 |
| 58 get isDuplexEnabled() { |
| 59 return this.getValue_( |
| 60 this.capabilities_.hasDuplexCapability, |
| 61 this.isDuplexEnabled_, |
| 62 this.capabilities_.defaultIsDuplexEnabled, |
| 63 true); |
| 64 }, |
| 65 |
| 66 set isDuplexEnabled(isDuplexEnabled) { |
| 67 this.isDuplexEnabled_ = isDuplexEnabled; |
| 68 }, |
| 69 |
| 70 get duplexMode() { |
| 71 return this.isDuplexEnabled ? |
| 72 ChromiumCapabilities.DuplexMode.LONG_EDGE : |
| 73 ChromiumCapabilities.DuplexMode.SIMPLEX; |
| 74 }, |
| 75 |
| 76 get isLandscapeEnabled() { |
| 77 return this.getValue_( |
| 78 this.capabilities_.hasOrientationCapability, |
| 79 this.isLandscapeEnabled_, |
| 80 this.capabilities_.defaultIsLandscapeEnabled, |
| 81 false); |
| 82 }, |
| 83 |
| 84 set isLandscapeEnabled(isLandscapeEnabled) { |
| 85 this.isLandscapeEnabled_ = isLandscapeEnabled; |
| 86 }, |
| 87 |
| 88 get isColorEnabled() { |
| 89 return this.getValue_( |
| 90 this.capabilities_.hasColorCapability, |
| 91 this.isColorEnabled_, |
| 92 this.capabilities_.defaultIsColorEnabled, |
| 93 false); |
| 94 }, |
| 95 |
| 96 get colorMode() { |
| 97 return this.isColorEnabled ? |
| 98 ChromiumCapabilities.ColorMode.COLOR : |
| 99 ChromiumCapabilities.ColorMode.GRAY; |
| 100 }, |
| 101 |
| 102 set isColorEnabled(isColorEnabled) { |
| 103 this.isColorEnabled_ = isColorEnabled; |
| 104 }, |
| 105 |
| 106 get marginsType() { |
| 107 return this.getValue_( |
| 108 this.capabilities_.hasMarginsCapability, |
| 109 this.marginsType_, |
| 110 this.capabilities_.defaultMarginsType, |
| 111 print_preview.Margins.Type.DEFAULT); |
| 112 }, |
| 113 |
| 114 set marginsType(marginsType) { |
| 115 this.marginsType_ = marginsType; |
| 116 }, |
| 117 |
| 118 get customMargins() { |
| 119 return this.getValue_( |
| 120 this.capabilities_.hasMarginsCapability, |
| 121 this.customMargins_, |
| 122 this.capabilities_.defaultCustomMargins, |
| 123 null); |
| 124 }, |
| 125 |
| 126 set customMargins(customMargins) { |
| 127 this.customMargins_ = customMargins; |
| 128 }, |
| 129 |
| 130 get isHeaderFooterEnabled() { |
| 131 return this.getValue_( |
| 132 this.capabilities_.hasHeaderFooterCapability, |
| 133 this.isHeaderFooterEnabled_, |
| 134 this.capabilities_.defaultIsHeaderFooterEnabled, |
| 135 true); |
| 136 }, |
| 137 |
| 138 set isHeaderFooterEnabled(isHeaderFooterEnabled) { |
| 139 this.isHeaderFooterEnabled_ = isHeaderFooterEnabled; |
| 140 }, |
| 141 |
| 142 getValue_: function(hasCap, userVal, defaultCapVal, defaultChromiumVal) { |
| 143 if (hasCap && userVal != null) { |
| 144 return userVal; |
| 145 } else if (hasCap && defaultCapVal != null) { |
| 146 return defaultCapVal; |
| 147 } else { |
| 148 return defaultChromiumVal; |
| 149 } |
| 150 } |
| 151 }; |
| 152 |
| 153 function ChromiumCapabilities() { |
| 154 this.hasPageRangeCapability = false; |
| 155 this.defaultPageRangeStr = ''; |
| 156 this.hasCopiesCapability = false; |
| 157 this.defaultCopiesStr = '1'; |
| 158 this.hasCollateCapability = false; |
| 159 this.defaultIsCollateEnabled = false; |
| 160 this.hasDuplexCapability = false; |
| 161 this.defaultIsDuplexEnabled = false; |
| 162 this.hasOrientationCapability = false; |
| 163 this.defaultIsLandscapeEnabled = false; |
| 164 this.hasColorCapability = false; |
| 165 this.defaultIsColorEnabled = false; |
| 166 this.hasMarginsCapability = false; |
| 167 this.defaultMarginsType = print_preview.Margins.Type.DEFAULT; |
| 168 this.defaultCustomMargins = new print_preview.Margins(72, 72, 72, 72); |
| 169 this.hasHeaderFooterCapability = false; |
| 170 this.defaultIsHeaderFooterEnabled = true; |
| 171 }; |
| 172 |
| 173 /** |
| 174 * Constant values matching printing::DuplexMode enum. |
| 175 * @enum {number} |
| 176 * @private |
| 177 */ |
| 178 ChromiumCapabilities.DuplexMode = { |
| 179 SIMPLEX: 0, |
| 180 LONG_EDGE: 1, |
| 181 UNKNOWN_DUPLEX_MODE: -1 |
| 182 }; |
| 183 |
| 184 /** |
| 185 * Enumeration of color modes used by Chromium. |
| 186 * @enum {number} |
| 187 * @private |
| 188 */ |
| 189 ChromiumCapabilities.ColorMode = { |
| 190 GRAY: 1, |
| 191 COLOR: 2 |
| 192 }; |
| 193 |
| 194 // Export |
| 195 return { |
| 196 ChromiumCapabilities: ChromiumCapabilities, |
| 197 ChromiumPrintTicket: ChromiumPrintTicket |
| 198 }; |
| 199 }); |
OLD | NEW |