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

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

Powered by Google App Engine
This is Rietveld 408576698