diff options
author | aayushkumar@chromium.org <aayushkumar@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-07-25 21:12:02 +0000 |
---|---|---|
committer | aayushkumar@chromium.org <aayushkumar@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-07-25 21:12:02 +0000 |
commit | 9d0d357eb0baf6be8ed51c7de7bc132ab64c10d1 (patch) | |
tree | e4b09b31ac5b8013c1fdcf0071089fe667751514 | |
parent | b0ff4e7c000ef7974e2b316388b4416d2ee59007 (diff) | |
download | chromium_src-9d0d357eb0baf6be8ed51c7de7bc132ab64c10d1.zip chromium_src-9d0d357eb0baf6be8ed51c7de7bc132ab64c10d1.tar.gz chromium_src-9d0d357eb0baf6be8ed51c7de7bc132ab64c10d1.tar.bz2 |
Added a struct to hold page sizes and margins.
BUG=none
TEST=none
Review URL: http://codereview.chromium.org/7492031
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@93943 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r-- | chrome/renderer/print_web_view_helper.cc | 80 | ||||
-rw-r--r-- | chrome/renderer/print_web_view_helper.h | 17 | ||||
-rw-r--r-- | chrome/renderer/print_web_view_helper_linux.cc | 34 | ||||
-rw-r--r-- | chrome/renderer/print_web_view_helper_win.cc | 25 |
4 files changed, 68 insertions, 88 deletions
diff --git a/chrome/renderer/print_web_view_helper.cc b/chrome/renderer/print_web_view_helper.cc index 00c36ed..36a67c4 100644 --- a/chrome/renderer/print_web_view_helper.cc +++ b/chrome/renderer/print_web_view_helper.cc @@ -575,12 +575,7 @@ void PrintWebViewHelper::GetPageSizeAndMarginsInPoints( 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) { + PageSizeMargins* page_layout_in_points) { int dpi = GetDPI(&default_params); WebSize page_size_in_pixels( @@ -612,38 +607,30 @@ void PrintWebViewHelper::GetPageSizeAndMarginsInPoints( 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); + page_layout_in_points->content_width = + ConvertPixelsToPoint(page_size_in_pixels.width - + margin_left_in_pixels - + margin_right_in_pixels); + page_layout_in_points->content_height = + 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); + if (page_layout_in_points->content_width < 1.0 || + page_layout_in_points->content_height < 1.0) { + GetPageSizeAndMarginsInPoints(NULL, page_index, default_params, + page_layout_in_points); return; } - if (margin_top_in_points) - *margin_top_in_points = + page_layout_in_points->margin_top = ConvertPixelsToPointDouble(margin_top_in_pixels); - if (margin_right_in_points) - *margin_right_in_points = + page_layout_in_points->margin_right = ConvertPixelsToPointDouble(margin_right_in_pixels); - if (margin_bottom_in_points) - *margin_bottom_in_points = + page_layout_in_points->margin_bottom = ConvertPixelsToPointDouble(margin_bottom_in_pixels); - if (margin_left_in_points) - *margin_left_in_points = + page_layout_in_points->margin_left = ConvertPixelsToPointDouble(margin_left_in_pixels); } @@ -651,28 +638,27 @@ void PrintWebViewHelper::UpdatePrintableSizeInPrintParameters( WebFrame* frame, WebNode* node, PrintMsg_Print_Params* 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; PrepareFrameAndViewForPrint prepare(*params, frame, node); + PageSizeMargins page_layout_in_points; PrintWebViewHelper::GetPageSizeAndMarginsInPoints(frame, 0, *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); + &page_layout_in_points); int dpi = GetDPI(params); params->printable_size = gfx::Size( - static_cast<int>(ConvertUnitDouble(content_width_in_points, + static_cast<int>(ConvertUnitDouble( + page_layout_in_points.content_width, printing::kPointsPerInch, dpi)), - static_cast<int>(ConvertUnitDouble(content_height_in_points, + static_cast<int>(ConvertUnitDouble( + page_layout_in_points.content_height, printing::kPointsPerInch, dpi))); - double page_width_in_points = content_width_in_points + - margin_left_in_points + margin_right_in_points; - double page_height_in_points = content_height_in_points + - margin_top_in_points + margin_bottom_in_points; + double page_width_in_points = + page_layout_in_points.content_width + + page_layout_in_points.margin_left + + page_layout_in_points.margin_right; + double page_height_in_points = + page_layout_in_points.content_height + + page_layout_in_points.margin_top + + page_layout_in_points.margin_bottom; params->page_size = gfx::Size( static_cast<int>(ConvertUnitDouble( @@ -681,9 +667,9 @@ void PrintWebViewHelper::UpdatePrintableSizeInPrintParameters( page_height_in_points, printing::kPointsPerInch, dpi))); params->margin_top = static_cast<int>(ConvertUnitDouble( - margin_top_in_points, printing::kPointsPerInch, dpi)); + page_layout_in_points.margin_top, printing::kPointsPerInch, dpi)); params->margin_left = static_cast<int>(ConvertUnitDouble( - margin_left_in_points, printing::kPointsPerInch, dpi)); + page_layout_in_points.margin_left, printing::kPointsPerInch, dpi)); } bool PrintWebViewHelper::InitPrintSettings(WebKit::WebFrame* frame, diff --git a/chrome/renderer/print_web_view_helper.h b/chrome/renderer/print_web_view_helper.h index 31e4f04..4bae6dc 100644 --- a/chrome/renderer/print_web_view_helper.h +++ b/chrome/renderer/print_web_view_helper.h @@ -66,6 +66,16 @@ class PrepareFrameAndViewForPrint { DISALLOW_COPY_AND_ASSIGN(PrepareFrameAndViewForPrint); }; +// Struct that holds margin and content area information of a page. +typedef struct PageSizeMargins { + double content_width; + double content_height; + double margin_top; + double margin_right; + double margin_bottom; + double margin_left; +} PageSizeMargins; + // PrintWebViewHelper handles most of the printing grunt work for RenderView. // We plan on making print asynchronous and that will require copying the DOM // of the document and creating a new WebView with the contents. @@ -222,12 +232,7 @@ class PrintWebViewHelper : public RenderViewObserver, 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); + PageSizeMargins* page_layout_in_points); void UpdatePrintableSizeInPrintParameters(WebKit::WebFrame* frame, WebKit::WebNode* node, diff --git a/chrome/renderer/print_web_view_helper_linux.cc b/chrome/renderer/print_web_view_helper_linux.cc index f293e21..3df18be 100644 --- a/chrome/renderer/print_web_view_helper_linux.cc +++ b/chrome/renderer/print_web_view_helper_linux.cc @@ -169,29 +169,21 @@ void PrintWebViewHelper::PrintPageInternal( const gfx::Size& canvas_size, WebFrame* frame, printing::Metafile* 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, - params.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); + PageSizeMargins page_layout_in_points; + GetPageSizeAndMarginsInPoints(frame, params.page_number, params.params, + &page_layout_in_points); gfx::Size page_size( - content_width_in_points + margin_right_in_points + - margin_left_in_points, - content_height_in_points + margin_top_in_points + - margin_bottom_in_points); - gfx::Rect content_area(margin_left_in_points, margin_top_in_points, - content_width_in_points, content_height_in_points); + page_layout_in_points.content_width + + page_layout_in_points.margin_right + + page_layout_in_points.margin_left, + page_layout_in_points.content_height + + page_layout_in_points.margin_top + + page_layout_in_points.margin_bottom); + gfx::Rect content_area(page_layout_in_points.margin_left, + page_layout_in_points.margin_top, + page_layout_in_points.content_width, + page_layout_in_points.content_height); SkDevice* device = metafile->StartPageForVectorCanvas( params.page_number, page_size, content_area, 1.0f); diff --git a/chrome/renderer/print_web_view_helper_win.cc b/chrome/renderer/print_web_view_helper_win.cc index b25cafd..d627fff 100644 --- a/chrome/renderer/print_web_view_helper_win.cc +++ b/chrome/renderer/print_web_view_helper_win.cc @@ -145,15 +145,9 @@ void PrintWebViewHelper::RenderPreviewPage(int page_number) { void PrintWebViewHelper::RenderPage( const PrintMsg_Print_Params& params, float* scale_factor, int page_number, bool is_preview, WebFrame* frame, scoped_ptr<Metafile>* metafile) { - double content_width_in_points; - double content_height_in_points; - double margin_top_in_points; - double margin_left_in_points; + PageSizeMargins page_layout_in_points; GetPageSizeAndMarginsInPoints(frame, page_number, params, - &content_width_in_points, - &content_height_in_points, - &margin_top_in_points, NULL, NULL, - &margin_left_in_points); + &page_layout_in_points); int width; int height; @@ -166,15 +160,18 @@ void PrintWebViewHelper::RenderPage( // Since WebKit extends the page width depending on the magical scale factor // we make sure the canvas covers the worst case scenario (x2.0 currently). // PrintContext will then set the correct clipping region. - width = static_cast<int>(content_width_in_points * params.max_shrink); - height = static_cast<int>(content_height_in_points * params.max_shrink); + width = static_cast<int>(page_layout_in_points.content_width * + params.max_shrink); + height = static_cast<int>(page_layout_in_points.content_height * + params.max_shrink); } gfx::Size page_size(width, height); - gfx::Rect content_area(static_cast<int>(margin_left_in_points), - static_cast<int>(margin_top_in_points), - static_cast<int>(content_width_in_points), - static_cast<int>(content_height_in_points)); + gfx::Rect content_area( + static_cast<int>(page_layout_in_points.margin_left), + static_cast<int>(page_layout_in_points.margin_top), + static_cast<int>(page_layout_in_points.content_width), + static_cast<int>(page_layout_in_points.content_height)); SkDevice* device = (*metafile)->StartPageForVectorCanvas( page_number, page_size, content_area, frame->getPrintPageShrink(page_number)); |