Skip to content

Commit

Permalink
Added Header and Footer support in Linux, Windows and Mac for Skia
Browse files Browse the repository at this point in the history
BUG=67514
TEST=
In the preview tab, note added options for printing headers and footers.  Toggle with the checkbox and ensure that the correct headers and footers are displayed.

Committed: http://src.chromium.org/viewvc/chrome?view=rev&revision=97219

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

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@97233 0039d316-1c4b-4281-b951-d872f2087c98
  • Loading branch information
aayushkumar@chromium.org committed Aug 17, 2011
1 parent 4e8e0d1 commit 55b23a0
Show file tree
Hide file tree
Showing 36 changed files with 738 additions and 20 deletions.
6 changes: 6 additions & 0 deletions chrome/app/generated_resources.grd
Original file line number Diff line number Diff line change
Expand Up @@ -5994,6 +5994,12 @@ Keep your key file in a safe place. You will need it to create new versions of y
<message name="IDS_PRINT_PREVIEW_PRINT_PAGES_LABEL" desc="ARIA label used by screen reader to explain the purpose of the page selection textbox">
Print Specific Pages
</message>
<message name="IDS_PRINT_PREVIEW_OPTIONS_LABEL" desc="Options label currently providing the choice to print headers and footers.">
Options
</message>
<message name="IDS_PRINT_PREVIEW_OPTION_HEADER_FOOTER" desc="Checkbox label that provides a choice to print the headers and footers.">
Headers and footers
</message>

<!-- Load State -->
<message name="IDS_LOAD_STATE_WAITING_FOR_DELEGATE">
Expand Down
7 changes: 7 additions & 0 deletions chrome/browser/printing/printing_message_filter.cc
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,13 @@ void RenderParamsFromPrintSettings(const printing::PrintSettings& settings,
params->document_cookie = 0;
params->selection_only = settings.selection_only;
params->supports_alpha_blend = settings.supports_alpha_blend();

params->display_header_footer = settings.display_header_footer;
if (!settings.display_header_footer)
return;
params->date = settings.date;
params->title = settings.title;
params->url = settings.url;
}

} // namespace
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<div id="header-footer-option" class="two-column option visible">
<h1 i18n-content="optionsLabel"></h1>
<div>
<input id="header-footer" type="checkbox" checked>
<label for="header-footer" i18n-content="optionHeaderFooter"></label>
</div>
</div>
68 changes: 68 additions & 0 deletions chrome/browser/resources/print_preview/header_footer_settings.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
// Copyright (c) 2011 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

cr.define('print_preview', function() {
'use strict';

/**
* Creates a HeaderFooterSettings object. This object encapsulates all
* settings and logic related to the headers and footers checkbox.
* @constructor
*/
function HeaderFooterSettings() {
this.headerFooterOption_ = $('header-footer-option');
this.headerFooterCheckbox_ = $('header-footer');
}

cr.addSingletonGetter(HeaderFooterSettings);

HeaderFooterSettings.prototype = {
/**
* The checkbox corresponding to the headers and footers option.
* @type {HTMLInputElement}
*/
get headerFooterCheckbox() {
return this.headerFooterCheckbox_;
},

/**
* Checks whether the Headers and Footers checkbox is checked or not.
* @return {boolean} true if Headers and Footers are checked.
*/
hasHeaderFooter: function() {
return this.headerFooterCheckbox_.checked;
},

/**
* Adding listeners to header footer related controls.
*/
addEventListeners: function() {
this.headerFooterCheckbox_.onclick =
this.onHeaderFooterChanged_.bind(this);
document.addEventListener('PDFLoaded', this.onPDFLoaded_.bind(this));
},

/**
* Listener executing when the user selects or de-selects the headers
* and footers option.
* @private
*/
onHeaderFooterChanged_: function() {
requestPrintPreview();
},

/**
* Listener executing when a PDFLoaded event occurs.
* @private
*/
onPDFLoaded_: function() {
if (!previewModifiable)
fadeOutElement(this.headerFooterOption_);
},
};

return {
HeaderFooterSettings: HeaderFooterSettings,
};
});
8 changes: 8 additions & 0 deletions chrome/browser/resources/print_preview/print_preview.css
Original file line number Diff line number Diff line change
Expand Up @@ -346,6 +346,14 @@ html[os=mac] input[type='checkbox']:checked::before {
top: 2px;
}

