1 // Copyright 2011 The Chromium Authors
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #ifndef PRINTING_PRINTING_CONTEXT_MAC_H_
6 #define PRINTING_PRINTING_CONTEXT_MAC_H_
8 #include <ApplicationServices/ApplicationServices.h>
12 #include "base/memory/raw_ptr_exclusion.h"
13 #include "base/strings/string_piece.h"
14 #include "printing/mojom/print.mojom.h"
15 #include "printing/print_job_constants.h"
16 #include "printing/printing_context.h"
22 class COMPONENT_EXPORT(PRINTING) PrintingContextMac : public PrintingContext {
24 explicit PrintingContextMac(Delegate* delegate);
25 PrintingContextMac(const PrintingContextMac&) = delete;
26 PrintingContextMac& operator=(const PrintingContextMac&) = delete;
27 ~PrintingContextMac() override;
29 // PrintingContext implementation.
30 void AskUserForSettings(int max_pages,
33 PrintSettingsCallback callback) override;
34 mojom::ResultCode UseDefaultSettings() override;
35 gfx::Size GetPdfPaperSizeDeviceUnits() override;
36 mojom::ResultCode UpdatePrinterSettings(
37 const PrinterSettings& printer_settings) override;
38 mojom::ResultCode NewDocument(const std::u16string& document_name) override;
39 mojom::ResultCode PrintDocument(const MetafilePlayer& metafile,
40 const PrintSettings& settings,
41 uint32_t num_pages) override;
42 mojom::ResultCode DocumentDone() override;
43 void Cancel() override;
44 void ReleaseContext() override;
45 printing::NativeDrawingContext context() const override;
48 // Initializes PrintSettings from `print_info_`. This must be called
49 // after changes to `print_info_` in order for the changes to take effect in
51 // This function ignores the page range information specified in the print
52 // info object and use `settings_.ranges` instead.
53 void InitPrintSettingsFromPrintInfo();
55 // Returns the set of page ranges constructed from `print_info_`.
56 PageRanges GetPageRangesFromPrintInfo();
58 // Updates `print_info_` to use the given printer.
59 // Returns true if the printer was set.
60 bool SetPrinter(const std::string& device_name);
62 // Updates `print_info_` page format with paper selected by user. If paper was
63 // not selected, default system paper is used.
64 // Returns true if the paper was set.
65 bool UpdatePageFormatWithPaperInfo();
67 // Updates `print_info_` page format with `paper`.
68 // Returns true if the paper was set.
69 bool UpdatePageFormatWithPaper(PMPaper paper, PMPageFormat page_format);
71 // Sets the print job destination type as preview job.
72 // Returns true if the print job destination type is set.
73 bool SetPrintPreviewJob();
75 // Sets `copies` in PMPrintSettings.
76 // Returns true if the number of copies is set.
77 bool SetCopiesInPrintSettings(int copies);
79 // Sets `collate` in PMPrintSettings.
80 // Returns true if `collate` is set.
81 bool SetCollateInPrintSettings(bool collate);
83 // Sets orientation in native print info object.
84 // Returns true if the orientation was set.
85 bool SetOrientationIsLandscape(bool landscape);
87 // Sets duplex mode in PMPrintSettings.
88 // Returns true if duplex mode is set.
89 bool SetDuplexModeInPrintSettings(mojom::DuplexMode mode);
91 // Sets output color mode in PMPrintSettings.
92 // Returns true if color mode is set.
93 bool SetOutputColor(int color_mode);
95 // Sets resolution in PMPrintSettings.
96 // Returns true if resolution is set.
97 bool SetResolution(const gfx::Size& dpi_size);
99 // Sets key-value pair in PMPrintSettings.
100 // Returns true is the pair is set.
101 bool SetKeyValue(base::StringPiece key, base::StringPiece value);
103 // Starts a new page.
104 mojom::ResultCode NewPage();
106 // Closes the printed page.
107 mojom::ResultCode PageDone();
109 // The native print info object.
110 NSPrintInfo* __strong print_info_;
112 // The current page's context; only valid between NewPage and PageDone call
114 // This field is not a raw_ptr<> because it was filtered by the rewriter
116 RAW_PTR_EXCLUSION CGContextRef context_ = nullptr;
119 } // namespace printing
121 #endif // PRINTING_PRINTING_CONTEXT_MAC_H_