From 9e3c08db40b8916968b9f30096c7be3f00ce9647 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Sun, 21 Apr 2024 13:44:51 +0200 Subject: Adding upstream version 1:115.7.0. Signed-off-by: Daniel Baumann --- widget/nsPrinterBase.h | 114 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 114 insertions(+) create mode 100644 widget/nsPrinterBase.h (limited to 'widget/nsPrinterBase.h') diff --git a/widget/nsPrinterBase.h b/widget/nsPrinterBase.h new file mode 100644 index 0000000000..abd4f82705 --- /dev/null +++ b/widget/nsPrinterBase.h @@ -0,0 +1,114 @@ +/* -*- 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__ + +#include "mozilla/gfx/Rect.h" +#include "nsIPrinter.h" +#include "nsTArray.h" +#include "nsCycleCollectionParticipant.h" +#include "nsISupportsImpl.h" +#include "nsPrintSettingsImpl.h" +#include "mozilla/EnumeratedArray.h" +#include "mozilla/Result.h" + +namespace mozilla { + +struct PaperInfo; + +namespace dom { +class Promise; +} + +} // namespace mozilla + +class nsPrinterBase : public nsIPrinter { + public: + using Promise = mozilla::dom::Promise; + using MarginDouble = mozilla::gfx::MarginDouble; + using PrintSettingsInitializer = mozilla::PrintSettingsInitializer; + + NS_IMETHOD CopyFromWithValidation(nsIPrintSettings*, JSContext*, + Promise**) override; + NS_IMETHOD GetSupportsDuplex(JSContext*, Promise**) final; + NS_IMETHOD GetSupportsColor(JSContext*, Promise**) final; + NS_IMETHOD GetSupportsMonochrome(JSContext*, Promise**) final; + NS_IMETHOD GetSupportsCollation(JSContext*, Promise**) final; + NS_IMETHOD GetPrinterInfo(JSContext*, Promise**) final; + + NS_DECL_CYCLE_COLLECTING_ISUPPORTS + NS_DECL_CYCLE_COLLECTION_CLASS(nsPrinterBase) + + // We require the paper info array + nsPrinterBase() = delete; + + // No copy or move, we're an identity. + nsPrinterBase(const nsPrinterBase&) = delete; + nsPrinterBase(nsPrinterBase&&) = delete; + + void QueryMarginsForPaper(Promise&, const nsString& aPaperId); + + /** + * Caches the argument by copying it into mPrintSettingsInitializer. + * If mPrintSettingsInitializer is already populated this is a no-op. + */ + void CachePrintSettingsInitializer( + const PrintSettingsInitializer& aInitializer); + + // Data to pass through to create the nsPrinterInfo + struct PrinterInfo { + nsTArray mPaperList; + PrintSettingsInitializer mDefaultSettings; + }; + + private: + enum class AsyncAttribute { + // If you change this list you must update attributeKeys in + // nsPrinterBase::AsyncPromiseAttributeGetter. + SupportsDuplex = 0, + SupportsColor, + SupportsMonochrome, + SupportsCollation, + PrinterInfo, + // Just a guard. + Last, + }; + + template + using BackgroundTask = Result (nsPrinterBase::*)(Args...) const; + + // Resolves an async attribute via a background task. + template + nsresult AsyncPromiseAttributeGetter(JSContext*, Promise**, AsyncAttribute, + BackgroundTask, + Args... aArgs); + + protected: + nsPrinterBase(const mozilla::CommonPaperInfoArray* aPaperInfoArray); + 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; + virtual bool SupportsMonochrome() const = 0; + virtual bool SupportsCollation() const = 0; + virtual MarginDouble GetMarginsForPaper(nsString aPaperId) const = 0; + virtual PrinterInfo CreatePrinterInfo() const = 0; + // 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; + + private: + mozilla::EnumeratedArray> + mAsyncAttributePromises; + // List of built-in, commonly used paper sizes. + const RefPtr mCommonPaperInfo; +}; + +#endif -- cgit v1.2.3