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