summaryrefslogtreecommitdiffstats
path: root/chrome/renderer
diff options
context:
space:
mode:
authorhamaji@chromium.org <hamaji@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-06-29 07:45:16 +0000
committerhamaji@chromium.org <hamaji@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-06-29 07:45:16 +0000
commit5a0700785783202483cfee429fd2e11e6cd8d93e (patch)
tree8f55328fc85c11ebc7ede42255fcf210ece8cc83 /chrome/renderer
parent19b818418f6e629f740a46429bdd4e940368bfb2 (diff)
downloadchromium_src-5a0700785783202483cfee429fd2e11e6cd8d93e.zip
chromium_src-5a0700785783202483cfee429fd2e11e6cd8d93e.tar.gz
chromium_src-5a0700785783202483cfee429fd2e11e6cd8d93e.tar.bz2
Implement limited paged media support for linux.
BUG=47277 TEST=none Review URL: http://codereview.chromium.org/2847025 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@51104 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/renderer')
-rw-r--r--chrome/renderer/print_web_view_helper_linux.cc114
1 files changed, 101 insertions, 13 deletions
diff --git a/chrome/renderer/print_web_view_helper_linux.cc b/chrome/renderer/print_web_view_helper_linux.cc
index 609f099..b909b07 100644
--- a/chrome/renderer/print_web_view_helper_linux.cc
+++ b/chrome/renderer/print_web_view_helper_linux.cc
@@ -11,31 +11,99 @@
#include "printing/units.h"
#include "skia/ext/vector_canvas.h"
#include "third_party/WebKit/WebKit/chromium/public/WebFrame.h"
+#include "third_party/WebKit/WebKit/chromium/public/WebSize.h"
+using printing::ConvertPixelsToPoint;
+using printing::ConvertPixelsToPointDouble;
using printing::NativeMetafile;
using WebKit::WebFrame;
+using WebKit::WebSize;
+
+// If frame is NULL, this function returns the default value.
+static void GetPageSizeAndMarginsInPoints(WebFrame* frame,
+ int page_index,
+ 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) {
+ // TODO(myhuang): Get printing parameters via IPC
+ // using the print_web_view_helper.cc version of Print.
+ // For testing purpose, we hard-coded printing parameters here.
+
+ // The paper size is US Letter (8.5 in. by 11 in.).
+ WebSize page_size_in_pixels(8.5 * printing::kPixelsPerInch,
+ 11.0 * printing::kPixelsPerInch);
+
+ int margin_top_in_pixels = static_cast<int>(
+ NativeMetafile::kTopMarginInInch * printing::kPixelsPerInch);
+ int margin_right_in_pixels = static_cast<int>(
+ NativeMetafile::kRightMarginInInch * printing::kPixelsPerInch);
+ int margin_bottom_in_pixels = static_cast<int>(
+ NativeMetafile::kBottomMarginInInch * printing::kPixelsPerInch);
+ int margin_left_in_pixels = static_cast<int>(
+ NativeMetafile::kLeftMarginInInch * printing::kPixelsPerInch);
+
+ if (frame) {
+ frame->pageSizeAndMarginsInPixels(page_index,
+ page_size_in_pixels,
+ margin_top_in_pixels,
+ margin_right_in_pixels,
+ margin_bottom_in_pixels,
+ margin_left_in_pixels);
+ }
+
+ *content_width_in_points = ConvertPixelsToPoint(page_size_in_pixels.width
+ - margin_left_in_pixels
+ - margin_right_in_pixels);
+ *content_height_in_points = ConvertPixelsToPoint(page_size_in_pixels.height
+ - margin_top_in_pixels
+ - margin_bottom_in_pixels);
+
+ // Invalid page size and/or margins. We just use the default setting.
+ if (*content_width_in_points < 1.0 || *content_height_in_points < 1.0) {
+ GetPageSizeAndMarginsInPoints(NULL,
+ page_index,
+ content_width_in_points,
+ content_height_in_points,
+ margin_top_in_points,
+ margin_right_in_points,
+ margin_bottom_in_points,
+ margin_left_in_points);
+ return;
+ }
+
+ if (margin_top_in_points)
+ *margin_top_in_points =
+ ConvertPixelsToPointDouble(margin_top_in_pixels);
+ if (margin_right_in_points)
+ *margin_right_in_points =
+ ConvertPixelsToPointDouble(margin_right_in_pixels);
+ if (margin_bottom_in_points)
+ *margin_bottom_in_points =
+ ConvertPixelsToPointDouble(margin_bottom_in_pixels);
+ if (margin_left_in_points)
+ *margin_left_in_points =
+ ConvertPixelsToPointDouble(margin_left_in_pixels);
+}
void PrintWebViewHelper::Print(WebFrame* frame, bool script_initiated) {
// If still not finished with earlier print request simply ignore.
if (IsPrinting())
return;
- // TODO(myhuang): Get printing parameters via IPC
- // using the print_web_view_helper.cc version of Print.
- // For testing purpose, we hard-coded printing parameters here.
+ double content_width, content_height;
+ GetPageSizeAndMarginsInPoints(frame, 0, &content_width, &content_height,
+ NULL, NULL, NULL, NULL);
- // The paper size is US Letter (8.5 in. by 11 in.).
- const int kDPI = printing::kPointsPerInch;
- const int kWidth = static_cast<int>(
- 8.5 * kDPI - NativeMetafile::kLeftMargin - NativeMetafile::kRightMargin);
- const int kHeight = static_cast<int>(
- 11 * kDPI - NativeMetafile::kTopMargin - NativeMetafile::kBottomMargin);
ViewMsg_Print_Params default_settings;
- default_settings.printable_size = gfx::Size(kWidth, kHeight);
- default_settings.dpi = kDPI;
+ default_settings.printable_size = gfx::Size(
+ static_cast<int>(content_width), static_cast<int>(content_height));
+ default_settings.dpi = printing::kPointsPerInch;
default_settings.min_shrink = 1.25;
default_settings.max_shrink = 2.0;
- default_settings.desired_dpi = kDPI;
+ default_settings.desired_dpi = printing::kPointsPerInch;
default_settings.document_cookie = 0;
default_settings.selection_only = false;
@@ -103,8 +171,28 @@ void PrintWebViewHelper::PrintPage(const ViewMsg_PrintPage_Params& params,
const gfx::Size& canvas_size,
WebFrame* frame,
printing::NativeMetafile* metafile) {
+ 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;
+ GetPageSizeAndMarginsInPoints(frame,
+ params.page_number,
+ &content_width_in_points,
+ &content_height_in_points,
+ &margin_top_in_points,
+ &margin_right_in_points,
+ &margin_bottom_in_points,
+ &margin_left_in_points);
+
cairo_t* cairo_context =
- metafile->StartPage(canvas_size.width(), canvas_size.height());
+ metafile->StartPage(content_width_in_points,
+ content_height_in_points,
+ margin_top_in_points,
+ margin_right_in_points,
+ margin_bottom_in_points,
+ margin_left_in_points);
if (!cairo_context)
return;