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

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: Indent Fix 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 "base/memory/scoped_ptr.h" 9 #include "base/memory/scoped_ptr.h"
10 #include "base/shared_memory.h" 10 #include "base/shared_memory.h"
11 #include "base/time.h" 11 #include "base/time.h"
12 #include "base/utf_string_conversions.h"
13 #include "base/values.h"
12 #include "content/renderer/render_view_observer.h" 14 #include "content/renderer/render_view_observer.h"
13 #include "content/renderer/render_view_observer_tracker.h" 15 #include "content/renderer/render_view_observer_tracker.h"
14 #include "printing/metafile.h" 16 #include "printing/metafile.h"
17 #include "skia/ext/vector_canvas.h"
18 #include "third_party/skia/include/core/SkPaint.h"
19 #include "third_party/skia/include/core/SkRefCnt.h"
20 #include "third_party/skia/include/core/SkScalar.h"
15 #include "third_party/WebKit/Source/WebKit/chromium/public/WebFrameClient.h" 21 #include "third_party/WebKit/Source/WebKit/chromium/public/WebFrameClient.h"
16 #include "third_party/WebKit/Source/WebKit/chromium/public/WebViewClient.h" 22 #include "third_party/WebKit/Source/WebKit/chromium/public/WebViewClient.h"
17 #include "ui/gfx/size.h" 23 #include "ui/gfx/size.h"
18 24
19 struct PrintMsg_Print_Params; 25 struct PrintMsg_Print_Params;
20 struct PrintMsg_PrintPage_Params; 26 struct PrintMsg_PrintPage_Params;
21 struct PrintMsg_PrintPages_Params; 27 struct PrintMsg_PrintPages_Params;
22 28
23 namespace base { 29 namespace base {
24 class DictionaryValue; 30 class DictionaryValue;
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
102 108
103 // Message handlers --------------------------------------------------------- 109 // Message handlers ---------------------------------------------------------
104 110
105 // Print the document. 111 // Print the document.
106 void OnPrintPages(); 112 void OnPrintPages();
107 113
108 // Initiate print preview. 114 // Initiate print preview.
109 void OnInitiatePrintPreview(); 115 void OnInitiatePrintPreview();
110 116
111 // Generate a print preview using |settings|. 117 // Generate a print preview using |settings|.
112 void OnPrintPreview(const base::DictionaryValue& settings); 118 // |header_footer_info| contains the necessary strings generated by the
119 // browser process to be printed as headers and footers if requested by the
120 // user.
121 void OnPrintPreview(const base::DictionaryValue& settings,
122 const DictionaryValue& header_footer_info);
113 123
114 // Print / preview the node under the context menu. 124 // Print / preview the node under the context menu.
115 void OnPrintNodeUnderContextMenu(); 125 void OnPrintNodeUnderContextMenu();
116 126
117 // Print the pages for print preview. Do not display the native print dialog 127 // Print the pages for print preview. Do not display the native print dialog
118 // for user settings. |job_settings| has new print job settings values. 128 // for user settings. |job_settings| has new print job settings values.
119 void OnPrintForPrintPreview(const base::DictionaryValue& job_settings); 129 void OnPrintForPrintPreview(const base::DictionaryValue& job_settings);
120 130
121 void OnPrintingDone(bool success); 131 void OnPrintingDone(bool success);
122 132
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
170 // It will implicitly revert the document to display CSS media type. 180 // It will implicitly revert the document to display CSS media type.
171 bool PrintPages(const PrintMsg_PrintPages_Params& params, 181 bool PrintPages(const PrintMsg_PrintPages_Params& params,
172 WebKit::WebFrame* frame, 182 WebKit::WebFrame* frame,
173 WebKit::WebNode* node); 183 WebKit::WebNode* node);
174 184
175 // Prints the page listed in |params|. 185 // Prints the page listed in |params|.
176 #if defined(USE_X11) 186 #if defined(USE_X11)
177 void PrintPageInternal(const PrintMsg_PrintPage_Params& params, 187 void PrintPageInternal(const PrintMsg_PrintPage_Params& params,
178 const gfx::Size& canvas_size, 188 const gfx::Size& canvas_size,
179 WebKit::WebFrame* frame, 189 WebKit::WebFrame* frame,
180 printing::Metafile* metafile); 190 printing::Metafile* metafile,
191 bool is_preview,
192 int total_pages);
181 #else 193 #else
182 void PrintPageInternal(const PrintMsg_PrintPage_Params& params, 194 void PrintPageInternal(const PrintMsg_PrintPage_Params& params,
183 const gfx::Size& canvas_size, 195 const gfx::Size& canvas_size,
184 WebKit::WebFrame* frame); 196 WebKit::WebFrame* frame);
185 #endif 197 #endif
186 198
187 // Render the frame for printing. 199 // Render the frame for printing.
188 bool RenderPagesForPrint(WebKit::WebFrame* frame, WebKit::WebNode* node); 200 bool RenderPagesForPrint(WebKit::WebFrame* frame, WebKit::WebNode* node);
189 201
190 // Render the frame for preview. 202 // Render the frame for preview.
(...skipping 27 matching lines...) Expand all
218 // Helper methods ----------------------------------------------------------- 230 // Helper methods -----------------------------------------------------------
219 231
220 bool CopyAndPrint(WebKit::WebFrame* web_frame); 232 bool CopyAndPrint(WebKit::WebFrame* web_frame);
221 233
222 bool CopyMetafileDataToSharedMem(printing::Metafile* metafile, 234 bool CopyMetafileDataToSharedMem(printing::Metafile* metafile,
223 base::SharedMemoryHandle* shared_mem_handle); 235 base::SharedMemoryHandle* shared_mem_handle);
224 236
225 void GetPageSizeAndMarginsInPoints( 237 void GetPageSizeAndMarginsInPoints(
226 WebKit::WebFrame* frame, 238 WebKit::WebFrame* frame,
227 int page_index, 239 int page_index,
228 const PrintMsg_Print_Params& default_params, 240 const PrintMsg_Print_Params& default_params);
229 double* content_width_in_points,
230 double* content_height_in_points,
231 double* margin_top_in_points,
232 double* margin_right_in_points,
233 double* margin_bottom_in_points,
234 double* margin_left_in_points);
235 241
236 bool IsModifiable(WebKit::WebFrame* frame, WebKit::WebNode* node); 242 bool IsModifiable(WebKit::WebFrame* frame, WebKit::WebNode* node);
237 243
238 void UpdatePrintableSizeInPrintParameters(WebKit::WebFrame* frame, 244 void UpdatePrintableSizeInPrintParameters(WebKit::WebFrame* frame,
239 WebKit::WebNode* node, 245 WebKit::WebNode* node,
240 PrintMsg_Print_Params* params); 246 PrintMsg_Print_Params* params);
241 247
242 bool GetPrintFrame(WebKit::WebFrame** frame); 248 bool GetPrintFrame(WebKit::WebFrame** frame);
243 249
244 // This reports the current time - |start_time| as the time to render 250 // This reports the current time - |start_time| as the time to render
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
288 base::Time last_cancelled_script_print_; 294 base::Time last_cancelled_script_print_;
289 int user_cancelled_scripted_print_count_; 295 int user_cancelled_scripted_print_count_;
290 296
291 // 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
292 // the failure came from the browser in the first place. 298 // the failure came from the browser in the first place.
293 bool notify_browser_of_print_failure_; 299 bool notify_browser_of_print_failure_;
294 300
295 int preview_page_count_; 301 int preview_page_count_;
296 scoped_ptr<PrintMsg_PrintPages_Params> old_print_pages_params_; 302 scoped_ptr<PrintMsg_PrintPages_Params> old_print_pages_params_;
297 303
304 // Contains strings generated by the browser process to be printed as headers
305 // and footers if requested by the user.
306 const DictionaryValue* header_footer_info_;
307
308 // Specifies the horizontal alignment of the Headers and Footers.
309 enum HorizontalHeaderFooterPosition {
310 LEFT,
311 CENTER,
312 RIGHT
313 };
314
315 // Specifies the vertical alignment of the Headers and Footers.
316 enum VerticalHeaderFooterPosition {
317 TOP,
318 BOTTOM
319 };
320
321 // Gets the x-coordinate from where we want to start printing the current text
322 // depending on the alignment (LEFT, RIGHT, CENTER).
323 SkScalar GetHorizontalCoordinate(
324 string16 text,
325 SkPaint paint,
326 HorizontalHeaderFooterPosition pos);
327
328 // Gets the y-coordinate from where we want to start printing based on if we
329 // are printing the Header or the Footer (TOP or BOTTOM).
330 SkScalar GetVerticalCoordinate(
331 SkPaint paint,
332 VerticalHeaderFooterPosition pos);
333
334 // Interstice or gap between different Header and Footer components.
335 // Hardcoded to 0.25cm = 1/10" = 7.2 points
336 const SkScalar header_footer_interstice;
337
338 // Given a text, the positions and the paint object, this method calculates
339 // the coordinates and prints the text at those co-ordinates.
340 void PrintHeaderFooterText(
341 string16 text,
342 SkPaint paint,
343 const SkRefPtr<skia::VectorCanvas>& canvas,
344 HorizontalHeaderFooterPosition hor_pos,
345 VerticalHeaderFooterPosition ver_pos,
346 float webkit_scale_factor);
347
348 // Given the device and canvas to draw on, prints the appropriate headers
349 // and footers on to the canvas.
350 void PrintHeaderAndFooter(SkDevice *device,
351 const SkRefPtr<skia::VectorCanvas>& canvas,
352 int page_number, int total_pages,
353 float webkit_scale_factor);
354
355 double content_width_in_points;
356 double content_height_in_points;
357 double margin_top_in_points;
358 double margin_right_in_points;
359 double margin_bottom_in_points;
360 double margin_left_in_points;
361
298 DISALLOW_COPY_AND_ASSIGN(PrintWebViewHelper); 362 DISALLOW_COPY_AND_ASSIGN(PrintWebViewHelper);
299 }; 363 };
300 364
301 #endif // CHROME_RENDERER_PRINT_WEB_VIEW_HELPER_H_ 365 #endif // CHROME_RENDERER_PRINT_WEB_VIEW_HELPER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698