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

Unified 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 side-by-side diff with in-line comments
Download patch
Index: chrome/renderer/print_web_view_helper.h
diff --git a/chrome/renderer/print_web_view_helper.h b/chrome/renderer/print_web_view_helper.h
index 48b7037999372703132400390e08ccf939139703..de41c474ed20ce9a7c2a884b1e08c4829f75d867 100644
--- a/chrome/renderer/print_web_view_helper.h
+++ b/chrome/renderer/print_web_view_helper.h
@@ -9,9 +9,15 @@
#include "base/memory/scoped_ptr.h"
#include "base/shared_memory.h"
#include "base/time.h"
+#include "base/utf_string_conversions.h"
+#include "base/values.h"
#include "content/renderer/render_view_observer.h"
#include "content/renderer/render_view_observer_tracker.h"
#include "printing/metafile.h"
+#include "skia/ext/vector_canvas.h"
+#include "third_party/skia/include/core/SkPaint.h"
+#include "third_party/skia/include/core/SkRefCnt.h"
+#include "third_party/skia/include/core/SkScalar.h"
#include "third_party/WebKit/Source/WebKit/chromium/public/WebFrameClient.h"
#include "third_party/WebKit/Source/WebKit/chromium/public/WebViewClient.h"
#include "ui/gfx/size.h"
@@ -109,7 +115,11 @@ class PrintWebViewHelper : public RenderViewObserver,
void OnInitiatePrintPreview();
// Generate a print preview using |settings|.
- void OnPrintPreview(const base::DictionaryValue& settings);
+ // |header_footer_info| contains the necessary strings generated by the
+ // browser process to be printed as headers and footers if requested by the
+ // user.
+ void OnPrintPreview(const base::DictionaryValue& settings,
+ const DictionaryValue& header_footer_info);
// Print / preview the node under the context menu.
void OnPrintNodeUnderContextMenu();
@@ -177,7 +187,9 @@ class PrintWebViewHelper : public RenderViewObserver,
void PrintPageInternal(const PrintMsg_PrintPage_Params& params,
const gfx::Size& canvas_size,
WebKit::WebFrame* frame,
- printing::Metafile* metafile);
+ printing::Metafile* metafile,
+ bool is_preview,
+ int total_pages);
#else
void PrintPageInternal(const PrintMsg_PrintPage_Params& params,
const gfx::Size& canvas_size,
@@ -225,13 +237,7 @@ class PrintWebViewHelper : public RenderViewObserver,
void GetPageSizeAndMarginsInPoints(
WebKit::WebFrame* frame,
int page_index,
- const PrintMsg_Print_Params& default_params,
- double* content_width_in_points,
- double* content_height_in_points,
- double* margin_top_in_points,
- double* margin_right_in_points,
- double* margin_bottom_in_points,
- double* margin_left_in_points);
+ const PrintMsg_Print_Params& default_params);
bool IsModifiable(WebKit::WebFrame* frame, WebKit::WebNode* node);
@@ -295,6 +301,64 @@ class PrintWebViewHelper : public RenderViewObserver,
int preview_page_count_;
scoped_ptr<PrintMsg_PrintPages_Params> old_print_pages_params_;
+ // Contains strings generated by the browser process to be printed as headers
+ // and footers if requested by the user.
+ const DictionaryValue* header_footer_info_;
+
+ // Specifies the horizontal alignment of the Headers and Footers.
+ enum HorizontalHeaderFooterPosition {
+ LEFT,
+ CENTER,
+ RIGHT
+ };
+
+ // Specifies the vertical alignment of the Headers and Footers.
+ enum VerticalHeaderFooterPosition {
+ TOP,
+ BOTTOM
+ };
+
+ // Gets the x-coordinate from where we want to start printing the current text
+ // depending on the alignment (LEFT, RIGHT, CENTER).
+ SkScalar GetHorizontalCoordinate(
+ string16 text,
+ SkPaint paint,
+ HorizontalHeaderFooterPosition pos);
+
+ // Gets the y-coordinate from where we want to start printing based on if we
+ // are printing the Header or the Footer (TOP or BOTTOM).
+ SkScalar GetVerticalCoordinate(
+ SkPaint paint,
+ VerticalHeaderFooterPosition pos);
+
+ // Interstice or gap between different Header and Footer components.
+ // Hardcoded to 0.25cm = 1/10" = 7.2 points
+ const SkScalar header_footer_interstice;
+
+ // Given a text, the positions and the paint object, this method calculates
+ // the coordinates and prints the text at those co-ordinates.
+ void PrintHeaderFooterText(
+ string16 text,
+ SkPaint paint,
+ const SkRefPtr<skia::VectorCanvas>& canvas,
+ HorizontalHeaderFooterPosition hor_pos,
+ VerticalHeaderFooterPosition ver_pos,
+ float webkit_scale_factor);
+
+ // Given the device and canvas to draw on, prints the appropriate headers
+ // and footers on to the canvas.
+ void PrintHeaderAndFooter(SkDevice *device,
+ const SkRefPtr<skia::VectorCanvas>& canvas,
+ int page_number, int total_pages,
+ float webkit_scale_factor);
+
+ double content_width_in_points;
+ double content_height_in_points;
+ double margin_top_in_points;
+ double margin_right_in_points;
+ double margin_bottom_in_points;
+ double margin_left_in_points;
+
DISALLOW_COPY_AND_ASSIGN(PrintWebViewHelper);
};

Powered by Google App Engine
This is Rietveld 408576698