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

Side by Side Diff: chrome/renderer/automation/automation_renderer_helper.cc

Issue 15006004: Correct scroll offset range for WebFrame in AutomationRendererHelper (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: re-enable disabled test Created 7 years, 7 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 | « no previous file | chrome/renderer/automation/automation_renderer_helper_browsertest.cc » ('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/automation/automation_renderer_helper.h" 5 #include "chrome/renderer/automation/automation_renderer_helper.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 8
9 #include "base/basictypes.h" 9 #include "base/basictypes.h"
10 #include "base/json/json_writer.h" 10 #include "base/json/json_writer.h"
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
47 47
48 AutomationRendererHelper::~AutomationRendererHelper() { } 48 AutomationRendererHelper::~AutomationRendererHelper() { }
49 49
50 bool AutomationRendererHelper::SnapshotEntirePage( 50 bool AutomationRendererHelper::SnapshotEntirePage(
51 WebView* view, 51 WebView* view,
52 std::vector<unsigned char>* png_data, 52 std::vector<unsigned char>* png_data,
53 std::string* error_msg) { 53 std::string* error_msg) {
54 WebFrame* frame = view->mainFrame(); 54 WebFrame* frame = view->mainFrame();
55 WebSize old_size = view->size(); 55 WebSize old_size = view->size();
56 WebSize new_size = frame->contentsSize(); 56 WebSize new_size = frame->contentsSize();
57 // For RTL, the minimum scroll offset may be negative.
58 WebSize min_scroll = frame->minimumScrollOffset();
59 WebSize old_scroll = frame->scrollOffset(); 57 WebSize old_scroll = frame->scrollOffset();
60 bool fixed_layout_enabled = view->isFixedLayoutModeEnabled(); 58 bool fixed_layout_enabled = view->isFixedLayoutModeEnabled();
61 WebSize fixed_size = view->fixedLayoutSize(); 59 WebSize fixed_size = view->fixedLayoutSize();
62 60
63 frame->setCanHaveScrollbars(false); 61 frame->setCanHaveScrollbars(false);
64 view->setFixedLayoutSize(old_size); 62 view->setFixedLayoutSize(old_size);
65 view->enableFixedLayoutMode(true); 63 view->enableFixedLayoutMode(true);
66 view->resize(new_size); 64 view->resize(new_size);
67 view->layout(); 65 view->layout();
68 frame->setScrollOffset(WebSize(0, 0)); 66 frame->setScrollOffset(frame->minimumScrollOffset());
69 67
70 skia::RefPtr<SkCanvas> canvas = skia::AdoptRef( 68 skia::RefPtr<SkCanvas> canvas = skia::AdoptRef(
71 skia::CreatePlatformCanvas(new_size.width, new_size.height, true)); 69 skia::CreatePlatformCanvas(new_size.width, new_size.height, true));
72 70
73 view->paint(webkit_glue::ToWebCanvas(canvas.get()), 71 view->paint(webkit_glue::ToWebCanvas(canvas.get()),
74 gfx::Rect(0, 0, new_size.width, new_size.height)); 72 gfx::Rect(0, 0, new_size.width, new_size.height));
75 73
76 frame->setCanHaveScrollbars(true); 74 frame->setCanHaveScrollbars(true);
77 view->setFixedLayoutSize(fixed_size); 75 view->setFixedLayoutSize(fixed_size);
78 view->enableFixedLayoutMode(fixed_layout_enabled); 76 view->enableFixedLayoutMode(fixed_layout_enabled);
79 view->resize(old_size); 77 view->resize(old_size);
80 view->layout(); 78 view->layout();
81 frame->setScrollOffset(WebSize(old_scroll.width - min_scroll.width, 79 frame->setScrollOffset(old_scroll);
82 old_scroll.height - min_scroll.height));
83 80
84 const SkBitmap& bmp = skia::GetTopDevice(*canvas)->accessBitmap(false); 81 const SkBitmap& bmp = skia::GetTopDevice(*canvas)->accessBitmap(false);
85 SkAutoLockPixels lock_pixels(bmp); 82 SkAutoLockPixels lock_pixels(bmp);
86 // EncodeBGRA uses FORMAT_SkBitmap, which doesn't work on windows for some 83 // EncodeBGRA uses FORMAT_SkBitmap, which doesn't work on windows for some
87 // cases dealing with transparency. See crbug.com/96317. Use FORMAT_BGRA. 84 // cases dealing with transparency. See crbug.com/96317. Use FORMAT_BGRA.
88 bool encode_success = gfx::PNGCodec::Encode( 85 bool encode_success = gfx::PNGCodec::Encode(
89 reinterpret_cast<unsigned char*>(bmp.getPixels()), 86 reinterpret_cast<unsigned char*>(bmp.getPixels()),
90 gfx::PNGCodec::FORMAT_BGRA, 87 gfx::PNGCodec::FORMAT_BGRA,
91 gfx::Size(bmp.width(), bmp.height()), 88 gfx::Size(bmp.width(), bmp.height()),
92 bmp.rowBytes(), 89 bmp.rowBytes(),
(...skipping 189 matching lines...) Expand 10 before | Expand all | Expand 10 after
282 routing_id(), frame->identifier())); 279 routing_id(), frame->identifier()));
283 } 280 }
284 281
285 void AutomationRendererHelper::OnProcessMouseEvent( 282 void AutomationRendererHelper::OnProcessMouseEvent(
286 const AutomationMouseEvent& event) { 283 const AutomationMouseEvent& event) {
287 std::string error_msg; 284 std::string error_msg;
288 bool success = ProcessMouseEvent(event, &error_msg); 285 bool success = ProcessMouseEvent(event, &error_msg);
289 Send(new AutomationMsg_ProcessMouseEventACK( 286 Send(new AutomationMsg_ProcessMouseEventACK(
290 routing_id(), success, error_msg)); 287 routing_id(), success, error_msg));
291 } 288 }
OLDNEW
« no previous file with comments | « no previous file | chrome/renderer/automation/automation_renderer_helper_browsertest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698