blob: 3d260efe4b08b967cc7d94ab15f4a961c6c72be8 [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]abe48112011-11-19 01:58:3811#include "base/callback.h"
[email protected]896d161f2013-06-11 22:52:2412#include "base/strings/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:
Vitaly Bukabd7c9812014-08-26 08:57:5428 // 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
initial.commit09911bf2008-07-26 23:55:2941 // Tri-state result for user behavior-dependent functions.
42 enum Result {
43 OK,
44 CANCEL,
45 FAILED,
46 };
47
[email protected]51e8d9352010-10-06 22:21:1748 virtual ~PrintingContext();
initial.commit09911bf2008-07-26 23:55:2949
[email protected]b7191422010-09-21 19:18:0550 // Callback of AskUserForSettings, used to notify the PrintJobWorker when
51 // print settings are available.
[email protected]abe48112011-11-19 01:58:3852 typedef base::Callback<void(Result)> PrintSettingsCallback;
[email protected]b7191422010-09-21 19:18:0553
initial.commit09911bf2008-07-26 23:55:2954 // Asks the user what printer and format should be used to print. Updates the
[email protected]b7191422010-09-21 19:18:0555 // context with the select device settings. The result of the call is returned
56 // in the callback. This is necessary for Linux, which only has an
57 // asynchronous printing API.
dgn4c172eea2014-12-15 21:11:2358 // On Android, when |is_scripted| is true, calling it initiates a full
59 // printing flow from the framework's PrintManager.
60 // (see https://codereview.chromium.org/740983002/)
Vitaly Bukabd7c9812014-08-26 08:57:5461 virtual void AskUserForSettings(int max_pages,
[email protected]51e8d9352010-10-06 22:21:1762 bool has_selection,
dgn4c172eea2014-12-15 21:11:2363 bool is_scripted,
[email protected]abe48112011-11-19 01:58:3864 const PrintSettingsCallback& callback) = 0;
[email protected]d8254622010-08-13 19:15:4665
initial.commit09911bf2008-07-26 23:55:2966 // Selects the user's default printer and format. Updates the context with the
67 // default device settings.
[email protected]51e8d9352010-10-06 22:21:1768 virtual Result UseDefaultSettings() = 0;
[email protected]38bba4f2010-03-12 05:29:0769
[email protected]2dafb8b2014-05-29 16:32:4870 // Updates the context with PDF printer settings.
71 Result UsePdfSettings();
72
[email protected]4c9054b2013-11-04 18:34:2973 // Returns paper size to be used for PDF or Cloud Print in device units.
74 virtual gfx::Size GetPdfPaperSizeDeviceUnits() = 0;
75
[email protected]e5324b52013-10-29 03:16:3776 // Updates printer settings.
[email protected]e5324b52013-10-29 03:16:3777 // |external_preview| is true if pdf is going to be opened in external
78 // preview. Used by MacOS only now to open Preview.app.
vitalybuka92ab8ce2014-08-26 23:41:4579 virtual Result UpdatePrinterSettings(bool external_preview,
vitalybuka95fa3c92015-05-05 03:03:3280 bool show_system_dialog,
81 int page_count) = 0;
[email protected]55b23a02011-08-17 23:09:3682
83 // Updates Print Settings. |job_settings| contains all print job
84 // settings information. |ranges| has the new page range settings.
[email protected]c95198b2014-06-12 16:56:5585 Result UpdatePrintSettings(const base::DictionaryValue& job_settings);
[email protected]7868ecab2011-03-05 00:12:5386
initial.commit09911bf2008-07-26 23:55:2987 // Initializes with predefined settings.
[email protected]51e8d9352010-10-06 22:21:1788 virtual Result InitWithSettings(const PrintSettings& settings) = 0;
initial.commit09911bf2008-07-26 23:55:2989
90 // Does platform specific setup of the printer before the printing. Signal the
91 // printer that a document is about to be spooled.
92 // Warning: This function enters a message loop. That may cause side effects
93 // like IPC message processing! Some printers have side-effects on this call
94 // like virtual printers that ask the user for the path of the saved document;
95 // for example a PDF printer.
[email protected]b5fa4ee2013-10-01 07:19:0796 virtual Result NewDocument(const base::string16& document_name) = 0;
initial.commit09911bf2008-07-26 23:55:2997
98 // Starts a new page.
[email protected]51e8d9352010-10-06 22:21:1799 virtual Result NewPage() = 0;
initial.commit09911bf2008-07-26 23:55:29100
101 // Closes the printed page.
[email protected]51e8d9352010-10-06 22:21:17102 virtual Result PageDone() = 0;
initial.commit09911bf2008-07-26 23:55:29103
104 // Closes the printing job. After this call the object is ready to start a new
105 // document.
[email protected]51e8d9352010-10-06 22:21:17106 virtual Result DocumentDone() = 0;
initial.commit09911bf2008-07-26 23:55:29107
[email protected]8ff1d422009-07-07 21:31:39108 // Cancels printing. Can be used in a multi-threaded context. Takes effect
initial.commit09911bf2008-07-26 23:55:29109 // immediately.
[email protected]51e8d9352010-10-06 22:21:17110 virtual void Cancel() = 0;
initial.commit09911bf2008-07-26 23:55:29111
[email protected]51e8d9352010-10-06 22:21:17112 // Releases the native printing context.
113 virtual void ReleaseContext() = 0;
114
115 // Returns the native context used to print.
116 virtual gfx::NativeDrawingContext context() const = 0;
117
118 // Creates an instance of this object. Implementers of this interface should
Vitaly Bukabd7c9812014-08-26 08:57:54119 // implement this method to create an object of their implementation.
120 static scoped_ptr<PrintingContext> Create(Delegate* delegate);
[email protected]51e8d9352010-10-06 22:21:17121
[email protected]1c23b4e82011-10-15 22:30:48122 void set_margin_type(MarginType type);
initial.commit09911bf2008-07-26 23:55:29123
124 const PrintSettings& settings() const {
125 return settings_;
126 }
127
[email protected]51e8d9352010-10-06 22:21:17128 protected:
Vitaly Bukabd7c9812014-08-26 08:57:54129 explicit PrintingContext(Delegate* delegate);
[email protected]51e8d9352010-10-06 22:21:17130
131 // Reinitializes the settings for object reuse.
132 void ResetSettings();
initial.commit09911bf2008-07-26 23:55:29133
[email protected]c8ad40c2009-06-08 17:05:21134 // Does bookkeeping when an error occurs.
135 PrintingContext::Result OnError();
initial.commit09911bf2008-07-26 23:55:29136
initial.commit09911bf2008-07-26 23:55:29137 // Complete print context settings.
138 PrintSettings settings_;
139
Vitaly Bukabd7c9812014-08-26 08:57:54140 // Printing context delegate.
141 Delegate* delegate_;
142
initial.commit09911bf2008-07-26 23:55:29143 // Is a print job being done.
144 volatile bool in_print_job_;
145
146 // Did the user cancel the print job.
147 volatile bool abort_printing_;
148
[email protected]b5fa4ee2013-10-01 07:19:07149 private:
[email protected]5930cb62009-12-08 02:04:22150 DISALLOW_COPY_AND_ASSIGN(PrintingContext);
initial.commit09911bf2008-07-26 23:55:29151};
152
153} // namespace printing
154
[email protected]8ff1d422009-07-07 21:31:39155#endif // PRINTING_PRINTING_CONTEXT_H_