Update V8 to version 4.5.92.
[chromium-blink-merge.git] / printing / printing_context_no_system_dialog.cc
blob746232a6ba735b5f0986e0d6c758badf6c486fd7
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 bool is_scripted,
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(
58 delegate_->GetAppLocale().c_str(), &height, &width, &error);
59 if (error > U_ZERO_ERROR) {
60 // 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;
63 width = static_cast<int>(
64 kLetterWidthInch * settings_.device_units_per_inch());
65 height = static_cast<int>(
66 kLetterHeightInch * settings_.device_units_per_inch());
67 } else {
68 // ulocdata_getPaperSize returns the width and height in mm.
69 // Convert this to pixels based on the dpi.
70 float multiplier = 100 * settings_.device_units_per_inch();
71 multiplier /= kHundrethsMMPerInch;
72 width *= multiplier;
73 height *= multiplier;
75 return gfx::Size(width, height);
78 PrintingContext::Result PrintingContextNoSystemDialog::UpdatePrinterSettings(
79 bool external_preview,
80 bool show_system_dialog,
81 int page_count) {
82 DCHECK(!show_system_dialog);
84 if (settings_.dpi() == 0)
85 UseDefaultSettings();
87 return OK;
90 PrintingContext::Result PrintingContextNoSystemDialog::InitWithSettings(
91 const PrintSettings& settings) {
92 DCHECK(!in_print_job_);
94 settings_ = settings;
96 return OK;
99 PrintingContext::Result PrintingContextNoSystemDialog::NewDocument(
100 const base::string16& document_name) {
101 DCHECK(!in_print_job_);
102 in_print_job_ = true;
104 return OK;
107 PrintingContext::Result PrintingContextNoSystemDialog::NewPage() {
108 if (abort_printing_)
109 return CANCEL;
110 DCHECK(in_print_job_);
112 // Intentional No-op.
114 return OK;
117 PrintingContext::Result PrintingContextNoSystemDialog::PageDone() {
118 if (abort_printing_)
119 return CANCEL;
120 DCHECK(in_print_job_);
122 // Intentional No-op.
124 return OK;
127 PrintingContext::Result PrintingContextNoSystemDialog::DocumentDone() {
128 if (abort_printing_)
129 return CANCEL;
130 DCHECK(in_print_job_);
132 ResetSettings();
133 return OK;
136 void PrintingContextNoSystemDialog::Cancel() {
137 abort_printing_ = true;
138 in_print_job_ = false;
141 void PrintingContextNoSystemDialog::ReleaseContext() {
142 // Intentional No-op.
145 gfx::NativeDrawingContext PrintingContextNoSystemDialog::context() const {
146 // Intentional No-op.
147 return NULL;
150 } // namespace printing