summaryrefslogtreecommitdiffstats
path: root/chrome/renderer
diff options
context:
space:
mode:
authorkmadhusu@chromium.org <kmadhusu@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-04-20 02:45:46 +0000
committerkmadhusu@chromium.org <kmadhusu@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-04-20 02:45:46 +0000
commitb963516676ef524cfa75da691a05b6aff1a3d175 (patch)
treeb991ff3675675af6ab7f7a5a1341351829454bf7 /chrome/renderer
parentdcd657a01f7a93f81b3cb23ffe8d27c9a4adadbb (diff)
downloadchromium_src-b963516676ef524cfa75da691a05b6aff1a3d175.zip
chromium_src-b963516676ef524cfa75da691a05b6aff1a3d175.tar.gz
chromium_src-b963516676ef524cfa75da691a05b6aff1a3d175.tar.bz2
[Print Preview] Refactored code to support auto fit to page functionality.
(1) Added |fit_to_paper_size| member variable in PrintMsg_Print_Params. (2) Removed |fit_to_page_| from PrintWebViewHelper. (3) Modified PrintWebViewHelper member functions accordingly. BUG=85132 TEST=none Review URL: http://codereview.chromium.org/10142002 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@133131 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/renderer')
-rw-r--r--chrome/renderer/mock_printer.cc3
-rw-r--r--chrome/renderer/mock_printer.h3
-rw-r--r--chrome/renderer/print_web_view_helper.cc44
-rw-r--r--chrome/renderer/print_web_view_helper.h11
-rw-r--r--chrome/renderer/print_web_view_helper_linux.cc6
-rw-r--r--chrome/renderer/print_web_view_helper_mac.mm6
-rw-r--r--chrome/renderer/print_web_view_helper_win.cc4
7 files changed, 36 insertions, 41 deletions
diff --git a/chrome/renderer/mock_printer.cc b/chrome/renderer/mock_printer.cc
index 949e588..5848ce8 100644
--- a/chrome/renderer/mock_printer.cc
+++ b/chrome/renderer/mock_printer.cc
@@ -65,6 +65,7 @@ MockPrinter::MockPrinter()
is_first_request_(true),
print_to_pdf_(false),
preview_request_id_(0),
+ fit_to_paper_size_(true),
display_header_footer_(false),
date_(ASCIIToUTF16("date")),
title_(ASCIIToUTF16("title")),
@@ -150,6 +151,7 @@ void MockPrinter::ScriptedPrint(int cookie,
settings->params.content_size = content_size_;
settings->params.printable_area = printable_area_;
settings->params.is_first_request = is_first_request_;
+ settings->params.fit_to_paper_size = fit_to_paper_size_;
settings->params.print_to_pdf = print_to_pdf_;
settings->params.preview_request_id = preview_request_id_;
settings->params.display_header_footer = display_header_footer_;
@@ -303,6 +305,7 @@ void MockPrinter::SetPrintParams(PrintMsg_Print_Params* params) {
params->margin_left = margin_left_;
params->margin_top = margin_top_;
params->is_first_request = is_first_request_;
+ params->fit_to_paper_size = fit_to_paper_size_;
params->print_to_pdf = print_to_pdf_;
params->preview_request_id = preview_request_id_;
params->display_header_footer = display_header_footer_;
diff --git a/chrome/renderer/mock_printer.h b/chrome/renderer/mock_printer.h
index 255dbd8..d75129e 100644
--- a/chrome/renderer/mock_printer.h
+++ b/chrome/renderer/mock_printer.h
@@ -143,6 +143,9 @@ class MockPrinter {
bool print_to_pdf_;
int preview_request_id_;
+ // True if we want to fit the html/pdf source to paper size.
+ bool fit_to_paper_size_;
+
// Used for displaying headers and footers.
bool display_header_footer_;
string16 date_;
diff --git a/chrome/renderer/print_web_view_helper.cc b/chrome/renderer/print_web_view_helper.cc
index b32ee66..b31cd85 100644
--- a/chrome/renderer/print_web_view_helper.cc
+++ b/chrome/renderer/print_web_view_helper.cc
@@ -133,6 +133,8 @@ bool PrintMsg_Print_Params_IsEqual(
newParams.params.supports_alpha_blend &&
oldParams.pages.size() == newParams.pages.size() &&
oldParams.params.print_to_pdf == newParams.params.print_to_pdf &&
+ oldParams.params.fit_to_paper_size ==
+ newParams.params.fit_to_paper_size &&
oldParams.params.display_header_footer ==
newParams.params.display_header_footer &&
oldParams.params.date == newParams.params.date &&
@@ -669,7 +671,6 @@ PrintWebViewHelper::PrintWebViewHelper(content::RenderView* render_view)
is_preview_enabled_(IsPrintPreviewEnabled()),
is_print_ready_metafile_sent_(false),
ignore_css_margins_(false),
- fit_to_page_(true),
user_cancelled_scripted_print_count_(0),
is_scripted_printing_blocked_(false),
notify_browser_of_print_failure_(true),
@@ -893,15 +894,14 @@ bool PrintWebViewHelper::CreatePreviewDocument() {
PrintMsg_Print_Params print_params = print_pages_params_->params;
const std::vector<int>& pages = print_pages_params_->pages;
if (!print_preview_context_.CreatePreviewDocument(&print_params, pages,
- ignore_css_margins_,
- fit_to_page_)) {
+ ignore_css_margins_)) {
return false;
}
PageSizeMargins default_page_layout;
ComputePageLayoutInPointsForCss(print_preview_context_.frame(), 0,
- print_params, ignore_css_margins_,
- fit_to_page_, NULL, &default_page_layout);
+ print_params, ignore_css_margins_, NULL,
+ &default_page_layout);
if (!old_print_pages_params_.get() ||
!PageLayoutIsEqual(*old_print_pages_params_, *print_pages_params_)) {
@@ -1171,8 +1171,7 @@ bool PrintWebViewHelper::PrintPages(WebFrame* frame, const WebNode& node) {
const PrintMsg_Print_Params& print_params = params.params;
PrepareFrameAndViewForPrint prep_frame_view(print_params, frame, node);
UpdateFrameAndViewFromCssPageLayout(frame, node, &prep_frame_view,
- print_params, ignore_css_margins_,
- fit_to_page_);
+ print_params, ignore_css_margins_);
int page_count = prep_frame_view.GetExpectedPageCount();
if (!page_count)
@@ -1211,14 +1210,11 @@ void PrintWebViewHelper::ComputePageLayoutInPointsForCss(
int page_index,
const PrintMsg_Print_Params& page_params,
bool ignore_css_margins,
- bool fit_to_page,
double* scale_factor,
PageSizeMargins* page_layout_in_points) {
- PrintMsg_Print_Params params = CalculatePrintParamsForCss(frame, page_index,
- page_params,
- ignore_css_margins,
- fit_to_page,
- scale_factor);
+ PrintMsg_Print_Params params = CalculatePrintParamsForCss(
+ frame, page_index, page_params, ignore_css_margins,
+ page_params.fit_to_paper_size, scale_factor);
CalculatePageLayoutFromPrintParams(params, page_layout_in_points);
}
@@ -1228,13 +1224,12 @@ void PrintWebViewHelper::UpdateFrameAndViewFromCssPageLayout(
const WebNode& node,
PrepareFrameAndViewForPrint* prepare,
const PrintMsg_Print_Params& params,
- bool ignore_css_margins,
- bool fit_to_page) {
+ bool ignore_css_margins) {
if (PrintingNodeOrPdfFrame(frame, node))
return;
PrintMsg_Print_Params print_params = CalculatePrintParamsForCss(
- frame, 0, params, ignore_css_margins, ignore_css_margins && fit_to_page,
- NULL);
+ frame, 0, params, ignore_css_margins,
+ ignore_css_margins && params.fit_to_paper_size, NULL);
prepare->UpdatePrintParams(print_params);
}
@@ -1258,7 +1253,7 @@ bool PrintWebViewHelper::InitPrintSettings() {
// Reset to default values.
ignore_css_margins_ = false;
- fit_to_page_ = true;
+ settings.params.fit_to_paper_size = true;
settings.pages.clear();
print_pages_params_.reset(new PrintMsg_PrintPages_Params(settings));
@@ -1282,7 +1277,7 @@ bool PrintWebViewHelper::InitPrintSettingsAndPrepareFrame(
frame, node));
UpdateFrameAndViewFromCssPageLayout(frame, node, prepare->get(),
print_pages_params_->params,
- ignore_css_margins_, fit_to_page_);
+ ignore_css_margins_);
Send(new PrintHostMsg_DidGetDocumentCookie(
routing_id(), print_pages_params_->params.document_cookie));
return true;
@@ -1385,7 +1380,10 @@ bool PrintWebViewHelper::UpdatePrintSettings(
settings.params.print_to_pdf = IsPrintToPdfRequested(*job_settings);
UpdateFrameMarginsCssInfo(*job_settings);
- fit_to_page_ = source_is_html && !IsPrintToPdfRequested(*job_settings);
+
+ // Fit to paper size.
+ settings.params.fit_to_paper_size = source_is_html &&
+ !IsPrintToPdfRequested(*job_settings);
// Header/Footer: Set |header_footer_info_|.
if (settings.params.display_header_footer) {
@@ -1639,8 +1637,7 @@ void PrintWebViewHelper::PrintPreviewContext::OnPrintPreview() {
bool PrintWebViewHelper::PrintPreviewContext::CreatePreviewDocument(
PrintMsg_Print_Params* print_params,
const std::vector<int>& pages,
- bool ignore_css_margins,
- bool fit_to_page) {
+ bool ignore_css_margins) {
DCHECK_EQ(INITIALIZED, state_);
state_ = RENDERING;
@@ -1655,8 +1652,7 @@ bool PrintWebViewHelper::PrintPreviewContext::CreatePreviewDocument(
prep_frame_view_.reset(new PrepareFrameAndViewForPrint(*print_params, frame(),
node()));
UpdateFrameAndViewFromCssPageLayout(frame_, node_, prep_frame_view_.get(),
- *print_params, ignore_css_margins,
- fit_to_page);
+ *print_params, ignore_css_margins);
print_params_.reset(new PrintMsg_Print_Params(*print_params));
diff --git a/chrome/renderer/print_web_view_helper.h b/chrome/renderer/print_web_view_helper.h
index 99eb0a9..55a2e6b 100644
--- a/chrome/renderer/print_web_view_helper.h
+++ b/chrome/renderer/print_web_view_helper.h
@@ -286,7 +286,6 @@ class PrintWebViewHelper
int page_index,
const PrintMsg_Print_Params& default_params,
bool ignore_css_margins,
- bool fit_to_page,
double* scale_factor,
printing::PageSizeMargins* page_layout_in_points);
@@ -297,8 +296,7 @@ class PrintWebViewHelper
const WebKit::WebNode& node,
PrepareFrameAndViewForPrint* prepare,
const PrintMsg_Print_Params& params,
- bool ignore_css_margins,
- bool fit_to_page);
+ bool ignore_css_margins);
// Given the |device| and |canvas| to draw on, prints the appropriate headers
// and footers using strings from |header_footer_info| on to the canvas.
@@ -355,10 +353,6 @@ class PrintWebViewHelper
bool is_print_ready_metafile_sent_;
bool ignore_css_margins_;
- // True if we need to auto fit to page else false.
- // NOTE: When we print to pdf, we don't fit to page.
- bool fit_to_page_;
-
// Used for scripted initiated printing blocking.
base::Time last_cancelled_script_print_;
int user_cancelled_scripted_print_count_;
@@ -394,8 +388,7 @@ class PrintWebViewHelper
// Create the print preview document. |pages| is empty to print all pages.
bool CreatePreviewDocument(PrintMsg_Print_Params* params,
const std::vector<int>& pages,
- bool ignore_css_margins,
- bool fit_to_page);
+ bool ignore_css_margins);
// Called after a page gets rendered. |page_time| is how long the
// rendering took.
diff --git a/chrome/renderer/print_web_view_helper_linux.cc b/chrome/renderer/print_web_view_helper_linux.cc
index 1101dbc1..a132019 100644
--- a/chrome/renderer/print_web_view_helper_linux.cc
+++ b/chrome/renderer/print_web_view_helper_linux.cc
@@ -143,7 +143,7 @@ bool PrintWebViewHelper::RenderPages(const PrintMsg_PrintPages_Params& params,
printing::Metafile* metafile) {
PrintMsg_Print_Params print_params = params.params;
UpdateFrameAndViewFromCssPageLayout(frame, node, prepare, print_params,
- ignore_css_margins_, fit_to_page_);
+ ignore_css_margins_);
*page_count = prepare->GetExpectedPageCount();
if (!*page_count)
@@ -183,8 +183,8 @@ void PrintWebViewHelper::PrintPageInternal(
printing::PageSizeMargins page_layout_in_points;
double scale_factor = 1.0f;
ComputePageLayoutInPointsForCss(frame, params.page_number, params.params,
- ignore_css_margins_, fit_to_page_,
- &scale_factor, &page_layout_in_points);
+ ignore_css_margins_, &scale_factor,
+ &page_layout_in_points);
gfx::Size page_size;
gfx::Rect content_area;
GetPageSizeAndContentAreaFromPageLayout(page_layout_in_points, &page_size,
diff --git a/chrome/renderer/print_web_view_helper_mac.mm b/chrome/renderer/print_web_view_helper_mac.mm
index 508fde2..6ff16c9 100644
--- a/chrome/renderer/print_web_view_helper_mac.mm
+++ b/chrome/renderer/print_web_view_helper_mac.mm
@@ -1,4 +1,4 @@
-// Copyright (c) 2011 The Chromium Authors. All rights reserved.
+// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
@@ -142,8 +142,8 @@ void PrintWebViewHelper::RenderPage(
gfx::Rect content_area;
ComputePageLayoutInPointsForCss(frame, page_number, params,
- ignore_css_margins_, fit_to_page_,
- &scale_factor, &page_layout_in_points);
+ ignore_css_margins_, &scale_factor,
+ &page_layout_in_points);
GetPageSizeAndContentAreaFromPageLayout(page_layout_in_points, page_size,
&content_area);
if (content_rect)
diff --git a/chrome/renderer/print_web_view_helper_win.cc b/chrome/renderer/print_web_view_helper_win.cc
index 8433752..e3fd154 100644
--- a/chrome/renderer/print_web_view_helper_win.cc
+++ b/chrome/renderer/print_web_view_helper_win.cc
@@ -220,8 +220,8 @@ Metafile* PrintWebViewHelper::RenderPage(
printing::PageSizeMargins page_layout_in_points;
double css_scale_factor = 1.0f;
ComputePageLayoutInPointsForCss(frame, page_number, params,
- ignore_css_margins_, fit_to_page_,
- &css_scale_factor, &page_layout_in_points);
+ ignore_css_margins_, &css_scale_factor,
+ &page_layout_in_points);
gfx::Size page_size;
gfx::Rect content_area;
GetPageSizeAndContentAreaFromPageLayout(page_layout_in_points, &page_size,