blob: 240bfd67a4f005e518fccda6c237d4de3b518a1b [file] [log] [blame]
[email protected]ea5e81d92011-11-08 18:45:151// 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
3// found in the LICENSE file.
4
5#include "printing/printing_context_no_system_dialog.h"
6
avi126e93c2015-12-21 21:48:167#include <stdint.h>
[email protected]ea5e81d92011-11-08 18:45:158#include <unicode/ulocdata.h>
9
skaub7931952016-07-27 18:04:5110#include <memory>
11
[email protected]ea5e81d92011-11-08 18:45:1512#include "base/logging.h"
13#include "base/values.h"
14#include "printing/metafile.h"
15#include "printing/print_job_constants.h"
16#include "printing/units.h"
17
18namespace printing {
19
skaub7931952016-07-27 18:04:5120#if !defined(USE_CUPS)
[email protected]ea5e81d92011-11-08 18:45:1521// static
dchengc3df9ba2016-04-07 23:09:3222std::unique_ptr<PrintingContext> PrintingContext::Create(Delegate* delegate) {
Gyuyoung Kimb480aba2018-01-27 07:00:0423 return std::make_unique<PrintingContextNoSystemDialog>(delegate);
[email protected]ea5e81d92011-11-08 18:45:1524}
skaub7931952016-07-27 18:04:5125#endif // !defined(USE_CUPS)
[email protected]ea5e81d92011-11-08 18:45:1526
Vitaly Bukabd7c9812014-08-26 08:57:5427PrintingContextNoSystemDialog::PrintingContextNoSystemDialog(Delegate* delegate)
28 : PrintingContext(delegate) {
[email protected]ea5e81d92011-11-08 18:45:1529}
30
31PrintingContextNoSystemDialog::~PrintingContextNoSystemDialog() {
32 ReleaseContext();
33}
34
35void PrintingContextNoSystemDialog::AskUserForSettings(
[email protected]ea5e81d92011-11-08 18:45:1536 int max_pages,
37 bool has_selection,
dgn4c172eea2014-12-15 21:11:2338 bool is_scripted,
[email protected]abe48112011-11-19 01:58:3839 const PrintSettingsCallback& callback) {
[email protected]ea5e81d92011-11-08 18:45:1540 // We don't want to bring up a dialog here. Ever. Just signal the callback.
[email protected]abe48112011-11-19 01:58:3841 callback.Run(OK);
[email protected]ea5e81d92011-11-08 18:45:1542}
43
44PrintingContext::Result PrintingContextNoSystemDialog::UseDefaultSettings() {
45 DCHECK(!in_print_job_);
46
47 ResetSettings();
[email protected]4c9054b2013-11-04 18:34:2948 settings_.set_dpi(kDefaultPdfDpi);
49 gfx::Size physical_size = GetPdfPaperSizeDeviceUnits();
50 // Assume full page is printable for now.
51 gfx::Rect printable_area(0, 0, physical_size.width(), physical_size.height());
52 DCHECK_EQ(settings_.device_units_per_inch(), kDefaultPdfDpi);
53 settings_.SetPrinterPrintableArea(physical_size, printable_area, true);
54 return OK;
55}
56
57gfx::Size PrintingContextNoSystemDialog::GetPdfPaperSizeDeviceUnits() {
[email protected]ea5e81d92011-11-08 18:45:1558 int32_t width = 0;
59 int32_t height = 0;
60 UErrorCode error = U_ZERO_ERROR;
Vitaly Bukabd7c9812014-08-26 08:57:5461 ulocdata_getPaperSize(
62 delegate_->GetAppLocale().c_str(), &height, &width, &error);
[email protected]d1bee422012-08-07 23:44:3163 if (error > U_ZERO_ERROR) {
[email protected]ea5e81d92011-11-08 18:45:1564 // If the call failed, assume a paper size of 8.5 x 11 inches.
65 LOG(WARNING) << "ulocdata_getPaperSize failed, using 8.5 x 11, error: "
66 << error;
[email protected]4c9054b2013-11-04 18:34:2967 width = static_cast<int>(
68 kLetterWidthInch * settings_.device_units_per_inch());
69 height = static_cast<int>(
70 kLetterHeightInch * settings_.device_units_per_inch());
[email protected]ea5e81d92011-11-08 18:45:1571 } else {
72 // ulocdata_getPaperSize returns the width and height in mm.
73 // Convert this to pixels based on the dpi.
[email protected]4c9054b2013-11-04 18:34:2974 float multiplier = 100 * settings_.device_units_per_inch();
75 multiplier /= kHundrethsMMPerInch;
76 width *= multiplier;
77 height *= multiplier;
[email protected]ea5e81d92011-11-08 18:45:1578 }
[email protected]4c9054b2013-11-04 18:34:2979 return gfx::Size(width, height);
[email protected]ea5e81d92011-11-08 18:45:1580}
81
82PrintingContext::Result PrintingContextNoSystemDialog::UpdatePrinterSettings(
vitalybuka92ab8ce2014-08-26 23:41:4583 bool external_preview,
vitalybuka95fa3c92015-05-05 03:03:3284 bool show_system_dialog,
85 int page_count) {
vitalybuka92ab8ce2014-08-26 23:41:4586 DCHECK(!show_system_dialog);
[email protected]0c5e3022013-11-01 14:25:0187
88 if (settings_.dpi() == 0)
89 UseDefaultSettings();
90
[email protected]ea5e81d92011-11-08 18:45:1591 return OK;
92}
93
[email protected]ea5e81d92011-11-08 18:45:1594PrintingContext::Result PrintingContextNoSystemDialog::NewDocument(
[email protected]b5fa4ee2013-10-01 07:19:0795 const base::string16& document_name) {
[email protected]ea5e81d92011-11-08 18:45:1596 DCHECK(!in_print_job_);
97 in_print_job_ = true;
98
99 return OK;
100}
101
102PrintingContext::Result PrintingContextNoSystemDialog::NewPage() {
103 if (abort_printing_)
104 return CANCEL;
105 DCHECK(in_print_job_);
106
107 // Intentional No-op.
108
109 return OK;
110}
111
112PrintingContext::Result PrintingContextNoSystemDialog::PageDone() {
113 if (abort_printing_)
114 return CANCEL;
115 DCHECK(in_print_job_);
116
117 // Intentional No-op.
118
119 return OK;
120}
121
122PrintingContext::Result PrintingContextNoSystemDialog::DocumentDone() {
123 if (abort_printing_)
124 return CANCEL;
125 DCHECK(in_print_job_);
126
127 ResetSettings();
128 return OK;
129}
130
131void PrintingContextNoSystemDialog::Cancel() {
132 abort_printing_ = true;
133 in_print_job_ = false;
134}
135
136void PrintingContextNoSystemDialog::ReleaseContext() {
137 // Intentional No-op.
138}
139
Nico Weber8e559562017-10-03 01:25:26140printing::NativeDrawingContext PrintingContextNoSystemDialog::context() const {
[email protected]ea5e81d92011-11-08 18:45:15141 // Intentional No-op.
skaub7931952016-07-27 18:04:51142 return nullptr;
[email protected]ea5e81d92011-11-08 18:45:15143}
144
145} // namespace printing
146