Upload upstream chromium 73.0.3683.0
[platform/framework/web/chromium-efl.git] / printing / printed_document_mac.cc
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "printing/printed_document.h"
6
7 #import <ApplicationServices/ApplicationServices.h>
8 #import <CoreFoundation/CoreFoundation.h>
9
10 #include "base/logging.h"
11 #include "printing/metafile.h"
12 #include "printing/printing_context.h"
13
14 namespace printing {
15
16 bool PrintedDocument::RenderPrintedDocument(PrintingContext* context) {
17   DCHECK(context);
18
19   const MetafilePlayer* metafile;
20   gfx::Size page_size;
21   gfx::Rect page_content_rect;
22   {
23     base::AutoLock lock(lock_);
24     metafile = GetMetafile();
25     page_size = mutable_.page_size_;
26     page_content_rect = mutable_.page_content_rect_;
27   }
28
29   DCHECK(metafile);
30   const PageSetup& page_setup = immutable_.settings_.page_setup_device_units();
31   gfx::Rect content_area = GetCenteredPageContentRect(
32       page_setup.physical_size(), page_size, page_content_rect);
33
34   struct Metafile::MacRenderPageParams params;
35   params.autorotate = true;
36   size_t num_pages = expected_page_count();
37   for (size_t metafile_page_number = 1; metafile_page_number <= num_pages;
38        metafile_page_number++) {
39     if (context->NewPage() != PrintingContext::OK)
40       return false;
41     metafile->RenderPage(metafile_page_number, context->context(),
42                          content_area.ToCGRect(), params);
43     if (context->PageDone() != PrintingContext::OK)
44       return false;
45   }
46   return true;
47 }
48
49 }  // namespace printing