Skip to content

Commit

Permalink
Refactors fit-to-page out of print ticket store.
Browse files Browse the repository at this point in the history
BUG=

Review URL: https://chromiumcodereview.appspot.com/14329017

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@196267 0039d316-1c4b-4281-b951-d872f2087c98
  • Loading branch information
rltoscano@chromium.org committed Apr 25, 2013
1 parent decc67a commit 1fa3ebb
Show file tree
Hide file tree
Showing 6 changed files with 46 additions and 47 deletions.
25 changes: 4 additions & 21 deletions chrome/browser/resources/print_preview/data/print_ticket_store.js
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,10 @@ cr.define('print_preview', function() {
return this.duplex_;
},

get fitToPage() {
return this.fitToPage_;
},

/** @return {boolean} Whether the document is modifiable. */
get isDocumentModifiable() {
return this.documentInfo_.isModifiable;
Expand Down Expand Up @@ -543,27 +547,6 @@ cr.define('print_preview', function() {
}
},

/** @return {boolean} Whether the fit-to-page capability is available. */
hasFitToPageCapability: function() {
return this.fitToPage_.isCapabilityAvailable();
},

/** @return {boolean} Whether the fit-to-page capability is enabled. */
isFitToPageEnabled: function() {
return this.fitToPage_.getValue();
},

/**
* @param {boolean} isFitToPageEnabled Whether to enable the fit-to-page
* capability.
*/
updateFitToPage: function(isFitToPageEnabled) {
if (this.fitToPage_.getValue() != isFitToPageEnabled) {
this.fitToPage_.updateValue(isFitToPageEnabled);
cr.dispatchSimpleEvent(this, PrintTicketStore.EventType.TICKET_CHANGE);
}
},

/**
* @return {boolean} Whether the print CSS backgrounds capability is
* available.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,28 +13,22 @@ cr.define('print_preview.ticket_items', function() {
* @param {!print_preview.DestinationStore} destinationStore Used to determine
* whether fit to page should be available.
* @constructor
* @extends {print_preview.ticket_items.TicketItem}
* @extends {print_preview.ticket_items.DestDependentTicketItem}
*/
function FitToPage(documentInfo, destinationStore) {
print_preview.ticket_items.TicketItem.call(this);
print_preview.ticket_items.DestDependentTicketItem.call(
this, destinationStore);

/**
* Information about the document to print.
* @type {!print_preview.DocumentInfo}
* @private
*/
this.documentInfo_ = documentInfo;

/**
* Used to determine whether fit to page should be available.
* @type {!print_preview.DestinationStore}
* @private
*/
this.destinationStore_ = destinationStore;
};

FitToPage.prototype = {
__proto__: print_preview.ticket_items.TicketItem.prototype,
__proto__: print_preview.ticket_items.DestDependentTicketItem.prototype,

/** @override */
wouldValueBeValid: function(value) {
Expand All @@ -44,8 +38,8 @@ cr.define('print_preview.ticket_items', function() {
/** @override */
isCapabilityAvailable: function() {
return !this.documentInfo_.isModifiable &&
(!this.destinationStore_.selectedDestination ||
this.destinationStore_.selectedDestination.id !=
(!this.getSelectedDestInternal() ||
this.getSelectedDestInternal().id !=
print_preview.Destination.GooglePromotedId.SAVE_AS_PDF);
},

Expand All @@ -56,8 +50,8 @@ cr.define('print_preview.ticket_items', function() {

/** @override */
getCapabilityNotAvailableValueInternal: function() {
return this.destinationStore_.selectedDestination &&
this.destinationStore_.selectedDestination.id ==
return this.getSelectedDestInternal() &&
this.getSelectedDestInternal().id ==
print_preview.Destination.GooglePromotedId.SAVE_AS_PDF;
}
};
Expand Down
4 changes: 2 additions & 2 deletions chrome/browser/resources/print_preview/native_layer.js
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ cr.define('print_preview', function() {
'printWithCloudPrint': destination != null && !destination.isLocal,
'deviceName': destination == null ? 'foo' : destination.id,
'generateDraftData': printTicketStore.isDocumentModifiable,
'fitToPageEnabled': printTicketStore.isFitToPageEnabled(),
'fitToPageEnabled': printTicketStore.fitToPage.getValue(),

// NOTE: Even though the following fields don't directly relate to the
// preview, they still need to be included.
Expand Down Expand Up @@ -242,7 +242,7 @@ cr.define('print_preview', function() {
'deviceName': destination.id,
'isFirstRequest': false,
'requestID': -1,
'fitToPageEnabled': printTicketStore.isFitToPageEnabled()
'fitToPageEnabled': printTicketStore.fitToPage.getValue()
};

if (!destination.isLocal) {
Expand Down
4 changes: 2 additions & 2 deletions chrome/browser/resources/print_preview/preview_generator.js
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ cr.define('print_preview', function() {
this.isHeaderFooterEnabled_ =
this.printTicketStore_.isHeaderFooterEnabled();
this.colorValue_ = this.printTicketStore_.color.getValue();
this.isFitToPageEnabled_ = this.printTicketStore_.isFitToPageEnabled();
this.isFitToPageEnabled_ = this.printTicketStore_.fitToPage.getValue();
this.pageRanges_ = this.printTicketStore_.getPageRanges();
this.marginsType_ = this.printTicketStore_.getMarginsType();
this.isCssBackgroundEnabled_ =
Expand Down Expand Up @@ -259,7 +259,7 @@ cr.define('print_preview', function() {
ticketStore.isLandscapeEnabled() != this.isLandscapeEnabled_ ||
ticketStore.isHeaderFooterEnabled() != this.isHeaderFooterEnabled_ ||
!ticketStore.color.isValueEqual(this.colorValue_) ||
ticketStore.isFitToPageEnabled() != this.isFitToPageEnabled_ ||
!ticketStore.fitToPage.isValueEqual(this.isFitToPageEnabled_) ||
this.pageRanges_ == null ||
!areRangesEqual(ticketStore.getPageRanges(), this.pageRanges_) ||
(ticketStore.getMarginsType() != this.marginsType_ &&
Expand Down
6 changes: 5 additions & 1 deletion chrome/browser/resources/print_preview/print_preview.js
Original file line number Diff line number Diff line change
Expand Up @@ -785,7 +785,11 @@ cr.define('print_preview', function() {
* @private
*/
onDisableScaling_: function() {
this.printTicketStore_.updateFitToPage(false);
// TODO(rltoscano): This should be a property of the document and should
// affect whether the fit-to-page capability is available. That way, we
// don't mistake this value for a user provided value.
// See crbug.com/234857
this.printTicketStore_.fitToPage.updateValue(false);
},

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,13 @@ cr.define('print_preview', function() {
*/
this.duplexTicketItem_ = printTicketStore.duplex;

/**
* Fit-to-page ticket item, used to read/write the fit-to-page selection.
* @type {!print_preview.ticket_items.FitToPage}
* @private
*/
this.fitToPageTicketItem_ = printTicketStore.fitToPage;

/**
* Used to monitor the state of the print ticket.
* @type {!print_preview.PrintTicketStore}
Expand Down Expand Up @@ -156,6 +163,10 @@ cr.define('print_preview', function() {
this.duplexTicketItem_,
print_preview.ticket_items.TicketItem.EventType.CHANGE,
this.onDuplexChange_.bind(this));
this.tracker.add(
this.fitToPageTicketItem_,
print_preview.ticket_items.TicketItem.EventType.CHANGE,
this.onFitToPageChange_.bind(this));
},

/** @override */
Expand Down Expand Up @@ -203,7 +214,7 @@ cr.define('print_preview', function() {
*/
updateContainerState_: function() {
if (this.printTicketStore_.hasHeaderFooterCapability() ||
this.printTicketStore_.hasFitToPageCapability() ||
this.fitToPageTicketItem_.isCapabilityAvailable() ||
this.duplexTicketItem_.isCapabilityAvailable() ||
this.printTicketStore_.hasCssBackgroundCapability() ||
this.printTicketStore_.hasSelectionOnlyCapability()) {
Expand All @@ -229,7 +240,7 @@ cr.define('print_preview', function() {
* @private
*/
onFitToPageCheckboxClick_: function() {
this.printTicketStore_.updateFitToPage(this.fitToPageCheckbox_.checked);
this.fitToPageTicketItem_.updateValue(this.fitToPageCheckbox_.checked);
},

/**
Expand Down Expand Up @@ -271,11 +282,6 @@ cr.define('print_preview', function() {
this.headerFooterCheckbox_.checked =
this.printTicketStore_.isHeaderFooterEnabled();

setIsVisible(this.fitToPageContainer_,
this.printTicketStore_.hasFitToPageCapability());
this.fitToPageCheckbox_.checked =
this.printTicketStore_.isFitToPageEnabled();

setIsVisible(this.cssBackgroundContainer_,
this.printTicketStore_.hasCssBackgroundCapability());
this.cssBackgroundCheckbox_.checked =
Expand All @@ -299,6 +305,18 @@ cr.define('print_preview', function() {
this.duplexTicketItem_.isCapabilityAvailable());
this.duplexCheckbox_.checked = this.duplexTicketItem_.getValue();
this.updateContainerState_();
},

/**
* Called when the fit-to-page ticket item has changed. Updates the
* fit-to-page checkbox.
* @private
*/
onFitToPageChange_: function() {
setIsVisible(this.fitToPageContainer_,
this.fitToPageTicketItem_.isCapabilityAvailable());
this.fitToPageCheckbox_.checked = this.fitToPageTicketItem_.getValue();
this.updateContainerState_();
}
};

Expand Down

0 comments on commit 1fa3ebb

Please sign in to comment.