cef/libcef/browser/print_settings_impl.cc

166 lines
5.1 KiB
C++
Raw Normal View History

// 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"
#include "printing/mojom/print.mojom.h"
CefPrintSettingsImpl::CefPrintSettingsImpl(
std::unique_ptr<printing::PrintSettings> settings,
bool read_only)
: CefValueBase<CefPrintSettings, printing::PrintSettings>(settings.get(),
nullptr,
kOwnerNoDelete,
read_only,
nullptr),
settings_(std::move(settings)) {}
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);
gfx::Rect rect(printable_area_device_units.x, printable_area_device_units.y,
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();
for (; it != ranges.end(); ++it) {
Implement Views framework on Windows and Linux (issue #1749). - Add Views header files in a new include/views directory. - Add initial top-level window (CefWindow), control (CefBrowserView, CefLabelButton, CefMenuButton, CefPanel, CefScrollView, CefTextfield) and layout (CefBoxLayout, CefFlowLayout) support. See libcef/browser/views/view_impl.h comments for implementation details. - Add Views example usage in cefclient and cefsimple and Views unit tests in cef_unittests. Pass the `--use-views` command-line flag to cefclient, cefsimple and cef_unittests to run using the Views framework instead of platform APIs. For cefclient and cefsimple this will create the browser window and all related functionality using the Views framework. For cef_unittests this will run all tests (except OSR tests) in a Views-based browser window. Views- specific unit tests (`--gtest_filter=Views*`) will be run even if the the `--use-views` flag is not specified. - Pass the `--hide-frame` command-line flag to cefclient to demo a frameless Views-based browser window. - Pass the `--hide-controls` command-line flag to cefclient to demo a browser window without top controls. This also works in non-Views mode. - Pass the `--enable-high-dpi-support` command-line flag to cef_unittests on Windows to test high-DPI support on a display that supports it. - Add CefImage for reading/writing image file formats. - Add CefBrowser::DownloadImage() for downloading image URLs as a CefImage representation. This is primarily for loading favicons. - Add CefMenuModel::CreateMenuModel() and CefMenuModelDelegate for creating custom menus. This is primarily for use with CefMenuButton. - Add CefBrowser::TryCloseBrowser() helper for closing a browser. Also improve related documentation in cef_life_span_handler.h. - Rename cef_page_range_t to cef_range_t. It is now also used by CefTextfield. - Remove CefLifeSpanHandler::RunModal() which is never called. - Add draggable regions example to cefclient.
2016-01-19 21:09:01 +01:00
const CefRange& cef_range = *it;
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);
if (!ranges.empty())
ranges.clear();
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;
Implement Views framework on Windows and Linux (issue #1749). - Add Views header files in a new include/views directory. - Add initial top-level window (CefWindow), control (CefBrowserView, CefLabelButton, CefMenuButton, CefPanel, CefScrollView, CefTextfield) and layout (CefBoxLayout, CefFlowLayout) support. See libcef/browser/views/view_impl.h comments for implementation details. - Add Views example usage in cefclient and cefsimple and Views unit tests in cef_unittests. Pass the `--use-views` command-line flag to cefclient, cefsimple and cef_unittests to run using the Views framework instead of platform APIs. For cefclient and cefsimple this will create the browser window and all related functionality using the Views framework. For cef_unittests this will run all tests (except OSR tests) in a Views-based browser window. Views- specific unit tests (`--gtest_filter=Views*`) will be run even if the the `--use-views` flag is not specified. - Pass the `--hide-frame` command-line flag to cefclient to demo a frameless Views-based browser window. - Pass the `--hide-controls` command-line flag to cefclient to demo a browser window without top controls. This also works in non-Views mode. - Pass the `--enable-high-dpi-support` command-line flag to cef_unittests on Windows to test high-DPI support on a display that supports it. - Add CefImage for reading/writing image file formats. - Add CefBrowser::DownloadImage() for downloading image URLs as a CefImage representation. This is primarily for loading favicons. - Add CefMenuModel::CreateMenuModel() and CefMenuModelDelegate for creating custom menus. This is primarily for use with CefMenuButton. - Add CefBrowser::TryCloseBrowser() helper for closing a browser. Also improve related documentation in cef_life_span_handler.h. - Rename cef_page_range_t to cef_range_t. It is now also used by CefTextfield. - Remove CefLifeSpanHandler::RunModal() which is never called. - Add draggable regions example to cefclient.
2016-01-19 21:09:01 +01:00
ranges.push_back(CefRange(range.from, range.to));
}
}
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);
mutable_value()->set_color(static_cast<printing::mojom::ColorModel>(model));
}
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);
mutable_value()->set_duplex_mode(
static_cast<printing::mojom::DuplexMode>(mode));
}
CefPrintSettings::DuplexMode CefPrintSettingsImpl::GetDuplexMode() {
CEF_VALUE_VERIFY_RETURN(false, DUPLEX_MODE_UNKNOWN);
return static_cast<DuplexMode>(const_value().duplex_mode());
}
std::unique_ptr<printing::PrintSettings> CefPrintSettingsImpl::TakeOwnership() {
Detach(nullptr);
return std::move(settings_);
}
// CefPrintSettings implementation.
// static
CefRefPtr<CefPrintSettings> CefPrintSettings::Create() {
return new CefPrintSettingsImpl(std::make_unique<printing::PrintSettings>(),
false);
}