1 // Copyright 2011 The Chromium Authors
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "printing/printing_context_no_system_dialog.h"
8 #include <unicode/ulocdata.h>
13 #include "base/logging.h"
14 #include "base/values.h"
15 #include "printing/metafile.h"
16 #include "printing/print_job_constants.h"
17 #include "printing/units.h"
21 #if !defined(USE_CUPS)
23 std::unique_ptr<PrintingContext> PrintingContext::CreateImpl(
25 bool skip_system_calls) {
26 return std::make_unique<PrintingContextNoSystemDialog>(delegate);
28 #endif // !defined(USE_CUPS)
30 PrintingContextNoSystemDialog::PrintingContextNoSystemDialog(Delegate* delegate)
31 : PrintingContext(delegate) {}
33 PrintingContextNoSystemDialog::~PrintingContextNoSystemDialog() {
37 void PrintingContextNoSystemDialog::AskUserForSettings(
41 PrintSettingsCallback callback) {
42 // We don't want to bring up a dialog here. Ever. Just signal the callback.
43 std::move(callback).Run(mojom::ResultCode::kSuccess);
46 mojom::ResultCode PrintingContextNoSystemDialog::UseDefaultSettings() {
47 DCHECK(!in_print_job_);
50 settings_->set_dpi(kDefaultPdfDpi);
51 gfx::Size physical_size = GetPdfPaperSizeDeviceUnits();
52 // Assume full page is printable for now.
53 gfx::Rect printable_area(0, 0, physical_size.width(), physical_size.height());
54 DCHECK_EQ(settings_->device_units_per_inch(), kDefaultPdfDpi);
55 settings_->SetPrinterPrintableArea(physical_size, printable_area, true);
56 return mojom::ResultCode::kSuccess;
59 gfx::Size PrintingContextNoSystemDialog::GetPdfPaperSizeDeviceUnits() {
62 UErrorCode error = U_ZERO_ERROR;
63 ulocdata_getPaperSize(delegate_->GetAppLocale().c_str(), &height, &width,
65 if (error > U_ZERO_ERROR) {
66 // If the call failed, assume a paper size of 8.5 x 11 inches.
67 LOG(WARNING) << "ulocdata_getPaperSize failed, using 8.5 x 11, error: "
70 static_cast<int>(kLetterWidthInch * settings_->device_units_per_inch());
71 height = static_cast<int>(kLetterHeightInch *
72 settings_->device_units_per_inch());
74 // ulocdata_getPaperSize returns the width and height in mm.
75 // Convert this to pixels based on the dpi.
76 float multiplier = settings_->device_units_per_inch() / kMicronsPerMil;
80 return gfx::Size(width, height);
83 mojom::ResultCode PrintingContextNoSystemDialog::UpdatePrinterSettings(
84 const PrinterSettings& printer_settings) {
85 DCHECK(!printer_settings.show_system_dialog);
87 if (settings_->dpi() == 0)
90 return mojom::ResultCode::kSuccess;
93 mojom::ResultCode PrintingContextNoSystemDialog::NewDocument(
94 const std::u16string& document_name) {
95 DCHECK(!in_print_job_);
98 return mojom::ResultCode::kSuccess;
101 mojom::ResultCode PrintingContextNoSystemDialog::PrintDocument(
102 const MetafilePlayer& metafile,
103 const PrintSettings& settings,
104 uint32_t num_pages) {
106 return mojom::ResultCode::kCanceled;
107 DCHECK(in_print_job_);
109 // Intentional No-op.
111 return mojom::ResultCode::kSuccess;
114 mojom::ResultCode PrintingContextNoSystemDialog::DocumentDone() {
116 return mojom::ResultCode::kCanceled;
117 DCHECK(in_print_job_);
120 return mojom::ResultCode::kSuccess;
123 void PrintingContextNoSystemDialog::Cancel() {
124 abort_printing_ = true;
125 in_print_job_ = false;
128 void PrintingContextNoSystemDialog::ReleaseContext() {
129 // Intentional No-op.
132 printing::NativeDrawingContext PrintingContextNoSystemDialog::context() const {
133 // Intentional No-op.
137 } // namespace printing