The DisplayVirtualKeyboard function on Windows 8 and beyond should not be displaying...
[chromium-blink-merge.git] / printing / printing_context_no_system_dialog.cc
blob7ae10ddaad06a6f15e326d087809ee3a801b4813
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 scoped_ptr<PrintingContext> PrintingContext::Create(Delegate* delegate) {
19 return make_scoped_ptr<PrintingContext>(
20 new PrintingContextNoSystemDialog(delegate));
23 PrintingContextNoSystemDialog::PrintingContextNoSystemDialog(Delegate* delegate)
24 : PrintingContext(delegate) {
27 PrintingContextNoSystemDialog::~PrintingContextNoSystemDialog() {
28 ReleaseContext();
31 void PrintingContextNoSystemDialog::AskUserForSettings(
32 int max_pages,
33 bool has_selection,
34 const PrintSettingsCallback& callback) {
35 // We don't want to bring up a dialog here. Ever. Just signal the callback.
36 callback.Run(OK);
39 PrintingContext::Result PrintingContextNoSystemDialog::UseDefaultSettings() {
40 DCHECK(!in_print_job_);
42 ResetSettings();
43 settings_.set_dpi(kDefaultPdfDpi);
44 gfx::Size physical_size = GetPdfPaperSizeDeviceUnits();
45 // Assume full page is printable for now.
46 gfx::Rect printable_area(0, 0, physical_size.width(), physical_size.height());
47 DCHECK_EQ(settings_.device_units_per_inch(), kDefaultPdfDpi);
48 settings_.SetPrinterPrintableArea(physical_size, printable_area, true);
49 return OK;
52 gfx::Size PrintingContextNoSystemDialog::GetPdfPaperSizeDeviceUnits() {
53 int32_t width = 0;
54 int32_t height = 0;
55 UErrorCode error = U_ZERO_ERROR;
56 ulocdata_getPaperSize(
57 delegate_->GetAppLocale().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,
79 bool show_system_dialog) {
80 DCHECK(!show_system_dialog);
82 if (settings_.dpi() == 0)
83 UseDefaultSettings();
85 return OK;
88 PrintingContext::Result PrintingContextNoSystemDialog::InitWithSettings(
89 const PrintSettings& settings) {
90 DCHECK(!in_print_job_);
92 settings_ = settings;
94 return OK;
97 PrintingContext::Result PrintingContextNoSystemDialog::NewDocument(
98 const base::string16& document_name) {
99 DCHECK(!in_print_job_);
100 in_print_job_ = true;
102 return OK;
105 PrintingContext::Result PrintingContextNoSystemDialog::NewPage() {
106 if (abort_printing_)
107 return CANCEL;
108 DCHECK(in_print_job_);
110 // Intentional No-op.
112 return OK;
115 PrintingContext::Result PrintingContextNoSystemDialog::PageDone() {
116 if (abort_printing_)
117 return CANCEL;
118 DCHECK(in_print_job_);
120 // Intentional No-op.
122 return OK;
125 PrintingContext::Result PrintingContextNoSystemDialog::DocumentDone() {
126 if (abort_printing_)
127 return CANCEL;
128 DCHECK(in_print_job_);
130 ResetSettings();
131 return OK;
134 void PrintingContextNoSystemDialog::Cancel() {
135 abort_printing_ = true;
136 in_print_job_ = false;
139 void PrintingContextNoSystemDialog::ReleaseContext() {
140 // Intentional No-op.
143 gfx::NativeDrawingContext PrintingContextNoSystemDialog::context() const {
144 // Intentional No-op.
145 return NULL;
148 } // namespace printing