Views Omnibox: tolerate minor click-to-select-all dragging.
[chromium-blink-merge.git] / printing / printing_context_linux.cc
blob98ed2e73d191af59fd7df0cbdd9b06d2379144e5
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 PrintingContext* PrintingContext::Create(const std::string& app_locale) {
31 return static_cast<PrintingContext*>(new PrintingContextLinux(app_locale));
34 PrintingContextLinux::PrintingContextLinux(const std::string& app_locale)
35 : PrintingContext(app_locale),
36 print_dialog_(NULL) {
39 PrintingContextLinux::~PrintingContextLinux() {
40 ReleaseContext();
42 if (print_dialog_)
43 print_dialog_->ReleaseDialog();
46 // static
47 void PrintingContextLinux::SetCreatePrintDialogFunction(
48 PrintDialogGtkInterface* (*create_dialog_func)(
49 PrintingContextLinux* context)) {
50 DCHECK(create_dialog_func);
51 DCHECK(!create_dialog_func_);
52 create_dialog_func_ = create_dialog_func;
55 // static
56 void PrintingContextLinux::SetPdfPaperSizeFunction(
57 gfx::Size (*get_pdf_paper_size)(PrintingContextLinux* context)) {
58 DCHECK(get_pdf_paper_size);
59 DCHECK(!get_pdf_paper_size_);
60 get_pdf_paper_size_ = get_pdf_paper_size;
63 void PrintingContextLinux::PrintDocument(const Metafile* metafile) {
64 DCHECK(print_dialog_);
65 DCHECK(metafile);
66 print_dialog_->PrintDocument(metafile, document_name_);
69 void PrintingContextLinux::AskUserForSettings(
70 gfx::NativeView parent_view,
71 int max_pages,
72 bool has_selection,
73 const PrintSettingsCallback& callback) {
74 print_dialog_->ShowDialog(parent_view, has_selection, callback);
77 PrintingContext::Result PrintingContextLinux::UseDefaultSettings() {
78 DCHECK(!in_print_job_);
80 ResetSettings();
82 if (!create_dialog_func_)
83 return OK;
85 if (!print_dialog_) {
86 print_dialog_ = create_dialog_func_(this);
87 print_dialog_->AddRefToDialog();
89 print_dialog_->UseDefaultSettings();
91 return OK;
94 gfx::Size PrintingContextLinux::GetPdfPaperSizeDeviceUnits() {
95 if (get_pdf_paper_size_)
96 return get_pdf_paper_size_(this);
98 return gfx::Size();
101 PrintingContext::Result PrintingContextLinux::UpdatePrinterSettings(
102 bool external_preview) {
103 DCHECK(!in_print_job_);
104 DCHECK(!external_preview) << "Not implemented";
106 if (!create_dialog_func_)
107 return OK;
109 if (!print_dialog_) {
110 print_dialog_ = create_dialog_func_(this);
111 print_dialog_->AddRefToDialog();
114 if (!print_dialog_->UpdateSettings(&settings_))
115 return OnError();
117 return OK;
120 PrintingContext::Result PrintingContextLinux::InitWithSettings(
121 const PrintSettings& settings) {
122 DCHECK(!in_print_job_);
124 settings_ = settings;
126 return OK;
129 PrintingContext::Result PrintingContextLinux::NewDocument(
130 const base::string16& document_name) {
131 DCHECK(!in_print_job_);
132 in_print_job_ = true;
134 document_name_ = document_name;
136 return OK;
139 PrintingContext::Result PrintingContextLinux::NewPage() {
140 if (abort_printing_)
141 return CANCEL;
142 DCHECK(in_print_job_);
144 // Intentional No-op.
146 return OK;
149 PrintingContext::Result PrintingContextLinux::PageDone() {
150 if (abort_printing_)
151 return CANCEL;
152 DCHECK(in_print_job_);
154 // Intentional No-op.
156 return OK;
159 PrintingContext::Result PrintingContextLinux::DocumentDone() {
160 if (abort_printing_)
161 return CANCEL;
162 DCHECK(in_print_job_);
164 ResetSettings();
165 return OK;
168 void PrintingContextLinux::Cancel() {
169 abort_printing_ = true;
170 in_print_job_ = false;
173 void PrintingContextLinux::ReleaseContext() {
174 // Intentional No-op.
177 gfx::NativeDrawingContext PrintingContextLinux::context() const {
178 // Intentional No-op.
179 return NULL;
182 } // namespace printing