Bug 1631735 Part 1: Make nsCocoaWindow animated transitions asynchronous and atomic...
[gecko.git] / widget / nsIDeviceContextSpec.h
blob0432a6816bbc150a0ca0b29923624a3d4fda6aa0
1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* This Source Code Form is subject to the terms of the Mozilla Public
3 * License, v. 2.0. If a copy of the MPL was not distributed with this
4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
6 #ifndef nsIDeviceContextSpec_h___
7 #define nsIDeviceContextSpec_h___
9 #include "gfxPoint.h"
10 #include "nsISupports.h"
11 #include "mozilla/StaticPrefs_print.h"
12 #include "mozilla/gfx/PrintPromise.h"
13 #include "mozilla/MoveOnlyFunction.h"
15 class nsIWidget;
16 class nsIPrintSettings;
18 namespace mozilla {
19 namespace gfx {
20 class DrawEventRecorder;
21 class PrintTarget;
22 } // namespace gfx
23 } // namespace mozilla
25 #define NS_IDEVICE_CONTEXT_SPEC_IID \
26 { \
27 0xf407cfba, 0xbe28, 0x46c9, { \
28 0x8a, 0xba, 0x04, 0x2d, 0xae, 0xbb, 0x4f, 0x23 \
29 } \
32 class nsIDeviceContextSpec : public nsISupports {
33 public:
34 typedef mozilla::gfx::PrintTarget PrintTarget;
36 NS_DECLARE_STATIC_IID_ACCESSOR(NS_IDEVICE_CONTEXT_SPEC_IID)
38 /**
39 * Initialize the device context spec.
40 * @param aWidget A widget a dialog can be hosted in
41 * @param aPrintSettings Print settings for the print operation
42 * @param aIsPrintPreview True if creating Spec for PrintPreview
43 * @return NS_OK or a suitable error code.
45 NS_IMETHOD Init(nsIPrintSettings* aPrintSettings, bool aIsPrintPreview) = 0;
47 virtual already_AddRefed<PrintTarget> MakePrintTarget() = 0;
49 /**
50 * If required override to return a recorder to record the print.
52 * @param aDrawEventRecorder out param for the recorder to use
53 * @return NS_OK or a suitable error code
55 NS_IMETHOD GetDrawEventRecorder(
56 mozilla::gfx::DrawEventRecorder** aDrawEventRecorder) {
57 MOZ_ASSERT(aDrawEventRecorder);
58 *aDrawEventRecorder = nullptr;
59 return NS_OK;
62 /**
63 * @return DPI for printing.
65 float GetDPI() { return mozilla::StaticPrefs::print_default_dpi(); }
67 /**
68 * @return the printing scale to be applied to the context for printing.
70 float GetPrintingScale();
72 /**
73 * @return the point to translate the context to for printing.
75 gfxPoint GetPrintingTranslate();
77 NS_IMETHOD BeginDocument(const nsAString& aTitle,
78 const nsAString& aPrintToFileName,
79 int32_t aStartPage, int32_t aEndPage) = 0;
81 virtual RefPtr<mozilla::gfx::PrintEndDocumentPromise> EndDocument() = 0;
82 NS_IMETHOD BeginPage() = 0;
83 NS_IMETHOD EndPage() = 0;
85 protected:
86 using AsyncEndDocumentFunction = mozilla::MoveOnlyFunction<nsresult()>;
87 static RefPtr<mozilla::gfx::PrintEndDocumentPromise> EndDocumentAsync(
88 const char* aCallSite, AsyncEndDocumentFunction aFunction);
90 static RefPtr<mozilla::gfx::PrintEndDocumentPromise>
91 EndDocumentPromiseFromResult(nsresult aResult, const char* aSite);
93 nsCOMPtr<nsIPrintSettings> mPrintSettings;
95 #ifdef MOZ_ENABLE_SKIA_PDF
96 // This variable is independant of nsIPrintSettings::kOutputFormatPDF (i.e.
97 // save-to-PDF). If set to true, then even when we print to a printer we
98 // output and send it PDF.
99 bool mPrintViaSkPDF = false;
100 #endif
103 NS_DEFINE_STATIC_IID_ACCESSOR(nsIDeviceContextSpec, NS_IDEVICE_CONTEXT_SPEC_IID)
104 #endif