[email protected] | 7868ecab | 2011-03-05 00:12:53 | [diff] [blame] | 1 | // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
[email protected] | 51e8d935 | 2010-10-06 22:21:17 | [diff] [blame] | 2 | // Use of this source code is governed by a BSD-style license that can be |
3 | // found in the LICENSE file. | ||||
4 | |||||
5 | #ifndef PRINTING_PRINTING_CONTEXT_MAC_H_ | ||||
6 | #define PRINTING_PRINTING_CONTEXT_MAC_H_ | ||||
7 | |||||
tapted | 05d4a5b | 2015-05-04 07:20:12 | [diff] [blame] | 8 | #include <ApplicationServices/ApplicationServices.h> |
[email protected] | ee5f36e4 | 2010-12-03 22:40:37 | [diff] [blame] | 9 | #include <string> |
10 | |||||
[email protected] | a852203 | 2013-06-24 22:51:46 | [diff] [blame] | 11 | #include "base/mac/scoped_nsobject.h" |
avi | 126e93c | 2015-12-21 21:48:16 | [diff] [blame] | 12 | #include "base/macros.h" |
Julie Jeongeun Kim | e454f260 | 2020-04-30 05:20:07 | [diff] [blame] | 13 | #include "printing/mojom/print.mojom.h" |
[email protected] | a44b0c14 | 2011-04-26 15:46:10 | [diff] [blame] | 14 | #include "printing/print_job_constants.h" |
[email protected] | a852203 | 2013-06-24 22:51:46 | [diff] [blame] | 15 | #include "printing/printing_context.h" |
[email protected] | 51e8d935 | 2010-10-06 22:21:17 | [diff] [blame] | 16 | |
[email protected] | 51e8d935 | 2010-10-06 22:21:17 | [diff] [blame] | 17 | @class NSPrintInfo; |
[email protected] | 51e8d935 | 2010-10-06 22:21:17 | [diff] [blame] | 18 | |
19 | namespace printing { | ||||
20 | |||||
[email protected] | 69f5b1e6 | 2011-09-01 06:34:04 | [diff] [blame] | 21 | class PRINTING_EXPORT PrintingContextMac : public PrintingContext { |
[email protected] | 51e8d935 | 2010-10-06 22:21:17 | [diff] [blame] | 22 | public: |
Vitaly Buka | bd7c981 | 2014-08-26 08:57:54 | [diff] [blame] | 23 | explicit PrintingContextMac(Delegate* delegate); |
dcheng | d5a0f18 | 2014-10-22 00:04:34 | [diff] [blame] | 24 | ~PrintingContextMac() override; |
[email protected] | 51e8d935 | 2010-10-06 22:21:17 | [diff] [blame] | 25 | |
26 | // PrintingContext implementation. | ||||
dcheng | d5a0f18 | 2014-10-22 00:04:34 | [diff] [blame] | 27 | void AskUserForSettings(int max_pages, |
28 | bool has_selection, | ||||
dgn | 4c172eea | 2014-12-15 21:11:23 | [diff] [blame] | 29 | bool is_scripted, |
Vladislav Kuzkokov | 48ceab2 | 2018-02-14 16:29:28 | [diff] [blame] | 30 | PrintSettingsCallback callback) override; |
dcheng | d5a0f18 | 2014-10-22 00:04:34 | [diff] [blame] | 31 | Result UseDefaultSettings() override; |
32 | gfx::Size GetPdfPaperSizeDeviceUnits() override; | ||||
33 | Result UpdatePrinterSettings(bool external_preview, | ||||
vitalybuka | 95fa3c9 | 2015-05-05 03:03:32 | [diff] [blame] | 34 | bool show_system_dialog, |
35 | int page_count) override; | ||||
dcheng | d5a0f18 | 2014-10-22 00:04:34 | [diff] [blame] | 36 | Result NewDocument(const base::string16& document_name) override; |
37 | Result NewPage() override; | ||||
38 | Result PageDone() override; | ||||
39 | Result DocumentDone() override; | ||||
40 | void Cancel() override; | ||||
41 | void ReleaseContext() override; | ||||
Nico Weber | 8e55956 | 2017-10-03 01:25:26 | [diff] [blame] | 42 | printing::NativeDrawingContext context() const override; |
[email protected] | 51e8d935 | 2010-10-06 22:21:17 | [diff] [blame] | 43 | |
44 | private: | ||||
[email protected] | 4274861a | 2011-06-03 19:27:00 | [diff] [blame] | 45 | // Initializes PrintSettings from |print_info_|. This must be called |
46 | // after changes to |print_info_| in order for the changes to take effect in | ||||
47 | // printing. | ||||
48 | // This function ignores the page range information specified in the print | ||||
[email protected] | e5324b5 | 2013-10-29 03:16:37 | [diff] [blame] | 49 | // info object and use |settings_.ranges| instead. |
50 | void InitPrintSettingsFromPrintInfo(); | ||||
[email protected] | 89f5aa8c | 2011-03-21 20:58:44 | [diff] [blame] | 51 | |
[email protected] | 4274861a | 2011-06-03 19:27:00 | [diff] [blame] | 52 | // Returns the set of page ranges constructed from |print_info_|. |
53 | PageRanges GetPageRangesFromPrintInfo(); | ||||
54 | |||||
[email protected] | 36fbeee2 | 2011-03-23 16:35:12 | [diff] [blame] | 55 | // Updates |print_info_| to use the given printer. |
[email protected] | f106a21 | 2014-06-20 05:02:37 | [diff] [blame] | 56 | // Returns true if the printer was set. |
[email protected] | 987e51f9 | 2011-05-04 21:10:15 | [diff] [blame] | 57 | bool SetPrinter(const std::string& device_name); |
[email protected] | 36fbeee2 | 2011-03-23 16:35:12 | [diff] [blame] | 58 | |
[email protected] | f106a21 | 2014-06-20 05:02:37 | [diff] [blame] | 59 | // Updates |print_info_| page format with paper selected by user. If paper was |
60 | // not selected, default system paper is used. | ||||
61 | // Returns true if the paper was set. | ||||
[email protected] | 4ed1df6 | 2011-11-02 02:32:57 | [diff] [blame] | 62 | bool UpdatePageFormatWithPaperInfo(); |
63 | |||||
[email protected] | f106a21 | 2014-06-20 05:02:37 | [diff] [blame] | 64 | // Updates |print_info_| page format with |paper|. |
65 | // Returns true if the paper was set. | ||||
66 | bool UpdatePageFormatWithPaper(PMPaper paper, PMPageFormat page_format); | ||||
67 | |||||
[email protected] | 97c29575 | 2011-11-17 00:44:37 | [diff] [blame] | 68 | // Sets the print job destination type as preview job. |
69 | // Returns true if the print job destination type is set. | ||||
70 | bool SetPrintPreviewJob(); | ||||
71 | |||||
[email protected] | c97e5e8 | 2011-04-05 18:50:23 | [diff] [blame] | 72 | // Sets |copies| in PMPrintSettings. |
73 | // Returns true if the number of copies is set. | ||||
74 | bool SetCopiesInPrintSettings(int copies); | ||||
75 | |||||
76 | // Sets |collate| in PMPrintSettings. | ||||
77 | // Returns true if |collate| is set. | ||||
78 | bool SetCollateInPrintSettings(bool collate); | ||||
79 | |||||
[email protected] | d203486 | 2011-04-05 20:03:31 | [diff] [blame] | 80 | // Sets orientation in native print info object. |
81 | // Returns true if the orientation was set. | ||||
82 | bool SetOrientationIsLandscape(bool landscape); | ||||
83 | |||||
[email protected] | 770f906 | 2011-04-07 16:22:13 | [diff] [blame] | 84 | // Sets duplex mode in PMPrintSettings. |
85 | // Returns true if duplex mode is set. | ||||
Julie Jeongeun Kim | e454f260 | 2020-04-30 05:20:07 | [diff] [blame] | 86 | bool SetDuplexModeInPrintSettings(mojom::DuplexMode mode); |
[email protected] | 770f906 | 2011-04-07 16:22:13 | [diff] [blame] | 87 | |
[email protected] | c7b3c63 | 2011-04-12 19:36:19 | [diff] [blame] | 88 | // Sets output color mode in PMPrintSettings. |
89 | // Returns true if color mode is set. | ||||
[email protected] | f3256b0d8 | 2011-09-04 23:36:29 | [diff] [blame] | 90 | bool SetOutputColor(int color_mode); |
[email protected] | c7b3c63 | 2011-04-12 19:36:19 | [diff] [blame] | 91 | |
[email protected] | 51e8d935 | 2010-10-06 22:21:17 | [diff] [blame] | 92 | // The native print info object. |
[email protected] | a852203 | 2013-06-24 22:51:46 | [diff] [blame] | 93 | base::scoped_nsobject<NSPrintInfo> print_info_; |
[email protected] | 51e8d935 | 2010-10-06 22:21:17 | [diff] [blame] | 94 | |
95 | // The current page's context; only valid between NewPage and PageDone call | ||||
96 | // pairs. | ||||
97 | CGContext* context_; | ||||
98 | |||||
99 | DISALLOW_COPY_AND_ASSIGN(PrintingContextMac); | ||||
100 | }; | ||||
101 | |||||
102 | } // namespace printing | ||||
103 | |||||
104 | #endif // PRINTING_PRINTING_CONTEXT_MAC_H_ |