#ifndef PRINTING_PRINT_SETTINGS_H_
#define PRINTING_PRINT_SETTINGS_H_
#include <algorithm>
#include <optional>
#include <string>
#include <utility>
#include <vector>
#include "base/component_export.h"
#include "build/build_config.h"
#include "printing/buildflags/buildflags.h"
#include "printing/mojom/print.mojom.h"
#include "printing/page_range.h"
#include "printing/page_setup.h"
#include "printing/print_job_constants.h"
#include "ui/gfx/geometry/rect.h"
#include "ui/gfx/geometry/size.h"
#if BUILDFLAG(ENABLE_OOP_PRINTING_NO_OOP_BASIC_PRINT_DIALOG)
#include "base/values.h"
#endif
#if BUILDFLAG(IS_LINUX) || BUILDFLAG(IS_CHROMEOS)
#include <map>
#include "base/values.h"
#endif
#if BUILDFLAG(IS_CHROMEOS)
#include "chromeos/crosapi/mojom/local_printer.mojom.h"
#include "printing/printing_features.h"
#endif
namespace printing {
#if BUILDFLAG(ENABLE_OOP_PRINTING_NO_OOP_BASIC_PRINT_DIALOG)
#if BUILDFLAG(IS_MAC)
inline constexpr char kMacSystemPrintDialogDataDestinationType[] =
"destination_type";
inline constexpr char kMacSystemPrintDialogDataDestinationFormat[] =
"destination_format";
inline constexpr char kMacSystemPrintDialogDataDestinationLocation[] =
"destination_location";
inline constexpr char kMacSystemPrintDialogDataPageFormat[] = "page_format";
inline constexpr char kMacSystemPrintDialogDataPrintSettings[] =
"print_settings";
#endif
#if BUILDFLAG(IS_LINUX)
inline constexpr char kLinuxSystemPrintDialogDataPrinter[] = "printer_name";
inline constexpr char kLinuxSystemPrintDialogDataPrintSettings[] =
"print_settings";
inline constexpr char kLinuxSystemPrintDialogDataPageSetup[] = "page_setup";
#endif
#endif
COMPONENT_EXPORT(PRINTING_SETTINGS)
mojom::ColorModel ColorModeToColorModel(int color_mode);
COMPONENT_EXPORT(PRINTING_SETTINGS)
std::optional<bool> IsColorModelSelected(mojom::ColorModel color_model);
#if BUILDFLAG(USE_CUPS)
COMPONENT_EXPORT(PRINTING_SETTINGS)
void GetColorModelForModel(mojom::ColorModel color_model,
std::string* color_setting_name,
std::string* color_value);
#endif
#if BUILDFLAG(USE_CUPS_IPP)
COMPONENT_EXPORT(PRINTING_SETTINGS)
std::string GetIppColorModelForModel(mojom::ColorModel color_model);
#endif
class COMPONENT_EXPORT(PRINTING_SETTINGS) PrintSettings {
public:
struct RequestedMedia {
bool operator==(const RequestedMedia& other) const;
bool IsDefault() const {
return size_microns.IsEmpty() && vendor_id.empty();
}
gfx::Size size_microns;
std::string vendor_id;
};
#if BUILDFLAG(IS_LINUX) || BUILDFLAG(IS_CHROMEOS)
using AdvancedSettings = std::map<std::string, base::Value>;
#endif
PrintSettings();
PrintSettings(const PrintSettings&);
PrintSettings& operator=(const PrintSettings&);
~PrintSettings();
bool operator==(const PrintSettings& other) const;
void Clear();
void SetCustomMargins(const PageMargins& requested_margins_in_microns);
#if BUILDFLAG(IS_CHROMEOS)
void SetCustomMarginsForBackend(
const PageMargins& requested_margins_in_microns);
#endif
const PageMargins& requested_custom_margins_in_microns() const {
return requested_custom_margins_in_microns_;
}
void set_margin_type(mojom::MarginType margin_type) {
#if BUILDFLAG(IS_CHROMEOS)
if (base::FeatureList::IsEnabled(features::kApiPrintingMarginsAndScale)) {
CHECK_NE(margin_type,
printing::mojom::MarginType::kPrecomputedMarginsForBackend);
}
#endif
margin_type_ = margin_type;
}
mojom::MarginType margin_type() const { return margin_type_; }
void SetOrientation(bool landscape);
bool landscape() const { return landscape_; }
void set_requested_media(const RequestedMedia& media) {
requested_media_ = media;
}
const RequestedMedia& requested_media() const { return requested_media_; }
void SetPrinterPrintableArea(const gfx::Size& physical_size_device_units,
const gfx::Rect& printable_area_device_units,
bool landscape_needs_flip);
#if BUILDFLAG(IS_WIN)
void UpdatePrinterPrintableArea(const gfx::Rect& printable_area_um);
#endif
const PageSetup& page_setup_device_units() const {
return page_setup_device_units_;
}
void set_page_setup_device_units(const PageSetup& page_setup_device_units) {
page_setup_device_units_ = page_setup_device_units;
}
void set_device_name(const std::u16string& device_name) {
device_name_ = device_name;
}
const std::u16string& device_name() const { return device_name_; }
void set_borderless(bool borderless) { borderless_ = borderless; }
bool borderless() const { return borderless_; }
void set_media_type(const std::string& media_type) {
media_type_ = media_type;
}
const std::string& media_type() const { return media_type_; }
void set_dpi(int dpi) { dpi_ = gfx::Size(dpi, dpi); }
void set_dpi_xy(int dpi_horizontal, int dpi_vertical) {
dpi_ = gfx::Size(dpi_horizontal, dpi_vertical);
}
int dpi() const { return std::max(dpi_.width(), dpi_.height()); }
int dpi_horizontal() const { return dpi_.width(); }
int dpi_vertical() const { return dpi_.height(); }
const gfx::Size& dpi_size() const { return dpi_; }
void set_scale_factor(double scale_factor) { scale_factor_ = scale_factor; }
double scale_factor() const { return scale_factor_; }
void set_rasterize_pdf(bool rasterize_pdf) { rasterize_pdf_ = rasterize_pdf; }
bool rasterize_pdf() const { return rasterize_pdf_; }
void set_rasterize_pdf_dpi(int32_t dpi) { rasterize_pdf_dpi_ = dpi; }
int32_t rasterize_pdf_dpi() const { return rasterize_pdf_dpi_; }
int device_units_per_inch() const {
#if BUILDFLAG(IS_MAC)
return kMacDeviceUnitsPerInch;
#else
return dpi();
#endif
}
const gfx::Size& device_units_per_inch_size() const {
#if BUILDFLAG(IS_MAC)
static constexpr gfx::Size kSize{kMacDeviceUnitsPerInch,
kMacDeviceUnitsPerInch};
return kSize;
#else
return dpi_size();
#endif
}
void set_ranges(const PageRanges& ranges) { ranges_ = ranges; }
const PageRanges& ranges() const { return ranges_; }
void set_selection_only(bool selection_only) {
selection_only_ = selection_only;
}
bool selection_only() const { return selection_only_; }
void set_should_print_backgrounds(bool should_print_backgrounds) {
should_print_backgrounds_ = should_print_backgrounds;
}
bool should_print_backgrounds() const { return should_print_backgrounds_; }
void set_display_header_footer(bool display_header_footer) {
display_header_footer_ = display_header_footer;
}
bool display_header_footer() const { return display_header_footer_; }
void set_title(const std::u16string& title) { title_ = title; }
const std::u16string& title() const { return title_; }
void set_url(const std::u16string& url) { url_ = url; }
const std::u16string& url() const { return url_; }
void set_collate(bool collate) { collate_ = collate; }
bool collate() const { return collate_; }
void set_color(mojom::ColorModel color) { color_ = color; }
mojom::ColorModel color() const { return color_; }
void set_copies(int copies) { copies_ = copies; }
int copies() const { return copies_; }
void set_duplex_mode(mojom::DuplexMode duplex_mode) {
duplex_mode_ = duplex_mode;
}
mojom::DuplexMode duplex_mode() const { return duplex_mode_; }
#if BUILDFLAG(IS_WIN)
void set_printer_language_type(mojom::PrinterLanguageType type) {
printer_language_type_ = type;
}
mojom::PrinterLanguageType printer_language_type() const {
return printer_language_type_;
}
bool printer_language_is_textonly() const {
return printer_language_type_ == mojom::PrinterLanguageType::kTextOnly;
}
bool printer_language_is_xps() const {
return printer_language_type_ == mojom::PrinterLanguageType::kXps;
}
bool printer_language_is_ps2() const {
return printer_language_type_ ==
mojom::PrinterLanguageType::kPostscriptLevel2;
}
bool printer_language_is_ps3() const {
return printer_language_type_ ==
mojom::PrinterLanguageType::kPostscriptLevel3;
}
#endif
void set_is_modifiable(bool is_modifiable) { is_modifiable_ = is_modifiable; }
bool is_modifiable() const { return is_modifiable_; }
int pages_per_sheet() const { return pages_per_sheet_; }
void set_pages_per_sheet(int pages_per_sheet) {
pages_per_sheet_ = pages_per_sheet;
}
#if BUILDFLAG(IS_LINUX) || BUILDFLAG(IS_CHROMEOS)
AdvancedSettings& advanced_settings() { return advanced_settings_; }
const AdvancedSettings& advanced_settings() const {
return advanced_settings_;
}
#endif
#if BUILDFLAG(IS_CHROMEOS)
void set_send_user_info(bool send_user_info) {
send_user_info_ = send_user_info;
}
bool send_user_info() const { return send_user_info_; }
void set_username(const std::string& username) { username_ = username; }
const std::string& username() const { return username_; }
void set_oauth_token(const std::string& oauth_token) {
oauth_token_ = oauth_token;
}
const std::string& oauth_token() const { return oauth_token_; }
void set_pin_value(const std::string& pin_value) { pin_value_ = pin_value; }
const std::string& pin_value() const { return pin_value_; }
void set_client_infos(std::vector<mojom::IppClientInfo> client_infos) {
client_infos_ = std::move(client_infos);
}
const std::vector<mojom::IppClientInfo>& client_infos() const {
return client_infos_;
}
void set_printer_manually_selected(bool printer_manually_selected) {
printer_manually_selected_ = printer_manually_selected;
}
bool printer_manually_selected() const { return printer_manually_selected_; }
void set_printer_status_reason(
crosapi::mojom::StatusReason::Reason printer_status_reason) {
printer_status_reason_ = printer_status_reason;
}
std::optional<crosapi::mojom::StatusReason::Reason> printer_status_reason()
const {
return printer_status_reason_;
}
void set_print_scaling(mojom::PrintScalingType print_scaling) {
print_scaling_ = print_scaling;
}
mojom::PrintScalingType print_scaling() const { return print_scaling_; }
void set_quality(mojom::Quality quality) { quality_ = quality; }
mojom::Quality quality() const { return quality_; }
#endif
#if BUILDFLAG(ENABLE_OOP_PRINTING_NO_OOP_BASIC_PRINT_DIALOG)
void set_system_print_dialog_data(base::Value::Dict data) {
system_print_dialog_data_ = std::move(data);
}
const base::Value::Dict& system_print_dialog_data() const {
return system_print_dialog_data_;
}
#endif
static int NewCookie();
static int NewInvalidCookie();
private:
#if BUILDFLAG(IS_MAC)
static constexpr int kMacDeviceUnitsPerInch = 72;
#endif
PageRanges ranges_;
bool selection_only_;
mojom::MarginType margin_type_;
std::u16string title_;
std::u16string url_;
bool display_header_footer_;
bool should_print_backgrounds_;
bool collate_;
mojom::ColorModel color_;
int copies_;
mojom::DuplexMode duplex_mode_;
std::u16string device_name_;
#if BUILDFLAG(ENABLE_OOP_PRINTING_NO_OOP_BASIC_PRINT_DIALOG)
base::Value::Dict system_print_dialog_data_;
#endif
RequestedMedia requested_media_;
PageSetup page_setup_device_units_;
bool borderless_;
std::string media_type_;
gfx::Size dpi_;
double scale_factor_;
bool rasterize_pdf_;
int32_t rasterize_pdf_dpi_;
bool landscape_;
#if BUILDFLAG(IS_WIN)
mojom::PrinterLanguageType printer_language_type_;
#endif
bool is_modifiable_;
PageMargins requested_custom_margins_in_microns_;
int pages_per_sheet_;
#if BUILDFLAG(IS_LINUX) || BUILDFLAG(IS_CHROMEOS)
AdvancedSettings advanced_settings_;
#endif
#if BUILDFLAG(IS_CHROMEOS)
bool send_user_info_;
std::string username_;
std::string oauth_token_;
std::string pin_value_;
std::vector<mojom::IppClientInfo> client_infos_;
bool printer_manually_selected_ = false;
std::optional<crosapi::mojom::StatusReason::Reason> printer_status_reason_;
mojom::PrintScalingType print_scaling_ =
mojom::PrintScalingType::kUnknownPrintScalingType;
mojom::Quality quality_ = mojom::Quality::kUnknownQuality;
#endif
};
}
#endif