OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 | 7 |
8 #include <vector> | 8 #include <vector> |
9 | 9 |
10 #include "base/gtest_prod_util.h" | 10 #include "base/gtest_prod_util.h" |
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/public/renderer/render_view_observer.h" | 14 #include "content/public/renderer/render_view_observer.h" |
15 #include "content/public/renderer/render_view_observer_tracker.h" | 15 #include "content/public/renderer/render_view_observer_tracker.h" |
16 #include "printing/metafile.h" | |
17 #include "printing/metafile_impl.h" | 16 #include "printing/metafile_impl.h" |
18 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebCanvas.h" | 17 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebCanvas.h" |
19 #include "third_party/WebKit/Source/WebKit/chromium/public/WebFrameClient.h" | 18 #include "third_party/WebKit/Source/WebKit/chromium/public/WebFrameClient.h" |
20 #include "third_party/WebKit/Source/WebKit/chromium/public/WebNode.h" | 19 #include "third_party/WebKit/Source/WebKit/chromium/public/WebNode.h" |
21 #include "third_party/WebKit/Source/WebKit/chromium/public/WebPrintParams.h" | 20 #include "third_party/WebKit/Source/WebKit/chromium/public/WebPrintParams.h" |
22 #include "third_party/WebKit/Source/WebKit/chromium/public/WebViewClient.h" | 21 #include "third_party/WebKit/Source/WebKit/chromium/public/WebViewClient.h" |
23 #include "ui/gfx/size.h" | 22 #include "ui/gfx/size.h" |
24 | 23 |
25 struct PrintMsg_Print_Params; | 24 struct PrintMsg_Print_Params; |
26 struct PrintMsg_PrintPage_Params; | 25 struct PrintMsg_PrintPage_Params; |
27 struct PrintMsg_PrintPages_Params; | 26 struct PrintMsg_PrintPages_Params; |
28 | 27 |
29 namespace base { | 28 namespace base { |
30 class DictionaryValue; | 29 class DictionaryValue; |
31 } | 30 } |
| 31 |
32 namespace printing { | 32 namespace printing { |
33 struct PageSizeMargins; | 33 struct PageSizeMargins; |
34 } | 34 } |
35 | 35 |
| 36 namespace WebKit { |
| 37 class WebFrame; |
| 38 class WebView; |
| 39 } |
| 40 |
36 // Class that calls the Begin and End print functions on the frame and changes | 41 // Class that calls the Begin and End print functions on the frame and changes |
37 // the size of the view temporarily to support full page printing.. | 42 // the size of the view temporarily to support full page printing.. |
38 // Do not serve any events in the time between construction and destruction of | 43 // Do not serve any events in the time between construction and destruction of |
39 // this class because it will cause flicker. | 44 // this class because it will cause flicker. |
40 class PrepareFrameAndViewForPrint { | 45 class PrepareFrameAndViewForPrint { |
41 public: | 46 public: |
42 // Prints |frame|. If |node| is not NULL, then only that node will be | 47 // Prints |frame|. If |node| is not NULL, then only that node will be |
43 // printed. | 48 // printed. |
44 PrepareFrameAndViewForPrint(const PrintMsg_Print_Params& print_params, | 49 PrepareFrameAndViewForPrint(const PrintMsg_Print_Params& print_params, |
45 WebKit::WebFrame* frame, | 50 WebKit::WebFrame* frame, |
46 const WebKit::WebNode& node); | 51 const WebKit::WebNode& node); |
47 ~PrepareFrameAndViewForPrint(); | 52 ~PrepareFrameAndViewForPrint(); |
48 | 53 |
49 void UpdatePrintParams(const PrintMsg_Print_Params& print_params); | 54 void UpdatePrintParams(const PrintMsg_Print_Params& print_params); |
50 | 55 |
51 int GetExpectedPageCount() const { | 56 int GetExpectedPageCount() const { |
52 return expected_pages_count_; | 57 return expected_pages_count_; |
53 } | 58 } |
54 | 59 |
55 bool ShouldUseBrowserOverlays() const { | 60 bool ShouldUseBrowserOverlays() const { |
56 return use_browser_overlays_; | 61 return use_browser_overlays_; |
57 } | 62 } |
58 | 63 |
59 gfx::Size GetPrintCanvasSize() const { | 64 gfx::Size GetPrintCanvasSize() const; |
60 return gfx::Size(web_print_params_.printContentArea.width, | |
61 web_print_params_.printContentArea.height); | |
62 } | |
63 | 65 |
64 void FinishPrinting(); | 66 void FinishPrinting(); |
65 | 67 |
66 private: | 68 private: |
67 void StartPrinting(const WebKit::WebPrintParams& webkit_print_params); | 69 void StartPrinting(const WebKit::WebPrintParams& webkit_print_params); |
68 | 70 |
69 WebKit::WebFrame* frame_; | 71 WebKit::WebFrame* frame_; |
70 WebKit::WebNode node_to_print_; | 72 WebKit::WebNode node_to_print_; |
71 WebKit::WebView* web_view_; | 73 WebKit::WebView* web_view_; |
72 WebKit::WebPrintParams web_print_params_; | 74 WebKit::WebPrintParams web_print_params_; |
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
184 void OnInitiatePrintPreview(); | 186 void OnInitiatePrintPreview(); |
185 | 187 |
186 // Start the process of generating a print preview using |settings|. | 188 // Start the process of generating a print preview using |settings|. |
187 void OnPrintPreview(const base::DictionaryValue& settings); | 189 void OnPrintPreview(const base::DictionaryValue& settings); |
188 | 190 |
189 // Initialize the print preview document. | 191 // Initialize the print preview document. |
190 bool CreatePreviewDocument(); | 192 bool CreatePreviewDocument(); |
191 | 193 |
192 // Renders a print preview page. |page_number| is 0-based. | 194 // Renders a print preview page. |page_number| is 0-based. |
193 // Returns true if print preview should continue, false on failure. | 195 // Returns true if print preview should continue, false on failure. |
194 bool RenderPreviewPage(int page_number); | 196 bool RenderPreviewPage(int page_number, |
| 197 const PrintMsg_Print_Params& print_params); |
195 | 198 |
196 // Finalize the print ready preview document. | 199 // Finalize the print ready preview document. |
197 bool FinalizePrintReadyDocument(); | 200 bool FinalizePrintReadyDocument(); |
198 | 201 |
199 // Print / preview the node under the context menu. | 202 // Print / preview the node under the context menu. |
200 void OnPrintNodeUnderContextMenu(); | 203 void OnPrintNodeUnderContextMenu(); |
201 | 204 |
202 // Print the pages for print preview. Do not display the native print dialog | 205 // Print the pages for print preview. Do not display the native print dialog |
203 // for user settings. |job_settings| has new print job settings values. | 206 // for user settings. |job_settings| has new print job settings values. |
204 void OnPrintForPrintPreview(const base::DictionaryValue& job_settings); | 207 void OnPrintForPrintPreview(const base::DictionaryValue& job_settings); |
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
315 bool ignore_css_margins); | 318 bool ignore_css_margins); |
316 | 319 |
317 // Given the |device| and |canvas| to draw on, prints the appropriate headers | 320 // Given the |device| and |canvas| to draw on, prints the appropriate headers |
318 // and footers using strings from |header_footer_info| on to the canvas. | 321 // and footers using strings from |header_footer_info| on to the canvas. |
319 static void PrintHeaderAndFooter( | 322 static void PrintHeaderAndFooter( |
320 WebKit::WebCanvas* canvas, | 323 WebKit::WebCanvas* canvas, |
321 int page_number, | 324 int page_number, |
322 int total_pages, | 325 int total_pages, |
323 float webkit_scale_factor, | 326 float webkit_scale_factor, |
324 const printing::PageSizeMargins& page_layout_in_points, | 327 const printing::PageSizeMargins& page_layout_in_points, |
325 const base::DictionaryValue& header_footer_info); | 328 const base::DictionaryValue& header_footer_info, |
| 329 const PrintMsg_Print_Params& params); |
326 | 330 |
327 bool GetPrintFrame(WebKit::WebFrame** frame); | 331 bool GetPrintFrame(WebKit::WebFrame** frame); |
328 | 332 |
329 // This reports the current time - |start_time| as the time to render a page. | 333 // This reports the current time - |start_time| as the time to render a page. |
330 void ReportPreviewPageRenderTime(base::TimeTicks start_time); | 334 void ReportPreviewPageRenderTime(base::TimeTicks start_time); |
331 | 335 |
332 // Script Initiated Printing ------------------------------------------------ | 336 // Script Initiated Printing ------------------------------------------------ |
333 | 337 |
334 // Return true if script initiated printing is currently | 338 // Return true if script initiated printing is currently |
335 // allowed. |user_initiated| should be true when a user event triggered the | 339 // allowed. |user_initiated| should be true when a user event triggered the |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
396 | 400 |
397 // Initializes the print preview context. Need to be called to set | 401 // Initializes the print preview context. Need to be called to set |
398 // the |web_frame| / |web_node| to generate the print preview for. | 402 // the |web_frame| / |web_node| to generate the print preview for. |
399 void InitWithFrame(WebKit::WebFrame* web_frame); | 403 void InitWithFrame(WebKit::WebFrame* web_frame); |
400 void InitWithNode(const WebKit::WebNode& web_node); | 404 void InitWithNode(const WebKit::WebNode& web_node); |
401 | 405 |
402 // Does bookkeeping at the beginning of print preview. | 406 // Does bookkeeping at the beginning of print preview. |
403 void OnPrintPreview(); | 407 void OnPrintPreview(); |
404 | 408 |
405 // Create the print preview document. |pages| is empty to print all pages. | 409 // Create the print preview document. |pages| is empty to print all pages. |
406 bool CreatePreviewDocument(PrintMsg_Print_Params* params, | 410 bool CreatePreviewDocument(const PrintMsg_Print_Params& params, |
407 const std::vector<int>& pages, | 411 const std::vector<int>& pages, |
408 bool ignore_css_margins); | 412 bool ignore_css_margins); |
409 | 413 |
410 // Called after a page gets rendered. |page_time| is how long the | 414 // Called after a page gets rendered. |page_time| is how long the |
411 // rendering took. | 415 // rendering took. |
412 void RenderedPreviewPage(const base::TimeDelta& page_time); | 416 void RenderedPreviewPage(const base::TimeDelta& page_time); |
413 | 417 |
414 // Updates the print preview context when the required pages are rendered. | 418 // Updates the print preview context when the required pages are rendered. |
415 void AllPagesRendered(); | 419 void AllPagesRendered(); |
416 | 420 |
(...skipping 16 matching lines...) Expand all Loading... |
433 // Setters | 437 // Setters |
434 void set_generate_draft_pages(bool generate_draft_pages); | 438 void set_generate_draft_pages(bool generate_draft_pages); |
435 void set_error(enum PrintPreviewErrorBuckets error); | 439 void set_error(enum PrintPreviewErrorBuckets error); |
436 | 440 |
437 // Getters | 441 // Getters |
438 WebKit::WebFrame* frame(); | 442 WebKit::WebFrame* frame(); |
439 const WebKit::WebNode& node() const; | 443 const WebKit::WebNode& node() const; |
440 int total_page_count() const; | 444 int total_page_count() const; |
441 bool generate_draft_pages() const; | 445 bool generate_draft_pages() const; |
442 printing::PreviewMetafile* metafile(); | 446 printing::PreviewMetafile* metafile(); |
443 const PrintMsg_Print_Params& print_params() const; | |
444 gfx::Size GetPrintCanvasSize() const; | 447 gfx::Size GetPrintCanvasSize() const; |
445 int last_error() const; | 448 int last_error() const; |
446 | 449 |
447 private: | 450 private: |
448 enum State { | 451 enum State { |
449 UNINITIALIZED, // Not ready to render. | 452 UNINITIALIZED, // Not ready to render. |
450 INITIALIZED, // Ready to render. | 453 INITIALIZED, // Ready to render. |
451 RENDERING, // Rendering. | 454 RENDERING, // Rendering. |
452 DONE // Finished rendering. | 455 DONE // Finished rendering. |
453 }; | 456 }; |
454 | 457 |
455 // Reset some of the internal rendering context. | 458 // Reset some of the internal rendering context. |
456 void ClearContext(); | 459 void ClearContext(); |
457 | 460 |
458 // Specifies what to render for print preview. | 461 // Specifies what to render for print preview. |
459 WebKit::WebFrame* frame_; | 462 WebKit::WebFrame* frame_; |
460 WebKit::WebNode node_; | 463 WebKit::WebNode node_; |
461 | 464 |
462 scoped_ptr<PrepareFrameAndViewForPrint> prep_frame_view_; | 465 scoped_ptr<PrepareFrameAndViewForPrint> prep_frame_view_; |
463 scoped_ptr<printing::PreviewMetafile> metafile_; | 466 scoped_ptr<printing::PreviewMetafile> metafile_; |
464 scoped_ptr<PrintMsg_Print_Params> print_params_; | |
465 | 467 |
466 // Total page count in the renderer. | 468 // Total page count in the renderer. |
467 int total_page_count_; | 469 int total_page_count_; |
468 | 470 |
469 // The current page to render. | 471 // The current page to render. |
470 int current_page_index_; | 472 int current_page_index_; |
471 | 473 |
472 // List of page indices that need to be rendered. | 474 // List of page indices that need to be rendered. |
473 std::vector<int> pages_to_render_; | 475 std::vector<int> pages_to_render_; |
474 | 476 |
475 // True, when draft pages needs to be generated. | 477 // True, when draft pages needs to be generated. |
476 bool generate_draft_pages_; | 478 bool generate_draft_pages_; |
477 | 479 |
478 // Specifies the total number of pages in the print ready metafile. | 480 // Specifies the total number of pages in the print ready metafile. |
479 int print_ready_metafile_page_count_; | 481 int print_ready_metafile_page_count_; |
480 | 482 |
481 base::TimeDelta document_render_time_; | 483 base::TimeDelta document_render_time_; |
482 base::TimeTicks begin_time_; | 484 base::TimeTicks begin_time_; |
483 | 485 |
484 enum PrintPreviewErrorBuckets error_; | 486 enum PrintPreviewErrorBuckets error_; |
485 | 487 |
486 State state_; | 488 State state_; |
487 }; | 489 }; |
488 | 490 |
489 PrintPreviewContext print_preview_context_; | 491 PrintPreviewContext print_preview_context_; |
490 DISALLOW_COPY_AND_ASSIGN(PrintWebViewHelper); | 492 DISALLOW_COPY_AND_ASSIGN(PrintWebViewHelper); |
491 }; | 493 }; |
492 | 494 |
493 #endif // CHROME_RENDERER_PRINT_WEB_VIEW_HELPER_H_ | 495 #endif // CHROME_RENDERER_PRINT_WEB_VIEW_HELPER_H_ |
OLD | NEW |