Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(20)

Side by Side Diff: chrome/browser/resources/print_preview/data/print_ticket_store.js

Issue 10450022: Print Preview Print Destination Search Widget (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Set --bary flag Created 8 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 cr.define('print_preview', function() { 5 cr.define('print_preview', function() {
6 'use strict'; 6 'use strict';
7 7
8 // TODO(rltoscano): Maybe clear print ticket when destination changes. Or 8 // TODO(rltoscano): Maybe clear print ticket when destination changes. Or
9 // better yet, carry over any print ticket state that is possible. I.e. if 9 // better yet, carry over any print ticket state that is possible. I.e. if
10 // destination changes, the new destination might not support duplex anymore, 10 // destination changes, the new destination might not support duplex anymore,
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
62 */ 62 */
63 this.measurementSystem_ = new print_preview.MeasurementSystem( 63 this.measurementSystem_ = new print_preview.MeasurementSystem(
64 ',', '.', print_preview.MeasurementSystem.UnitType.IMPERIAL); 64 ',', '.', print_preview.MeasurementSystem.UnitType.IMPERIAL);
65 65
66 /** 66 /**
67 * Collate ticket item. 67 * Collate ticket item.
68 * @type {!print_preview.ticket_items.Collate} 68 * @type {!print_preview.ticket_items.Collate}
69 * @private 69 * @private
70 */ 70 */
71 this.collate_ = 71 this.collate_ =
72 new print_preview.ticket_items.Collate(this.capabilitiesHolder_); 72 new print_preview.ticket_items.Collate(this.capabilitiesHolder_);
73 73
74 /** 74 /**
75 * Color ticket item. 75 * Color ticket item.
76 * @type {!print_preview.ticket_items.Color} 76 * @type {!print_preview.ticket_items.Color}
77 * @private 77 * @private
78 */ 78 */
79 this.color_ = new print_preview.ticket_items.Color( 79 this.color_ = new print_preview.ticket_items.Color(
80 this.capabilitiesHolder_, this.destinationStore_); 80 this.capabilitiesHolder_, this.destinationStore_);
81 81
82 /** 82 /**
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
135 this.headerFooter_ = new print_preview.ticket_items.HeaderFooter( 135 this.headerFooter_ = new print_preview.ticket_items.HeaderFooter(
136 this.documentInfo_, this.marginsType_, this.customMargins_); 136 this.documentInfo_, this.marginsType_, this.customMargins_);
137 137
138 /** 138 /**
139 * Fit-to-page ticket item. 139 * Fit-to-page ticket item.
140 * @type {!print_preview.ticket_items.FitToPage} 140 * @type {!print_preview.ticket_items.FitToPage}
141 * @private 141 * @private
142 */ 142 */
143 this.fitToPage_ = new print_preview.ticket_items.FitToPage( 143 this.fitToPage_ = new print_preview.ticket_items.FitToPage(
144 this.documentInfo_, this.destinationStore_); 144 this.documentInfo_, this.destinationStore_);
145
146 /**
147 * Keeps track of event listeners for the print ticket store.
148 * @type {!EventTracker}
149 * @private
150 */
151 this.tracker_ = new EventTracker();
152
153 this.addEventListeners_();
145 }; 154 };
146 155
147 /** 156 /**
148 * Event types dispatched by the print ticket store. 157 * Event types dispatched by the print ticket store.
149 * @enum {string} 158 * @enum {string}
150 */ 159 */
151 PrintTicketStore.EventType = { 160 PrintTicketStore.EventType = {
152 CAPABILITIES_CHANGE: 'print_preview.PrintTicketStore.CAPABILITIES_CHANGE', 161 CAPABILITIES_CHANGE: 'print_preview.PrintTicketStore.CAPABILITIES_CHANGE',
153 DOCUMENT_CHANGE: 'print_preview.PrintTicketStore.DOCUMENT_CHANGE', 162 DOCUMENT_CHANGE: 'print_preview.PrintTicketStore.DOCUMENT_CHANGE',
154 INITIALIZE: 'print_preview.PrintTicketStore.INITIALIZE', 163 INITIALIZE: 'print_preview.PrintTicketStore.INITIALIZE',
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
236 getDocumentMargins: function() { 245 getDocumentMargins: function() {
237 return this.documentInfo_.margins; 246 return this.documentInfo_.margins;
238 }, 247 },
239 248
240 /** 249 /**
241 * Initializes the print ticket store. Dispatches an INITIALIZE event. 250 * Initializes the print ticket store. Dispatches an INITIALIZE event.
242 * @param {boolean} isDocumentModifiable Whether the document to print is 251 * @param {boolean} isDocumentModifiable Whether the document to print is
243 * modifiable (i.e. can be re-flowed by Chromium). 252 * modifiable (i.e. can be re-flowed by Chromium).
244 * @param {?boolean} isDuplexEnabled Previous duplex setting. 253 * @param {?boolean} isDuplexEnabled Previous duplex setting.
245 * @param {?boolean} isHeaderFooterEnabled Previous header-footer setting. 254 * @param {?boolean} isHeaderFooterEnabled Previous header-footer setting.
246 * @param {?print_preview.ticket_items.MarginsType.Value} marginsType 255 * @param {print_preview.ticket_items.MarginsType.Value} marginsType
247 * Previous margins type. 256 * Previous margins type.
248 * @param {print_preview.Margins} customMargins Previous custom margins. 257 * @param {print_preview.Margins} customMargins Previous custom margins.
249 * @param {string} thousandsDelimeter Delimeter of the thousands place. 258 * @param {string} thousandsDelimeter Delimeter of the thousands place.
250 * @param {string} decimalDelimeter Delimeter of the decimal point. 259 * @param {string} decimalDelimeter Delimeter of the decimal point.
251 * @param {print_preview.MeasurementSystem.UnitType} unitType Type of unit 260 * @param {!print_preview.MeasurementSystem.UnitType} unitType Type of unit
252 * of the local measurement system. 261 * of the local measurement system.
253 */ 262 */
254 initialize: function( 263 initialize: function(
255 isDocumentModifiable, 264 isDocumentModifiable,
256 isDuplexEnabled, 265 isDuplexEnabled,
257 isHeaderFooterEnabled, 266 isHeaderFooterEnabled,
258 marginsType, 267 marginsType,
259 customMargins, 268 customMargins,
260 thousandsDelimeter, 269 thousandsDelimeter,
261 decimalDelimeter, 270 decimalDelimeter,
262 unitType) { 271 unitType) {
263 272
264 this.documentInfo_.isModifiable = isDocumentModifiable; 273 this.documentInfo_.isModifiable = isDocumentModifiable;
265 this.measurementSystem_.setSystem( 274 this.measurementSystem_.setSystem(
266 thousandsDelimeter, decimalDelimeter, unitType); 275 thousandsDelimeter, decimalDelimeter, unitType);
267 276
268 // Initialize ticket with user's previous values. 277 // Initialize ticket with user's previous values.
269 this.duplex_.updateValue(isDuplexEnabled); 278 this.duplex_.updateValue(isDuplexEnabled);
270 this.headerFooter_.updateValue(isHeaderFooterEnabled); 279 this.headerFooter_.updateValue(isHeaderFooterEnabled);
271 if (marginsType != null) { 280 if (marginsType != null) {
272 this.marginsType_.updateValue(marginsType); 281 this.marginsType_.updateValue(marginsType);
273 } 282 }
274 if (customMargins != null) { 283 if (customMargins != null) {
275 this.customMargins_.updateValue(customMargins); 284 this.customMargins_.updateValue(customMargins);
276 } 285 }
277 }, 286 },
278 287
279 /**
280 * Updates the capabilities of the destination the print ticket is for.
281 * Dispatches a CAPABILITIES_CHANGE event.
282 * @param {!print_preview.ChromiumCapabilities} caps New capabilities.
283 */
284 updateDestinationCapabilities: function(caps) {
285 var isFirstUpdate = this.capabilitiesHolder_.get() == null;
286 this.capabilitiesHolder_.set(caps);
287 if (isFirstUpdate) {
288 cr.dispatchSimpleEvent(this, PrintTicketStore.EventType.INITIALIZE);
289 } else {
290 this.customMargins_.updateValue(null);
291 if (this.marginsType_.getValue() ==
292 print_preview.ticket_items.MarginsType.Value.CUSTOM) {
293 this.marginsType_.updateValue(
294 print_preview.ticket_items.MarginsType.Value.DEFAULT);
295 }
296 cr.dispatchSimpleEvent(
297 this, PrintTicketStore.EventType.CAPABILITIES_CHANGE);
298 }
299 },
300
301 /** @return {boolean} Whether the ticket store has the copies capability. */ 288 /** @return {boolean} Whether the ticket store has the copies capability. */
302 hasCopiesCapability: function() { 289 hasCopiesCapability: function() {
303 return this.copies_.isCapabilityAvailable(); 290 return this.copies_.isCapabilityAvailable();
304 }, 291 },
305 292
306 /** 293 /**
307 * @return {boolean} Whether the string representation of the copies value 294 * @return {boolean} Whether the string representation of the copies value
308 * currently in the ticket store is valid. 295 * currently in the ticket store is valid.
309 */ 296 */
310 isCopiesValid: function() { 297 isCopiesValid: function() {
(...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after
462 cr.dispatchSimpleEvent(this, PrintTicketStore.EventType.TICKET_CHANGE); 449 cr.dispatchSimpleEvent(this, PrintTicketStore.EventType.TICKET_CHANGE);
463 } 450 }
464 }, 451 },
465 452
466 /** @return {boolean} Whether the margins capability is available. */ 453 /** @return {boolean} Whether the margins capability is available. */
467 hasMarginsCapability: function() { 454 hasMarginsCapability: function() {
468 return this.marginsType_.isCapabilityAvailable(); 455 return this.marginsType_.isCapabilityAvailable();
469 }, 456 },
470 457
471 /** 458 /**
472 * @return {print_preview.ticket_items.MarginsType.Value} Type of predefined 459 * @return {!print_preview.ticket_items.MarginsType.Value} Type of
473 * margins. 460 * predefined margins.
474 */ 461 */
475 getMarginsType: function() { 462 getMarginsType: function() {
476 return this.marginsType_.getValue(); 463 return this.marginsType_.getValue();
477 }, 464 },
478 465
479 /** 466 /**
480 * Updates the type of predefined margins. Dispatches a TICKET_CHANGE event 467 * Updates the type of predefined margins. Dispatches a TICKET_CHANGE event
481 * if the margins type changes. 468 * if the margins type changes.
482 * @param {print_preview.ticket_items.MarginsType.Value} marginsType Type of 469 * @param {print_preview.ticket_items.MarginsType.Value} marginsType Type of
483 * predefined margins. 470 * predefined margins.
(...skipping 18 matching lines...) Expand all
502 489
503 /** 490 /**
504 * @return {!print_preview.Margins} Custom margins of the document in 491 * @return {!print_preview.Margins} Custom margins of the document in
505 * points. 492 * points.
506 */ 493 */
507 getCustomMargins: function() { 494 getCustomMargins: function() {
508 return this.customMargins_.getValue(); 495 return this.customMargins_.getValue();
509 }, 496 },
510 497
511 /** 498 /**
512 * @param {print_preview.ticket_items.CustomMargins.Orientation} orientation 499 * @param {!print_preview.ticket_items.CustomMargins.Orientation}
513 * Specifies the margin to get the maximum value for. 500 * orientation Specifies the margin to get the maximum value for.
514 * @return {number} Maximum value in points of the specified margin. 501 * @return {number} Maximum value in points of the specified margin.
515 */ 502 */
516 getCustomMarginMax: function(orientation) { 503 getCustomMarginMax: function(orientation) {
517 return this.customMargins_.getMarginMax(orientation); 504 return this.customMargins_.getMarginMax(orientation);
518 }, 505 },
519 506
520 /** 507 /**
521 * Updates the custom margins of the document. Dispatches a TICKET_CHANGE 508 * Updates the custom margins of the document. Dispatches a TICKET_CHANGE
522 * event if the margins have changed. 509 * event if the margins have changed.
523 * @param {!print_preview.Margins} margins New document page margins in 510 * @param {!print_preview.Margins} margins New document page margins in
524 * points. 511 * points.
525 */ 512 */
526 updateCustomMargins: function(margins) { 513 updateCustomMargins: function(margins) {
527 if (!this.isCustomMarginsValid() || 514 if (!this.isCustomMarginsValid() ||
528 !margins.equals(this.getCustomMargins())) { 515 !margins.equals(this.getCustomMargins())) {
529 this.customMargins_.updateValue(margins); 516 this.customMargins_.updateValue(margins);
530 cr.dispatchSimpleEvent(this, PrintTicketStore.EventType.TICKET_CHANGE); 517 cr.dispatchSimpleEvent(this, PrintTicketStore.EventType.TICKET_CHANGE);
531 } 518 }
532 }, 519 },
533 520
534 /** 521 /**
535 * Updates a single custom margin's value in points. 522 * Updates a single custom margin's value in points.
536 * @param {print_preview.ticket_items.CustomMargins.Orientation} orientation 523 * @param {!print_preview.ticket_items.CustomMargins.Orientation}
537 * Specifies the margin to update. 524 * orientation Specifies the margin to update.
538 * @param {number} value Updated margin in points. 525 * @param {number} value Updated margin in points.
539 */ 526 */
540 updateCustomMargin: function(orientation, value) { 527 updateCustomMargin: function(orientation, value) {
541 if (this.customMargins_.getValue().get(orientation) != value) { 528 if (this.customMargins_.getValue().get(orientation) != value) {
542 this.customMargins_.updateMargin(orientation, value); 529 this.customMargins_.updateMargin(orientation, value);
543 cr.dispatchSimpleEvent(this, PrintTicketStore.EventType.TICKET_CHANGE); 530 cr.dispatchSimpleEvent(this, PrintTicketStore.EventType.TICKET_CHANGE);
544 } 531 }
545 }, 532 },
546 533
547 /** @return {boolean} Whether the page range capability is available. */ 534 /** @return {boolean} Whether the page range capability is available. */
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
612 (!this.hasPageRangeCapability() || this.isPageRangeValid()); 599 (!this.hasPageRangeCapability() || this.isPageRangeValid());
613 }, 600 },
614 601
615 /** @return {boolean} Whether the ticket is valid for preview generation. */ 602 /** @return {boolean} Whether the ticket is valid for preview generation. */
616 isTicketValidForPreview: function() { 603 isTicketValidForPreview: function() {
617 return (!this.hasCopiesCapability() || this.isCopiesValid()) && 604 return (!this.hasCopiesCapability() || this.isCopiesValid()) &&
618 (!this.hasMarginsCapability() || 605 (!this.hasMarginsCapability() ||
619 this.getMarginsType() != 606 this.getMarginsType() !=
620 print_preview.ticket_items.MarginsType.Value.CUSTOM || 607 print_preview.ticket_items.MarginsType.Value.CUSTOM ||
621 this.isCustomMarginsValid()); 608 this.isCustomMarginsValid());
609 },
610
611 /**
612 * Adds event listeners for the print ticket store.
613 * @private
614 */
615 addEventListeners_: function() {
616 this.tracker_.add(
617 this.destinationStore_,
618 print_preview.DestinationStore.EventType.
619 SELECTED_DESTINATION_CAPABILITIES_READY,
620 this.onSelectedDestinationCapabilitiesReady_.bind(this));
621 },
622
623 /**
624 * Called when the capabilities of the selected destination are ready.
625 * @private
626 */
627 onSelectedDestinationCapabilitiesReady_: function() {
628 var caps = this.destinationStore_.selectedDestination.capabilities;
629 var isFirstUpdate = this.capabilitiesHolder_.get() == null;
630 this.capabilitiesHolder_.set(caps);
631 if (isFirstUpdate) {
632 cr.dispatchSimpleEvent(this, PrintTicketStore.EventType.INITIALIZE);
633 } else {
634 this.customMargins_.updateValue(null);
635 if (this.marginsType_.getValue() ==
636 print_preview.ticket_items.MarginsType.Value.CUSTOM) {
637 this.marginsType_.updateValue(
638 print_preview.ticket_items.MarginsType.Value.DEFAULT);
639 }
640 cr.dispatchSimpleEvent(
641 this, PrintTicketStore.EventType.CAPABILITIES_CHANGE);
642 }
622 } 643 }
623 }; 644 };
624 645
625 // Export 646 // Export
626 return { 647 return {
627 PrintTicketStore: PrintTicketStore 648 PrintTicketStore: PrintTicketStore
628 }; 649 };
629 }); 650 });
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698