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

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

Issue 6539011: Fix for Issue 73274: Printing causes view to scroll (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/chrome
Patch Set: Created 9 years, 10 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 | Annotate | Revision Log
« no previous file with comments | « chrome/renderer/print_web_view_helper.h ('k') | no next file » | 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) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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/logging.h" 9 #include "base/logging.h"
10 #include "base/process_util.h" 10 #include "base/process_util.h"
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
64 64
65 // Layout page according to printer page size. Since WebKit shrinks the 65 // Layout page according to printer page size. Since WebKit shrinks the
66 // size of the page automatically (from 125% to 200%) we trick it to 66 // size of the page automatically (from 125% to 200%) we trick it to
67 // think the page is 125% larger so the size of the page is correct for 67 // think the page is 125% larger so the size of the page is correct for
68 // minimum (default) scaling. 68 // minimum (default) scaling.
69 // This is important for sites that try to fill the page. 69 // This is important for sites that try to fill the page.
70 gfx::Size print_layout_size(print_canvas_size_); 70 gfx::Size print_layout_size(print_canvas_size_);
71 print_layout_size.set_height(static_cast<int>( 71 print_layout_size.set_height(static_cast<int>(
72 static_cast<double>(print_layout_size.height()) * 1.25)); 72 static_cast<double>(print_layout_size.height()) * 1.25));
73 73
74 if (WebFrame* web_frame = web_view_->mainFrame())
75 prev_scroll_offset_ = web_frame->scrollOffset();
74 prev_view_size_ = web_view->size(); 76 prev_view_size_ = web_view->size();
75 77
76 web_view->resize(print_layout_size); 78 web_view->resize(print_layout_size);
77 79
78 WebNode node_to_print; 80 WebNode node_to_print;
79 if (node) 81 if (node)
80 node_to_print = *node; 82 node_to_print = *node;
81 expected_pages_count_ = frame->printBegin( 83 expected_pages_count_ = frame->printBegin(
82 print_canvas_size_, node_to_print, static_cast<int>(print_params.dpi), 84 print_canvas_size_, node_to_print, static_cast<int>(print_params.dpi),
83 &use_browser_overlays_); 85 &use_browser_overlays_);
84 } 86 }
85 87
86 PrepareFrameAndViewForPrint::~PrepareFrameAndViewForPrint() { 88 PrepareFrameAndViewForPrint::~PrepareFrameAndViewForPrint() {
87 frame_->printEnd(); 89 frame_->printEnd();
88 web_view_->resize(prev_view_size_); 90 web_view_->resize(prev_view_size_);
91 if (WebFrame* web_frame = web_view_->mainFrame())
92 web_frame->setScrollOffset(prev_scroll_offset_);
89 } 93 }
90 94
91 95
92 PrintWebViewHelper::PrintWebViewHelper(RenderView* render_view) 96 PrintWebViewHelper::PrintWebViewHelper(RenderView* render_view)
93 : RenderViewObserver(render_view), 97 : RenderViewObserver(render_view),
94 print_web_view_(NULL), 98 print_web_view_(NULL),
95 user_cancelled_scripted_print_count_(0), 99 user_cancelled_scripted_print_count_(0),
96 is_preview_(false) {} 100 is_preview_(false) {}
97 101
98 PrintWebViewHelper::~PrintWebViewHelper() {} 102 PrintWebViewHelper::~PrintWebViewHelper() {}
(...skipping 478 matching lines...) Expand 10 before | Expand all | Expand 10 after
577 shared_buf.GiveToProcess(base::GetCurrentProcessHandle(), 581 shared_buf.GiveToProcess(base::GetCurrentProcessHandle(),
578 shared_mem_handle); 582 shared_mem_handle);
579 return true; 583 return true;
580 } 584 }
581 } 585 }
582 } 586 }
583 NOTREACHED(); 587 NOTREACHED();
584 return false; 588 return false;
585 } 589 }
586 #endif 590 #endif
OLDNEW
« no previous file with comments | « chrome/renderer/print_web_view_helper.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698