[M120 Migration][MM] Fix EME AD insert issue
[platform/framework/web/chromium-efl.git] / printing / printing_context_no_system_dialog.cc
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.
4
5 #include "printing/printing_context_no_system_dialog.h"
6
7 #include <stdint.h>
8 #include <unicode/ulocdata.h>
9
10 #include <memory>
11 #include <utility>
12
13 #include "base/logging.h"
14 #include "base/values.h"
15 #include "printing/buildflags/buildflags.h"
16 #include "printing/metafile.h"
17 #include "printing/print_job_constants.h"
18 #include "printing/units.h"
19
20 namespace printing {
21
22 #if !BUILDFLAG(USE_CUPS)
23 // static
24 std::unique_ptr<PrintingContext> PrintingContext::CreateImpl(
25     Delegate* delegate,
26     bool skip_system_calls) {
27   return std::make_unique<PrintingContextNoSystemDialog>(delegate);
28 }
29 #endif  // !BUILDFLAG(USE_CUPS)
30
31 PrintingContextNoSystemDialog::PrintingContextNoSystemDialog(Delegate* delegate)
32     : PrintingContext(delegate) {}
33
34 PrintingContextNoSystemDialog::~PrintingContextNoSystemDialog() {
35   ReleaseContext();
36 }
37
38 void PrintingContextNoSystemDialog::AskUserForSettings(
39     int max_pages,
40     bool has_selection,
41     bool is_scripted,
42     PrintSettingsCallback callback) {
43   // We don't want to bring up a dialog here.  Ever.  Just signal the callback.
44   std::move(callback).Run(mojom::ResultCode::kSuccess);
45 }
46
47 mojom::ResultCode PrintingContextNoSystemDialog::UseDefaultSettings() {
48   DCHECK(!in_print_job_);
49
50   ResetSettings();
51   settings_->set_dpi(kDefaultPdfDpi);
52   gfx::Size physical_size = GetPdfPaperSizeDeviceUnits();
53   // Assume full page is printable for now.
54   gfx::Rect printable_area(0, 0, physical_size.width(), physical_size.height());
55   DCHECK_EQ(settings_->device_units_per_inch(), kDefaultPdfDpi);
56   settings_->SetPrinterPrintableArea(physical_size, printable_area, true);
57   return mojom::ResultCode::kSuccess;
58 }
59
60 gfx::Size PrintingContextNoSystemDialog::GetPdfPaperSizeDeviceUnits() {
61   int32_t width = 0;
62   int32_t height = 0;
63   UErrorCode error = U_ZERO_ERROR;
64   ulocdata_getPaperSize(delegate_->GetAppLocale().c_str(), &height, &width,
65                         &error);
66   if (error > U_ZERO_ERROR) {
67     // If the call failed, assume a paper size of 8.5 x 11 inches.
68     LOG(WARNING) << "ulocdata_getPaperSize failed, using 8.5 x 11, error: "
69                  << error;
70     width =
71         static_cast<int>(kLetterWidthInch * settings_->device_units_per_inch());
72     height = static_cast<int>(kLetterHeightInch *
73                               settings_->device_units_per_inch());
74   } else {
75     // ulocdata_getPaperSize returns the width and height in mm.
76     // Convert this to pixels based on the dpi.
77     float multiplier = settings_->device_units_per_inch() / kMicronsPerMil;
78     width *= multiplier;
79     height *= multiplier;
80   }
81   return gfx::Size(width, height);
82 }
83
84 mojom::ResultCode PrintingContextNoSystemDialog::UpdatePrinterSettings(
85     const PrinterSettings& printer_settings) {
86   DCHECK(!printer_settings.show_system_dialog);
87
88   if (settings_->dpi() == 0)
89     UseDefaultSettings();
90
91   return mojom::ResultCode::kSuccess;
92 }
93
94 mojom::ResultCode PrintingContextNoSystemDialog::NewDocument(
95     const std::u16string& document_name) {
96   DCHECK(!in_print_job_);
97   in_print_job_ = true;
98
99   return mojom::ResultCode::kSuccess;
100 }
101
102 mojom::ResultCode PrintingContextNoSystemDialog::PrintDocument(
103     const MetafilePlayer& metafile,
104     const PrintSettings& settings,
105     uint32_t num_pages) {
106   if (abort_printing_)
107     return mojom::ResultCode::kCanceled;
108   DCHECK(in_print_job_);
109
110   // Intentional No-op.
111
112   return mojom::ResultCode::kSuccess;
113 }
114
115 mojom::ResultCode PrintingContextNoSystemDialog::DocumentDone() {
116   if (abort_printing_)
117     return mojom::ResultCode::kCanceled;
118   DCHECK(in_print_job_);
119
120   ResetSettings();
121   return mojom::ResultCode::kSuccess;
122 }
123
124 void PrintingContextNoSystemDialog::Cancel() {
125   abort_printing_ = true;
126   in_print_job_ = false;
127 }
128
129 void PrintingContextNoSystemDialog::ReleaseContext() {
130   // Intentional No-op.
131 }
132
133 printing::NativeDrawingContext PrintingContextNoSystemDialog::context() const {
134   // Intentional No-op.
135   return nullptr;
136 }
137
138 }  // namespace printing