From b95b915d8a831681ee4f7219152f2c00e5cd93cd Mon Sep 17 00:00:00 2001 From: "yuzo@chromium.org" Date: Wed, 23 Feb 2011 01:01:34 +0000 Subject: Fix for Issue 73274: Printing causes view to scroll Save and restore scroll offset when printing a page. This patch is applicable only after the patch for https://bugs.webkit.org/show_bug.cgi?id=54632 has been landed. This patch doesn't completely fix https://bugs.webkit.org/show_bug.cgi?id=52552 but the remaining issue is relatively minor. BUG=73274 TEST= Open a web page, scroll to the bottom, print, and observe the scroll position is not changed. See http://code.google.com/p/chromium/issues/detail?id=73274 Review URL: http://codereview.chromium.org/6539011 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@75689 0039d316-1c4b-4281-b951-d872f2087c98 --- chrome/renderer/print_web_view_helper.cc | 4 ++++ chrome/renderer/print_web_view_helper.h | 1 + 2 files changed, 5 insertions(+) (limited to 'chrome/renderer') diff --git a/chrome/renderer/print_web_view_helper.cc b/chrome/renderer/print_web_view_helper.cc index 518529d..5ca14e6 100644 --- a/chrome/renderer/print_web_view_helper.cc +++ b/chrome/renderer/print_web_view_helper.cc @@ -82,6 +82,8 @@ PrepareFrameAndViewForPrint::PrepareFrameAndViewForPrint( print_layout_size.set_height(static_cast( static_cast(print_layout_size.height()) * 1.25)); + if (WebFrame* web_frame = web_view_->mainFrame()) + prev_scroll_offset_ = web_frame->scrollOffset(); prev_view_size_ = web_view->size(); web_view->resize(print_layout_size); @@ -97,6 +99,8 @@ PrepareFrameAndViewForPrint::PrepareFrameAndViewForPrint( PrepareFrameAndViewForPrint::~PrepareFrameAndViewForPrint() { frame_->printEnd(); web_view_->resize(prev_view_size_); + if (WebFrame* web_frame = web_view_->mainFrame()) + web_frame->setScrollOffset(prev_scroll_offset_); } diff --git a/chrome/renderer/print_web_view_helper.h b/chrome/renderer/print_web_view_helper.h index 5c7afcc..dfe3e92 100644 --- a/chrome/renderer/print_web_view_helper.h +++ b/chrome/renderer/print_web_view_helper.h @@ -60,6 +60,7 @@ class PrepareFrameAndViewForPrint { WebKit::WebView* web_view_; gfx::Size print_canvas_size_; gfx::Size prev_view_size_; + gfx::Size prev_scroll_offset_; int expected_pages_count_; bool use_browser_overlays_; -- cgit v1.1