1 // 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.
5 #include "printing/printing_context_no_system_dialog.h"
7 #include <unicode/ulocdata.h>
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"
18 PrintingContext
* PrintingContext::Create(const std::string
& app_locale
) {
19 return static_cast<PrintingContext
*>(
20 new PrintingContextNoSystemDialog(app_locale
));
23 PrintingContextNoSystemDialog::PrintingContextNoSystemDialog(
24 const std::string
& app_locale
) : PrintingContext(app_locale
) {
27 PrintingContextNoSystemDialog::~PrintingContextNoSystemDialog() {
31 void PrintingContextNoSystemDialog::AskUserForSettings(
32 gfx::NativeView parent_view
,
35 const PrintSettingsCallback
& callback
) {
36 // We don't want to bring up a dialog here. Ever. Just signal the callback.
40 PrintingContext::Result
PrintingContextNoSystemDialog::UseDefaultSettings() {
41 DCHECK(!in_print_job_
);
44 // TODO(abodenha): Fetch these settings from the OS where possible. See
46 // TODO(sanjeevr): We need a better feedback loop between the cloud print
47 // dialog and this code.
49 gfx::Size physical_size_device_units
;
50 gfx::Rect printable_area_device_units
;
53 UErrorCode error
= U_ZERO_ERROR
;
54 ulocdata_getPaperSize(app_locale_
.c_str(), &height
, &width
, &error
);
55 if (error
> U_ZERO_ERROR
) {
56 // If the call failed, assume a paper size of 8.5 x 11 inches.
57 LOG(WARNING
) << "ulocdata_getPaperSize failed, using 8.5 x 11, error: "
59 width
= static_cast<int>(8.5 * dpi
);
60 height
= static_cast<int>(11 * dpi
);
62 // ulocdata_getPaperSize returns the width and height in mm.
63 // Convert this to pixels based on the dpi.
64 width
= static_cast<int>(ConvertUnitDouble(width
, 25.4, 1.0) * dpi
);
65 height
= static_cast<int>(ConvertUnitDouble(height
, 25.4, 1.0) * dpi
);
68 physical_size_device_units
.SetSize(width
, height
);
70 // Assume full page is printable for now.
71 printable_area_device_units
.SetRect(0, 0, width
, height
);
73 settings_
.set_dpi(dpi
);
74 settings_
.SetPrinterPrintableArea(physical_size_device_units
,
75 printable_area_device_units
,
81 PrintingContext::Result
PrintingContextNoSystemDialog::UpdatePrinterSettings(
82 const DictionaryValue
& job_settings
, const PageRanges
& ranges
) {
83 bool landscape
= false;
85 if (!job_settings
.GetBoolean(kSettingLandscape
, &landscape
))
88 if (settings_
.dpi() == 0)
91 settings_
.SetOrientation(landscape
);
92 settings_
.ranges
= ranges
;
97 PrintingContext::Result
PrintingContextNoSystemDialog::InitWithSettings(
98 const PrintSettings
& settings
) {
99 DCHECK(!in_print_job_
);
101 settings_
= settings
;
106 PrintingContext::Result
PrintingContextNoSystemDialog::NewDocument(
107 const string16
& document_name
) {
108 DCHECK(!in_print_job_
);
109 in_print_job_
= true;
114 PrintingContext::Result
PrintingContextNoSystemDialog::NewPage() {
117 DCHECK(in_print_job_
);
119 // Intentional No-op.
124 PrintingContext::Result
PrintingContextNoSystemDialog::PageDone() {
127 DCHECK(in_print_job_
);
129 // Intentional No-op.
134 PrintingContext::Result
PrintingContextNoSystemDialog::DocumentDone() {
137 DCHECK(in_print_job_
);
143 void PrintingContextNoSystemDialog::Cancel() {
144 abort_printing_
= true;
145 in_print_job_
= false;
148 void PrintingContextNoSystemDialog::ReleaseContext() {
149 // Intentional No-op.
152 gfx::NativeDrawingContext
PrintingContextNoSystemDialog::context() const {
153 // Intentional No-op.
157 } // namespace printing