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

Side by Side Diff: chrome/renderer/print_web_view_helper.cc

Issue 11818062: Adds option to enable CSS backgrounds for printing. (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Merge with trunk. Created 7 years, 11 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 unified diff | Download patch
« no previous file with comments | « chrome/renderer/print_web_view_helper.h ('k') | printing/print_job_constants.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/renderer/print_web_view_helper.h" 5 #include "chrome/renderer/print_web_view_helper.h"
6 6
7 #include <string> 7 #include <string>
8 8
9 #include "base/auto_reset.h" 9 #include "base/auto_reset.h"
10 #include "base/command_line.h" 10 #include "base/command_line.h"
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after
102 oldParams.pages.size() == newParams.pages.size() && 102 oldParams.pages.size() == newParams.pages.size() &&
103 oldParams.params.print_to_pdf == newParams.params.print_to_pdf && 103 oldParams.params.print_to_pdf == newParams.params.print_to_pdf &&
104 oldParams.params.print_scaling_option == 104 oldParams.params.print_scaling_option ==
105 newParams.params.print_scaling_option && 105 newParams.params.print_scaling_option &&
106 oldParams.params.display_header_footer == 106 oldParams.params.display_header_footer ==
107 newParams.params.display_header_footer && 107 newParams.params.display_header_footer &&
108 oldParams.params.date == newParams.params.date && 108 oldParams.params.date == newParams.params.date &&
109 oldParams.params.title == newParams.params.title && 109 oldParams.params.title == newParams.params.title &&
110 oldParams.params.url == newParams.params.url && 110 oldParams.params.url == newParams.params.url &&
111 std::equal(oldParams.pages.begin(), oldParams.pages.end(), 111 std::equal(oldParams.pages.begin(), oldParams.pages.end(),
112 newParams.pages.begin()); 112 newParams.pages.begin()) &&
113 oldParams.params.should_print_backgrounds ==
114 newParams.params.should_print_backgrounds;
113 } 115 }
114 116
115 PrintMsg_Print_Params GetCssPrintParams( 117 PrintMsg_Print_Params GetCssPrintParams(
116 WebKit::WebFrame* frame, 118 WebKit::WebFrame* frame,
117 int page_index, 119 int page_index,
118 const PrintMsg_Print_Params& page_params) { 120 const PrintMsg_Print_Params& page_params) {
119 PrintMsg_Print_Params page_css_params = page_params; 121 PrintMsg_Print_Params page_css_params = page_params;
120 int dpi = GetDPI(&page_params); 122 int dpi = GetDPI(&page_params);
121 123
122 using printing::ConvertUnit; 124 using printing::ConvertUnit;
(...skipping 356 matching lines...) Expand 10 before | Expand all | Expand 10 after
479 481
480 PrepareFrameAndViewForPrint::PrepareFrameAndViewForPrint( 482 PrepareFrameAndViewForPrint::PrepareFrameAndViewForPrint(
481 const PrintMsg_Print_Params& print_params, 483 const PrintMsg_Print_Params& print_params,
482 WebKit::WebFrame* frame, 484 WebKit::WebFrame* frame,
483 const WebKit::WebNode& node) 485 const WebKit::WebNode& node)
484 : frame_(frame), 486 : frame_(frame),
485 node_to_print_(node), 487 node_to_print_(node),
486 web_view_(frame->view()), 488 web_view_(frame->view()),
487 expected_pages_count_(0), 489 expected_pages_count_(0),
488 use_browser_overlays_(true), 490 use_browser_overlays_(true),
489 finished_(false) { 491 finished_(false),
492 should_print_backgrounds_(print_params.should_print_backgrounds) {
490 WebKit::WebPrintParams webkit_print_params; 493 WebKit::WebPrintParams webkit_print_params;
491 ComputeWebKitPrintParamsInDesiredDpi(print_params, &webkit_print_params); 494 ComputeWebKitPrintParamsInDesiredDpi(print_params, &webkit_print_params);
492 495
493 if (WebKit::WebFrame* web_frame = web_view_->mainFrame()) 496 if (WebKit::WebFrame* web_frame = web_view_->mainFrame())
494 prev_scroll_offset_ = web_frame->scrollOffset(); 497 prev_scroll_offset_ = web_frame->scrollOffset();
495 prev_view_size_ = web_view_->size(); 498 prev_view_size_ = web_view_->size();
496 499
497 StartPrinting(webkit_print_params); 500 StartPrinting(webkit_print_params);
498 } 501 }
499 502
500 PrepareFrameAndViewForPrint::~PrepareFrameAndViewForPrint() { 503 PrepareFrameAndViewForPrint::~PrepareFrameAndViewForPrint() {
501 FinishPrinting(); 504 FinishPrinting();
502 } 505 }
503 506
504 void PrepareFrameAndViewForPrint::UpdatePrintParams( 507 void PrepareFrameAndViewForPrint::UpdatePrintParams(
505 const PrintMsg_Print_Params& print_params) { 508 const PrintMsg_Print_Params& print_params) {
506 DCHECK(!finished_); 509 DCHECK(!finished_);
507 WebKit::WebPrintParams webkit_print_params; 510 WebKit::WebPrintParams webkit_print_params;
508 ComputeWebKitPrintParamsInDesiredDpi(print_params, &webkit_print_params); 511 ComputeWebKitPrintParamsInDesiredDpi(print_params, &webkit_print_params);
509 512
513 should_print_backgrounds_ = print_params.should_print_backgrounds;
514
510 if (webkit_print_params.printContentArea == 515 if (webkit_print_params.printContentArea ==
511 web_print_params_.printContentArea && 516 web_print_params_.printContentArea &&
512 webkit_print_params.printableArea == web_print_params_.printableArea && 517 webkit_print_params.printableArea == web_print_params_.printableArea &&
513 webkit_print_params.paperSize == web_print_params_.paperSize && 518 webkit_print_params.paperSize == web_print_params_.paperSize &&
514 webkit_print_params.printScalingOption == 519 webkit_print_params.printScalingOption ==
515 web_print_params_.printScalingOption) { 520 web_print_params_.printScalingOption) {
516 return; 521 return;
517 } 522 }
518 523
519 frame_->printEnd(); 524 frame_->printEnd();
(...skipping 17 matching lines...) Expand all
537 gfx::Size print_layout_size(web_print_params_.printContentArea.width, 542 gfx::Size print_layout_size(web_print_params_.printContentArea.width,
538 web_print_params_.printContentArea.height); 543 web_print_params_.printContentArea.height);
539 print_layout_size.set_height(static_cast<int>( 544 print_layout_size.set_height(static_cast<int>(
540 static_cast<double>(print_layout_size.height()) * 1.25)); 545 static_cast<double>(print_layout_size.height()) * 1.25));
541 546
542 web_view_->resize(print_layout_size); 547 web_view_->resize(print_layout_size);
543 548
544 expected_pages_count_ = frame_->printBegin(web_print_params_, 549 expected_pages_count_ = frame_->printBegin(web_print_params_,
545 node_to_print_, 550 node_to_print_,
546 &use_browser_overlays_); 551 &use_browser_overlays_);
552
553 web_view_->settings()->setShouldPrintBackgrounds(should_print_backgrounds_);
547 } 554 }
548 555
549 void PrepareFrameAndViewForPrint::FinishPrinting() { 556 void PrepareFrameAndViewForPrint::FinishPrinting() {
550 if (!finished_) { 557 if (!finished_) {
551 finished_ = true; 558 finished_ = true;
552 frame_->printEnd(); 559 frame_->printEnd();
553 web_view_->resize(prev_view_size_); 560 web_view_->resize(prev_view_size_);
554 if (WebKit::WebFrame* web_frame = web_view_->mainFrame()) 561 if (WebKit::WebFrame* web_frame = web_view_->mainFrame())
555 web_frame->setScrollOffset(prev_scroll_offset_); 562 web_frame->setScrollOffset(prev_scroll_offset_);
563 web_view_->settings()->setShouldPrintBackgrounds(false);
556 } 564 }
557 } 565 }
558 566
559 PrintWebViewHelper::PrintWebViewHelper(content::RenderView* render_view) 567 PrintWebViewHelper::PrintWebViewHelper(content::RenderView* render_view)
560 : content::RenderViewObserver(render_view), 568 : content::RenderViewObserver(render_view),
561 content::RenderViewObserverTracker<PrintWebViewHelper>(render_view), 569 content::RenderViewObserverTracker<PrintWebViewHelper>(render_view),
562 print_web_view_(NULL), 570 print_web_view_(NULL),
563 is_preview_enabled_(IsPrintPreviewEnabled()), 571 is_preview_enabled_(IsPrintPreviewEnabled()),
564 is_scripted_print_throttling_disabled_(IsPrintThrottlingDisabled()), 572 is_scripted_print_throttling_disabled_(IsPrintThrottlingDisabled()),
565 is_print_ready_metafile_sent_(false), 573 is_print_ready_metafile_sent_(false),
(...skipping 776 matching lines...) Expand 10 before | Expand all | Expand 10 after
1342 header_footer_info_->SetString(printing::kSettingHeaderFooterURL, 1350 header_footer_info_->SetString(printing::kSettingHeaderFooterURL,
1343 settings.params.url); 1351 settings.params.url);
1344 header_footer_info_->SetString(printing::kSettingHeaderFooterTitle, 1352 header_footer_info_->SetString(printing::kSettingHeaderFooterTitle,
1345 settings.params.title); 1353 settings.params.title);
1346 } 1354 }
1347 } 1355 }
1348 1356
1349 print_pages_params_.reset(new PrintMsg_PrintPages_Params(settings)); 1357 print_pages_params_.reset(new PrintMsg_PrintPages_Params(settings));
1350 Send(new PrintHostMsg_DidGetDocumentCookie(routing_id(), 1358 Send(new PrintHostMsg_DidGetDocumentCookie(routing_id(),
1351 settings.params.document_cookie)); 1359 settings.params.document_cookie));
1360
1352 return true; 1361 return true;
1353 } 1362 }
1354 1363
1355 bool PrintWebViewHelper::GetPrintSettingsFromUser(WebKit::WebFrame* frame, 1364 bool PrintWebViewHelper::GetPrintSettingsFromUser(WebKit::WebFrame* frame,
1356 const WebKit::WebNode& node, 1365 const WebKit::WebNode& node,
1357 int expected_pages_count, 1366 int expected_pages_count,
1358 bool use_browser_overlays) { 1367 bool use_browser_overlays) {
1359 PrintHostMsg_ScriptedPrint_Params params; 1368 PrintHostMsg_ScriptedPrint_Params params;
1360 PrintMsg_PrintPages_Params print_settings; 1369 PrintMsg_PrintPages_Params print_settings;
1361 1370
(...skipping 393 matching lines...) Expand 10 before | Expand all | Expand 10 after
1755 DCHECK(IsRendering()); 1764 DCHECK(IsRendering());
1756 return prep_frame_view_->GetPrintCanvasSize(); 1765 return prep_frame_view_->GetPrintCanvasSize();
1757 } 1766 }
1758 1767
1759 void PrintWebViewHelper::PrintPreviewContext::ClearContext() { 1768 void PrintWebViewHelper::PrintPreviewContext::ClearContext() {
1760 prep_frame_view_.reset(); 1769 prep_frame_view_.reset();
1761 metafile_.reset(); 1770 metafile_.reset();
1762 pages_to_render_.clear(); 1771 pages_to_render_.clear();
1763 error_ = PREVIEW_ERROR_NONE; 1772 error_ = PREVIEW_ERROR_NONE;
1764 } 1773 }
OLDNEW
« no previous file with comments | « chrome/renderer/print_web_view_helper.h ('k') | printing/print_job_constants.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698