Updating XTBs based on .GRDs from branch master
[chromium-blink-merge.git] / printing / printing_context_linux.cc
blob83d321ecf6ae3e6381875d376691d26301b14a65
1 // Copyright 2014 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_linux.h"
7 #include "base/logging.h"
8 #include "base/values.h"
9 #include "printing/metafile.h"
10 #include "printing/print_dialog_gtk_interface.h"
11 #include "printing/print_job_constants.h"
12 #include "printing/units.h"
14 namespace {
16 // Function pointer for creating print dialogs. |callback| is only used when
17 // |show_dialog| is true.
18 printing::PrintDialogGtkInterface* (*create_dialog_func_)(
19 printing::PrintingContextLinux* context) = NULL;
21 // Function pointer for determining paper size.
22 gfx::Size (*get_pdf_paper_size_)(
23 printing::PrintingContextLinux* context) = NULL;
25 } // namespace
27 namespace printing {
29 // static
30 scoped_ptr<PrintingContext> PrintingContext::Create(Delegate* delegate) {
31 return make_scoped_ptr<PrintingContext>(new PrintingContextLinux(delegate));
34 PrintingContextLinux::PrintingContextLinux(Delegate* delegate)
35 : PrintingContext(delegate), print_dialog_(NULL) {
38 PrintingContextLinux::~PrintingContextLinux() {
39 ReleaseContext();
41 if (print_dialog_)
42 print_dialog_->ReleaseDialog();
45 // static
46 void PrintingContextLinux::SetCreatePrintDialogFunction(
47 PrintDialogGtkInterface* (*create_dialog_func)(
48 PrintingContextLinux* context)) {
49 DCHECK(create_dialog_func);
50 DCHECK(!create_dialog_func_);
51 create_dialog_func_ = create_dialog_func;
54 // static
55 void PrintingContextLinux::SetPdfPaperSizeFunction(
56 gfx::Size (*get_pdf_paper_size)(PrintingContextLinux* context)) {
57 DCHECK(get_pdf_paper_size);
58 DCHECK(!get_pdf_paper_size_);
59 get_pdf_paper_size_ = get_pdf_paper_size;
62 void PrintingContextLinux::PrintDocument(const MetafilePlayer& metafile) {
63 DCHECK(print_dialog_);
64 print_dialog_->PrintDocument(metafile, document_name_);
67 void PrintingContextLinux::AskUserForSettings(
68 int max_pages,
69 bool has_selection,
70 bool is_scripted,
71 const PrintSettingsCallback& callback) {
72 if (!print_dialog_) {
73 // Can only get here if the renderer is sending bad messages.
74 // http://crbug.com/341777
75 NOTREACHED();
76 callback.Run(FAILED);
77 return;
80 print_dialog_->ShowDialog(
81 delegate_->GetParentView(), has_selection, callback);
84 PrintingContext::Result PrintingContextLinux::UseDefaultSettings() {
85 DCHECK(!in_print_job_);
87 ResetSettings();
89 if (!create_dialog_func_)
90 return OK;
92 if (!print_dialog_) {
93 print_dialog_ = create_dialog_func_(this);
94 print_dialog_->AddRefToDialog();
96 print_dialog_->UseDefaultSettings();
98 return OK;
101 gfx::Size PrintingContextLinux::GetPdfPaperSizeDeviceUnits() {
102 if (get_pdf_paper_size_)
103 return get_pdf_paper_size_(this);
105 return gfx::Size();
108 PrintingContext::Result PrintingContextLinux::UpdatePrinterSettings(
109 bool external_preview,
110 bool show_system_dialog,
111 int page_count) {
112 DCHECK(!show_system_dialog);
113 DCHECK(!in_print_job_);
114 DCHECK(!external_preview) << "Not implemented";
116 if (!create_dialog_func_)
117 return OK;
119 if (!print_dialog_) {
120 print_dialog_ = create_dialog_func_(this);
121 print_dialog_->AddRefToDialog();
124 if (!print_dialog_->UpdateSettings(&settings_))
125 return OnError();
127 return OK;
130 PrintingContext::Result PrintingContextLinux::InitWithSettings(
131 const PrintSettings& settings) {
132 DCHECK(!in_print_job_);
134 settings_ = settings;
136 return OK;
139 PrintingContext::Result PrintingContextLinux::NewDocument(
140 const base::string16& document_name) {
141 DCHECK(!in_print_job_);
142 in_print_job_ = true;
144 document_name_ = document_name;
146 return OK;
149 PrintingContext::Result PrintingContextLinux::NewPage() {
150 if (abort_printing_)
151 return CANCEL;
152 DCHECK(in_print_job_);
154 // Intentional No-op.
156 return OK;
159 PrintingContext::Result PrintingContextLinux::PageDone() {
160 if (abort_printing_)
161 return CANCEL;
162 DCHECK(in_print_job_);
164 // Intentional No-op.
166 return OK;
169 PrintingContext::Result PrintingContextLinux::DocumentDone() {
170 if (abort_printing_)
171 return CANCEL;
172 DCHECK(in_print_job_);
174 ResetSettings();
175 return OK;
178 void PrintingContextLinux::Cancel() {
179 abort_printing_ = true;
180 in_print_job_ = false;
183 void PrintingContextLinux::ReleaseContext() {
184 // Intentional No-op.
187 gfx::NativeDrawingContext PrintingContextLinux::context() const {
188 // Intentional No-op.
189 return NULL;
192 } // namespace printing