OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef PRINTING_PRINTING_CONTEXT_H_ | 5 #ifndef PRINTING_PRINTING_CONTEXT_H_ |
6 #define PRINTING_PRINTING_CONTEXT_H_ | 6 #define PRINTING_PRINTING_CONTEXT_H_ |
7 | 7 |
8 #include <string> | 8 #include <string> |
9 | 9 |
10 #include "base/basictypes.h" | 10 #include "base/basictypes.h" |
11 #include "base/callback.h" | 11 #include "base/callback.h" |
12 #include "base/strings/string16.h" | 12 #include "base/strings/string16.h" |
13 #include "printing/print_settings.h" | 13 #include "printing/print_settings.h" |
14 #include "ui/gfx/native_widget_types.h" | 14 #include "ui/gfx/native_widget_types.h" |
15 | 15 |
16 namespace base { | 16 namespace base { |
17 class DictionaryValue; | 17 class DictionaryValue; |
18 } | 18 } |
19 | 19 |
20 namespace printing { | 20 namespace printing { |
21 | 21 |
22 // An abstraction of a printer context, implemented by objects that describe the | 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 | 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 | 24 // user about the print settings. Concrete implementations directly talk to the |
25 // printer and manage the document and page breaks. | 25 // printer and manage the document and page breaks. |
26 class PRINTING_EXPORT PrintingContext { | 26 class PRINTING_EXPORT PrintingContext { |
27 public: | 27 public: |
| 28 // Printing context delegate. |
| 29 class Delegate { |
| 30 public: |
| 31 Delegate() {}; |
| 32 virtual ~Delegate() {}; |
| 33 |
| 34 // Returns parent view to use for modal dialogs. |
| 35 virtual gfx::NativeView GetParentView() = 0; |
| 36 |
| 37 // Returns application locale. |
| 38 virtual std::string GetAppLocale() = 0; |
| 39 }; |
| 40 |
28 // Tri-state result for user behavior-dependent functions. | 41 // Tri-state result for user behavior-dependent functions. |
29 enum Result { | 42 enum Result { |
30 OK, | 43 OK, |
31 CANCEL, | 44 CANCEL, |
32 FAILED, | 45 FAILED, |
33 }; | 46 }; |
34 | 47 |
35 virtual ~PrintingContext(); | 48 virtual ~PrintingContext(); |
36 | 49 |
37 // Callback of AskUserForSettings, used to notify the PrintJobWorker when | 50 // Callback of AskUserForSettings, used to notify the PrintJobWorker when |
38 // print settings are available. | 51 // print settings are available. |
39 typedef base::Callback<void(Result)> PrintSettingsCallback; | 52 typedef base::Callback<void(Result)> PrintSettingsCallback; |
40 | 53 |
41 // Asks the user what printer and format should be used to print. Updates the | 54 // Asks the user what printer and format should be used to print. Updates the |
42 // context with the select device settings. The result of the call is returned | 55 // 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 | 56 // in the callback. This is necessary for Linux, which only has an |
44 // asynchronous printing API. | 57 // asynchronous printing API. |
45 virtual void AskUserForSettings(gfx::NativeView parent_view, | 58 virtual void AskUserForSettings(int max_pages, |
46 int max_pages, | |
47 bool has_selection, | 59 bool has_selection, |
48 const PrintSettingsCallback& callback) = 0; | 60 const PrintSettingsCallback& callback) = 0; |
49 | 61 |
50 // Selects the user's default printer and format. Updates the context with the | 62 // Selects the user's default printer and format. Updates the context with the |
51 // default device settings. | 63 // default device settings. |
52 virtual Result UseDefaultSettings() = 0; | 64 virtual Result UseDefaultSettings() = 0; |
53 | 65 |
54 // Updates the context with PDF printer settings. | 66 // Updates the context with PDF printer settings. |
55 Result UsePdfSettings(); | 67 Result UsePdfSettings(); |
56 | 68 |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
91 // immediately. | 103 // immediately. |
92 virtual void Cancel() = 0; | 104 virtual void Cancel() = 0; |
93 | 105 |
94 // Releases the native printing context. | 106 // Releases the native printing context. |
95 virtual void ReleaseContext() = 0; | 107 virtual void ReleaseContext() = 0; |
96 | 108 |
97 // Returns the native context used to print. | 109 // Returns the native context used to print. |
98 virtual gfx::NativeDrawingContext context() const = 0; | 110 virtual gfx::NativeDrawingContext context() const = 0; |
99 | 111 |
100 // Creates an instance of this object. Implementers of this interface should | 112 // Creates an instance of this object. Implementers of this interface should |
101 // implement this method to create an object of their implementation. The | 113 // implement this method to create an object of their implementation. |
102 // caller owns the returned object. | 114 static scoped_ptr<PrintingContext> Create(Delegate* delegate); |
103 static PrintingContext* Create(const std::string& app_locale); | |
104 | 115 |
105 void set_margin_type(MarginType type); | 116 void set_margin_type(MarginType type); |
106 | 117 |
107 const PrintSettings& settings() const { | 118 const PrintSettings& settings() const { |
108 return settings_; | 119 return settings_; |
109 } | 120 } |
110 | 121 |
111 protected: | 122 protected: |
112 explicit PrintingContext(const std::string& app_locale); | 123 explicit PrintingContext(Delegate* delegate); |
113 | 124 |
114 // Reinitializes the settings for object reuse. | 125 // Reinitializes the settings for object reuse. |
115 void ResetSettings(); | 126 void ResetSettings(); |
116 | 127 |
117 // Does bookkeeping when an error occurs. | 128 // Does bookkeeping when an error occurs. |
118 PrintingContext::Result OnError(); | 129 PrintingContext::Result OnError(); |
119 | 130 |
120 // Complete print context settings. | 131 // Complete print context settings. |
121 PrintSettings settings_; | 132 PrintSettings settings_; |
122 | 133 |
| 134 // Printing context delegate. |
| 135 Delegate* delegate_; |
| 136 |
123 // The dialog box has been dismissed. | 137 // The dialog box has been dismissed. |
124 volatile bool dialog_box_dismissed_; | 138 volatile bool dialog_box_dismissed_; |
125 | 139 |
126 // Is a print job being done. | 140 // Is a print job being done. |
127 volatile bool in_print_job_; | 141 volatile bool in_print_job_; |
128 | 142 |
129 // Did the user cancel the print job. | 143 // Did the user cancel the print job. |
130 volatile bool abort_printing_; | 144 volatile bool abort_printing_; |
131 | 145 |
132 // The application locale. | |
133 std::string app_locale_; | |
134 | |
135 private: | 146 private: |
136 DISALLOW_COPY_AND_ASSIGN(PrintingContext); | 147 DISALLOW_COPY_AND_ASSIGN(PrintingContext); |
137 }; | 148 }; |
138 | 149 |
139 } // namespace printing | 150 } // namespace printing |
140 | 151 |
141 #endif // PRINTING_PRINTING_CONTEXT_H_ | 152 #endif // PRINTING_PRINTING_CONTEXT_H_ |
OLD | NEW |