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 <utility> | 9 #include <utility> |
10 #include <vector> | 10 #include <vector> |
11 | 11 |
12 #include "base/memory/scoped_ptr.h" | 12 #include "base/memory/scoped_ptr.h" |
13 #include "base/shared_memory.h" | 13 #include "base/shared_memory.h" |
14 #include "base/time.h" | 14 #include "base/time.h" |
15 #include "content/renderer/render_view_observer.h" | 15 #include "content/renderer/render_view_observer.h" |
16 #include "content/renderer/render_view_observer_tracker.h" | 16 #include "content/renderer/render_view_observer_tracker.h" |
17 #include "printing/metafile.h" | 17 #include "printing/metafile.h" |
18 #include "third_party/WebKit/Source/WebKit/chromium/public/WebFrameClient.h" | 18 #include "third_party/WebKit/Source/WebKit/chromium/public/WebFrameClient.h" |
19 #include "third_party/WebKit/Source/WebKit/chromium/public/WebNode.h" | 19 #include "third_party/WebKit/Source/WebKit/chromium/public/WebNode.h" |
20 #include "third_party/WebKit/Source/WebKit/chromium/public/WebViewClient.h" | 20 #include "third_party/WebKit/Source/WebKit/chromium/public/WebViewClient.h" |
21 #include "ui/gfx/size.h" | 21 #include "ui/gfx/size.h" |
22 | 22 |
23 struct PrintMsg_Print_Params; | 23 struct PrintMsg_Print_Params; |
24 struct PrintMsg_PrintPage_Params; | 24 struct PrintMsg_PrintPage_Params; |
25 struct PrintMsg_PrintPages_Params; | 25 struct PrintMsg_PrintPages_Params; |
26 | 26 |
27 namespace base { | 27 namespace base { |
28 class DictionaryValue; | 28 class DictionaryValue; |
29 } | 29 } |
30 #if defined(USE_SKIA) | |
31 namespace skia { | |
32 class VectorCanvas; | |
33 } | |
34 #endif | |
30 | 35 |
31 // Class that calls the Begin and End print functions on the frame and changes | 36 // Class that calls the Begin and End print functions on the frame and changes |
32 // the size of the view temporarily to support full page printing.. | 37 // the size of the view temporarily to support full page printing.. |
33 // Do not serve any events in the time between construction and destruction of | 38 // Do not serve any events in the time between construction and destruction of |
34 // this class because it will cause flicker. | 39 // this class because it will cause flicker. |
35 class PrepareFrameAndViewForPrint { | 40 class PrepareFrameAndViewForPrint { |
36 public: | 41 public: |
37 // Prints |frame|. If |node| is not NULL, then only that node will be | 42 // Prints |frame|. If |node| is not NULL, then only that node will be |
38 // printed. | 43 // printed. |
39 PrepareFrameAndViewForPrint(const PrintMsg_Print_Params& print_params, | 44 PrepareFrameAndViewForPrint(const PrintMsg_Print_Params& print_params, |
(...skipping 167 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
207 bool PrintPages(const PrintMsg_PrintPages_Params& params, | 212 bool PrintPages(const PrintMsg_PrintPages_Params& params, |
208 WebKit::WebFrame* frame, | 213 WebKit::WebFrame* frame, |
209 WebKit::WebNode* node, | 214 WebKit::WebNode* node, |
210 PrepareFrameAndViewForPrint* prepare); | 215 PrepareFrameAndViewForPrint* prepare); |
211 | 216 |
212 // Prints the page listed in |params|. | 217 // Prints the page listed in |params|. |
213 #if defined(USE_X11) | 218 #if defined(USE_X11) |
214 void PrintPageInternal(const PrintMsg_PrintPage_Params& params, | 219 void PrintPageInternal(const PrintMsg_PrintPage_Params& params, |
215 const gfx::Size& canvas_size, | 220 const gfx::Size& canvas_size, |
216 WebKit::WebFrame* frame, | 221 WebKit::WebFrame* frame, |
222 bool is_preview, | |
217 printing::Metafile* metafile); | 223 printing::Metafile* metafile); |
218 #else | 224 #else |
219 void PrintPageInternal(const PrintMsg_PrintPage_Params& params, | 225 void PrintPageInternal(const PrintMsg_PrintPage_Params& params, |
220 const gfx::Size& canvas_size, | 226 const gfx::Size& canvas_size, |
221 WebKit::WebFrame* frame); | 227 WebKit::WebFrame* frame); |
222 #endif | 228 #endif |
223 | 229 |
224 // Render the frame for printing. | 230 // Render the frame for printing. |
225 bool RenderPagesForPrint(WebKit::WebFrame* frame, WebKit::WebNode* node, | 231 bool RenderPagesForPrint(WebKit::WebFrame* frame, WebKit::WebNode* node, |
226 PrepareFrameAndViewForPrint* prepare); | 232 PrepareFrameAndViewForPrint* prepare); |
227 | 233 |
228 // Platform specific helper function for rendering page(s) to |metafile|. | 234 // Platform specific helper function for rendering page(s) to |metafile|. |
229 #if defined(OS_WIN) | 235 #if defined(OS_WIN) |
230 void RenderPage(const PrintMsg_Print_Params& params, float* scale_factor, | 236 void RenderPage(const PrintMsg_Print_Params& params, float* scale_factor, |
231 int page_number, int page_slot, bool is_preview, | 237 int page_number, int page_slot, bool is_preview, |
232 WebKit::WebFrame* frame, | 238 WebKit::WebFrame* frame, |
233 scoped_ptr<printing::Metafile>* metafile); | 239 scoped_ptr<printing::Metafile>* metafile); |
234 #elif defined(OS_MACOSX) | 240 #elif defined(OS_MACOSX) |
235 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, |
236 const float& scale_factor, int page_number, int page_slot, | 242 const float& scale_factor, int page_number, int page_slot, |
237 WebKit::WebFrame* frame, printing::Metafile* metafile); | 243 WebKit::WebFrame* frame, bool is_preview, |
244 printing::Metafile* metafile); | |
238 #elif defined(OS_POSIX) | 245 #elif defined(OS_POSIX) |
239 bool RenderPages(const PrintMsg_PrintPages_Params& params, | 246 bool RenderPages(const PrintMsg_PrintPages_Params& params, |
240 WebKit::WebFrame* frame, WebKit::WebNode* node, | 247 WebKit::WebFrame* frame, WebKit::WebNode* node, |
241 int* page_count, PrepareFrameAndViewForPrint* prepare, | 248 int* page_count, PrepareFrameAndViewForPrint* prepare, |
242 printing::Metafile* metafile); | 249 printing::Metafile* metafile); |
243 #endif // defined(OS_WIN) | 250 #endif // defined(OS_WIN) |
244 | 251 |
245 // Helper methods ----------------------------------------------------------- | 252 // Helper methods ----------------------------------------------------------- |
246 | 253 |
247 bool CopyAndPrint(WebKit::WebFrame* web_frame); | 254 bool CopyAndPrint(WebKit::WebFrame* web_frame); |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
282 // Displays the print job error message to the user. | 289 // Displays the print job error message to the user. |
283 void DisplayPrintJobError(); | 290 void DisplayPrintJobError(); |
284 | 291 |
285 void RequestPrintPreview(); | 292 void RequestPrintPreview(); |
286 | 293 |
287 // Notify the browser a print preview page has been rendered. | 294 // Notify the browser a print preview page has been rendered. |
288 // |page_number| is 0-based or |printing::INVALID_PAGE_INDEX| to check | 295 // |page_number| is 0-based or |printing::INVALID_PAGE_INDEX| to check |
289 // for pending preview requests. | 296 // for pending preview requests. |
290 void PreviewPageRendered(int page_number, printing::Metafile* metafile); | 297 void PreviewPageRendered(int page_number, printing::Metafile* metafile); |
291 | 298 |
299 // Given the |device| and |canvas| to draw on, prints the appropriate headers | |
300 // and footers using strings from |header_footer_info| on to the canvas. | |
kmadhusu
2011/07/28 20:31:20
Add comments after #defined(USE_SKIA)
Aayush Kumar
2011/07/29 00:21:46
Done.
| |
301 #if defined(USE_SKIA) | |
302 void PrintHeaderAndFooter(SkDevice* device, | |
kmadhusu
2011/07/28 20:31:20
Add the "static" keyword to the function signature
Aayush Kumar
2011/07/29 00:21:46
Done.
| |
303 skia::VectorCanvas& canvas, | |
304 int page_number, | |
305 int total_pages, | |
306 float webkit_scale_factor, | |
307 const PageSizeMargins& page_layout_in_points, | |
308 const base::DictionaryValue& header_footer_info); | |
309 #endif // USE_SKIA | |
310 | |
292 WebKit::WebView* print_web_view_; | 311 WebKit::WebView* print_web_view_; |
293 | 312 |
294 scoped_ptr<PrintMsg_PrintPages_Params> print_pages_params_; | 313 scoped_ptr<PrintMsg_PrintPages_Params> print_pages_params_; |
295 bool is_preview_; | 314 bool is_preview_; |
296 | 315 |
297 // Used for scripted initiated printing blocking. | 316 // Used for scripted initiated printing blocking. |
298 base::Time last_cancelled_script_print_; | 317 base::Time last_cancelled_script_print_; |
299 int user_cancelled_scripted_print_count_; | 318 int user_cancelled_scripted_print_count_; |
300 | 319 |
301 // Let the browser process know of a printing failure. Only set to false when | 320 // Let the browser process know of a printing failure. Only set to false when |
302 // the failure came from the browser in the first place. | 321 // the failure came from the browser in the first place. |
303 bool notify_browser_of_print_failure_; | 322 bool notify_browser_of_print_failure_; |
304 | 323 |
305 scoped_ptr<PrintMsg_PrintPages_Params> old_print_pages_params_; | 324 scoped_ptr<PrintMsg_PrintPages_Params> old_print_pages_params_; |
306 | 325 |
326 // Contains strings generated by the browser process to be printed as headers | |
327 // and footers if requested by the user. | |
328 scoped_ptr<base::DictionaryValue> header_footer_info_; | |
329 | |
307 // Keeps track of the state of print preview between messages. | 330 // Keeps track of the state of print preview between messages. |
308 class PrintPreviewContext { | 331 class PrintPreviewContext { |
309 public: | 332 public: |
310 PrintPreviewContext(); | 333 PrintPreviewContext(); |
311 ~PrintPreviewContext(); | 334 ~PrintPreviewContext(); |
312 | 335 |
313 // Initializes the print preview context. Need to be called to set | 336 // Initializes the print preview context. Need to be called to set |
314 // the |web_frame| / |web_node| to generate the print preview for. | 337 // the |web_frame| / |web_node| to generate the print preview for. |
315 void InitWithFrame(WebKit::WebFrame* web_frame); | 338 void InitWithFrame(WebKit::WebFrame* web_frame); |
316 void InitWithNode(const WebKit::WebNode& web_node); | 339 void InitWithNode(const WebKit::WebNode& web_node); |
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
392 | 415 |
393 State state_; | 416 State state_; |
394 }; | 417 }; |
395 | 418 |
396 PrintPreviewContext print_preview_context_; | 419 PrintPreviewContext print_preview_context_; |
397 | 420 |
398 DISALLOW_COPY_AND_ASSIGN(PrintWebViewHelper); | 421 DISALLOW_COPY_AND_ASSIGN(PrintWebViewHelper); |
399 }; | 422 }; |
400 | 423 |
401 #endif // CHROME_RENDERER_PRINT_WEB_VIEW_HELPER_H_ | 424 #endif // CHROME_RENDERER_PRINT_WEB_VIEW_HELPER_H_ |
OLD | NEW |