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

Unified Diff: chrome/renderer/print_web_view_helper.cc

Issue 10168013: [Print Preview] Modified PrepareFrameAndViewPrint class to call the new printBegin function to supp… (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
« chrome/renderer/mock_printer.h ('K') | « chrome/renderer/print_web_view_helper.h ('k') | no next file » | 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 b31cd851cfe5213c2219515b3dde4681cd01e5f7..371514486b12c4e1a9f64f130f1ddaabdee674fd 100644
--- a/chrome/renderer/print_web_view_helper.cc
+++ b/chrome/renderer/print_web_view_helper.cc
@@ -133,8 +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.print_scaling_option ==
+ newParams.params.print_scaling_option &&
oldParams.params.display_header_footer ==
newParams.params.display_header_footer &&
oldParams.params.date == newParams.params.date &&
@@ -302,14 +302,29 @@ void EnsureOrientationMatches(const PrintMsg_Print_Params& css_params,
page_params->printable_area.width()));
}
-void CalculatePrintCanvasSize(const PrintMsg_Print_Params& print_params,
- gfx::Size* result) {
+void ComputePrintParamsInDesiredDpi(const PrintMsg_Print_Params& print_params,
+ gfx::Size* content_size,
+ gfx::Rect* printable_area,
+ gfx::Size* paper_size) {
int dpi = GetDPI(&print_params);
- result->set_width(ConvertUnit(print_params.content_size.width(), dpi,
- print_params.desired_dpi));
-
- result->set_height(ConvertUnit(print_params.content_size.height(), dpi,
- print_params.desired_dpi));
+ content_size->set_width(ConvertUnit(print_params.content_size.width(), dpi,
+ print_params.desired_dpi));
+
+ content_size->set_height(ConvertUnit(print_params.content_size.height(), dpi,
+ print_params.desired_dpi));
+
+ printable_area->SetRect(ConvertUnit(print_params.printable_area.x(), dpi,
+ print_params.desired_dpi),
+ ConvertUnit(print_params.printable_area.y(), dpi,
+ print_params.desired_dpi),
+ ConvertUnit(print_params.printable_area.width(), dpi,
+ print_params.desired_dpi),
+ ConvertUnit(print_params.printable_area.height(), dpi,
+ print_params.desired_dpi));
+ paper_size->SetSize(ConvertUnit(print_params.page_size.width(), dpi,
+ print_params.desired_dpi),
+ ConvertUnit(print_params.page_size.height(), dpi,
+ print_params.desired_dpi));
}
bool PrintingNodeOrPdfFrame(const WebFrame* frame, const WebNode& node) {
@@ -607,15 +622,19 @@ PrepareFrameAndViewForPrint::PrepareFrameAndViewForPrint(
dpi_(static_cast<int>(print_params.dpi)),
expected_pages_count_(0),
use_browser_overlays_(true),
+ print_scaling_option_(print_params.print_scaling_option),
finished_(false) {
gfx::Size canvas_size;
- CalculatePrintCanvasSize(print_params, &canvas_size);
+ gfx::Rect printable_area;
+ gfx::Size paper_size;
+ ComputePrintParamsInDesiredDpi(print_params, &canvas_size, &printable_area,
+ &paper_size);
if (WebFrame* web_frame = web_view_->mainFrame())
prev_scroll_offset_ = web_frame->scrollOffset();
prev_view_size_ = web_view_->size();
- StartPrinting(canvas_size);
+ StartPrinting(canvas_size, printable_area, paper_size);
}
PrepareFrameAndViewForPrint::~PrepareFrameAndViewForPrint() {
@@ -626,18 +645,30 @@ void PrepareFrameAndViewForPrint::UpdatePrintParams(
const PrintMsg_Print_Params& print_params) {
DCHECK(!finished_);
gfx::Size canvas_size;
- CalculatePrintCanvasSize(print_params, &canvas_size);
- if (canvas_size == print_canvas_size_)
+ gfx::Rect printable_area;
+ gfx::Size paper_size;
+ ComputePrintParamsInDesiredDpi(print_params, &canvas_size, &printable_area,
+ &paper_size);
+ if (canvas_size == print_canvas_size_ &&
+ printable_area == printable_area_ &&
+ paper_size == paper_size_ &&
+ print_params.print_scaling_option == print_scaling_option_) {
return;
+ }
frame_->printEnd();
dpi_ = static_cast<int>(print_params.dpi);
- StartPrinting(canvas_size);
+ print_scaling_option_ = print_params.print_scaling_option;
+ StartPrinting(canvas_size, printable_area, paper_size);
}
void PrepareFrameAndViewForPrint::StartPrinting(
- const gfx::Size& print_canvas_size) {
+ const gfx::Size& print_canvas_size,
+ const gfx::Rect& printable_area,
+ const gfx::Size& paper_size) {
print_canvas_size_ = print_canvas_size;
+ printable_area_ = printable_area;
+ paper_size_ = paper_size;
// Layout page according to printer page size. Since WebKit shrinks the
// size of the page automatically (from 125% to 200%) we trick it to
@@ -650,8 +681,13 @@ void PrepareFrameAndViewForPrint::StartPrinting(
web_view_->resize(print_layout_size);
- expected_pages_count_ = frame_->printBegin(print_canvas_size_, node_to_print_,
- dpi_, &use_browser_overlays_);
+ expected_pages_count_ = frame_->printBegin(print_canvas_size_,
+ printable_area_,
+ paper_size_,
+ node_to_print_,
+ dpi_,
+ print_scaling_option_,
+ &use_browser_overlays_);
}
void PrepareFrameAndViewForPrint::FinishPrinting() {
@@ -1214,7 +1250,8 @@ void PrintWebViewHelper::ComputePageLayoutInPointsForCss(
PageSizeMargins* page_layout_in_points) {
PrintMsg_Print_Params params = CalculatePrintParamsForCss(
frame, page_index, page_params, ignore_css_margins,
- page_params.fit_to_paper_size, scale_factor);
+ page_params.print_scaling_option == WebKit::WebPrintFitToPrintableArea,
+ scale_factor);
CalculatePageLayoutFromPrintParams(params, page_layout_in_points);
}
@@ -1229,11 +1266,13 @@ void PrintWebViewHelper::UpdateFrameAndViewFromCssPageLayout(
return;
PrintMsg_Print_Params print_params = CalculatePrintParamsForCss(
frame, 0, params, ignore_css_margins,
- ignore_css_margins && params.fit_to_paper_size, NULL);
+ ignore_css_margins &&
+ params.print_scaling_option == WebKit::WebPrintFitToPrintableArea,
+ NULL);
prepare->UpdatePrintParams(print_params);
}
-bool PrintWebViewHelper::InitPrintSettings() {
+bool PrintWebViewHelper::InitPrintSettings(bool fit_to_paper_size) {
PrintMsg_PrintPages_Params settings;
Send(new PrintHostMsg_GetDefaultPrintSettings(routing_id(),
&settings.params));
@@ -1253,8 +1292,9 @@ bool PrintWebViewHelper::InitPrintSettings() {
// Reset to default values.
ignore_css_margins_ = false;
- settings.params.fit_to_paper_size = true;
settings.pages.clear();
+ settings.params.print_scaling_option = fit_to_paper_size ?
+ WebKit::WebPrintFitToPrintableArea : WebKit::WebPrintSourceSize;
print_pages_params_.reset(new PrintMsg_PrintPages_Params(settings));
return result;
@@ -1264,7 +1304,10 @@ bool PrintWebViewHelper::InitPrintSettingsAndPrepareFrame(
WebKit::WebFrame* frame, const WebKit::WebNode& node,
scoped_ptr<PrepareFrameAndViewForPrint>* prepare) {
DCHECK(frame);
- if (!InitPrintSettings()) {
+
+ // If the source is html, fit to paper size else print the source pdf size.
+ bool fit_to_paper_size = !(PrintingNodeOrPdfFrame(frame, node));
+ if (!InitPrintSettings(fit_to_paper_size)) {
notify_browser_of_print_failure_ = false;
render_view()->RunModalAlertDialog(
frame,
@@ -1381,9 +1424,22 @@ bool PrintWebViewHelper::UpdatePrintSettings(
settings.params.print_to_pdf = IsPrintToPdfRequested(*job_settings);
UpdateFrameMarginsCssInfo(*job_settings);
- // Fit to paper size.
- settings.params.fit_to_paper_size = source_is_html &&
- !IsPrintToPdfRequested(*job_settings);
+ // Fit to Paper Size.
+ WebKit::WebPrintScalingOption scaling_option =
vandebo (ex-Chrome) 2012/04/23 21:42:19 nit: No need for a local variable, just set the on
kmadhusu 2012/05/11 21:36:02 I have added a new function GetPrintScalingOption(
+ WebKit::WebPrintFitToPrintableArea;
+ if (print_for_preview_ || settings.params.print_to_pdf) {
+ scaling_option = WebKit::WebPrintSourceSize;
+ } else if (!source_is_html) {
+ bool fit_to_paper_size = false;
+ job_settings->GetBoolean(printing::kSettingFitToPageEnabled,
kmadhusu 2012/04/23 17:39:10 (We will send FitToPage option along with JobSetti
vandebo (ex-Chrome) 2012/04/23 21:42:19 nit: Do you want to create another method like IsP
kmadhusu 2012/05/11 21:36:02 Added FitToPageEnabled() and GetPrintScalingOption
+ &(fit_to_paper_size));
+ if ((settings.params.is_first_request &&
+ frame->isPrintScalingDisabledForPlugin(
+ print_preview_context_.node())) ||
+ !(fit_to_paper_size)) {
+ scaling_option = WebKit::WebPrintScaleNone;
+ }
+ settings.params.print_scaling_option = scaling_option;
// Header/Footer: Set |header_footer_info_|.
if (settings.params.display_header_footer) {
« chrome/renderer/mock_printer.h ('K') | « chrome/renderer/print_web_view_helper.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698