From da51f56cc21233c2d30f0fe0d171727c3102b2e0 Mon Sep 17 00:00:00 2001 From: Allan Sandfeld Jensen Date: Wed, 31 Jan 2018 16:33:43 +0100 Subject: BASELINE: Update Chromium to 65.0.3525.40 Also imports missing submodules Change-Id: I36901b7c6a325cda3d2c10cedb2186c25af3b79b Reviewed-by: Alexandru Croitor --- chromium/printing/BUILD.gn | 32 +++-- chromium/printing/backend/print_backend.cc | 10 +- .../printing/backend/print_backend_chromeos.cc | 4 +- chromium/printing/backend/test_print_backend.cc | 4 +- chromium/printing/common/pdf_metafile_utils.cc | 3 +- chromium/printing/image.cc | 9 +- chromium/printing/image.h | 3 +- chromium/printing/image_android.cc | 1 + chromium/printing/image_fuchsia.cc | 14 ++ chromium/printing/image_linux.cc | 1 + chromium/printing/metafile.cc | 12 +- chromium/printing/page_setup.cc | 2 +- chromium/printing/pdf_metafile_skia.cc | 23 ++-- chromium/printing/pdf_metafile_skia.h | 3 +- chromium/printing/print_job_constants.cc | 6 - chromium/printing/print_job_constants.h | 2 - chromium/printing/print_settings.cc | 6 +- chromium/printing/print_settings.h | 18 ++- chromium/printing/printed_document.cc | 145 +++++++++++++++------ chromium/printing/printed_document.h | 72 ++++++---- chromium/printing/printed_document_chromeos.cc | 33 ++--- chromium/printing/printed_document_linux.cc | 23 +--- chromium/printing/printed_document_mac.cc | 57 ++++---- chromium/printing/printed_document_unittest.cc | 59 +++++++++ chromium/printing/printed_document_win.cc | 6 +- chromium/printing/printed_page.cc | 45 ------- chromium/printing/printed_page.h | 76 ----------- chromium/printing/printed_page_unittest.cc | 68 ---------- chromium/printing/printed_page_win.cc | 26 ++++ chromium/printing/printed_page_win.h | 68 ++++++++++ chromium/printing/printed_page_win_unittest.cc | 21 +++ chromium/printing/printing_context.cc | 3 +- chromium/printing/printing_context_win.cc | 11 +- chromium/printing/pwg_raster_settings.h | 2 + 34 files changed, 457 insertions(+), 411 deletions(-) create mode 100644 chromium/printing/image_fuchsia.cc create mode 100644 chromium/printing/printed_document_unittest.cc delete mode 100644 chromium/printing/printed_page.cc delete mode 100644 chromium/printing/printed_page.h delete mode 100644 chromium/printing/printed_page_unittest.cc create mode 100644 chromium/printing/printed_page_win.cc create mode 100644 chromium/printing/printed_page_win.h create mode 100644 chromium/printing/printed_page_win_unittest.cc (limited to 'chromium/printing') diff --git a/chromium/printing/BUILD.gn b/chromium/printing/BUILD.gn index 5ee1cb33ac8..086afa4b368 100644 --- a/chromium/printing/BUILD.gn +++ b/chromium/printing/BUILD.gn @@ -33,12 +33,6 @@ component("printing") { "backend/printing_info_win.h", "emf_win.cc", "emf_win.h", - "image.cc", - "image.h", - "image_android.cc", - "image_linux.cc", - "image_mac.cc", - "image_win.cc", "metafile.cc", "metafile.h", "metafile_skia_wrapper.cc", @@ -71,8 +65,6 @@ component("printing") { "printed_document.h", "printed_document_mac.cc", "printed_document_win.cc", - "printed_page.cc", - "printed_page.h", "printing_context.cc", "printing_context.h", "printing_export.h", @@ -132,6 +124,8 @@ component("printing") { "backend/print_backend_win.cc", "backend/win_helper.cc", "backend/win_helper.h", + "printed_page_win.cc", + "printed_page_win.h", "printing_context_system_dialog_win.cc", "printing_context_system_dialog_win.h", "printing_context_win.cc", @@ -249,12 +243,25 @@ static_library("test_support") { sources = [ "backend/test_print_backend.cc", "backend/test_print_backend.h", + "image.cc", + "image.h", + "image_android.cc", + "image_linux.cc", + "image_mac.cc", + "image_win.cc", ] + if (is_fuchsia) { + sources += [ "image_fuchsia.cc" ] + } + public_deps = [ "//printing", + "//ui/gfx/geometry", ] deps = [ "//base", + "//skia", + "//ui/gfx", ] } @@ -265,7 +272,6 @@ test("printing_unittests") { "page_range_unittest.cc", "page_setup_unittest.cc", "pdf_metafile_cg_mac_unittest.cc", - "printed_page_unittest.cc", "printing_context_win_unittest.cc", "printing_test.h", "printing_utils_unittest.cc", @@ -287,6 +293,14 @@ test("printing_unittests") { sources += [ "pdf_transform_unittest.cc" ] } + if (is_win || is_mac) { + sources += [ "printed_document_unittest.cc" ] + } + + if (is_win) { + sources += [ "printed_page_win_unittest.cc" ] + } + if (use_cups) { configs += [ ":cups" ] diff --git a/chromium/printing/backend/print_backend.cc b/chromium/printing/backend/print_backend.cc index 3a03950347d..b19fb76305f 100644 --- a/chromium/printing/backend/print_backend.cc +++ b/chromium/printing/backend/print_backend.cc @@ -19,7 +19,7 @@ PrinterBasicInfo::PrinterBasicInfo() PrinterBasicInfo::PrinterBasicInfo(const PrinterBasicInfo& other) = default; -PrinterBasicInfo::~PrinterBasicInfo() {} +PrinterBasicInfo::~PrinterBasicInfo() = default; PrinterSemanticCapsAndDefaults::PrinterSemanticCapsAndDefaults() : collate_capable(false), @@ -36,16 +36,16 @@ PrinterSemanticCapsAndDefaults::PrinterSemanticCapsAndDefaults() PrinterSemanticCapsAndDefaults::PrinterSemanticCapsAndDefaults( const PrinterSemanticCapsAndDefaults& other) = default; -PrinterSemanticCapsAndDefaults::~PrinterSemanticCapsAndDefaults() {} +PrinterSemanticCapsAndDefaults::~PrinterSemanticCapsAndDefaults() = default; -PrinterCapsAndDefaults::PrinterCapsAndDefaults() {} +PrinterCapsAndDefaults::PrinterCapsAndDefaults() = default; PrinterCapsAndDefaults::PrinterCapsAndDefaults( const PrinterCapsAndDefaults& other) = default; -PrinterCapsAndDefaults::~PrinterCapsAndDefaults() {} +PrinterCapsAndDefaults::~PrinterCapsAndDefaults() = default; -PrintBackend::~PrintBackend() {} +PrintBackend::~PrintBackend() = default; // static scoped_refptr PrintBackend::CreateInstance( diff --git a/chromium/printing/backend/print_backend_chromeos.cc b/chromium/printing/backend/print_backend_chromeos.cc index 96e44573817..882e6a84feb 100644 --- a/chromium/printing/backend/print_backend_chromeos.cc +++ b/chromium/printing/backend/print_backend_chromeos.cc @@ -60,10 +60,10 @@ class PrintBackendChromeOS : public PrintBackend { bool IsValidPrinter(const std::string& printer_name) override; protected: - ~PrintBackendChromeOS() override {} + ~PrintBackendChromeOS() override = default; }; -PrintBackendChromeOS::PrintBackendChromeOS() {} +PrintBackendChromeOS::PrintBackendChromeOS() = default; bool PrintBackendChromeOS::EnumeratePrinters(PrinterList* printer_list) { return true; diff --git a/chromium/printing/backend/test_print_backend.cc b/chromium/printing/backend/test_print_backend.cc index 5e7eaf940e4..3c4d2172b01 100644 --- a/chromium/printing/backend/test_print_backend.cc +++ b/chromium/printing/backend/test_print_backend.cc @@ -12,9 +12,9 @@ namespace printing { -TestPrintBackend::TestPrintBackend() {} +TestPrintBackend::TestPrintBackend() = default; -TestPrintBackend::~TestPrintBackend() {} +TestPrintBackend::~TestPrintBackend() = default; bool TestPrintBackend::EnumeratePrinters(PrinterList* printer_list) { if (printer_list_.empty()) diff --git a/chromium/printing/common/pdf_metafile_utils.cc b/chromium/printing/common/pdf_metafile_utils.cc index 3a30ad0018d..0f77f7bbb87 100644 --- a/chromium/printing/common/pdf_metafile_utils.cc +++ b/chromium/printing/common/pdf_metafile_utils.cc @@ -39,8 +39,7 @@ sk_sp MakePdfDocument(const std::string& creator, metadata.fCreator = creator.empty() ? SkString("Chromium") : SkString(creator.c_str(), creator.size()); - return SkDocument::MakePDF(stream, SK_ScalarDefaultRasterDPI, metadata, - nullptr, false); + return SkDocument::MakePDF(stream, metadata); } } // namespace printing diff --git a/chromium/printing/image.cc b/chromium/printing/image.cc index 37c4ceda851..194a410ceb1 100644 --- a/chromium/printing/image.cc +++ b/chromium/printing/image.cc @@ -24,14 +24,9 @@ Image::Image(const Metafile& metafile) LoadMetafile(metafile); } -Image::Image(const Image& image) - : size_(image.size_), - row_length_(image.row_length_), - data_(image.data_), - ignore_alpha_(image.ignore_alpha_) { -} +Image::Image(const Image& image) = default; -Image::~Image() {} +Image::~Image() = default; std::string Image::checksum() const { base::MD5Digest digest; diff --git a/chromium/printing/image.h b/chromium/printing/image.h index 0245185f87b..13ac4d537bc 100644 --- a/chromium/printing/image.h +++ b/chromium/printing/image.h @@ -12,7 +12,6 @@ #include #include "base/logging.h" -#include "printing/printing_export.h" #include "ui/gfx/geometry/size.h" namespace base { @@ -25,7 +24,7 @@ class Metafile; // Lightweight raw-bitmap management. The image, once initialized, is immutable. // The main purpose is testing image contents. -class PRINTING_EXPORT Image { +class Image { public: // Creates the image from the metafile. Deduces bounds based on bounds in // metafile. If loading fails size().IsEmpty() will be true. diff --git a/chromium/printing/image_android.cc b/chromium/printing/image_android.cc index 544cf070d93..2ae4c3a797d 100644 --- a/chromium/printing/image_android.cc +++ b/chromium/printing/image_android.cc @@ -7,6 +7,7 @@ namespace printing { bool Image::LoadMetafile(const Metafile& metafile) { + NOTIMPLEMENTED(); return false; } diff --git a/chromium/printing/image_fuchsia.cc b/chromium/printing/image_fuchsia.cc new file mode 100644 index 00000000000..5389ca27f3b --- /dev/null +++ b/chromium/printing/image_fuchsia.cc @@ -0,0 +1,14 @@ +// Copyright 2017 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. + +#include "printing/image.h" + +namespace printing { + +bool Image::LoadMetafile(const Metafile& metafile) { + NOTIMPLEMENTED(); + return false; +} + +} // namespace printing diff --git a/chromium/printing/image_linux.cc b/chromium/printing/image_linux.cc index d89c4e9d808..6ccb213942d 100644 --- a/chromium/printing/image_linux.cc +++ b/chromium/printing/image_linux.cc @@ -7,6 +7,7 @@ namespace printing { bool Image::LoadMetafile(const Metafile& metafile) { + NOTIMPLEMENTED(); return false; } diff --git a/chromium/printing/metafile.cc b/chromium/printing/metafile.cc index fd2c829041b..7ecbea7c82f 100644 --- a/chromium/printing/metafile.cc +++ b/chromium/printing/metafile.cc @@ -13,17 +13,13 @@ namespace printing { -MetafilePlayer::MetafilePlayer() { -} +MetafilePlayer::MetafilePlayer() = default; -MetafilePlayer::~MetafilePlayer() { -} +MetafilePlayer::~MetafilePlayer() = default; -Metafile::Metafile() { -} +Metafile::Metafile() = default; -Metafile::~Metafile() { -} +Metafile::~Metafile() = default; bool Metafile::GetDataAsVector(std::vector* buffer) const { buffer->resize(GetDataSize()); diff --git a/chromium/printing/page_setup.cc b/chromium/printing/page_setup.cc index 69442b00ff3..fb342d538f6 100644 --- a/chromium/printing/page_setup.cc +++ b/chromium/printing/page_setup.cc @@ -43,7 +43,7 @@ PageSetup::PageSetup() { PageSetup::PageSetup(const PageSetup& other) = default; -PageSetup::~PageSetup() {} +PageSetup::~PageSetup() = default; void PageSetup::Clear() { physical_size_.SetSize(0, 0); diff --git a/chromium/printing/pdf_metafile_skia.cc b/chromium/printing/pdf_metafile_skia.cc index d5b59a7d315..2a73cfb2efa 100644 --- a/chromium/printing/pdf_metafile_skia.cc +++ b/chromium/printing/pdf_metafile_skia.cc @@ -10,7 +10,6 @@ #include #include "base/files/file.h" -#include "base/memory/ptr_util.h" #include "base/time/time.h" #include "cc/paint/paint_record.h" #include "cc/paint/paint_recorder.h" @@ -39,15 +38,14 @@ bool WriteAssetToBuffer(const SkStreamAsset* asset, // Calling duplicate() keeps original asset state unchanged. std::unique_ptr assetCopy(asset->duplicate()); size_t length = assetCopy->getLength(); - if (length > size) - return false; - return (length == assetCopy->read(buffer, length)); + return length <= size && length == assetCopy->read(buffer, length); } } // namespace namespace printing { +// TODO(thestig): struct members should not have trailing underscore. struct Page { Page(SkSize s, sk_sp c) : size_(s), content_(std::move(c)) {} Page(Page&& that) : size_(that.size_), content_(std::move(that.content_)) {} @@ -80,7 +78,12 @@ struct PdfMetafileSkiaData { #endif }; -PdfMetafileSkia::~PdfMetafileSkia() {} +PdfMetafileSkia::PdfMetafileSkia(SkiaDocumentType type) + : data_(std::make_unique()) { + data_->type_ = type; +} + +PdfMetafileSkia::~PdfMetafileSkia() = default; bool PdfMetafileSkia::Init() { return true; @@ -91,7 +94,7 @@ bool PdfMetafileSkia::Init() { // PdfMetafileSkia does. bool PdfMetafileSkia::InitFromData(const void* src_buffer, size_t src_buffer_size) { - data_->pdf_data_ = base::MakeUnique( + data_->pdf_data_ = std::make_unique( src_buffer, src_buffer_size, true /* copy_data? */); return true; } @@ -274,17 +277,11 @@ bool PdfMetafileSkia::SaveTo(base::File* file) const { return true; } -PdfMetafileSkia::PdfMetafileSkia(SkiaDocumentType type) - : data_(new PdfMetafileSkiaData) { - data_->type_ = type; -} - std::unique_ptr PdfMetafileSkia::GetMetafileForCurrentPage( SkiaDocumentType type) { // If we only ever need the metafile for the last page, should we // only keep a handle on one PaintRecord? - std::unique_ptr metafile(new PdfMetafileSkia(type)); - + auto metafile = std::make_unique(type); if (data_->pages_.size() == 0) return metafile; diff --git a/chromium/printing/pdf_metafile_skia.h b/chromium/printing/pdf_metafile_skia.h index e5898c807c4..a8539739cc8 100644 --- a/chromium/printing/pdf_metafile_skia.h +++ b/chromium/printing/pdf_metafile_skia.h @@ -24,7 +24,8 @@ namespace printing { struct PdfMetafileSkiaData; -// This class uses Skia graphics library to generate a PDF document. +// This class uses Skia graphics library to generate a PDF or MSKP document. +// TODO(thestig): Rename to MetafileSkia. class PRINTING_EXPORT PdfMetafileSkia : public Metafile { public: explicit PdfMetafileSkia(SkiaDocumentType type); diff --git a/chromium/printing/print_job_constants.cc b/chromium/printing/print_job_constants.cc index c0b4935e865..8f03d3a8b2a 100644 --- a/chromium/printing/print_job_constants.cc +++ b/chromium/printing/print_job_constants.cc @@ -14,12 +14,6 @@ const char kIsFirstRequest[] = "isFirstRequest"; // Unique ID sent along every preview request. const char kPreviewRequestID[] = "requestID"; -// Unique ID of Print Preview initiator host. -const char kPreviewInitiatorHostId[] = "previewInitiatorHostId"; - -// Routing ID of Print Preview initiator. -const char kPreviewInitiatorRoutingId[] = "previewInitiatorRoutingId"; - // Unique ID to identify a print preview UI. const char kPreviewUIID[] = "previewUIID"; diff --git a/chromium/printing/print_job_constants.h b/chromium/printing/print_job_constants.h index 331494fc8c3..888c6afefd0 100644 --- a/chromium/printing/print_job_constants.h +++ b/chromium/printing/print_job_constants.h @@ -13,8 +13,6 @@ namespace printing { PRINTING_EXPORT extern const char kIsFirstRequest[]; PRINTING_EXPORT extern const char kPreviewRequestID[]; -PRINTING_EXPORT extern const char kPreviewInitiatorHostId[]; -PRINTING_EXPORT extern const char kPreviewInitiatorRoutingId[]; PRINTING_EXPORT extern const char kPreviewUIID[]; PRINTING_EXPORT extern const char kSettingCapabilities[]; PRINTING_EXPORT extern const char kSettingCloudPrintId[]; diff --git a/chromium/printing/print_settings.cc b/chromium/printing/print_settings.cc index f7935649e6c..b95ba271197 100644 --- a/chromium/printing/print_settings.cc +++ b/chromium/printing/print_settings.cc @@ -154,8 +154,7 @@ PrintSettings::PrintSettings() { PrintSettings::PrintSettings(const PrintSettings& other) = default; -PrintSettings::~PrintSettings() { -} +PrintSettings::~PrintSettings() = default; void PrintSettings::Clear() { ranges_.clear(); @@ -172,8 +171,7 @@ void PrintSettings::Clear() { device_name_.clear(); requested_media_ = RequestedMedia(); page_setup_device_units_.Clear(); - dpi_[0] = 0; - dpi_[1] = 0; + dpi_ = gfx::Size(); scale_factor_ = 1.0f; rasterize_pdf_ = false; landscape_ = false; diff --git a/chromium/printing/print_settings.h b/chromium/printing/print_settings.h index 68f793b7ad1..354b5377d77 100644 --- a/chromium/printing/print_settings.h +++ b/chromium/printing/print_settings.h @@ -14,6 +14,7 @@ #include "printing/print_job_constants.h" #include "printing/printing_export.h" #include "ui/gfx/geometry/rect.h" +#include "ui/gfx/geometry/size.h" namespace printing { @@ -101,17 +102,14 @@ class PRINTING_EXPORT PrintSettings { } const base::string16& device_name() const { return device_name_; } - void set_dpi(int dpi) { - dpi_[0] = dpi; - dpi_[1] = dpi; - } + void set_dpi(int dpi) { dpi_ = gfx::Size(dpi, dpi); } void set_dpi_xy(int dpi_horizontal, int dpi_vertical) { - dpi_[0] = dpi_horizontal; - dpi_[1] = dpi_vertical; + dpi_ = gfx::Size(dpi_horizontal, dpi_vertical); } - int dpi() const { return std::max(dpi_[0], dpi_[1]); } - int dpi_horizontal() const { return dpi_[0]; } - int dpi_vertical() const { return dpi_[1]; } + + int dpi() const { return std::max(dpi_.width(), dpi_.height()); } + int dpi_horizontal() const { return dpi_.width(); } + int dpi_vertical() const { return dpi_.height(); } void set_scale_factor(double scale_factor) { scale_factor_ = scale_factor; } double scale_factor() const { return scale_factor_; } @@ -238,7 +236,7 @@ class PRINTING_EXPORT PrintSettings { // Printer's device effective dots per inch in both axes. The two values will // generally be identical. However, on Windows, there are a few rare printers // that support resolutions with different DPI in different dimensions. - int dpi_[2]; + gfx::Size dpi_; // Scale factor double scale_factor_; diff --git a/chromium/printing/printed_document.cc b/chromium/printing/printed_document.cc index f541f3dfe62..05987fcf959 100644 --- a/chromium/printing/printed_document.cc +++ b/chromium/printing/printed_document.cc @@ -27,13 +27,17 @@ #include "base/threading/thread_restrictions.h" #include "base/time/time.h" #include "base/values.h" +#include "printing/metafile.h" #include "printing/page_number.h" #include "printing/print_settings_conversion.h" -#include "printing/printed_page.h" #include "printing/units.h" #include "ui/gfx/font.h" #include "ui/gfx/text_elider.h" +#if defined(OS_WIN) +#include "printing/printed_page_win.h" +#endif + namespace printing { namespace { @@ -41,19 +45,15 @@ namespace { base::LazyInstance::Leaky g_debug_dump_info = LAZY_INSTANCE_INITIALIZER; +#if defined(OS_WIN) void DebugDumpPageTask(const base::string16& doc_name, const PrintedPage* page) { base::AssertBlockingAllowed(); - if (g_debug_dump_info.Get().empty()) - return; + DCHECK(PrintedDocument::HasDebugDumpPath()); static constexpr base::FilePath::CharType kExtension[] = -#if defined(OS_WIN) FILE_PATH_LITERAL(".emf"); -#else - FILE_PATH_LITERAL(".pdf"); -#endif base::string16 name = doc_name; name += base::ASCIIToUTF16(base::StringPrintf("_%04d", page->page_number())); @@ -62,6 +62,23 @@ void DebugDumpPageTask(const base::string16& doc_name, base::File::FLAG_CREATE_ALWAYS | base::File::FLAG_WRITE); page->metafile()->SaveTo(&file); } +#else +void DebugDumpTask(const base::string16& doc_name, + const MetafilePlayer* metafile) { + base::AssertBlockingAllowed(); + + DCHECK(PrintedDocument::HasDebugDumpPath()); + + static constexpr base::FilePath::CharType kExtension[] = + FILE_PATH_LITERAL(".pdf"); + + base::string16 name = doc_name; + base::FilePath path = PrintedDocument::CreateDebugDumpPath(name, kExtension); + base::File file(path, + base::File::FLAG_CREATE_ALWAYS | base::File::FLAG_WRITE); + metafile->SaveTo(&file); +} +#endif void DebugDumpDataTask(const base::string16& doc_name, const base::FilePath::StringType& extension, @@ -107,37 +124,29 @@ PrintedDocument::PrintedDocument(const PrintSettings& settings, } } - if (!g_debug_dump_info.Get().empty()) + if (HasDebugDumpPath()) DebugDumpSettings(name, settings); } -PrintedDocument::~PrintedDocument() { -} +PrintedDocument::~PrintedDocument() = default; +#if defined(OS_WIN) void PrintedDocument::SetPage(int page_number, std::unique_ptr metafile, -#if defined(OS_WIN) float shrink, -#endif - const gfx::Size& paper_size, - const gfx::Rect& page_rect) { + const gfx::Size& page_size, + const gfx::Rect& page_content_rect) { // Notice the page_number + 1, the reason is that this is the value that will // be shown. Users dislike 0-based counting. auto page = base::MakeRefCounted( - page_number + 1, std::move(metafile), paper_size, page_rect); -#if defined(OS_WIN) + page_number + 1, std::move(metafile), page_size, page_content_rect); page->set_shrink_factor(shrink); -#endif { base::AutoLock lock(lock_); mutable_.pages_[page_number] = page; - -#if defined(OS_POSIX) - mutable_.first_page = std::min(mutable_.first_page, page_number); -#endif } - if (!g_debug_dump_info.Get().empty()) { + if (HasDebugDumpPath()) { base::PostTaskWithTraits( FROM_HERE, {base::TaskPriority::BACKGROUND, base::MayBlock()}, base::BindOnce(&DebugDumpPageTask, name(), base::RetainedRef(page))); @@ -155,27 +164,52 @@ scoped_refptr PrintedDocument::GetPage(int page_number) { return page; } +#else +void PrintedDocument::SetDocument(std::unique_ptr metafile, + const gfx::Size& page_size, + const gfx::Rect& page_content_rect) { + { + base::AutoLock lock(lock_); + mutable_.metafile_ = std::move(metafile); +#if defined(OS_MACOSX) + mutable_.page_size_ = page_size; + mutable_.page_content_rect_ = page_content_rect; +#endif + } + + if (HasDebugDumpPath()) { + base::PostTaskWithTraits( + FROM_HERE, {base::TaskPriority::BACKGROUND, base::MayBlock()}, + base::BindOnce(&DebugDumpTask, name(), mutable_.metafile_.get())); + } +} + +const MetafilePlayer* PrintedDocument::GetMetafile() { + return mutable_.metafile_.get(); +} + +#endif + bool PrintedDocument::IsComplete() const { base::AutoLock lock(lock_); if (!mutable_.page_count_) return false; +#if defined(OS_WIN) PageNumber page(immutable_.settings_, mutable_.page_count_); if (page == PageNumber::npos()) return false; for (; page != PageNumber::npos(); ++page) { -#if defined(OS_WIN) - const bool metafile_must_be_valid = true; -#elif defined(OS_POSIX) - const bool metafile_must_be_valid = (page.ToInt() == mutable_.first_page); -#endif PrintedPages::const_iterator it = mutable_.pages_.find(page.ToInt()); - if (it == mutable_.pages_.end() || !it->second.get()) - return false; - if (metafile_must_be_valid && !it->second->metafile()) + if (it == mutable_.pages_.end() || !it->second.get() || + !it->second->metafile()) { return false; + } } return true; +#else + return !!mutable_.metafile_; +#endif } void PrintedDocument::set_page_count(int max_page) { @@ -201,16 +235,23 @@ int PrintedDocument::expected_page_count() const { return mutable_.expected_page_count_; } -void PrintedDocument::set_debug_dump_path( - const base::FilePath& debug_dump_path) { +// static +void PrintedDocument::SetDebugDumpPath(const base::FilePath& debug_dump_path) { + DCHECK(!debug_dump_path.empty()); g_debug_dump_info.Get() = debug_dump_path; } +// static +bool PrintedDocument::HasDebugDumpPath() { + return g_debug_dump_info.IsCreated(); +} + +// static base::FilePath PrintedDocument::CreateDebugDumpPath( const base::string16& document_name, const base::FilePath::StringType& extension) { - if (g_debug_dump_info.Get().empty()) - return base::FilePath(); + DCHECK(HasDebugDumpPath()); + // Create a filename. base::string16 filename; base::Time now(base::Time::Now()); @@ -224,37 +265,55 @@ base::FilePath PrintedDocument::CreateDebugDumpPath( system_filename = base::UTF16ToUTF8(filename); #endif // OS_WIN base::i18n::ReplaceIllegalCharactersInPath(&system_filename, '_'); - return g_debug_dump_info.Get().Append(system_filename).AddExtension( - extension); + const auto& dump_path = g_debug_dump_info.Get(); + DCHECK(!dump_path.empty()); + return dump_path.Append(system_filename).AddExtension(extension); } void PrintedDocument::DebugDumpData( const base::RefCountedMemory* data, const base::FilePath::StringType& extension) { - if (g_debug_dump_info.Get().empty()) - return; + DCHECK(HasDebugDumpPath()); base::PostTaskWithTraits(FROM_HERE, {base::TaskPriority::BACKGROUND, base::MayBlock()}, base::BindOnce(&DebugDumpDataTask, name(), extension, base::RetainedRef(data))); } -PrintedDocument::Mutable::Mutable() {} +#if defined(OS_WIN) || defined(OS_MACOSX) +gfx::Rect PrintedDocument::GetCenteredPageContentRect( + const gfx::Size& paper_size, + const gfx::Size& page_size, + const gfx::Rect& page_content_rect) const { + gfx::Rect content_rect = page_content_rect; + if (paper_size.width() > page_size.width()) { + int diff = paper_size.width() - page_size.width(); + content_rect.set_x(content_rect.x() + diff / 2); + } + if (paper_size.height() > page_size.height()) { + int diff = paper_size.height() - page_size.height(); + content_rect.set_y(content_rect.y() + diff / 2); + } + return content_rect; +} +#endif + +PrintedDocument::Mutable::Mutable() = default; -PrintedDocument::Mutable::~Mutable() {} +PrintedDocument::Mutable::~Mutable() = default; PrintedDocument::Immutable::Immutable(const PrintSettings& settings, const base::string16& name, int cookie) : settings_(settings), name_(name), cookie_(cookie) {} -PrintedDocument::Immutable::~Immutable() {} +PrintedDocument::Immutable::~Immutable() = default; #if defined(OS_ANDROID) // This function is not used on android. -void PrintedDocument::RenderPrintedPage(const PrintedPage& page, - PrintingContext* context) const { +bool PrintedDocument::RenderPrintedDocument(PrintingContext* context) { NOTREACHED(); + return false; } #endif diff --git a/chromium/printing/printed_document.h b/chromium/printing/printed_document.h index 3ccfb06482d..9a52abb6d28 100644 --- a/chromium/printing/printed_document.h +++ b/chromium/printing/printed_document.h @@ -42,29 +42,38 @@ class PRINTING_EXPORT PrintedDocument const base::string16& name, int cookie); - // Sets a page's data. 0-based. Takes metafile ownership. - // Note: locks for a short amount of time. +#if defined(OS_WIN) + // Sets a page's data. 0-based. Note: locks for a short amount of time. void SetPage(int page_number, std::unique_ptr metafile, -#if defined(OS_WIN) float shrink, -#endif - const gfx::Size& paper_size, - const gfx::Rect& page_rect); + const gfx::Size& page_size, + const gfx::Rect& page_content_rect); // Retrieves a page. If the page is not available right now, it // requests to have this page be rendered and returns NULL. // Note: locks for a short amount of time. scoped_refptr GetPage(int page_number); +#else + // Sets the document data. Note: locks for a short amount of time. + void SetDocument(std::unique_ptr metafile, + const gfx::Size& page_size, + const gfx::Rect& page_content_rect); + + // Retrieves the metafile with the data to print. Lock must be held when + // calling this function + const MetafilePlayer* GetMetafile(); +#endif - // Draws the page in the context. - // Note: locks for a short amount of time in debug only. -#if defined(OS_WIN) || (defined(OS_MACOSX) && !defined(USE_AURA)) +// Draws the page in the context. +// Note: locks for a short amount of time in debug only. +#if defined(OS_WIN) void RenderPrintedPage(const PrintedPage& page, printing::NativeDrawingContext context) const; #elif defined(OS_POSIX) - void RenderPrintedPage(const PrintedPage& page, - PrintingContext* context) const; + // Draws the document in the context. Returns true on success and false on + // failure. Fails if context->NewPage() or context->PageDone() fails. + bool RenderPrintedDocument(PrintingContext* context); #endif // Returns true if all the necessary pages for the settings are already @@ -92,21 +101,33 @@ class PRINTING_EXPORT PrintedDocument const base::string16& name() const { return immutable_.name_; } int cookie() const { return immutable_.cookie_; } - // Sets a path where to dump printing output files for debugging. If never set - // no files are generated. - static void set_debug_dump_path(const base::FilePath& debug_dump_path); + // Sets a path where to dump printing output files for debugging. If never + // set, no files are generated. |debug_dump_path| must not be empty. + static void SetDebugDumpPath(const base::FilePath& debug_dump_path); + + // Returns true if SetDebugDumpPath() has been called. + static bool HasDebugDumpPath(); // Creates debug file name from given |document_name| and |extension|. - // |extension| should include '.', example ".pdf" - // Returns empty |base::FilePath| if debug dumps is not enabled. + // |extension| should include the leading dot. e.g. ".pdf" + // Should only be called when debug dumps are enabled. static base::FilePath CreateDebugDumpPath( const base::string16& document_name, const base::FilePath::StringType& extension); - // Dump data on blocking task runner if debug dumps enabled. + // Dump data on blocking task runner. + // Should only be called when debug dumps are enabled. void DebugDumpData(const base::RefCountedMemory* data, const base::FilePath::StringType& extension); +#if defined(OS_WIN) || defined(OS_MACOSX) + // Get page content rect adjusted based on + // http://dev.w3.org/csswg/css3-page/#positioning-page-box + gfx::Rect GetCenteredPageContentRect(const gfx::Size& paper_size, + const gfx::Size& page_size, + const gfx::Rect& content_rect) const; +#endif + private: friend class base::RefCountedThreadSafe; @@ -121,10 +142,6 @@ class PRINTING_EXPORT PrintedDocument Mutable(); ~Mutable(); - // Contains the pages' representation. This is a collection of PrintedPage. - // Warning: Lock must be held when accessing this member. - PrintedPages pages_; - // Number of expected pages to be rendered. // Warning: Lock must be held when accessing this member. int expected_page_count_ = 0; @@ -132,9 +149,16 @@ class PRINTING_EXPORT PrintedDocument // The total number of pages in the document. int page_count_ = 0; -#if defined(OS_POSIX) - // Page number of the first page. - int first_page = INT_MAX; +#if defined(OS_WIN) + // Contains the pages' representation. This is a collection of PrintedPage. + // Warning: Lock must be held when accessing this member. + PrintedPages pages_; +#else + std::unique_ptr metafile_; +#endif +#if defined(OS_MACOSX) + gfx::Size page_size_; + gfx::Rect page_content_rect_; #endif }; diff --git a/chromium/printing/printed_document_chromeos.cc b/chromium/printing/printed_document_chromeos.cc index aac115fb766..224acd8926c 100644 --- a/chromium/printing/printed_document_chromeos.cc +++ b/chromium/printing/printed_document_chromeos.cc @@ -5,42 +5,35 @@ #include "printing/printed_document.h" #include "base/logging.h" -#include "printing/page_number.h" -#include "printing/printed_page.h" #if defined(USE_CUPS) +#include "printing/metafile.h" #include "printing/printing_context_chromeos.h" #endif namespace printing { -void PrintedDocument::RenderPrintedPage(const PrintedPage& page, - PrintingContext* context) const { +bool PrintedDocument::RenderPrintedDocument(PrintingContext* context) { #if defined(USE_CUPS) -#if defined(NDEBUG) - { - // Make sure the page is from our list. - base::AutoLock lock(lock_); - DCHECK(&page == mutable_.pages_.find(page.page_number() - 1)->second.get()); - } -#endif // defined(NDEBUG) - DCHECK(context); + if (context->NewPage() != PrintingContext::OK) + return false; { base::AutoLock lock(lock_); - if (page.page_number() - 1 == mutable_.first_page) { - std::vector buffer; - - if (page.metafile()->GetDataAsVector(&buffer)) { - static_cast(context)->StreamData(buffer); - } else { - LOG(WARNING) << "Failed to read data from metafile"; - } + std::vector buffer; + const MetafilePlayer* metafile = GetMetafile(); + DCHECK(metafile); + if (metafile->GetDataAsVector(&buffer)) { + static_cast(context)->StreamData(buffer); + } else { + LOG(WARNING) << "Failed to read data from metafile"; } } + return context->PageDone() == PrintingContext::OK; #else NOTREACHED(); + return false; #endif // defined(USE_CUPS) } diff --git a/chromium/printing/printed_document_linux.cc b/chromium/printing/printed_document_linux.cc index 2beec84b95d..87bc30e7d0f 100644 --- a/chromium/printing/printed_document_linux.cc +++ b/chromium/printing/printed_document_linux.cc @@ -6,8 +6,6 @@ #include "base/logging.h" #include "build/build_config.h" -#include "printing/page_number.h" -#include "printing/printed_page.h" #include "printing/printing_context_linux.h" #if defined(OS_ANDROID) || defined(OS_CHROMEOS) @@ -16,25 +14,18 @@ namespace printing { -void PrintedDocument::RenderPrintedPage( - const PrintedPage& page, PrintingContext* context) const { -#ifndef NDEBUG - { - // Make sure the page is from our list. - base::AutoLock lock(lock_); - DCHECK(&page == mutable_.pages_.find(page.page_number() - 1)->second.get()); - } -#endif - +bool PrintedDocument::RenderPrintedDocument(PrintingContext* context) { DCHECK(context); + if (context->NewPage() != PrintingContext::OK) + return false; { base::AutoLock lock(lock_); - if (page.page_number() - 1 == mutable_.first_page) { - static_cast(context) - ->PrintDocument(*page.metafile()); - } + const MetafilePlayer* metafile = GetMetafile(); + DCHECK(metafile); + static_cast(context)->PrintDocument(*metafile); } + return context->PageDone() == PrintingContext::OK; } } // namespace printing diff --git a/chromium/printing/printed_document_mac.cc b/chromium/printing/printed_document_mac.cc index 3224d12f873..1cfa1eebfc1 100644 --- a/chromium/printing/printed_document_mac.cc +++ b/chromium/printing/printed_document_mac.cc @@ -8,55 +8,42 @@ #import #include "base/logging.h" -#include "printing/page_number.h" -#include "printing/printed_page.h" +#include "printing/metafile.h" +#include "printing/printing_context.h" namespace printing { -void PrintedDocument::RenderPrintedPage( - const PrintedPage& page, - printing::NativeDrawingContext context) const { +bool PrintedDocument::RenderPrintedDocument(PrintingContext* context) { DCHECK(context); - // |mutable_.pages_| is 0-based, whereas the page number is 1-based. - const int page_index = page.page_number() - 1; - const MetafilePlayer* metafile; - size_t metafile_page_number; + gfx::Size page_size; + gfx::Rect page_content_rect; { base::AutoLock lock(lock_); - - // Make sure |page| is from our list. - DCHECK(&page == mutable_.pages_.find(page_index)->second.get()); - - // Make sure the first page exists in the list too. - DCHECK_GE(mutable_.first_page, 0); - DCHECK_NE(mutable_.first_page, INT_MAX); - DCHECK(mutable_.pages_.find(mutable_.first_page)->second.get()); - - // Always use the metafile from the first page. - metafile = mutable_.pages_.find(mutable_.first_page)->second->metafile(); - - // Figure out the mapping from |page| to the page inside |metafile|. - // e.g. If |metafile| contains 3 pages that corresponds to pages 1, 5, 7, - // then page 5 has index 1, which is page number 2. - // Use 1-based page number here because that is what RenderPage() takes. - metafile_page_number = 1; - for (const auto& it : mutable_.pages_) { - if (it.first == page_index) - break; - ++metafile_page_number; - } + metafile = GetMetafile(); + page_size = mutable_.page_size_; + page_content_rect = mutable_.page_content_rect_; } + DCHECK(metafile); const PageSetup& page_setup = immutable_.settings_.page_setup_device_units(); - gfx::Rect content_area = - page.GetCenteredPageContentRect(page_setup.physical_size()); + gfx::Rect content_area = GetCenteredPageContentRect( + page_setup.physical_size(), page_size, page_content_rect); struct Metafile::MacRenderPageParams params; params.autorotate = true; - metafile->RenderPage(metafile_page_number, context, content_area.ToCGRect(), - params); + size_t num_pages = expected_page_count(); + for (size_t metafile_page_number = 1; metafile_page_number <= num_pages; + metafile_page_number++) { + if (context->NewPage() != PrintingContext::OK) + return false; + metafile->RenderPage(metafile_page_number, context->context(), + content_area.ToCGRect(), params); + if (context->PageDone() != PrintingContext::OK) + return false; + } + return true; } } // namespace printing diff --git a/chromium/printing/printed_document_unittest.cc b/chromium/printing/printed_document_unittest.cc new file mode 100644 index 00000000000..efb2aa8e440 --- /dev/null +++ b/chromium/printing/printed_document_unittest.cc @@ -0,0 +1,59 @@ +// Copyright 2017 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. + +#include "printing/printed_document.h" +#include "base/strings/utf_string_conversions.h" +#include "testing/gtest/include/gtest/gtest.h" + +namespace printing { + +TEST(PrintedDocumentTest, GetCenteredPageContentRect) { + scoped_refptr document; + PrintSettings settings; + gfx::Rect page_content; + const base::string16 name(base::ASCIIToUTF16("name")); + + // No centering. + document = base::MakeRefCounted(settings, name, 1); + gfx::Size page_size = gfx::Size(1200, 1200); + gfx::Rect page_content_rect = gfx::Rect(0, 0, 400, 1100); + page_content = document->GetCenteredPageContentRect( + gfx::Size(1000, 1000), page_size, page_content_rect); + EXPECT_EQ(0, page_content.x()); + EXPECT_EQ(0, page_content.y()); + EXPECT_EQ(400, page_content.width()); + EXPECT_EQ(1100, page_content.height()); + + // X centered. + document = base::MakeRefCounted(settings, name, 1); + page_size = gfx::Size(500, 1200); + page_content = document->GetCenteredPageContentRect( + gfx::Size(1000, 1000), page_size, page_content_rect); + EXPECT_EQ(250, page_content.x()); + EXPECT_EQ(0, page_content.y()); + EXPECT_EQ(400, page_content.width()); + EXPECT_EQ(1100, page_content.height()); + + // Y centered. + document = base::MakeRefCounted(settings, name, 1); + page_size = gfx::Size(1200, 500); + page_content = document->GetCenteredPageContentRect( + gfx::Size(1000, 1000), page_size, page_content_rect); + EXPECT_EQ(0, page_content.x()); + EXPECT_EQ(250, page_content.y()); + EXPECT_EQ(400, page_content.width()); + EXPECT_EQ(1100, page_content.height()); + + // Both X and Y centered. + document = base::MakeRefCounted(settings, name, 1); + page_size = gfx::Size(500, 500), + page_content = document->GetCenteredPageContentRect( + gfx::Size(1000, 1000), page_size, page_content_rect); + EXPECT_EQ(250, page_content.x()); + EXPECT_EQ(250, page_content.y()); + EXPECT_EQ(400, page_content.width()); + EXPECT_EQ(1100, page_content.height()); +} + +} // namespace printing diff --git a/chromium/printing/printed_document_win.cc b/chromium/printing/printed_document_win.cc index 3913a38067d..19bfb4554d8 100644 --- a/chromium/printing/printed_document_win.cc +++ b/chromium/printing/printed_document_win.cc @@ -6,7 +6,7 @@ #include "base/logging.h" #include "printing/page_number.h" -#include "printing/printed_page.h" +#include "printing/printed_page_win.h" #include "printing/units.h" #include "skia/ext/skia_utils_win.h" @@ -42,8 +42,8 @@ void PrintedDocument::RenderPrintedPage( DCHECK(context); const PageSetup& page_setup = immutable_.settings_.page_setup_device_units(); - gfx::Rect content_area = - page.GetCenteredPageContentRect(page_setup.physical_size()); + gfx::Rect content_area = GetCenteredPageContentRect( + page_setup.physical_size(), page.page_size(), page.page_content_rect()); // Save the state to make sure the context this function call does not modify // the device context. diff --git a/chromium/printing/printed_page.cc b/chromium/printing/printed_page.cc deleted file mode 100644 index 5bc848750f1..00000000000 --- a/chromium/printing/printed_page.cc +++ /dev/null @@ -1,45 +0,0 @@ -// Copyright (c) 2011 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. - -#include "printing/printed_page.h" - -#include - -namespace printing { - -PrintedPage::PrintedPage(int page_number, - std::unique_ptr metafile, - const gfx::Size& page_size, - const gfx::Rect& page_content_rect) - : page_number_(page_number), - metafile_(std::move(metafile)), -#if defined(OS_WIN) - shrink_factor_(0.0f), -#endif // OS_WIN - page_size_(page_size), - page_content_rect_(page_content_rect) { -} - -PrintedPage::~PrintedPage() { -} - -const MetafilePlayer* PrintedPage::metafile() const { - return metafile_.get(); -} - -gfx::Rect PrintedPage::GetCenteredPageContentRect( - const gfx::Size& paper_size) const { - gfx::Rect content_rect = page_content_rect(); - if (paper_size.width() > page_size().width()) { - int diff = paper_size.width() - page_size().width(); - content_rect.set_x(content_rect.x() + diff / 2); - } - if (paper_size.height() > page_size().height()) { - int diff = paper_size.height() - page_size().height(); - content_rect.set_y(content_rect.y() + diff / 2); - } - return content_rect; -} - -} // namespace printing diff --git a/chromium/printing/printed_page.h b/chromium/printing/printed_page.h deleted file mode 100644 index 3aa67539f6d..00000000000 --- a/chromium/printing/printed_page.h +++ /dev/null @@ -1,76 +0,0 @@ -// Copyright (c) 2011 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 PRINTING_PRINTED_PAGE_H_ -#define PRINTING_PRINTED_PAGE_H_ - -#include - -#include "base/macros.h" -#include "base/memory/ref_counted.h" -#include "printing/metafile.h" -#include "ui/gfx/geometry/rect.h" -#include "ui/gfx/geometry/size.h" - -namespace printing { - -// Contains the data to reproduce a printed page, either on screen or on -// paper. Once created, this object is immutable. It has no reference to the -// PrintedDocument containing this page. -// Note: May be accessed from many threads at the same time. This is an non -// issue since this object is immutable. The reason is that a page may be -// printed and be displayed at the same time. -class PRINTING_EXPORT PrintedPage - : public base::RefCountedThreadSafe { - public: - PrintedPage(int page_number, - std::unique_ptr metafile, - const gfx::Size& page_size, - const gfx::Rect& page_content_rect); - - // Getters - int page_number() const { return page_number_; } - const MetafilePlayer* metafile() const; - const gfx::Size& page_size() const { return page_size_; } - const gfx::Rect& page_content_rect() const { return page_content_rect_; } -#if defined(OS_WIN) - void set_shrink_factor(float shrink_factor) { - shrink_factor_ = shrink_factor; - } - float shrink_factor() const { return shrink_factor_; } -#endif // OS_WIN - - // Get page content rect adjusted based on - // http://dev.w3.org/csswg/css3-page/#positioning-page-box - gfx::Rect GetCenteredPageContentRect(const gfx::Size& paper_size) const; - - private: - friend class base::RefCountedThreadSafe; - - ~PrintedPage(); - - // Page number inside the printed document. - const int page_number_; - - // Actual paint data. - const std::unique_ptr metafile_; - -#if defined(OS_WIN) - // Shrink done in comparison to desired_dpi. - float shrink_factor_; -#endif // OS_WIN - - // The physical page size. To support multiple page formats inside on print - // job. - const gfx::Size page_size_; - - // The printable area of the page. - const gfx::Rect page_content_rect_; - - DISALLOW_COPY_AND_ASSIGN(PrintedPage); -}; - -} // namespace printing - -#endif // PRINTING_PRINTED_PAGE_H_ diff --git a/chromium/printing/printed_page_unittest.cc b/chromium/printing/printed_page_unittest.cc deleted file mode 100644 index 62b7f00cef5..00000000000 --- a/chromium/printing/printed_page_unittest.cc +++ /dev/null @@ -1,68 +0,0 @@ -// Copyright (c) 2011 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. - -#include "printing/printed_page.h" -#include "testing/gtest/include/gtest/gtest.h" - -namespace printing { - -TEST(PrintedPageTest, GetCenteredPageContentRect) { - scoped_refptr page; - gfx::Rect page_content; - - // No centering. - page = base::MakeRefCounted(1, std::unique_ptr(), - gfx::Size(1200, 1200), - gfx::Rect(0, 0, 400, 1100)); - page_content = page->GetCenteredPageContentRect(gfx::Size(1000, 1000)); - EXPECT_EQ(0, page_content.x()); - EXPECT_EQ(0, page_content.y()); - EXPECT_EQ(400, page_content.width()); - EXPECT_EQ(1100, page_content.height()); - - // X centered. - page = base::MakeRefCounted(1, std::unique_ptr(), - gfx::Size(500, 1200), - gfx::Rect(0, 0, 400, 1100)); - page_content = page->GetCenteredPageContentRect(gfx::Size(1000, 1000)); - EXPECT_EQ(250, page_content.x()); - EXPECT_EQ(0, page_content.y()); - EXPECT_EQ(400, page_content.width()); - EXPECT_EQ(1100, page_content.height()); - - // Y centered. - page = base::MakeRefCounted(1, std::unique_ptr(), - gfx::Size(1200, 500), - gfx::Rect(0, 0, 400, 1100)); - page_content = page->GetCenteredPageContentRect(gfx::Size(1000, 1000)); - EXPECT_EQ(0, page_content.x()); - EXPECT_EQ(250, page_content.y()); - EXPECT_EQ(400, page_content.width()); - EXPECT_EQ(1100, page_content.height()); - - // Both X and Y centered. - page = base::MakeRefCounted(1, std::unique_ptr(), - gfx::Size(500, 500), - gfx::Rect(0, 0, 400, 1100)); - page_content = page->GetCenteredPageContentRect(gfx::Size(1000, 1000)); - EXPECT_EQ(250, page_content.x()); - EXPECT_EQ(250, page_content.y()); - EXPECT_EQ(400, page_content.width()); - EXPECT_EQ(1100, page_content.height()); -} - -#if defined(OS_WIN) -TEST(PrintedPageTest, Shrink) { - scoped_refptr page = base::MakeRefCounted( - 1, std::unique_ptr(), gfx::Size(1200, 1200), - gfx::Rect(0, 0, 400, 1100)); - EXPECT_EQ(0.0f, page->shrink_factor()); - page->set_shrink_factor(0.2f); - EXPECT_EQ(0.2f, page->shrink_factor()); - page->set_shrink_factor(0.7f); - EXPECT_EQ(0.7f, page->shrink_factor()); -} -#endif - -} // namespace printing diff --git a/chromium/printing/printed_page_win.cc b/chromium/printing/printed_page_win.cc new file mode 100644 index 00000000000..b9df411b722 --- /dev/null +++ b/chromium/printing/printed_page_win.cc @@ -0,0 +1,26 @@ +// Copyright (c) 2011 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. + +#include "printing/printed_page_win.h" + +#include + +namespace printing { + +PrintedPage::PrintedPage(int page_number, + std::unique_ptr metafile, + const gfx::Size& page_size, + const gfx::Rect& page_content_rect) + : page_number_(page_number), + metafile_(std::move(metafile)), + shrink_factor_(0.0f), + page_size_(page_size), + page_content_rect_(page_content_rect) {} + +PrintedPage::~PrintedPage() = default; + +const MetafilePlayer* PrintedPage::metafile() const { + return metafile_.get(); +} +} // namespace printing diff --git a/chromium/printing/printed_page_win.h b/chromium/printing/printed_page_win.h new file mode 100644 index 00000000000..6a69de2cc26 --- /dev/null +++ b/chromium/printing/printed_page_win.h @@ -0,0 +1,68 @@ +// Copyright (c) 2011 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 PRINTING_PRINTED_PAGE_WIN_H_ +#define PRINTING_PRINTED_PAGE_WIN_H_ + +#include + +#include "base/macros.h" +#include "base/memory/ref_counted.h" +#include "printing/metafile.h" +#include "ui/gfx/geometry/rect.h" +#include "ui/gfx/geometry/size.h" + +namespace printing { + +// Contains the data to reproduce a printed page, either on screen or on +// paper. Once created, this object is immutable. It has no reference to the +// PrintedDocument containing this page. +// Note: May be accessed from many threads at the same time. This is an non +// issue since this object is immutable. The reason is that a page may be +// printed and be displayed at the same time. +class PRINTING_EXPORT PrintedPage + : public base::RefCountedThreadSafe { + public: + PrintedPage(int page_number, + std::unique_ptr metafile, + const gfx::Size& page_size, + const gfx::Rect& page_content_rect); + + // Getters + int page_number() const { return page_number_; } + const MetafilePlayer* metafile() const; + const gfx::Size& page_size() const { return page_size_; } + const gfx::Rect& page_content_rect() const { return page_content_rect_; } + void set_shrink_factor(float shrink_factor) { + shrink_factor_ = shrink_factor; + } + float shrink_factor() const { return shrink_factor_; } + + private: + friend class base::RefCountedThreadSafe; + + ~PrintedPage(); + + // Page number inside the printed document. + const int page_number_; + + // Actual paint data. + const std::unique_ptr metafile_; + + // Shrink done in comparison to desired_dpi. + float shrink_factor_; + + // The physical page size. To support multiple page formats inside on print + // job. + const gfx::Size page_size_; + + // The printable area of the page. + const gfx::Rect page_content_rect_; + + DISALLOW_COPY_AND_ASSIGN(PrintedPage); +}; + +} // namespace printing + +#endif // PRINTING_PRINTED_PAGE_WIN_H_ diff --git a/chromium/printing/printed_page_win_unittest.cc b/chromium/printing/printed_page_win_unittest.cc new file mode 100644 index 00000000000..18b7e5a79f8 --- /dev/null +++ b/chromium/printing/printed_page_win_unittest.cc @@ -0,0 +1,21 @@ +// Copyright (c) 2011 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. + +#include "printing/printed_page_win.h" +#include "testing/gtest/include/gtest/gtest.h" + +namespace printing { + +TEST(PrintedPageTest, Shrink) { + scoped_refptr page = base::MakeRefCounted( + 1, std::unique_ptr(), gfx::Size(1200, 1200), + gfx::Rect(0, 0, 400, 1100)); + EXPECT_EQ(0.0f, page->shrink_factor()); + page->set_shrink_factor(0.2f); + EXPECT_EQ(0.2f, page->shrink_factor()); + page->set_shrink_factor(0.7f); + EXPECT_EQ(0.7f, page->shrink_factor()); +} + +} // namespace printing diff --git a/chromium/printing/printing_context.cc b/chromium/printing/printing_context.cc index 26b7df3ebeb..9cdde9fd3a6 100644 --- a/chromium/printing/printing_context.cc +++ b/chromium/printing/printing_context.cc @@ -26,8 +26,7 @@ PrintingContext::PrintingContext(Delegate* delegate) DCHECK(delegate_); } -PrintingContext::~PrintingContext() { -} +PrintingContext::~PrintingContext() = default; void PrintingContext::set_margin_type(MarginType type) { DCHECK(type != CUSTOM_MARGINS); diff --git a/chromium/printing/printing_context_win.cc b/chromium/printing/printing_context_win.cc index 402d55f5036..a8359e65e6d 100644 --- a/chromium/printing/printing_context_win.cc +++ b/chromium/printing/printing_context_win.cc @@ -263,11 +263,12 @@ PrintingContext::Result PrintingContextWin::NewDocument( di.lpszDocName = document_name.c_str(); // Is there a debug dump directory specified? If so, force to print to a file. - base::string16 debug_dump_path = - PrintedDocument::CreateDebugDumpPath(document_name, - FILE_PATH_LITERAL(".prn")).value(); - if (!debug_dump_path.empty()) - di.lpszOutput = debug_dump_path.c_str(); + if (PrintedDocument::HasDebugDumpPath()) { + base::FilePath debug_dump_path = PrintedDocument::CreateDebugDumpPath( + document_name, FILE_PATH_LITERAL(".prn")); + if (!debug_dump_path.empty()) + di.lpszOutput = debug_dump_path.value().c_str(); + } // No message loop running in unit tests. DCHECK(!base::MessageLoop::current() || diff --git a/chromium/printing/pwg_raster_settings.h b/chromium/printing/pwg_raster_settings.h index 46f0b550f68..fe7ae4cad05 100644 --- a/chromium/printing/pwg_raster_settings.h +++ b/chromium/printing/pwg_raster_settings.h @@ -22,6 +22,8 @@ struct PwgRasterSettings { bool rotate_all_pages; // Rasterize pages in reverse order. bool reverse_page_order; + // Rasterize pages in color. + bool use_color; }; } // namespace printing -- cgit v1.2.1