Commit 5c4d6c9f authored by ckitagawa's avatar ckitagawa Committed by Commit Bot

[Paint Preview] Scroll Transform

Paint Previews were getting clipped if a scroll occurred before capture.
This CL fixes this by applying a transform to fix this behavior.

Bug: 1061918
Change-Id: Iff3f461b57cdc95ddcc864cbb006cc20657325b2
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2105397Reviewed-by: default avatarPhilip Rogers <pdr@chromium.org>
Commit-Queue: Calder Kitagawa <ckitagawa@chromium.org>
Cr-Commit-Position: refs/heads/master@{#750943}
parent 3aa4d66b
...@@ -78,6 +78,7 @@ TEST_F(PaintPreviewRecorderRenderViewTest, TestCaptureMainFrameAndClipping) { ...@@ -78,6 +78,7 @@ TEST_F(PaintPreviewRecorderRenderViewTest, TestCaptureMainFrameAndClipping) {
" background: yellow;'></div>" " background: yellow;'></div>"
" </div>" " </div>"
"</body>"); "</body>");
base::FilePath skp_path = MakeTestFilePath("test.skp"); base::FilePath skp_path = MakeTestFilePath("test.skp");
mojom::PaintPreviewCaptureParamsPtr params = mojom::PaintPreviewCaptureParamsPtr params =
...@@ -141,6 +142,64 @@ TEST_F(PaintPreviewRecorderRenderViewTest, TestCaptureMainFrameAndClipping) { ...@@ -141,6 +142,64 @@ TEST_F(PaintPreviewRecorderRenderViewTest, TestCaptureMainFrameAndClipping) {
0xFFFFFFFFU); 0xFFFFFFFFU);
} }
TEST_F(PaintPreviewRecorderRenderViewTest, TestCaptureMainFrameWithScroll) {
LoadHTML(
"<body>"
" <div style='width: 600px; height: 80vh; "
" background-color: #ff0000'>&nbsp;</div>"
" <div style='width: 600px; height: 1200px; "
" background-color: #00ff00'>&nbsp;</div>"
"</body>");
// Scroll to bottom of page to ensure scroll position has no effect on
// capture.
ExecuteJavaScriptForTests("window.scrollTo(0,document.body.scrollHeight);");
base::FilePath skp_path = MakeTestFilePath("test.skp");
mojom::PaintPreviewCaptureParamsPtr params =
mojom::PaintPreviewCaptureParams::New();
auto token = base::UnguessableToken::Create();
params->guid = token;
params->clip_rect = gfx::Rect();
params->is_main_frame = true;
base::File skp_file(skp_path,
base::File::FLAG_CREATE_ALWAYS | base::File::FLAG_WRITE);
params->file = std::move(skp_file);
auto out_response = mojom::PaintPreviewCaptureResponse::New();
content::RenderFrame* frame = GetFrame();
PaintPreviewRecorderImpl paint_preview_recorder(frame);
paint_preview_recorder.CapturePaintPreview(
std::move(params),
base::BindOnce(&OnCaptureFinished, mojom::PaintPreviewStatus::kOk,
base::Unretained(&out_response)));
EXPECT_FALSE(out_response->embedding_token.has_value());
EXPECT_EQ(out_response->content_id_to_embedding_token.size(), 0U);
// Relaxed checks on dimensions and no checks on positions. This is not
// intended to intensively test the rendering behavior of the page.
sk_sp<SkPicture> pic;
{
base::ScopedAllowBlockingForTesting scope;
FileRStream rstream(base::File(
skp_path, base::File::FLAG_OPEN_ALWAYS | base::File::FLAG_READ));
pic = SkPicture::MakeFromStream(&rstream, nullptr);
}
SkBitmap bitmap;
ASSERT_TRUE(bitmap.tryAllocN32Pixels(pic->cullRect().width(),
pic->cullRect().height()));
SkCanvas canvas(bitmap);
canvas.drawPicture(pic);
// This should be inside the top right corner of the top div. Success means
// there was no horizontal or vertical clipping as this region is red,
// matching the div.
EXPECT_EQ(bitmap.getColor(600, 50), 0xFFFF0000U);
// This should be inside the bottom of the bottom div. Success means there was
// no vertical clipping as this region is blue matching the div.
EXPECT_EQ(bitmap.getColor(50, pic->cullRect().height() - 100), 0xFF00FF00U);
}
TEST_F(PaintPreviewRecorderRenderViewTest, TestCaptureFragment) { TEST_F(PaintPreviewRecorderRenderViewTest, TestCaptureFragment) {
// Use position absolute position to check that the captured link dimensions // Use position absolute position to check that the captured link dimensions
// match what is specified. // match what is specified.
......
...@@ -533,7 +533,7 @@ class PaintPreviewContext : public PrintContext { ...@@ -533,7 +533,7 @@ class PaintPreviewContext : public PrintContext {
LocalFrameView* frame_view = GetFrame()->View(); LocalFrameView* frame_view = GetFrame()->View();
DCHECK(frame_view); DCHECK(frame_view);
PropertyTreeState property_tree_state = PropertyTreeState property_tree_state =
frame_view->GetLayoutView()->FirstFragment().LocalBorderBoxProperties(); frame_view->GetLayoutView()->FirstFragment().ContentsProperties();
// This calls BeginRecording on |builder| with dimensions specified by the // This calls BeginRecording on |builder| with dimensions specified by the
// CullRect. // CullRect.
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment