diff options
author | hamaji@chromium.org <hamaji@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-06-30 04:48:18 +0000 |
---|---|---|
committer | hamaji@chromium.org <hamaji@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-06-30 04:48:18 +0000 |
commit | 71e4087a14a8e82c95869ce133c4077397830ff2 (patch) | |
tree | 02df05644a75b7edc39fdbd5cbe3748299c2bb88 /chrome/renderer/print_web_view_helper.cc | |
parent | 0b1ad660afb3f79dd7975f295ad41e6b9afe598a (diff) | |
download | chromium_src-71e4087a14a8e82c95869ce133c4077397830ff2.zip chromium_src-71e4087a14a8e82c95869ce133c4077397830ff2.tar.gz chromium_src-71e4087a14a8e82c95869ce133c4077397830ff2.tar.bz2 |
Move GetPageSizeAndMarginsInPoints from linux code to generic code.
It seems we can use this function in other environments.
BUG=47277
TEST=none
Review URL: http://codereview.chromium.org/2807029
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@51227 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/renderer/print_web_view_helper.cc')
-rw-r--r-- | chrome/renderer/print_web_view_helper.cc | 85 |
1 files changed, 85 insertions, 0 deletions
diff --git a/chrome/renderer/print_web_view_helper.cc b/chrome/renderer/print_web_view_helper.cc index 9133e38..d229df1 100644 --- a/chrome/renderer/print_web_view_helper.cc +++ b/chrome/renderer/print_web_view_helper.cc @@ -19,9 +19,13 @@ #include "third_party/WebKit/WebKit/chromium/public/WebURLRequest.h" #include "webkit/glue/webkit_glue.h" +using printing::ConvertPixelsToPoint; +using printing::ConvertPixelsToPointDouble; +using printing::ConvertUnit; using WebKit::WebConsoleMessage; using WebKit::WebFrame; using WebKit::WebRect; +using WebKit::WebSize; using WebKit::WebScreenInfo; using WebKit::WebString; using WebKit::WebURLRequest; @@ -345,3 +349,84 @@ void PrintWebViewHelper::didStopLoading() { DCHECK(print_pages_params_.get() != NULL); PrintPages(*print_pages_params_.get(), print_web_view_->mainFrame()); } + +void PrintWebViewHelper::GetPageSizeAndMarginsInPoints( + WebFrame* frame, + int page_index, + const ViewMsg_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) { + int dpi = static_cast<int>(default_params.dpi); +#if defined(OS_MACOSX) + // On the Mac, the printable area is in points, don't do any scaling based + // on dpi. + dpi = printing::kPointsPerInch; +#endif + + WebSize page_size_in_pixels( + ConvertUnit(default_params.page_size.width(), + dpi, printing::kPixelsPerInch), + ConvertUnit(default_params.page_size.height(), + dpi, printing::kPixelsPerInch)); + int margin_top_in_pixels = ConvertUnit( + default_params.margin_top, + dpi, printing::kPixelsPerInch); + int margin_right_in_pixels = ConvertUnit( + default_params.page_size.width() + - default_params.printable_size.width() - default_params.margin_left, + dpi, printing::kPixelsPerInch); + int margin_bottom_in_pixels = ConvertUnit( + default_params.page_size.height() + - default_params.printable_size.height() - default_params.margin_top, + dpi, printing::kPixelsPerInch); + int margin_left_in_pixels = ConvertUnit( + default_params.margin_left, + dpi, 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, + default_params, + 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); +} |