print_dialog_gtk.h 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  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.
  4. #ifndef UI_GTK_PRINTING_PRINT_DIALOG_GTK_H_
  5. #define UI_GTK_PRINTING_PRINT_DIALOG_GTK_H_
  6. #include <memory>
  7. #include "base/files/file_path.h"
  8. #include "base/memory/raw_ptr.h"
  9. #include "base/memory/ref_counted_delete_on_sequence.h"
  10. #include "printing/print_dialog_linux_interface.h"
  11. #include "printing/printing_context_linux.h"
  12. #include "ui/aura/window_observer.h"
  13. #include "ui/base/glib/glib_signal.h"
  14. #include "ui/gtk/gtk_compat.h"
  15. namespace printing {
  16. class MetafilePlayer;
  17. class PrintSettings;
  18. } // namespace printing
  19. using printing::PrintingContextLinux;
  20. // Needs to be freed on the UI thread to clean up its GTK members variables.
  21. class PrintDialogGtk : public printing::PrintDialogLinuxInterface,
  22. public base::RefCountedDeleteOnSequence<PrintDialogGtk>,
  23. public aura::WindowObserver {
  24. public:
  25. // Creates and returns a print dialog.
  26. static printing::PrintDialogLinuxInterface* CreatePrintDialog(
  27. PrintingContextLinux* context);
  28. PrintDialogGtk(const PrintDialogGtk&) = delete;
  29. PrintDialogGtk& operator=(const PrintDialogGtk&) = delete;
  30. // printing::PrintDialogLinuxInterface implementation.
  31. void UseDefaultSettings() override;
  32. void UpdateSettings(
  33. std::unique_ptr<printing::PrintSettings> settings) override;
  34. void ShowDialog(
  35. gfx::NativeView parent_view,
  36. bool has_selection,
  37. PrintingContextLinux::PrintSettingsCallback callback) override;
  38. void PrintDocument(const printing::MetafilePlayer& metafile,
  39. const std::u16string& document_name) override;
  40. void ReleaseDialog() override;
  41. // Handles print job response.
  42. void OnJobCompleted(GtkPrintJob* print_job, const GError* error);
  43. private:
  44. friend class base::RefCountedDeleteOnSequence<PrintDialogGtk>;
  45. friend class base::DeleteHelper<PrintDialogGtk>;
  46. explicit PrintDialogGtk(PrintingContextLinux* context);
  47. ~PrintDialogGtk() override;
  48. // Handles dialog response.
  49. CHROMEG_CALLBACK_1(PrintDialogGtk, void, OnResponse, GtkWidget*, int);
  50. // Prints document named |document_name|.
  51. void SendDocumentToPrinter(const std::u16string& document_name);
  52. // Helper function for initializing |context_|'s PrintSettings with a given
  53. // |settings|.
  54. void InitPrintSettings(std::unique_ptr<printing::PrintSettings> settings);
  55. // aura::WindowObserver implementation.
  56. void OnWindowDestroying(aura::Window* window) override;
  57. // Printing dialog callback.
  58. PrintingContextLinux::PrintSettingsCallback callback_;
  59. raw_ptr<PrintingContextLinux> context_;
  60. // Print dialog settings. PrintDialogGtk owns |dialog_| and holds references
  61. // to the other objects.
  62. GtkWidget* dialog_ = nullptr;
  63. raw_ptr<GtkPrintSettings> gtk_settings_ = nullptr;
  64. raw_ptr<GtkPageSetup> page_setup_ = nullptr;
  65. raw_ptr<GtkPrinter> printer_ = nullptr;
  66. base::FilePath path_to_pdf_;
  67. };
  68. #endif // UI_GTK_PRINTING_PRINT_DIALOG_GTK_H_