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> | |
10 #include <unicode/uset.h> | |
jungshik at Google
2010/12/03 19:34:55
nit: Do you need to include uset.h? I guess not.
| |
9 | 11 |
10 #include "base/logging.h" | 12 #include "base/logging.h" |
13 #include "printing/native_metafile.h" | |
11 #include "printing/print_settings_initializer_gtk.h" | 14 #include "printing/print_settings_initializer_gtk.h" |
15 #include "printing/units.h" | |
12 | 16 |
13 namespace printing { | 17 namespace printing { |
14 | 18 |
15 // static | 19 // static |
16 PrintingContext* PrintingContext::Create() { | 20 PrintingContext* PrintingContext::Create(const std::string& app_locale) { |
17 return static_cast<PrintingContext*>(new PrintingContextCairo); | 21 return static_cast<PrintingContext*>(new PrintingContextCairo(app_locale)); |
18 } | 22 } |
19 | 23 |
20 PrintingContextCairo::PrintingContextCairo() : PrintingContext() { | 24 PrintingContextCairo::PrintingContextCairo(const std::string& app_locale) |
25 : PrintingContext(app_locale) { | |
21 } | 26 } |
22 | 27 |
23 PrintingContextCairo::~PrintingContextCairo() { | 28 PrintingContextCairo::~PrintingContextCairo() { |
24 ReleaseContext(); | 29 ReleaseContext(); |
25 } | 30 } |
26 | 31 |
27 void PrintingContextCairo::AskUserForSettings( | 32 void PrintingContextCairo::AskUserForSettings( |
28 gfx::NativeView parent_view, | 33 gfx::NativeView parent_view, |
29 int max_pages, | 34 int max_pages, |
30 bool has_selection, | 35 bool has_selection, |
31 PrintSettingsCallback* callback) { | 36 PrintSettingsCallback* callback) { |
32 NOTIMPLEMENTED(); | 37 NOTIMPLEMENTED(); |
33 callback->Run(OK); | 38 callback->Run(OK); |
34 } | 39 } |
35 | 40 |
36 PrintingContext::Result PrintingContextCairo::UseDefaultSettings() { | 41 PrintingContext::Result PrintingContextCairo::UseDefaultSettings() { |
37 DCHECK(!in_print_job_); | 42 DCHECK(!in_print_job_); |
38 | 43 |
39 ResetSettings(); | 44 ResetSettings(); |
45 #if defined(OS_CHROMEOS) | |
46 // For Chrome OS use default values based on the app locale rather than rely | |
47 // on GTK. | |
48 // TODO(sanjeevr): We need a better feedback loop between the cloud print | |
49 // dialog and this code. | |
jungshik at Google
2010/12/03 19:34:55
Can you also mention that relying on app_locale do
| |
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 |