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

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: style changes as per demetrios 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 "base/values.h"
14 #include "content/renderer/render_view_observer.h" 15 #include "content/renderer/render_view_observer.h"
15 #include "content/renderer/render_view_observer_tracker.h" 16 #include "content/renderer/render_view_observer_tracker.h"
16 #include "printing/metafile.h" 17 #include "printing/metafile.h"
18 #include "skia/ext/vector_canvas.h"
vandebo (ex-Chrome) 2011/07/22 22:58:33 Don't include heads for things you only use as poi
Aayush Kumar 2011/07/24 02:09:02 Done.
19 #include "skia/ext/vector_platform_device_skia.h"
20 #include "third_party/skia/include/core/SkRefCnt.h"
17 #include "third_party/WebKit/Source/WebKit/chromium/public/WebFrameClient.h" 21 #include "third_party/WebKit/Source/WebKit/chromium/public/WebFrameClient.h"
18 #include "third_party/WebKit/Source/WebKit/chromium/public/WebViewClient.h" 22 #include "third_party/WebKit/Source/WebKit/chromium/public/WebViewClient.h"
19 #include "ui/gfx/size.h" 23 #include "ui/gfx/size.h"
20 24
21 struct PrintMsg_Print_Params; 25 struct PrintMsg_Print_Params;
22 struct PrintMsg_PrintPage_Params; 26 struct PrintMsg_PrintPage_Params;
23 struct PrintMsg_PrintPages_Params; 27 struct PrintMsg_PrintPages_Params;
24 28
25 namespace base { 29 namespace base {
26 class DictionaryValue; 30 class DictionaryValue;
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
59 gfx::Size print_canvas_size_; 63 gfx::Size print_canvas_size_;
60 gfx::Size prev_view_size_; 64 gfx::Size prev_view_size_;
61 gfx::Size prev_scroll_offset_; 65 gfx::Size prev_scroll_offset_;
62 int expected_pages_count_; 66 int expected_pages_count_;
63 bool use_browser_overlays_; 67 bool use_browser_overlays_;
64 bool finished_; 68 bool finished_;
65 69
66 DISALLOW_COPY_AND_ASSIGN(PrepareFrameAndViewForPrint); 70 DISALLOW_COPY_AND_ASSIGN(PrepareFrameAndViewForPrint);
67 }; 71 };
68 72
73 // Struct that holds margin and content area information of a page.
74 typedef struct PageSizeMargins {
75 double content_width;
76 double content_height;
77 double margin_top;
78 double margin_right;
79 double margin_bottom;
80 double margin_left;
81 } PageSizeMargins;
82
83 // Given the |device| and |canvas| to draw on, prints the appropriate headers
84 // and footers using strings from |header_footer_info| on to the canvas.
85 void PrintHeaderAndFooter(skia::VectorPlatformDeviceSkia* device,
86 const SkRefPtr<skia::VectorCanvas>& canvas,
87 int page_number, int total_pages,
88 float webkit_scale_factor,
89 PageSizeMargins& page_size_margins,
90 const DictionaryValue* header_footer_info);
91
69 // PrintWebViewHelper handles most of the printing grunt work for RenderView. 92 // PrintWebViewHelper handles most of the printing grunt work for RenderView.
70 // We plan on making print asynchronous and that will require copying the DOM 93 // We plan on making print asynchronous and that will require copying the DOM
71 // of the document and creating a new WebView with the contents. 94 // of the document and creating a new WebView with the contents.
72 class PrintWebViewHelper : public RenderViewObserver, 95 class PrintWebViewHelper : public RenderViewObserver,
73 public RenderViewObserverTracker<PrintWebViewHelper>, 96 public RenderViewObserverTracker<PrintWebViewHelper>,
74 public WebKit::WebViewClient, 97 public WebKit::WebViewClient,
75 public WebKit::WebFrameClient { 98 public WebKit::WebFrameClient {
76 public: 99 public:
77 explicit PrintWebViewHelper(RenderView* render_view); 100 explicit PrintWebViewHelper(RenderView* render_view);
78 virtual ~PrintWebViewHelper(); 101 virtual ~PrintWebViewHelper();
(...skipping 24 matching lines...) Expand all
103 126
104 // Message handlers --------------------------------------------------------- 127 // Message handlers ---------------------------------------------------------
105 128
106 // Print the document. 129 // Print the document.
107 void OnPrintPages(); 130 void OnPrintPages();
108 131
109 // Initiate print preview. 132 // Initiate print preview.
110 void OnInitiatePrintPreview(); 133 void OnInitiatePrintPreview();
111 134
112 // Start the process of generating a print preview using |settings|. 135 // Start the process of generating a print preview using |settings|.
113 void OnPrintPreview(const base::DictionaryValue& settings); 136 // |header_footer_info| contains the necessary strings generated by the
137 // browser process to be printed as headers and footers if requested by the
138 // user.
139 void OnPrintPreview(const base::DictionaryValue& settings,
140 const DictionaryValue& header_footer_info);
114 // Initialize the print preview document. 141 // Initialize the print preview document.
115 bool CreatePreviewDocument(); 142 bool CreatePreviewDocument();
116 143
117 // Continue generating the print preview. 144 // Continue generating the print preview.
118 void OnContinuePreview(); 145 void OnContinuePreview();
119 // Renders a print preview page. |page_number| is 0-based. 146 // Renders a print preview page. |page_number| is 0-based.
120 void RenderPreviewPage(int page_number); 147 void RenderPreviewPage(int page_number);
121 // Finalize the print preview document. 148 // Finalize the print preview document.
122 bool FinalizePreviewDocument(); 149 bool FinalizePreviewDocument();
123 150
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
181 // It will implicitly revert the document to display CSS media type. 208 // It will implicitly revert the document to display CSS media type.
182 bool PrintPages(const PrintMsg_PrintPages_Params& params, 209 bool PrintPages(const PrintMsg_PrintPages_Params& params,
183 WebKit::WebFrame* frame, 210 WebKit::WebFrame* frame,
184 WebKit::WebNode* node); 211 WebKit::WebNode* node);
185 212
186 // Prints the page listed in |params|. 213 // Prints the page listed in |params|.
187 #if defined(USE_X11) 214 #if defined(USE_X11)
188 void PrintPageInternal(const PrintMsg_PrintPage_Params& params, 215 void PrintPageInternal(const PrintMsg_PrintPage_Params& params,
189 const gfx::Size& canvas_size, 216 const gfx::Size& canvas_size,
190 WebKit::WebFrame* frame, 217 WebKit::WebFrame* frame,
191 printing::Metafile* metafile); 218 printing::Metafile* metafile,
219 bool is_preview);
192 #else 220 #else
193 void PrintPageInternal(const PrintMsg_PrintPage_Params& params, 221 void PrintPageInternal(const PrintMsg_PrintPage_Params& params,
194 const gfx::Size& canvas_size, 222 const gfx::Size& canvas_size,
195 WebKit::WebFrame* frame); 223 WebKit::WebFrame* frame);
196 #endif 224 #endif
197 225
198 // Render the frame for printing. 226 // Render the frame for printing.
199 bool RenderPagesForPrint(WebKit::WebFrame* frame, WebKit::WebNode* node); 227 bool RenderPagesForPrint(WebKit::WebFrame* frame, WebKit::WebNode* node);
200 228
201 // Platform specific helper function for rendering page(s) to |metafile|. 229 // Platform specific helper function for rendering page(s) to |metafile|.
202 #if defined(OS_WIN) 230 #if defined(OS_WIN)
203 void RenderPage(const PrintMsg_Print_Params& params, float* scale_factor, 231 void RenderPage(const PrintMsg_Print_Params& params, float* scale_factor,
204 int page_number, bool is_preview, WebKit::WebFrame* frame, 232 int page_number, bool is_preview, WebKit::WebFrame* frame,
205 scoped_ptr<printing::Metafile>* metafile); 233 scoped_ptr<printing::Metafile>* metafile);
206 #elif defined(OS_MACOSX) 234 #elif defined(OS_MACOSX)
207 void RenderPage(const gfx::Size& page_size, const gfx::Rect& content_area, 235 void RenderPage(const gfx::Size& page_size, const gfx::Rect& content_area,
208 const float& scale_factor, int page_number, 236 const float& scale_factor, int page_number,
209 WebKit::WebFrame* frame, printing::Metafile* metafile); 237 WebKit::WebFrame* frame, printing::Metafile* metafile,
238 bool is_preview, bool display_header_footer);
210 #elif defined(OS_POSIX) 239 #elif defined(OS_POSIX)
211 bool RenderPages(const PrintMsg_PrintPages_Params& params, 240 bool RenderPages(const PrintMsg_PrintPages_Params& params,
212 WebKit::WebFrame* frame, WebKit::WebNode* node, 241 WebKit::WebFrame* frame, WebKit::WebNode* node,
213 int* page_count, printing::Metafile* metafile); 242 int* page_count, printing::Metafile* metafile);
214 #endif // defined(OS_WIN) 243 #endif // defined(OS_WIN)
215 244
216 // Helper methods ----------------------------------------------------------- 245 // Helper methods -----------------------------------------------------------
217 246
218 bool CopyAndPrint(WebKit::WebFrame* web_frame); 247 bool CopyAndPrint(WebKit::WebFrame* web_frame);
219 248
220 bool CopyMetafileDataToSharedMem(printing::Metafile* metafile, 249 bool CopyMetafileDataToSharedMem(printing::Metafile* metafile,
221 base::SharedMemoryHandle* shared_mem_handle); 250 base::SharedMemoryHandle* shared_mem_handle);
222 251
223 void GetPageSizeAndMarginsInPoints( 252 PageSizeMargins GetPageSizeAndMarginsInPoints(
224 WebKit::WebFrame* frame, 253 WebKit::WebFrame* frame,
225 int page_index, 254 int page_index,
226 const PrintMsg_Print_Params& default_params, 255 const PrintMsg_Print_Params& default_params);
227 double* content_width_in_points,
228 double* content_height_in_points,
229 double* margin_top_in_points,
230 double* margin_right_in_points,
231 double* margin_bottom_in_points,
232 double* margin_left_in_points);
233 256
234 void UpdatePrintableSizeInPrintParameters(WebKit::WebFrame* frame, 257 void UpdatePrintableSizeInPrintParameters(WebKit::WebFrame* frame,
235 WebKit::WebNode* node, 258 WebKit::WebNode* node,
236 PrintMsg_Print_Params* params); 259 PrintMsg_Print_Params* params);
237 260
238 bool GetPrintFrame(WebKit::WebFrame** frame); 261 bool GetPrintFrame(WebKit::WebFrame** frame);
239 262
240 // This reports the current time - |start_time| as the time to render a page. 263 // This reports the current time - |start_time| as the time to render a page.
241 void ReportPreviewPageRenderTime(base::TimeTicks start_time); 264 void ReportPreviewPageRenderTime(base::TimeTicks start_time);
242 265
(...skipping 27 matching lines...) Expand all
270 // Used for scripted initiated printing blocking. 293 // Used for scripted initiated printing blocking.
271 base::Time last_cancelled_script_print_; 294 base::Time last_cancelled_script_print_;
272 int user_cancelled_scripted_print_count_; 295 int user_cancelled_scripted_print_count_;
273 296
274 // Let the browser process know of a printing failure. Only set to false when 297 // Let the browser process know of a printing failure. Only set to false when
275 // the failure came from the browser in the first place. 298 // the failure came from the browser in the first place.
276 bool notify_browser_of_print_failure_; 299 bool notify_browser_of_print_failure_;
277 300
278 scoped_ptr<PrintMsg_PrintPages_Params> old_print_pages_params_; 301 scoped_ptr<PrintMsg_PrintPages_Params> old_print_pages_params_;
279 302
303 // Contains strings generated by the browser process to be printed as headers
304 // and footers if requested by the user.
305 const DictionaryValue* header_footer_info_;
306
280 // Keeps track of the state of print preview between messages. 307 // Keeps track of the state of print preview between messages.
281 class PrintPreviewContext { 308 class PrintPreviewContext {
282 public: 309 public:
283 PrintPreviewContext(); 310 PrintPreviewContext();
284 ~PrintPreviewContext(); 311 ~PrintPreviewContext();
285 312
286 // Initializes the print preview context. Need to be called to set 313 // Initializes the print preview context. Need to be called to set
287 // the |web_frame| / |web_node| to generate the print preview for. 314 // the |web_frame| / |web_node| to generate the print preview for.
288 void InitWithFrame(WebKit::WebFrame* web_frame); 315 void InitWithFrame(WebKit::WebFrame* web_frame);
289 void InitWithNode(const WebKit::WebNode& web_node); 316 void InitWithNode(const WebKit::WebNode& web_node);
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
358 385
359 State state_; 386 State state_;
360 }; 387 };
361 388
362 PrintPreviewContext print_preview_context_; 389 PrintPreviewContext print_preview_context_;
363 390
364 DISALLOW_COPY_AND_ASSIGN(PrintWebViewHelper); 391 DISALLOW_COPY_AND_ASSIGN(PrintWebViewHelper);
365 }; 392 };
366 393
367 #endif // CHROME_RENDERER_PRINT_WEB_VIEW_HELPER_H_ 394 #endif // CHROME_RENDERER_PRINT_WEB_VIEW_HELPER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698