Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(100)

Side by Side Diff: chrome/renderer/print_web_view_helper.h

Issue 7348010: Added Header and Footer support using Skia (Closed) Base URL: http://git.chromium.org/git/chromium.git@trunk
Patch Set: Updated as per Chris' comments. Created 9 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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;
vandebo (ex-Chrome) 2011/07/26 06:11:37 I don't think this line is needed.
Aayush Kumar 2011/07/26 07:37:33 Done.
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
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 skia::VectorCanvas& canvas,
88 int page_number,
89 int total_pages,
90 float webkit_scale_factor,
91 const PageSizeMargins& page_layout_in_points,
92 const base::DictionaryValue* header_footer_info);
93
79 // PrintWebViewHelper handles most of the printing grunt work for RenderView. 94 // PrintWebViewHelper handles most of the printing grunt work for RenderView.
80 // We plan on making print asynchronous and that will require copying the DOM 95 // 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. 96 // of the document and creating a new WebView with the contents.
82 class PrintWebViewHelper : public RenderViewObserver, 97 class PrintWebViewHelper : public RenderViewObserver,
83 public RenderViewObserverTracker<PrintWebViewHelper>, 98 public RenderViewObserverTracker<PrintWebViewHelper>,
84 public WebKit::WebViewClient, 99 public WebKit::WebViewClient,
85 public WebKit::WebFrameClient { 100 public WebKit::WebFrameClient {
86 public: 101 public:
87 explicit PrintWebViewHelper(RenderView* render_view); 102 explicit PrintWebViewHelper(RenderView* render_view);
88 virtual ~PrintWebViewHelper(); 103 virtual ~PrintWebViewHelper();
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after
199 // It will implicitly revert the document to display CSS media type. 214 // It will implicitly revert the document to display CSS media type.
200 bool PrintPages(const PrintMsg_PrintPages_Params& params, 215 bool PrintPages(const PrintMsg_PrintPages_Params& params,
201 WebKit::WebFrame* frame, 216 WebKit::WebFrame* frame,
202 WebKit::WebNode* node); 217 WebKit::WebNode* node);
203 218
204 // Prints the page listed in |params|. 219 // Prints the page listed in |params|.
205 #if defined(USE_X11) 220 #if defined(USE_X11)
206 void PrintPageInternal(const PrintMsg_PrintPage_Params& params, 221 void PrintPageInternal(const PrintMsg_PrintPage_Params& params,
207 const gfx::Size& canvas_size, 222 const gfx::Size& canvas_size,
208 WebKit::WebFrame* frame, 223 WebKit::WebFrame* frame,
209 printing::Metafile* metafile); 224 printing::Metafile* metafile,
225 bool is_preview);
vandebo (ex-Chrome) 2011/07/26 06:11:37 metafile is an output param, so is_preview has to
Aayush Kumar 2011/07/26 07:37:33 Done.
210 #else 226 #else
211 void PrintPageInternal(const PrintMsg_PrintPage_Params& params, 227 void PrintPageInternal(const PrintMsg_PrintPage_Params& params,
212 const gfx::Size& canvas_size, 228 const gfx::Size& canvas_size,
213 WebKit::WebFrame* frame); 229 WebKit::WebFrame* frame);
214 #endif 230 #endif
215 231
216 // Render the frame for printing. 232 // Render the frame for printing.
217 bool RenderPagesForPrint(WebKit::WebFrame* frame, WebKit::WebNode* node); 233 bool RenderPagesForPrint(WebKit::WebFrame* frame, WebKit::WebNode* node);
218 234
219 // Platform specific helper function for rendering page(s) to |metafile|. 235 // Platform specific helper function for rendering page(s) to |metafile|.
220 #if defined(OS_WIN) 236 #if defined(OS_WIN)
221 void RenderPage(const PrintMsg_Print_Params& params, float* scale_factor, 237 void RenderPage(const PrintMsg_Print_Params& params, float* scale_factor,
222 int page_number, bool is_preview, WebKit::WebFrame* frame, 238 int page_number, bool is_preview, WebKit::WebFrame* frame,
223 scoped_ptr<printing::Metafile>* metafile); 239 scoped_ptr<printing::Metafile>* metafile);
224 #elif defined(OS_MACOSX) 240 #elif defined(OS_MACOSX)
225 void RenderPage(const gfx::Size& page_size, const gfx::Rect& content_area, 241 void RenderPage(const gfx::Size& page_size, const gfx::Rect& content_area,
226 const float& scale_factor, int page_number, 242 const float& scale_factor, int page_number,
227 WebKit::WebFrame* frame, printing::Metafile* metafile); 243 WebKit::WebFrame* frame, printing::Metafile* metafile,
244 bool is_preview);
228 #elif defined(OS_POSIX) 245 #elif defined(OS_POSIX)
229 bool RenderPages(const PrintMsg_PrintPages_Params& params, 246 bool RenderPages(const PrintMsg_PrintPages_Params& params,
230 WebKit::WebFrame* frame, WebKit::WebNode* node, 247 WebKit::WebFrame* frame, WebKit::WebNode* node,
231 int* page_count, printing::Metafile* metafile); 248 int* page_count, printing::Metafile* metafile);
232 #endif // defined(OS_WIN) 249 #endif // defined(OS_WIN)
233 250
234 // Helper methods ----------------------------------------------------------- 251 // Helper methods -----------------------------------------------------------
235 252
236 bool CopyAndPrint(WebKit::WebFrame* web_frame); 253 bool CopyAndPrint(WebKit::WebFrame* web_frame);
237 254
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
283 // Used for scripted initiated printing blocking. 300 // Used for scripted initiated printing blocking.
284 base::Time last_cancelled_script_print_; 301 base::Time last_cancelled_script_print_;
285 int user_cancelled_scripted_print_count_; 302 int user_cancelled_scripted_print_count_;
286 303
287 // Let the browser process know of a printing failure. Only set to false when 304 // 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. 305 // the failure came from the browser in the first place.
289 bool notify_browser_of_print_failure_; 306 bool notify_browser_of_print_failure_;
290 307
291 scoped_ptr<PrintMsg_PrintPages_Params> old_print_pages_params_; 308 scoped_ptr<PrintMsg_PrintPages_Params> old_print_pages_params_;
292 309
310 // Contains strings generated by the browser process to be printed as headers
311 // and footers if requested by the user.
312 base::DictionaryValue* header_footer_info_;
313
293 // Keeps track of the state of print preview between messages. 314 // Keeps track of the state of print preview between messages.
294 class PrintPreviewContext { 315 class PrintPreviewContext {
295 public: 316 public:
296 PrintPreviewContext(); 317 PrintPreviewContext();
297 ~PrintPreviewContext(); 318 ~PrintPreviewContext();
298 319
299 // Initializes the print preview context. Need to be called to set 320 // Initializes the print preview context. Need to be called to set
300 // the |web_frame| / |web_node| to generate the print preview for. 321 // the |web_frame| / |web_node| to generate the print preview for.
301 void InitWithFrame(WebKit::WebFrame* web_frame); 322 void InitWithFrame(WebKit::WebFrame* web_frame);
302 void InitWithNode(const WebKit::WebNode& web_node); 323 void InitWithNode(const WebKit::WebNode& web_node);
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
371 392
372 State state_; 393 State state_;
373 }; 394 };
374 395
375 PrintPreviewContext print_preview_context_; 396 PrintPreviewContext print_preview_context_;
376 397
377 DISALLOW_COPY_AND_ASSIGN(PrintWebViewHelper); 398 DISALLOW_COPY_AND_ASSIGN(PrintWebViewHelper);
378 }; 399 };
379 400
380 #endif // CHROME_RENDERER_PRINT_WEB_VIEW_HELPER_H_ 401 #endif // CHROME_RENDERER_PRINT_WEB_VIEW_HELPER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698