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 #if defined(USE_SKIA) | |
| 29 namespace skia { | |
| 30 class VectorCanvas; | |
| 31 } | |
| 32 #endif | |
| 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 #if defined(USE_SKIA) | |
| 87 void PrintHeaderAndFooter(SkDevice* device, | |
|
kmadhusu
2011/07/26 20:27:50
As per style guide, completely global functions sh
Aayush Kumar
2011/07/28 17:28:41
Done.
| |
| 88 skia::VectorCanvas& canvas, | |
| 89 int page_number, | |
| 90 int total_pages, | |
| 91 float webkit_scale_factor, | |
| 92 const PageSizeMargins& page_layout_in_points, | |
| 93 const base::DictionaryValue* header_footer_info); | |
| 94 #endif // USE_SKIA | |
| 95 | |
| 79 // PrintWebViewHelper handles most of the printing grunt work for RenderView. | 96 // PrintWebViewHelper handles most of the printing grunt work for RenderView. |
| 80 // We plan on making print asynchronous and that will require copying the DOM | 97 // 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. | 98 // of the document and creating a new WebView with the contents. |
| 82 class PrintWebViewHelper : public RenderViewObserver, | 99 class PrintWebViewHelper : public RenderViewObserver, |
| 83 public RenderViewObserverTracker<PrintWebViewHelper>, | 100 public RenderViewObserverTracker<PrintWebViewHelper>, |
| 84 public WebKit::WebViewClient, | 101 public WebKit::WebViewClient, |
| 85 public WebKit::WebFrameClient { | 102 public WebKit::WebFrameClient { |
| 86 public: | 103 public: |
| 87 explicit PrintWebViewHelper(RenderView* render_view); | 104 explicit PrintWebViewHelper(RenderView* render_view); |
| 88 virtual ~PrintWebViewHelper(); | 105 virtual ~PrintWebViewHelper(); |
| (...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 189 // It will implicitly revert the document to display CSS media type. | 206 // It will implicitly revert the document to display CSS media type. |
| 190 bool PrintPages(const PrintMsg_PrintPages_Params& params, | 207 bool PrintPages(const PrintMsg_PrintPages_Params& params, |
| 191 WebKit::WebFrame* frame, | 208 WebKit::WebFrame* frame, |
| 192 WebKit::WebNode* node); | 209 WebKit::WebNode* node); |
| 193 | 210 |
| 194 // Prints the page listed in |params|. | 211 // Prints the page listed in |params|. |
| 195 #if defined(USE_X11) | 212 #if defined(USE_X11) |
| 196 void PrintPageInternal(const PrintMsg_PrintPage_Params& params, | 213 void PrintPageInternal(const PrintMsg_PrintPage_Params& params, |
| 197 const gfx::Size& canvas_size, | 214 const gfx::Size& canvas_size, |
| 198 WebKit::WebFrame* frame, | 215 WebKit::WebFrame* frame, |
| 216 bool is_preview, | |
| 199 printing::Metafile* metafile); | 217 printing::Metafile* metafile); |
| 200 #else | 218 #else |
| 201 void PrintPageInternal(const PrintMsg_PrintPage_Params& params, | 219 void PrintPageInternal(const PrintMsg_PrintPage_Params& params, |
| 202 const gfx::Size& canvas_size, | 220 const gfx::Size& canvas_size, |
| 203 WebKit::WebFrame* frame); | 221 WebKit::WebFrame* frame); |
| 204 #endif | 222 #endif |
| 205 | 223 |
| 206 // Render the frame for printing. | 224 // Render the frame for printing. |
| 207 bool RenderPagesForPrint(WebKit::WebFrame* frame, WebKit::WebNode* node); | 225 bool RenderPagesForPrint(WebKit::WebFrame* frame, WebKit::WebNode* node); |
| 208 | 226 |
| 209 // Platform specific helper function for rendering page(s) to |metafile|. | 227 // Platform specific helper function for rendering page(s) to |metafile|. |
| 210 #if defined(OS_WIN) | 228 #if defined(OS_WIN) |
| 211 void RenderPage(const PrintMsg_Print_Params& params, float* scale_factor, | 229 void RenderPage(const PrintMsg_Print_Params& params, float* scale_factor, |
| 212 int page_number, bool is_preview, WebKit::WebFrame* frame, | 230 int page_number, bool is_preview, WebKit::WebFrame* frame, |
| 213 scoped_ptr<printing::Metafile>* metafile); | 231 scoped_ptr<printing::Metafile>* metafile); |
| 214 #elif defined(OS_MACOSX) | 232 #elif defined(OS_MACOSX) |
| 215 void RenderPage(const gfx::Size& page_size, const gfx::Rect& content_area, | 233 void RenderPage(const gfx::Size& page_size, const gfx::Rect& content_area, |
| 216 const float& scale_factor, int page_number, | 234 const float& scale_factor, int page_number, |
| 217 WebKit::WebFrame* frame, printing::Metafile* metafile); | 235 WebKit::WebFrame* frame, bool is_preview, |
| 236 printing::Metafile* metafile); | |
| 218 #elif defined(OS_POSIX) | 237 #elif defined(OS_POSIX) |
| 219 bool RenderPages(const PrintMsg_PrintPages_Params& params, | 238 bool RenderPages(const PrintMsg_PrintPages_Params& params, |
| 220 WebKit::WebFrame* frame, WebKit::WebNode* node, | 239 WebKit::WebFrame* frame, WebKit::WebNode* node, |
| 221 int* page_count, printing::Metafile* metafile); | 240 int* page_count, printing::Metafile* metafile); |
| 222 #endif // defined(OS_WIN) | 241 #endif // defined(OS_WIN) |
| 223 | 242 |
| 224 // Helper methods ----------------------------------------------------------- | 243 // Helper methods ----------------------------------------------------------- |
| 225 | 244 |
| 226 bool CopyAndPrint(WebKit::WebFrame* web_frame); | 245 bool CopyAndPrint(WebKit::WebFrame* web_frame); |
| 227 | 246 |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 273 // Used for scripted initiated printing blocking. | 292 // Used for scripted initiated printing blocking. |
| 274 base::Time last_cancelled_script_print_; | 293 base::Time last_cancelled_script_print_; |
| 275 int user_cancelled_scripted_print_count_; | 294 int user_cancelled_scripted_print_count_; |
| 276 | 295 |
| 277 // Let the browser process know of a printing failure. Only set to false when | 296 // Let the browser process know of a printing failure. Only set to false when |
| 278 // the failure came from the browser in the first place. | 297 // the failure came from the browser in the first place. |
| 279 bool notify_browser_of_print_failure_; | 298 bool notify_browser_of_print_failure_; |
| 280 | 299 |
| 281 scoped_ptr<PrintMsg_PrintPages_Params> old_print_pages_params_; | 300 scoped_ptr<PrintMsg_PrintPages_Params> old_print_pages_params_; |
| 282 | 301 |
| 302 // Contains strings generated by the browser process to be printed as headers | |
| 303 // and footers if requested by the user. | |
| 304 scoped_ptr<base::DictionaryValue> header_footer_info_; | |
| 305 | |
| 283 // Keeps track of the state of print preview between messages. | 306 // Keeps track of the state of print preview between messages. |
| 284 class PrintPreviewContext { | 307 class PrintPreviewContext { |
| 285 public: | 308 public: |
| 286 PrintPreviewContext(); | 309 PrintPreviewContext(); |
| 287 ~PrintPreviewContext(); | 310 ~PrintPreviewContext(); |
| 288 | 311 |
| 289 // Initializes the print preview context. Need to be called to set | 312 // Initializes the print preview context. Need to be called to set |
| 290 // the |web_frame| / |web_node| to generate the print preview for. | 313 // the |web_frame| / |web_node| to generate the print preview for. |
| 291 void InitWithFrame(WebKit::WebFrame* web_frame); | 314 void InitWithFrame(WebKit::WebFrame* web_frame); |
| 292 void InitWithNode(const WebKit::WebNode& web_node); | 315 void InitWithNode(const WebKit::WebNode& web_node); |
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 361 | 384 |
| 362 State state_; | 385 State state_; |
| 363 }; | 386 }; |
| 364 | 387 |
| 365 PrintPreviewContext print_preview_context_; | 388 PrintPreviewContext print_preview_context_; |
| 366 | 389 |
| 367 DISALLOW_COPY_AND_ASSIGN(PrintWebViewHelper); | 390 DISALLOW_COPY_AND_ASSIGN(PrintWebViewHelper); |
| 368 }; | 391 }; |
| 369 | 392 |
| 370 #endif // CHROME_RENDERER_PRINT_WEB_VIEW_HELPER_H_ | 393 #endif // CHROME_RENDERER_PRINT_WEB_VIEW_HELPER_H_ |
| OLD | NEW |