cef/patch/patches/linux_printing_context.patch

137 lines
4.8 KiB
Diff

diff --git printing/printing_context_linux.cc printing/printing_context_linux.cc
index 49f0ddab8318e..a3a9cd189fc2f 100644
--- printing/printing_context_linux.cc
+++ printing/printing_context_linux.cc
@@ -69,11 +69,11 @@ mojom::ResultCode PrintingContextLinux::UseDefaultSettings() {
ResetSettings();
#if BUILDFLAG(IS_LINUX)
- if (!ui::LinuxUi::instance())
+ if (!ui::PrintingContextLinuxDelegate::instance())
return mojom::ResultCode::kSuccess;
if (!print_dialog_)
- print_dialog_ = ui::LinuxUi::instance()->CreatePrintDialog(this);
+ print_dialog_ = ui::PrintingContextLinuxDelegate::instance()->CreatePrintDialog(this);
if (print_dialog_) {
print_dialog_->UseDefaultSettings();
@@ -85,8 +85,8 @@ mojom::ResultCode PrintingContextLinux::UseDefaultSettings() {
gfx::Size PrintingContextLinux::GetPdfPaperSizeDeviceUnits() {
#if BUILDFLAG(IS_LINUX)
- if (ui::LinuxUi::instance())
- return ui::LinuxUi::instance()->GetPdfPaperSize(this);
+ if (ui::PrintingContextLinuxDelegate::instance())
+ return ui::PrintingContextLinuxDelegate::instance()->GetPdfPaperSize(this);
#endif
return gfx::Size();
@@ -98,11 +98,11 @@ mojom::ResultCode PrintingContextLinux::UpdatePrinterSettings(
DCHECK(!in_print_job_);
#if BUILDFLAG(IS_LINUX)
- if (!ui::LinuxUi::instance())
+ if (!ui::PrintingContextLinuxDelegate::instance())
return mojom::ResultCode::kSuccess;
if (!print_dialog_)
- print_dialog_ = ui::LinuxUi::instance()->CreatePrintDialog(this);
+ print_dialog_ = ui::PrintingContextLinuxDelegate::instance()->CreatePrintDialog(this);
if (print_dialog_) {
// PrintDialogGtk::UpdateSettings() calls InitWithSettings() so settings_ will
diff --git ui/linux/linux_ui.cc ui/linux/linux_ui.cc
index 29db798e8b171..f8b9546b90321 100644
--- ui/linux/linux_ui.cc
+++ ui/linux/linux_ui.cc
@@ -18,11 +18,29 @@ namespace ui {
namespace {
LinuxUi* g_linux_ui = nullptr;
+static PrintingContextLinuxDelegate* g_delegate = nullptr;
} // namespace
+// static
+PrintingContextLinuxDelegate* PrintingContextLinuxDelegate::SetInstance(
+ PrintingContextLinuxDelegate* delegate) {
+ auto old_delegate = g_delegate;
+ g_delegate = delegate;
+ return old_delegate;
+}
+
+// static
+PrintingContextLinuxDelegate* PrintingContextLinuxDelegate::instance() {
+ return g_delegate;
+}
+
// static
LinuxUi* LinuxUi::SetInstance(LinuxUi* instance) {
+#if BUILDFLAG(IS_LINUX) && BUILDFLAG(ENABLE_PRINTING)
+ PrintingContextLinuxDelegate::SetInstance(instance);
+#endif
+
return std::exchange(g_linux_ui, instance);
}
diff --git ui/linux/linux_ui.h ui/linux/linux_ui.h
index 69f678a91012f..d518b476002b3 100644
--- ui/linux/linux_ui.h
+++ ui/linux/linux_ui.h
@@ -19,6 +19,10 @@
#include "printing/buildflags/buildflags.h"
#include "ui/gfx/geometry/rect.h"
+#if BUILDFLAG(ENABLE_PRINTING)
+#include "printing/printing_context_linux.h" // nogncheck
+#endif
+
// The main entrypoint into Linux toolkit specific code. GTK/QT code should only
// be executed behind this interface.
@@ -92,9 +96,27 @@ inline DisplayConfig::DisplayConfig(DisplayConfig&& other) = default;
inline DisplayConfig& DisplayConfig::operator=(DisplayConfig&& other) = default;
inline DisplayConfig::~DisplayConfig() = default;
+class COMPONENT_EXPORT(LINUX_UI) PrintingContextLinuxDelegate {
+ public:
+ virtual ~PrintingContextLinuxDelegate() = default;
+
+ virtual printing::PrintDialogLinuxInterface* CreatePrintDialog(
+ printing::PrintingContextLinux* context) = 0;
+
+ virtual gfx::Size GetPdfPaperSize(printing::PrintingContextLinux* context) = 0;
+
+ static PrintingContextLinuxDelegate* SetInstance(
+ PrintingContextLinuxDelegate* delegate);
+ static PrintingContextLinuxDelegate* instance();
+};
+
// Adapter class with targets to render like different toolkits. Set by any
// project that wants to do linux desktop native rendering.
-class COMPONENT_EXPORT(LINUX_UI) LinuxUi {
+class COMPONENT_EXPORT(LINUX_UI) LinuxUi
+#if BUILDFLAG(ENABLE_PRINTING)
+ : public PrintingContextLinuxDelegate
+#endif
+ {
public:
// Describes the window management actions that could be taken in response to
// a middle click in the non client area.
@@ -161,14 +183,6 @@ class COMPONENT_EXPORT(LINUX_UI) LinuxUi {
// Returns a map of KeyboardEvent code to KeyboardEvent key values.
virtual base::flat_map<std::string, std::string> GetKeyboardLayoutMap() = 0;
-#if BUILDFLAG(ENABLE_PRINTING)
- virtual printing::PrintDialogLinuxInterface* CreatePrintDialog(
- printing::PrintingContextLinux* context) = 0;
-
- virtual gfx::Size GetPdfPaperSize(
- printing::PrintingContextLinux* context) = 0;
-#endif
-
// Returns a native file selection dialog. `listener` is of type
// SelectFileDialog::Listener. TODO(thomasanderson): Move
// SelectFileDialog::Listener to SelectFileDialogListener so that it can be