2020-08-04 15:06:37 +03:00
|
|
|
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
|
|
|
|
|
|
|
#ifndef nsPrinterBase_h__
|
|
|
|
#define nsPrinterBase_h__
|
|
|
|
|
2020-08-05 14:26:13 +03:00
|
|
|
#include "mozilla/gfx/Rect.h"
|
2020-08-04 15:06:37 +03:00
|
|
|
#include "nsIPrinter.h"
|
2020-08-10 01:05:57 +03:00
|
|
|
#include "nsTArray.h"
|
2020-08-04 15:06:37 +03:00
|
|
|
#include "nsCycleCollectionParticipant.h"
|
|
|
|
#include "nsISupportsImpl.h"
|
2020-08-24 03:53:46 +03:00
|
|
|
#include "nsPrintSettingsImpl.h"
|
2020-08-04 15:06:37 +03:00
|
|
|
#include "mozilla/EnumeratedArray.h"
|
|
|
|
#include "mozilla/Result.h"
|
|
|
|
|
2020-08-05 04:24:49 +03:00
|
|
|
namespace mozilla {
|
|
|
|
|
|
|
|
struct PaperInfo;
|
|
|
|
|
|
|
|
namespace dom {
|
2020-08-04 15:06:37 +03:00
|
|
|
class Promise;
|
|
|
|
}
|
|
|
|
|
2020-08-05 04:24:49 +03:00
|
|
|
} // namespace mozilla
|
|
|
|
|
2020-08-04 15:06:37 +03:00
|
|
|
class nsPrinterBase : public nsIPrinter {
|
|
|
|
public:
|
|
|
|
using Promise = mozilla::dom::Promise;
|
2020-08-05 14:26:13 +03:00
|
|
|
using MarginDouble = mozilla::gfx::MarginDouble;
|
2020-08-20 09:11:08 +03:00
|
|
|
using PrintSettingsInitializer = mozilla::PrintSettingsInitializer;
|
2020-08-04 15:06:37 +03:00
|
|
|
|
2021-11-16 11:17:02 +03:00
|
|
|
NS_IMETHOD CopyFromWithValidation(nsIPrintSettings*, JSContext*,
|
|
|
|
Promise**) override;
|
2020-08-04 15:06:37 +03:00
|
|
|
NS_IMETHOD GetSupportsDuplex(JSContext*, Promise**) final;
|
|
|
|
NS_IMETHOD GetSupportsColor(JSContext*, Promise**) final;
|
2020-09-07 21:58:48 +03:00
|
|
|
NS_IMETHOD GetSupportsMonochrome(JSContext*, Promise**) final;
|
2020-08-14 23:41:59 +03:00
|
|
|
NS_IMETHOD GetSupportsCollation(JSContext*, Promise**) final;
|
2020-11-03 23:35:38 +03:00
|
|
|
NS_IMETHOD GetPrinterInfo(JSContext*, Promise**) final;
|
2020-08-04 15:06:37 +03:00
|
|
|
|
|
|
|
NS_DECL_CYCLE_COLLECTING_ISUPPORTS
|
|
|
|
NS_DECL_CYCLE_COLLECTION_CLASS(nsPrinterBase)
|
|
|
|
|
2020-10-14 00:52:04 +03:00
|
|
|
// We require the paper info array
|
|
|
|
nsPrinterBase() = delete;
|
|
|
|
|
2020-08-04 15:06:37 +03:00
|
|
|
// No copy or move, we're an identity.
|
|
|
|
nsPrinterBase(const nsPrinterBase&) = delete;
|
|
|
|
nsPrinterBase(nsPrinterBase&&) = delete;
|
|
|
|
|
2020-09-17 23:05:08 +03:00
|
|
|
void QueryMarginsForPaper(Promise&, const nsString& aPaperId);
|
2020-08-05 14:26:13 +03:00
|
|
|
|
2020-08-24 03:53:46 +03:00
|
|
|
/**
|
|
|
|
* Caches the argument by copying it into mPrintSettingsInitializer.
|
|
|
|
* If mPrintSettingsInitializer is already populated this is a no-op.
|
|
|
|
*/
|
|
|
|
void CachePrintSettingsInitializer(
|
|
|
|
const PrintSettingsInitializer& aInitializer);
|
|
|
|
|
2020-11-03 23:35:38 +03:00
|
|
|
// Data to pass through to create the nsPrinterInfo
|
|
|
|
struct PrinterInfo {
|
|
|
|
nsTArray<mozilla::PaperInfo> mPaperList;
|
|
|
|
PrintSettingsInitializer mDefaultSettings;
|
|
|
|
};
|
|
|
|
|
2020-08-04 15:06:37 +03:00
|
|
|
private:
|
|
|
|
enum class AsyncAttribute {
|
2020-08-31 17:36:45 +03:00
|
|
|
// If you change this list you must update attributeKeys in
|
|
|
|
// nsPrinterBase::AsyncPromiseAttributeGetter.
|
2020-08-04 15:06:37 +03:00
|
|
|
SupportsDuplex = 0,
|
|
|
|
SupportsColor,
|
2020-09-07 21:58:48 +03:00
|
|
|
SupportsMonochrome,
|
2020-08-14 23:41:59 +03:00
|
|
|
SupportsCollation,
|
2020-11-03 23:35:38 +03:00
|
|
|
PrinterInfo,
|
2020-08-04 15:06:37 +03:00
|
|
|
// Just a guard.
|
|
|
|
Last,
|
|
|
|
};
|
|
|
|
|
2020-08-10 01:05:57 +03:00
|
|
|
template <typename Result, typename... Args>
|
|
|
|
using BackgroundTask = Result (nsPrinterBase::*)(Args...) const;
|
2020-08-04 15:06:37 +03:00
|
|
|
|
|
|
|
// Resolves an async attribute via a background task.
|
2020-08-05 14:26:13 +03:00
|
|
|
template <typename T, typename... Args>
|
|
|
|
nsresult AsyncPromiseAttributeGetter(JSContext*, Promise**, AsyncAttribute,
|
|
|
|
BackgroundTask<T, Args...>,
|
|
|
|
Args... aArgs);
|
2020-08-04 15:06:37 +03:00
|
|
|
|
|
|
|
protected:
|
2020-10-14 00:52:04 +03:00
|
|
|
nsPrinterBase(const mozilla::CommonPaperInfoArray* aPaperInfoArray);
|
2020-08-04 15:06:37 +03:00
|
|
|
virtual ~nsPrinterBase();
|
|
|
|
|
|
|
|
// Implementation-specific methods. These must not make assumptions about
|
|
|
|
// which thread they run on.
|
|
|
|
virtual bool SupportsDuplex() const = 0;
|
|
|
|
virtual bool SupportsColor() const = 0;
|
2020-09-07 21:58:48 +03:00
|
|
|
virtual bool SupportsMonochrome() const = 0;
|
2020-08-14 23:41:59 +03:00
|
|
|
virtual bool SupportsCollation() const = 0;
|
2020-09-17 23:05:08 +03:00
|
|
|
virtual MarginDouble GetMarginsForPaper(nsString aPaperId) const = 0;
|
2020-11-03 23:35:38 +03:00
|
|
|
virtual PrinterInfo CreatePrinterInfo() const = 0;
|
2020-10-14 00:52:04 +03:00
|
|
|
// Searches our built-in list of commonly used PWG paper sizes for a matching,
|
|
|
|
// localized PaperInfo. Returns null if there is no matching size.
|
|
|
|
const mozilla::PaperInfo* FindCommonPaperSize(
|
|
|
|
const mozilla::gfx::SizeDouble& aSize) const;
|
2020-08-04 15:06:37 +03:00
|
|
|
|
|
|
|
private:
|
2024-03-02 10:50:19 +03:00
|
|
|
mozilla::EnumeratedArray<AsyncAttribute, RefPtr<Promise>,
|
2024-03-02 10:50:19 +03:00
|
|
|
size_t(AsyncAttribute::Last)>
|
2020-08-04 15:06:37 +03:00
|
|
|
mAsyncAttributePromises;
|
2020-10-14 00:52:04 +03:00
|
|
|
// List of built-in, commonly used paper sizes.
|
|
|
|
const RefPtr<const mozilla::CommonPaperInfoArray> mCommonPaperInfo;
|
2020-08-04 15:06:37 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif
|