Implement nacl_irt_memory for non-sfi mode.
[chromium-blink-merge.git] / printing / printing_context_no_system_dialog.cc
blob4768e4d3a3d65ffce2285fb8631bbc593dc0ad98
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"
15 namespace printing {
17 // static
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() {
28 ReleaseContext();
31 void PrintingContextNoSystemDialog::AskUserForSettings(
32 gfx::NativeView parent_view,
33 int max_pages,
34 bool has_selection,
35 const PrintSettingsCallback& callback) {
36 // We don't want to bring up a dialog here. Ever. Just signal the callback.
37 callback.Run(OK);
40 PrintingContext::Result PrintingContextNoSystemDialog::UseDefaultSettings() {
41 DCHECK(!in_print_job_);
43 ResetSettings();
44 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;
53 gfx::Size PrintingContextNoSystemDialog::GetPdfPaperSizeDeviceUnits() {
54 int32_t width = 0;
55 int32_t height = 0;
56 UErrorCode error = U_ZERO_ERROR;
57 ulocdata_getPaperSize(app_locale_.c_str(), &height, &width, &error);
58 if (error > U_ZERO_ERROR) {
59 // If the call failed, assume a paper size of 8.5 x 11 inches.
60 LOG(WARNING) << "ulocdata_getPaperSize failed, using 8.5 x 11, error: "
61 << error;
62 width = static_cast<int>(
63 kLetterWidthInch * settings_.device_units_per_inch());
64 height = static_cast<int>(
65 kLetterHeightInch * settings_.device_units_per_inch());
66 } else {
67 // ulocdata_getPaperSize returns the width and height in mm.
68 // Convert this to pixels based on the dpi.
69 float multiplier = 100 * settings_.device_units_per_inch();
70 multiplier /= kHundrethsMMPerInch;
71 width *= multiplier;
72 height *= multiplier;
74 return gfx::Size(width, height);
77 PrintingContext::Result PrintingContextNoSystemDialog::UpdatePrinterSettings(
78 bool external_preview) {
80 if (settings_.dpi() == 0)
81 UseDefaultSettings();
83 return OK;
86 PrintingContext::Result PrintingContextNoSystemDialog::InitWithSettings(
87 const PrintSettings& settings) {
88 DCHECK(!in_print_job_);
90 settings_ = settings;
92 return OK;
95 PrintingContext::Result PrintingContextNoSystemDialog::NewDocument(
96 const base::string16& document_name) {
97 DCHECK(!in_print_job_);
98 in_print_job_ = true;
100 return OK;
103 PrintingContext::Result PrintingContextNoSystemDialog::NewPage() {
104 if (abort_printing_)
105 return CANCEL;
106 DCHECK(in_print_job_);
108 // Intentional No-op.
110 return OK;
113 PrintingContext::Result PrintingContextNoSystemDialog::PageDone() {
114 if (abort_printing_)
115 return CANCEL;
116 DCHECK(in_print_job_);
118 // Intentional No-op.
120 return OK;
123 PrintingContext::Result PrintingContextNoSystemDialog::DocumentDone() {
124 if (abort_printing_)
125 return CANCEL;
126 DCHECK(in_print_job_);
128 ResetSettings();
129 return OK;
132 void PrintingContextNoSystemDialog::Cancel() {
133 abort_printing_ = true;
134 in_print_job_ = false;
137 void PrintingContextNoSystemDialog::ReleaseContext() {
138 // Intentional No-op.
141 gfx::NativeDrawingContext PrintingContextNoSystemDialog::context() const {
142 // Intentional No-op.
143 return NULL;
146 } // namespace printing