Backed out changeset e9d46c179688 (bug 1855759) for causing build bustages CLOSED...
[gecko.git] / widget / nsIDeviceContextSpec.h
blob6afe4ea850a9e06d9c4987e5355c87556b1ca935
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/Point.h"
13 #include "mozilla/gfx/PrintPromise.h"
14 #include "mozilla/MoveOnlyFunction.h"
16 class nsIWidget;
17 class nsIPrintSettings;
19 namespace mozilla {
20 namespace gfx {
21 class DrawEventRecorder;
22 class PrintTarget;
23 } // namespace gfx
24 } // namespace mozilla
26 #define NS_IDEVICE_CONTEXT_SPEC_IID \
27 { \
28 0xf407cfba, 0xbe28, 0x46c9, { \
29 0x8a, 0xba, 0x04, 0x2d, 0xae, 0xbb, 0x4f, 0x23 \
30 } \
33 class nsIDeviceContextSpec : public nsISupports {
34 public:
35 typedef mozilla::gfx::PrintTarget PrintTarget;
36 using IntSize = mozilla::gfx::IntSize;
38 NS_DECLARE_STATIC_IID_ACCESSOR(NS_IDEVICE_CONTEXT_SPEC_IID)
40 /**
41 * Initialize the device context spec.
42 * @param aWidget A widget a dialog can be hosted in
43 * @param aPrintSettings Print settings for the print operation
44 * @param aIsPrintPreview True if creating Spec for PrintPreview
45 * @return NS_OK or a suitable error code.
47 NS_IMETHOD Init(nsIPrintSettings* aPrintSettings, bool aIsPrintPreview) = 0;
49 virtual already_AddRefed<PrintTarget> MakePrintTarget() = 0;
51 /**
52 * If required override to return a recorder to record the print.
54 * @param aDrawEventRecorder out param for the recorder to use
55 * @return NS_OK or a suitable error code
57 NS_IMETHOD GetDrawEventRecorder(
58 mozilla::gfx::DrawEventRecorder** aDrawEventRecorder) {
59 MOZ_ASSERT(aDrawEventRecorder);
60 *aDrawEventRecorder = nullptr;
61 return NS_OK;
64 /**
65 * @return DPI for printing.
67 float GetDPI() { return mozilla::StaticPrefs::print_default_dpi(); }
69 /**
70 * @return the printing scale to be applied to the context for printing.
72 float GetPrintingScale();
74 /**
75 * @return the point to translate the context to for printing.
77 gfxPoint GetPrintingTranslate();
79 NS_IMETHOD BeginDocument(const nsAString& aTitle,
80 const nsAString& aPrintToFileName,
81 int32_t aStartPage, int32_t aEndPage) = 0;
83 virtual RefPtr<mozilla::gfx::PrintEndDocumentPromise> EndDocument() = 0;
84 /**
85 * Note: not all print devices implement mixed page sizing. Internally,
86 * aSizeInPoints gets handed off to a PrintTarget, and most PrintTarget
87 * subclasses will ignore `aSizeInPoints`.
89 NS_IMETHOD BeginPage(const IntSize& aSizeInPoints) = 0;
90 NS_IMETHOD EndPage() = 0;
92 protected:
93 using AsyncEndDocumentFunction = mozilla::MoveOnlyFunction<nsresult()>;
94 static RefPtr<mozilla::gfx::PrintEndDocumentPromise> EndDocumentAsync(
95 const char* aCallSite, AsyncEndDocumentFunction aFunction);
97 static RefPtr<mozilla::gfx::PrintEndDocumentPromise>
98 EndDocumentPromiseFromResult(nsresult aResult, const char* aSite);
100 nsCOMPtr<nsIPrintSettings> mPrintSettings;
102 #ifdef MOZ_ENABLE_SKIA_PDF
103 // This variable is independant of nsIPrintSettings::kOutputFormatPDF (i.e.
104 // save-to-PDF). If set to true, then even when we print to a printer we
105 // output and send it PDF.
106 bool mPrintViaSkPDF = false;
107 #endif
110 NS_DEFINE_STATIC_IID_ACCESSOR(nsIDeviceContextSpec, NS_IDEVICE_CONTEXT_SPEC_IID)
111 #endif