2022-07-21 19:26:10 +02:00
|
|
|
diff --git printing/printing_context_linux.cc printing/printing_context_linux.cc
|
2023-01-03 00:34:43 +01:00
|
|
|
index 5520e15c232c8..70742cba8056c 100644
|
2022-07-21 19:26:10 +02:00
|
|
|
--- printing/printing_context_linux.cc
|
|
|
|
+++ printing/printing_context_linux.cc
|
2022-07-25 19:49:32 +02:00
|
|
|
@@ -25,6 +25,12 @@
|
|
|
|
|
|
|
|
namespace printing {
|
2022-07-21 19:26:10 +02:00
|
|
|
|
2022-07-25 19:49:32 +02:00
|
|
|
+namespace {
|
|
|
|
+
|
|
|
|
+static PrintingContextLinuxDelegate* g_delegate = nullptr;
|
|
|
|
+
|
|
|
|
+} // namespace
|
|
|
|
+
|
2022-07-21 19:26:10 +02:00
|
|
|
// static
|
2022-07-25 19:49:32 +02:00
|
|
|
std::unique_ptr<PrintingContext> PrintingContext::CreateImpl(
|
|
|
|
Delegate* delegate,
|
|
|
|
@@ -47,6 +53,14 @@ PrintingContextLinux::~PrintingContextLinux() {
|
2023-01-03 00:34:43 +01:00
|
|
|
print_dialog_.ExtractAsDangling()->ReleaseDialog();
|
2022-07-25 19:49:32 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
+// static
|
2022-07-21 19:26:10 +02:00
|
|
|
+PrintingContextLinuxDelegate* PrintingContextLinuxDelegate::SetInstance(
|
2022-07-25 19:49:32 +02:00
|
|
|
+ PrintingContextLinuxDelegate* delegate) {
|
2022-07-21 19:26:10 +02:00
|
|
|
+ auto old_delegate = g_delegate;
|
2022-07-25 19:49:32 +02:00
|
|
|
+ g_delegate = delegate;
|
2022-07-21 19:26:10 +02:00
|
|
|
+ return old_delegate;
|
2022-07-25 19:49:32 +02:00
|
|
|
+}
|
|
|
|
+
|
|
|
|
void PrintingContextLinux::AskUserForSettings(int max_pages,
|
|
|
|
bool has_selection,
|
|
|
|
bool is_scripted,
|
|
|
|
@@ -68,23 +82,19 @@ mojom::ResultCode PrintingContextLinux::UseDefaultSettings() {
|
|
|
|
|
|
|
|
ResetSettings();
|
|
|
|
|
|
|
|
-#if BUILDFLAG(IS_LINUX)
|
|
|
|
- if (!ui::LinuxUi::instance())
|
|
|
|
+ if (!g_delegate)
|
|
|
|
return mojom::ResultCode::kSuccess;
|
|
|
|
|
|
|
|
if (!print_dialog_)
|
|
|
|
- print_dialog_ = ui::LinuxUi::instance()->CreatePrintDialog(this);
|
|
|
|
+ print_dialog_ = g_delegate->CreatePrintDialog(this);
|
|
|
|
print_dialog_->UseDefaultSettings();
|
|
|
|
-#endif
|
|
|
|
|
|
|
|
return mojom::ResultCode::kSuccess;
|
2022-07-21 19:26:10 +02:00
|
|
|
}
|
|
|
|
|
2022-07-25 19:49:32 +02:00
|
|
|
gfx::Size PrintingContextLinux::GetPdfPaperSizeDeviceUnits() {
|
|
|
|
-#if BUILDFLAG(IS_LINUX)
|
|
|
|
- if (ui::LinuxUi::instance())
|
|
|
|
- return ui::LinuxUi::instance()->GetPdfPaperSize(this);
|
|
|
|
-#endif
|
|
|
|
+ if (g_delegate)
|
|
|
|
+ return g_delegate->GetPdfPaperSize(this);
|
|
|
|
|
|
|
|
return gfx::Size();
|
|
|
|
}
|
|
|
|
@@ -94,18 +104,16 @@ mojom::ResultCode PrintingContextLinux::UpdatePrinterSettings(
|
|
|
|
DCHECK(!printer_settings.show_system_dialog);
|
|
|
|
DCHECK(!in_print_job_);
|
|
|
|
|
|
|
|
-#if BUILDFLAG(IS_LINUX)
|
|
|
|
- if (!ui::LinuxUi::instance())
|
|
|
|
+ if (!g_delegate)
|
|
|
|
return mojom::ResultCode::kSuccess;
|
|
|
|
|
|
|
|
if (!print_dialog_)
|
|
|
|
- print_dialog_ = ui::LinuxUi::instance()->CreatePrintDialog(this);
|
|
|
|
+ print_dialog_ = g_delegate->CreatePrintDialog(this);
|
|
|
|
|
|
|
|
// PrintDialogGtk::UpdateSettings() calls InitWithSettings() so settings_ will
|
|
|
|
// remain non-null after this line.
|
|
|
|
print_dialog_->UpdateSettings(std::move(settings_));
|
|
|
|
DCHECK(settings_);
|
|
|
|
-#endif
|
|
|
|
|
|
|
|
return mojom::ResultCode::kSuccess;
|
|
|
|
}
|
2022-07-21 19:26:10 +02:00
|
|
|
diff --git printing/printing_context_linux.h printing/printing_context_linux.h
|
2023-01-03 00:34:43 +01:00
|
|
|
index 6fb35248ec459..3be9c29c7ebf9 100644
|
2022-07-21 19:26:10 +02:00
|
|
|
--- printing/printing_context_linux.h
|
|
|
|
+++ printing/printing_context_linux.h
|
2022-07-25 19:49:32 +02:00
|
|
|
@@ -16,6 +16,20 @@ namespace printing {
|
2022-07-21 19:26:10 +02:00
|
|
|
|
2022-07-25 19:49:32 +02:00
|
|
|
class MetafilePlayer;
|
|
|
|
class PrintDialogLinuxInterface;
|
|
|
|
+class PrintingContextLinux;
|
|
|
|
+
|
|
|
|
+class COMPONENT_EXPORT(PRINTING) PrintingContextLinuxDelegate {
|
|
|
|
+ public:
|
|
|
|
+ virtual ~PrintingContextLinuxDelegate() = default;
|
|
|
|
+
|
|
|
|
+ virtual PrintDialogLinuxInterface* CreatePrintDialog(
|
|
|
|
+ PrintingContextLinux* context) = 0;
|
|
|
|
+
|
|
|
|
+ virtual gfx::Size GetPdfPaperSize(PrintingContextLinux* context) = 0;
|
|
|
|
+
|
2022-07-21 19:26:10 +02:00
|
|
|
+ static PrintingContextLinuxDelegate* SetInstance(
|
|
|
|
+ PrintingContextLinuxDelegate* delegate);
|
2022-07-25 19:49:32 +02:00
|
|
|
+};
|
2022-07-21 19:26:10 +02:00
|
|
|
|
|
|
|
// PrintingContext with optional native UI for print dialog and pdf_paper_size.
|
2022-07-25 19:49:32 +02:00
|
|
|
class COMPONENT_EXPORT(PRINTING) PrintingContextLinux : public PrintingContext {
|
2022-08-08 19:13:18 +02:00
|
|
|
diff --git tools/v8_context_snapshot/BUILD.gn tools/v8_context_snapshot/BUILD.gn
|
2023-01-03 00:34:43 +01:00
|
|
|
index eed0eed705d7f..482037423bc01 100644
|
2022-08-08 19:13:18 +02:00
|
|
|
--- tools/v8_context_snapshot/BUILD.gn
|
|
|
|
+++ tools/v8_context_snapshot/BUILD.gn
|
2023-01-03 00:34:43 +01:00
|
|
|
@@ -105,6 +105,7 @@ if (use_v8_context_snapshot) {
|
2022-08-08 19:13:18 +02:00
|
|
|
deps = [
|
|
|
|
"//gin:gin",
|
|
|
|
"//mojo/core/embedder",
|
|
|
|
+ "//printing",
|
|
|
|
"//services/service_manager/public/cpp",
|
|
|
|
"//third_party/blink/public:blink",
|
|
|
|
"//v8",
|
2022-07-25 19:49:32 +02:00
|
|
|
diff --git ui/linux/linux_ui.cc ui/linux/linux_ui.cc
|
2022-11-15 18:50:53 +01:00
|
|
|
index 29db798e8b171..a541ef1bef264 100644
|
2022-07-25 19:49:32 +02:00
|
|
|
--- ui/linux/linux_ui.cc
|
|
|
|
+++ ui/linux/linux_ui.cc
|
2022-09-26 21:30:45 +02:00
|
|
|
@@ -23,6 +23,10 @@ LinuxUi* g_linux_ui = nullptr;
|
|
|
|
|
2022-08-23 03:37:40 +02:00
|
|
|
// static
|
2022-09-26 21:30:45 +02:00
|
|
|
LinuxUi* LinuxUi::SetInstance(LinuxUi* instance) {
|
2022-07-25 19:49:32 +02:00
|
|
|
+#if BUILDFLAG(IS_LINUX) && BUILDFLAG(ENABLE_PRINTING)
|
2022-09-26 21:30:45 +02:00
|
|
|
+ printing::PrintingContextLinuxDelegate::SetInstance(instance);
|
2022-07-25 19:49:32 +02:00
|
|
|
+#endif
|
2022-08-23 03:37:40 +02:00
|
|
|
+
|
2022-09-26 21:30:45 +02:00
|
|
|
return std::exchange(g_linux_ui, instance);
|
2022-07-25 19:49:32 +02:00
|
|
|
}
|
2022-08-23 03:37:40 +02:00
|
|
|
|
2022-07-25 19:49:32 +02:00
|
|
|
diff --git ui/linux/linux_ui.h ui/linux/linux_ui.h
|
2022-11-15 18:50:53 +01:00
|
|
|
index b5fd57741d2f4..9ebbd444ec3ac 100644
|
2022-07-25 19:49:32 +02:00
|
|
|
--- ui/linux/linux_ui.h
|
|
|
|
+++ ui/linux/linux_ui.h
|
2022-11-15 18:50:53 +01:00
|
|
|
@@ -18,6 +18,10 @@
|
2022-08-23 03:37:40 +02:00
|
|
|
#include "build/chromecast_buildflags.h"
|
|
|
|
#include "printing/buildflags/buildflags.h"
|
2022-07-25 19:49:32 +02:00
|
|
|
|
|
|
|
+#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.
|
|
|
|
|
2022-11-15 18:50:53 +01:00
|
|
|
@@ -62,7 +66,11 @@ class WindowFrameProvider;
|
2022-08-23 03:37:40 +02:00
|
|
|
|
2022-07-25 19:49:32 +02:00
|
|
|
// Adapter class with targets to render like different toolkits. Set by any
|
|
|
|
// project that wants to do linux desktop native rendering.
|
2022-08-23 03:37:40 +02:00
|
|
|
-class COMPONENT_EXPORT(LINUX_UI) LinuxUi {
|
|
|
|
+class COMPONENT_EXPORT(LINUX_UI) LinuxUi
|
2022-07-25 19:49:32 +02:00
|
|
|
+#if BUILDFLAG(ENABLE_PRINTING)
|
2022-08-23 03:37:40 +02:00
|
|
|
+ : public printing::PrintingContextLinuxDelegate
|
2022-07-25 19:49:32 +02:00
|
|
|
+#endif
|
2022-08-23 03:37:40 +02:00
|
|
|
+ {
|
2022-07-25 19:49:32 +02:00
|
|
|
public:
|
2022-11-15 18:50:53 +01:00
|
|
|
// Describes the window management actions that could be taken in response to
|
|
|
|
// a middle click in the non client area.
|
|
|
|
@@ -129,14 +137,6 @@ class COMPONENT_EXPORT(LINUX_UI) LinuxUi {
|
2022-07-25 19:49:32 +02:00
|
|
|
// 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
|