blob: 5dbe70d02fe51dc4b8dc4f38acc6a787d1563e26 [file] [log] [blame]
[email protected]7868ecab2011-03-05 00:12:531// Copyright (c) 2011 The Chromium Authors. All rights reserved.
license.botbf09a502008-08-24 00:55:552// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
initial.commit09911bf2008-07-26 23:55:294
[email protected]8ff1d422009-07-07 21:31:395#ifndef PRINTING_PRINTING_CONTEXT_H_
6#define PRINTING_PRINTING_CONTEXT_H_
initial.commit09911bf2008-07-26 23:55:297
initial.commit09911bf2008-07-26 23:55:298#include <string>
9
10#include "base/basictypes.h"
[email protected]2b623242011-05-10 00:37:4011#include "base/callback_old.h"
[email protected]d9d42992010-09-13 19:39:1912#include "base/string16.h"
[email protected]8ff1d422009-07-07 21:31:3913#include "printing/print_settings.h"
[email protected]08397d52011-02-05 01:53:3814#include "ui/gfx/native_widget_types.h"
initial.commit09911bf2008-07-26 23:55:2915
[email protected]f3a1c642011-07-12 19:15:0316namespace base {
[email protected]89f5aa8c2011-03-21 20:58:4417class DictionaryValue;
[email protected]f3a1c642011-07-12 19:15:0318}
[email protected]89f5aa8c2011-03-21 20:58:4419
initial.commit09911bf2008-07-26 23:55:2920namespace printing {
21
[email protected]51e8d9352010-10-06 22:21:1722// 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]69f5b1e62011-09-01 06:34:0426class PRINTING_EXPORT PrintingContext {
initial.commit09911bf2008-07-26 23:55:2927 public:
28 // Tri-state result for user behavior-dependent functions.
29 enum Result {
30 OK,
31 CANCEL,
32 FAILED,
33 };
34
[email protected]51e8d9352010-10-06 22:21:1735 virtual ~PrintingContext();
initial.commit09911bf2008-07-26 23:55:2936
[email protected]b7191422010-09-21 19:18:0537 // Callback of AskUserForSettings, used to notify the PrintJobWorker when
38 // print settings are available.
39 typedef Callback1<Result>::Type PrintSettingsCallback;
40
initial.commit09911bf2008-07-26 23:55:2941 // Asks the user what printer and format should be used to print. Updates the
[email protected]b7191422010-09-21 19:18:0542 // 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]51e8d9352010-10-06 22:21:1745 virtual void AskUserForSettings(gfx::NativeView parent_view,
46 int max_pages,
47 bool has_selection,
48 PrintSettingsCallback* callback) = 0;
[email protected]d8254622010-08-13 19:15:4649
initial.commit09911bf2008-07-26 23:55:2950 // Selects the user's default printer and format. Updates the context with the
51 // default device settings.
[email protected]51e8d9352010-10-06 22:21:1752 virtual Result UseDefaultSettings() = 0;
[email protected]38bba4f2010-03-12 05:29:0753
[email protected]55b23a02011-08-17 23:09:3654 // Updates printer related settings. |job_settings| contains all print job
55 // settings information. |ranges| has the new page range settings.
56 virtual Result UpdatePrinterSettings(
57 const base::DictionaryValue& job_settings,
58 const PageRanges& ranges) = 0;
59
60 // Updates Print Settings. |job_settings| contains all print job
61 // settings information. |ranges| has the new page range settings.
62 Result UpdatePrintSettings(const base::DictionaryValue& job_settings,
63 const PageRanges& ranges);
[email protected]7868ecab2011-03-05 00:12:5364
initial.commit09911bf2008-07-26 23:55:2965 // Initializes with predefined settings.
[email protected]51e8d9352010-10-06 22:21:1766 virtual Result InitWithSettings(const PrintSettings& settings) = 0;
initial.commit09911bf2008-07-26 23:55:2967
68 // Does platform specific setup of the printer before the printing. Signal the
69 // printer that a document is about to be spooled.
70 // Warning: This function enters a message loop. That may cause side effects
71 // like IPC message processing! Some printers have side-effects on this call
72 // like virtual printers that ask the user for the path of the saved document;
73 // for example a PDF printer.
[email protected]51e8d9352010-10-06 22:21:1774 virtual Result NewDocument(const string16& document_name) = 0;
initial.commit09911bf2008-07-26 23:55:2975
76 // Starts a new page.
[email protected]51e8d9352010-10-06 22:21:1777 virtual Result NewPage() = 0;
initial.commit09911bf2008-07-26 23:55:2978
79 // Closes the printed page.
[email protected]51e8d9352010-10-06 22:21:1780 virtual Result PageDone() = 0;
initial.commit09911bf2008-07-26 23:55:2981
82 // Closes the printing job. After this call the object is ready to start a new
83 // document.
[email protected]51e8d9352010-10-06 22:21:1784 virtual Result DocumentDone() = 0;
initial.commit09911bf2008-07-26 23:55:2985
[email protected]8ff1d422009-07-07 21:31:3986 // Cancels printing. Can be used in a multi-threaded context. Takes effect
initial.commit09911bf2008-07-26 23:55:2987 // immediately.
[email protected]51e8d9352010-10-06 22:21:1788 virtual void Cancel() = 0;
initial.commit09911bf2008-07-26 23:55:2989
[email protected]51e8d9352010-10-06 22:21:1790 // Releases the native printing context.
91 virtual void ReleaseContext() = 0;
92
93 // Returns the native context used to print.
94 virtual gfx::NativeDrawingContext context() const = 0;
95
96 // Creates an instance of this object. Implementers of this interface should
97 // implement this method to create an object of their implementation. The
98 // caller owns the returned object.
[email protected]ee5f36e42010-12-03 22:40:3799 static PrintingContext* Create(const std::string& app_locale);
[email protected]51e8d9352010-10-06 22:21:17100
[email protected]1c23b4e82011-10-15 22:30:48101 void set_margin_type(MarginType type);
initial.commit09911bf2008-07-26 23:55:29102
103 const PrintSettings& settings() const {
104 return settings_;
105 }
106
[email protected]51e8d9352010-10-06 22:21:17107 protected:
[email protected]ee5f36e42010-12-03 22:40:37108 explicit PrintingContext(const std::string& app_locale);
[email protected]51e8d9352010-10-06 22:21:17109
110 // Reinitializes the settings for object reuse.
111 void ResetSettings();
initial.commit09911bf2008-07-26 23:55:29112
[email protected]c8ad40c2009-06-08 17:05:21113 // Does bookkeeping when an error occurs.
114 PrintingContext::Result OnError();
initial.commit09911bf2008-07-26 23:55:29115
initial.commit09911bf2008-07-26 23:55:29116 // Complete print context settings.
117 PrintSettings settings_;
118
initial.commit09911bf2008-07-26 23:55:29119 // The dialog box has been dismissed.
120 volatile bool dialog_box_dismissed_;
121
122 // Is a print job being done.
123 volatile bool in_print_job_;
124
125 // Did the user cancel the print job.
126 volatile bool abort_printing_;
127
[email protected]ee5f36e42010-12-03 22:40:37128 // The application locale.
129 std::string app_locale_;
130
[email protected]5930cb62009-12-08 02:04:22131 DISALLOW_COPY_AND_ASSIGN(PrintingContext);
initial.commit09911bf2008-07-26 23:55:29132};
133
134} // namespace printing
135
[email protected]8ff1d422009-07-07 21:31:39136#endif // PRINTING_PRINTING_CONTEXT_H_