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

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: Remove header_footer_info from settings Dictionary. Changes as per Steve and Kausalya's comments. Created 9 years, 4 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 <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 145 matching lines...) Expand 10 before | Expand all | Expand 10 after
185 scoped_ptr<PrepareFrameAndViewForPrint>* prepare); 190 scoped_ptr<PrepareFrameAndViewForPrint>* prepare);
186 191
187 // Parse the request id out of |job_settings| and store it in |params|. 192 // Parse the request id out of |job_settings| and store it in |params|.
188 // Returns false on failure. 193 // Returns false on failure.
189 bool UpdatePrintSettingsRequestId(const base::DictionaryValue& job_settings, 194 bool UpdatePrintSettingsRequestId(const base::DictionaryValue& job_settings,
190 PrintMsg_Print_Params* params); 195 PrintMsg_Print_Params* params);
191 196
192 // Update the current print settings with new |job_settings|. |job_settings| 197 // Update the current print settings with new |job_settings|. |job_settings|
193 // dictionary contains print job details such as printer name, number of 198 // dictionary contains print job details such as printer name, number of
194 // copies, page range, etc. 199 // copies, page range, etc.
195 bool UpdatePrintSettings(const base::DictionaryValue& job_settings); 200 bool UpdatePrintSettings(base::DictionaryValue* job_settings);
196 201
197 // Get final print settings from the user. 202 // Get final print settings from the user.
198 // Return false if the user cancels or on error. 203 // Return false if the user cancels or on error.
199 bool GetPrintSettingsFromUser(WebKit::WebFrame* frame, 204 bool GetPrintSettingsFromUser(WebKit::WebFrame* frame,
200 int expected_pages_count, 205 int expected_pages_count,
201 bool use_browser_overlays); 206 bool use_browser_overlays);
202 207
203 // Page Printing / Rendering ------------------------------------------------ 208 // Page Printing / Rendering ------------------------------------------------
204 209
205 // Prints all the pages listed in |params|. 210 // Prints all the pages listed in |params|.
(...skipping 21 matching lines...) Expand all
227 232
228 // Platform specific helper function for rendering page(s) to |metafile|. 233 // Platform specific helper function for rendering page(s) to |metafile|.
229 #if defined(OS_WIN) 234 #if defined(OS_WIN)
230 void RenderPage(const PrintMsg_Print_Params& params, float* scale_factor, 235 void RenderPage(const PrintMsg_Print_Params& params, float* scale_factor,
231 int page_number, int page_slot, bool is_preview, 236 int page_number, int page_slot, bool is_preview,
232 WebKit::WebFrame* frame, 237 WebKit::WebFrame* frame,
233 scoped_ptr<printing::Metafile>* metafile); 238 scoped_ptr<printing::Metafile>* metafile);
234 #elif defined(OS_MACOSX) 239 #elif defined(OS_MACOSX)
235 void RenderPage(const gfx::Size& page_size, const gfx::Rect& content_area, 240 void RenderPage(const gfx::Size& page_size, const gfx::Rect& content_area,
236 const float& scale_factor, int page_number, int page_slot, 241 const float& scale_factor, int page_number, int page_slot,
237 WebKit::WebFrame* frame, printing::Metafile* metafile); 242 WebKit::WebFrame* frame, bool is_preview,
243 printing::Metafile* metafile);
238 #elif defined(OS_POSIX) 244 #elif defined(OS_POSIX)
239 bool RenderPages(const PrintMsg_PrintPages_Params& params, 245 bool RenderPages(const PrintMsg_PrintPages_Params& params,
240 WebKit::WebFrame* frame, WebKit::WebNode* node, 246 WebKit::WebFrame* frame, WebKit::WebNode* node,
241 int* page_count, PrepareFrameAndViewForPrint* prepare, 247 int* page_count, PrepareFrameAndViewForPrint* prepare,
242 printing::Metafile* metafile); 248 printing::Metafile* metafile);
243 #endif // defined(OS_WIN) 249 #endif // defined(OS_WIN)
244 250
245 // Helper methods ----------------------------------------------------------- 251 // Helper methods -----------------------------------------------------------
246 252
247 bool CopyAndPrint(WebKit::WebFrame* web_frame); 253 bool CopyAndPrint(WebKit::WebFrame* web_frame);
248 254
249 bool CopyMetafileDataToSharedMem(printing::Metafile* metafile, 255 bool CopyMetafileDataToSharedMem(printing::Metafile* metafile,
250 base::SharedMemoryHandle* shared_mem_handle); 256 base::SharedMemoryHandle* shared_mem_handle);
251 257
252 static void GetPageSizeAndMarginsInPoints( 258 static void GetPageSizeAndMarginsInPoints(
253 WebKit::WebFrame* frame, 259 WebKit::WebFrame* frame,
254 int page_index, 260 int page_index,
255 const PrintMsg_Print_Params& default_params, 261 const PrintMsg_Print_Params& default_params,
256 PageSizeMargins* page_layout_in_points); 262 PageSizeMargins* page_layout_in_points);
257 263
258 static void UpdatePrintableSizeInPrintParameters( 264 static void UpdatePrintableSizeInPrintParameters(
259 WebKit::WebFrame* frame, 265 WebKit::WebFrame* frame,
260 WebKit::WebNode* node, 266 WebKit::WebNode* node,
261 PrepareFrameAndViewForPrint* prepare, 267 PrepareFrameAndViewForPrint* prepare,
262 PrintMsg_Print_Params* params); 268 PrintMsg_Print_Params* params);
263 269
270 #if defined(USE_SKIA)
271 // Given the |device| and |canvas| to draw on, prints the appropriate headers
272 // and footers using strings from |header_footer_info| on to the canvas.
273 static void PrintHeaderAndFooter(
274 SkDevice* device,
275 skia::VectorCanvas* canvas,
276 int page_number,
277 int total_pages,
278 float webkit_scale_factor,
279 const PageSizeMargins& page_layout_in_points,
280 const base::DictionaryValue& header_footer_info);
281 #endif // USE_SKIA
282
264 bool GetPrintFrame(WebKit::WebFrame** frame); 283 bool GetPrintFrame(WebKit::WebFrame** frame);
265 284
266 // This reports the current time - |start_time| as the time to render a page. 285 // This reports the current time - |start_time| as the time to render a page.
267 void ReportPreviewPageRenderTime(base::TimeTicks start_time); 286 void ReportPreviewPageRenderTime(base::TimeTicks start_time);
268 287
269 // Script Initiated Printing ------------------------------------------------ 288 // Script Initiated Printing ------------------------------------------------
270 289
271 // Returns true if script initiated printing occurs too often. 290 // Returns true if script initiated printing occurs too often.
272 bool IsScriptInitiatedPrintTooFrequent(WebKit::WebFrame* frame); 291 bool IsScriptInitiatedPrintTooFrequent(WebKit::WebFrame* frame);
273 292
(...skipping 23 matching lines...) Expand all
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
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_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698