OLD | NEW |
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 "base/logging.h" |
| 8 #include "printing/units.h" |
| 9 |
| 10 #if defined(OS_CHROMEOS) |
| 11 #include <unicode/ulocdata.h> |
| 12 #include <printing/native_metafile.h> |
| 13 #else |
7 #include <gtk/gtk.h> | 14 #include <gtk/gtk.h> |
8 #include <gtk/gtkprintunixdialog.h> | 15 #include <gtk/gtkprintunixdialog.h> |
9 #include <unicode/ulocdata.h> | |
10 | 16 |
11 #include "base/logging.h" | |
12 #include "printing/native_metafile.h" | |
13 #include "printing/print_settings_initializer_gtk.h" | 17 #include "printing/print_settings_initializer_gtk.h" |
14 #include "printing/units.h" | 18 #endif // defined(OS_CHROMEOS) |
| 19 |
| 20 #if !defined(OS_CHROMEOS) |
| 21 namespace { |
| 22 // Function pointer for creating print dialogs. |
| 23 static void* (*create_dialog_func_)( |
| 24 printing::PrintingContext::PrintSettingsCallback* callback, |
| 25 printing::PrintingContextCairo* context) = NULL; |
| 26 // Function pointer for printing documents. |
| 27 static void (*print_document_func_)( |
| 28 void* print_dialog, |
| 29 const printing::NativeMetafile* metafile, |
| 30 const string16& document_name) = NULL; |
| 31 } // namespace |
| 32 #endif // !defined(OS_CHROMEOS) |
15 | 33 |
16 namespace printing { | 34 namespace printing { |
17 | 35 |
18 // static | 36 // static |
19 PrintingContext* PrintingContext::Create(const std::string& app_locale) { | 37 PrintingContext* PrintingContext::Create(const std::string& app_locale) { |
20 return static_cast<PrintingContext*>(new PrintingContextCairo(app_locale)); | 38 return static_cast<PrintingContext*>(new PrintingContextCairo(app_locale)); |
21 } | 39 } |
22 | 40 |
23 PrintingContextCairo::PrintingContextCairo(const std::string& app_locale) | 41 PrintingContextCairo::PrintingContextCairo(const std::string& app_locale) |
24 : PrintingContext(app_locale) { | 42 #if defined(OS_CHROMEOS) |
| 43 : PrintingContext(app_locale) { |
| 44 #else |
| 45 : PrintingContext(app_locale), |
| 46 print_dialog_(NULL) { |
| 47 #endif |
25 } | 48 } |
26 | 49 |
27 PrintingContextCairo::~PrintingContextCairo() { | 50 PrintingContextCairo::~PrintingContextCairo() { |
28 ReleaseContext(); | 51 ReleaseContext(); |
29 } | 52 } |
30 | 53 |
| 54 #if !defined(OS_CHROMEOS) |
| 55 // static |
| 56 void PrintingContextCairo::SetPrintingFunctions( |
| 57 void* (*create_dialog_func)(PrintSettingsCallback* callback, |
| 58 PrintingContextCairo* context), |
| 59 void (*print_document_func)(void* print_dialog, |
| 60 const NativeMetafile* metafile, |
| 61 const string16& document_name)) { |
| 62 DCHECK(create_dialog_func); |
| 63 DCHECK(print_document_func); |
| 64 DCHECK(!create_dialog_func_); |
| 65 DCHECK(!print_document_func_); |
| 66 create_dialog_func_ = create_dialog_func; |
| 67 print_document_func_ = print_document_func; |
| 68 } |
| 69 |
| 70 void PrintingContextCairo::PrintDocument(const NativeMetafile* metafile) { |
| 71 DCHECK(print_dialog_); |
| 72 DCHECK(metafile); |
| 73 print_document_func_(print_dialog_, metafile, document_name_); |
| 74 } |
| 75 #endif // !defined(OS_CHROMEOS) |
| 76 |
31 void PrintingContextCairo::AskUserForSettings( | 77 void PrintingContextCairo::AskUserForSettings( |
32 gfx::NativeView parent_view, | 78 gfx::NativeView parent_view, |
33 int max_pages, | 79 int max_pages, |
34 bool has_selection, | 80 bool has_selection, |
35 PrintSettingsCallback* callback) { | 81 PrintSettingsCallback* callback) { |
36 NOTIMPLEMENTED(); | 82 #if defined(OS_CHROMEOS) |
37 callback->Run(OK); | 83 callback->Run(OK); |
| 84 #else |
| 85 print_dialog_ = create_dialog_func_(callback, this); |
| 86 #endif // defined(OS_CHROMEOS) |
38 } | 87 } |
39 | 88 |
40 PrintingContext::Result PrintingContextCairo::UseDefaultSettings() { | 89 PrintingContext::Result PrintingContextCairo::UseDefaultSettings() { |
41 DCHECK(!in_print_job_); | 90 DCHECK(!in_print_job_); |
42 | 91 |
43 ResetSettings(); | 92 ResetSettings(); |
44 #if defined(OS_CHROMEOS) | 93 #if defined(OS_CHROMEOS) |
45 // For Chrome OS use default values based on the app locale rather than rely | 94 // 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 well if it is | 95 // on GTK. Note that relying on the app locale does not work well if it is |
47 // different from the system locale, e.g. a user using Chinese ChromeOS in the | 96 // different from the system locale, e.g. a user using Chinese ChromeOS in the |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
99 | 148 |
100 return OK; | 149 return OK; |
101 } | 150 } |
102 | 151 |
103 PrintingContext::Result PrintingContextCairo::InitWithSettings( | 152 PrintingContext::Result PrintingContextCairo::InitWithSettings( |
104 const PrintSettings& settings) { | 153 const PrintSettings& settings) { |
105 DCHECK(!in_print_job_); | 154 DCHECK(!in_print_job_); |
106 | 155 |
107 settings_ = settings; | 156 settings_ = settings; |
108 | 157 |
109 NOTIMPLEMENTED(); | 158 return OK; |
110 | |
111 return FAILED; | |
112 } | 159 } |
113 | 160 |
114 PrintingContext::Result PrintingContextCairo::NewDocument( | 161 PrintingContext::Result PrintingContextCairo::NewDocument( |
115 const string16& document_name) { | 162 const string16& document_name) { |
116 DCHECK(!in_print_job_); | 163 DCHECK(!in_print_job_); |
| 164 in_print_job_ = true; |
117 | 165 |
118 NOTIMPLEMENTED(); | 166 #if !defined(OS_CHROMEOS) |
| 167 document_name_ = document_name; |
| 168 #endif // !defined(OS_CHROMEOS) |
119 | 169 |
120 return FAILED; | 170 return OK; |
121 } | 171 } |
122 | 172 |
123 PrintingContext::Result PrintingContextCairo::NewPage() { | 173 PrintingContext::Result PrintingContextCairo::NewPage() { |
124 if (abort_printing_) | 174 if (abort_printing_) |
125 return CANCEL; | 175 return CANCEL; |
126 DCHECK(in_print_job_); | 176 DCHECK(in_print_job_); |
127 | 177 |
128 NOTIMPLEMENTED(); | 178 // Intentional No-op. |
129 | 179 |
130 return FAILED; | 180 return OK; |
131 } | 181 } |
132 | 182 |
133 PrintingContext::Result PrintingContextCairo::PageDone() { | 183 PrintingContext::Result PrintingContextCairo::PageDone() { |
134 if (abort_printing_) | 184 if (abort_printing_) |
135 return CANCEL; | 185 return CANCEL; |
136 DCHECK(in_print_job_); | 186 DCHECK(in_print_job_); |
137 | 187 |
138 NOTIMPLEMENTED(); | 188 // Intentional No-op. |
139 | 189 |
140 return FAILED; | 190 return OK; |
141 } | 191 } |
142 | 192 |
143 PrintingContext::Result PrintingContextCairo::DocumentDone() { | 193 PrintingContext::Result PrintingContextCairo::DocumentDone() { |
144 if (abort_printing_) | 194 if (abort_printing_) |
145 return CANCEL; | 195 return CANCEL; |
146 DCHECK(in_print_job_); | 196 DCHECK(in_print_job_); |
147 | 197 |
148 NOTIMPLEMENTED(); | |
149 | |
150 ResetSettings(); | 198 ResetSettings(); |
151 return FAILED; | 199 return OK; |
152 } | 200 } |
153 | 201 |
154 void PrintingContextCairo::Cancel() { | 202 void PrintingContextCairo::Cancel() { |
155 abort_printing_ = true; | 203 abort_printing_ = true; |
156 in_print_job_ = false; | 204 in_print_job_ = false; |
157 | |
158 NOTIMPLEMENTED(); | |
159 } | 205 } |
160 | 206 |
161 void PrintingContextCairo::ReleaseContext() { | 207 void PrintingContextCairo::ReleaseContext() { |
162 // Nothing to do yet. | 208 // Intentional No-op. |
163 } | 209 } |
164 | 210 |
165 gfx::NativeDrawingContext PrintingContextCairo::context() const { | 211 gfx::NativeDrawingContext PrintingContextCairo::context() const { |
| 212 // Intentional No-op. |
166 return NULL; | 213 return NULL; |
167 } | 214 } |
168 | 215 |
169 } // namespace printing | 216 } // namespace printing |
OLD | NEW |