From a9b59ab8626439e94c005f3c4b0765f751690155 Mon Sep 17 00:00:00 2001 From: "rltoscano@chromium.org" Date: Sat, 18 May 2013 08:48:39 +0000 Subject: Small refactoring to fit-to-page and bug fix. BUG=234857 Review URL: https://chromiumcodereview.appspot.com/14495005 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@200969 0039d316-1c4b-4281-b951-d872f2087c98 --- .../resources/print_preview/data/document_info.js | 25 ++++++++++++++++++++++ .../print_preview/data/ticket_items/fit_to_page.js | 21 ++++++++---------- .../print_preview/previewarea/preview_area.js | 4 ++++ .../resources/print_preview/print_preview.js | 11 ++++------ chrome/test/data/webui/print_preview.js | 2 +- 5 files changed, 43 insertions(+), 20 deletions(-) diff --git a/chrome/browser/resources/print_preview/data/document_info.js b/chrome/browser/resources/print_preview/data/document_info.js index d763b38..f604cfd 100644 --- a/chrome/browser/resources/print_preview/data/document_info.js +++ b/chrome/browser/resources/print_preview/data/document_info.js @@ -35,6 +35,13 @@ cr.define('print_preview', function() { this.isModifiable_ = true; /** + * Whether scaling of the document is prohibited. + * @type {boolean} + * @private + */ + this.isScalingDisabled_ = false; + + /** * Margins of the document in points. * @type {print_preview.Margins} * @private @@ -113,6 +120,11 @@ cr.define('print_preview', function() { return this.isModifiable_; }, + /** @return {boolean} Whether scaling of the document is prohibited. */ + get isScalingDisabled() { + return this.isScalingDisabled_; + }, + /** @return {print_preview.Margins} Margins of the document in points. */ get margins() { return this.margins_; @@ -159,6 +171,19 @@ cr.define('print_preview', function() { }, /** + * Updates whether scaling is disabled for the document and dispatches a + * CHANGE event. + * @param {boolean} isScalingDisabled Whether scaling of the document is + * prohibited. + */ + updateIsScalingDisabled: function(isScalingDisabled) { + if (this.isInitialized_ && this.isScalingDisabled_ != isScalingDisabled) { + this.isScalingDisabled_ = isScalingDisabled; + cr.dispatchSimpleEvent(this, DocumentInfo.EventType.CHANGE); + } + }, + + /** * Updates the total number of pages in the document and dispatches a CHANGE * event. * @param {number} pageCount Number of pages in the document. diff --git a/chrome/browser/resources/print_preview/data/ticket_items/fit_to_page.js b/chrome/browser/resources/print_preview/data/ticket_items/fit_to_page.js index b40e915..1023ce1 100644 --- a/chrome/browser/resources/print_preview/data/ticket_items/fit_to_page.js +++ b/chrome/browser/resources/print_preview/data/ticket_items/fit_to_page.js @@ -17,14 +17,11 @@ cr.define('print_preview.ticket_items', function() { */ function FitToPage(documentInfo, destinationStore) { print_preview.ticket_items.TicketItem.call( - this, null /*appState*/, null /*field*/, destinationStore); - - /** - * Information about the document to print. - * @type {!print_preview.DocumentInfo} - * @private - */ - this.documentInfo_ = documentInfo; + this, + null /*appState*/, + null /*field*/, + destinationStore, + documentInfo); }; FitToPage.prototype = { @@ -37,7 +34,7 @@ cr.define('print_preview.ticket_items', function() { /** @override */ isCapabilityAvailable: function() { - return !this.documentInfo_.isModifiable && + return !this.getDocumentInfoInternal().isModifiable && (!this.getSelectedDestInternal() || this.getSelectedDestInternal().id != print_preview.Destination.GooglePromotedId.SAVE_AS_PDF); @@ -45,13 +42,13 @@ cr.define('print_preview.ticket_items', function() { /** @override */ getDefaultValueInternal: function() { - return true; + return !this.getDocumentInfoInternal().isScalingDisabled; }, /** @override */ getCapabilityNotAvailableValueInternal: function() { - return this.getSelectedDestInternal() && - this.getSelectedDestInternal().id == + return !this.getSelectedDestInternal() || + this.getSelectedDestInternal().id != print_preview.Destination.GooglePromotedId.SAVE_AS_PDF; } }; diff --git a/chrome/browser/resources/print_preview/previewarea/preview_area.js b/chrome/browser/resources/print_preview/previewarea/preview_area.js index 4ddb785..689c0b7 100644 --- a/chrome/browser/resources/print_preview/previewarea/preview_area.js +++ b/chrome/browser/resources/print_preview/previewarea/preview_area.js @@ -290,6 +290,10 @@ cr.define('print_preview', function() { print_preview.ticket_items.TicketItem.EventType.CHANGE, this.onTicketChange_.bind(this)); this.tracker.add( + this.printTicketStore_.fitToPage, + print_preview.ticket_items.TicketItem.EventType.CHANGE, + this.onTicketChange_.bind(this)); + this.tracker.add( this.printTicketStore_.selectionOnly, print_preview.ticket_items.TicketItem.EventType.CHANGE, this.onTicketChange_.bind(this)); diff --git a/chrome/browser/resources/print_preview/print_preview.js b/chrome/browser/resources/print_preview/print_preview.js index 071d279..927e18e 100644 --- a/chrome/browser/resources/print_preview/print_preview.js +++ b/chrome/browser/resources/print_preview/print_preview.js @@ -791,16 +791,13 @@ cr.define('print_preview', function() { }, /** - * Called when the native layer dispatches a DISABLE_SCALING event. Updates - * the print ticket. + * Called when the native layer dispatches a DISABLE_SCALING event. Resets + * fit-to-page selection and updates document info. * @private */ onDisableScaling_: function() { - // 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); + this.printTicketStore_.fitToPage.updateValue(null); + this.documentInfo_.updateIsScalingDisabled(true); }, /** diff --git a/chrome/test/data/webui/print_preview.js b/chrome/test/data/webui/print_preview.js index 836304d..df906a8 100644 --- a/chrome/test/data/webui/print_preview.js +++ b/chrome/test/data/webui/print_preview.js @@ -720,7 +720,7 @@ TEST_F('PrintPreviewWebUITest', 'TestPrinterChangeUpdatesPreview', function() { var previewGenerator = mock(print_preview.PreviewGenerator); printPreview.previewArea_.previewGenerator_ = previewGenerator.proxy(); - previewGenerator.expects(exactly(2)).requestPreview(); + previewGenerator.expects(exactly(3)).requestPreview(); var barDestination; var destinations = printPreview.destinationStore_.destinations; -- cgit v1.1