printing_context_mac.h 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  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
  3. // found in the LICENSE file.
  4. #ifndef PRINTING_PRINTING_CONTEXT_MAC_H_
  5. #define PRINTING_PRINTING_CONTEXT_MAC_H_
  6. #include <ApplicationServices/ApplicationServices.h>
  7. #include <string>
  8. #include "base/mac/scoped_nsobject.h"
  9. #include "base/strings/string_piece.h"
  10. #include "printing/mojom/print.mojom.h"
  11. #include "printing/print_job_constants.h"
  12. #include "printing/printing_context.h"
  13. @class NSPrintInfo;
  14. namespace printing {
  15. class COMPONENT_EXPORT(PRINTING) PrintingContextMac : public PrintingContext {
  16. public:
  17. explicit PrintingContextMac(Delegate* delegate);
  18. PrintingContextMac(const PrintingContextMac&) = delete;
  19. PrintingContextMac& operator=(const PrintingContextMac&) = delete;
  20. ~PrintingContextMac() override;
  21. // PrintingContext implementation.
  22. void AskUserForSettings(int max_pages,
  23. bool has_selection,
  24. bool is_scripted,
  25. PrintSettingsCallback callback) override;
  26. mojom::ResultCode UseDefaultSettings() override;
  27. gfx::Size GetPdfPaperSizeDeviceUnits() override;
  28. mojom::ResultCode UpdatePrinterSettings(
  29. const PrinterSettings& printer_settings) override;
  30. mojom::ResultCode NewDocument(const std::u16string& document_name) override;
  31. mojom::ResultCode PrintDocument(const MetafilePlayer& metafile,
  32. const PrintSettings& settings,
  33. uint32_t num_pages) override;
  34. mojom::ResultCode DocumentDone() override;
  35. void Cancel() override;
  36. void ReleaseContext() override;
  37. printing::NativeDrawingContext context() const override;
  38. private:
  39. // Initializes PrintSettings from `print_info_`. This must be called
  40. // after changes to `print_info_` in order for the changes to take effect in
  41. // printing.
  42. // This function ignores the page range information specified in the print
  43. // info object and use `settings_.ranges` instead.
  44. void InitPrintSettingsFromPrintInfo();
  45. // Returns the set of page ranges constructed from `print_info_`.
  46. PageRanges GetPageRangesFromPrintInfo();
  47. // Updates `print_info_` to use the given printer.
  48. // Returns true if the printer was set.
  49. bool SetPrinter(const std::string& device_name);
  50. // Updates `print_info_` page format with paper selected by user. If paper was
  51. // not selected, default system paper is used.
  52. // Returns true if the paper was set.
  53. bool UpdatePageFormatWithPaperInfo();
  54. // Updates `print_info_` page format with `paper`.
  55. // Returns true if the paper was set.
  56. bool UpdatePageFormatWithPaper(PMPaper paper, PMPageFormat page_format);
  57. // Sets the print job destination type as preview job.
  58. // Returns true if the print job destination type is set.
  59. bool SetPrintPreviewJob();
  60. // Sets `copies` in PMPrintSettings.
  61. // Returns true if the number of copies is set.
  62. bool SetCopiesInPrintSettings(int copies);
  63. // Sets `collate` in PMPrintSettings.
  64. // Returns true if `collate` is set.
  65. bool SetCollateInPrintSettings(bool collate);
  66. // Sets orientation in native print info object.
  67. // Returns true if the orientation was set.
  68. bool SetOrientationIsLandscape(bool landscape);
  69. // Sets duplex mode in PMPrintSettings.
  70. // Returns true if duplex mode is set.
  71. bool SetDuplexModeInPrintSettings(mojom::DuplexMode mode);
  72. // Sets output color mode in PMPrintSettings.
  73. // Returns true if color mode is set.
  74. bool SetOutputColor(int color_mode);
  75. // Sets resolution in PMPrintSettings.
  76. // Returns true if resolution is set.
  77. bool SetResolution(const gfx::Size& dpi_size);
  78. // Sets key-value pair in PMPrintSettings.
  79. // Returns true is the pair is set.
  80. bool SetKeyValue(base::StringPiece key, base::StringPiece value);
  81. // Starts a new page.
  82. mojom::ResultCode NewPage();
  83. // Closes the printed page.
  84. mojom::ResultCode PageDone();
  85. // The native print info object.
  86. base::scoped_nsobject<NSPrintInfo> print_info_;
  87. // The current page's context; only valid between NewPage and PageDone call
  88. // pairs.
  89. CGContext* context_;
  90. };
  91. } // namespace printing
  92. #endif // PRINTING_PRINTING_CONTEXT_MAC_H_