summaryrefslogtreecommitdiffstats
path: root/chrome/renderer/print_web_view_helper.cc
diff options
context:
space:
mode:
authorvandebo@chromium.org <vandebo@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-10-07 06:12:40 +0000
committervandebo@chromium.org <vandebo@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-10-07 06:12:40 +0000
commit06bd186663697846e43c040f249f3f1109c1445e (patch)
treee60dc94d7ef79475e62ea8bdc7220c614028e7fb /chrome/renderer/print_web_view_helper.cc
parent83deae27106077366e8ae894798dd440e514d809 (diff)
downloadchromium_src-06bd186663697846e43c040f249f3f1109c1445e.zip
chromium_src-06bd186663697846e43c040f249f3f1109c1445e.tar.gz
chromium_src-06bd186663697846e43c040f249f3f1109c1445e.tar.bz2
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
Diffstat (limited to 'chrome/renderer/print_web_view_helper.cc')
-rw-r--r--chrome/renderer/print_web_view_helper.cc41
1 files changed, 30 insertions, 11 deletions
diff --git a/chrome/renderer/print_web_view_helper.cc b/chrome/renderer/print_web_view_helper.cc
index 7114a5d..f278ef8 100644
--- a/chrome/renderer/print_web_view_helper.cc
+++ b/chrome/renderer/print_web_view_helper.cc
@@ -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()