Skip to content

Commit

Permalink
PrintPreview: [MAC] Set duplex binding settings in print ticket.
Browse files Browse the repository at this point in the history
BUG=none
TEST=Set duplex binding settings in print preview tab and observe the printed data.

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

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@82335 0039d316-1c4b-4281-b951-d872f2087c98
  • Loading branch information
kmadhusu@chromium.org committed Apr 20, 2011
1 parent 7c158cc commit 826e63a
Show file tree
Hide file tree
Showing 6 changed files with 46 additions and 11 deletions.
18 changes: 17 additions & 1 deletion chrome/browser/resources/print_preview.js
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,22 @@ function isTwoSided() {
return $('two-sided').checked;
}

/**
* Gets the duplex mode for printing.
* @return {number} duplex mode.
*/
function getDuplexMode() {
// Constants values matches printing::PrintingContext::DuplexMode enum.
const SIMPLEX = 0;
const LONG_EDGE = 1;
const SHORT_EDGE = 2;

if (!isTwoSided())
return SIMPLEX;

return $('long-edge').checked ? LONG_EDGE : SHORT_EDGE;
}

/**
* Creates a JSON string based on the values in the printer settings.
*
Expand All @@ -261,7 +277,7 @@ function getSettingsJSON() {
return JSON.stringify({'printerName': printerName,
'pageRange': getSelectedPageRanges(),
'printAll': printAll,
'twoSided': isTwoSided(),
'duplex': getDuplexMode(),
'copies': getCopies(),
'collate': isCollated(),
'landscape': isLandscape(),
Expand Down
6 changes: 3 additions & 3 deletions printing/print_job_constants.cc
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ const char kSettingColor[] = "color";
// Number of copies.
const char kSettingCopies[] = "copies";

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

// Page orientation: true for landscape, false for portrait.
const char kSettingLandscape[] = "landscape";

Expand All @@ -24,7 +27,4 @@ const char kSettingPrinterName[] = "printerName";
// Print to PDF option: true if selected, false if not.
const char kSettingPrintToPDF[] = "printToPDF";

// Print job duplex setting.
const char kSettingTwoSided[] = "twoSided";

} // namespace printing
2 changes: 1 addition & 1 deletion printing/print_job_constants.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@ namespace printing {
extern const char kSettingCollate[];
extern const char kSettingColor[];
extern const char kSettingCopies[];
extern const char kSettingDuplexMode[];
extern const char kSettingLandscape[];
extern const char kSettingPrinterName[];
extern const char kSettingPrintToPDF[];
extern const char kSettingTwoSided[];

} // namespace printing

Expand Down
7 changes: 7 additions & 0 deletions printing/printing_context.h
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,13 @@ class PrintingContext {
}

protected:
// Print job duplex mode values.
enum DuplexMode {
SIMPLEX,
LONG_EDGE,
SHORT_EDGE,
};

explicit PrintingContext(const std::string& app_locale);

// Reinitializes the settings for object reuse.
Expand Down
2 changes: 1 addition & 1 deletion printing/printing_context_mac.h
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ class PrintingContextMac : public PrintingContext {

// Sets duplex mode in PMPrintSettings.
// Returns true if duplex mode is set.
bool SetDuplexModeIsTwoSided(bool two_sided);
bool SetDuplexModeInPrintSettings(DuplexMode mode);

// Sets output color mode in PMPrintSettings.
// Returns true if color mode is set.
Expand Down
22 changes: 17 additions & 5 deletions printing/printing_context_mac.mm
Original file line number Diff line number Diff line change
Expand Up @@ -96,13 +96,13 @@
std::string printer_name;
int copies;
bool collate;
bool two_sided;
int duplex_mode;
bool color;
if (!job_settings.GetBoolean(kSettingLandscape, &landscape) ||
!job_settings.GetString(kSettingPrinterName, &printer_name) ||
!job_settings.GetInteger(kSettingCopies, &copies) ||
!job_settings.GetBoolean(kSettingCollate, &collate) ||
!job_settings.GetBoolean(kSettingTwoSided, &two_sided) ||
!job_settings.GetInteger(kSettingDuplexMode, &duplex_mode) ||
!job_settings.GetBoolean(kSettingColor, &color)) {
return OnError();
}
Expand All @@ -119,7 +119,7 @@
if (!SetOrientationIsLandscape(landscape))
return OnError();

if (!SetDuplexModeIsTwoSided(two_sided))
if (!SetDuplexModeInPrintSettings(static_cast<DuplexMode>(duplex_mode)))
return OnError();

if (!SetOutputIsColor(color))
Expand Down Expand Up @@ -186,8 +186,20 @@
return true;
}

bool PrintingContextMac::SetDuplexModeIsTwoSided(bool two_sided) {
PMDuplexMode duplexSetting = two_sided ? kPMDuplexNoTumble : kPMDuplexNone;
bool PrintingContextMac::SetDuplexModeInPrintSettings(DuplexMode mode) {
PMDuplexMode duplexSetting;
switch (mode) {
case LONG_EDGE:
duplexSetting = kPMDuplexNoTumble;
break;
case SHORT_EDGE:
duplexSetting = kPMDuplexTumble;
break;
default:
duplexSetting = kPMDuplexNone;
break;
}

PMPrintSettings pmPrintSettings =
static_cast<PMPrintSettings>([print_info_.get() PMPrintSettings]);
return PMSetDuplex(pmPrintSettings, duplexSetting) == noErr;
Expand Down

0 comments on commit 826e63a

Please sign in to comment.