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

Unified Diff: chrome/renderer/print_web_view_helper.cc

Issue 9699040: PrintPreview: Hide/Show the header footer option based on print frame margins. (Closed) Base URL: http://git.chromium.org/git/chromium.git@trunk
Patch Set: Created 8 years, 9 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
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 024ac9818771ad9ba0b97a7e1601d635da52ce6a..c3387f446fa252cbfe4b2a34b97ec78569dbd807 100644
--- a/chrome/renderer/print_web_view_helper.cc
+++ b/chrome/renderer/print_web_view_helper.cc
@@ -852,7 +852,11 @@ void PrintWebViewHelper::OnPrintPreview(const DictionaryValue& settings) {
}
print_preview_context_.set_generate_draft_pages(generate_draft_pages);
- if (CreatePreviewDocument()) {
+ int margins_type = 0;
+ if (!settings.GetInteger(printing::kSettingMarginsType, &margins_type))
+ margins_type = printing::DEFAULT_MARGINS;
+
+ if (CreatePreviewDocument(margins_type)) {
DidFinishPrinting(OK);
} else {
if (notify_browser_of_print_failure_)
@@ -861,7 +865,7 @@ void PrintWebViewHelper::OnPrintPreview(const DictionaryValue& settings) {
}
}
-bool PrintWebViewHelper::CreatePreviewDocument() {
+bool PrintWebViewHelper::CreatePreviewDocument(int margins_type) {
PrintMsg_Print_Params print_params = print_pages_params_->params;
const std::vector<int>& pages = print_pages_params_->pages;
if (!print_preview_context_.CreatePreviewDocument(&print_params, pages,
@@ -874,20 +878,47 @@ bool PrintWebViewHelper::CreatePreviewDocument() {
ComputePageLayoutInPointsForCss(print_preview_context_.frame(), 0,
print_params, ignore_css_margins_,
fit_to_page_, NULL, &default_page_layout);
+
+ bool preview_is_modifiable = print_preview_context_.IsModifiable();
if (!old_print_pages_params_.get() ||
!PageLayoutIsEqual(*old_print_pages_params_, *print_pages_params_)) {
bool has_page_size_style = PrintingFrameHasPageSizeStyle(
print_preview_context_.frame(),
print_preview_context_.total_page_count());
+
+ bool header_footer_applies = true;
+ if (!preview_is_modifiable || margins_type == printing::NO_MARGINS) {
+ header_footer_applies = false;
+ } else if (margins_type != printing::PRINTABLE_AREA_MARGINS) {
+#if defined(OS_LINUX)
+ header_footer_applies =
+ (default_page_layout.margin_top > 0) ||
+ (default_page_layout.margin_bottom > 0);
+#else
+ int dpi = GetDPI(&print_params);
+ int non_printable_area_top = ConvertUnit(
+ print_pages_params_->params.printable_area.y(),
+ dpi, printing::kPointsPerInch);
+ int non_printable_area_bottom = ConvertUnit(
+ print_pages_params_->params.page_size.height() -
+ print_pages_params_->params.printable_area.y() -
+ print_pages_params_->params.printable_area.height(),
+ dpi, printing::kPointsPerInch);
+ header_footer_applies =
+ (default_page_layout.margin_top > non_printable_area_top) ||
+ (default_page_layout.margin_bottom > non_printable_area_bottom);
+#endif
+ }
// Margins: Send default page layout to browser process.
Send(new PrintHostMsg_DidGetDefaultPageLayout(routing_id(),
default_page_layout,
- has_page_size_style));
+ has_page_size_style,
+ header_footer_applies));
}
PrintHostMsg_DidGetPreviewPageCount_Params params;
params.page_count = print_preview_context_.total_page_count();
- params.is_modifiable = print_preview_context_.IsModifiable();
+ params.is_modifiable = preview_is_modifiable;
params.document_cookie = print_pages_params_->params.document_cookie;
params.preview_request_id = print_pages_params_->params.preview_request_id;
params.clear_preview_data = print_preview_context_.generate_draft_pages();

Powered by Google App Engine
This is Rietveld 408576698