Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1343)

Unified Diff: chrome/renderer/print_web_view_helper.cc

Issue 10142002: [Print Preview] Refactored code to support auto fit to page functionality. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « chrome/renderer/print_web_view_helper.h ('k') | chrome/renderer/print_web_view_helper_linux.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 ae6fc69fdcbb0688d31e2932dcd353db78d26d32..b5e12679d45842b9959104f00592665698d20834 100644
--- a/chrome/renderer/print_web_view_helper.cc
+++ b/chrome/renderer/print_web_view_helper.cc
@@ -129,6 +129,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 &&
@@ -663,7 +665,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),
@@ -887,15 +888,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_)) {
@@ -1165,8 +1165,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)
@@ -1205,14 +1204,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);
}
@@ -1222,17 +1218,17 @@ 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);
}
-bool PrintWebViewHelper::InitPrintSettings() {
+bool PrintWebViewHelper::InitPrintSettings(WebKit::WebFrame* frame,
+ const WebKit::WebNode& node) {
PrintMsg_PrintPages_Params settings;
Send(new PrintHostMsg_GetDefaultPrintSettings(routing_id(),
&settings.params));
@@ -1252,9 +1248,11 @@ bool PrintWebViewHelper::InitPrintSettings() {
// Reset to default values.
ignore_css_margins_ = false;
- fit_to_page_ = true;
settings.pages.clear();
+ settings.params.fit_to_paper_size = !(PrintingNodeOrPdfFrame(frame, node) &&
vandebo (ex-Chrome) 2012/04/19 23:56:07 Looks like there's only one caller to this method.
kmadhusu 2012/04/20 00:36:37 ok.
+ frame->isPrintScalingDisabledForPlugin(node));
vandebo (ex-Chrome) 2012/04/19 23:56:07 Is this a change in behavior? For a refactoring c
kmadhusu 2012/04/20 00:36:37 Reverted the changes.
+
print_pages_params_.reset(new PrintMsg_PrintPages_Params(settings));
return result;
}
@@ -1263,7 +1261,7 @@ bool PrintWebViewHelper::InitPrintSettingsAndPrepareFrame(
WebKit::WebFrame* frame, const WebKit::WebNode& node,
scoped_ptr<PrepareFrameAndViewForPrint>* prepare) {
DCHECK(frame);
- if (!InitPrintSettings()) {
+ if (!InitPrintSettings(frame, node)) {
notify_browser_of_print_failure_ = false;
render_view()->RunModalAlertDialog(
frame,
@@ -1276,7 +1274,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;
@@ -1379,7 +1377,15 @@ 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.
+ bool fit_to_paper_size = true;
vandebo (ex-Chrome) 2012/04/19 23:56:07 Looks like you're making changes here as well.
kmadhusu 2012/04/20 00:36:37 Reverted these changes.
+ if (print_for_preview_ || IsPrintToPdfRequested(*job_settings) ||
+ (PrintingNodeOrPdfFrame(frame, node) &&
+ frame->isPrintScalingDisabledForPlugin(node))) {
+ fit_to_paper_size = false;
+ }
+ settings.params.fit_to_paper_size = fit_to_paper_size;
vandebo (ex-Chrome) 2012/04/19 23:56:07 Looks like you can negate the conditional in the i
kmadhusu 2012/04/20 00:36:37 Will do this in the next CL.
// Header/Footer: Set |header_footer_info_|.
if (settings.params.display_header_footer) {
@@ -1633,8 +1639,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;
@@ -1649,8 +1654,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));
« no previous file with comments | « chrome/renderer/print_web_view_helper.h ('k') | chrome/renderer/print_web_view_helper_linux.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698