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
GetSupportsDuplex(JSContext
*, Promise
**) final
;
35 NS_IMETHOD
GetSupportsColor(JSContext
*, Promise
**) final
;
36 NS_IMETHOD
GetSupportsMonochrome(JSContext
*, Promise
**) final
;
37 NS_IMETHOD
GetSupportsCollation(JSContext
*, Promise
**) final
;
38 NS_IMETHOD
GetPrinterInfo(JSContext
*, Promise
**) final
;
40 NS_DECL_CYCLE_COLLECTING_ISUPPORTS
41 NS_DECL_CYCLE_COLLECTION_CLASS(nsPrinterBase
)
43 // We require the paper info array
44 nsPrinterBase() = delete;
46 // No copy or move, we're an identity.
47 nsPrinterBase(const nsPrinterBase
&) = delete;
48 nsPrinterBase(nsPrinterBase
&&) = delete;
50 void QueryMarginsForPaper(Promise
&, const nsString
& aPaperId
);
53 * Caches the argument by copying it into mPrintSettingsInitializer.
54 * If mPrintSettingsInitializer is already populated this is a no-op.
56 void CachePrintSettingsInitializer(
57 const PrintSettingsInitializer
& aInitializer
);
59 // Data to pass through to create the nsPrinterInfo
61 nsTArray
<mozilla::PaperInfo
> mPaperList
;
62 PrintSettingsInitializer mDefaultSettings
;
66 enum class AsyncAttribute
{
67 // If you change this list you must update attributeKeys in
68 // nsPrinterBase::AsyncPromiseAttributeGetter.
78 template <typename Result
, typename
... Args
>
79 using BackgroundTask
= Result (nsPrinterBase::*)(Args
...) const;
81 // Resolves an async attribute via a background task.
82 template <typename T
, typename
... Args
>
83 nsresult
AsyncPromiseAttributeGetter(JSContext
*, Promise
**, AsyncAttribute
,
84 BackgroundTask
<T
, Args
...>,
88 nsPrinterBase(const mozilla::CommonPaperInfoArray
* aPaperInfoArray
);
89 virtual ~nsPrinterBase();
91 // Implementation-specific methods. These must not make assumptions about
92 // which thread they run on.
93 virtual bool SupportsDuplex() const = 0;
94 virtual bool SupportsColor() const = 0;
95 virtual bool SupportsMonochrome() const = 0;
96 virtual bool SupportsCollation() const = 0;
97 virtual MarginDouble
GetMarginsForPaper(nsString aPaperId
) const = 0;
98 virtual PrinterInfo
CreatePrinterInfo() const = 0;
99 // Searches our built-in list of commonly used PWG paper sizes for a matching,
100 // localized PaperInfo. Returns null if there is no matching size.
101 const mozilla::PaperInfo
* FindCommonPaperSize(
102 const mozilla::gfx::SizeDouble
& aSize
) const;
105 mozilla::EnumeratedArray
<AsyncAttribute
, AsyncAttribute::Last
,
107 mAsyncAttributePromises
;
108 // List of built-in, commonly used paper sizes.
109 const RefPtr
<const mozilla::CommonPaperInfoArray
> mCommonPaperInfo
;