Enable chrome with aura for tizen
[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/metafile.h"
16 #include "printing/print_job_constants.h"
17 #include "printing/units.h"
18
19 namespace printing {
20
21 #if !defined(USE_CUPS)
22 // static
23 std::unique_ptr<PrintingContext> PrintingContext::CreateImpl(
24     Delegate* delegate,
25     bool skip_system_calls) {
26   return std::make_unique<PrintingContextNoSystemDialog>(delegate);
27 }
28 #endif  // !defined(USE_CUPS)
29
30 PrintingContextNoSystemDialog::PrintingContextNoSystemDialog(Delegate* delegate)
31     : PrintingContext(delegate) {}
32
33 PrintingContextNoSystemDialog::~PrintingContextNoSystemDialog() {
34   ReleaseContext();
35 }
36
37 void PrintingContextNoSystemDialog::AskUserForSettings(
38     int max_pages,
39     bool has_selection,
40     bool is_scripted,
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);
44 }
45
46 mojom::ResultCode PrintingContextNoSystemDialog::UseDefaultSettings() {
47   DCHECK(!in_print_job_);
48
49   ResetSettings();
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;
57 }
58
59 gfx::Size PrintingContextNoSystemDialog::GetPdfPaperSizeDeviceUnits() {
60   int32_t width = 0;
61   int32_t height = 0;
62   UErrorCode error = U_ZERO_ERROR;
63   ulocdata_getPaperSize(delegate_->GetAppLocale().c_str(), &height, &width,
64                         &error);
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: "
68                  << error;
69     width =
70         static_cast<int>(kLetterWidthInch * settings_->device_units_per_inch());
71     height = static_cast<int>(kLetterHeightInch *
72                               settings_->device_units_per_inch());
73   } else {
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;
77     width *= multiplier;
78     height *= multiplier;
79   }
80   return gfx::Size(width, height);
81 }
82
83 mojom::ResultCode PrintingContextNoSystemDialog::UpdatePrinterSettings(
84     const PrinterSettings& printer_settings) {
85   DCHECK(!printer_settings.show_system_dialog);
86
87   if (settings_->dpi() == 0)
88     UseDefaultSettings();
89
90   return mojom::ResultCode::kSuccess;
91 }
92
93 mojom::ResultCode PrintingContextNoSystemDialog::NewDocument(
94     const std::u16string& document_name) {
95   DCHECK(!in_print_job_);
96   in_print_job_ = true;
97
98   return mojom::ResultCode::kSuccess;
99 }
100
101 mojom::ResultCode PrintingContextNoSystemDialog::PrintDocument(
102     const MetafilePlayer& metafile,
103     const PrintSettings& settings,
104     uint32_t num_pages) {
105   if (abort_printing_)
106     return mojom::ResultCode::kCanceled;
107   DCHECK(in_print_job_);
108
109   // Intentional No-op.
110
111   return mojom::ResultCode::kSuccess;
112 }
113
114 mojom::ResultCode PrintingContextNoSystemDialog::DocumentDone() {
115   if (abort_printing_)
116     return mojom::ResultCode::kCanceled;
117   DCHECK(in_print_job_);
118
119   ResetSettings();
120   return mojom::ResultCode::kSuccess;
121 }
122
123 void PrintingContextNoSystemDialog::Cancel() {
124   abort_printing_ = true;
125   in_print_job_ = false;
126 }
127
128 void PrintingContextNoSystemDialog::ReleaseContext() {
129   // Intentional No-op.
130 }
131
132 printing::NativeDrawingContext PrintingContextNoSystemDialog::context() const {
133   // Intentional No-op.
134   return nullptr;
135 }
136
137 }  // namespace printing