summaryrefslogtreecommitdiffstats
path: root/printing
diff options
context:
space:
mode:
authorthestig@chromium.org <thestig@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-04-19 20:57:03 +0000
committerthestig@chromium.org <thestig@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-04-19 20:57:03 +0000
commit2ed86fdf0eb70c6799027792e726ccdf3908e2d7 (patch)
tree7aa8fda1e506a875bce1cde12ac3141ab21acb2b /printing
parent1730395f996faaa2097b7afa2b23c1def9f94e18 (diff)
downloadchromium_src-2ed86fdf0eb70c6799027792e726ccdf3908e2d7.zip
chromium_src-2ed86fdf0eb70c6799027792e726ccdf3908e2d7.tar.gz
chromium_src-2ed86fdf0eb70c6799027792e726ccdf3908e2d7.tar.bz2
Print Preview: Implement dialog-less printing on Linux.
BUG=76124 TEST=Printed boarding pass using this code + print preview. Review URL: http://codereview.chromium.org/6835008 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@82153 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'printing')
-rw-r--r--printing/print_dialog_gtk_interface.h13
-rw-r--r--printing/print_settings_initializer_gtk.cc13
-rw-r--r--printing/printing_context_cairo.cc38
3 files changed, 35 insertions, 29 deletions
diff --git a/printing/print_dialog_gtk_interface.h b/printing/print_dialog_gtk_interface.h
index dab0c9c..c47f978 100644
--- a/printing/print_dialog_gtk_interface.h
+++ b/printing/print_dialog_gtk_interface.h
@@ -17,7 +17,18 @@ class Metafile;
// correct without exposing those requirements to printing/.
class PrintDialogGtkInterface {
public:
- // Shows the dialog and handles the response with |callback|.
+ // Tell the dialog to use the default print setting.
+ virtual void UseDefaultSettings() = 0;
+
+ // Update the dialog to use |settings| and |ranges|, where |settings| is a
+ // dictionary of settings with possible keys from
+ // printing/print_job_constants.h. Only used when printing without the system
+ // print dialog. E.g. for Print Preview. Returns false on error.
+ virtual bool UpdateSettings(const DictionaryValue& settings,
+ const PageRanges& ranges) = 0;
+
+ // Shows the dialog and handles the response with |callback|. Only used when
+ // printing with the native print dialog.
virtual void ShowDialog(
PrintingContextCairo::PrintSettingsCallback* callback) = 0;
diff --git a/printing/print_settings_initializer_gtk.cc b/printing/print_settings_initializer_gtk.cc
index a42561ba..9b8915c 100644
--- a/printing/print_settings_initializer_gtk.cc
+++ b/printing/print_settings_initializer_gtk.cc
@@ -33,9 +33,6 @@ void PrintSettingsInitializerGtk::InitPrintSettings(
print_settings->ranges = new_ranges;
print_settings->selection_only = print_selection_only;
- GtkPageOrientation orientation = gtk_print_settings_get_orientation(settings);
- print_settings->set_landscape(orientation == GTK_PAGE_ORIENTATION_LANDSCAPE);
-
gfx::Size physical_size_device_units;
gfx::Rect printable_area_device_units;
int dpi = gtk_print_settings_get_resolution(settings);
@@ -68,6 +65,16 @@ void PrintSettingsInitializerGtk::InitPrintSettings(
print_settings->SetPrinterPrintableArea(physical_size_device_units,
printable_area_device_units,
dpi);
+
+ // Note: With the normal GTK print dialog, when the user selects the landscape
+ // orientation, all that does is change the paper size. Which seems to be
+ // enough to render the right output and send it to the printer.
+ // The orientation value stays as portrait and does not actually affect
+ // printing.
+ // Thus this is only useful in print preview mode, where we manually set the
+ // orientation and change the paper size ourselves.
+ GtkPageOrientation orientation = gtk_print_settings_get_orientation(settings);
+ print_settings->SetOrientation(orientation == GTK_PAGE_ORIENTATION_LANDSCAPE);
}
const double PrintSettingsInitializerGtk::kTopMarginInInch = 0.25;
diff --git a/printing/printing_context_cairo.cc b/printing/printing_context_cairo.cc
index 6b24063..81d8696 100644
--- a/printing/printing_context_cairo.cc
+++ b/printing/printing_context_cairo.cc
@@ -8,11 +8,11 @@
#include "base/values.h"
#include "printing/metafile.h"
#include "printing/print_job_constants.h"
-#include "printing/print_settings_initializer_gtk.h"
#include "printing/units.h"
#if defined(OS_CHROMEOS)
#include <unicode/ulocdata.h>
+#include "printing/print_settings_initializer_gtk.h"
#else
#include <gtk/gtk.h>
#include <gtk/gtkprintunixdialog.h>
@@ -78,8 +78,6 @@ void PrintingContextCairo::AskUserForSettings(
#if defined(OS_CHROMEOS)
callback->Run(OK);
#else
- print_dialog_ = create_dialog_func_(this);
- print_dialog_->AddRefToDialog();
print_dialog_->ShowDialog(callback);
#endif // defined(OS_CHROMEOS)
}
@@ -128,20 +126,12 @@ PrintingContext::Result PrintingContextCairo::UseDefaultSettings() {
settings_.SetPrinterPrintableArea(physical_size_device_units,
printable_area_device_units,
dpi);
-#else // defined(OS_CHROMEOS)
- GtkWidget* dialog = gtk_print_unix_dialog_new(NULL, NULL);
- GtkPrintSettings* settings =
- gtk_print_unix_dialog_get_settings(GTK_PRINT_UNIX_DIALOG(dialog));
- GtkPageSetup* page_setup =
- gtk_print_unix_dialog_get_page_setup(GTK_PRINT_UNIX_DIALOG(dialog));
-
- PageRanges ranges_vector; // Nothing to initialize for default settings.
- PrintSettingsInitializerGtk::InitPrintSettings(
- settings, page_setup, ranges_vector, false, &settings_);
-
- g_object_unref(settings);
- // |page_setup| is owned by dialog, so it does not need to be unref'ed.
- gtk_widget_destroy(dialog);
+#else
+ if (!print_dialog_) {
+ print_dialog_ = create_dialog_func_(this);
+ print_dialog_->AddRefToDialog();
+ }
+ print_dialog_->UseDefaultSettings();
#endif // defined(OS_CHROMEOS)
return OK;
@@ -149,19 +139,17 @@ PrintingContext::Result PrintingContextCairo::UseDefaultSettings() {
PrintingContext::Result PrintingContextCairo::UpdatePrintSettings(
const DictionaryValue& job_settings, const PageRanges& ranges) {
+#if defined(OS_CHROMEOS)
+ NOTIMPLEMENTED();
+ return OK;
+#else
DCHECK(!in_print_job_);
- bool landscape;
- if (!job_settings.GetBoolean(kSettingLandscape, &landscape))
+ if (!print_dialog_->UpdateSettings(job_settings, ranges))
return OnError();
- settings_.SetOrientation(landscape);
- settings_.ranges = ranges;
-
- // TODO(kmadhusu): Update other print settings such as number of copies,
- // collate, duplex printing, etc.,
-
return OK;
+#endif
}
PrintingContext::Result PrintingContextCairo::InitWithSettings(