| Index: chrome/renderer/print_web_view_helper.cc
|
| diff --git a/chrome/renderer/print_web_view_helper.cc b/chrome/renderer/print_web_view_helper.cc
|
| index 9133e38330a922d94cab5a9720d4e75dad3559ae..d229df1556ce48c1cb6b1b6a6800553430ed93b3 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);
|
| +}
|
|
|