blob: 6679fd70fcddbe937e0be1fb547e92b636092897 [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,
Vladislav Kuzkokov48ceab22018-02-14 16:29:2839 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.
Vladislav Kuzkokov48ceab22018-02-14 16:29:2841 std::move(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.
Lei Zhangd11ab162018-06-26 04:28:5074 float multiplier = settings_.device_units_per_inch() / kMicronsPerMil;
[email protected]4c9054b2013-11-04 18:34:2975 width *= multiplier;
76 height *= multiplier;
[email protected]ea5e81d92011-11-08 18:45:1577 }
[email protected]4c9054b2013-11-04 18:34:2978 return gfx::Size(width, height);
[email protected]ea5e81d92011-11-08 18:45:1579}
80
81PrintingContext::Result PrintingContextNoSystemDialog::UpdatePrinterSettings(
vitalybuka92ab8ce2014-08-26 23:41:4582 bool external_preview,
vitalybuka95fa3c92015-05-05 03:03:3283 bool show_system_dialog,
84 int page_count) {
vitalybuka92ab8ce2014-08-26 23:41:4585 DCHECK(!show_system_dialog);
[email protected]0c5e3022013-11-01 14:25:0186
87 if (settings_.dpi() == 0)
88 UseDefaultSettings();
89
[email protected]ea5e81d92011-11-08 18:45:1590 return OK;
91}
92
[email protected]ea5e81d92011-11-08 18:45:1593PrintingContext::Result PrintingContextNoSystemDialog::NewDocument(
[email protected]b5fa4ee2013-10-01 07:19:0794 const base::string16& document_name) {
[email protected]ea5e81d92011-11-08 18:45:1595 DCHECK(!in_print_job_);
96 in_print_job_ = true;
97
98 return OK;
99}
100
101PrintingContext::Result PrintingContextNoSystemDialog::NewPage() {
102 if (abort_printing_)
103 return CANCEL;
104 DCHECK(in_print_job_);
105
106 // Intentional No-op.
107
108 return OK;
109}
110
111PrintingContext::Result PrintingContextNoSystemDialog::PageDone() {
112 if (abort_printing_)
113 return CANCEL;
114 DCHECK(in_print_job_);
115
116 // Intentional No-op.
117
118 return OK;
119}
120
121PrintingContext::Result PrintingContextNoSystemDialog::DocumentDone() {
122 if (abort_printing_)
123 return CANCEL;
124 DCHECK(in_print_job_);
125
126 ResetSettings();
127 return OK;
128}
129
130void PrintingContextNoSystemDialog::Cancel() {
131 abort_printing_ = true;
132 in_print_job_ = false;
133}
134
135void PrintingContextNoSystemDialog::ReleaseContext() {
136 // Intentional No-op.
137}
138
Nico Weber8e559562017-10-03 01:25:26139printing::NativeDrawingContext PrintingContextNoSystemDialog::context() const {
[email protected]ea5e81d92011-11-08 18:45:15140 // Intentional No-op.
skaub7931952016-07-27 18:04:51141 return nullptr;
[email protected]ea5e81d92011-11-08 18:45:15142}
143
144} // namespace printing
145