Skip to content

Commit

Permalink
Revert 100233 - PrintPreview: Added code to identify the printer defa…
Browse files Browse the repository at this point in the history
…ult duplex value.

Added code to identify the printer default duplex value. If we are
unable to get the default value, hide the two sided option in the preview tab.

BUG=89204
TEST=Please refer to bug description.

Review URL: http://codereview.chromium.org/7817013

TBR=kmadhusu@chromium.org
Review URL: http://codereview.chromium.org/7828106

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@100234 0039d316-1c4b-4281-b951-d872f2087c98
  • Loading branch information
kmadhusu@chromium.org committed Sep 8, 2011
1 parent 7e86d8b commit d33ed29
Show file tree
Hide file tree
Showing 8 changed files with 27 additions and 141 deletions.
29 changes: 12 additions & 17 deletions chrome/browser/printing/print_dialog_gtk.cc
Original file line number Diff line number Diff line change
Expand Up @@ -200,24 +200,19 @@ bool PrintDialogGtk::UpdateSettings(const DictionaryValue& settings,
}
gtk_print_settings_set(gtk_settings_, kCUPSColorModel, color_mode);

if (duplex_mode != printing::UNKNOWN_DUPLEX_MODE) {
const char* cups_duplex_mode;
switch (duplex_mode) {
case printing::LONG_EDGE:
cups_duplex_mode = kDuplexNoTumble;
break;
case printing::SHORT_EDGE:
cups_duplex_mode = kDuplexTumble;
break;
case printing::SIMPLEX:
cups_duplex_mode = kDuplexNone;
break;
default: // UNKNOWN_DUPLEX_MODE
NOTREACHED();
break;
}
gtk_print_settings_set(gtk_settings_, kCUPSDuplex, cups_duplex_mode);
const char* cups_duplex_mode;
switch (duplex_mode) {
case printing::LONG_EDGE:
cups_duplex_mode = kDuplexNoTumble;
break;
case printing::SHORT_EDGE:
cups_duplex_mode = kDuplexTumble;
break;
default:
cups_duplex_mode = kDuplexNone;
break;
}
gtk_print_settings_set(gtk_settings_, kCUPSDuplex, cups_duplex_mode);
}

