[go: nahoru, domu]

PrintPreview: [MAC] Set duplex binding settings in print ticket.

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
diff --git a/chrome/browser/resources/print_preview.js b/chrome/browser/resources/print_preview.js
index 521775d..141f067 100644
--- a/chrome/browser/resources/print_preview.js
+++ b/chrome/browser/resources/print_preview.js
@@ -245,6 +245,22 @@
 }
 
 /**
+ * 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.
  *
  * @return {string} JSON string with print job settings.
@@ -261,7 +277,7 @@
   return JSON.stringify({'printerName': printerName,
                          'pageRange': getSelectedPageRanges(),
                          'printAll': printAll,
-                         'twoSided': isTwoSided(),
+                         'duplex': getDuplexMode(),
                          'copies': getCopies(),
                          'collate': isCollated(),
                          'landscape': isLandscape(),
diff --git a/printing/print_job_constants.cc b/printing/print_job_constants.cc
index bbb8d2b..21a0199 100644
--- a/printing/print_job_constants.cc
+++ b/printing/print_job_constants.cc
@@ -15,6 +15,9 @@
 // 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";
 
@@ -24,7 +27,4 @@
 // Print to PDF option: true if selected, false if not.
 const char kSettingPrintToPDF[] = "printToPDF";
 
-// Print job duplex setting.
-const char kSettingTwoSided[] = "twoSided";
-
 }  // namespace printing
diff --git a/printing/print_job_constants.h b/printing/print_job_constants.h
index 30102eb..ec8ca8c 100644
--- a/printing/print_job_constants.h
+++ b/printing/print_job_constants.h
@@ -10,10 +10,10 @@
 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
 
diff --git a/printing/printing_context.h b/printing/printing_context.h
index c4e2094..77ac84468 100644
--- a/printing/printing_context.h
+++ b/printing/printing_context.h
@@ -99,6 +99,13 @@
   }
 
  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.
diff --git a/printing/printing_context_mac.h b/printing/printing_context_mac.h
index 90be22bc..3005602 100644
--- a/printing/printing_context_mac.h
+++ b/printing/printing_context_mac.h
@@ -65,7 +65,7 @@
 
   // 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.
diff --git a/printing/printing_context_mac.mm b/printing/printing_context_mac.mm
index 3bb383d..755069a 100644
--- a/printing/printing_context_mac.mm
+++ b/printing/printing_context_mac.mm
@@ -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();
   }
@@ -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))
@@ -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;