[email protected] | 1407b6e | 2010-08-27 21:39:48 | [diff] [blame] | 1 | // Copyright (c) 2010 The Chromium Authors. All rights reserved. |
license.bot | bf09a50 | 2008-08-24 00:55:55 | [diff] [blame] | 2 | // Use of this source code is governed by a BSD-style license that can be |
3 | // found in the LICENSE file. | ||||
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 4 | |
[email protected] | 8ff1d42 | 2009-07-07 21:31:39 | [diff] [blame] | 5 | #ifndef PRINTING_PRINTING_CONTEXT_H_ |
6 | #define PRINTING_PRINTING_CONTEXT_H_ | ||||
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 7 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 8 | #include <string> |
9 | |||||
10 | #include "base/basictypes.h" | ||||
[email protected] | b719142 | 2010-09-21 19:18:05 | [diff] [blame] | 11 | #include "base/callback.h" |
[email protected] | d9d4299 | 2010-09-13 19:39:19 | [diff] [blame] | 12 | #include "base/string16.h" |
[email protected] | 8ff1d42 | 2009-07-07 21:31:39 | [diff] [blame] | 13 | #include "printing/print_settings.h" |
[email protected] | 08397d5 | 2011-02-05 01:53:38 | [diff] [blame^] | 14 | #include "ui/gfx/native_widget_types.h" |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 15 | |
16 | namespace printing { | ||||
17 | |||||
[email protected] | 51e8d935 | 2010-10-06 22:21:17 | [diff] [blame] | 18 | // An abstraction of a printer context, implemented by objects that describe the |
19 | // user selected printing context. This includes the OS-dependent UI to ask the | ||||
20 | // user about the print settings. Concrete implementations directly talk to the | ||||
21 | // printer and manage the document and page breaks. | ||||
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 22 | class PrintingContext { |
23 | public: | ||||
24 | // Tri-state result for user behavior-dependent functions. | ||||
25 | enum Result { | ||||
26 | OK, | ||||
27 | CANCEL, | ||||
28 | FAILED, | ||||
29 | }; | ||||
30 | |||||
[email protected] | 51e8d935 | 2010-10-06 22:21:17 | [diff] [blame] | 31 | virtual ~PrintingContext(); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 32 | |
[email protected] | b719142 | 2010-09-21 19:18:05 | [diff] [blame] | 33 | // Callback of AskUserForSettings, used to notify the PrintJobWorker when |
34 | // print settings are available. | ||||
35 | typedef Callback1<Result>::Type PrintSettingsCallback; | ||||
36 | |||||
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 37 | // Asks the user what printer and format should be used to print. Updates the |
[email protected] | b719142 | 2010-09-21 19:18:05 | [diff] [blame] | 38 | // context with the select device settings. The result of the call is returned |
39 | // in the callback. This is necessary for Linux, which only has an | ||||
40 | // asynchronous printing API. | ||||
[email protected] | 51e8d935 | 2010-10-06 22:21:17 | [diff] [blame] | 41 | virtual void AskUserForSettings(gfx::NativeView parent_view, |
42 | int max_pages, | ||||
43 | bool has_selection, | ||||
44 | PrintSettingsCallback* callback) = 0; | ||||
[email protected] | d825462 | 2010-08-13 19:15:46 | [diff] [blame] | 45 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 46 | // Selects the user's default printer and format. Updates the context with the |
47 | // default device settings. | ||||
[email protected] | 51e8d935 | 2010-10-06 22:21:17 | [diff] [blame] | 48 | virtual Result UseDefaultSettings() = 0; |
[email protected] | 38bba4f | 2010-03-12 05:29:07 | [diff] [blame] | 49 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 50 | // Initializes with predefined settings. |
[email protected] | 51e8d935 | 2010-10-06 22:21:17 | [diff] [blame] | 51 | virtual Result InitWithSettings(const PrintSettings& settings) = 0; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 52 | |
53 | // Does platform specific setup of the printer before the printing. Signal the | ||||
54 | // printer that a document is about to be spooled. | ||||
55 | // Warning: This function enters a message loop. That may cause side effects | ||||
56 | // like IPC message processing! Some printers have side-effects on this call | ||||
57 | // like virtual printers that ask the user for the path of the saved document; | ||||
58 | // for example a PDF printer. | ||||
[email protected] | 51e8d935 | 2010-10-06 22:21:17 | [diff] [blame] | 59 | virtual Result NewDocument(const string16& document_name) = 0; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 60 | |
61 | // Starts a new page. | ||||
[email protected] | 51e8d935 | 2010-10-06 22:21:17 | [diff] [blame] | 62 | virtual Result NewPage() = 0; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 63 | |
64 | // Closes the printed page. | ||||
[email protected] | 51e8d935 | 2010-10-06 22:21:17 | [diff] [blame] | 65 | virtual Result PageDone() = 0; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 66 | |
67 | // Closes the printing job. After this call the object is ready to start a new | ||||
68 | // document. | ||||
[email protected] | 51e8d935 | 2010-10-06 22:21:17 | [diff] [blame] | 69 | virtual Result DocumentDone() = 0; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 70 | |
[email protected] | 8ff1d42 | 2009-07-07 21:31:39 | [diff] [blame] | 71 | // Cancels printing. Can be used in a multi-threaded context. Takes effect |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 72 | // immediately. |
[email protected] | 51e8d935 | 2010-10-06 22:21:17 | [diff] [blame] | 73 | virtual void Cancel() = 0; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 74 | |
75 | // Dismiss the Print... dialog box if shown. | ||||
[email protected] | 51e8d935 | 2010-10-06 22:21:17 | [diff] [blame] | 76 | virtual void DismissDialog() = 0; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 77 | |
[email protected] | 51e8d935 | 2010-10-06 22:21:17 | [diff] [blame] | 78 | // Releases the native printing context. |
79 | virtual void ReleaseContext() = 0; | ||||
80 | |||||
81 | // Returns the native context used to print. | ||||
82 | virtual gfx::NativeDrawingContext context() const = 0; | ||||
83 | |||||
84 | // Creates an instance of this object. Implementers of this interface should | ||||
85 | // implement this method to create an object of their implementation. The | ||||
86 | // caller owns the returned object. | ||||
[email protected] | ee5f36e4 | 2010-12-03 22:40:37 | [diff] [blame] | 87 | static PrintingContext* Create(const std::string& app_locale); |
[email protected] | 51e8d935 | 2010-10-06 22:21:17 | [diff] [blame] | 88 | |
89 | void set_use_overlays(bool use_overlays) { | ||||
90 | settings_.use_overlays = use_overlays; | ||||
[email protected] | b75dca8 | 2009-10-13 18:46:21 | [diff] [blame] | 91 | } |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 92 | |
93 | const PrintSettings& settings() const { | ||||
94 | return settings_; | ||||
95 | } | ||||
96 | |||||
[email protected] | 51e8d935 | 2010-10-06 22:21:17 | [diff] [blame] | 97 | protected: |
[email protected] | ee5f36e4 | 2010-12-03 22:40:37 | [diff] [blame] | 98 | explicit PrintingContext(const std::string& app_locale); |
[email protected] | 51e8d935 | 2010-10-06 22:21:17 | [diff] [blame] | 99 | |
100 | // Reinitializes the settings for object reuse. | ||||
101 | void ResetSettings(); | ||||
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 102 | |
[email protected] | c8ad40c | 2009-06-08 17:05:21 | [diff] [blame] | 103 | // Does bookkeeping when an error occurs. |
104 | PrintingContext::Result OnError(); | ||||
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 105 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 106 | // Complete print context settings. |
107 | PrintSettings settings_; | ||||
108 | |||||
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 109 | // The dialog box has been dismissed. |
110 | volatile bool dialog_box_dismissed_; | ||||
111 | |||||
112 | // Is a print job being done. | ||||
113 | volatile bool in_print_job_; | ||||
114 | |||||
115 | // Did the user cancel the print job. | ||||
116 | volatile bool abort_printing_; | ||||
117 | |||||
[email protected] | ee5f36e4 | 2010-12-03 22:40:37 | [diff] [blame] | 118 | // The application locale. |
119 | std::string app_locale_; | ||||
120 | |||||
[email protected] | 5930cb6 | 2009-12-08 02:04:22 | [diff] [blame] | 121 | DISALLOW_COPY_AND_ASSIGN(PrintingContext); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 122 | }; |
123 | |||||
124 | } // namespace printing | ||||
125 | |||||
[email protected] | 8ff1d42 | 2009-07-07 21:31:39 | [diff] [blame] | 126 | #endif // PRINTING_PRINTING_CONTEXT_H_ |