OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef CHROME_RENDERER_PRINT_WEB_VIEW_HELPER_H_ | 5 #ifndef CHROME_RENDERER_PRINT_WEB_VIEW_HELPER_H_ |
6 #define CHROME_RENDERER_PRINT_WEB_VIEW_HELPER_H_ | 6 #define CHROME_RENDERER_PRINT_WEB_VIEW_HELPER_H_ |
7 #pragma once | 7 #pragma once |
8 | 8 |
9 #include <vector> | 9 #include <vector> |
10 | 10 |
11 #include "base/memory/scoped_ptr.h" | 11 #include "base/memory/scoped_ptr.h" |
12 #include "base/shared_memory.h" | 12 #include "base/shared_memory.h" |
13 #include "base/time.h" | 13 #include "base/time.h" |
14 #include "content/renderer/render_view_observer.h" | 14 #include "content/renderer/render_view_observer.h" |
15 #include "content/renderer/render_view_observer_tracker.h" | 15 #include "content/renderer/render_view_observer_tracker.h" |
16 #include "printing/metafile.h" | 16 #include "printing/metafile.h" |
17 #include "third_party/WebKit/Source/WebKit/chromium/public/WebFrameClient.h" | 17 #include "third_party/WebKit/Source/WebKit/chromium/public/WebFrameClient.h" |
18 #include "third_party/WebKit/Source/WebKit/chromium/public/WebViewClient.h" | 18 #include "third_party/WebKit/Source/WebKit/chromium/public/WebViewClient.h" |
19 #include "ui/gfx/size.h" | 19 #include "ui/gfx/size.h" |
20 | 20 |
21 struct PrintMsg_Print_Params; | 21 struct PrintMsg_Print_Params; |
22 struct PrintMsg_PrintPage_Params; | 22 struct PrintMsg_PrintPage_Params; |
23 struct PrintMsg_PrintPages_Params; | 23 struct PrintMsg_PrintPages_Params; |
24 | 24 |
25 namespace base { | 25 namespace base { |
26 class DictionaryValue; | 26 class DictionaryValue; |
27 } | 27 } |
| 28 namespace skia { |
| 29 class VectorCanvas; |
| 30 class VectorPlatformDeviceSkia; |
| 31 } |
| 32 template <typename t> class SkRefPtr; |
28 | 33 |
29 // Class that calls the Begin and End print functions on the frame and changes | 34 // Class that calls the Begin and End print functions on the frame and changes |
30 // the size of the view temporarily to support full page printing.. | 35 // the size of the view temporarily to support full page printing.. |
31 // Do not serve any events in the time between construction and destruction of | 36 // Do not serve any events in the time between construction and destruction of |
32 // this class because it will cause flicker. | 37 // this class because it will cause flicker. |
33 class PrepareFrameAndViewForPrint { | 38 class PrepareFrameAndViewForPrint { |
34 public: | 39 public: |
35 // Prints |frame|. If |node| is not NULL, then only that node will be | 40 // Prints |frame|. If |node| is not NULL, then only that node will be |
36 // printed. | 41 // printed. |
37 PrepareFrameAndViewForPrint(const PrintMsg_Print_Params& print_params, | 42 PrepareFrameAndViewForPrint(const PrintMsg_Print_Params& print_params, |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
69 // Struct that holds margin and content area information of a page. | 74 // Struct that holds margin and content area information of a page. |
70 typedef struct PageSizeMargins { | 75 typedef struct PageSizeMargins { |
71 double content_width; | 76 double content_width; |
72 double content_height; | 77 double content_height; |
73 double margin_top; | 78 double margin_top; |
74 double margin_right; | 79 double margin_right; |
75 double margin_bottom; | 80 double margin_bottom; |
76 double margin_left; | 81 double margin_left; |
77 } PageSizeMargins; | 82 } PageSizeMargins; |
78 | 83 |
| 84 // Given the |device| and |canvas| to draw on, prints the appropriate headers |
| 85 // and footers using strings from |header_footer_info| on to the canvas. |
| 86 void PrintHeaderAndFooter(skia::VectorPlatformDeviceSkia* device, |
| 87 const SkRefPtr<skia::VectorCanvas>& canvas, |
| 88 int page_number, int total_pages, |
| 89 float webkit_scale_factor, |
| 90 PageSizeMargins& page_layout_in_points, |
| 91 const base::DictionaryValue* header_footer_info); |
| 92 |
79 // PrintWebViewHelper handles most of the printing grunt work for RenderView. | 93 // PrintWebViewHelper handles most of the printing grunt work for RenderView. |
80 // We plan on making print asynchronous and that will require copying the DOM | 94 // We plan on making print asynchronous and that will require copying the DOM |
81 // of the document and creating a new WebView with the contents. | 95 // of the document and creating a new WebView with the contents. |
82 class PrintWebViewHelper : public RenderViewObserver, | 96 class PrintWebViewHelper : public RenderViewObserver, |
83 public RenderViewObserverTracker<PrintWebViewHelper>, | 97 public RenderViewObserverTracker<PrintWebViewHelper>, |
84 public WebKit::WebViewClient, | 98 public WebKit::WebViewClient, |
85 public WebKit::WebFrameClient { | 99 public WebKit::WebFrameClient { |
86 public: | 100 public: |
87 explicit PrintWebViewHelper(RenderView* render_view); | 101 explicit PrintWebViewHelper(RenderView* render_view); |
88 virtual ~PrintWebViewHelper(); | 102 virtual ~PrintWebViewHelper(); |
(...skipping 27 matching lines...) Expand all Loading... |
116 // Print the document. | 130 // Print the document. |
117 void OnPrintPages(); | 131 void OnPrintPages(); |
118 | 132 |
119 // Print the document with the print preview frame/node. | 133 // Print the document with the print preview frame/node. |
120 void OnPrintForSystemDialog(); | 134 void OnPrintForSystemDialog(); |
121 | 135 |
122 // Initiate print preview. | 136 // Initiate print preview. |
123 void OnInitiatePrintPreview(); | 137 void OnInitiatePrintPreview(); |
124 | 138 |
125 // Start the process of generating a print preview using |settings|. | 139 // Start the process of generating a print preview using |settings|. |
126 void OnPrintPreview(const base::DictionaryValue& settings); | 140 // |header_footer_info| contains the necessary strings generated by the |
| 141 // browser process to be printed as headers and footers if requested by the |
| 142 // user. |
| 143 void OnPrintPreview(const base::DictionaryValue& settings, |
| 144 const base::DictionaryValue& header_footer_info); |
127 // Initialize the print preview document. | 145 // Initialize the print preview document. |
128 bool CreatePreviewDocument(); | 146 bool CreatePreviewDocument(); |
129 | 147 |
130 // Continue generating the print preview. | 148 // Continue generating the print preview. |
131 void OnContinuePreview(); | 149 void OnContinuePreview(); |
132 // Renders a print preview page. |page_number| is 0-based. | 150 // Renders a print preview page. |page_number| is 0-based. |
133 void RenderPreviewPage(int page_number); | 151 void RenderPreviewPage(int page_number); |
134 // Finalize the print preview document. | 152 // Finalize the print preview document. |
135 bool FinalizePreviewDocument(); | 153 bool FinalizePreviewDocument(); |
136 | 154 |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
199 // It will implicitly revert the document to display CSS media type. | 217 // It will implicitly revert the document to display CSS media type. |
200 bool PrintPages(const PrintMsg_PrintPages_Params& params, | 218 bool PrintPages(const PrintMsg_PrintPages_Params& params, |
201 WebKit::WebFrame* frame, | 219 WebKit::WebFrame* frame, |
202 WebKit::WebNode* node); | 220 WebKit::WebNode* node); |
203 | 221 |
204 // Prints the page listed in |params|. | 222 // Prints the page listed in |params|. |
205 #if defined(USE_X11) | 223 #if defined(USE_X11) |
206 void PrintPageInternal(const PrintMsg_PrintPage_Params& params, | 224 void PrintPageInternal(const PrintMsg_PrintPage_Params& params, |
207 const gfx::Size& canvas_size, | 225 const gfx::Size& canvas_size, |
208 WebKit::WebFrame* frame, | 226 WebKit::WebFrame* frame, |
209 printing::Metafile* metafile); | 227 printing::Metafile* metafile, |
| 228 bool is_preview); |
210 #else | 229 #else |
211 void PrintPageInternal(const PrintMsg_PrintPage_Params& params, | 230 void PrintPageInternal(const PrintMsg_PrintPage_Params& params, |
212 const gfx::Size& canvas_size, | 231 const gfx::Size& canvas_size, |
213 WebKit::WebFrame* frame); | 232 WebKit::WebFrame* frame); |
214 #endif | 233 #endif |
215 | 234 |
216 // Render the frame for printing. | 235 // Render the frame for printing. |
217 bool RenderPagesForPrint(WebKit::WebFrame* frame, WebKit::WebNode* node); | 236 bool RenderPagesForPrint(WebKit::WebFrame* frame, WebKit::WebNode* node); |
218 | 237 |
219 // Platform specific helper function for rendering page(s) to |metafile|. | 238 // Platform specific helper function for rendering page(s) to |metafile|. |
220 #if defined(OS_WIN) | 239 #if defined(OS_WIN) |
221 void RenderPage(const PrintMsg_Print_Params& params, float* scale_factor, | 240 void RenderPage(const PrintMsg_Print_Params& params, float* scale_factor, |
222 int page_number, bool is_preview, WebKit::WebFrame* frame, | 241 int page_number, bool is_preview, WebKit::WebFrame* frame, |
223 scoped_ptr<printing::Metafile>* metafile); | 242 scoped_ptr<printing::Metafile>* metafile); |
224 #elif defined(OS_MACOSX) | 243 #elif defined(OS_MACOSX) |
225 void RenderPage(const gfx::Size& page_size, const gfx::Rect& content_area, | 244 void RenderPage(const gfx::Size& page_size, const gfx::Rect& content_area, |
226 const float& scale_factor, int page_number, | 245 const float& scale_factor, int page_number, |
227 WebKit::WebFrame* frame, printing::Metafile* metafile); | 246 WebKit::WebFrame* frame, printing::Metafile* metafile, |
| 247 bool is_preview); |
228 #elif defined(OS_POSIX) | 248 #elif defined(OS_POSIX) |
229 bool RenderPages(const PrintMsg_PrintPages_Params& params, | 249 bool RenderPages(const PrintMsg_PrintPages_Params& params, |
230 WebKit::WebFrame* frame, WebKit::WebNode* node, | 250 WebKit::WebFrame* frame, WebKit::WebNode* node, |
231 int* page_count, printing::Metafile* metafile); | 251 int* page_count, printing::Metafile* metafile); |
232 #endif // defined(OS_WIN) | 252 #endif // defined(OS_WIN) |
233 | 253 |
234 // Helper methods ----------------------------------------------------------- | 254 // Helper methods ----------------------------------------------------------- |
235 | 255 |
236 bool CopyAndPrint(WebKit::WebFrame* web_frame); | 256 bool CopyAndPrint(WebKit::WebFrame* web_frame); |
237 | 257 |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
283 // Used for scripted initiated printing blocking. | 303 // Used for scripted initiated printing blocking. |
284 base::Time last_cancelled_script_print_; | 304 base::Time last_cancelled_script_print_; |
285 int user_cancelled_scripted_print_count_; | 305 int user_cancelled_scripted_print_count_; |
286 | 306 |
287 // Let the browser process know of a printing failure. Only set to false when | 307 // Let the browser process know of a printing failure. Only set to false when |
288 // the failure came from the browser in the first place. | 308 // the failure came from the browser in the first place. |
289 bool notify_browser_of_print_failure_; | 309 bool notify_browser_of_print_failure_; |
290 | 310 |
291 scoped_ptr<PrintMsg_PrintPages_Params> old_print_pages_params_; | 311 scoped_ptr<PrintMsg_PrintPages_Params> old_print_pages_params_; |
292 | 312 |
| 313 // Contains strings generated by the browser process to be printed as headers |
| 314 // and footers if requested by the user. |
| 315 const base::DictionaryValue* header_footer_info_; |
| 316 |
293 // Keeps track of the state of print preview between messages. | 317 // Keeps track of the state of print preview between messages. |
294 class PrintPreviewContext { | 318 class PrintPreviewContext { |
295 public: | 319 public: |
296 PrintPreviewContext(); | 320 PrintPreviewContext(); |
297 ~PrintPreviewContext(); | 321 ~PrintPreviewContext(); |
298 | 322 |
299 // Initializes the print preview context. Need to be called to set | 323 // Initializes the print preview context. Need to be called to set |
300 // the |web_frame| / |web_node| to generate the print preview for. | 324 // the |web_frame| / |web_node| to generate the print preview for. |
301 void InitWithFrame(WebKit::WebFrame* web_frame); | 325 void InitWithFrame(WebKit::WebFrame* web_frame); |
302 void InitWithNode(const WebKit::WebNode& web_node); | 326 void InitWithNode(const WebKit::WebNode& web_node); |
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
371 | 395 |
372 State state_; | 396 State state_; |
373 }; | 397 }; |
374 | 398 |
375 PrintPreviewContext print_preview_context_; | 399 PrintPreviewContext print_preview_context_; |
376 | 400 |
377 DISALLOW_COPY_AND_ASSIGN(PrintWebViewHelper); | 401 DISALLOW_COPY_AND_ASSIGN(PrintWebViewHelper); |
378 }; | 402 }; |
379 | 403 |
380 #endif // CHROME_RENDERER_PRINT_WEB_VIEW_HELPER_H_ | 404 #endif // CHROME_RENDERER_PRINT_WEB_VIEW_HELPER_H_ |
OLD | NEW |