1 /* -*- Mode: C++; tab-width: 4; 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 nsPrinterBase_h__
7 #define nsPrinterBase_h__
9 #include "mozilla/gfx/Rect.h"
10 #include "nsIPrinter.h"
12 #include "nsCycleCollectionParticipant.h"
13 #include "nsISupportsImpl.h"
14 #include "nsPrintSettingsImpl.h"
15 #include "mozilla/EnumeratedArray.h"
16 #include "mozilla/Result.h"
26 } // namespace mozilla
28 class nsPrinterBase
: public nsIPrinter
{
30 using Promise
= mozilla::dom::Promise
;
31 using MarginDouble
= mozilla::gfx::MarginDouble
;
32 using PrintSettingsInitializer
= mozilla::PrintSettingsInitializer
;
34 NS_IMETHOD
CopyFromWithValidation(nsIPrintSettings
*, JSContext
*,
36 NS_IMETHOD
GetSupportsDuplex(JSContext
*, Promise
**) final
;
37 NS_IMETHOD
GetSupportsColor(JSContext
*, Promise
**) final
;
38 NS_IMETHOD
GetSupportsMonochrome(JSContext
*, Promise
**) final
;
39 NS_IMETHOD
GetSupportsCollation(JSContext
*, Promise
**) final
;
40 NS_IMETHOD
GetPrinterInfo(JSContext
*, Promise
**) final
;
42 NS_DECL_CYCLE_COLLECTING_ISUPPORTS
43 NS_DECL_CYCLE_COLLECTION_CLASS(nsPrinterBase
)
45 // We require the paper info array
46 nsPrinterBase() = delete;
48 // No copy or move, we're an identity.
49 nsPrinterBase(const nsPrinterBase
&) = delete;
50 nsPrinterBase(nsPrinterBase
&&) = delete;
52 void QueryMarginsForPaper(Promise
&, const nsString
& aPaperId
);
55 * Caches the argument by copying it into mPrintSettingsInitializer.
56 * If mPrintSettingsInitializer is already populated this is a no-op.
58 void CachePrintSettingsInitializer(
59 const PrintSettingsInitializer
& aInitializer
);
61 // Data to pass through to create the nsPrinterInfo
63 nsTArray
<mozilla::PaperInfo
> mPaperList
;
64 PrintSettingsInitializer mDefaultSettings
;
68 enum class AsyncAttribute
{
69 // If you change this list you must update attributeKeys in
70 // nsPrinterBase::AsyncPromiseAttributeGetter.
80 template <typename Result
, typename
... Args
>
81 using BackgroundTask
= Result (nsPrinterBase::*)(Args
...) const;
83 // Resolves an async attribute via a background task.
84 template <typename T
, typename
... Args
>
85 nsresult
AsyncPromiseAttributeGetter(JSContext
*, Promise
**, AsyncAttribute
,
86 BackgroundTask
<T
, Args
...>,
90 nsPrinterBase(const mozilla::CommonPaperInfoArray
* aPaperInfoArray
);
91 virtual ~nsPrinterBase();
93 // Implementation-specific methods. These must not make assumptions about
94 // which thread they run on.
95 virtual bool SupportsDuplex() const = 0;
96 virtual bool SupportsColor() const = 0;
97 virtual bool SupportsMonochrome() const = 0;
98 virtual bool SupportsCollation() const = 0;
99 virtual MarginDouble
GetMarginsForPaper(nsString aPaperId
) const = 0;
100 virtual PrinterInfo
CreatePrinterInfo() const = 0;
101 // Searches our built-in list of commonly used PWG paper sizes for a matching,
102 // localized PaperInfo. Returns null if there is no matching size.
103 const mozilla::PaperInfo
* FindCommonPaperSize(
104 const mozilla::gfx::SizeDouble
& aSize
) const;
107 mozilla::EnumeratedArray
<AsyncAttribute
, AsyncAttribute::Last
,
109 mAsyncAttributePromises
;
110 // List of built-in, commonly used paper sizes.
111 const RefPtr
<const mozilla::CommonPaperInfoArray
> mCommonPaperInfo
;