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 #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/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" | 16 #include "printing/metafile.h" |
17 #include "printing/metafile_impl.h" | 17 #include "printing/metafile_impl.h" |
18 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebCanvas.h" | 18 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebCanvas.h" |
19 #include "third_party/WebKit/Source/WebKit/chromium/public/WebFrameClient.h" | 19 #include "third_party/WebKit/Source/WebKit/chromium/public/WebFrameClient.h" |
20 #include "third_party/WebKit/Source/WebKit/chromium/public/WebNode.h" | 20 #include "third_party/WebKit/Source/WebKit/chromium/public/WebNode.h" |
21 #include "third_party/WebKit/Source/WebKit/chromium/public/WebPrintScalingOption .h" | |
kmadhusu
2012/04/20 22:23:58
Style??? Do I need to intent 4 space?
kmadhusu
2012/04/23 17:39:10
Leaving this as it is.
| |
21 #include "third_party/WebKit/Source/WebKit/chromium/public/WebViewClient.h" | 22 #include "third_party/WebKit/Source/WebKit/chromium/public/WebViewClient.h" |
22 #include "ui/gfx/size.h" | 23 #include "ui/gfx/size.h" |
23 | 24 |
24 struct PrintMsg_Print_Params; | 25 struct PrintMsg_Print_Params; |
25 struct PrintMsg_PrintPage_Params; | 26 struct PrintMsg_PrintPage_Params; |
26 struct PrintMsg_PrintPages_Params; | 27 struct PrintMsg_PrintPages_Params; |
27 | 28 |
28 namespace base { | 29 namespace base { |
29 class DictionaryValue; | 30 class DictionaryValue; |
30 } | 31 } |
31 namespace printing { | 32 namespace printing { |
32 struct PageSizeMargins; | 33 struct PageSizeMargins; |
33 } | 34 } |
34 | 35 |
35 // Class that calls the Begin and End print functions on the frame and changes | 36 // Class that calls the Begin and End print functions on the frame and changes |
36 // the size of the view temporarily to support full page printing.. | 37 // the size of the view temporarily to support full page printing.. |
37 // Do not serve any events in the time between construction and destruction of | 38 // Do not serve any events in the time between construction and destruction of |
38 // this class because it will cause flicker. | 39 // this class because it will cause flicker. |
39 class PrepareFrameAndViewForPrint { | 40 class PrepareFrameAndViewForPrint { |
40 public: | 41 public: |
41 // Prints |frame|. If |node| is not NULL, then only that node will be | 42 // Prints |frame|. If |node| is not NULL, then only that node will be |
42 // printed. | 43 // printed. |
43 PrepareFrameAndViewForPrint(const PrintMsg_Print_Params& print_params, | 44 PrepareFrameAndViewForPrint(const PrintMsg_Print_Params& print_params, |
44 WebKit::WebFrame* frame, | 45 WebKit::WebFrame* frame, |
45 const WebKit::WebNode& node); | 46 const WebKit::WebNode& node, |
47 WebKit::WebPrintScalingOption option); | |
46 ~PrepareFrameAndViewForPrint(); | 48 ~PrepareFrameAndViewForPrint(); |
47 | 49 |
48 void UpdatePrintParams(const PrintMsg_Print_Params& print_params); | 50 void UpdatePrintParams(const PrintMsg_Print_Params& print_params); |
49 | 51 |
50 int GetExpectedPageCount() const { | 52 int GetExpectedPageCount() const { |
51 return expected_pages_count_; | 53 return expected_pages_count_; |
52 } | 54 } |
53 | 55 |
54 bool ShouldUseBrowserOverlays() const { | 56 bool ShouldUseBrowserOverlays() const { |
55 return use_browser_overlays_; | 57 return use_browser_overlays_; |
56 } | 58 } |
57 | 59 |
58 const gfx::Size& GetPrintCanvasSize() const { | 60 const gfx::Size& GetPrintCanvasSize() const { |
59 return print_canvas_size_; | 61 return print_canvas_size_; |
60 } | 62 } |
61 | 63 |
62 void FinishPrinting(); | 64 void FinishPrinting(); |
63 | 65 |
64 private: | 66 private: |
65 void StartPrinting(const gfx::Size& print_params); | 67 void StartPrinting(const gfx::Size& canvas_size, |
68 const gfx::Rect& printable_area, | |
69 const gfx::Size& paper_size); | |
66 | 70 |
67 WebKit::WebFrame* frame_; | 71 WebKit::WebFrame* frame_; |
68 WebKit::WebNode node_to_print_; | 72 WebKit::WebNode node_to_print_; |
69 WebKit::WebView* web_view_; | 73 WebKit::WebView* web_view_; |
70 gfx::Size print_canvas_size_; | 74 gfx::Size print_canvas_size_; |
75 gfx::Rect printable_area_; | |
76 gfx::Size paper_size_; | |
71 gfx::Size prev_view_size_; | 77 gfx::Size prev_view_size_; |
72 gfx::Size prev_scroll_offset_; | 78 gfx::Size prev_scroll_offset_; |
73 int dpi_; | 79 int dpi_; |
74 int expected_pages_count_; | 80 int expected_pages_count_; |
75 bool use_browser_overlays_; | 81 bool use_browser_overlays_; |
82 WebKit::WebPrintScalingOption print_scaling_option_; | |
76 bool finished_; | 83 bool finished_; |
77 | 84 |
78 DISALLOW_COPY_AND_ASSIGN(PrepareFrameAndViewForPrint); | 85 DISALLOW_COPY_AND_ASSIGN(PrepareFrameAndViewForPrint); |
79 }; | 86 }; |
80 | 87 |
81 // PrintWebViewHelper handles most of the printing grunt work for RenderView. | 88 // PrintWebViewHelper handles most of the printing grunt work for RenderView. |
82 // We plan on making print asynchronous and that will require copying the DOM | 89 // We plan on making print asynchronous and that will require copying the DOM |
83 // of the document and creating a new WebView with the contents. | 90 // of the document and creating a new WebView with the contents. |
84 class PrintWebViewHelper | 91 class PrintWebViewHelper |
85 : public content::RenderViewObserver, | 92 : public content::RenderViewObserver, |
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
193 | 200 |
194 void Print(WebKit::WebFrame* frame, const WebKit::WebNode& node); | 201 void Print(WebKit::WebFrame* frame, const WebKit::WebNode& node); |
195 | 202 |
196 // Notification when printing is done - signal tear-down/free resources. | 203 // Notification when printing is done - signal tear-down/free resources. |
197 void DidFinishPrinting(PrintingResult result); | 204 void DidFinishPrinting(PrintingResult result); |
198 | 205 |
199 // Print Settings ----------------------------------------------------------- | 206 // Print Settings ----------------------------------------------------------- |
200 | 207 |
201 // Initialize print page settings with default settings. | 208 // Initialize print page settings with default settings. |
202 // Used only for native printing workflow. | 209 // Used only for native printing workflow. |
203 bool InitPrintSettings(); | 210 bool InitPrintSettings(bool fit_to_paper_size); |
204 | 211 |
205 // Initialize print page settings with default settings and prepare the frame | 212 // Initialize print page settings with default settings and prepare the frame |
206 // for print. A new PrepareFrameAndViewForPrint is created to fulfill the | 213 // for print. A new PrepareFrameAndViewForPrint is created to fulfill the |
207 // request and is filled into the |prepare| argument. | 214 // request and is filled into the |prepare| argument. |
208 // Used only for native printing workflow. | 215 // Used only for native printing workflow. |
209 bool InitPrintSettingsAndPrepareFrame( | 216 bool InitPrintSettingsAndPrepareFrame( |
210 WebKit::WebFrame* frame, | 217 WebKit::WebFrame* frame, |
211 const WebKit::WebNode& node, | 218 const WebKit::WebNode& node, |
212 scoped_ptr<PrepareFrameAndViewForPrint>* prepare); | 219 scoped_ptr<PrepareFrameAndViewForPrint>* prepare); |
213 | 220 |
(...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
358 int user_cancelled_scripted_print_count_; | 365 int user_cancelled_scripted_print_count_; |
359 bool is_scripted_printing_blocked_; | 366 bool is_scripted_printing_blocked_; |
360 | 367 |
361 // Let the browser process know of a printing failure. Only set to false when | 368 // Let the browser process know of a printing failure. Only set to false when |
362 // the failure came from the browser in the first place. | 369 // the failure came from the browser in the first place. |
363 bool notify_browser_of_print_failure_; | 370 bool notify_browser_of_print_failure_; |
364 | 371 |
365 // True, when printing from print preview. | 372 // True, when printing from print preview. |
366 bool print_for_preview_; | 373 bool print_for_preview_; |
367 | 374 |
375 // Specifies the print scaling option for the current workflow. | |
376 WebKit::WebPrintScalingOption print_scaling_option_; | |
377 | |
368 scoped_ptr<PrintMsg_PrintPages_Params> old_print_pages_params_; | 378 scoped_ptr<PrintMsg_PrintPages_Params> old_print_pages_params_; |
369 | 379 |
370 // Strings generated by the browser process to be printed as headers and | 380 // Strings generated by the browser process to be printed as headers and |
371 // footers if requested by the user. | 381 // footers if requested by the user. |
372 scoped_ptr<base::DictionaryValue> header_footer_info_; | 382 scoped_ptr<base::DictionaryValue> header_footer_info_; |
373 | 383 |
374 // Keeps track of the state of print preview between messages. | 384 // Keeps track of the state of print preview between messages. |
375 class PrintPreviewContext { | 385 class PrintPreviewContext { |
376 public: | 386 public: |
377 PrintPreviewContext(); | 387 PrintPreviewContext(); |
378 ~PrintPreviewContext(); | 388 ~PrintPreviewContext(); |
379 | 389 |
380 // Initializes the print preview context. Need to be called to set | 390 // Initializes the print preview context. Need to be called to set |
381 // the |web_frame| / |web_node| to generate the print preview for. | 391 // the |web_frame| / |web_node| to generate the print preview for. |
382 void InitWithFrame(WebKit::WebFrame* web_frame); | 392 void InitWithFrame(WebKit::WebFrame* web_frame); |
383 void InitWithNode(const WebKit::WebNode& web_node); | 393 void InitWithNode(const WebKit::WebNode& web_node); |
384 | 394 |
385 // Does bookkeeping at the beginning of print preview. | 395 // Does bookkeeping at the beginning of print preview. |
386 void OnPrintPreview(); | 396 void OnPrintPreview(); |
387 | 397 |
388 // Create the print preview document. |pages| is empty to print all pages. | 398 // Create the print preview document. |pages| is empty to print all pages. |
389 bool CreatePreviewDocument(PrintMsg_Print_Params* params, | 399 bool CreatePreviewDocument(PrintMsg_Print_Params* params, |
390 const std::vector<int>& pages, | 400 const std::vector<int>& pages, |
391 bool ignore_css_margins); | 401 bool ignore_css_margins, |
402 WebKit::WebPrintScalingOption scaling_option); | |
392 | 403 |
393 // Called after a page gets rendered. |page_time| is how long the | 404 // Called after a page gets rendered. |page_time| is how long the |
394 // rendering took. | 405 // rendering took. |
395 void RenderedPreviewPage(const base::TimeDelta& page_time); | 406 void RenderedPreviewPage(const base::TimeDelta& page_time); |
396 | 407 |
397 // Updates the print preview context when the required pages are rendered. | 408 // Updates the print preview context when the required pages are rendered. |
398 void AllPagesRendered(); | 409 void AllPagesRendered(); |
399 | 410 |
400 // Finalizes the print ready preview document. | 411 // Finalizes the print ready preview document. |
401 void FinalizePrintReadyDocument(); | 412 void FinalizePrintReadyDocument(); |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
467 enum PrintPreviewErrorBuckets error_; | 478 enum PrintPreviewErrorBuckets error_; |
468 | 479 |
469 State state_; | 480 State state_; |
470 }; | 481 }; |
471 | 482 |
472 PrintPreviewContext print_preview_context_; | 483 PrintPreviewContext print_preview_context_; |
473 DISALLOW_COPY_AND_ASSIGN(PrintWebViewHelper); | 484 DISALLOW_COPY_AND_ASSIGN(PrintWebViewHelper); |
474 }; | 485 }; |
475 | 486 |
476 #endif // CHROME_RENDERER_PRINT_WEB_VIEW_HELPER_H_ | 487 #endif // CHROME_RENDERER_PRINT_WEB_VIEW_HELPER_H_ |
OLD | NEW |