2014-07-10 17:41:30 +02:00
|
|
|
// Copyright (c) 2014 The Chromium Embedded Framework Authors. All rights
|
|
|
|
// reserved. Use of this source code is governed by a BSD-style license that
|
|
|
|
// can be found in the LICENSE file.
|
|
|
|
|
|
|
|
#include "libcef/browser/print_settings_impl.h"
|
|
|
|
|
|
|
|
#include "base/logging.h"
|
|
|
|
|
2020-06-09 19:48:00 +02:00
|
|
|
#include "printing/mojom/print.mojom.h"
|
|
|
|
|
2019-10-01 15:55:16 +02:00
|
|
|
CefPrintSettingsImpl::CefPrintSettingsImpl(
|
|
|
|
std::unique_ptr<printing::PrintSettings> settings,
|
|
|
|
bool read_only)
|
2021-05-14 18:58:55 +02:00
|
|
|
: CefValueBase<CefPrintSettings, printing::PrintSettings>(
|
|
|
|
settings.release(),
|
|
|
|
nullptr,
|
|
|
|
kOwnerWillDelete,
|
|
|
|
read_only,
|
|
|
|
nullptr) {}
|
2014-07-10 17:41:30 +02:00
|
|
|
|
|
|
|
bool CefPrintSettingsImpl::IsValid() {
|
|
|
|
return !detached();
|
|
|
|
}
|
|
|
|
|
|
|
|
bool CefPrintSettingsImpl::IsReadOnly() {
|
|
|
|
return read_only();
|
|
|
|
}
|
|
|
|
|
|
|
|
void CefPrintSettingsImpl::SetOrientation(bool landscape) {
|
|
|
|
CEF_VALUE_VERIFY_RETURN_VOID(true);
|
|
|
|
mutable_value()->SetOrientation(landscape);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool CefPrintSettingsImpl::IsLandscape() {
|
|
|
|
CEF_VALUE_VERIFY_RETURN(false, false);
|
|
|
|
return const_value().landscape();
|
|
|
|
}
|
|
|
|
|
|
|
|
void CefPrintSettingsImpl::SetPrinterPrintableArea(
|
|
|
|
const CefSize& physical_size_device_units,
|
|
|
|
const CefRect& printable_area_device_units,
|
|
|
|
bool landscape_needs_flip) {
|
|
|
|
CEF_VALUE_VERIFY_RETURN_VOID(true);
|
|
|
|
gfx::Size size(physical_size_device_units.width,
|
|
|
|
physical_size_device_units.height);
|
2017-05-17 11:29:28 +02:00
|
|
|
gfx::Rect rect(printable_area_device_units.x, printable_area_device_units.y,
|
2014-07-10 17:41:30 +02:00
|
|
|
printable_area_device_units.width,
|
|
|
|
printable_area_device_units.height);
|
|
|
|
mutable_value()->SetPrinterPrintableArea(size, rect, landscape_needs_flip);
|
|
|
|
}
|
|
|
|
|
|
|
|
void CefPrintSettingsImpl::SetDeviceName(const CefString& name) {
|
|
|
|
CEF_VALUE_VERIFY_RETURN_VOID(true);
|
|
|
|
mutable_value()->set_device_name(name.ToString16());
|
|
|
|
}
|
|
|
|
|
|
|
|
CefString CefPrintSettingsImpl::GetDeviceName() {
|
|
|
|
CEF_VALUE_VERIFY_RETURN(false, CefString());
|
|
|
|
return const_value().device_name();
|
|
|
|
}
|
|
|
|
|
|
|
|
void CefPrintSettingsImpl::SetDPI(int dpi) {
|
|
|
|
CEF_VALUE_VERIFY_RETURN_VOID(true);
|
|
|
|
mutable_value()->set_dpi(dpi);
|
|
|
|
}
|
|
|
|
|
|
|
|
int CefPrintSettingsImpl::GetDPI() {
|
|
|
|
CEF_VALUE_VERIFY_RETURN(false, 0);
|
|
|
|
return const_value().dpi();
|
|
|
|
}
|
|
|
|
|
|
|
|
void CefPrintSettingsImpl::SetPageRanges(const PageRangeList& ranges) {
|
|
|
|
CEF_VALUE_VERIFY_RETURN_VOID(true);
|
|
|
|
printing::PageRanges page_ranges;
|
|
|
|
PageRangeList::const_iterator it = ranges.begin();
|
2017-05-17 11:29:28 +02:00
|
|
|
for (; it != ranges.end(); ++it) {
|
2016-01-19 21:09:01 +01:00
|
|
|
const CefRange& cef_range = *it;
|
2014-07-10 17:41:30 +02:00
|
|
|
printing::PageRange range;
|
|
|
|
range.from = cef_range.from;
|
|
|
|
range.to = cef_range.to;
|
|
|
|
page_ranges.push_back(range);
|
|
|
|
}
|
|
|
|
mutable_value()->set_ranges(page_ranges);
|
|
|
|
}
|
|
|
|
|
|
|
|
size_t CefPrintSettingsImpl::GetPageRangesCount() {
|
|
|
|
CEF_VALUE_VERIFY_RETURN(false, 0);
|
|
|
|
return const_value().ranges().size();
|
|
|
|
}
|
|
|
|
|
|
|
|
void CefPrintSettingsImpl::GetPageRanges(PageRangeList& ranges) {
|
|
|
|
CEF_VALUE_VERIFY_RETURN_VOID(false);
|
2023-01-02 23:59:03 +01:00
|
|
|
if (!ranges.empty()) {
|
2014-07-10 17:41:30 +02:00
|
|
|
ranges.clear();
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2014-07-10 17:41:30 +02:00
|
|
|
const printing::PageRanges& page_ranges = const_value().ranges();
|
|
|
|
printing::PageRanges::const_iterator it = page_ranges.begin();
|
|
|
|
for (; it != page_ranges.end(); ++it) {
|
|
|
|
const printing::PageRange& range = *it;
|
2016-01-19 21:09:01 +01:00
|
|
|
ranges.push_back(CefRange(range.from, range.to));
|
2014-07-10 17:41:30 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void CefPrintSettingsImpl::SetSelectionOnly(bool selection_only) {
|
|
|
|
CEF_VALUE_VERIFY_RETURN_VOID(true);
|
|
|
|
mutable_value()->set_selection_only(selection_only);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool CefPrintSettingsImpl::IsSelectionOnly() {
|
|
|
|
CEF_VALUE_VERIFY_RETURN(false, false);
|
|
|
|
return const_value().selection_only();
|
|
|
|
}
|
|
|
|
|
|
|
|
void CefPrintSettingsImpl::SetCollate(bool collate) {
|
|
|
|
CEF_VALUE_VERIFY_RETURN_VOID(true);
|
|
|
|
mutable_value()->set_collate(collate);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool CefPrintSettingsImpl::WillCollate() {
|
|
|
|
CEF_VALUE_VERIFY_RETURN(false, false);
|
|
|
|
return const_value().collate();
|
|
|
|
}
|
|
|
|
|
|
|
|
void CefPrintSettingsImpl::SetColorModel(ColorModel model) {
|
|
|
|
CEF_VALUE_VERIFY_RETURN_VOID(true);
|
2020-08-29 00:39:23 +02:00
|
|
|
mutable_value()->set_color(static_cast<printing::mojom::ColorModel>(model));
|
2014-07-10 17:41:30 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
CefPrintSettings::ColorModel CefPrintSettingsImpl::GetColorModel() {
|
|
|
|
CEF_VALUE_VERIFY_RETURN(false, COLOR_MODEL_UNKNOWN);
|
|
|
|
return static_cast<ColorModel>(const_value().color());
|
|
|
|
}
|
|
|
|
|
|
|
|
void CefPrintSettingsImpl::SetCopies(int copies) {
|
|
|
|
CEF_VALUE_VERIFY_RETURN_VOID(true);
|
|
|
|
mutable_value()->set_copies(copies);
|
|
|
|
}
|
|
|
|
|
|
|
|
int CefPrintSettingsImpl::GetCopies() {
|
|
|
|
CEF_VALUE_VERIFY_RETURN(false, false);
|
|
|
|
return const_value().copies();
|
|
|
|
}
|
|
|
|
|
|
|
|
void CefPrintSettingsImpl::SetDuplexMode(DuplexMode mode) {
|
|
|
|
CEF_VALUE_VERIFY_RETURN_VOID(true);
|
2020-06-09 19:48:00 +02:00
|
|
|
mutable_value()->set_duplex_mode(
|
|
|
|
static_cast<printing::mojom::DuplexMode>(mode));
|
2014-07-10 17:41:30 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
CefPrintSettings::DuplexMode CefPrintSettingsImpl::GetDuplexMode() {
|
|
|
|
CEF_VALUE_VERIFY_RETURN(false, DUPLEX_MODE_UNKNOWN);
|
|
|
|
return static_cast<DuplexMode>(const_value().duplex_mode());
|
|
|
|
}
|
|
|
|
|
2019-10-01 15:55:16 +02:00
|
|
|
std::unique_ptr<printing::PrintSettings> CefPrintSettingsImpl::TakeOwnership() {
|
2021-05-14 18:58:55 +02:00
|
|
|
return base::WrapUnique(Detach(nullptr));
|
2019-10-01 15:55:16 +02:00
|
|
|
}
|
|
|
|
|
2014-07-10 17:41:30 +02:00
|
|
|
// CefPrintSettings implementation.
|
|
|
|
|
|
|
|
// static
|
|
|
|
CefRefPtr<CefPrintSettings> CefPrintSettings::Create() {
|
2019-10-01 15:55:16 +02:00
|
|
|
return new CefPrintSettingsImpl(std::make_unique<printing::PrintSettings>(),
|
|
|
|
false);
|
2014-07-10 17:41:30 +02:00
|
|
|
}
|