Chromium Code Reviews| Index: chrome/browser/printing/printing_message_filter.cc |
| diff --git a/chrome/browser/printing/printing_message_filter.cc b/chrome/browser/printing/printing_message_filter.cc |
| index f74fdc07d19eef2e63b49f41aaacc1b317485247..9f308f8b559b79ead92b6ab4422591bb1ae92c75 100644 |
| --- a/chrome/browser/printing/printing_message_filter.cc |
| +++ b/chrome/browser/printing/printing_message_filter.cc |
| @@ -4,12 +4,19 @@ |
| #include "chrome/browser/printing/printing_message_filter.h" |
| +#include "base/i18n/time_formatting.h" |
| #include "base/process_util.h" |
| +#include "base/string_number_conversions.h" |
| +#include "base/time.h" |
| +#include "base/utf_string_conversions.h" |
| #include "chrome/browser/browser_process.h" |
| #include "chrome/browser/printing/printer_query.h" |
| #include "chrome/browser/printing/print_job_manager.h" |
| #include "chrome/common/print_messages.h" |
| #include "content/common/view_messages.h" |
| +#include "printing/print_job_constants.h" |
| +#include "printing/units.h" |
| +#include "ui/base/text/text_elider.h" |
| #if defined(OS_CHROMEOS) |
| #include <fcntl.h> |
| @@ -22,6 +29,12 @@ |
| #include "chrome/common/chrome_switches.h" |
| #endif |
| +using base::Time; |
| +using printing::ConvertPointsToPixelDouble; |
| +using printing::ConvertUnitDouble; |
| +using printing::GetSegmentWidth; |
| +using printing::GetDPI; |
| + |
| namespace { |
| #if defined(OS_CHROMEOS) |
| @@ -275,6 +288,25 @@ void PrintingMessageFilter::OnUpdatePrintSettings( |
| IPC::Message* reply_msg) { |
| scoped_refptr<printing::PrinterQuery> printer_query; |
| print_job_manager_->PopPrinterQuery(document_cookie, &printer_query); |
| + |
| + // Getting Header and Footer settings. |
| + if (!job_settings.GetBoolean(printing::kSettingHeaderFooterEnabled, |
| + &display_header_footer_)) { |
| + NOTREACHED(); |
| + } |
| + |
| + if (display_header_footer_) { |
| + string16 title; |
| + std::string url; |
| + if (!job_settings.GetString(printing::kSettingHeaderFooterTitle, &title) || |
| + !job_settings.GetString(printing::kSettingHeaderFooterURL, &url)) { |
| + NOTREACHED(); |
| + } |
| + header_footer_info_.reset(new DictionaryValue()); |
| + header_footer_info_->SetString(printing::kSettingHeaderFooterURL, url); |
| + header_footer_info_->SetString(printing::kSettingHeaderFooterTitle, title); |
| + } |
| + |
| if (printer_query.get()) { |
| CancelableTask* task = NewRunnableMethod( |
| this, |
| @@ -285,6 +317,40 @@ void PrintingMessageFilter::OnUpdatePrintSettings( |
| } |
| } |
| +void UpdateHeaderFooterStrings(const base::DictionaryValue& header_footer_info, |
|
vandebo (ex-Chrome)
2011/08/11 23:32:13
What process adds the strings to params? Can the
Aayush Kumar
2011/08/12 08:35:40
As discussed, this is the browser process. :)
|
| + PrintMsg_PrintPages_Params* params) { |
| + string16 date = base::TimeFormatShortDateNumeric(Time::Now()); |
| + string16 title; |
| + std::string url; |
| + if (!header_footer_info.GetString(printing::kSettingHeaderFooterTitle, |
| + &title) || |
| + !header_footer_info.GetString(printing::kSettingHeaderFooterURL, |
| + &url)) { |
| + NOTREACHED(); |
| + } |
| + |
| + gfx::Font font(UTF8ToUTF16(printing::kSettingHeaderFooterFontName), |
| + ceil(ConvertPointsToPixelDouble( |
| + printing::kSettingHeaderFooterFontSize))); |
| + double segment_width = GetSegmentWidth(ConvertUnitDouble( |
| + params->params.page_size.width(), GetDPI(¶ms->params), |
| + printing::kPixelsPerInch)); |
| + params->params.date = ui::ElideText(date, font, segment_width, false); |
| + |
| + // Calculate the available title width. If the date string is not long |
| + // enough, increase the available space for the title. |
| + // Assumes there is no header text to RIGHT of title. |
| + double date_width = font.GetStringWidth(date); |
| + SkScalar max_title_width = std::min(2 * segment_width, |
| + 2 * (segment_width - date_width) + |
| + segment_width); |
| + params->params.title = ui::ElideText(title, font, max_title_width, false); |
| + |
| + double max_url_width = 2 * segment_width; |
| + GURL gurl(url); |
| + params->params.url = ui::ElideUrl(gurl, font, max_url_width, std::string()); |
| +} |
| + |
| void PrintingMessageFilter::OnUpdatePrintSettingsReply( |
| scoped_refptr<printing::PrinterQuery> printer_query, |
| IPC::Message* reply_msg) { |
| @@ -296,6 +362,9 @@ void PrintingMessageFilter::OnUpdatePrintSettingsReply( |
| params.params.document_cookie = printer_query->cookie(); |
| params.pages = |
| printing::PageRange::GetPages(printer_query->settings().ranges); |
| + |
| + if (display_header_footer_) |
| + UpdateHeaderFooterStrings(*header_footer_info_, ¶ms); |
| } |
| PrintHostMsg_UpdatePrintSettings::WriteReplyParams(reply_msg, params); |
| Send(reply_msg); |