diff --git a/layout/base/tests/chrome/chrome.ini b/layout/base/tests/chrome/chrome.ini index 51c7233f042d..ab41d4608825 100644 --- a/layout/base/tests/chrome/chrome.ini +++ b/layout/base/tests/chrome/chrome.ini @@ -70,6 +70,7 @@ tags = openwindow [test_leaf_layers_partition_browser_window.xhtml] skip-if = true # Bug 992311 [test_prerendered_transforms.html] +[test_printer_default_settings.html] [test_printpreview.xhtml] skip-if = (os == "linux" && bits == 32) || (verify && (os == 'win')) # Disabled on Linux32 for bug 1278957 [test_printpreview_bug396024.xhtml] diff --git a/layout/base/tests/chrome/test_printer_default_settings.html b/layout/base/tests/chrome/test_printer_default_settings.html new file mode 100644 index 000000000000..cfef9fafe9db --- /dev/null +++ b/layout/base/tests/chrome/test_printer_default_settings.html @@ -0,0 +1,66 @@ + + + + + + + + + diff --git a/widget/android/nsPrintSettingsServiceAndroid.cpp b/widget/android/nsPrintSettingsServiceAndroid.cpp index 3abf2e4bb848..67f978c6e343 100644 --- a/widget/android/nsPrintSettingsServiceAndroid.cpp +++ b/widget/android/nsPrintSettingsServiceAndroid.cpp @@ -24,3 +24,10 @@ nsresult nsPrintSettingsServiceAndroid::_CreatePrintSettings( nsIPrintSettings::kInitSaveAll); return NS_OK; } + +already_AddRefed CreatePlatformPrintSettings( + const mozilla::PrintSettingsInitializer& aSettings) { + RefPtr settings = new nsPrintSettingsAndroid(); + settings->InitWithInitializer(aSettings); + return settings.forget(); +} diff --git a/widget/cocoa/nsPrintSettingsX.h b/widget/cocoa/nsPrintSettingsX.h index d479c9cf2869..fe0678c9f56e 100644 --- a/widget/cocoa/nsPrintSettingsX.h +++ b/widget/cocoa/nsPrintSettingsX.h @@ -22,6 +22,7 @@ class nsPrintSettingsX : public nsPrintSettings { NS_DECL_ISUPPORTS_INHERITED nsPrintSettingsX(); + explicit nsPrintSettingsX(const PrintSettingsInitializer& aSettings); nsresult Init(); NSPrintInfo* GetCocoaPrintInfo() { return mPrintInfo; } void SetCocoaPrintInfo(NSPrintInfo* aPrintInfo); diff --git a/widget/cocoa/nsPrintSettingsX.mm b/widget/cocoa/nsPrintSettingsX.mm index 60c5c6777fef..d028ae8d5dec 100644 --- a/widget/cocoa/nsPrintSettingsX.mm +++ b/widget/cocoa/nsPrintSettingsX.mm @@ -47,6 +47,14 @@ nsPrintSettingsX::nsPrintSettingsX() : mAdjustedPaperWidth{0.0}, mAdjustedPaperH NS_OBJC_END_TRY_ABORT_BLOCK; } +already_AddRefed CreatePlatformPrintSettings( + const PrintSettingsInitializer& aSettings) { + RefPtr settings = new nsPrintSettingsX(); + settings->InitWithInitializer(aSettings); + settings->SetDefaultFileName(); + return settings.forget(); +} + nsPrintSettingsX::nsPrintSettingsX(const nsPrintSettingsX& src) { *this = src; } nsPrintSettingsX::~nsPrintSettingsX() { diff --git a/widget/gtk/nsPrintSettingsGTK.cpp b/widget/gtk/nsPrintSettingsGTK.cpp index ccbab80e0a12..39808c12435f 100644 --- a/widget/gtk/nsPrintSettingsGTK.cpp +++ b/widget/gtk/nsPrintSettingsGTK.cpp @@ -50,6 +50,14 @@ nsPrintSettingsGTK::nsPrintSettingsGTK() SetOutputFormat(nsIPrintSettings::kOutputFormatNative); } +already_AddRefed CreatePlatformPrintSettings( + const PrintSettingsInitializer& aSettings) { + RefPtr settings = new nsPrintSettingsGTK(); + settings->InitWithInitializer(aSettings); + settings->SetDefaultFileName(); + return settings.forget(); +} + /** --------------------------------------------------- */ nsPrintSettingsGTK::~nsPrintSettingsGTK() { diff --git a/widget/gtk/nsPrintSettingsGTK.h b/widget/gtk/nsPrintSettingsGTK.h index 708154ac0c47..301c250eaed0 100644 --- a/widget/gtk/nsPrintSettingsGTK.h +++ b/widget/gtk/nsPrintSettingsGTK.h @@ -31,6 +31,7 @@ class nsPrintSettingsGTK : public nsPrintSettings { NS_DECLARE_STATIC_IID_ACCESSOR(NS_PRINTSETTINGSGTK_IID) nsPrintSettingsGTK(); + explicit nsPrintSettingsGTK(const PrintSettingsInitializer& aSettings); // We're overriding these methods because we want to read/write with GTK // objects, not local variables. This allows a simpler settings implementation diff --git a/widget/nsCUPSShim.h b/widget/nsCUPSShim.h index a80078f5159e..a38cc63cba87 100644 --- a/widget/nsCUPSShim.h +++ b/widget/nsCUPSShim.h @@ -35,6 +35,7 @@ class nsCUPSShim { X(cupsCopyDestInfo) \ X(cupsFreeDestInfo) \ X(cupsFreeDests) \ + X(cupsGetDestMediaDefault) \ X(cupsGetDestMediaCount) \ X(cupsGetDestMediaByIndex) \ X(cupsGetDest) \ diff --git a/widget/nsIPrintSettings.idl b/widget/nsIPrintSettings.idl index 968d0b3a542f..fa3c6c685db0 100644 --- a/widget/nsIPrintSettings.idl +++ b/widget/nsIPrintSettings.idl @@ -273,3 +273,11 @@ interface nsIPrintSettings : nsISupports */ [noscript] void GetPageRanges(in IntegerArray aPages); }; + +%{ C++ +namespace mozilla { +struct PrintSettingsInitializer; +} + +already_AddRefed CreatePlatformPrintSettings(const mozilla::PrintSettingsInitializer&); +%} diff --git a/widget/nsIPrinter.idl b/widget/nsIPrinter.idl index 8e93e7401c73..538e2b00c22f 100644 --- a/widget/nsIPrinter.idl +++ b/widget/nsIPrinter.idl @@ -14,6 +14,14 @@ interface nsIPrinter : nsISupports */ readonly attribute AString name; + /** + * Creates a Promise that will resolve to an nsIPrintSettings object containing + * the default settings for this printer. For convenience, a new, mutable + * nsIPrintSettings object is created for each call. + */ + [implicit_jscontext] + Promise createDefaultSettings(); + /** * Returns a Promise that resolves to an array of * nsIPaper instances with the list of available paper diff --git a/widget/nsPaper.cpp b/widget/nsPaper.cpp index 75452e90466e..e80b332e0290 100644 --- a/widget/nsPaper.cpp +++ b/widget/nsPaper.cpp @@ -10,6 +10,7 @@ #include "mozilla/dom/Promise.h" using mozilla::ErrorResult; +using mozilla::PaperInfo; NS_IMPL_CYCLE_COLLECTION(nsPaper, mMarginPromise, mPrinter) diff --git a/widget/nsPaper.h b/widget/nsPaper.h index ae60bc047bed..e2ca685abbc3 100644 --- a/widget/nsPaper.h +++ b/widget/nsPaper.h @@ -25,12 +25,21 @@ struct PaperInfo { using MarginDouble = mozilla::gfx::MarginDouble; using SizeDouble = mozilla::gfx::SizeDouble; + PaperInfo() = default; + PaperInfo(const nsAString& aName, const SizeDouble& aSize, + const Maybe& aUnwriteableMargin, + uint64_t aPaperId = 0) + : mName(aName), + mSize(aSize), + mUnwriteableMargin(aUnwriteableMargin), + mPaperId(aPaperId) {} + const nsString mName; SizeDouble mSize; // The margins may not be known by some back-ends. - const Maybe mUnwriteableMargin; + const Maybe mUnwriteableMargin{Nothing()}; // The paper id from the device, this is only useful on Windows, right now. uint64_t mPaperId{0}; diff --git a/widget/nsPrintSettingsImpl.cpp b/widget/nsPrintSettingsImpl.cpp index 4fd724d5374d..174368a03ded 100644 --- a/widget/nsPrintSettingsImpl.cpp +++ b/widget/nsPrintSettingsImpl.cpp @@ -4,6 +4,9 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ #include "nsPrintSettingsImpl.h" + +#include "nsCoord.h" +#include "nsPaper.h" #include "nsReadableUtils.h" #include "nsIPrintSession.h" #include "mozilla/RefPtr.h" @@ -57,6 +60,29 @@ nsPrintSettings::nsPrintSettings() mFooterStrs[2].AssignLiteral("&D"); } +void nsPrintSettings::InitWithInitializer( + const PrintSettingsInitializer& aSettings) { + const double kInchesPerPoint = 1.0 / 72.0; + + SetPrinterName(aSettings.mPrinter); + SetPrintInColor(aSettings.mPrintInColor); + SetPaperName(aSettings.mPaperInfo.mName); + SetPaperWidth(aSettings.mPaperInfo.mSize.Width() * kInchesPerPoint); + SetPaperHeight(aSettings.mPaperInfo.mSize.Height() * kInchesPerPoint); + SetPaperSizeUnit(nsIPrintSettings::kPaperSizeInches); + + if (aSettings.mPaperInfo.mUnwriteableMargin) { + const auto& margin = aSettings.mPaperInfo.mUnwriteableMargin.value(); + SetUnwriteableMarginTop(NS_POINTS_TO_TWIPS(margin.top)); + SetUnwriteableMarginRight(NS_POINTS_TO_TWIPS(margin.right)); + SetUnwriteableMarginBottom(NS_POINTS_TO_TWIPS(margin.bottom)); + SetUnwriteableMarginLeft(NS_POINTS_TO_TWIPS(margin.left)); + } + + // Set this last because other setters may overwrite its value. + SetIsInitializedFromPrinter(true); +} + nsPrintSettings::nsPrintSettings(const nsPrintSettings& aPS) { *this = aPS; } nsPrintSettings::~nsPrintSettings() = default; @@ -797,3 +823,23 @@ nsPrintSettings& nsPrintSettings::operator=(const nsPrintSettings& rhs) { return *this; } + +void nsPrintSettings::SetDefaultFileName() { + nsAutoString filename; + nsresult rv = GetToFileName(filename); + if (NS_FAILED(rv) || filename.IsEmpty()) { + const char* path = PR_GetEnv("PWD"); + if (!path) { + path = PR_GetEnv("HOME"); + } + + if (path) { + CopyUTF8toUTF16(mozilla::MakeStringSpan(path), filename); + filename.AppendLiteral("/mozilla.pdf"); + } else { + filename.AssignLiteral("mozilla.pdf"); + } + + SetToFileName(filename); + } +} diff --git a/widget/nsPrintSettingsImpl.h b/widget/nsPrintSettingsImpl.h index 166369adf264..a296a9b0c786 100644 --- a/widget/nsPrintSettingsImpl.h +++ b/widget/nsPrintSettingsImpl.h @@ -10,6 +10,7 @@ #include "nsIPrintSettings.h" #include "nsIWeakReferenceUtils.h" #include "nsMargin.h" +#include "nsPaper.h" #include "nsString.h" #define NUM_HEAD_FOOT 3 @@ -18,16 +19,41 @@ //*** nsPrintSettings //***************************************************************************** +namespace mozilla { + +/** + * A struct that can be used off the main thread to collect printer-specific + * info that can be used to initialized a default nsIPrintSettings object. + */ +struct PrintSettingsInitializer { + nsString mPrinter; + PaperInfo mPaperInfo; + bool mPrintInColor = false; +}; + +} // namespace mozilla + class nsPrintSettings : public nsIPrintSettings { public: NS_DECL_ISUPPORTS NS_DECL_NSIPRINTSETTINGS + using PrintSettingsInitializer = mozilla::PrintSettingsInitializer; nsPrintSettings(); nsPrintSettings(const nsPrintSettings& aPS); + /** + * Initialize relevant members from the PrintSettingsInitializer. + * This is specifically not a constructor so that we can ensure that the + * relevant setters are dynamically dispatched to derived classes. + */ + void InitWithInitializer(const PrintSettingsInitializer& aSettings); + nsPrintSettings& operator=(const nsPrintSettings& rhs); + // Sets a default file name for the print settings. + void SetDefaultFileName(); + protected: virtual ~nsPrintSettings(); diff --git a/widget/nsPrinterBase.cpp b/widget/nsPrinterBase.cpp index 8fea772badec..123376d2326a 100644 --- a/widget/nsPrinterBase.cpp +++ b/widget/nsPrinterBase.cpp @@ -7,6 +7,7 @@ #include "nsPaperMargin.h" #include #include "nsPaper.h" +#include "nsIPrintSettings.h" #include "PrintBackgroundTask.h" #include "mozilla/dom/Promise.h" @@ -53,6 +54,13 @@ void ResolveOrReject(Promise& aPromise, nsPrinterBase& aPrinter, aPromise.MaybeResolve(result); } +template <> +void ResolveOrReject(Promise& aPromise, nsPrinterBase& aPrinter, + const PrintSettingsInitializer& aResult) { + aPromise.MaybeResolve( + RefPtr(CreatePlatformPrintSettings(aResult))); +} + } // namespace mozilla template @@ -65,6 +73,14 @@ nsresult nsPrinterBase::AsyncPromiseAttributeGetter( aBackgroundTask, std::forward(aArgs)...); } +NS_IMETHODIMP nsPrinterBase::CreateDefaultSettings(JSContext* aCx, + Promise** aResultPromise) { + // This doesn't yet implement caching. See bug 1659551. + MOZ_ASSERT(NS_IsMainThread()); + return PrintBackgroundTaskPromise(*this, aCx, aResultPromise, + &nsPrinterBase::DefaultSettings); +} + NS_IMETHODIMP nsPrinterBase::GetSupportsDuplex(JSContext* aCx, Promise** aResultPromise) { return AsyncPromiseAttributeGetter(aCx, aResultPromise, diff --git a/widget/nsPrinterBase.h b/widget/nsPrinterBase.h index 076996300cc9..891bd0e34ebb 100644 --- a/widget/nsPrinterBase.h +++ b/widget/nsPrinterBase.h @@ -17,6 +17,7 @@ namespace mozilla { struct PaperInfo; +struct PrintSettingsInitializer; namespace dom { class Promise; @@ -28,7 +29,9 @@ class nsPrinterBase : public nsIPrinter { public: using Promise = mozilla::dom::Promise; using MarginDouble = mozilla::gfx::MarginDouble; + using PrintSettingsInitializer = mozilla::PrintSettingsInitializer; + NS_IMETHOD CreateDefaultSettings(JSContext*, Promise**) final; NS_IMETHOD GetSupportsDuplex(JSContext*, Promise**) final; NS_IMETHOD GetSupportsColor(JSContext*, Promise**) final; NS_IMETHOD GetSupportsCollation(JSContext*, Promise**) final; @@ -68,6 +71,7 @@ class nsPrinterBase : public nsIPrinter { // Implementation-specific methods. These must not make assumptions about // which thread they run on. + virtual PrintSettingsInitializer DefaultSettings() const = 0; virtual bool SupportsDuplex() const = 0; virtual bool SupportsColor() const = 0; virtual bool SupportsCollation() const = 0; diff --git a/widget/nsPrinterCUPS.cpp b/widget/nsPrinterCUPS.cpp index c33c6f3cb8ad..d38f43e7bdeb 100644 --- a/widget/nsPrinterCUPS.cpp +++ b/widget/nsPrinterCUPS.cpp @@ -6,9 +6,24 @@ #include "nsPrinterCUPS.h" #include "nsPaper.h" #include "nsPrinterBase.h" +#include "nsPrintSettingsImpl.h" #include "plstr.h" +static PaperInfo MakePaperInfo(const char* aName, const cups_size_t& aMedia) { + // XXX Do we actually have the guarantee that this is utf-8? + NS_ConvertUTF8toUTF16 name(aName ? aName : aMedia.media); + const double kPointsPerHundredthMillimeter = 0.0283465; + return PaperInfo( + name, + {aMedia.width * kPointsPerHundredthMillimeter, + aMedia.length * kPointsPerHundredthMillimeter}, + Some(MarginDouble{aMedia.top * kPointsPerHundredthMillimeter, + aMedia.right * kPointsPerHundredthMillimeter, + aMedia.bottom * kPointsPerHundredthMillimeter, + aMedia.left * kPointsPerHundredthMillimeter})); +} + nsPrinterCUPS::~nsPrinterCUPS() { if (mPrinterInfo) { mShim.cupsFreeDestInfo(mPrinterInfo); @@ -20,15 +35,69 @@ nsPrinterCUPS::~nsPrinterCUPS() { } } +PrintSettingsInitializer nsPrinterCUPS::DefaultSettings() const { + nsString printerName; + GetPrinterName(printerName); + + cups_size_t media; + + bool hasDefaultMedia = + mShim.cupsGetDestMediaDefault(CUPS_HTTP_DEFAULT, mPrinter, mPrinterInfo, + CUPS_MEDIA_FLAGS_DEFAULT, &media); + + if (!hasDefaultMedia) { + Nothing(); + return PrintSettingsInitializer{ + std::move(printerName), + PaperInfo(), + SupportsColor(), + }; + } + + const char* localizedName = nullptr; + + // blocking call + http_t* connection = mShim.cupsConnectDest(mPrinter, CUPS_DEST_FLAGS_NONE, + /* timeout(ms) */ 5000, + /* cancel */ nullptr, + /* resource */ nullptr, + /* resourcesize */ 0, + /* callback */ nullptr, + /* user_data */ nullptr); + + if (connection) { + localizedName = LocalizeMediaName(*connection, media); + mShim.httpClose(connection); + } + + return PrintSettingsInitializer{ + std::move(printerName), + MakePaperInfo(localizedName, media), + SupportsColor(), + }; +} + NS_IMETHODIMP nsPrinterCUPS::GetName(nsAString& aName) { + GetPrinterName(aName); + return NS_OK; +} + +void nsPrinterCUPS::GetPrinterName(nsAString& aName) const { if (mDisplayName.IsEmpty()) { aName.Truncate(); CopyUTF8toUTF16(MakeStringSpan(mPrinter->name), aName); } else { aName = mDisplayName; } - return NS_OK; +} + +const char* nsPrinterCUPS::LocalizeMediaName(http_t& aConnection, + cups_size_t& aMedia) const { + // The returned string is owned by mPrinterInfo. + // https://www.cups.org/doc/cupspm.html#cupsLocalizeDestMedia + return mShim.cupsLocalizeDestMedia(&aConnection, mPrinter, mPrinterInfo, + CUPS_MEDIA_FLAGS_DEFAULT, &aMedia); } bool nsPrinterCUPS::SupportsDuplex() const { @@ -81,37 +150,17 @@ nsTArray nsPrinterCUPS::PaperList() const { nsTArray paperList; for (int i = 0; i < paperCount; ++i) { - cups_size_t info; + cups_size_t media; int getInfoSucceded = mShim.cupsGetDestMediaByIndex(CUPS_HTTP_DEFAULT, mPrinter, mPrinterInfo, - i, CUPS_MEDIA_FLAGS_DEFAULT, &info); + i, CUPS_MEDIA_FLAGS_DEFAULT, &media); if (!getInfoSucceded) { continue; } - // localizedName is owned by mPrinterInfo. - // https://www.cups.org/doc/cupspm.html#cupsLocalizeDestMedia - const char* localizedName = mShim.cupsLocalizeDestMedia( - connection, mPrinter, mPrinterInfo, CUPS_MEDIA_FLAGS_DEFAULT, &info); - - if (!localizedName) { - continue; - } - - // XXX Do we actually have the guarantee that this is utf-8? - NS_ConvertUTF8toUTF16 name(localizedName); - const double kPointsPerHundredthMillimeter = 0.0283465; - - paperList.AppendElement(PaperInfo{ - std::move(name), - {info.width * kPointsPerHundredthMillimeter, - info.length * kPointsPerHundredthMillimeter}, - Some(MarginDouble{info.top * kPointsPerHundredthMillimeter, - info.right * kPointsPerHundredthMillimeter, - info.bottom * kPointsPerHundredthMillimeter, - info.left * kPointsPerHundredthMillimeter}), - }); + paperList.AppendElement( + MakePaperInfo(LocalizeMediaName(*connection, media), media)); } mShim.httpClose(connection); diff --git a/widget/nsPrinterCUPS.h b/widget/nsPrinterCUPS.h index ba5f13da298a..7684188585f5 100644 --- a/widget/nsPrinterCUPS.h +++ b/widget/nsPrinterCUPS.h @@ -7,6 +7,7 @@ #define nsPrinterCUPS_h___ #include "nsPrinterBase.h" +#include "nsPrintSettingsImpl.h" #include "nsCUPSShim.h" #include "nsString.h" @@ -16,6 +17,7 @@ class nsPrinterCUPS final : public nsPrinterBase { public: NS_IMETHOD GetName(nsAString& aName) override; + PrintSettingsInitializer DefaultSettings() const final; bool SupportsDuplex() const final; bool SupportsColor() const final; bool SupportsCollation() const final; @@ -39,6 +41,13 @@ class nsPrinterCUPS final : public nsPrinterBase { private: ~nsPrinterCUPS(); + /** + * Retrieves the localized name for a given media (paper). + */ + const char* LocalizeMediaName(http_t& aConnection, cups_size_t& aMedia) const; + + void GetPrinterName(nsAString& aName) const; + // Little util for getting support flags using the direct CUPS names. bool Supports(const char* option, const char* value) const; diff --git a/widget/windows/nsPrintSettingsWin.cpp b/widget/windows/nsPrintSettingsWin.cpp index 1a107dd986dc..4095e50211f3 100644 --- a/widget/windows/nsPrintSettingsWin.cpp +++ b/widget/windows/nsPrintSettingsWin.cpp @@ -6,6 +6,7 @@ #include "mozilla/ArrayUtils.h" #include "nsCRT.h" +#include "nsDeviceContextSpecWin.h" #include "WinUtils.h" // Using paper sizes from wingdi.h and the units given there, plus a little @@ -159,6 +160,40 @@ nsPrintSettingsWin::nsPrintSettingsWin(const nsPrintSettingsWin& aPS) *this = aPS; } +already_AddRefed CreatePlatformPrintSettings( + const PrintSettingsInitializer& aSettings) { + auto settings = MakeRefPtr(); + settings->InitWithInitializer(aSettings); + + // When printing to PDF on Windows there is no associated printer driver. + int16_t outputFormat; + settings->GetOutputFormat(&outputFormat); + if (outputFormat == nsIPrintSettings::kOutputFormatPDF) { + return settings.forget(); + } + + RefPtr devSpecWin = new nsDeviceContextSpecWin(); + + nsString name; + settings->GetPrinterName(name); + devSpecWin->GetDataFromPrinter(name); + + LPDEVMODEW devmode; + devSpecWin->GetDevMode(devmode); + if (NS_WARN_IF(!devmode)) { + return settings.forget(); + } + + // TODO(nordzilla, 1658299) + // We need to get information from the device as well. + // See InitPrintSettingsFromPrinter call to CreateICW and the code + // below it. The issue is that we can't do it here. It needs to + // happen async, off the main thread, similar to the code that + // populates the PrintSettingsInitializer argument. + + return settings.forget(); +} + /** --------------------------------------------------- * See documentation in nsPrintSettingsWin.h * @update diff --git a/widget/windows/nsPrintSettingsWin.h b/widget/windows/nsPrintSettingsWin.h index 8f512df7f4e3..eed35e38da8e 100644 --- a/widget/windows/nsPrintSettingsWin.h +++ b/widget/windows/nsPrintSettingsWin.h @@ -23,6 +23,7 @@ class nsPrintSettingsWin : public nsPrintSettings, public nsIPrintSettingsWin { nsPrintSettingsWin(); nsPrintSettingsWin(const nsPrintSettingsWin& aPS); + explicit nsPrintSettingsWin(const PrintSettingsInitializer&); /** * Makes a new copy diff --git a/widget/windows/nsPrinterWin.cpp b/widget/windows/nsPrinterWin.cpp index fb3128f58126..6d4a02a0ccc0 100644 --- a/widget/windows/nsPrinterWin.cpp +++ b/widget/windows/nsPrinterWin.cpp @@ -24,6 +24,14 @@ already_AddRefed nsPrinterWin::Create(const nsAString& aName) { return do_AddRef(new nsPrinterWin(aName)); } +// TODO(nordzilla, 165829) This needs to be implemented for windows. +// It should basically collect the same information as +// nsPrinterListWin::InitPrintSettingsFromPrinter. +PrintSettingsInitializer nsPrinterWin::DefaultSettings() const { + PrintSettingsInitializer settings; + return settings; +} + template static nsTArray GetDeviceCapabilityArray(const LPWSTR aPrinterName, WORD aCapabilityID) { @@ -119,12 +127,8 @@ nsTArray nsPrinterWin::PaperList() const { // We don't resolve the margins eagerly because they're really expensive (on // the order of seconds for some drivers). nsDependentSubstring name(paperNames[i].cbegin(), nameLength); - paperList.AppendElement(mozilla::PaperInfo{ - nsString(name), - {width, height}, - Nothing(), - paperIds[i], - }); + paperList.AppendElement(mozilla::PaperInfo(nsString(name), {width, height}, + Nothing(), paperIds[i])); } return paperList; diff --git a/widget/windows/nsPrinterWin.h b/widget/windows/nsPrinterWin.h index 0da2cc4a8f0b..78fa864e76e9 100644 --- a/widget/windows/nsPrinterWin.h +++ b/widget/windows/nsPrinterWin.h @@ -11,7 +11,7 @@ class nsPrinterWin final : public nsPrinterBase { public: NS_IMETHOD GetName(nsAString& aName) override; - + PrintSettingsInitializer DefaultSettings() const final; bool SupportsDuplex() const final; bool SupportsColor() const final; bool SupportsCollation() const final;