2020-08-04 12:06:37 +00: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 11:26:13 +00:00
|
|
|
#include "mozilla/gfx/Rect.h"
|
2020-08-04 12:06:37 +00:00
|
|
|
#include "nsIPrinter.h"
|
2020-08-09 22:05:57 +00:00
|
|
|
#include "nsTArray.h"
|
2020-08-04 12:06:37 +00:00
|
|
|
#include "nsCycleCollectionParticipant.h"
|
|
|
|
#include "nsISupportsImpl.h"
|
|
|
|
#include "mozilla/EnumeratedArray.h"
|
|
|
|
#include "mozilla/Result.h"
|
|
|
|
|
2020-08-05 01:24:49 +00:00
|
|
|
namespace mozilla {
|
|
|
|
|
|
|
|
struct PaperInfo;
|
2020-08-20 06:11:08 +00:00
|
|
|
struct PrintSettingsInitializer;
|
2020-08-05 01:24:49 +00:00
|
|
|
|
|
|
|
namespace dom {
|
2020-08-04 12:06:37 +00:00
|
|
|
class Promise;
|
|
|
|
}
|
|
|
|
|
2020-08-05 01:24:49 +00:00
|
|
|
} // namespace mozilla
|
|
|
|
|
2020-08-04 12:06:37 +00:00
|
|
|
class nsPrinterBase : public nsIPrinter {
|
|
|
|
public:
|
|
|
|
using Promise = mozilla::dom::Promise;
|
2020-08-05 11:26:13 +00:00
|
|
|
using MarginDouble = mozilla::gfx::MarginDouble;
|
2020-08-20 06:11:08 +00:00
|
|
|
using PrintSettingsInitializer = mozilla::PrintSettingsInitializer;
|
2020-08-04 12:06:37 +00:00
|
|
|
|
2020-08-20 06:11:08 +00:00
|
|
|
NS_IMETHOD CreateDefaultSettings(JSContext*, Promise**) final;
|
2020-08-04 12:06:37 +00:00
|
|
|
NS_IMETHOD GetSupportsDuplex(JSContext*, Promise**) final;
|
|
|
|
NS_IMETHOD GetSupportsColor(JSContext*, Promise**) final;
|
2020-08-14 20:41:59 +00:00
|
|
|
NS_IMETHOD GetSupportsCollation(JSContext*, Promise**) final;
|
2020-08-05 01:24:49 +00:00
|
|
|
NS_IMETHOD GetPaperList(JSContext*, Promise**) final;
|
2020-08-04 12:06:37 +00:00
|
|
|
|
|
|
|
NS_DECL_CYCLE_COLLECTING_ISUPPORTS
|
|
|
|
NS_DECL_CYCLE_COLLECTION_CLASS(nsPrinterBase)
|
|
|
|
|
|
|
|
// No copy or move, we're an identity.
|
|
|
|
nsPrinterBase(const nsPrinterBase&) = delete;
|
|
|
|
nsPrinterBase(nsPrinterBase&&) = delete;
|
|
|
|
|
2020-08-05 11:26:13 +00:00
|
|
|
void QueryMarginsForPaper(Promise&, uint64_t aPaperId);
|
|
|
|
|
2020-08-04 12:06:37 +00:00
|
|
|
private:
|
|
|
|
enum class AsyncAttribute {
|
|
|
|
SupportsDuplex = 0,
|
|
|
|
SupportsColor,
|
2020-08-14 20:41:59 +00:00
|
|
|
SupportsCollation,
|
2020-08-05 01:24:49 +00:00
|
|
|
PaperList,
|
2020-08-04 12:06:37 +00:00
|
|
|
// Just a guard.
|
|
|
|
Last,
|
|
|
|
};
|
|
|
|
|
2020-08-09 22:05:57 +00:00
|
|
|
template <typename Result, typename... Args>
|
|
|
|
using BackgroundTask = Result (nsPrinterBase::*)(Args...) const;
|
2020-08-04 12:06:37 +00:00
|
|
|
|
|
|
|
// Resolves an async attribute via a background task.
|
2020-08-05 11:26:13 +00:00
|
|
|
template <typename T, typename... Args>
|
|
|
|
nsresult AsyncPromiseAttributeGetter(JSContext*, Promise**, AsyncAttribute,
|
|
|
|
BackgroundTask<T, Args...>,
|
|
|
|
Args... aArgs);
|
2020-08-04 12:06:37 +00:00
|
|
|
|
|
|
|
protected:
|
|
|
|
nsPrinterBase();
|
|
|
|
virtual ~nsPrinterBase();
|
|
|
|
|
|
|
|
// Implementation-specific methods. These must not make assumptions about
|
|
|
|
// which thread they run on.
|
2020-08-20 06:11:08 +00:00
|
|
|
virtual PrintSettingsInitializer DefaultSettings() const = 0;
|
2020-08-04 12:06:37 +00:00
|
|
|
virtual bool SupportsDuplex() const = 0;
|
|
|
|
virtual bool SupportsColor() const = 0;
|
2020-08-14 20:41:59 +00:00
|
|
|
virtual bool SupportsCollation() const = 0;
|
2020-08-05 01:24:49 +00:00
|
|
|
virtual nsTArray<mozilla::PaperInfo> PaperList() const = 0;
|
2020-08-05 11:26:13 +00:00
|
|
|
virtual MarginDouble GetMarginsForPaper(uint64_t aPaperId) const = 0;
|
2020-08-04 12:06:37 +00:00
|
|
|
|
|
|
|
private:
|
|
|
|
mozilla::EnumeratedArray<AsyncAttribute, AsyncAttribute::Last,
|
|
|
|
RefPtr<Promise>>
|
|
|
|
mAsyncAttributePromises;
|
|
|
|
};
|
|
|
|
|
|
|
|
#endif
|