gtk_print_settings_set_orientation(
Expand Down
44 changes: 8 additions & 36 deletions chrome/browser/resources/print_preview/copies_settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,6 @@ cr.define('print_preview', function() {
this.collateCheckbox_ = $('collate');
this.hint_ = $('copies-hint');
this.twoSidedCheckbox_ = $('two-sided');
this.twoSidedOption_ = $('two-sided-div');

// Constant values matches printing::DuplexMode enum. Not using const
// keyword because it is not allowed by JS strict mode.
this.SIMPLEX = 0;
this.LONG_EDGE = 1;
this.UNKNOWN_DUPLEX_MODE = -1;
}

cr.addSingletonGetter(CopiesSettings);
Expand Down Expand Up @@ -63,16 +56,15 @@ cr.define('print_preview', function() {
},

/**
* Gets the duplex mode information for printing.
* Gets the duplex mode for printing.
* @return {number} duplex mode.
*/
get duplexMode() {
if (this.twoSidedOption_.hidden)
return this.UNKNOWN_DUPLEX_MODE;
else if (this.twoSidedCheckbox_.checked)
return this.LONG_EDGE;
else
return this.SIMPLEX;
get duplexMode() {
// Constant values matches printing::DuplexMode enum. Not using const
// keyword because it is not allowed by JS strict mode.
var SIMPLEX = 0;
var LONG_EDGE = 1;
return !this.twoSidedCheckbox_.checked ? SIMPLEX : LONG_EDGE;
},

/**
Expand Down Expand Up @@ -166,8 +158,7 @@ cr.define('print_preview', function() {
fadeInElement(this.copiesOption_);
$('hr-before-copies').classList.add('invisible');
}
this.updateTwoSidedOption_(
e.printerCapabilities.printerDefaultDuplexValue);
this.twoSidedCheckbox_.checked = e.printerCapabilities.setDuplexAsDefault;
},

/**
Expand Down Expand Up @@ -199,25 +190,6 @@ cr.define('print_preview', function() {
this.collateOption_.hidden);
},

/*
* Takes care of showing/hiding the two sided option and also updates the
* default state of the checkbox.
* @param {number} defaultDuplexValue Specifies the default duplex value.
* @private
*/
updateTwoSidedOption_: function(defaultDuplexValue) {
// On Windows, some printers don't specify their duplex values in the
// printer schema. If the printer duplex value is UNKNOWN_DUPLEX_MODE,
// hide the two sided option in preview tab UI.
// Ref bug: http://crbug.com/89204
this.twoSidedOption_.hidden =
(defaultDuplexValue == this.UNKNOWN_DUPLEX_MODE);
this.twoSidedOption_.setAttribute('aria-hidden',
this.twoSidedOption_.hidden);
if (!this.twoSidedOption_.hidden)
this.twoSidedCheckbox_.checked = !!defaultDuplexValue;
},

/**
* Updates the state of the increment/decrement buttons based on the current
* |textfield_| value.
Expand Down
1 change: 0 additions & 1 deletion chrome/browser/resources/print_preview/print_preview.js
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,6 @@ function updateControlsWithSelectedPrinterCapabilities() {
'setColorAsDefault': true,
'setDuplexAsDefault': false,
'printerColorModelForColor': colorSettings.COLOR,
'printerDefaultDuplexValue': copiesSettings.UNKNOWN_DUPLEX_MODE,
'disableCopiesOption': true});
} else {
// This message will call back to 'updateWithPrinterCapabilities'
Expand Down
31 changes: 5 additions & 26 deletions chrome/browser/ui/webui/print_preview_handler.cc
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,6 @@ const char kDisableColorOption[] = "disableColorOption";
const char kSetColorAsDefault[] = "setColorAsDefault";
const char kSetDuplexAsDefault[] = "setDuplexAsDefault";
const char kPrinterColorModelForColor[] = "printerColorModelForColor";
const char kPrinterDefaultDuplexValue[] = "printerDefaultDuplexValue";

#if defined(USE_CUPS)
const char kColorDevice[] = "ColorDevice";
Expand Down Expand Up @@ -282,7 +281,6 @@ class PrintSystemTaskProxy
bool supports_color = true;
bool set_duplex_as_default = false;
int printer_color_space = printing::GRAY;
int default_duplex_setting_value = printing::UNKNOWN_DUPLEX_MODE;
if (!print_backend_->GetPrinterCapsAndDefaults(printer_name,
&printer_info)) {
return;
Expand All @@ -308,24 +306,16 @@ class PrintSystemTaskProxy
if (attr && attr->value)
supports_color = ppd->color_device;

ppd_choice_t* duplex_choice = ppdFindMarkedChoice(ppd, kDuplex);
if (duplex_choice == NULL) {
ppd_choice_t* ch = ppdFindMarkedChoice(ppd, kDuplex);
if (ch == NULL) {
ppd_option_t* option = ppdFindOption(ppd, kDuplex);
if (option != NULL)
duplex_choice = ppdFindChoice(option, option->defchoice);
ch = ppdFindChoice(option, option->defchoice);
}

if (duplex_choice != NULL &&
strcmp(duplex_choice->choice, kDuplexNone) != 0)
if (ch != NULL && strcmp(ch->choice, kDuplexNone) != 0)
set_duplex_as_default = true;

if (duplex_choice != NULL) {
if (strcmp(duplex_choice->choice, kDuplexNone) != 0)
default_duplex_setting_value = printing::LONG_EDGE;
else
default_duplex_setting_value = printing::SIMPLEX;
}

if (supports_color) {
// Identify the color space (COLOR/CMYK) for this printer.
ppd_option_t* color_model = ppdFindOption(ppd, kColorModel);
Expand All @@ -336,6 +326,7 @@ class PrintSystemTaskProxy
printer_color_space = printing::CMYK;
}
}

ppdClose(ppd);
}
file_util::Delete(ppd_file_path, false);
Expand All @@ -354,16 +345,6 @@ class PrintSystemTaskProxy
std::string::npos) &&
(printer_info.printer_defaults.find(kPskTwoSided) !=
std::string::npos);

if (printer_info.printer_defaults.find(kPskDuplexFeature) !=
std::string::npos) {
if (printer_info.printer_defaults.find(kPskTwoSided) !=
std::string::npos) {
default_duplex_setting_value = printing::LONG_EDGE;
} else {
default_duplex_setting_value = printing::SIMPLEX;
}
}
#else
NOTIMPLEMENTED();
#endif
Expand All @@ -378,8 +359,6 @@ class PrintSystemTaskProxy
}
settings_info.SetBoolean(kSetDuplexAsDefault, set_duplex_as_default);
settings_info.SetInteger(kPrinterColorModelForColor, printer_color_space);
settings_info.SetInteger(kPrinterDefaultDuplexValue,
default_duplex_setting_value);
BrowserThread::PostTask(
BrowserThread::UI, FROM_HERE,
NewRunnableMethod(this,
Expand Down
54 changes: 0 additions & 54 deletions chrome/test/data/webui/print_preview.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,6 @@ PrintPreviewWebUITest.prototype = {
disableColorOption: true,
setColorAsDefault: true,
disableCopiesOption: true,
printerDefaultDuplexValue: copiesSettings.SIMPLEX,
});
}));
var savedArgs = new SaveMockArguments();
Expand Down Expand Up @@ -299,7 +298,6 @@ TEST_F('PrintPreviewWebUITest', 'TestSectionsDisabled', function() {
setColorAsDefault: true,
disableCopiesOption: true,
disableLandscapeOption: true,
printerDefaultDuplexValue: copiesSettings.SIMPLEX,
});
}));

Expand All @@ -319,7 +317,6 @@ TEST_F('PrintPreviewWebUITest', 'TestColorSettings', function() {
setColorAsDefault: true,
disableCopiesOption: false,
disableLandscapeOption: false,
printerDefaultDuplexValue: copiesSettings.SIMPLEX,
});
}));

Expand All @@ -334,7 +331,6 @@ TEST_F('PrintPreviewWebUITest', 'TestColorSettings', function() {
setColorAsDefault: false,
disableCopiesOption: false,
disableLandscapeOption: false,
printerDefaultDuplexValue: copiesSettings.SIMPLEX,
});
}));

Expand All @@ -343,56 +339,6 @@ TEST_F('PrintPreviewWebUITest', 'TestColorSettings', function() {
expectTrue(colorSettings.bwRadioButton.checked);
});

// Test to verify that duplex settings are set according to the printer
// capabilities.
TEST_F('PrintPreviewWebUITest', 'TestDuplexSettings', function() {
this.mockHandler.expects(once()).getPrinterCapabilities('FooDevice').
will(callFunction(function() {
updateWithPrinterCapabilities({
disableColorOption: false,
setColorAsDefault: false,
disableCopiesOption: false,
disableLandscapeOption: false,
printerDefaultDuplexValue: copiesSettings.SIMPLEX,
});
}));
updateControlsWithSelectedPrinterCapabilities();
expectEquals(copiesSettings.duplexMode, copiesSettings.SIMPLEX);
expectEquals(copiesSettings.twoSidedOption_.hidden, false);

// If the printer default duplex value is UNKNOWN_DUPLEX_MODE, hide the
// two sided option.
this.mockHandler.expects(once()).getPrinterCapabilities('FooDevice').
will(callFunction(function() {
updateWithPrinterCapabilities({
disableColorOption: false,
setColorAsDefault: false,
disableCopiesOption: false,
disableLandscapeOption: false,
printerDefaultDuplexValue: copiesSettings.UNKNOWN_DUPLEX_MODE,
});
}));
updateControlsWithSelectedPrinterCapabilities();
expectEquals(copiesSettings.duplexMode, copiesSettings.UNKNOWN_DUPLEX_MODE);
expectEquals(copiesSettings.twoSidedOption_.hidden, true);

this.mockHandler.expects(once()).getPrinterCapabilities('FooDevice').
will(callFunction(function() {
updateWithPrinterCapabilities({
disableColorOption: false,
setColorAsDefault: false,
disableCopiesOption: false,
disableLandscapeOption: false,
printerDefaultDuplexValue: copiesSettings.SIMPLEX,
});
}));
updateControlsWithSelectedPrinterCapabilities();
expectEquals(copiesSettings.twoSidedOption_.hidden, false);
expectEquals(copiesSettings.duplexMode, copiesSettings.SIMPLEX);
copiesSettings.twoSidedCheckbox.checked = true;
expectEquals(copiesSettings.duplexMode, copiesSettings.LONG_EDGE);
});

// Test that changing the selected printer updates the preview.
TEST_F('PrintPreviewWebUITest', 'TestPrinterChangeUpdatesPreview', function() {
var savedArgs = new SaveMockArguments();
Expand Down
1 change: 0 additions & 1 deletion printing/print_job_constants.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@ PRINTING_EXPORT extern const int COMPLETE_PREVIEW_DOCUMENT_INDEX;

// Print job duplex mode values.
enum DuplexMode {
UNKNOWN_DUPLEX_MODE = -1,
SIMPLEX,
LONG_EDGE,
SHORT_EDGE,
Expand Down
4 changes: 1 addition & 3 deletions printing/printing_context_mac.mm
Original file line number Diff line number Diff line change
Expand Up @@ -236,11 +236,9 @@
case SHORT_EDGE:
duplexSetting = kPMDuplexTumble;
break;
case SIMPLEX:
default:
duplexSetting = kPMDuplexNone;
break;
default: // UNKNOWN_DUPLEX_MODE
return true;
}

PMPrintSettings pmPrintSettings =
Expand Down
4 changes: 1 addition & 3 deletions printing/printing_context_win.cc
Original file line number Diff line number Diff line change
Expand Up @@ -383,11 +383,9 @@ PrintingContext::Result PrintingContextWin::UpdatePrinterSettings(
case SHORT_EDGE:
dev_mode->dmDuplex = DMDUP_HORIZONTAL;
break;
case SIMPLEX:
default: // simplex
dev_mode->dmDuplex = DMDUP_SIMPLEX;
break;
default: // UNKNOWN_DUPLEX_MODE
break;
}
dev_mode->dmOrientation = landscape ? DMORIENT_LANDSCAPE : DMORIENT_PORTRAIT;

Expand Down

0 comments on commit d33ed29

Please sign in to comment.