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

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: Now we print either headers or footers (if we have space to print any). 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 213 matching lines...) Expand 10 before | Expand all | Expand 10 after
253 int page_index, 258 int page_index,
254 const PrintMsg_Print_Params& default_params, 259 const PrintMsg_Print_Params& default_params,
255 PageSizeMargins* page_layout_in_points); 260 PageSizeMargins* page_layout_in_points);
256 261
257 static void UpdatePrintableSizeInPrintParameters( 262 static void UpdatePrintableSizeInPrintParameters(
258 WebKit::WebFrame* frame, 263 WebKit::WebFrame* frame,
259 WebKit::WebNode* node, 264 WebKit::WebNode* node,
260 PrepareFrameAndViewForPrint* prepare, 265 PrepareFrameAndViewForPrint* prepare,
261 PrintMsg_Print_Params* params); 266 PrintMsg_Print_Params* params);
262 267
268 #if defined(USE_SKIA)
269 // Given the |device| and |canvas| to draw on, prints the appropriate headers
270 // and footers using strings from |header_footer_info| on to the canvas.
271 static void PrintHeaderAndFooter(
272 SkDevice* device,
273 skia::VectorCanvas* canvas,
274 int page_number,
275 int total_pages,
276 float webkit_scale_factor,
277 const PageSizeMargins& page_layout_in_points,
278 const base::DictionaryValue& header_footer_info);
279 #endif // USE_SKIA
280
263 bool GetPrintFrame(WebKit::WebFrame** frame); 281 bool GetPrintFrame(WebKit::WebFrame** frame);
264 282
265 // This reports the current time - |start_time| as the time to render a page. 283 // This reports the current time - |start_time| as the time to render a page.
266 void ReportPreviewPageRenderTime(base::TimeTicks start_time); 284 void ReportPreviewPageRenderTime(base::TimeTicks start_time);
267 285
268 // Script Initiated Printing ------------------------------------------------ 286 // Script Initiated Printing ------------------------------------------------
269 287
270 // Returns true if script initiated printing occurs too often. 288 // Returns true if script initiated printing occurs too often.
271 bool IsScriptInitiatedPrintTooFrequent(WebKit::WebFrame* frame); 289 bool IsScriptInitiatedPrintTooFrequent(WebKit::WebFrame* frame);
272 290
(...skipping 23 matching lines...) Expand all
296 // Used for scripted initiated printing blocking. 314 // Used for scripted initiated printing blocking.
297 base::Time last_cancelled_script_print_; 315 base::Time last_cancelled_script_print_;
298 int user_cancelled_scripted_print_count_; 316 int user_cancelled_scripted_print_count_;
299 317
300 // Let the browser process know of a printing failure. Only set to false when 318 // Let the browser process know of a printing failure. Only set to false when
301 // the failure came from the browser in the first place. 319 // the failure came from the browser in the first place.
302 bool notify_browser_of_print_failure_; 320 bool notify_browser_of_print_failure_;
303 321
304 scoped_ptr<PrintMsg_PrintPages_Params> old_print_pages_params_; 322 scoped_ptr<PrintMsg_PrintPages_Params> old_print_pages_params_;
305 323
324 // Contains strings generated by the browser process to be printed as headers
325 // and footers if requested by the user.
326 scoped_ptr<base::DictionaryValue> header_footer_info_;
327
306 // Keeps track of the state of print preview between messages. 328 // Keeps track of the state of print preview between messages.
307 class PrintPreviewContext { 329 class PrintPreviewContext {
308 public: 330 public:
309 PrintPreviewContext(); 331 PrintPreviewContext();
310 ~PrintPreviewContext(); 332 ~PrintPreviewContext();
311 333
312 // Initializes the print preview context. Need to be called to set 334 // Initializes the print preview context. Need to be called to set
313 // the |web_frame| / |web_node| to generate the print preview for. 335 // the |web_frame| / |web_node| to generate the print preview for.
314 void InitWithFrame(WebKit::WebFrame* web_frame); 336 void InitWithFrame(WebKit::WebFrame* web_frame);
315 void InitWithNode(const WebKit::WebNode& web_node); 337 void InitWithNode(const WebKit::WebNode& web_node);
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
386 408
387 State state_; 409 State state_;
388 }; 410 };
389 411
390 PrintPreviewContext print_preview_context_; 412 PrintPreviewContext print_preview_context_;
391 413
392 DISALLOW_COPY_AND_ASSIGN(PrintWebViewHelper); 414 DISALLOW_COPY_AND_ASSIGN(PrintWebViewHelper);
393 }; 415 };
394 416
395 #endif // CHROME_RENDERER_PRINT_WEB_VIEW_HELPER_H_ 417 #endif // CHROME_RENDERER_PRINT_WEB_VIEW_HELPER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698