0

Patch up excessive margins until we can get the real fix plumbed through.

BUG=92000
TEST=NONE

Review URL: http://codereview.chromium.org/8173016

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@104442 0039d316-1c4b-4281-b951-d872f2087c98
This commit is contained in:
vandebo@chromium.org
2011-10-07 06:12:40 +00:00
parent 83deae2710
commit 06bd186663
4 changed files with 37 additions and 17 deletions

@ -143,6 +143,22 @@ void CalculatePrintCanvasSize(const PrintMsg_Print_Params& print_params,
print_params.desired_dpi));
}
bool PrintingNodeOrPdfFrame(const WebFrame* frame, const WebNode& node) {
if (!node.isNull())
return true;
std::string mime(frame->dataSource()->response().mimeType().utf8());
return mime == "application/pdf";
}
void SetMarginsForPDF(PrintMsg_Print_Params* settings) {
// This is the wrong way to do this. But the pipeline for the right way is
// too long. This will be removed soon. http://crbug.com/92000
settings->margin_top = 0;
settings->margin_left = 0;
settings->printable_size.set_width(settings->page_size.width());
settings->printable_size.set_height(settings->page_size.height());
}
// Get the margins option selected and set custom margins appropriately.
void SetCustomMarginsIfSelected(const DictionaryValue& job_settings,
PrintMsg_PrintPages_Params* settings) {
@ -1008,6 +1024,8 @@ void PrintWebViewHelper::UpdatePrintableSizeInPrintParameters(
const WebNode& node,
PrepareFrameAndViewForPrint* prepare,
PrintMsg_Print_Params* params) {
if (PrintingNodeOrPdfFrame(frame, node))
return;
PageSizeMargins page_layout_in_points;
PrintWebViewHelper::GetPageSizeAndMarginsInPoints(frame, 0, *params,
&page_layout_in_points);
@ -1091,9 +1109,9 @@ bool PrintWebViewHelper::InitPrintSettingsAndPrepareFrame(
}
bool PrintWebViewHelper::UpdatePrintSettings(
const DictionaryValue& job_settings, bool is_preview) {
const DictionaryValue& job_settings, bool generating_preview) {
if (job_settings.empty()) {
if (is_preview)
if (generating_preview)
print_preview_context_.set_error(PREVIEW_ERROR_BAD_SETTING);
return false;
}
@ -1108,7 +1126,7 @@ bool PrintWebViewHelper::UpdatePrintSettings(
print_pages_params_.reset(new PrintMsg_PrintPages_Params(settings));
if (PrintMsg_Print_Params_IsEmpty(settings.params)) {
if (is_preview) {
if (generating_preview) {
print_preview_context_.set_error(PREVIEW_ERROR_INVALID_PRINTER_SETTINGS);
} else {
WebKit::WebFrame* frame = print_preview_context_.frame();
@ -1130,7 +1148,7 @@ bool PrintWebViewHelper::UpdatePrintSettings(
return false;
}
if (is_preview) {
if (generating_preview) {
// Validate expected print preview settings.
if (!job_settings.GetString(printing::kPreviewUIAddr,
&(settings.params.preview_ui_addr)) ||
@ -1171,6 +1189,12 @@ bool PrintWebViewHelper::UpdatePrintSettings(
}
}
if ((is_preview_ && !generating_preview) ||
PrintingNodeOrPdfFrame(print_preview_context_.frame(),
print_preview_context_.node())) {
SetMarginsForPDF(&settings.params);
}
print_pages_params_.reset(new PrintMsg_PrintPages_Params(settings));
Send(new PrintHostMsg_DidGetDocumentCookie(routing_id(),
settings.params.document_cookie));
@ -1505,13 +1529,8 @@ bool PrintWebViewHelper::PrintPreviewContext::IsReadyToRender() const {
}
bool PrintWebViewHelper::PrintPreviewContext::IsModifiable() const {
// TODO(vandebo) I think this should only return false if the content is a
// PDF, just because we are printing a particular node does not mean it's
// a PDF (right?), we should check the mime type of the node.
if (!node().isNull())
return false;
std::string mime(frame()->dataSource()->response().mimeType().utf8());
return mime != "application/pdf";
// The only kind of node we can print right now is a PDF node.
return !PrintingNodeOrPdfFrame(frame(), node());
}
bool PrintWebViewHelper::PrintPreviewContext::IsLastPageOfPrintReadyMetafile()

@ -189,7 +189,7 @@ class PrintWebViewHelper
// dictionary contains print job details such as printer name, number of
// copies, page range, etc.
bool UpdatePrintSettings(const base::DictionaryValue& job_settings,
bool is_preview);
bool generating_preview);
// Get final print settings from the user.
// Return false if the user cancels or on error.

@ -68,9 +68,9 @@ const int kSettingHeaderFooterFontSize = 8;
// Number of horizontal regions for headers and footers.
const float kSettingHeaderFooterHorizontalRegions = 3;
// Interstice or gap between different header footer components.
// Hardcoded to 0.25cm = 1/10" = 7.2points.
const float kSettingHeaderFooterInterstice = 7.2f;
// Interstice or gap between different header footer components. Hardcoded to
// about 0.5cm, match the value in PrintSettings::SetPrinterPrintableArea.
const float kSettingHeaderFooterInterstice = 14.2f;
// Key that specifies the date of the page that will be printed in the headers
// and footers.

@ -5,6 +5,7 @@
#include "printing/print_settings.h"
#include "base/atomic_sequence_num.h"
#include "printing/print_job_constants.h"
#include "printing/units.h"
namespace printing {
@ -54,8 +55,8 @@ void PrintSettings::SetPrinterPrintableArea(
int margin_printer_units = 0;
if (use_overlays) {
// Hard-code text_height = 0.5cm = ~1/5 of inch.
header_footer_text_height = ConvertUnit(500, kHundrethsMMPerInch,
units_per_inch);
header_footer_text_height = ConvertUnit(kSettingHeaderFooterInterstice,
kPointsPerInch, units_per_inch);
// Default margins 1.0cm = ~2/5 of an inch.
margin_printer_units = ConvertUnit(1000, kHundrethsMMPerInch,
units_per_inch);