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 // TODO Maybe clear print ticket when destination changes. Or better yet, |
| 9 // carry over any print ticket state that is possible. I.e. if destination |
| 10 // changes, the new destination might not support duplex anymore, so we should |
| 11 // clear the ticket's isDuplexEnabled state. |
| 12 |
| 13 /** |
| 14 * Storage of the print ticket and document statistics. Dispatches events when |
| 15 * the contents of the print ticket or document statistics change. Also |
| 16 * handles validation of the print ticket against destination capabilities and |
| 17 * against the document. |
| 18 * @param {!print_preview.DestinationStore} destinationStore Used to |
| 19 * understand which printer is selected. |
| 20 * @constructor |
| 21 * @extends {cr.EventTarget} |
| 22 */ |
| 23 function PrintTicketStore(destinationStore) { |
| 24 cr.EventTarget.call(this); |
| 25 |
| 26 /** |
| 27 * Destination store used to understand which printer is selected. |
| 28 * @type {!print_preview.DestinationStore} |
| 29 * @private |
| 30 */ |
| 31 this.destinationStore_ = destinationStore; |
| 32 |
| 33 // Create the document info with some initial settings. Actual |
| 34 // page-related information won't be set until preview generation occurs, |
| 35 // so we'll use some defaults until then. This way, the print ticket store |
| 36 // will be valid even if no preview can be generated. |
| 37 var initialPageSize = new print_preview.Size(612, 792); // 8.5"x11" |
| 38 |
| 39 /** |
| 40 * Information about the document to print. |
| 41 * @type {!print_preview.DocumentInfo} |
| 42 * @private |
| 43 */ |
| 44 this.documentInfo_ = new print_preview.DocumentInfo(); |
| 45 this.documentInfo_.isModifiable = true; |
| 46 this.documentInfo_.pageCount = 1; |
| 47 this.documentInfo_.pageSize = initialPageSize; |
| 48 this.documentInfo_.printableArea = new print_preview.PrintableArea( |
| 49 new print_preview.Coordinate2d(0, 0), initialPageSize); |
| 50 |
| 51 /** |
| 52 * Printing capabilities of Chromium and the currently selected destination. |
| 53 * @type {!print_preview.CapabilitiesHolder} |
| 54 * @private |
| 55 */ |
| 56 this.capabilitiesHolder_ = new print_preview.CapabilitiesHolder(); |
| 57 |
| 58 /** |
| 59 * Current measurement system. Used to work with margin measurements. |
| 60 * @type {!print_preview.MeasurementSystem} |
| 61 * @private |
| 62 */ |
| 63 this.measurementSystem_ = new print_preview.MeasurementSystem( |
| 64 ',', '.', print_preview.MeasurementSystem.UnitType.IMPERIAL); |
| 65 |
| 66 /** |
| 67 * Collate ticket item. |
| 68 * @type {!print_preview.ticket_items.Collate} |
| 69 * @private |
| 70 */ |
| 71 this.collate_ = |
| 72 new print_preview.ticket_items.Collate(this.capabilitiesHolder_); |
| 73 |
| 74 /** |
| 75 * Color ticket item. |
| 76 * @type {!print_preview.ticket_items.Color} |
| 77 * @private |
| 78 */ |
| 79 this.color_ = new print_preview.ticket_items.Color( |
| 80 this.capabilitiesHolder_, this.destinationStore_); |
| 81 |
| 82 /** |
| 83 * Copies ticket item. |
| 84 * @type {!print_preview.ticket_items.Copies} |
| 85 * @private |
| 86 */ |
| 87 this.copies_ = |
| 88 new print_preview.ticket_items.Copies(this.capabilitiesHolder_); |
| 89 |
| 90 /** |
| 91 * Duplex ticket item. |
| 92 * @type {!print_preview.ticket_items.Duplex} |
| 93 * @private |
| 94 */ |
| 95 this.duplex_ = |
| 96 new print_preview.ticket_items.Duplex(this.capabilitiesHolder_); |
| 97 |
| 98 /** |
| 99 * Landscape ticket item. |
| 100 * @type {!print_preview.ticket_items.Landscape} |
| 101 * @private |
| 102 */ |
| 103 this.landscape_ = new print_preview.ticket_items.Landscape( |
| 104 this.capabilitiesHolder_, this.documentInfo_); |
| 105 |
| 106 /** |
| 107 * Page range ticket item. |
| 108 * @type {!print_preview.ticket_items.PageRange} |
| 109 * @private |
| 110 */ |
| 111 this.pageRange_ = |
| 112 new print_preview.ticket_items.PageRange(this.documentInfo_); |
| 113 |
| 114 /** |
| 115 * Margins type ticket item. |
| 116 * @type {!print_preview.ticket_items.MarginsType} |
| 117 * @private |
| 118 */ |
| 119 this.marginsType_ = |
| 120 new print_preview.ticket_items.MarginsType(this.documentInfo_); |
| 121 |
| 122 /** |
| 123 * Custom margins ticket item. |
| 124 * @type {!print_preview.ticket_items.CustomMargins} |
| 125 * @private |
| 126 */ |
| 127 this.customMargins_ = new print_preview.ticket_items.CustomMargins( |
| 128 this.documentInfo_, this.measurementSystem_); |
| 129 |
| 130 /** |
| 131 * Header-footer ticket item. |
| 132 * @type {!print_preview.ticket_items.HeaderFooter} |
| 133 * @private |
| 134 */ |
| 135 this.headerFooter_ = new print_preview.ticket_items.HeaderFooter( |
| 136 this.documentInfo_, this.marginsType_, this.customMargins_); |
| 137 |
| 138 /** |
| 139 * Fit-to-page ticket item. |
| 140 * @type {!print_preview.ticket_items.FitToPage} |
| 141 * @private |
| 142 */ |
| 143 this.fitToPage_ = new print_preview.ticket_items.FitToPage( |
| 144 this.documentInfo_, this.destinationStore_); |
| 145 }; |
| 146 |
| 147 /** |
| 148 * Event types dispatched by the print ticket store. |
| 149 * @enum {string} |
| 150 */ |
| 151 PrintTicketStore.EventType = { |
| 152 CAPABILITIES_CHANGE: 'print_preview.PrintTicketStore.CAPABILITIES_CHANGE', |
| 153 DOCUMENT_CHANGE: 'print_preview.PrintTicketStore.DOCUMENT_CHANGE', |
| 154 INITIALIZE: 'print_preview.PrintTicketStore.INITIALIZE', |
| 155 TICKET_CHANGE: 'print_preview.PrintTicketStore.TICKET_CHANGE' |
| 156 }; |
| 157 |
| 158 PrintTicketStore.prototype = { |
| 159 __proto__: cr.EventTarget.prototype, |
| 160 |
| 161 /** @return {boolean} Whether the document is modifiable. */ |
| 162 get isDocumentModifiable() { |
| 163 return this.documentInfo_.isModifiable; |
| 164 }, |
| 165 |
| 166 /** @return {number} Number of pages in the document. */ |
| 167 get pageCount() { |
| 168 return this.documentInfo_.pageCount; |
| 169 }, |
| 170 |
| 171 /** |
| 172 * @param {number} pageCount New number of pages in the document. |
| 173 * Dispatches a DOCUMENT_CHANGE event if the value changes. |
| 174 */ |
| 175 updatePageCount: function(pageCount) { |
| 176 if (this.documentInfo_.pageCount != pageCount) { |
| 177 this.documentInfo_.pageCount = pageCount; |
| 178 cr.dispatchSimpleEvent( |
| 179 this, PrintTicketStore.EventType.DOCUMENT_CHANGE); |
| 180 } |
| 181 }, |
| 182 |
| 183 /** |
| 184 * @return {!print_preview.PrintableArea} Printable area of the document in |
| 185 * points. |
| 186 */ |
| 187 get printableArea() { |
| 188 return this.documentInfo_.printableArea; |
| 189 }, |
| 190 |
| 191 /** @return {!print_preview.Size} Size of the document in points. */ |
| 192 get pageSize() { |
| 193 return this.documentInfo_.pageSize; |
| 194 }, |
| 195 |
| 196 /** |
| 197 * Updates a subset of fields of the print document relating to the format |
| 198 * of the page. |
| 199 * @param {!print_preview.PrintableArea} printableArea New printable area of |
| 200 * the document in points. Dispatches a DOCUMENT_CHANGE event if the |
| 201 * value changes. |
| 202 * @param {!print_preview.Size} pageSize New size of the document in points. |
| 203 * Dispatches a DOCUMENT_CHANGE event if the value changes. |
| 204 * @param {boolean} documentHasCssMediaStyles Whether the document is styled |
| 205 * with CSS media styles. |
| 206 * @param {!print_preview.Margins} margins Document margins in points. |
| 207 */ |
| 208 updateDocumentPageInfo: function( |
| 209 printableArea, pageSize, documentHasCssMediaStyles, margins) { |
| 210 if (!this.documentInfo_.printableArea.equals(printableArea) || |
| 211 !this.documentInfo_.pageSize.equals(pageSize) || |
| 212 this.documentInfo_.hasCssMediaStyles != documentHasCssMediaStyles || |
| 213 !this.documentInfo_.margins.equals(margins)) { |
| 214 this.documentInfo_.printableArea = printableArea; |
| 215 this.documentInfo_.pageSize = pageSize; |
| 216 this.documentInfo_.hasCssMediaStyles = documentHasCssMediaStyles; |
| 217 this.documentInfo_.margins = margins; |
| 218 cr.dispatchSimpleEvent( |
| 219 this, PrintTicketStore.EventType.DOCUMENT_CHANGE); |
| 220 } |
| 221 }, |
| 222 |
| 223 /** |
| 224 * @return {!print_preview.MeasurementSystem} Measurement system of the |
| 225 * local system. |
| 226 */ |
| 227 get measurementSystem() { |
| 228 return this.measurementSystem_; |
| 229 }, |
| 230 |
| 231 /** |
| 232 * Initializes the print ticket store. Dispatches an INITIALIZE event. |
| 233 * @param {boolean} isDocumentModifiable Whether the document to print is |
| 234 * modifiable (i.e. can be re-flowed by Chromium). |
| 235 * @param {?boolean} isDuplexEnabled Previous duplex setting. |
| 236 * @param {?boolean} isHeaderFooterEnabled Previous header-footer setting. |
| 237 * @param {?print_preview.ticket_items.MarginsType.Value} marginsType |
| 238 * Previous margins type. |
| 239 * @param {print_preview.Margins} customMargins Previous custom margins. |
| 240 * @param {string} thousandsDelimeter Delimeter of the thousands place. |
| 241 * @param {string} decimalDelimeter Delimeter of the decimal point. |
| 242 * @param {print_preview.MeasurementSystem.UnitType} unitType Type of unit |
| 243 * of the local measurement system. |
| 244 */ |
| 245 initialize: function( |
| 246 isDocumentModifiable, |
| 247 isDuplexEnabled, |
| 248 isHeaderFooterEnabled, |
| 249 marginsType, |
| 250 customMargins, |
| 251 thousandsDelimeter, |
| 252 decimalDelimeter, |
| 253 unitType) { |
| 254 |
| 255 this.documentInfo_.isModifiable = isDocumentModifiable; |
| 256 this.measurementSystem_.setSystem( |
| 257 thousandsDelimeter, decimalDelimeter, unitType); |
| 258 |
| 259 // Initialize ticket with user's previous values. |
| 260 if (isDuplexEnabled != null) { |
| 261 this.duplex_.updateValue(isDuplexEnabled); |
| 262 } |
| 263 if (isHeaderFooterEnabled != null) { |
| 264 this.headerFooter_.updateValue(isHeaderFooterEnabled); |
| 265 } |
| 266 if (marginsType != null) { |
| 267 this.marginsType_.updateValue(marginsType); |
| 268 } |
| 269 if (customMargins != null) { |
| 270 this.customMargins_.updateValue(customMargins); |
| 271 } |
| 272 }, |
| 273 |
| 274 /** |
| 275 * Updates the capabilities of the destination the print ticket is for. |
| 276 * Dispatches a CAPABILITIES_CHANGE event. |
| 277 * @param {!print_preview.ChromiumCapabilities} caps New capabilities. |
| 278 */ |
| 279 updateDestinationCapabilities: function(caps) { |
| 280 var isFirstUpdate = this.capabilitiesHolder_.get() == null; |
| 281 this.capabilitiesHolder_.set(caps); |
| 282 this.customMargins_.updateValue(null); |
| 283 this.marginsType_.updateValue( |
| 284 print_preview.ticket_items.MarginsType.Value.DEFAULT); |
| 285 if (isFirstUpdate) { |
| 286 cr.dispatchSimpleEvent(this, PrintTicketStore.EventType.INITIALIZE); |
| 287 } else { |
| 288 cr.dispatchSimpleEvent( |
| 289 this, PrintTicketStore.EventType.CAPABILITIES_CHANGE); |
| 290 } |
| 291 }, |
| 292 |
| 293 /** @return {boolean} Whether the ticket store has the copies capability. */ |
| 294 hasCopiesCapability: function() { |
| 295 return this.copies_.isCapabilityAvailable(); |
| 296 }, |
| 297 |
| 298 /** |
| 299 * @return {boolean} Whether the string representation of the copies value |
| 300 * currently in the ticket store is valid. |
| 301 */ |
| 302 isCopiesValid: function() { |
| 303 return this.copies_.isValid(); |
| 304 }, |
| 305 |
| 306 isCopiesValidForValue: function(value) { |
| 307 return this.copies_.wouldValueBeValid(value); |
| 308 }, |
| 309 |
| 310 /** @return {number} Number of copies to print. */ |
| 311 getCopies: function() { |
| 312 return this.copies_.getValueAsNumber(); |
| 313 }, |
| 314 |
| 315 /** |
| 316 * @return {string} String representation of the number of copies to print. |
| 317 */ |
| 318 getCopiesStr: function() { |
| 319 return this.copies_.getValue(); |
| 320 }, |
| 321 |
| 322 /** |
| 323 * Updates the string representation of the number of copies to print. |
| 324 * Dispatches a TICKET_CHANGE event if the string value has changed. |
| 325 * @param {string} New string representation of the number of copies to |
| 326 * print. |
| 327 */ |
| 328 updateCopies: function(copies) { |
| 329 if (this.copies_.getValue() != copies) { |
| 330 this.copies_.updateValue(copies); |
| 331 cr.dispatchSimpleEvent(this, PrintTicketStore.EventType.TICKET_CHANGE); |
| 332 } |
| 333 }, |
| 334 |
| 335 /** @return {boolean} Whether the ticket store has a collate capability. */ |
| 336 hasCollateCapability: function() { |
| 337 return this.collate_.isCapabilityAvailable(); |
| 338 }, |
| 339 |
| 340 /** @return {boolean} Whether collate is enabled. */ |
| 341 isCollateEnabled: function() { |
| 342 return this.collate_.getValue(); |
| 343 }, |
| 344 |
| 345 /** |
| 346 * Updates whether collate is enabled. Dispatches a TICKET_CHANGE event if |
| 347 * collate has changed. |
| 348 * @param {boolean} isCollateEnabled Whether collate is enabled. |
| 349 */ |
| 350 updateCollate: function(isCollateEnabled) { |
| 351 if (this.collate_.getValue() != isCollateEnabled) { |
| 352 this.collate_.updateValue(isCollateEnabled); |
| 353 cr.dispatchSimpleEvent(this, PrintTicketStore.EventType.TICKET_CHANGE); |
| 354 } |
| 355 }, |
| 356 |
| 357 /** |
| 358 * @return {boolean} Whether the ticket store has color printing capability. |
| 359 */ |
| 360 hasColorCapability: function() { |
| 361 return this.color_.isCapabilityAvailable(); |
| 362 }, |
| 363 |
| 364 /** @return {boolean} Whether color printing is enabled. */ |
| 365 isColorEnabled: function() { |
| 366 return this.color_.getValue(); |
| 367 }, |
| 368 |
| 369 /** |
| 370 * Updates whether color printing is enabled. Dispatches a TICKET_CHANGE if |
| 371 * color has changed. |
| 372 * @param {boolean} isColorEnabled Whether the color printing is enabled. |
| 373 */ |
| 374 updateColor: function(isColorEnabled) { |
| 375 if (this.color_.getValue() != isColorEnabled) { |
| 376 this.color_.updateValue(isColorEnabled); |
| 377 cr.dispatchSimpleEvent(this, PrintTicketStore.EventType.TICKET_CHANGE); |
| 378 } |
| 379 }, |
| 380 |
| 381 /** @return {boolean} Whether the header-footer capability is available. */ |
| 382 hasHeaderFooterCapability: function() { |
| 383 return this.headerFooter_.isCapabilityAvailable(); |
| 384 }, |
| 385 |
| 386 /** @return {boolean} Whether the header-footer setting is enabled. */ |
| 387 isHeaderFooterEnabled: function() { |
| 388 return this.headerFooter_.getValue(); |
| 389 }, |
| 390 |
| 391 /** |
| 392 * Updates the whether the header-footer setting is enabled. Dispatches a |
| 393 * TICKET_CHANGE event if the setting changed. |
| 394 * @param {boolean} isHeaderFooterEnabled Whether the header-footer setting |
| 395 * is enabled. |
| 396 */ |
| 397 updateHeaderFooter: function(isHeaderFooterEnabled) { |
| 398 if (this.headerFooter_.getValue() != isHeaderFooterEnabled) { |
| 399 this.headerFooter_.updateValue(isHeaderFooterEnabled); |
| 400 cr.dispatchSimpleEvent(this, PrintTicketStore.EventType.TICKET_CHANGE); |
| 401 } |
| 402 }, |
| 403 |
| 404 /** |
| 405 * @return {boolean} Whether the page orientation capability is available. |
| 406 */ |
| 407 hasOrientationCapability: function() { |
| 408 return this.landscape_.isCapabilityAvailable(); |
| 409 }, |
| 410 |
| 411 /** |
| 412 * @return {boolean} Whether the document should be printed in landscape. |
| 413 */ |
| 414 isLandscapeEnabled: function() { |
| 415 return this.landscape_.getValue(); |
| 416 }, |
| 417 |
| 418 /** |
| 419 * Updates whether the document should be printed in landscape. Dispatches |
| 420 * a TICKET_CHANGE event if the setting changes. |
| 421 * @param {boolean} isLandscapeEnabled Whether the document should be |
| 422 * printed in landscape. |
| 423 */ |
| 424 updateOrientation: function(isLandscapeEnabled) { |
| 425 if (this.landscape_.getValue() != isLandscapeEnabled) { |
| 426 this.landscape_.updateValue(isLandscapeEnabled); |
| 427 // Reset the user set margins. |
| 428 this.customMargins_.updateValue(null); |
| 429 cr.dispatchSimpleEvent(this, PrintTicketStore.EventType.TICKET_CHANGE); |
| 430 } |
| 431 }, |
| 432 |
| 433 /** @return {boolean} Whether the duplexing capability is available. */ |
| 434 hasDuplexCapability: function() { |
| 435 return this.duplex_.isCapabilityAvailable(); |
| 436 }, |
| 437 |
| 438 /** @return {boolean} Whether the document should be printed in duplex. */ |
| 439 isDuplexEnabled: function() { |
| 440 return this.duplex_.getValue(); |
| 441 }, |
| 442 |
| 443 /** |
| 444 * Updates the duplexing setting. Dispatches a TICKET_CHANGE event if the |
| 445 * value changes. |
| 446 * @param {boolean} isDuplexEnabled Whether the document should be printed |
| 447 * in duplex. |
| 448 */ |
| 449 updateDuplex: function(isDuplexEnabled) { |
| 450 if (this.duplex_.getValue() != isDuplexEnabled) { |
| 451 this.duplex_.updateValue(isDuplexEnabled); |
| 452 cr.dispatchSimpleEvent(this, PrintTicketStore.EventType.TICKET_CHANGE); |
| 453 } |
| 454 }, |
| 455 |
| 456 /** @return {boolean} Whether the margins capability is available. */ |
| 457 hasMarginsCapability: function() { |
| 458 return this.marginsType_.isCapabilityAvailable(); |
| 459 }, |
| 460 |
| 461 /** |
| 462 * @return {print_preview.ticket_items.MarginsType.Value} Type of predefined |
| 463 * margins. |
| 464 */ |
| 465 getMarginsType: function() { |
| 466 return this.marginsType_.getValue(); |
| 467 }, |
| 468 |
| 469 /** |
| 470 * Updates the type of predefined margins. Dispatches a TICKET_CHANGE event |
| 471 * if the margins type changes. |
| 472 * @param {print_preview.ticket_items.MarginsType.Value} marginsType Type of |
| 473 * predefined margins. |
| 474 */ |
| 475 updateMarginsType: function(marginsType) { |
| 476 if (this.marginsType_.getValue() != marginsType) { |
| 477 this.marginsType_.updateValue(marginsType); |
| 478 if (marginsType == |
| 479 print_preview.ticket_items.MarginsType.Value.CUSTOM) { |
| 480 // If CUSTOM, set the value of the custom margins so that it won't be |
| 481 // overriden by the default value. |
| 482 this.customMargins_.updateValue(this.customMargins_.getValue()); |
| 483 } |
| 484 cr.dispatchSimpleEvent(this, PrintTicketStore.EventType.TICKET_CHANGE); |
| 485 } |
| 486 }, |
| 487 |
| 488 /** @return {boolean} Whether all of the custom margins are valid. */ |
| 489 isCustomMarginsValid: function() { |
| 490 return this.customMargins_.isValid(); |
| 491 }, |
| 492 |
| 493 /** |
| 494 * @return {!print_preview.Margins} Custom margins of the document in |
| 495 * points. |
| 496 */ |
| 497 getCustomMargins: function() { |
| 498 return this.customMargins_.getValue(); |
| 499 }, |
| 500 |
| 501 /** |
| 502 * @param {print_preview.ticket_items.CustomMargins.Orientation} orientation |
| 503 * Specifies the margin to get the maximum value for. |
| 504 * @return {number} Maximum value in points of the specified margin. |
| 505 */ |
| 506 getCustomMarginMax: function(orientation) { |
| 507 return this.customMargins_.getMarginMax(orientation); |
| 508 }, |
| 509 |
| 510 /** |
| 511 * Updates the custom margins of the document. Dispatches a TICKET_CHANGE |
| 512 * event if the margins have changed. |
| 513 * @param {!print_preview.Margins} margins New document page margins in |
| 514 * points. |
| 515 */ |
| 516 updateCustomMargins: function(margins) { |
| 517 if (!this.isCustomMarginsValid() || |
| 518 !margins.equals(this.getCustomMargins())) { |
| 519 this.customMargins_.updateValue(margins); |
| 520 cr.dispatchSimpleEvent(this, PrintTicketStore.EventType.TICKET_CHANGE); |
| 521 } |
| 522 }, |
| 523 |
| 524 /** |
| 525 * Updates a single custom margin's value in points. |
| 526 * @param {print_preview.ticket_items.CustomMargins.Orientation} orientation |
| 527 * Specifies the margin to update. |
| 528 * @param {number} value Updated margin in points. |
| 529 */ |
| 530 updateCustomMargin: function(orientation, value) { |
| 531 if (this.customMargins_.getValue().get(orientation) != value) { |
| 532 this.customMargins_.updateMargin(orientation, value); |
| 533 cr.dispatchSimpleEvent(this, PrintTicketStore.EventType.TICKET_CHANGE); |
| 534 } |
| 535 }, |
| 536 |
| 537 /** @return {boolean} Whether the page range capability is available. */ |
| 538 hasPageRangeCapability: function() { |
| 539 return this.pageRange_.isCapabilityAvailable(); |
| 540 }, |
| 541 |
| 542 /** |
| 543 * @return {boolean} Whether the current page range string is defines a |
| 544 * valid page number set. |
| 545 */ |
| 546 isPageRangeValid: function() { |
| 547 return this.pageRange_.isValid(); |
| 548 }, |
| 549 |
| 550 /** @return {string} String representation of the page range. */ |
| 551 getPageRangeStr: function() { |
| 552 return this.pageRange_.getValue(); |
| 553 }, |
| 554 |
| 555 /** |
| 556 * @return {!print_preview.PageNumberSet} Page number set specified by the |
| 557 * string representation of the page range string. |
| 558 */ |
| 559 getPageNumberSet: function() { |
| 560 return this.pageRange_.getPageNumberSet(); |
| 561 }, |
| 562 |
| 563 /** |
| 564 * Updates the page range string. Dispatches a TICKET_CHANGE if the string |
| 565 * changed. |
| 566 * @param {string} pageRangeStr New page range string. |
| 567 */ |
| 568 updatePageRange: function(pageRangeStr) { |
| 569 if (this.pageRange_.getValue() != pageRangeStr) { |
| 570 this.pageRange_.updateValue(pageRangeStr); |
| 571 cr.dispatchSimpleEvent(this, PrintTicketStore.EventType.TICKET_CHANGE); |
| 572 } |
| 573 }, |
| 574 |
| 575 /** @return {boolean} Whether the fit-to-page capability is available. */ |
| 576 hasFitToPageCapability: function() { |
| 577 return this.fitToPage_.isCapabilityAvailable(); |
| 578 }, |
| 579 |
| 580 /** @return {boolean} Whether the fit-to-page capability is enabled. */ |
| 581 isFitToPageEnabled: function() { |
| 582 return this.fitToPage_.getValue(); |
| 583 }, |
| 584 |
| 585 /** |
| 586 * @param {boolean} isFitToPageEnabled Whether to enable the fit-to-page |
| 587 * capability. |
| 588 */ |
| 589 updateFitToPage: function(isFitToPageEnabled) { |
| 590 if (this.fitToPage_.getValue() != isFitToPageEnabled) { |
| 591 this.fitToPage_.updateValue(isFitToPageEnabled); |
| 592 cr.dispatchSimpleEvent(this, PrintTicketStore.EventType.TICKET_CHANGE); |
| 593 } |
| 594 }, |
| 595 |
| 596 /** |
| 597 * @return {boolean} {@code true} if the stored print ticket is valid, |
| 598 * {@code false} otherwise. |
| 599 */ |
| 600 isTicketValid: function() { |
| 601 return (!this.hasCopiesCapability() || this.isCopiesValid()) && |
| 602 (!this.hasPageRangeCapability() || this.isPageRangeValid()) && |
| 603 (!this.hasMarginsCapability() || |
| 604 this.getMarginsType() != |
| 605 print_preview.ticket_items.MarginsType.Value.CUSTOM || |
| 606 this.isCustomMarginsValid()); |
| 607 } |
| 608 }; |
| 609 |
| 610 // Export |
| 611 return { |
| 612 PrintTicketStore: PrintTicketStore |
| 613 }; |
| 614 }); |
OLD | NEW |