html[os=mac] #options-horizontal-separator {
display: none;
}

html[os=mac] #options-option {
display: none;
}

input[type='radio'] {
-webkit-box-shadow: inset 0 1px 2px white,
0 1px 2px rgba(0, 0, 0, .2);
Expand Down
2 changes: 2 additions & 0 deletions chrome/browser/resources/print_preview/print_preview.html
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ <h1 i18n-content="destinationLabel"></h1>
<hr>
<include src="color_settings.html"></include>
<hr>
<include src="header_footer_settings.html"></include>
<hr id="options-horizontal-separator">
<div id="system-dialog-div">
<button id="system-dialog-link" class="link-button"
i18n-content="systemDialogOption"></button>
Expand Down
7 changes: 7 additions & 0 deletions chrome/browser/resources/print_preview/print_preview.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,9 @@ var copiesSettings;
// Object holding all the layout related settings.
var layoutSettings;

// Object holding all the header footer related settings.
var headerFooterSettings;

// Object holding all the color related settings.
var colorSettings;

Expand Down Expand Up @@ -104,10 +107,12 @@ function onLoad() {
pageSettings = print_preview.PageSettings.getInstance();
copiesSettings = print_preview.CopiesSettings.getInstance();
layoutSettings = print_preview.LayoutSettings.getInstance();
headerFooterSettings = print_preview.HeaderFooterSettings.getInstance();
colorSettings = print_preview.ColorSettings.getInstance();
printHeader.addEventListeners();
pageSettings.addEventListeners();
copiesSettings.addEventListeners();
headerFooterSettings.addEventListeners();
layoutSettings.addEventListeners();
colorSettings.addEventListeners();
$('printer-list').onchange = updateControlsWithSelectedPrinterCapabilities;
Expand Down Expand Up @@ -311,6 +316,7 @@ function getSettings() {
'color': colorSettings.isColor(),
'printToPDF': printToPDF,
'isFirstRequest' : false,
'headerFooterEnabled': headerFooterSettings.hasHeaderFooter(),
'requestID': -1};

var printerList = $('printer-list');
Expand Down Expand Up @@ -957,5 +963,6 @@ function setDefaultValuesAndRegeneratePreview() {
<include src="print_header.js"/>
<include src="page_settings.js"/>
<include src="copies_settings.js"/>
<include src="header_footer_settings.js"/>
<include src="layout_settings.js"/>
<include src="color_settings.js"/>
3 changes: 3 additions & 0 deletions chrome/browser/ui/webui/print_preview_data_source.cc
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,9 @@ PrintPreviewDataSource::PrintPreviewDataSource()
AddLocalizedString("incrementTitle", IDS_PRINT_PREVIEW_INCREMENT_TITLE);
AddLocalizedString("decrementTitle", IDS_PRINT_PREVIEW_DECREMENT_TITLE);
AddLocalizedString("printPagesLabel", IDS_PRINT_PREVIEW_PRINT_PAGES_LABEL);
AddLocalizedString("optionsLabel", IDS_PRINT_PREVIEW_OPTIONS_LABEL);
AddLocalizedString("optionHeaderFooter",
IDS_PRINT_PREVIEW_OPTION_HEADER_FOOTER);

set_json_path("strings.js");
add_resource_path("print_preview.js", IDR_PRINT_PREVIEW_JS);
Expand Down
20 changes: 20 additions & 0 deletions chrome/browser/ui/webui/print_preview_handler.cc
Original file line number Diff line number Diff line change
Expand Up @@ -493,6 +493,24 @@ void PrintPreviewHandler::HandleGetPreview(const ListValue* args) {
print_preview_ui->OnPrintPreviewFailed();
return;
}

// Retrieve the page title and url and send it to the renderer process if
// headers and footers are to be displayed.
bool display_header_footer = false;
if (!settings->GetBoolean(printing::kSettingHeaderFooterEnabled,
&display_header_footer)) {
NOTREACHED();
}
if (display_header_footer) {
settings->SetString(printing::kSettingHeaderFooterTitle,
initiator_tab->GetTitle());
std::string url;
NavigationEntry* entry = initiator_tab->controller().GetActiveEntry();
if (entry)
url = entry->virtual_url().spec();
settings->SetString(printing::kSettingHeaderFooterURL, url);
}

VLOG(1) << "Print preview request start";
RenderViewHost* rvh = initiator_tab->render_view_host();
rvh->Send(new PrintMsg_PrintPreview(rvh->routing_id(), *settings));
Expand Down Expand Up @@ -522,6 +540,8 @@ void PrintPreviewHandler::HandlePrint(const ListValue* args) {
bool print_to_pdf = false;
settings->GetBoolean(printing::kSettingPrintToPDF, &print_to_pdf);

settings->SetBoolean(printing::kSettingHeaderFooterEnabled, false);

TabContentsWrapper* preview_tab_wrapper =
TabContentsWrapper::GetCurrentWrapperForContents(preview_tab());

Expand Down
12 changes: 12 additions & 0 deletions chrome/common/print_messages.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,18 @@ IPC_STRUCT_BEGIN(PrintMsg_Print_Params)

// True if this is the first preview request, used only for print preview.
IPC_STRUCT_MEMBER(bool, is_first_request)

// Specifies if the header and footer should be rendered.
IPC_STRUCT_MEMBER(bool, display_header_footer)

// Date string to be printed as header if requested by the user.
IPC_STRUCT_MEMBER(string16, date)

// Title string to be printed as header if requested by the user.
IPC_STRUCT_MEMBER(string16, title)

// URL string to be printed as footer if requested by the user.
IPC_STRUCT_MEMBER(string16, url)
IPC_STRUCT_END()

IPC_STRUCT_BEGIN(PrintMsg_PrintPage_Params)
Expand Down
92 changes: 88 additions & 4 deletions chrome/renderer/mock_printer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,78 @@

#include "chrome/renderer/mock_printer.h"

#include "base/basictypes.h"
#include "base/file_util.h"
#include "base/shared_memory.h"
#include "base/string16.h"
#include "base/utf_string_conversions.h"
#include "chrome/common/print_messages.h"
#include "ipc/ipc_message_utils.h"
#include "printing/metafile_impl.h"
#include "printing/units.h"
#include "testing/gtest/include/gtest/gtest.h"

PrintMsg_Print_Params_Clone::PrintMsg_Print_Params_Clone()
: page_size_(),
printable_size_(),
margin_top_(0),
margin_left_(0),
dpi_(0),
min_shrink_(0),
max_shrink_(0),
desired_dpi_(0),
document_cookie_(0),
selection_only_(0),
supports_alpha_blend_(0),
preview_request_id_(0),
is_first_request_(0),
display_header_footer_(0),
date_(),
title_(),
url_() {
}

PrintMsg_Print_Params_Clone::~PrintMsg_Print_Params_Clone(){}

void PrintMsg_Print_Params_Clone::ResetParams(PrintMsg_Print_Params* params) {
params->dpi = dpi_;
params->max_shrink = max_shrink_;
params->min_shrink = min_shrink_;
params->desired_dpi = desired_dpi_;
params->selection_only = selection_only_;
params->document_cookie = document_cookie_;
params->page_size = page_size_;
params->printable_size = printable_size_;
params->margin_left = margin_left_;
params->margin_top = margin_top_;
params->is_first_request = is_first_request_;
params->preview_request_id = preview_request_id_;
params->display_header_footer = display_header_footer_;
params->date = date_;
params->title = title_;
params->url = url_;

COMPILE_ASSERT(sizeof(PrintMsg_Print_Params_Clone) ==
sizeof(PrintMsg_Print_Params),
PrintMsg_Print_Params);
}

PrintMsg_PrintPages_Params_Clone::PrintMsg_PrintPages_Params_Clone()
: pages_(0) {
}

PrintMsg_PrintPages_Params_Clone::~PrintMsg_PrintPages_Params_Clone(){}

void PrintMsg_PrintPages_Params_Clone::ResetParams(
PrintMsg_PrintPages_Params* params) {
params_.ResetParams(&params->params);
params->pages = pages_;

COMPILE_ASSERT(sizeof(PrintMsg_PrintPages_Params_Clone) ==
sizeof(PrintMsg_PrintPages_Params_Clone),
PrintMsg_PrintPages_Params);
}

MockPrinterPage::MockPrinterPage(const void* source_data,
uint32 source_size,
const printing::Image& image)
Expand All @@ -37,7 +101,11 @@ MockPrinter::MockPrinter()
number_pages_(0),
page_number_(0),
is_first_request_(true),
preview_request_id_(0) {
preview_request_id_(0),
display_header_footer_(false),
date_(ASCIIToUTF16("date")),
title_(ASCIIToUTF16("title")),
url_(ASCIIToUTF16("url")) {
page_size_.SetSize(static_cast<int>(8.5 * dpi_),
static_cast<int>(11.0 * dpi_));
printable_size_.SetSize(static_cast<int>((7.5 * dpi_)),
Expand All @@ -60,7 +128,8 @@ void MockPrinter::GetDefaultPrintSettings(PrintMsg_Print_Params* params) {

// Assign a unit document cookie and set the print settings.
document_cookie_ = CreateDocumentCookie();
memset(params, 0, sizeof(PrintMsg_Print_Params));
PrintMsg_Print_Params_Clone params_clone;
params_clone.ResetParams(params);
SetPrintParams(params);
}

Expand All @@ -74,6 +143,10 @@ void MockPrinter::SetDefaultPrintSettings(const PrintMsg_Print_Params& params) {
printable_size_ = params.printable_size;
margin_left_ = params.margin_left;
margin_top_ = params.margin_top;
display_header_footer_ = params.display_header_footer;
date_ = params.date;
title_ = params.title;
url_ = params.url;
}

void MockPrinter::ScriptedPrint(int cookie,
Expand All @@ -83,7 +156,9 @@ void MockPrinter::ScriptedPrint(int cookie,
// Verify the input parameters.
EXPECT_EQ(document_cookie_, cookie);

memset(settings, 0, sizeof(PrintMsg_PrintPages_Params));
PrintMsg_PrintPages_Params_Clone params_clone;
params_clone.ResetParams(settings);

settings->params.dpi = dpi_;
settings->params.max_shrink = max_shrink_;
settings->params.min_shrink = min_shrink_;
Expand All @@ -94,14 +169,19 @@ void MockPrinter::ScriptedPrint(int cookie,
settings->params.printable_size = printable_size_;
settings->params.is_first_request = is_first_request_;
settings->params.preview_request_id = preview_request_id_;
settings->params.display_header_footer = display_header_footer_;
settings->params.date = date_;
settings->params.title = title_;
settings->params.url = url_;
printer_status_ = PRINTER_PRINTING;
}

void MockPrinter::UpdateSettings(int cookie,
PrintMsg_PrintPages_Params* params) {
EXPECT_EQ(document_cookie_, cookie);

memset(params, 0, sizeof(PrintMsg_PrintPages_Params));
PrintMsg_PrintPages_Params_Clone params_clone;
params_clone.ResetParams(params);
SetPrintParams(&(params->params));
printer_status_ = PRINTER_PRINTING;
}
Expand Down Expand Up @@ -236,4 +316,8 @@ void MockPrinter::SetPrintParams(PrintMsg_Print_Params* params) {
params->margin_top = margin_top_;
params->is_first_request = is_first_request_;
params->preview_request_id = preview_request_id_;
params->display_header_footer = display_header_footer_;
params->date = date_;
params->title = title_;
params->url = url_;
}
Loading

0 comments on commit 55b23a0

Please sign in to comment.