summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorvitalybuka@chromium.org <vitalybuka@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-01-31 23:35:09 +0000
committervitalybuka@chromium.org <vitalybuka@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-01-31 23:35:09 +0000
commit7edd1bcb46afdb2fe69713e8a810359f3126aafa (patch)
treee1c736fac6eb4dcf683cdab813ce537d9a42a50b
parenta5ca230649d3f99600920b193568e5537d8d0499 (diff)
downloadchromium_src-7edd1bcb46afdb2fe69713e8a810359f3126aafa.zip
chromium_src-7edd1bcb46afdb2fe69713e8a810359f3126aafa.tar.gz
chromium_src-7edd1bcb46afdb2fe69713e8a810359f3126aafa.tar.bz2
Resizes source frame to fit page before copying selected content.
Selected content includes effective style, so without resizing, if element outsize the page, then it will be outside, printing selection. BUG=173213 Review URL: https://chromiumcodereview.appspot.com/12086071 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@180001 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r--chrome/renderer/printing/print_web_view_helper.cc38
1 files changed, 27 insertions, 11 deletions
diff --git a/chrome/renderer/printing/print_web_view_helper.cc b/chrome/renderer/printing/print_web_view_helper.cc
index 6e1018a..d9a5cd7 100644
--- a/chrome/renderer/printing/print_web_view_helper.cc
+++ b/chrome/renderer/printing/print_web_view_helper.cc
@@ -520,6 +520,8 @@ class PrepareFrameAndViewForPrint : public WebKit::WebViewClient,
virtual void CallOnReady();
private:
+ void ResizeForPrinting();
+ void RestoreSize();
void CopySelection(const webkit_glue::WebPreferences& preferences);
base::WeakPtrFactory<PrepareFrameAndViewForPrint> weak_ptr_factory_;
@@ -570,7 +572,7 @@ PrepareFrameAndViewForPrint::~PrepareFrameAndViewForPrint() {
FinishPrinting();
}
-void PrepareFrameAndViewForPrint::StartPrinting() {
+void PrepareFrameAndViewForPrint::ResizeForPrinting() {
// Layout page according to printer page size. Since WebKit shrinks the
// size of the page automatically (from 125% to 200%) we trick it to
// think the page is 125% larger so the size of the page is correct for
@@ -592,6 +594,12 @@ void PrepareFrameAndViewForPrint::StartPrinting() {
prev_view_size_ = web_view->size();
web_view->resize(print_layout_size);
+}
+
+
+void PrepareFrameAndViewForPrint::StartPrinting() {
+ ResizeForPrinting();
+ WebKit::WebView* web_view = frame_->view();
web_view->settings()->setShouldPrintBackgrounds(should_print_backgrounds_);
// TODO(vitalybuka): Update call after
// https://bugs.webkit.org/show_bug.cgi?id=107718 is fixed.
@@ -612,11 +620,10 @@ void PrepareFrameAndViewForPrint::CopySelectionIfNeeded(
void PrepareFrameAndViewForPrint::CopySelection(
const webkit_glue::WebPreferences& preferences) {
- std::string html = frame_->selectionAsMarkup().utf8();
+ ResizeForPrinting();
std::string url_str = "data:text/html;charset=utf-8,";
- url_str.append(html);
- GURL url(url_str);
-
+ url_str.append(frame_->selectionAsMarkup().utf8());
+ RestoreSize();
// Create a new WebView with the same settings as the current display one.
// Except that we disable javascript (don't want any active content running
// on the page).
@@ -633,7 +640,7 @@ void PrepareFrameAndViewForPrint::CopySelection(
// When loading is done this will call didStopLoading() and that will do the
// actual printing.
- frame_->loadRequest(WebKit::WebURLRequest(url));
+ frame_->loadRequest(WebKit::WebURLRequest(GURL(url_str)));
}
void PrepareFrameAndViewForPrint::didStopLoading() {
@@ -654,17 +661,26 @@ gfx::Size PrepareFrameAndViewForPrint::GetPrintCanvasSize() const {
web_print_params_.printContentArea.height);
}
-void PrepareFrameAndViewForPrint::FinishPrinting() {
+void PrepareFrameAndViewForPrint::RestoreSize() {
if (frame_) {
- if (is_printing_started_)
- frame_->printEnd();
WebKit::WebView* web_view = frame_->view();
web_view->resize(prev_view_size_);
if (WebKit::WebFrame* web_frame = web_view->mainFrame())
web_frame->setScrollOffset(prev_scroll_offset_);
- web_view->settings()->setShouldPrintBackgrounds(false);
- if (should_close_web_view_)
+ }
+}
+
+void PrepareFrameAndViewForPrint::FinishPrinting() {
+ if (frame_) {
+ if (is_printing_started_)
+ frame_->printEnd();
+ WebKit::WebView* web_view = frame_->view();
+ if (should_close_web_view_) {
web_view->close();
+ } else {
+ web_view->settings()->setShouldPrintBackgrounds(false);
+ RestoreSize();
+ }
}
frame_ = NULL;
on_ready_.Reset();