diff options
author | thestig@chromium.org <thestig@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-04-11 04:58:20 +0000 |
---|---|---|
committer | thestig@chromium.org <thestig@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-04-11 04:58:20 +0000 |
commit | eaa389e3a4be9d9f87113043156cf6ac85f67c8d (patch) | |
tree | 5bf89af4a8b7a477dd2e878e08e98b9852333b47 /printing | |
parent | 9b6db26fcc22a7a4ec0510a93733b2e190d9e649 (diff) | |
download | chromium_src-eaa389e3a4be9d9f87113043156cf6ac85f67c8d.zip chromium_src-eaa389e3a4be9d9f87113043156cf6ac85f67c8d.tar.gz chromium_src-eaa389e3a4be9d9f87113043156cf6ac85f67c8d.tar.bz2 |
Linux: Refactor PrintDialogGtk in preparation for adding dialog-less printing.
BUG=none
TEST=Printing on Linux still works.
Review URL: http://codereview.chromium.org/6811016
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@81069 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'printing')
-rw-r--r-- | printing/print_dialog_gtk_interface.h | 39 | ||||
-rw-r--r-- | printing/printing.gyp | 1 | ||||
-rw-r--r-- | printing/printing_context_cairo.cc | 35 | ||||
-rw-r--r-- | printing/printing_context_cairo.h | 16 |
4 files changed, 62 insertions, 29 deletions
diff --git a/printing/print_dialog_gtk_interface.h b/printing/print_dialog_gtk_interface.h new file mode 100644 index 0000000..04198da --- /dev/null +++ b/printing/print_dialog_gtk_interface.h @@ -0,0 +1,39 @@ +// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef PRINTING_PRINT_DIALOG_GTK_INTERFACE_H_ +#define PRINTING_PRINT_DIALOG_GTK_INTERFACE_H_ + +#include "base/string16.h" +#include "printing/printing_context_cairo.h" + +namespace printing { + +// An interface for GTK printing dialogs. Classes that live outside of +// printing/ can implement this interface and get threading requirements +// correct without exposing those requirements to printing/. +class PrintDialogGtkInterface { + public: + // Shows the dialog and handles the response with |callback|. + virtual void ShowDialog( + PrintingContextCairo::PrintSettingsCallback* callback) = 0; + + // Prints the document named |document_name| contained in |metafile|. + // Called from the print worker thread. Once called, the + // PrintDialogGtkInterface instance should not be reused. + virtual void PrintDocument(const NativeMetafile* metafile, + const string16& document_name) = 0; + + // Same as AddRef/Release, but with different names since + // PrintDialogGtkInterface does not inherit from RefCounted. + virtual void AddRefToDialog() = 0; + virtual void ReleaseDialog() = 0; + + protected: + virtual ~PrintDialogGtkInterface() {} +}; + +} // namespace printing + +#endif // PRINTING_PRINT_DIALOG_GTK_INTERFACE_H_ diff --git a/printing/printing.gyp b/printing/printing.gyp index 87b9485..6e9afcb 100644 --- a/printing/printing.gyp +++ b/printing/printing.gyp @@ -70,6 +70,7 @@ 'printing_context_mac.h', 'printing_context_win.cc', 'printing_context_win.h', + 'print_dialog_gtk_interface.h', 'print_job_constants.cc', 'print_job_constants.h', 'print_settings.cc', diff --git a/printing/printing_context_cairo.cc b/printing/printing_context_cairo.cc index 7f31efb..d1c43f1 100644 --- a/printing/printing_context_cairo.cc +++ b/printing/printing_context_cairo.cc @@ -6,6 +6,7 @@ #include "base/logging.h" #include "base/values.h" +#include "printing/print_dialog_gtk_interface.h" #include "printing/print_job_constants.h" #include "printing/print_settings_initializer_gtk.h" #include "printing/units.h" @@ -19,22 +20,17 @@ #if !defined(OS_CHROMEOS) namespace { - // Function pointer for creating print dialogs. - static void* (*create_dialog_func_)( - printing::PrintingContext::PrintSettingsCallback* callback, + // Function pointer for creating print dialogs. |callback| is only used when + // |show_dialog| is true. + static printing::PrintDialogGtkInterface* (*create_dialog_func_)( printing::PrintingContextCairo* context) = NULL; - // Function pointer for printing documents. - static void (*print_document_func_)( - void* print_dialog, - const printing::NativeMetafile* metafile, - const string16& document_name) = NULL; } // namespace #endif // !defined(OS_CHROMEOS) namespace printing { // static - PrintingContext* PrintingContext::Create(const std::string& app_locale) { +PrintingContext* PrintingContext::Create(const std::string& app_locale) { return static_cast<PrintingContext*>(new PrintingContextCairo(app_locale)); } @@ -49,28 +45,25 @@ PrintingContextCairo::PrintingContextCairo(const std::string& app_locale) PrintingContextCairo::~PrintingContextCairo() { ReleaseContext(); + + if (print_dialog_) + print_dialog_->ReleaseDialog(); } #if !defined(OS_CHROMEOS) // static -void PrintingContextCairo::SetPrintingFunctions( - void* (*create_dialog_func)(PrintSettingsCallback* callback, - PrintingContextCairo* context), - void (*print_document_func)(void* print_dialog, - const NativeMetafile* metafile, - const string16& document_name)) { +void PrintingContextCairo::SetCreatePrintDialogFunction( + PrintDialogGtkInterface* (*create_dialog_func)( + PrintingContextCairo* context)) { DCHECK(create_dialog_func); - DCHECK(print_document_func); DCHECK(!create_dialog_func_); - DCHECK(!print_document_func_); create_dialog_func_ = create_dialog_func; - print_document_func_ = print_document_func; } void PrintingContextCairo::PrintDocument(const NativeMetafile* metafile) { DCHECK(print_dialog_); DCHECK(metafile); - print_document_func_(print_dialog_, metafile, document_name_); + print_dialog_->PrintDocument(metafile, document_name_); } #endif // !defined(OS_CHROMEOS) @@ -82,7 +75,9 @@ void PrintingContextCairo::AskUserForSettings( #if defined(OS_CHROMEOS) callback->Run(OK); #else - print_dialog_ = create_dialog_func_(callback, this); + print_dialog_ = create_dialog_func_(this); + print_dialog_->AddRefToDialog(); + print_dialog_->ShowDialog(callback); #endif // defined(OS_CHROMEOS) } diff --git a/printing/printing_context_cairo.h b/printing/printing_context_cairo.h index caee1e3..3002b06 100644 --- a/printing/printing_context_cairo.h +++ b/printing/printing_context_cairo.h @@ -15,20 +15,18 @@ namespace printing { +class PrintDialogGtkInterface; + class PrintingContextCairo : public PrintingContext { public: explicit PrintingContextCairo(const std::string& app_locale); ~PrintingContextCairo(); #if !defined(OS_CHROMEOS) - // Sets the function that creates the print dialog, and the function that - // prints the document. - static void SetPrintingFunctions( - void* (*create_dialog_func)(PrintSettingsCallback* callback, - PrintingContextCairo* context), - void (*print_document_func)(void* print_dialog, - const NativeMetafile* metafile, - const string16& document_name)); + // Sets the function that creates the print dialog. + static void SetCreatePrintDialogFunction( + PrintDialogGtkInterface* (*create_dialog_func)( + PrintingContextCairo* context)); // Prints the document contained in |metafile|. void PrintDocument(const NativeMetafile* metafile); @@ -54,7 +52,7 @@ class PrintingContextCairo : public PrintingContext { private: #if !defined(OS_CHROMEOS) string16 document_name_; - void* print_dialog_; + PrintDialogGtkInterface* print_dialog_; #endif DISALLOW_COPY_AND_ASSIGN(PrintingContextCairo); |