OLD | NEW |
1 // Copyright (c) 2011 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_no_system_dialog.h" | 5 #include "printing/printing_context_no_system_dialog.h" |
6 | 6 |
7 #include <unicode/ulocdata.h> | 7 #include <unicode/ulocdata.h> |
8 | 8 |
9 #include "base/logging.h" | 9 #include "base/logging.h" |
10 #include "base/values.h" | 10 #include "base/values.h" |
11 #include "printing/metafile.h" | 11 #include "printing/metafile.h" |
12 #include "printing/print_job_constants.h" | 12 #include "printing/print_job_constants.h" |
13 #include "printing/units.h" | 13 #include "printing/units.h" |
14 | 14 |
15 namespace printing { | 15 namespace printing { |
16 | 16 |
17 // static | 17 // static |
18 scoped_ptr<PrintingContext> PrintingContext::Create(Delegate* delegate) { | 18 PrintingContext* PrintingContext::Create(const std::string& app_locale) { |
19 return make_scoped_ptr<PrintingContext>( | 19 return static_cast<PrintingContext*>( |
20 new PrintingContextNoSystemDialog(delegate)); | 20 new PrintingContextNoSystemDialog(app_locale)); |
21 } | 21 } |
22 | 22 |
23 PrintingContextNoSystemDialog::PrintingContextNoSystemDialog(Delegate* delegate) | 23 PrintingContextNoSystemDialog::PrintingContextNoSystemDialog( |
24 : PrintingContext(delegate) { | 24 const std::string& app_locale) : PrintingContext(app_locale) { |
25 } | 25 } |
26 | 26 |
27 PrintingContextNoSystemDialog::~PrintingContextNoSystemDialog() { | 27 PrintingContextNoSystemDialog::~PrintingContextNoSystemDialog() { |
28 ReleaseContext(); | 28 ReleaseContext(); |
29 } | 29 } |
30 | 30 |
31 void PrintingContextNoSystemDialog::AskUserForSettings( | 31 void PrintingContextNoSystemDialog::AskUserForSettings( |
| 32 gfx::NativeView parent_view, |
32 int max_pages, | 33 int max_pages, |
33 bool has_selection, | 34 bool has_selection, |
34 const PrintSettingsCallback& callback) { | 35 const PrintSettingsCallback& callback) { |
35 // We don't want to bring up a dialog here. Ever. Just signal the callback. | 36 // We don't want to bring up a dialog here. Ever. Just signal the callback. |
36 callback.Run(OK); | 37 callback.Run(OK); |
37 } | 38 } |
38 | 39 |
39 PrintingContext::Result PrintingContextNoSystemDialog::UseDefaultSettings() { | 40 PrintingContext::Result PrintingContextNoSystemDialog::UseDefaultSettings() { |
40 DCHECK(!in_print_job_); | 41 DCHECK(!in_print_job_); |
41 | 42 |
42 ResetSettings(); | 43 ResetSettings(); |
43 settings_.set_dpi(kDefaultPdfDpi); | 44 settings_.set_dpi(kDefaultPdfDpi); |
44 gfx::Size physical_size = GetPdfPaperSizeDeviceUnits(); | 45 gfx::Size physical_size = GetPdfPaperSizeDeviceUnits(); |
45 // Assume full page is printable for now. | 46 // Assume full page is printable for now. |
46 gfx::Rect printable_area(0, 0, physical_size.width(), physical_size.height()); | 47 gfx::Rect printable_area(0, 0, physical_size.width(), physical_size.height()); |
47 DCHECK_EQ(settings_.device_units_per_inch(), kDefaultPdfDpi); | 48 DCHECK_EQ(settings_.device_units_per_inch(), kDefaultPdfDpi); |
48 settings_.SetPrinterPrintableArea(physical_size, printable_area, true); | 49 settings_.SetPrinterPrintableArea(physical_size, printable_area, true); |
49 return OK; | 50 return OK; |
50 } | 51 } |
51 | 52 |
52 gfx::Size PrintingContextNoSystemDialog::GetPdfPaperSizeDeviceUnits() { | 53 gfx::Size PrintingContextNoSystemDialog::GetPdfPaperSizeDeviceUnits() { |
53 int32_t width = 0; | 54 int32_t width = 0; |
54 int32_t height = 0; | 55 int32_t height = 0; |
55 UErrorCode error = U_ZERO_ERROR; | 56 UErrorCode error = U_ZERO_ERROR; |
56 ulocdata_getPaperSize( | 57 ulocdata_getPaperSize(app_locale_.c_str(), &height, &width, &error); |
57 delegate_->GetAppLocale().c_str(), &height, &width, &error); | |
58 if (error > U_ZERO_ERROR) { | 58 if (error > U_ZERO_ERROR) { |
59 // If the call failed, assume a paper size of 8.5 x 11 inches. | 59 // If the call failed, assume a paper size of 8.5 x 11 inches. |
60 LOG(WARNING) << "ulocdata_getPaperSize failed, using 8.5 x 11, error: " | 60 LOG(WARNING) << "ulocdata_getPaperSize failed, using 8.5 x 11, error: " |
61 << error; | 61 << error; |
62 width = static_cast<int>( | 62 width = static_cast<int>( |
63 kLetterWidthInch * settings_.device_units_per_inch()); | 63 kLetterWidthInch * settings_.device_units_per_inch()); |
64 height = static_cast<int>( | 64 height = static_cast<int>( |
65 kLetterHeightInch * settings_.device_units_per_inch()); | 65 kLetterHeightInch * settings_.device_units_per_inch()); |
66 } else { | 66 } else { |
67 // ulocdata_getPaperSize returns the width and height in mm. | 67 // ulocdata_getPaperSize returns the width and height in mm. |
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
138 // Intentional No-op. | 138 // Intentional No-op. |
139 } | 139 } |
140 | 140 |
141 gfx::NativeDrawingContext PrintingContextNoSystemDialog::context() const { | 141 gfx::NativeDrawingContext PrintingContextNoSystemDialog::context() const { |
142 // Intentional No-op. | 142 // Intentional No-op. |
143 return NULL; | 143 return NULL; |
144 } | 144 } |
145 | 145 |
146 } // namespace printing | 146 } // namespace printing |
147 | 147 |
OLD | NEW |