Upstream version 10.39.225.0
[platform/framework/web/crosswalk.git] / src / printing / printed_page.h
1 // Copyright (c) 2011 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 #ifndef PRINTING_PRINTED_PAGE_H_
6 #define PRINTING_PRINTED_PAGE_H_
7
8 #include "base/memory/ref_counted.h"
9 #include "base/memory/scoped_ptr.h"
10 #include "printing/metafile.h"
11 #include "ui/gfx/rect.h"
12 #include "ui/gfx/size.h"
13
14 namespace printing {
15
16 // Contains the data to reproduce a printed page, either on screen or on
17 // paper. Once created, this object is immutable. It has no reference to the
18 // PrintedDocument containing this page.
19 // Note: May be accessed from many threads at the same time. This is an non
20 // issue since this object is immutable. The reason is that a page may be
21 // printed and be displayed at the same time.
22 class PRINTING_EXPORT PrintedPage
23     : public base::RefCountedThreadSafe<PrintedPage> {
24  public:
25   PrintedPage(int page_number,
26               scoped_ptr<MetafilePlayer> metafile,
27               const gfx::Size& page_size,
28               const gfx::Rect& page_content_rect);
29
30   // Getters
31   int page_number() const { return page_number_; }
32   const MetafilePlayer* metafile() const;
33   const gfx::Size& page_size() const { return page_size_; }
34   const gfx::Rect& page_content_rect() const { return page_content_rect_; }
35 #if defined(OS_WIN)
36   void set_shrink_factor(double shrink_factor) {
37     shrink_factor_ = shrink_factor;
38   }
39   double shrink_factor() const { return shrink_factor_; }
40 #endif  // OS_WIN
41
42   // Get page content rect adjusted based on
43   // http://dev.w3.org/csswg/css3-page/#positioning-page-box
44   void GetCenteredPageContentRect(const gfx::Size& paper_size,
45                                   gfx::Rect* content_rect) const;
46
47  private:
48   friend class base::RefCountedThreadSafe<PrintedPage>;
49
50   ~PrintedPage();
51
52   // Page number inside the printed document.
53   const int page_number_;
54
55   // Actual paint data.
56   const scoped_ptr<MetafilePlayer> metafile_;
57
58 #if defined(OS_WIN)
59   // Shrink done in comparison to desired_dpi.
60   double shrink_factor_;
61 #endif  // OS_WIN
62
63   // The physical page size. To support multiple page formats inside on print
64   // job.
65   const gfx::Size page_size_;
66
67   // The printable area of the page.
68   const gfx::Rect page_content_rect_;
69
70   DISALLOW_COPY_AND_ASSIGN(PrintedPage);
71 };
72
73 }  // namespace printing
74
75 #endif  // PRINTING_PRINTED_PAGE_H_