Enable chrome with aura for tizen
[platform/framework/web/chromium-efl.git] / printing / metafile_skia.h
1 // Copyright 2012 The Chromium Authors
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #ifndef PRINTING_METAFILE_SKIA_H_
6 #define PRINTING_METAFILE_SKIA_H_
7
8 #include <stdint.h>
9
10 #include <memory>
11
12 #include "base/gtest_prod_util.h"
13 #include "build/build_config.h"
14 #include "cc/paint/paint_canvas.h"
15 #include "printing/common/metafile_utils.h"
16 #include "printing/metafile.h"
17 #include "printing/mojom/print.mojom-forward.h"
18 #include "skia/ext/platform_canvas.h"
19 #include "ui/accessibility/ax_tree_update.h"
20
21 #if BUILDFLAG(IS_WIN)
22 #include <windows.h>
23 #endif
24
25 namespace base {
26 class UnguessableToken;
27 }  // namespace base
28
29 namespace printing {
30
31 struct MetafileSkiaData;
32
33 // This class uses Skia graphics library to generate a PDF or MSKP document.
34 class COMPONENT_EXPORT(PRINTING_METAFILE) MetafileSkia : public Metafile {
35  public:
36   // Default constructor, for mojom::SkiaDocumentType::kPDF type only.
37   // TODO(weili): we should split up this use case into a different class, see
38   //              comments before InitFromData()'s implementation.
39   MetafileSkia();
40   MetafileSkia(mojom::SkiaDocumentType type, int document_cookie);
41   MetafileSkia(const MetafileSkia&) = delete;
42   MetafileSkia& operator=(const MetafileSkia&) = delete;
43   ~MetafileSkia() override;
44
45   // Metafile methods.
46   bool Init() override;
47   bool InitFromData(base::span<const uint8_t> data) override;
48
49   void StartPage(const gfx::Size& page_size,
50                  const gfx::Rect& content_area,
51                  float scale_factor,
52                  mojom::PageOrientation page_orientation) override;
53   bool FinishPage() override;
54   bool FinishDocument() override;
55
56   uint32_t GetDataSize() const override;
57   bool GetData(void* dst_buffer, uint32_t dst_buffer_size) const override;
58   bool ShouldCopySharedMemoryRegionData() const override;
59   mojom::MetafileDataType GetDataType() const override;
60
61   gfx::Rect GetPageBounds(unsigned int page_number) const override;
62   unsigned int GetPageCount() const override;
63
64   printing::NativeDrawingContext context() const override;
65
66 #if BUILDFLAG(IS_WIN)
67   bool Playback(printing::NativeDrawingContext hdc,
68                 const RECT* rect) const override;
69   bool SafePlayback(printing::NativeDrawingContext hdc) const override;
70 #elif BUILDFLAG(IS_MAC)
71   bool RenderPage(unsigned int page_number,
72                   printing::NativeDrawingContext context,
73                   const CGRect& rect,
74                   bool autorotate,
75                   bool fit_to_page) const override;
76 #endif
77
78 #if BUILDFLAG(IS_ANDROID)
79   bool SaveToFileDescriptor(int fd) const override;
80 #else
81   bool SaveTo(base::File* file) const override;
82 #endif  // BUILDFLAG(IS_ANDROID)
83
84   // Unlike FinishPage() or FinishDocument(), this is for out-of-process
85   // subframe printing. It will just serialize the content into SkPicture
86   // format and store it as final data.
87   void FinishFrameContent();
88
89   // Return a new metafile containing just the current page in draft mode.
90   std::unique_ptr<MetafileSkia> GetMetafileForCurrentPage(
91       mojom::SkiaDocumentType type);
92
93   // This method calls StartPage and then returns an appropriate
94   // PlatformCanvas implementation bound to the context created by
95   // StartPage or NULL on error.  The PaintCanvas pointer that
96   // is returned is owned by this MetafileSkia object and does not
97   // need to be ref()ed or unref()ed.  The canvas will remain valid
98   // until FinishPage() or FinishDocument() is called.
99   cc::PaintCanvas* GetVectorCanvasForNewPage(
100       const gfx::Size& page_size,
101       const gfx::Rect& content_area,
102       float scale_factor,
103       mojom::PageOrientation page_orientation);
104
105   // This is used for painting content of out-of-process subframes.
106   // For such a subframe, since the content is in another process, we create a
107   // place holder picture now, and replace it with actual content by pdf
108   // compositor service later.
109   uint32_t CreateContentForRemoteFrame(
110       const gfx::Rect& rect,
111       const base::UnguessableToken& render_proxy_token);
112
113   int GetDocumentCookie() const;
114   const ContentToProxyTokenMap& GetSubframeContentInfo() const;
115
116   void UtilizeTypefaceContext(ContentProxySet* typeface_content_info);
117
118   const ui::AXTreeUpdate& accessibility_tree() const {
119     return accessibility_tree_;
120   }
121   ui::AXTreeUpdate& accessibility_tree() { return accessibility_tree_; }
122
123  private:
124   FRIEND_TEST_ALL_PREFIXES(MetafileSkiaTest, TestFrameContent);
125   FRIEND_TEST_ALL_PREFIXES(MetafileSkiaTest, TestMultiPictureDocumentTypefaces);
126
127   // The following three functions are used for tests only.
128   void AppendPage(const SkSize& page_size, sk_sp<cc::PaintRecord> record);
129   void AppendSubframeInfo(uint32_t content_id,
130                           const base::UnguessableToken& proxy_token,
131                           sk_sp<SkPicture> subframe_pic_holder);
132   SkStreamAsset* GetPdfData() const;
133
134   // Callback function used during page content drawing to replace a custom
135   // data holder with corresponding place holder SkPicture.
136   void CustomDataToSkPictureCallback(SkCanvas* canvas, uint32_t content_id);
137
138   std::unique_ptr<MetafileSkiaData> data_;
139
140   ui::AXTreeUpdate accessibility_tree_;
141 };
142
143 }  // namespace printing
144
145 #endif  // PRINTING_METAFILE_SKIA_H_