Upstream version 9.38.198.0
[platform/framework/web/crosswalk.git] / src / third_party / WebKit / Source / core / page / PrintContext.h
1 /*
2  * Copyright (C) 2007 Alp Toker <alp@atoker.com>
3  * Copyright (C) 2007 Apple Inc.
4  *
5  * This library is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU Library General Public
7  * License as published by the Free Software Foundation; either
8  * version 2 of the License, or (at your option) any later version.
9  *
10  * This library is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13  * Library General Public License for more details.
14  *
15  * You should have received a copy of the GNU Library General Public License
16  * along with this library; see the file COPYING.LIB.  If not, write to
17  * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18  * Boston, MA 02110-1301, USA.
19  */
20
21 #ifndef PrintContext_h
22 #define PrintContext_h
23
24 #include "platform/heap/Handle.h"
25 #include "wtf/Forward.h"
26 #include "wtf/HashMap.h"
27 #include "wtf/Vector.h"
28 #include "wtf/text/WTFString.h"
29
30 namespace blink {
31
32 class Element;
33 class LocalFrame;
34 class FloatRect;
35 class FloatSize;
36 class GraphicsContext;
37 class IntRect;
38 class Node;
39
40 class PrintContext : public NoBaseWillBeGarbageCollectedFinalized<PrintContext> {
41 public:
42     explicit PrintContext(LocalFrame*);
43     virtual ~PrintContext();
44
45     LocalFrame* frame() const { return m_frame; }
46
47     // Break up a page into rects without relayout.
48     // FIXME: This means that CSS page breaks won't be on page boundary if the size is different than what was passed to begin(). That's probably not always desirable.
49     // FIXME: Header and footer height should be applied before layout, not after.
50     // FIXME: The printRect argument is only used to determine page aspect ratio, it would be better to pass a FloatSize with page dimensions instead.
51     virtual void computePageRects(const FloatRect& printRect, float headerHeight, float footerHeight, float userScaleFactor, float& outPageHeight);
52
53     // Deprecated. Page size computation is already in this class, clients shouldn't be copying it.
54     // FIXME: Everyone passes |false| for the second paramer. We should remove the second parameter.
55     virtual void computePageRectsWithPageSize(const FloatSize& pageSizeInPixels, bool allowHorizontalTiling);
56
57     // These are only valid after page rects are computed.
58     size_t pageCount() const { return m_pageRects.size(); }
59     const IntRect& pageRect(size_t pageNumber) const { return m_pageRects[pageNumber]; }
60     const Vector<IntRect>& pageRects() const { return m_pageRects; }
61
62     // Enter print mode, updating layout for new page size.
63     // This function can be called multiple times to apply new print options without going back to screen mode.
64     virtual void begin(float width, float height = 0);
65
66     // Return to screen mode.
67     virtual void end();
68
69     // Used by layout tests.
70     static int pageNumberForElement(Element*, const FloatSize& pageSizeInPixels); // Returns -1 if page isn't found.
71     static String pageProperty(LocalFrame* frame, const char* propertyName, int pageNumber);
72     static bool isPageBoxVisible(LocalFrame* frame, int pageNumber);
73     static String pageSizeAndMarginsInPixels(LocalFrame* frame, int pageNumber, int width, int height, int marginTop, int marginRight, int marginBottom, int marginLeft);
74     static int numberOfPages(LocalFrame*, const FloatSize& pageSizeInPixels);
75
76     virtual void trace(Visitor*);
77
78 protected:
79     void outputLinkedDestinations(GraphicsContext&, Node*, const IntRect& pageRect);
80
81     LocalFrame* m_frame;
82     Vector<IntRect> m_pageRects;
83
84 private:
85     void computePageRectsWithPageSizeInternal(const FloatSize& pageSizeInPixels, bool allowHorizontalTiling);
86     void collectLinkedDestinations(Node*);
87
88     // Used to prevent misuses of begin() and end() (e.g., call end without begin).
89     bool m_isPrinting;
90
91     WillBeHeapHashMap<String, RawPtrWillBeMember<Element> > m_linkedDestinations;
92     bool m_linkedDestinationsValid;
93 };
94
95 }
96
97 #endif