| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef CHROME_BROWSER_PRINTING_PRINT_DIALOG_GTK_H_ | 5 #ifndef CHROME_BROWSER_PRINTING_PRINT_DIALOG_GTK_H_ |
| 6 #define CHROME_BROWSER_PRINTING_PRINT_DIALOG_GTK_H_ | 6 #define CHROME_BROWSER_PRINTING_PRINT_DIALOG_GTK_H_ |
| 7 #pragma once | 7 #pragma once |
| 8 | 8 |
| 9 #include <gtk/gtk.h> | 9 #include <gtk/gtk.h> |
| 10 #include <gtk/gtkprintunixdialog.h> | 10 #include <gtk/gtkprintunixdialog.h> |
| 11 | 11 |
| 12 #include "base/compiler_specific.h" | 12 #include "base/compiler_specific.h" |
| 13 #include "base/file_path.h" | 13 #include "base/file_path.h" |
| 14 #include "base/memory/ref_counted.h" | 14 #include "base/memory/ref_counted.h" |
| 15 #include "base/memory/scoped_ptr.h" | 15 #include "base/memory/scoped_ptr.h" |
| 16 #include "content/public/browser/browser_thread.h" | 16 #include "content/public/browser/browser_thread.h" |
| 17 #include "printing/print_dialog_gtk_interface.h" | 17 #include "printing/print_dialog_gtk_interface.h" |
| 18 #include "printing/printing_context_cairo.h" | 18 #include "printing/printing_context_gtk.h" |
| 19 #include "ui/base/gtk/gtk_signal.h" | 19 #include "ui/base/gtk/gtk_signal.h" |
| 20 | 20 |
| 21 namespace printing { | 21 namespace printing { |
| 22 class Metafile; | 22 class Metafile; |
| 23 class PrintSettings; | 23 class PrintSettings; |
| 24 } | 24 } |
| 25 | 25 |
| 26 using printing::PrintingContextCairo; | 26 using printing::PrintingContextGtk; |
| 27 | 27 |
| 28 // Needs to be freed on the UI thread to clean up its GTK members variables. | 28 // Needs to be freed on the UI thread to clean up its GTK members variables. |
| 29 class PrintDialogGtk | 29 class PrintDialogGtk |
| 30 : public printing::PrintDialogGtkInterface, | 30 : public printing::PrintDialogGtkInterface, |
| 31 public base::RefCountedThreadSafe< | 31 public base::RefCountedThreadSafe< |
| 32 PrintDialogGtk, content::BrowserThread::DeleteOnUIThread> { | 32 PrintDialogGtk, content::BrowserThread::DeleteOnUIThread> { |
| 33 public: | 33 public: |
| 34 // Creates and returns a print dialog. | 34 // Creates and returns a print dialog. |
| 35 static printing::PrintDialogGtkInterface* CreatePrintDialog( | 35 static printing::PrintDialogGtkInterface* CreatePrintDialog( |
| 36 PrintingContextCairo* context); | 36 PrintingContextGtk* context); |
| 37 | 37 |
| 38 // printing::PrintDialogGtkInterface implementation. | 38 // printing::PrintDialogGtkInterface implementation. |
| 39 virtual void UseDefaultSettings() OVERRIDE; | 39 virtual void UseDefaultSettings() OVERRIDE; |
| 40 virtual bool UpdateSettings(const base::DictionaryValue& job_settings, | 40 virtual bool UpdateSettings(const base::DictionaryValue& job_settings, |
| 41 const printing::PageRanges& ranges, | 41 const printing::PageRanges& ranges, |
| 42 printing::PrintSettings* settings) OVERRIDE; | 42 printing::PrintSettings* settings) OVERRIDE; |
| 43 virtual void ShowDialog( | 43 virtual void ShowDialog( |
| 44 PrintingContextCairo::PrintSettingsCallback* callback) OVERRIDE; | 44 PrintingContextGtk::PrintSettingsCallback* callback) OVERRIDE; |
| 45 virtual void PrintDocument(const printing::Metafile* metafile, | 45 virtual void PrintDocument(const printing::Metafile* metafile, |
| 46 const string16& document_name) OVERRIDE; | 46 const string16& document_name) OVERRIDE; |
| 47 virtual void AddRefToDialog() OVERRIDE; | 47 virtual void AddRefToDialog() OVERRIDE; |
| 48 virtual void ReleaseDialog() OVERRIDE; | 48 virtual void ReleaseDialog() OVERRIDE; |
| 49 | 49 |
| 50 private: | 50 private: |
| 51 friend struct content::BrowserThread::DeleteOnThread< | 51 friend struct content::BrowserThread::DeleteOnThread< |
| 52 content::BrowserThread::UI>; | 52 content::BrowserThread::UI>; |
| 53 friend class DeleteTask<PrintDialogGtk>; | 53 friend class DeleteTask<PrintDialogGtk>; |
| 54 | 54 |
| 55 explicit PrintDialogGtk(PrintingContextCairo* context); | 55 explicit PrintDialogGtk(PrintingContextGtk* context); |
| 56 virtual ~PrintDialogGtk(); | 56 virtual ~PrintDialogGtk(); |
| 57 | 57 |
| 58 // Handles dialog response. | 58 // Handles dialog response. |
| 59 CHROMEGTK_CALLBACK_1(PrintDialogGtk, void, OnResponse, int); | 59 CHROMEGTK_CALLBACK_1(PrintDialogGtk, void, OnResponse, int); |
| 60 | 60 |
| 61 // Prints document named |document_name|. | 61 // Prints document named |document_name|. |
| 62 void SendDocumentToPrinter(const string16& document_name); | 62 void SendDocumentToPrinter(const string16& document_name); |
| 63 | 63 |
| 64 // Handles print job response. | 64 // Handles print job response. |
| 65 static void OnJobCompletedThunk(GtkPrintJob* print_job, | 65 static void OnJobCompletedThunk(GtkPrintJob* print_job, |
| 66 gpointer user_data, | 66 gpointer user_data, |
| 67 GError* error); | 67 GError* error); |
| 68 void OnJobCompleted(GtkPrintJob* print_job, GError* error); | 68 void OnJobCompleted(GtkPrintJob* print_job, GError* error); |
| 69 | 69 |
| 70 // Helper function for initializing |context_|'s PrintSettings with a given | 70 // Helper function for initializing |context_|'s PrintSettings with a given |
| 71 // set of |page_ranges| and |settings|. | 71 // set of |page_ranges| and |settings|. |
| 72 void InitPrintSettings(const printing::PageRanges& page_ranges, | 72 void InitPrintSettings(const printing::PageRanges& page_ranges, |
| 73 printing::PrintSettings* settings); | 73 printing::PrintSettings* settings); |
| 74 | 74 |
| 75 // Printing dialog callback. | 75 // Printing dialog callback. |
| 76 PrintingContextCairo::PrintSettingsCallback* callback_; | 76 PrintingContextGtk::PrintSettingsCallback* callback_; |
| 77 PrintingContextCairo* context_; | 77 PrintingContextGtk* context_; |
| 78 | 78 |
| 79 // Print dialog settings. PrintDialogGtk owns |dialog_| and holds references | 79 // Print dialog settings. PrintDialogGtk owns |dialog_| and holds references |
| 80 // to the other objects. | 80 // to the other objects. |
| 81 GtkWidget* dialog_; | 81 GtkWidget* dialog_; |
| 82 GtkPrintSettings* gtk_settings_; | 82 GtkPrintSettings* gtk_settings_; |
| 83 GtkPageSetup* page_setup_; | 83 GtkPageSetup* page_setup_; |
| 84 GtkPrinter* printer_; | 84 GtkPrinter* printer_; |
| 85 | 85 |
| 86 FilePath path_to_pdf_; | 86 FilePath path_to_pdf_; |
| 87 | 87 |
| 88 DISALLOW_COPY_AND_ASSIGN(PrintDialogGtk); | 88 DISALLOW_COPY_AND_ASSIGN(PrintDialogGtk); |
| 89 }; | 89 }; |
| 90 | 90 |
| 91 #endif // CHROME_BROWSER_PRINTING_PRINT_DIALOG_GTK_H_ | 91 #endif // CHROME_BROWSER_PRINTING_PRINT_DIALOG_GTK_H_ |
| OLD | NEW |