2014-07-10 17:41:30 +02:00
|
|
|
// Copyright (c) 2014 The Chromium Embedded Framework Authors.
|
|
|
|
// Portions copyright (c) 2012 The Chromium Authors. All rights reserved.
|
|
|
|
// Use of this source code is governed by a BSD-style license that can be
|
|
|
|
// found in the LICENSE file.
|
|
|
|
|
|
|
|
#ifndef LIBCEF_BROWSER_PRINTING_PRINT_DIALOG_LINUX_H_
|
|
|
|
#define LIBCEF_BROWSER_PRINTING_PRINT_DIALOG_LINUX_H_
|
|
|
|
|
|
|
|
#include "include/cef_print_handler.h"
|
2020-09-18 00:24:08 +02:00
|
|
|
#include "libcef/browser/browser_host_base.h"
|
2014-07-10 17:41:30 +02:00
|
|
|
|
|
|
|
#include "base/files/file_path.h"
|
|
|
|
#include "base/memory/ref_counted.h"
|
2021-11-10 22:57:31 +01:00
|
|
|
#include "base/task/sequenced_task_runner_helpers.h"
|
2014-07-10 17:41:30 +02:00
|
|
|
#include "content/public/browser/browser_thread.h"
|
|
|
|
#include "printing/print_dialog_gtk_interface.h"
|
|
|
|
#include "printing/printing_context_linux.h"
|
|
|
|
|
|
|
|
namespace printing {
|
2014-09-27 01:48:19 +02:00
|
|
|
class MetafilePlayer;
|
2014-07-10 17:41:30 +02:00
|
|
|
class PrintSettings;
|
2018-01-02 22:51:02 +01:00
|
|
|
} // namespace printing
|
2014-07-10 17:41:30 +02:00
|
|
|
|
|
|
|
using printing::PrintingContextLinux;
|
|
|
|
|
|
|
|
// Needs to be freed on the UI thread to clean up its member variables.
|
2017-05-17 11:29:28 +02:00
|
|
|
class CefPrintDialogLinux : public printing::PrintDialogGtkInterface,
|
|
|
|
public base::RefCountedThreadSafe<
|
|
|
|
CefPrintDialogLinux,
|
|
|
|
content::BrowserThread::DeleteOnUIThread> {
|
2014-07-10 17:41:30 +02:00
|
|
|
public:
|
2021-12-06 21:40:25 +01:00
|
|
|
CefPrintDialogLinux(const CefPrintDialogLinux&) = delete;
|
|
|
|
CefPrintDialogLinux& operator=(const CefPrintDialogLinux&) = delete;
|
|
|
|
|
2014-07-10 17:41:30 +02:00
|
|
|
// Creates and returns a print dialog.
|
|
|
|
static printing::PrintDialogGtkInterface* CreatePrintDialog(
|
|
|
|
PrintingContextLinux* context);
|
|
|
|
|
2015-03-24 16:40:08 +01:00
|
|
|
// Returns the paper size in device units.
|
2017-05-17 11:29:28 +02:00
|
|
|
static gfx::Size GetPdfPaperSize(printing::PrintingContextLinux* context);
|
2015-03-24 16:40:08 +01:00
|
|
|
|
2022-04-15 21:55:23 +02:00
|
|
|
// Used for calling into the default GTK implementation.
|
|
|
|
static void SetDefaultPrintingContextFuncs(
|
|
|
|
printing::PrintingContextLinux::CreatePrintDialogFunctionPtr
|
|
|
|
create_print_dialog_func,
|
|
|
|
printing::PrintingContextLinux::PdfPaperSizeFunctionPtr
|
|
|
|
pdf_paper_size_func);
|
|
|
|
|
2015-10-12 22:45:14 +02:00
|
|
|
// Notify the client when printing has started.
|
2020-10-08 21:54:42 +02:00
|
|
|
static void OnPrintStart(CefRefPtr<CefBrowserHostBase> browser);
|
2015-10-12 22:45:14 +02:00
|
|
|
|
2018-03-20 21:15:08 +01:00
|
|
|
// PrintDialogGtkInterface implementation.
|
2014-11-12 20:25:15 +01:00
|
|
|
void UseDefaultSettings() override;
|
2019-10-01 15:55:16 +02:00
|
|
|
void UpdateSettings(
|
|
|
|
std::unique_ptr<printing::PrintSettings> settings) override;
|
2014-11-12 20:25:15 +01:00
|
|
|
void ShowDialog(
|
2014-07-10 17:41:30 +02:00
|
|
|
gfx::NativeView parent_view,
|
|
|
|
bool has_selection,
|
2018-03-20 21:15:08 +01:00
|
|
|
PrintingContextLinux::PrintSettingsCallback callback) override;
|
2014-11-12 20:25:15 +01:00
|
|
|
void PrintDocument(const printing::MetafilePlayer& metafile,
|
2021-04-21 00:52:34 +02:00
|
|
|
const std::u16string& document_name) override;
|
2014-11-12 20:25:15 +01:00
|
|
|
void ReleaseDialog() override;
|
2014-07-10 17:41:30 +02:00
|
|
|
|
|
|
|
private:
|
2014-11-12 20:25:15 +01:00
|
|
|
friend class base::DeleteHelper<CefPrintDialogLinux>;
|
|
|
|
friend class base::RefCountedThreadSafe<
|
2017-05-17 11:29:28 +02:00
|
|
|
CefPrintDialogLinux,
|
|
|
|
content::BrowserThread::DeleteOnUIThread>;
|
2014-07-10 17:41:30 +02:00
|
|
|
friend struct content::BrowserThread::DeleteOnThread<
|
|
|
|
content::BrowserThread::UI>;
|
|
|
|
friend class CefPrintDialogCallbackImpl;
|
|
|
|
friend class CefPrintJobCallbackImpl;
|
|
|
|
|
2022-04-15 21:55:23 +02:00
|
|
|
CefPrintDialogLinux(PrintingContextLinux* context,
|
|
|
|
CefRefPtr<CefBrowserHostBase> browser,
|
|
|
|
CefRefPtr<CefPrintHandler> handler);
|
2014-11-12 20:25:15 +01:00
|
|
|
~CefPrintDialogLinux() override;
|
2014-07-10 17:41:30 +02:00
|
|
|
|
2019-10-01 15:55:16 +02:00
|
|
|
bool UpdateSettings(std::unique_ptr<printing::PrintSettings> settings,
|
|
|
|
bool get_defaults);
|
2014-07-10 17:41:30 +02:00
|
|
|
|
|
|
|
// Prints document named |document_name|.
|
2021-04-21 00:52:34 +02:00
|
|
|
void SendDocumentToPrinter(const std::u16string& document_name);
|
2014-07-10 17:41:30 +02:00
|
|
|
|
|
|
|
// Handles print dialog response.
|
|
|
|
void OnPrintContinue(CefRefPtr<CefPrintSettings> settings);
|
|
|
|
void OnPrintCancel();
|
|
|
|
|
|
|
|
// Handles print job response.
|
|
|
|
void OnJobCompleted();
|
|
|
|
|
|
|
|
// Printing dialog callback.
|
|
|
|
PrintingContextLinux::PrintSettingsCallback callback_;
|
2022-04-15 21:55:23 +02:00
|
|
|
|
2014-07-10 17:41:30 +02:00
|
|
|
PrintingContextLinux* context_;
|
2020-09-18 00:24:08 +02:00
|
|
|
CefRefPtr<CefBrowserHostBase> browser_;
|
2022-04-15 21:55:23 +02:00
|
|
|
CefRefPtr<CefPrintHandler> handler_;
|
2014-07-10 17:41:30 +02:00
|
|
|
|
|
|
|
base::FilePath path_to_pdf_;
|
|
|
|
};
|
|
|
|
|
|
|
|
#endif // LIBCEF_BROWSER_PRINTING_PRINT_DIALOG_LINUX_H_
|