blob: b6246d6cbbf567f5341b1f531c922582989e515e [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
7#include <unicode/ulocdata.h>
8
9#include "base/logging.h"
10#include "base/values.h"
11#include "printing/metafile.h"
12#include "printing/print_job_constants.h"
13#include "printing/units.h"
14
15namespace printing {
16
17// static
Vitaly Bukabd7c9812014-08-26 08:57:5418scoped_ptr<PrintingContext> PrintingContext::Create(Delegate* delegate) {
19 return make_scoped_ptr<PrintingContext>(
20 new PrintingContextNoSystemDialog(delegate));
[email protected]ea5e81d92011-11-08 18:45:1521}
22
Vitaly Bukabd7c9812014-08-26 08:57:5423PrintingContextNoSystemDialog::PrintingContextNoSystemDialog(Delegate* delegate)
24 : PrintingContext(delegate) {
[email protected]ea5e81d92011-11-08 18:45:1525}
26
27PrintingContextNoSystemDialog::~PrintingContextNoSystemDialog() {
28 ReleaseContext();
29}
30
31void PrintingContextNoSystemDialog::AskUserForSettings(
[email protected]ea5e81d92011-11-08 18:45:1532 int max_pages,
33 bool has_selection,
dgn4c172eea2014-12-15 21:11:2334 bool is_scripted,
[email protected]abe48112011-11-19 01:58:3835 const PrintSettingsCallback& callback) {
[email protected]ea5e81d92011-11-08 18:45:1536 // We don't want to bring up a dialog here. Ever. Just signal the callback.
[email protected]abe48112011-11-19 01:58:3837 callback.Run(OK);
[email protected]ea5e81d92011-11-08 18:45:1538}
39
40PrintingContext::Result PrintingContextNoSystemDialog::UseDefaultSettings() {
41 DCHECK(!in_print_job_);
42
43 ResetSettings();
[email protected]4c9054b2013-11-04 18:34:2944 settings_.set_dpi(kDefaultPdfDpi);
45 gfx::Size physical_size = GetPdfPaperSizeDeviceUnits();
46 // Assume full page is printable for now.
47 gfx::Rect printable_area(0, 0, physical_size.width(), physical_size.height());
48 DCHECK_EQ(settings_.device_units_per_inch(), kDefaultPdfDpi);
49 settings_.SetPrinterPrintableArea(physical_size, printable_area, true);
50 return OK;
51}
52
53gfx::Size PrintingContextNoSystemDialog::GetPdfPaperSizeDeviceUnits() {
[email protected]ea5e81d92011-11-08 18:45:1554 int32_t width = 0;
55 int32_t height = 0;
56 UErrorCode error = U_ZERO_ERROR;
Vitaly Bukabd7c9812014-08-26 08:57:5457 ulocdata_getPaperSize(
58 delegate_->GetAppLocale().c_str(), &height, &width, &error);
[email protected]d1bee422012-08-07 23:44:3159 if (error > U_ZERO_ERROR) {
[email protected]ea5e81d92011-11-08 18:45:1560 // If the call failed, assume a paper size of 8.5 x 11 inches.
61 LOG(WARNING) << "ulocdata_getPaperSize failed, using 8.5 x 11, error: "
62 << error;
[email protected]4c9054b2013-11-04 18:34:2963 width = static_cast<int>(
64 kLetterWidthInch * settings_.device_units_per_inch());
65 height = static_cast<int>(
66 kLetterHeightInch * settings_.device_units_per_inch());
[email protected]ea5e81d92011-11-08 18:45:1567 } else {
68 // ulocdata_getPaperSize returns the width and height in mm.
69 // Convert this to pixels based on the dpi.
[email protected]4c9054b2013-11-04 18:34:2970 float multiplier = 100 * settings_.device_units_per_inch();
71 multiplier /= kHundrethsMMPerInch;
72 width *= multiplier;
73 height *= multiplier;
[email protected]ea5e81d92011-11-08 18:45:1574 }
[email protected]4c9054b2013-11-04 18:34:2975 return gfx::Size(width, height);
[email protected]ea5e81d92011-11-08 18:45:1576}
77
78PrintingContext::Result PrintingContextNoSystemDialog::UpdatePrinterSettings(
vitalybuka92ab8ce2014-08-26 23:41:4579 bool external_preview,
80 bool show_system_dialog) {
81 DCHECK(!show_system_dialog);
[email protected]0c5e3022013-11-01 14:25:0182
83 if (settings_.dpi() == 0)
84 UseDefaultSettings();
85
[email protected]ea5e81d92011-11-08 18:45:1586 return OK;
87}
88
89PrintingContext::Result PrintingContextNoSystemDialog::InitWithSettings(
90 const PrintSettings& settings) {
91 DCHECK(!in_print_job_);
92
93 settings_ = settings;
94
95 return OK;
96}
97
98PrintingContext::Result PrintingContextNoSystemDialog::NewDocument(
[email protected]b5fa4ee2013-10-01 07:19:0799 const base::string16& document_name) {
[email protected]ea5e81d92011-11-08 18:45:15100 DCHECK(!in_print_job_);
101 in_print_job_ = true;
102
103 return OK;
104}
105
106PrintingContext::Result PrintingContextNoSystemDialog::NewPage() {
107 if (abort_printing_)
108 return CANCEL;
109 DCHECK(in_print_job_);
110
111 // Intentional No-op.
112
113 return OK;
114}
115
116PrintingContext::Result PrintingContextNoSystemDialog::PageDone() {
117 if (abort_printing_)
118 return CANCEL;
119 DCHECK(in_print_job_);
120
121 // Intentional No-op.
122
123 return OK;
124}
125
126PrintingContext::Result PrintingContextNoSystemDialog::DocumentDone() {
127 if (abort_printing_)
128 return CANCEL;
129 DCHECK(in_print_job_);
130
131 ResetSettings();
132 return OK;
133}
134
135void PrintingContextNoSystemDialog::Cancel() {
136 abort_printing_ = true;
137 in_print_job_ = false;
138}
139
140void PrintingContextNoSystemDialog::ReleaseContext() {
141 // Intentional No-op.
142}
143
144gfx::NativeDrawingContext PrintingContextNoSystemDialog::context() const {
145 // Intentional No-op.
146 return NULL;
147}
148
149} // namespace printing
150