Skip to content

Commit

Permalink
Support NumCopies print preset
Browse files Browse the repository at this point in the history
Chrome side javascript changes to support NumCopies print preset
option. Copies in print preview dialog should be set to value set for
NumCopies in pdf source document.

BUG=169120

Review URL: https://codereview.chromium.org/407733002

Cr-Commit-Position: refs/heads/master@{#307454}
  • Loading branch information
n.bansal authored and Commit bot committed Dec 9, 2014
1 parent b58903f commit 2604a97
Show file tree
Hide file tree
Showing 6 changed files with 66 additions and 21 deletions.
21 changes: 12 additions & 9 deletions chrome/browser/resources/print_preview/native_layer.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,6 @@ cr.define('print_preview', function() {
this.onDidGetPreviewPageCount_.bind(this);
global.onDidPreviewPage = this.onDidPreviewPage_.bind(this);
global.updatePrintPreview = this.onUpdatePrintPreview_.bind(this);
global.printScalingDisabledForSourcePDF =
this.onPrintScalingDisabledForSourcePDF_.bind(this);
global.onDidGetAccessToken = this.onDidGetAccessToken_.bind(this);
global.autoCancelForTesting = this.autoCancelForTesting_.bind(this);
global.onPrivetPrinterChanged = this.onPrivetPrinterChanged_.bind(this);
Expand All @@ -61,6 +59,8 @@ cr.define('print_preview', function() {
global.onPrivetPrintFailed = this.onPrivetPrintFailed_.bind(this);
global.onEnableManipulateSettingsForTest =
this.onEnableManipulateSettingsForTest_.bind(this);
global.printPresetOptionsFromDocument =
this.onPrintPresetOptionsFromDocument_.bind(this);
};

/**
Expand Down Expand Up @@ -95,6 +95,7 @@ cr.define('print_preview', function() {
PRIVET_CAPABILITIES_SET:
'print_preview.NativeLayer.PRIVET_CAPABILITIES_SET',
PRIVET_PRINT_FAILED: 'print_preview.NativeLayer.PRIVET_PRINT_FAILED',
PRINT_PRESET_OPTIONS: 'print_preview.NativeLayer.PRINT_PRESET_OPTIONS',
};

/**
Expand Down Expand Up @@ -652,15 +653,17 @@ cr.define('print_preview', function() {
},

/**
* Updates the fit to page option state based on the print scaling option of
* source pdf. PDF's have an option to enable/disable print scaling. When we
* find out that the print scaling option is disabled for the source pdf, we
* uncheck the fitToPage_ to page checkbox. This function is called from C++
* code.
* Updates print preset options from source PDF document.
* Called from PrintPreviewUI::OnSetOptionsFromDocument().
* @param {{disableScaling: boolean, copies: number}} options Specifies
* printing options according to source document presets.
* @private
*/
onPrintScalingDisabledForSourcePDF_: function() {
cr.dispatchSimpleEvent(this, NativeLayer.EventType.DISABLE_SCALING);
onPrintPresetOptionsFromDocument_: function(options) {
var printPresetOptionsEvent = new Event(
NativeLayer.EventType.PRINT_PRESET_OPTIONS);
printPresetOptionsEvent.optionsFromDocument = options;
this.dispatchEvent(printPresetOptionsEvent);
},

/**
Expand Down
22 changes: 15 additions & 7 deletions chrome/browser/resources/print_preview/print_preview.js
Original file line number Diff line number Diff line change
Expand Up @@ -347,8 +347,8 @@ cr.define('print_preview', function() {
this.onSettingsInvalid_.bind(this));
this.tracker.add(
this.nativeLayer_,
print_preview.NativeLayer.EventType.DISABLE_SCALING,
this.onDisableScaling_.bind(this));
print_preview.NativeLayer.EventType.PRINT_PRESET_OPTIONS,
this.onPrintPresetOptionsFromDocument_.bind(this));
this.tracker.add(
this.nativeLayer_,
print_preview.NativeLayer.EventType.PRIVET_PRINT_FAILED,
Expand Down Expand Up @@ -979,13 +979,21 @@ cr.define('print_preview', function() {
},

/**
* Called when the native layer dispatches a DISABLE_SCALING event. Resets
* fit-to-page selection and updates document info.
* Updates printing options according to source document presets.
* @param {Event} event Contains options from source document.
* @private
*/
onDisableScaling_: function() {
this.printTicketStore_.fitToPage.updateValue(null);
this.documentInfo_.updateIsScalingDisabled(true);
onPrintPresetOptionsFromDocument_: function(event) {
if (event.optionsFromDocument.disableScaling) {
this.printTicketStore_.fitToPage.updateValue(null);
this.documentInfo_.updateIsScalingDisabled(true);
}

if (event.optionsFromDocument.copies > 0 &&
this.printTicketStore_.copies.isCapabilityAvailable()) {
this.printTicketStore_.copies.updateValue(
event.optionsFromDocument.copies);
}
},

/**
Expand Down
8 changes: 5 additions & 3 deletions chrome/browser/ui/webui/print_preview/print_preview_ui.cc
Original file line number Diff line number Diff line change
Expand Up @@ -628,9 +628,11 @@ void PrintPreviewUI::OnReloadPrintersList() {

void PrintPreviewUI::OnSetOptionsFromDocument(
const PrintHostMsg_SetOptionsFromDocument_Params& params) {
// Notify WebUI that print scaling is disabled
if (params.is_scaling_disabled)
web_ui()->CallJavascriptFunction("printScalingDisabledForSourcePDF");
base::DictionaryValue options;
options.SetBoolean(printing::kSettingDisableScaling,
params.is_scaling_disabled);
options.SetInteger(printing::kSettingCopies, params.copies);
web_ui()->CallJavascriptFunction("printPresetOptionsFromDocument", options);
}

// static
Expand Down
32 changes: 30 additions & 2 deletions chrome/test/data/webui/print_preview.js
Original file line number Diff line number Diff line change
Expand Up @@ -474,8 +474,10 @@ TEST_F('PrintPreviewWebUITest', 'PrintScalingDisabledForPlugin', function() {
this.setCapabilities(getCddTemplate("FooDevice"));

// Indicate that the PDF does not support scaling by default.
cr.dispatchSimpleEvent(
this.nativeLayer_, print_preview.NativeLayer.EventType.DISABLE_SCALING);
var printPresetOptionsEvent = new Event(
print_preview.NativeLayer.EventType.PRINT_PRESET_OPTIONS);
printPresetOptionsEvent.optionsFromDocument = {disableScaling: true};
this.nativeLayer_.dispatchEvent(printPresetOptionsEvent);

var otherOptions = $('other-options-settings');
checkSectionVisible(otherOptions, true);
Expand All @@ -487,6 +489,32 @@ TEST_F('PrintPreviewWebUITest', 'PrintScalingDisabledForPlugin', function() {
this.waitForAnimationToEnd('other-options-collapsible');
});

// When the number of copies print preset is set for source 'PDF', we update
// copies value if capability is supported by printer.
TEST_F('PrintPreviewWebUITest', 'CheckNumCopiesPrintPreset', function() {
this.initialSettings_.isDocumentModifiable_ = false;
this.setInitialSettings();
this.setLocalDestinations();
this.setCapabilities(getCddTemplate("FooDevice"));

// Indicate that the number of copies print preset is set for source PDF.
var printPresetOptions = {
disableScaling: true,
copies: 2
};
var printPresetOptionsEvent = new Event(
print_preview.NativeLayer.EventType.PRINT_PRESET_OPTIONS);
printPresetOptionsEvent.optionsFromDocument = printPresetOptions;
this.nativeLayer_.dispatchEvent(printPresetOptionsEvent);

checkSectionVisible($('copies-settings'), true);
expectEquals(
printPresetOptions.copies,
parseInt($('copies-settings').querySelector('.copies').value));

this.waitForAnimationToEnd('other-options-collapsible');
});

// Make sure that custom margins controls are properly set up.
TEST_F('PrintPreviewWebUITest', 'CustomMarginsControlsCheck', function() {
this.setInitialSettings();
Expand Down
3 changes: 3 additions & 0 deletions printing/print_job_constants.cc
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,9 @@ const char kSettingCopies[] = "copies";
// Device name: Unique printer identifier.
const char kSettingDeviceName[] = "deviceName";

// Option to disable scaling. True if scaling is disabled else false.
const char kSettingDisableScaling[] = "disableScaling";

// Print job duplex mode.
const char kSettingDuplexMode[] = "duplex";

Expand Down
1 change: 1 addition & 0 deletions printing/print_job_constants.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ PRINTING_EXPORT extern const char kSettingContentHeight[];
PRINTING_EXPORT extern const char kSettingContentWidth[];
PRINTING_EXPORT extern const char kSettingCopies[];
PRINTING_EXPORT extern const char kSettingDeviceName[];
PRINTING_EXPORT extern const char kSettingDisableScaling[];
PRINTING_EXPORT extern const char kSettingDuplexMode[];
PRINTING_EXPORT extern const char kSettingFitToPageEnabled[];
PRINTING_EXPORT extern const char kSettingGenerateDraftData[];
Expand Down

0 comments on commit 2604a97

Please sign in to comment.