Revert 162447 - Temporarily remove "Swap primary monitor" from keyboard overlay for...
[chromium-blink-merge.git] / printing / printing_context_gtk.cc
blob4bfa666b2365527b45fa937851ee3e6e15d10654
1 // Copyright (c) 2012 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_gtk.h"
7 #include <gtk/gtk.h>
8 #include <gtk/gtkunixprint.h>
10 #include "base/logging.h"
11 #include "base/values.h"
12 #include "printing/metafile.h"
13 #include "printing/print_dialog_gtk_interface.h"
14 #include "printing/print_job_constants.h"
15 #include "printing/units.h"
17 namespace {
19 // Function pointer for creating print dialogs. |callback| is only used when
20 // |show_dialog| is true.
21 printing::PrintDialogGtkInterface* (*create_dialog_func_)(
22 printing::PrintingContextGtk* context) = NULL;
24 } // namespace
26 namespace printing {
28 // static
29 PrintingContext* PrintingContext::Create(const std::string& app_locale) {
30 return static_cast<PrintingContext*>(new PrintingContextGtk(app_locale));
33 PrintingContextGtk::PrintingContextGtk(const std::string& app_locale)
34 : PrintingContext(app_locale),
35 print_dialog_(NULL) {
38 PrintingContextGtk::~PrintingContextGtk() {
39 ReleaseContext();
41 if (print_dialog_)
42 print_dialog_->ReleaseDialog();
45 // static
46 void PrintingContextGtk::SetCreatePrintDialogFunction(
47 PrintDialogGtkInterface* (*create_dialog_func)(
48 PrintingContextGtk* context)) {
49 DCHECK(create_dialog_func);
50 DCHECK(!create_dialog_func_);
51 create_dialog_func_ = create_dialog_func;
54 void PrintingContextGtk::PrintDocument(const Metafile* metafile) {
55 DCHECK(print_dialog_);
56 DCHECK(metafile);
57 print_dialog_->PrintDocument(metafile, document_name_);
60 void PrintingContextGtk::AskUserForSettings(
61 gfx::NativeView parent_view,
62 int max_pages,
63 bool has_selection,
64 const PrintSettingsCallback& callback) {
65 print_dialog_->ShowDialog(parent_view, has_selection, callback);
68 PrintingContext::Result PrintingContextGtk::UseDefaultSettings() {
69 DCHECK(!in_print_job_);
71 ResetSettings();
72 if (!print_dialog_) {
73 print_dialog_ = create_dialog_func_(this);
74 print_dialog_->AddRefToDialog();
76 print_dialog_->UseDefaultSettings();
78 return OK;
81 PrintingContext::Result PrintingContextGtk::UpdatePrinterSettings(
82 const DictionaryValue& job_settings, const PageRanges& ranges) {
83 DCHECK(!in_print_job_);
85 if (!print_dialog_) {
86 print_dialog_ = create_dialog_func_(this);
87 print_dialog_->AddRefToDialog();
90 if (!print_dialog_->UpdateSettings(job_settings, ranges, &settings_))
91 return OnError();
93 return OK;
96 PrintingContext::Result PrintingContextGtk::InitWithSettings(
97 const PrintSettings& settings) {
98 DCHECK(!in_print_job_);
100 settings_ = settings;
102 return OK;
105 PrintingContext::Result PrintingContextGtk::NewDocument(
106 const string16& document_name) {
107 DCHECK(!in_print_job_);
108 in_print_job_ = true;
110 document_name_ = document_name;
112 return OK;
115 PrintingContext::Result PrintingContextGtk::NewPage() {
116 if (abort_printing_)
117 return CANCEL;
118 DCHECK(in_print_job_);
120 // Intentional No-op.
122 return OK;
125 PrintingContext::Result PrintingContextGtk::PageDone() {
126 if (abort_printing_)
127 return CANCEL;
128 DCHECK(in_print_job_);
130 // Intentional No-op.
132 return OK;
135 PrintingContext::Result PrintingContextGtk::DocumentDone() {
136 if (abort_printing_)
137 return CANCEL;
138 DCHECK(in_print_job_);
140 ResetSettings();
141 return OK;
144 void PrintingContextGtk::Cancel() {
145 abort_printing_ = true;
146 in_print_job_ = false;
149 void PrintingContextGtk::ReleaseContext() {
150 // Intentional No-op.
153 gfx::NativeDrawingContext PrintingContextGtk::context() const {
154 // Intentional No-op.
155 return NULL;
158 } // namespace printing