[email protected] | 7868ecab | 2011-03-05 00:12:53 | [diff] [blame] | 1 | // Copyright (c) 2011 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] | abe4811 | 2011-11-19 01:58:38 | [diff] [blame] | 11 | #include "base/callback.h" |
[email protected] | 896d161f | 2013-06-11 22:52:24 | [diff] [blame] | 12 | #include "base/strings/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 | |
[email protected] | f3a1c64 | 2011-07-12 19:15:03 | [diff] [blame] | 16 | namespace base { |
[email protected] | 89f5aa8c | 2011-03-21 20:58:44 | [diff] [blame] | 17 | class DictionaryValue; |
[email protected] | f3a1c64 | 2011-07-12 19:15:03 | [diff] [blame] | 18 | } |
[email protected] | 89f5aa8c | 2011-03-21 20:58:44 | [diff] [blame] | 19 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 20 | namespace printing { |
| 21 | |
[email protected] | 51e8d935 | 2010-10-06 22:21:17 | [diff] [blame] | 22 | // An abstraction of a printer context, implemented by objects that describe the |
| 23 | // user selected printing context. This includes the OS-dependent UI to ask the |
| 24 | // user about the print settings. Concrete implementations directly talk to the |
| 25 | // printer and manage the document and page breaks. |
[email protected] | 69f5b1e6 | 2011-09-01 06:34:04 | [diff] [blame] | 26 | class PRINTING_EXPORT PrintingContext { |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 27 | public: |
| 28 | // Tri-state result for user behavior-dependent functions. |
| 29 | enum Result { |
| 30 | OK, |
| 31 | CANCEL, |
| 32 | FAILED, |
| 33 | }; |
| 34 | |
[email protected] | 51e8d935 | 2010-10-06 22:21:17 | [diff] [blame] | 35 | virtual ~PrintingContext(); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 36 | |
[email protected] | b719142 | 2010-09-21 19:18:05 | [diff] [blame] | 37 | // Callback of AskUserForSettings, used to notify the PrintJobWorker when |
| 38 | // print settings are available. |
[email protected] | abe4811 | 2011-11-19 01:58:38 | [diff] [blame] | 39 | typedef base::Callback<void(Result)> PrintSettingsCallback; |
[email protected] | b719142 | 2010-09-21 19:18:05 | [diff] [blame] | 40 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 41 | // 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] | 42 | // context with the select device settings. The result of the call is returned |
| 43 | // in the callback. This is necessary for Linux, which only has an |
| 44 | // asynchronous printing API. |
[email protected] | 51e8d935 | 2010-10-06 22:21:17 | [diff] [blame] | 45 | virtual void AskUserForSettings(gfx::NativeView parent_view, |
| 46 | int max_pages, |
| 47 | bool has_selection, |
[email protected] | abe4811 | 2011-11-19 01:58:38 | [diff] [blame] | 48 | const PrintSettingsCallback& callback) = 0; |
[email protected] | d825462 | 2010-08-13 19:15:46 | [diff] [blame] | 49 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 50 | // Selects the user's default printer and format. Updates the context with the |
| 51 | // default device settings. |
[email protected] | 51e8d935 | 2010-10-06 22:21:17 | [diff] [blame] | 52 | virtual Result UseDefaultSettings() = 0; |
[email protected] | 38bba4f | 2010-03-12 05:29:07 | [diff] [blame] | 53 | |
[email protected] | e5324b5 | 2013-10-29 03:16:37 | [diff] [blame^] | 54 | // Updates printer settings. |
| 55 | // |target_is_pdf| is true if implementation needs to generate PDF without |
| 56 | // actual printing. In this case implementation may avoid setup of native |
| 57 | // print system. Ex. "save to pdf" or Cloud Print. |
| 58 | // |external_preview| is true if pdf is going to be opened in external |
| 59 | // preview. Used by MacOS only now to open Preview.app. |
| 60 | virtual Result UpdatePrinterSettings(bool target_is_pdf, |
| 61 | bool external_preview) = 0; |
[email protected] | 55b23a0 | 2011-08-17 23:09:36 | [diff] [blame] | 62 | |
| 63 | // Updates Print Settings. |job_settings| contains all print job |
| 64 | // settings information. |ranges| has the new page range settings. |
| 65 | Result UpdatePrintSettings(const base::DictionaryValue& job_settings, |
| 66 | const PageRanges& ranges); |
[email protected] | 7868ecab | 2011-03-05 00:12:53 | [diff] [blame] | 67 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 68 | // Initializes with predefined settings. |
[email protected] | 51e8d935 | 2010-10-06 22:21:17 | [diff] [blame] | 69 | virtual Result InitWithSettings(const PrintSettings& settings) = 0; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 70 | |
| 71 | // Does platform specific setup of the printer before the printing. Signal the |
| 72 | // printer that a document is about to be spooled. |
| 73 | // Warning: This function enters a message loop. That may cause side effects |
| 74 | // like IPC message processing! Some printers have side-effects on this call |
| 75 | // like virtual printers that ask the user for the path of the saved document; |
| 76 | // for example a PDF printer. |
[email protected] | b5fa4ee | 2013-10-01 07:19:07 | [diff] [blame] | 77 | virtual Result NewDocument(const base::string16& document_name) = 0; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 78 | |
| 79 | // Starts a new page. |
[email protected] | 51e8d935 | 2010-10-06 22:21:17 | [diff] [blame] | 80 | virtual Result NewPage() = 0; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 81 | |
| 82 | // Closes the printed page. |
[email protected] | 51e8d935 | 2010-10-06 22:21:17 | [diff] [blame] | 83 | virtual Result PageDone() = 0; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 84 | |
| 85 | // Closes the printing job. After this call the object is ready to start a new |
| 86 | // document. |
[email protected] | 51e8d935 | 2010-10-06 22:21:17 | [diff] [blame] | 87 | virtual Result DocumentDone() = 0; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 88 | |
[email protected] | 8ff1d42 | 2009-07-07 21:31:39 | [diff] [blame] | 89 | // Cancels printing. Can be used in a multi-threaded context. Takes effect |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 90 | // immediately. |
[email protected] | 51e8d935 | 2010-10-06 22:21:17 | [diff] [blame] | 91 | virtual void Cancel() = 0; |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 92 | |
[email protected] | 51e8d935 | 2010-10-06 22:21:17 | [diff] [blame] | 93 | // Releases the native printing context. |
| 94 | virtual void ReleaseContext() = 0; |
| 95 | |
| 96 | // Returns the native context used to print. |
| 97 | virtual gfx::NativeDrawingContext context() const = 0; |
| 98 | |
| 99 | // Creates an instance of this object. Implementers of this interface should |
| 100 | // implement this method to create an object of their implementation. The |
| 101 | // caller owns the returned object. |
[email protected] | ee5f36e4 | 2010-12-03 22:40:37 | [diff] [blame] | 102 | static PrintingContext* Create(const std::string& app_locale); |
[email protected] | 51e8d935 | 2010-10-06 22:21:17 | [diff] [blame] | 103 | |
[email protected] | 1c23b4e8 | 2011-10-15 22:30:48 | [diff] [blame] | 104 | void set_margin_type(MarginType type); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 105 | |
| 106 | const PrintSettings& settings() const { |
| 107 | return settings_; |
| 108 | } |
| 109 | |
[email protected] | 51e8d935 | 2010-10-06 22:21:17 | [diff] [blame] | 110 | protected: |
[email protected] | ee5f36e4 | 2010-12-03 22:40:37 | [diff] [blame] | 111 | explicit PrintingContext(const std::string& app_locale); |
[email protected] | 51e8d935 | 2010-10-06 22:21:17 | [diff] [blame] | 112 | |
| 113 | // Reinitializes the settings for object reuse. |
| 114 | void ResetSettings(); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 115 | |
[email protected] | c8ad40c | 2009-06-08 17:05:21 | [diff] [blame] | 116 | // Does bookkeeping when an error occurs. |
| 117 | PrintingContext::Result OnError(); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 118 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 119 | // Complete print context settings. |
| 120 | PrintSettings settings_; |
| 121 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 122 | // The dialog box has been dismissed. |
| 123 | volatile bool dialog_box_dismissed_; |
| 124 | |
| 125 | // Is a print job being done. |
| 126 | volatile bool in_print_job_; |
| 127 | |
| 128 | // Did the user cancel the print job. |
| 129 | volatile bool abort_printing_; |
| 130 | |
[email protected] | ee5f36e4 | 2010-12-03 22:40:37 | [diff] [blame] | 131 | // The application locale. |
| 132 | std::string app_locale_; |
| 133 | |
[email protected] | b5fa4ee | 2013-10-01 07:19:07 | [diff] [blame] | 134 | private: |
[email protected] | 5930cb6 | 2009-12-08 02:04:22 | [diff] [blame] | 135 | DISALLOW_COPY_AND_ASSIGN(PrintingContext); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 136 | }; |
| 137 | |
| 138 | } // namespace printing |
| 139 | |
[email protected] | 8ff1d42 | 2009-07-07 21:31:39 | [diff] [blame] | 140 | #endif // PRINTING_PRINTING_CONTEXT_H_ |