1 | /* |
2 | * Copyright (C) 2012 Igalia S.L. |
3 | * |
4 | * Redistribution and use in source and binary forms, with or without |
5 | * modification, are permitted provided that the following conditions |
6 | * are met: |
7 | * 1. Redistributions of source code must retain the above copyright |
8 | * notice, this list of conditions and the following disclaimer. |
9 | * 2. Redistributions in binary form must reproduce the above copyright |
10 | * notice, this list of conditions and the following disclaimer in the |
11 | * documentation and/or other materials provided with the distribution. |
12 | * |
13 | * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' |
14 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, |
15 | * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR |
16 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS |
17 | * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
18 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
19 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
20 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
21 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
22 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF |
23 | * THE POSSIBILITY OF SUCH DAMAGE. |
24 | */ |
25 | |
26 | #ifndef WebPrintOperationGtk_h |
27 | #define WebPrintOperationGtk_h |
28 | |
29 | #include "CallbackID.h" |
30 | #include "PrintInfo.h" |
31 | #include <WebCore/RefPtrCairo.h> |
32 | #include <wtf/RefCounted.h> |
33 | #include <wtf/RefPtr.h> |
34 | #include <wtf/glib/GRefPtr.h> |
35 | |
36 | typedef struct _GtkPrintSettings GtkPrintSettings; |
37 | typedef struct _GtkPageSetup GtkPageSetup; |
38 | typedef struct ; |
39 | |
40 | namespace WebCore { |
41 | class PrintContext; |
42 | class ResourceError; |
43 | }; |
44 | |
45 | namespace WebKit { |
46 | |
47 | class WebPage; |
48 | |
49 | class WebPrintOperationGtk : public RefCounted<WebPrintOperationGtk> { |
50 | public: |
51 | static RefPtr<WebPrintOperationGtk> create(WebPage*, const PrintInfo&); |
52 | virtual ~WebPrintOperationGtk(); |
53 | |
54 | WebCore::PrintContext* printContext() const { return m_printContext; } |
55 | GtkPrintSettings* printSettings() const { return m_printSettings.get(); } |
56 | GtkPageSetup* pageSetup() const { return m_pageSetup.get(); } |
57 | PrintInfo::PrintMode printMode() const { return m_printMode; } |
58 | void setNumberOfPagesToPrint(size_t numberOfPages) { m_numberOfPagesToPrint = numberOfPages; } |
59 | unsigned int pagesToPrint() const { return m_pagesToPrint; } |
60 | int pageCount() const; |
61 | bool currentPageIsFirstPageOfSheet() const; |
62 | bool currentPageIsLastPageOfSheet() const; |
63 | size_t pagePosition() const { return m_pagePosition; } |
64 | void setPagePosition(size_t position) { m_pagePosition = position; } |
65 | GtkPageRange* () const { return m_pageRanges; } |
66 | size_t () const { return m_pageRangesCount; } |
67 | |
68 | unsigned int numberUp() const { return m_numberUp; } |
69 | unsigned int numberUpLayout() const { return m_numberUpLayout; } |
70 | unsigned int pageSet() const { return m_pageSet; } |
71 | bool reverse() const { return m_reverse; } |
72 | unsigned int copies() const { return m_copies; } |
73 | bool collateCopies() const { return m_collateCopies; } |
74 | double scale() const { return m_scale; } |
75 | |
76 | void disconnectFromPage(); |
77 | |
78 | virtual void startPrint(WebCore::PrintContext*, CallbackID) = 0; |
79 | |
80 | protected: |
81 | WebPrintOperationGtk(WebPage*, const PrintInfo&); |
82 | |
83 | virtual void startPage(cairo_t*) = 0; |
84 | virtual void endPage(cairo_t*) = 0; |
85 | virtual void endPrint() = 0; |
86 | |
87 | static gboolean printPagesIdle(gpointer); |
88 | static void printPagesIdleDone(gpointer); |
89 | |
90 | void print(cairo_surface_t*, double xDPI, double yDPI); |
91 | void renderPage(int pageNumber); |
92 | void rotatePageIfNeeded(); |
93 | void getRowsAndColumnsOfPagesPerSheet(size_t& rows, size_t& columns); |
94 | void getPositionOfPageInSheet(size_t rows, size_t columns, int& x, int&y); |
95 | void prepareContextToDraw(); |
96 | void printPagesDone(); |
97 | void printDone(const WebCore::ResourceError&); |
98 | void sendPrintFinished(const WebCore::ResourceError&); |
99 | URL frameURL() const; |
100 | |
101 | WebPage* m_webPage; |
102 | GRefPtr<GtkPrintSettings> m_printSettings; |
103 | GRefPtr<GtkPageSetup> m_pageSetup; |
104 | PrintInfo::PrintMode m_printMode; |
105 | WebCore::PrintContext* m_printContext; |
106 | CallbackID m_callbackID; |
107 | RefPtr<cairo_t> m_cairoContext; |
108 | double m_xDPI; |
109 | double m_yDPI; |
110 | |
111 | unsigned int m_printPagesIdleId; |
112 | size_t m_numberOfPagesToPrint; |
113 | unsigned int m_pagesToPrint; |
114 | size_t m_pagePosition; |
115 | GtkPageRange* ; |
116 | size_t ; |
117 | bool m_needsRotation; |
118 | |
119 | // Manual capabilities. |
120 | unsigned int m_numberUp; |
121 | unsigned int m_numberUpLayout; |
122 | unsigned int m_pageSet; |
123 | bool m_reverse; |
124 | unsigned int m_copies; |
125 | bool m_collateCopies; |
126 | double m_scale; |
127 | }; |
128 | |
129 | } |
130 | |
131 | #endif // WebPrintOperationGtk_h |
132 | |