Chromium Code Reviews| 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, | |
|
Chris Guillory
2011/07/26 00:10:45
Optional: PrintHeaderAndFooterForPage?
Aayush Kumar
2011/07/26 01:55:41
I feel that the function name becomes really long,
| |
| 87 const SkRefPtr<skia::VectorCanvas>& canvas, | |
|
Chris Guillory
2011/07/26 00:10:45
Can we remove the SkRefPtr usage here.
Aayush Kumar
2011/07/26 01:55:41
Done.
| |
| 88 int page_number, int total_pages, | |
|
Chris Guillory
2011/07/26 00:10:45
Can you place these arguments on separate lines.
Aayush Kumar
2011/07/26 01:55:41
Done.
| |
| 89 float webkit_scale_factor, | |
| 90 PageSizeMargins& page_layout_in_points, | |
|
Chris Guillory
2011/07/26 00:10:45
Can this be const.
Aayush Kumar
2011/07/26 01:55:41
Done.
| |
| 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 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 199 // It will implicitly revert the document to display CSS media type. | 213 // It will implicitly revert the document to display CSS media type. |
| 200 bool PrintPages(const PrintMsg_PrintPages_Params& params, | 214 bool PrintPages(const PrintMsg_PrintPages_Params& params, |
| 201 WebKit::WebFrame* frame, | 215 WebKit::WebFrame* frame, |
| 202 WebKit::WebNode* node); | 216 WebKit::WebNode* node); |
| 203 | 217 |
| 204 // Prints the page listed in |params|. | 218 // Prints the page listed in |params|. |
| 205 #if defined(USE_X11) | 219 #if defined(USE_X11) |
| 206 void PrintPageInternal(const PrintMsg_PrintPage_Params& params, | 220 void PrintPageInternal(const PrintMsg_PrintPage_Params& params, |
| 207 const gfx::Size& canvas_size, | 221 const gfx::Size& canvas_size, |
| 208 WebKit::WebFrame* frame, | 222 WebKit::WebFrame* frame, |
| 209 printing::Metafile* metafile); | 223 printing::Metafile* metafile, |
| 224 bool is_preview); | |
| 210 #else | 225 #else |
| 211 void PrintPageInternal(const PrintMsg_PrintPage_Params& params, | 226 void PrintPageInternal(const PrintMsg_PrintPage_Params& params, |
| 212 const gfx::Size& canvas_size, | 227 const gfx::Size& canvas_size, |
| 213 WebKit::WebFrame* frame); | 228 WebKit::WebFrame* frame); |
| 214 #endif | 229 #endif |
| 215 | 230 |
| 216 // Render the frame for printing. | 231 // Render the frame for printing. |
| 217 bool RenderPagesForPrint(WebKit::WebFrame* frame, WebKit::WebNode* node); | 232 bool RenderPagesForPrint(WebKit::WebFrame* frame, WebKit::WebNode* node); |
| 218 | 233 |
| 219 // Platform specific helper function for rendering page(s) to |metafile|. | 234 // Platform specific helper function for rendering page(s) to |metafile|. |
| 220 #if defined(OS_WIN) | 235 #if defined(OS_WIN) |
| 221 void RenderPage(const PrintMsg_Print_Params& params, float* scale_factor, | 236 void RenderPage(const PrintMsg_Print_Params& params, float* scale_factor, |
| 222 int page_number, bool is_preview, WebKit::WebFrame* frame, | 237 int page_number, bool is_preview, WebKit::WebFrame* frame, |
| 223 scoped_ptr<printing::Metafile>* metafile); | 238 scoped_ptr<printing::Metafile>* metafile); |
| 224 #elif defined(OS_MACOSX) | 239 #elif defined(OS_MACOSX) |
| 225 void RenderPage(const gfx::Size& page_size, const gfx::Rect& content_area, | 240 void RenderPage(const gfx::Size& page_size, const gfx::Rect& content_area, |
| 226 const float& scale_factor, int page_number, | 241 const float& scale_factor, int page_number, |
| 227 WebKit::WebFrame* frame, printing::Metafile* metafile); | 242 WebKit::WebFrame* frame, printing::Metafile* metafile, |
| 243 bool is_preview); | |
| 228 #elif defined(OS_POSIX) | 244 #elif defined(OS_POSIX) |
| 229 bool RenderPages(const PrintMsg_PrintPages_Params& params, | 245 bool RenderPages(const PrintMsg_PrintPages_Params& params, |
| 230 WebKit::WebFrame* frame, WebKit::WebNode* node, | 246 WebKit::WebFrame* frame, WebKit::WebNode* node, |
| 231 int* page_count, printing::Metafile* metafile); | 247 int* page_count, printing::Metafile* metafile); |
| 232 #endif // defined(OS_WIN) | 248 #endif // defined(OS_WIN) |
| 233 | 249 |
| 234 // Helper methods ----------------------------------------------------------- | 250 // Helper methods ----------------------------------------------------------- |
| 235 | 251 |
| 236 bool CopyAndPrint(WebKit::WebFrame* web_frame); | 252 bool CopyAndPrint(WebKit::WebFrame* web_frame); |
| 237 | 253 |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 283 // Used for scripted initiated printing blocking. | 299 // Used for scripted initiated printing blocking. |
| 284 base::Time last_cancelled_script_print_; | 300 base::Time last_cancelled_script_print_; |
| 285 int user_cancelled_scripted_print_count_; | 301 int user_cancelled_scripted_print_count_; |
| 286 | 302 |
| 287 // Let the browser process know of a printing failure. Only set to false when | 303 // 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. | 304 // the failure came from the browser in the first place. |
| 289 bool notify_browser_of_print_failure_; | 305 bool notify_browser_of_print_failure_; |
| 290 | 306 |
| 291 scoped_ptr<PrintMsg_PrintPages_Params> old_print_pages_params_; | 307 scoped_ptr<PrintMsg_PrintPages_Params> old_print_pages_params_; |
| 292 | 308 |
| 309 // Contains strings generated by the browser process to be printed as headers | |
| 310 // and footers if requested by the user. | |
| 311 base::DictionaryValue* header_footer_info_; | |
| 312 | |
| 293 // Keeps track of the state of print preview between messages. | 313 // Keeps track of the state of print preview between messages. |
| 294 class PrintPreviewContext { | 314 class PrintPreviewContext { |
| 295 public: | 315 public: |
| 296 PrintPreviewContext(); | 316 PrintPreviewContext(); |
| 297 ~PrintPreviewContext(); | 317 ~PrintPreviewContext(); |
| 298 | 318 |
| 299 // Initializes the print preview context. Need to be called to set | 319 // Initializes the print preview context. Need to be called to set |
| 300 // the |web_frame| / |web_node| to generate the print preview for. | 320 // the |web_frame| / |web_node| to generate the print preview for. |
| 301 void InitWithFrame(WebKit::WebFrame* web_frame); | 321 void InitWithFrame(WebKit::WebFrame* web_frame); |
| 302 void InitWithNode(const WebKit::WebNode& web_node); | 322 void InitWithNode(const WebKit::WebNode& web_node); |
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 371 | 391 |
| 372 State state_; | 392 State state_; |
| 373 }; | 393 }; |
| 374 | 394 |
| 375 PrintPreviewContext print_preview_context_; | 395 PrintPreviewContext print_preview_context_; |
| 376 | 396 |
| 377 DISALLOW_COPY_AND_ASSIGN(PrintWebViewHelper); | 397 DISALLOW_COPY_AND_ASSIGN(PrintWebViewHelper); |
| 378 }; | 398 }; |
| 379 | 399 |
| 380 #endif // CHROME_RENDERER_PRINT_WEB_VIEW_HELPER_H_ | 400 #endif // CHROME_RENDERER_PRINT_WEB_VIEW_HELPER_H_ |
| OLD | NEW |