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" |
(...skipping 23 matching lines...) Expand all Loading... |
34 bool has_selection, | 34 bool has_selection, |
35 const PrintSettingsCallback& callback) { | 35 const PrintSettingsCallback& callback) { |
36 // 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. |
37 callback.Run(OK); | 37 callback.Run(OK); |
38 } | 38 } |
39 | 39 |
40 PrintingContext::Result PrintingContextNoSystemDialog::UseDefaultSettings() { | 40 PrintingContext::Result PrintingContextNoSystemDialog::UseDefaultSettings() { |
41 DCHECK(!in_print_job_); | 41 DCHECK(!in_print_job_); |
42 | 42 |
43 ResetSettings(); | 43 ResetSettings(); |
44 // TODO(abodenha): Fetch these settings from the OS where possible. See | 44 settings_.set_dpi(kDefaultPdfDpi); |
45 // bug 102583. | 45 gfx::Size physical_size = GetPdfPaperSizeDeviceUnits(); |
46 // TODO(sanjeevr): We need a better feedback loop between the cloud print | 46 // Assume full page is printable for now. |
47 // dialog and this code. | 47 gfx::Rect printable_area(0, 0, physical_size.width(), physical_size.height()); |
48 int dpi = 300; | 48 settings_.SetPrinterPrintableArea(physical_size, printable_area, true); |
49 gfx::Size physical_size_device_units; | 49 return OK; |
50 gfx::Rect printable_area_device_units; | 50 } |
| 51 |
| 52 gfx::Size PrintingContextNoSystemDialog::GetPdfPaperSizeDeviceUnits() { |
51 int32_t width = 0; | 53 int32_t width = 0; |
52 int32_t height = 0; | 54 int32_t height = 0; |
53 UErrorCode error = U_ZERO_ERROR; | 55 UErrorCode error = U_ZERO_ERROR; |
54 ulocdata_getPaperSize(app_locale_.c_str(), &height, &width, &error); | 56 ulocdata_getPaperSize(app_locale_.c_str(), &height, &width, &error); |
55 if (error > U_ZERO_ERROR) { | 57 if (error > U_ZERO_ERROR) { |
56 // If the call failed, assume a paper size of 8.5 x 11 inches. | 58 // If the call failed, assume a paper size of 8.5 x 11 inches. |
57 LOG(WARNING) << "ulocdata_getPaperSize failed, using 8.5 x 11, error: " | 59 LOG(WARNING) << "ulocdata_getPaperSize failed, using 8.5 x 11, error: " |
58 << error; | 60 << error; |
59 width = static_cast<int>(8.5 * dpi); | 61 width = static_cast<int>( |
60 height = static_cast<int>(11 * dpi); | 62 kLetterWidthInch * settings_.device_units_per_inch()); |
| 63 height = static_cast<int>( |
| 64 kLetterHeightInch * settings_.device_units_per_inch()); |
61 } else { | 65 } else { |
62 // ulocdata_getPaperSize returns the width and height in mm. | 66 // ulocdata_getPaperSize returns the width and height in mm. |
63 // Convert this to pixels based on the dpi. | 67 // Convert this to pixels based on the dpi. |
64 width = static_cast<int>(ConvertUnitDouble(width, 25.4, 1.0) * dpi); | 68 float multiplier = 100 * settings_.device_units_per_inch(); |
65 height = static_cast<int>(ConvertUnitDouble(height, 25.4, 1.0) * dpi); | 69 multiplier /= kHundrethsMMPerInch; |
| 70 width *= multiplier; |
| 71 height *= multiplier; |
66 } | 72 } |
67 | 73 return gfx::Size(width, height); |
68 physical_size_device_units.SetSize(width, height); | |
69 | |
70 // Assume full page is printable for now. | |
71 printable_area_device_units.SetRect(0, 0, width, height); | |
72 | |
73 settings_.set_dpi(dpi); | |
74 settings_.SetPrinterPrintableArea(physical_size_device_units, | |
75 printable_area_device_units, | |
76 dpi, true); | |
77 | |
78 return OK; | |
79 } | 74 } |
80 | 75 |
81 PrintingContext::Result PrintingContextNoSystemDialog::UpdatePrinterSettings( | 76 PrintingContext::Result PrintingContextNoSystemDialog::UpdatePrinterSettings( |
82 bool target_is_pdf, | |
83 bool external_preview) { | 77 bool external_preview) { |
84 return OK; | 78 return OK; |
85 } | 79 } |
86 | 80 |
87 PrintingContext::Result PrintingContextNoSystemDialog::InitWithSettings( | 81 PrintingContext::Result PrintingContextNoSystemDialog::InitWithSettings( |
88 const PrintSettings& settings) { | 82 const PrintSettings& settings) { |
89 DCHECK(!in_print_job_); | 83 DCHECK(!in_print_job_); |
90 | 84 |
91 settings_ = settings; | 85 settings_ = settings; |
92 | 86 |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
139 // Intentional No-op. | 133 // Intentional No-op. |
140 } | 134 } |
141 | 135 |
142 gfx::NativeDrawingContext PrintingContextNoSystemDialog::context() const { | 136 gfx::NativeDrawingContext PrintingContextNoSystemDialog::context() const { |
143 // Intentional No-op. | 137 // Intentional No-op. |
144 return NULL; | 138 return NULL; |
145 } | 139 } |
146 | 140 |
147 } // namespace printing | 141 } // namespace printing |
148 | 142 |
OLD | NEW |