Teach create_nmf.py about new toolchains' BFD format names
[chromium-blink-merge.git] / printing / printing_context_gtk.cc
blobd757df726fdb0cd581e26bcd0668b65d60389612
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 gfx::Size PrintingContextGtk::GetPdfPaperSizeDeviceUnits() {
82 GtkPageSetup* page_setup = gtk_page_setup_new();
84 gfx::SizeF paper_size(
85 gtk_page_setup_get_paper_width(page_setup, GTK_UNIT_INCH),
86 gtk_page_setup_get_paper_height(page_setup, GTK_UNIT_INCH));
88 g_object_unref(page_setup);
90 return gfx::Size(
91 paper_size.width() * settings_.device_units_per_inch(),
92 paper_size.height() * settings_.device_units_per_inch());
95 PrintingContext::Result PrintingContextGtk::UpdatePrinterSettings(
96 bool external_preview) {
97 DCHECK(!in_print_job_);
98 DCHECK(!external_preview) << "Not implemented";
100 if (!print_dialog_) {
101 print_dialog_ = create_dialog_func_(this);
102 print_dialog_->AddRefToDialog();
105 if (!print_dialog_->UpdateSettings(&settings_))
106 return OnError();
108 return OK;
111 PrintingContext::Result PrintingContextGtk::InitWithSettings(
112 const PrintSettings& settings) {
113 DCHECK(!in_print_job_);
115 settings_ = settings;
117 return OK;
120 PrintingContext::Result PrintingContextGtk::NewDocument(
121 const base::string16& document_name) {
122 DCHECK(!in_print_job_);
123 in_print_job_ = true;
125 document_name_ = document_name;
127 return OK;
130 PrintingContext::Result PrintingContextGtk::NewPage() {
131 if (abort_printing_)
132 return CANCEL;
133 DCHECK(in_print_job_);
135 // Intentional No-op.
137 return OK;
140 PrintingContext::Result PrintingContextGtk::PageDone() {
141 if (abort_printing_)
142 return CANCEL;
143 DCHECK(in_print_job_);
145 // Intentional No-op.
147 return OK;
150 PrintingContext::Result PrintingContextGtk::DocumentDone() {
151 if (abort_printing_)
152 return CANCEL;
153 DCHECK(in_print_job_);
155 ResetSettings();
156 return OK;
159 void PrintingContextGtk::Cancel() {
160 abort_printing_ = true;
161 in_print_job_ = false;
164 void PrintingContextGtk::ReleaseContext() {
165 // Intentional No-op.
168 gfx::NativeDrawingContext PrintingContextGtk::context() const {
169 // Intentional No-op.
170 return NULL;
173 } // namespace printing