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 "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 class DictionaryValue; | 25 class DictionaryValue; |
20 struct PrintMsg_Print_Params; | 26 struct PrintMsg_Print_Params; |
21 struct PrintMsg_PrintPage_Params; | 27 struct PrintMsg_PrintPage_Params; |
22 struct PrintMsg_PrintPages_Params; | 28 struct PrintMsg_PrintPages_Params; |
23 | 29 |
24 // Class that calls the Begin and End print functions on the frame and changes | 30 // Class that calls the Begin and End print functions on the frame and changes |
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
100 | 106 |
101 // Message handlers --------------------------------------------------------- | 107 // Message handlers --------------------------------------------------------- |
102 | 108 |
103 // Print the document. | 109 // Print the document. |
104 void OnPrintPages(); | 110 void OnPrintPages(); |
105 | 111 |
106 // Initiate print preview. | 112 // Initiate print preview. |
107 void OnInitiatePrintPreview(); | 113 void OnInitiatePrintPreview(); |
108 | 114 |
109 // Generate a print preview using |settings|. | 115 // Generate a print preview using |settings|. |
110 void OnPrintPreview(const DictionaryValue& settings); | 116 // |header_footer_info| contains the necessary strings generated by the |
117 // browser process to be printed as headers and footers if requested by the | |
118 // user. | |
119 void OnPrintPreview(const DictionaryValue& settings, | |
120 const DictionaryValue& header_footer_info); | |
kmadhusu
2011/07/13 18:47:53
nit: Fix indentation.
Aayush Kumar
2011/07/13 21:52:16
Done.
| |
111 | 121 |
112 // Print / preview the node under the context menu. | 122 // Print / preview the node under the context menu. |
113 void OnPrintNodeUnderContextMenu(); | 123 void OnPrintNodeUnderContextMenu(); |
114 | 124 |
115 // Print the pages for print preview. Do not display the native print dialog | 125 // Print the pages for print preview. Do not display the native print dialog |
116 // for user settings. |job_settings| has new print job settings values. | 126 // for user settings. |job_settings| has new print job settings values. |
117 void OnPrintForPrintPreview(const DictionaryValue& job_settings); | 127 void OnPrintForPrintPreview(const DictionaryValue& job_settings); |
118 | 128 |
119 void OnPrintingDone(bool success); | 129 void OnPrintingDone(bool success); |
120 | 130 |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
158 // It will implicitly revert the document to display CSS media type. | 168 // It will implicitly revert the document to display CSS media type. |
159 bool PrintPages(const PrintMsg_PrintPages_Params& params, | 169 bool PrintPages(const PrintMsg_PrintPages_Params& params, |
160 WebKit::WebFrame* frame, | 170 WebKit::WebFrame* frame, |
161 WebKit::WebNode* node); | 171 WebKit::WebNode* node); |
162 | 172 |
163 // Prints the page listed in |params|. | 173 // Prints the page listed in |params|. |
164 #if defined(USE_X11) | 174 #if defined(USE_X11) |
165 void PrintPageInternal(const PrintMsg_PrintPage_Params& params, | 175 void PrintPageInternal(const PrintMsg_PrintPage_Params& params, |
166 const gfx::Size& canvas_size, | 176 const gfx::Size& canvas_size, |
167 WebKit::WebFrame* frame, | 177 WebKit::WebFrame* frame, |
168 printing::Metafile* metafile); | 178 printing::Metafile* metafile, |
179 bool is_preview, | |
180 int total_pages); | |
169 #else | 181 #else |
170 void PrintPageInternal(const PrintMsg_PrintPage_Params& params, | 182 void PrintPageInternal(const PrintMsg_PrintPage_Params& params, |
171 const gfx::Size& canvas_size, | 183 const gfx::Size& canvas_size, |
172 WebKit::WebFrame* frame); | 184 WebKit::WebFrame* frame); |
173 #endif | 185 #endif |
174 | 186 |
175 // Render the frame for printing. | 187 // Render the frame for printing. |
176 bool RenderPagesForPrint(WebKit::WebFrame* frame, WebKit::WebNode* node); | 188 bool RenderPagesForPrint(WebKit::WebFrame* frame, WebKit::WebNode* node); |
177 | 189 |
178 // Render the frame for preview. | 190 // Render the frame for preview. |
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
276 base::Time last_cancelled_script_print_; | 288 base::Time last_cancelled_script_print_; |
277 int user_cancelled_scripted_print_count_; | 289 int user_cancelled_scripted_print_count_; |
278 | 290 |
279 // Let the browser process know of a printing failure. Only set to false when | 291 // Let the browser process know of a printing failure. Only set to false when |
280 // the failure came from the browser in the first place. | 292 // the failure came from the browser in the first place. |
281 bool notify_browser_of_print_failure_; | 293 bool notify_browser_of_print_failure_; |
282 | 294 |
283 int preview_page_count_; | 295 int preview_page_count_; |
284 scoped_ptr<PrintMsg_PrintPages_Params> old_print_pages_params_; | 296 scoped_ptr<PrintMsg_PrintPages_Params> old_print_pages_params_; |
285 | 297 |
298 // Contains strings generated by the browser process to be printed as headers | |
299 // and footers if requested by the user. | |
300 const DictionaryValue* header_footer_info_; | |
301 | |
302 // Specifies the horizontal alignment of the Headers and Footers. | |
303 enum HorizontalHeaderFooterPosition { | |
kmadhusu
2011/07/13 18:47:53
Move these enums to print_job_constants.h &.cc and
| |
304 LEFT, | |
305 CENTER, | |
306 RIGHT | |
307 }; | |
308 | |
309 // Specifies the vertical alignment of the Headers and Footers. | |
310 enum VerticalHeaderFooterPosition { | |
311 TOP, | |
312 BOTTOM | |
313 }; | |
314 | |
315 // Gets the x-coordinate from where we want to start printing the current text | |
316 // depending on the alignment (LEFT, RIGHT, CENTER). | |
317 SkScalar GetHorizontalCoordinate( | |
318 string16 text, | |
319 SkPaint paint, | |
320 HorizontalHeaderFooterPosition pos, | |
321 SkScalar margin_left_in_points, | |
322 SkScalar margin_right_in_points, | |
323 SkScalar content_width_in_points); | |
324 | |
325 // Gets the y-coordinate from where we want to start printing based on if we | |
326 // are printing the Header or the Footer (TOP or BOTTOM). | |
327 SkScalar GetVerticalCoordinate( | |
328 SkPaint paint, | |
329 VerticalHeaderFooterPosition pos, | |
330 SkScalar margin_left_in_points, | |
331 SkScalar margin_right_in_points, | |
332 SkScalar content_height_in_points); | |
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 SkScalar margin_left_in_points, | |
Lei Zhang
2011/07/12 22:04:50
Consider using some additional data structures. Wh
Aayush Kumar
2011/07/13 21:52:16
Now private variables in PrintWebViewHelper class
| |
345 SkScalar margin_right_in_points, | |
346 SkScalar content_width_in_points, | |
347 SkScalar margin_top_in_points, | |
348 SkScalar margin_bottom_in_points, | |
349 SkScalar content_height_in_points, | |
350 HorizontalHeaderFooterPosition hor_pos, | |
351 VerticalHeaderFooterPosition ver_pos); | |
352 | |
286 DISALLOW_COPY_AND_ASSIGN(PrintWebViewHelper); | 353 DISALLOW_COPY_AND_ASSIGN(PrintWebViewHelper); |
287 }; | 354 }; |
288 | 355 |
289 #endif // CHROME_RENDERER_PRINT_WEB_VIEW_HELPER_H_ | 356 #endif // CHROME_RENDERER_PRINT_WEB_VIEW_HELPER_H_ |
OLD | NEW |