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 |
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
110 virtual void PrintPage(WebKit::WebFrame* frame) OVERRIDE; | 110 virtual void PrintPage(WebKit::WebFrame* frame) OVERRIDE; |
111 | 111 |
112 // Message handlers --------------------------------------------------------- | 112 // Message handlers --------------------------------------------------------- |
113 | 113 |
114 // Print the document. | 114 // Print the document. |
115 void OnPrintPages(); | 115 void OnPrintPages(); |
116 | 116 |
117 // Print the document with the print preview frame/node. | 117 // Print the document with the print preview frame/node. |
118 void OnPrintForSystemDialog(); | 118 void OnPrintForSystemDialog(); |
119 | 119 |
120 // Get |page_size| and |content_area| information from | |
121 // |page_layout_in_points|. | |
122 void GetPageSizeAndContentAreaFromPageLayout( | |
123 const printing::PageSizeMargins& page_layout_in_points, | |
124 gfx::Size* page_size, | |
125 gfx::Rect* content_area); | |
126 | |
127 // Update |ignore_css_margins_| based on settings. | |
128 void UpdateFrameMarginsCssInfo(const base::DictionaryValue& settings); | |
129 | |
130 // Returns true if the current destination printer is PRINT_TO_PDF. | |
131 bool IsPrintToPdfRequested(const base::DictionaryValue& settings); | |
132 | |
120 // Initiate print preview. | 133 // Initiate print preview. |
121 void OnInitiatePrintPreview(); | 134 void OnInitiatePrintPreview(); |
122 | 135 |
123 // Start the process of generating a print preview using |settings|. | 136 // Start the process of generating a print preview using |settings|. |
124 void OnPrintPreview(const base::DictionaryValue& settings); | 137 void OnPrintPreview(const base::DictionaryValue& settings); |
125 | 138 |
126 // Initialize the print preview document. | 139 // Initialize the print preview document. |
127 bool CreatePreviewDocument(); | 140 bool CreatePreviewDocument(); |
128 | 141 |
129 // Renders a print preview page. |page_number| is 0-based. | 142 // Renders a print preview page. |page_number| is 0-based. |
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
208 // Render the frame for printing. | 221 // Render the frame for printing. |
209 bool RenderPagesForPrint(WebKit::WebFrame* frame, | 222 bool RenderPagesForPrint(WebKit::WebFrame* frame, |
210 const WebKit::WebNode& node); | 223 const WebKit::WebNode& node); |
211 | 224 |
212 // Platform specific helper function for rendering page(s) to |metafile|. | 225 // Platform specific helper function for rendering page(s) to |metafile|. |
213 #if defined(OS_WIN) | 226 #if defined(OS_WIN) |
214 // Because of mixed support for alpha channels on printers, this method may | 227 // Because of mixed support for alpha channels on printers, this method may |
215 // need to create a new metafile. The result may be either the passed | 228 // need to create a new metafile. The result may be either the passed |
216 // |metafile| or a new one. In either case, the caller owns both |metafile| | 229 // |metafile| or a new one. In either case, the caller owns both |metafile| |
217 // and the result. | 230 // and the result. |
218 printing::Metafile* RenderPage(const PrintMsg_Print_Params& params, | 231 printing::Metafile* RenderPage(const PrintMsg_Print_Params& params, |
vandebo (ex-Chrome)
2012/01/07 00:23:19
It looks like the Win and Mac prototypes can be un
kmadhusu
2012/01/09 17:15:55
okay.
Done.
| |
219 float* scale_factor, int page_number, | 232 int page_number, bool is_preview, |
vandebo (ex-Chrome)
2012/01/07 00:23:19
match the parameter order to the Mac function (i.e
kmadhusu
2012/01/09 17:15:55
Done.
| |
220 bool is_preview, WebKit::WebFrame* frame, | 233 WebKit::WebFrame* frame, |
221 printing::Metafile* metafile); | 234 printing::Metafile* metafile, |
235 double* scale_factor, | |
236 gfx::Size* page_size_in_dpi, | |
237 gfx::Rect* content_area_in_dpi); | |
222 #elif defined(OS_MACOSX) | 238 #elif defined(OS_MACOSX) |
223 void RenderPage(const gfx::Size& page_size, const gfx::Rect& content_area, | 239 void RenderPage(const PrintMsg_Print_Params& params, |
224 const float& scale_factor, int page_number, | 240 int page_number, WebKit::WebFrame* frame, bool is_preview, |
225 WebKit::WebFrame* frame, bool is_preview, | 241 printing::Metafile* metafile, double* scale_factor, |
226 printing::Metafile* metafile); | 242 gfx::Size* page_size, gfx::Rect* content_rect); |
227 #elif defined(OS_POSIX) | 243 #elif defined(OS_POSIX) |
228 bool RenderPages(const PrintMsg_PrintPages_Params& params, | 244 bool RenderPages(const PrintMsg_PrintPages_Params& params, |
229 WebKit::WebFrame* frame, const WebKit::WebNode& node, | 245 WebKit::WebFrame* frame, const WebKit::WebNode& node, |
230 int* page_count, PrepareFrameAndViewForPrint* prepare, | 246 int* page_count, PrepareFrameAndViewForPrint* prepare, |
231 printing::Metafile* metafile); | 247 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 |
238 bool CopyMetafileDataToSharedMem(printing::Metafile* metafile, | 254 bool CopyMetafileDataToSharedMem(printing::Metafile* metafile, |
239 base::SharedMemoryHandle* shared_mem_handle); | 255 base::SharedMemoryHandle* shared_mem_handle); |
240 | 256 |
241 static void GetPageSizeAndMarginsInPoints( | 257 // Helper method to get page layout in points and fit to page if needed. |
258 static void ComputePageLayoutInPoints( | |
242 WebKit::WebFrame* frame, | 259 WebKit::WebFrame* frame, |
243 int page_index, | 260 int page_index, |
244 const PrintMsg_Print_Params& default_params, | 261 const PrintMsg_Print_Params& default_params, |
262 bool ignore_css_margins, | |
263 bool fit_to_page, | |
264 double* scale_factor, | |
245 printing::PageSizeMargins* page_layout_in_points); | 265 printing::PageSizeMargins* page_layout_in_points); |
246 | 266 |
247 static void UpdatePrintableSizeInPrintParameters( | 267 // Prepare the frame and view for print and then call this function to honor |
268 // the CSS page layout information. | |
269 static void UpdateFrameAndViewFromCssPageLayout( | |
248 WebKit::WebFrame* frame, | 270 WebKit::WebFrame* frame, |
249 const WebKit::WebNode& node, | 271 const WebKit::WebNode& node, |
250 PrepareFrameAndViewForPrint* prepare, | 272 PrepareFrameAndViewForPrint* prepare, |
251 PrintMsg_Print_Params* params); | 273 const PrintMsg_Print_Params& params, |
274 bool ignore_css_margins, | |
275 bool fit_to_page); | |
252 | 276 |
253 // Given the |device| and |canvas| to draw on, prints the appropriate headers | 277 // Given the |device| and |canvas| to draw on, prints the appropriate headers |
254 // and footers using strings from |header_footer_info| on to the canvas. | 278 // and footers using strings from |header_footer_info| on to the canvas. |
255 static void PrintHeaderAndFooter( | 279 static void PrintHeaderAndFooter( |
256 WebKit::WebCanvas* canvas, | 280 WebKit::WebCanvas* canvas, |
257 int page_number, | 281 int page_number, |
258 int total_pages, | 282 int total_pages, |
259 float webkit_scale_factor, | 283 float webkit_scale_factor, |
260 const printing::PageSizeMargins& page_layout_in_points, | 284 const printing::PageSizeMargins& page_layout_in_points, |
261 const base::DictionaryValue& header_footer_info); | 285 const base::DictionaryValue& header_footer_info); |
(...skipping 30 matching lines...) Expand all Loading... | |
292 // For a valid |page_number| with modifiable content, | 316 // For a valid |page_number| with modifiable content, |
293 // |metafile| is the rendered page. Otherwise |metafile| is NULL. | 317 // |metafile| is the rendered page. Otherwise |metafile| is NULL. |
294 // Returns true if print preview should continue, false on failure. | 318 // Returns true if print preview should continue, false on failure. |
295 bool PreviewPageRendered(int page_number, printing::Metafile* metafile); | 319 bool PreviewPageRendered(int page_number, printing::Metafile* metafile); |
296 | 320 |
297 WebKit::WebView* print_web_view_; | 321 WebKit::WebView* print_web_view_; |
298 | 322 |
299 scoped_ptr<PrintMsg_PrintPages_Params> print_pages_params_; | 323 scoped_ptr<PrintMsg_PrintPages_Params> print_pages_params_; |
300 bool is_preview_enabled_; | 324 bool is_preview_enabled_; |
301 bool is_print_ready_metafile_sent_; | 325 bool is_print_ready_metafile_sent_; |
326 bool ignore_css_margins_; | |
327 | |
328 // True if we need to auto fit to page else false. | |
329 // NOTE: When we print to pdf, we don't fit to page. | |
330 bool fit_to_page_; | |
302 | 331 |
303 // Used for scripted initiated printing blocking. | 332 // Used for scripted initiated printing blocking. |
304 base::Time last_cancelled_script_print_; | 333 base::Time last_cancelled_script_print_; |
305 int user_cancelled_scripted_print_count_; | 334 int user_cancelled_scripted_print_count_; |
306 | 335 |
307 // Let the browser process know of a printing failure. Only set to false when | 336 // Let the browser process know of a printing failure. Only set to false when |
308 // the failure came from the browser in the first place. | 337 // the failure came from the browser in the first place. |
309 bool notify_browser_of_print_failure_; | 338 bool notify_browser_of_print_failure_; |
310 | 339 |
311 scoped_ptr<PrintMsg_PrintPages_Params> old_print_pages_params_; | 340 scoped_ptr<PrintMsg_PrintPages_Params> old_print_pages_params_; |
(...skipping 24 matching lines...) Expand all Loading... | |
336 // Initializes the print preview context. Need to be called to set | 365 // Initializes the print preview context. Need to be called to set |
337 // the |web_frame| / |web_node| to generate the print preview for. | 366 // the |web_frame| / |web_node| to generate the print preview for. |
338 void InitWithFrame(WebKit::WebFrame* web_frame); | 367 void InitWithFrame(WebKit::WebFrame* web_frame); |
339 void InitWithNode(const WebKit::WebNode& web_node); | 368 void InitWithNode(const WebKit::WebNode& web_node); |
340 | 369 |
341 // Does bookkeeping at the beginning of print preview. | 370 // Does bookkeeping at the beginning of print preview. |
342 void OnPrintPreview(); | 371 void OnPrintPreview(); |
343 | 372 |
344 // Create the print preview document. |pages| is empty to print all pages. | 373 // Create the print preview document. |pages| is empty to print all pages. |
345 bool CreatePreviewDocument(PrintMsg_Print_Params* params, | 374 bool CreatePreviewDocument(PrintMsg_Print_Params* params, |
346 const std::vector<int>& pages); | 375 const std::vector<int>& pages, |
376 bool ignore_css_margins, | |
377 bool fit_to_page); | |
347 | 378 |
348 // Called after a page gets rendered. |page_time| is how long the | 379 // Called after a page gets rendered. |page_time| is how long the |
349 // rendering took. | 380 // rendering took. |
350 void RenderedPreviewPage(const base::TimeDelta& page_time); | 381 void RenderedPreviewPage(const base::TimeDelta& page_time); |
351 | 382 |
352 // Updates the print preview context when the required pages are rendered. | 383 // Updates the print preview context when the required pages are rendered. |
353 void AllPagesRendered(); | 384 void AllPagesRendered(); |
354 | 385 |
355 // Finalizes the print ready preview document. | 386 // Finalizes the print ready preview document. |
356 void FinalizePrintReadyDocument(); | 387 void FinalizePrintReadyDocument(); |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
423 | 454 |
424 State state_; | 455 State state_; |
425 }; | 456 }; |
426 | 457 |
427 PrintPreviewContext print_preview_context_; | 458 PrintPreviewContext print_preview_context_; |
428 | 459 |
429 DISALLOW_COPY_AND_ASSIGN(PrintWebViewHelper); | 460 DISALLOW_COPY_AND_ASSIGN(PrintWebViewHelper); |
430 }; | 461 }; |
431 | 462 |
432 #endif // CHROME_RENDERER_PRINT_WEB_VIEW_HELPER_H_ | 463 #endif // CHROME_RENDERER_PRINT_WEB_VIEW_HELPER_H_ |
OLD | NEW |