blob: 9257510807ef5f3a8a44e601d0608b64f84ecb6e [file] [log] [blame]
Torne (Richard Coles)58218062012-11-14 11:43:16 +00001// 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
5#ifndef PRINTING_PRINTING_CONTEXT_MAC_H_
6#define PRINTING_PRINTING_CONTEXT_MAC_H_
7
8#include <string>
9
Ben Murdocheb525c52013-07-10 11:40:50 +010010#include "base/mac/scoped_nsobject.h"
Torne (Richard Coles)58218062012-11-14 11:43:16 +000011#include "printing/print_job_constants.h"
Ben Murdocheb525c52013-07-10 11:40:50 +010012#include "printing/printing_context.h"
Torne (Richard Coles)58218062012-11-14 11:43:16 +000013
14#ifdef __OBJC__
15@class NSPrintInfo;
16#else
17class NSPrintInfo;
18#endif // __OBJC__
19
20namespace printing {
21
22class PRINTING_EXPORT PrintingContextMac : public PrintingContext {
23 public:
24 explicit PrintingContextMac(const std::string& app_locale);
25 virtual ~PrintingContextMac();
26
27 // PrintingContext implementation.
28 virtual void AskUserForSettings(
29 gfx::NativeView parent_view,
30 int max_pages,
31 bool has_selection,
32 const PrintSettingsCallback& callback) OVERRIDE;
33 virtual Result UseDefaultSettings() OVERRIDE;
Torne (Richard Coles)0f1bc082013-11-06 12:27:47 +000034 virtual gfx::Size GetPdfPaperSizeDeviceUnits() OVERRIDE;
35 virtual Result UpdatePrinterSettings(bool external_preview) OVERRIDE;
Torne (Richard Coles)58218062012-11-14 11:43:16 +000036 virtual Result InitWithSettings(const PrintSettings& settings) OVERRIDE;
Torne (Richard Coles)4e180b62013-10-18 15:46:22 +010037 virtual Result NewDocument(const base::string16& document_name) OVERRIDE;
Torne (Richard Coles)58218062012-11-14 11:43:16 +000038 virtual Result NewPage() OVERRIDE;
39 virtual Result PageDone() OVERRIDE;
40 virtual Result DocumentDone() OVERRIDE;
41 virtual void Cancel() OVERRIDE;
42 virtual void ReleaseContext() OVERRIDE;
43 virtual gfx::NativeDrawingContext context() const OVERRIDE;
44
45 private:
46 // Initializes PrintSettings from |print_info_|. This must be called
47 // after changes to |print_info_| in order for the changes to take effect in
48 // printing.
49 // This function ignores the page range information specified in the print
Torne (Richard Coles)1e9bf3e2013-10-31 11:16:26 +000050 // info object and use |settings_.ranges| instead.
51 void InitPrintSettingsFromPrintInfo();
Torne (Richard Coles)58218062012-11-14 11:43:16 +000052
53 // Returns the set of page ranges constructed from |print_info_|.
54 PageRanges GetPageRangesFromPrintInfo();
55
56 // Updates |print_info_| to use the given printer.
57 // Returns true if the printer was set else returns false.
58 bool SetPrinter(const std::string& device_name);
59
60 // Updates |print_info_| page format with user default paper information.
61 // Returns true if the paper was set else returns false.
62 bool UpdatePageFormatWithPaperInfo();
63
64 // Sets the print job destination type as preview job.
65 // Returns true if the print job destination type is set.
66 bool SetPrintPreviewJob();
67
68 // Sets |copies| in PMPrintSettings.
69 // Returns true if the number of copies is set.
70 bool SetCopiesInPrintSettings(int copies);
71
72 // Sets |collate| in PMPrintSettings.
73 // Returns true if |collate| is set.
74 bool SetCollateInPrintSettings(bool collate);
75
76 // Sets orientation in native print info object.
77 // Returns true if the orientation was set.
78 bool SetOrientationIsLandscape(bool landscape);
79
80 // Sets duplex mode in PMPrintSettings.
81 // Returns true if duplex mode is set.
82 bool SetDuplexModeInPrintSettings(DuplexMode mode);
83
84 // Sets output color mode in PMPrintSettings.
85 // Returns true if color mode is set.
86 bool SetOutputColor(int color_mode);
87
88 // The native print info object.
Ben Murdocheb525c52013-07-10 11:40:50 +010089 base::scoped_nsobject<NSPrintInfo> print_info_;
Torne (Richard Coles)58218062012-11-14 11:43:16 +000090
91 // The current page's context; only valid between NewPage and PageDone call
92 // pairs.
93 CGContext* context_;
94
95 DISALLOW_COPY_AND_ASSIGN(PrintingContextMac);
96};
97
98} // namespace printing
99
100#endif // PRINTING_PRINTING_CONTEXT_MAC_H_