| OLD | NEW |
| 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "printing/printing_context_cairo.h" | 5 #include "printing/printing_context_cairo.h" |
| 6 | 6 |
| 7 #include <gtk/gtk.h> | 7 #include <gtk/gtk.h> |
| 8 #include <gtk/gtkprintunixdialog.h> | 8 #include <gtk/gtkprintunixdialog.h> |
| 9 #include <unicode/ulocdata.h> |
| 9 | 10 |
| 10 #include "base/logging.h" | 11 #include "base/logging.h" |
| 12 #include "printing/native_metafile.h" |
| 11 #include "printing/print_settings_initializer_gtk.h" | 13 #include "printing/print_settings_initializer_gtk.h" |
| 14 #include "printing/units.h" |
| 12 | 15 |
| 13 namespace printing { | 16 namespace printing { |
| 14 | 17 |
| 15 // static | 18 // static |
| 16 PrintingContext* PrintingContext::Create() { | 19 PrintingContext* PrintingContext::Create(const std::string& app_locale) { |
| 17 return static_cast<PrintingContext*>(new PrintingContextCairo); | 20 return static_cast<PrintingContext*>(new PrintingContextCairo(app_locale)); |
| 18 } | 21 } |
| 19 | 22 |
| 20 PrintingContextCairo::PrintingContextCairo() : PrintingContext() { | 23 PrintingContextCairo::PrintingContextCairo(const std::string& app_locale) |
| 24 : PrintingContext(app_locale) { |
| 21 } | 25 } |
| 22 | 26 |
| 23 PrintingContextCairo::~PrintingContextCairo() { | 27 PrintingContextCairo::~PrintingContextCairo() { |
| 24 ReleaseContext(); | 28 ReleaseContext(); |
| 25 } | 29 } |
| 26 | 30 |
| 27 void PrintingContextCairo::AskUserForSettings( | 31 void PrintingContextCairo::AskUserForSettings( |
| 28 gfx::NativeView parent_view, | 32 gfx::NativeView parent_view, |
| 29 int max_pages, | 33 int max_pages, |
| 30 bool has_selection, | 34 bool has_selection, |
| 31 PrintSettingsCallback* callback) { | 35 PrintSettingsCallback* callback) { |
| 32 NOTIMPLEMENTED(); | 36 NOTIMPLEMENTED(); |
| 33 callback->Run(OK); | 37 callback->Run(OK); |
| 34 } | 38 } |
| 35 | 39 |
| 36 PrintingContext::Result PrintingContextCairo::UseDefaultSettings() { | 40 PrintingContext::Result PrintingContextCairo::UseDefaultSettings() { |
| 37 DCHECK(!in_print_job_); | 41 DCHECK(!in_print_job_); |
| 38 | 42 |
| 39 ResetSettings(); | 43 ResetSettings(); |
| 44 #if defined(OS_CHROMEOS) |
| 45 // For Chrome OS use default values based on the app locale rather than rely |
| 46 // on GTK. Note that relying on the app locale does not work if the user uses |
| 47 // Chinese ChromeOS in the US. |
| 48 // TODO(sanjeevr): We need a better feedback loop between the cloud print |
| 49 // dialog and this code. |
| 50 int dpi = 300; |
| 51 gfx::Size physical_size_device_units; |
| 52 gfx::Rect printable_area_device_units; |
| 53 int32_t width = 0; |
| 54 int32_t height = 0; |
| 55 UErrorCode error = U_ZERO_ERROR; |
| 56 ulocdata_getPaperSize(app_locale_.c_str(), &height, &width, &error); |
| 57 if (error != U_ZERO_ERROR) { |
| 58 // If the call failed, assume a paper size of 8.5 x 11 inches. |
| 59 LOG(WARNING) << "ulocdata_getPaperSize failed, using 8.5 x 11, error: " |
| 60 << error; |
| 61 width = static_cast<int>(8.5 * dpi); |
| 62 height = static_cast<int>(11 * dpi); |
| 63 } else { |
| 64 // ulocdata_getPaperSize returns the width and height in mm. |
| 65 // Convert this to pixels based on the dpi. |
| 66 width = static_cast<int>(ConvertUnitDouble(width, 25.4, 1.0) * dpi); |
| 67 height = static_cast<int>(ConvertUnitDouble(height, 25.4, 1.0) * dpi); |
| 68 } |
| 40 | 69 |
| 70 physical_size_device_units.SetSize(width, height); |
| 71 printable_area_device_units.SetRect( |
| 72 static_cast<int>(NativeMetafile::kLeftMarginInInch * dpi), |
| 73 static_cast<int>(NativeMetafile::kTopMarginInInch * dpi), |
| 74 width - (NativeMetafile::kLeftMarginInInch + |
| 75 NativeMetafile::kRightMarginInInch) * dpi, |
| 76 height - (NativeMetafile::kTopMarginInInch + |
| 77 NativeMetafile::kBottomMarginInInch) * dpi); |
| 78 |
| 79 settings_.set_dpi(dpi); |
| 80 settings_.SetPrinterPrintableArea(physical_size_device_units, |
| 81 printable_area_device_units, |
| 82 dpi); |
| 83 #else // defined(OS_CHROMEOS) |
| 41 GtkWidget* dialog = gtk_print_unix_dialog_new(NULL, NULL); | 84 GtkWidget* dialog = gtk_print_unix_dialog_new(NULL, NULL); |
| 42 GtkPrintSettings* settings = | 85 GtkPrintSettings* settings = |
| 43 gtk_print_unix_dialog_get_settings(GTK_PRINT_UNIX_DIALOG(dialog)); | 86 gtk_print_unix_dialog_get_settings(GTK_PRINT_UNIX_DIALOG(dialog)); |
| 44 GtkPageSetup* page_setup = | 87 GtkPageSetup* page_setup = |
| 45 gtk_print_unix_dialog_get_page_setup(GTK_PRINT_UNIX_DIALOG(dialog)); | 88 gtk_print_unix_dialog_get_page_setup(GTK_PRINT_UNIX_DIALOG(dialog)); |
| 46 | 89 |
| 47 PageRanges ranges_vector; // Nothing to initialize for default settings. | 90 PageRanges ranges_vector; // Nothing to initialize for default settings. |
| 48 PrintSettingsInitializerGtk::InitPrintSettings( | 91 PrintSettingsInitializerGtk::InitPrintSettings( |
| 49 settings, page_setup, ranges_vector, false, &settings_); | 92 settings, page_setup, ranges_vector, false, &settings_); |
| 50 | 93 |
| 51 g_object_unref(settings); | 94 g_object_unref(settings); |
| 52 // |page_setup| is owned by dialog, so it does not need to be unref'ed. | 95 // |page_setup| is owned by dialog, so it does not need to be unref'ed. |
| 53 gtk_widget_destroy(dialog); | 96 gtk_widget_destroy(dialog); |
| 97 #endif // defined(OS_CHROMEOS) |
| 54 | 98 |
| 55 return OK; | 99 return OK; |
| 56 } | 100 } |
| 57 | 101 |
| 58 PrintingContext::Result PrintingContextCairo::InitWithSettings( | 102 PrintingContext::Result PrintingContextCairo::InitWithSettings( |
| 59 const PrintSettings& settings) { | 103 const PrintSettings& settings) { |
| 60 DCHECK(!in_print_job_); | 104 DCHECK(!in_print_job_); |
| 61 | 105 |
| 62 settings_ = settings; | 106 settings_ = settings; |
| 63 | 107 |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 119 | 163 |
| 120 void PrintingContextCairo::ReleaseContext() { | 164 void PrintingContextCairo::ReleaseContext() { |
| 121 // Nothing to do yet. | 165 // Nothing to do yet. |
| 122 } | 166 } |
| 123 | 167 |
| 124 gfx::NativeDrawingContext PrintingContextCairo::context() const { | 168 gfx::NativeDrawingContext PrintingContextCairo::context() const { |
| 125 return NULL; | 169 return NULL; |
| 126 } | 170 } |
| 127 | 171 |
| 128 } // namespace printing | 172 } // namespace printing |
| OLD | NEW |