forked from chromium/chromium
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix HTMLVideoElement poster zoom issue
The cached image size of the video poster has been scaled using the style's EffectiveZoom, so it should not be scaled again in LayoutVideo::UpdateIntrinsicSize(). Bug: 1107377 Change-Id: I57ca1ccf59531ac00aac0fbf261d3be59ede8bbc Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2317487 Reviewed-by: Koji Ishii <kojii@chromium.org> Commit-Queue: Koji Ishii <kojii@chromium.org> Cr-Commit-Position: refs/heads/master@{#794898}
- Loading branch information
WangShicheng
authored and
Commit Bot
committed
Aug 5, 2020
1 parent
4d7f5e6
commit 75dc85b
Showing
5 changed files
with
93 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
68 changes: 68 additions & 0 deletions
68
third_party/blink/renderer/core/layout/layout_video_test.cc
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
// Copyright 2020 The Chromium Authors. All rights reserved. | ||
// Use of this source code is governed by a BSD-style license that can be | ||
// found in the LICENSE file. | ||
|
||
#include "third_party/blink/renderer/core/layout/layout_video.h" | ||
|
||
#include "third_party/blink/renderer/core/layout/layout_image.h" | ||
#include "third_party/blink/renderer/core/loader/resource/image_resource_content.h" | ||
#include "third_party/blink/renderer/core/testing/core_unit_test_helper.h" | ||
#include "third_party/blink/renderer/platform/graphics/unaccelerated_static_bitmap_image.h" | ||
#include "third_party/skia/include/core/SkImage.h" | ||
#include "third_party/skia/include/core/SkSurface.h" | ||
|
||
namespace blink { | ||
|
||
class LayoutVideoTest : public RenderingTest { | ||
public: | ||
void CreateAndSetImage(const char* id, int width, int height) { | ||
// Create one image with size(width, height) | ||
sk_sp<SkColorSpace> src_rgb_color_space = SkColorSpace::MakeSRGB(); | ||
SkImageInfo raster_image_info = | ||
SkImageInfo::MakeN32Premul(width, height, src_rgb_color_space); | ||
sk_sp<SkSurface> surface(SkSurface::MakeRaster(raster_image_info)); | ||
sk_sp<SkImage> image = surface->makeImageSnapshot(); | ||
ImageResourceContent* image_content = ImageResourceContent::CreateLoaded( | ||
UnacceleratedStaticBitmapImage::Create(image).get()); | ||
|
||
// Set image to video | ||
auto* layout_image = (LayoutImage*)GetLayoutObjectByElementId(id); | ||
layout_image->ImageResource()->SetImageResource(image_content); | ||
} | ||
}; | ||
|
||
TEST_F(LayoutVideoTest, PosterSizeWithNormal) { | ||
SetBodyInnerHTML(R"HTML( | ||
<style> | ||
video {zoom:1} | ||
</style> | ||
<video id='video' /> | ||
)HTML"); | ||
|
||
CreateAndSetImage("video", 10, 10); | ||
UpdateAllLifecyclePhasesForTest(); | ||
|
||
int width = ((LayoutBox*)GetLayoutObjectByElementId("video")) | ||
->AbsoluteBoundingBoxRect() | ||
.Width(); | ||
EXPECT_EQ(width, 10); | ||
} | ||
|
||
TEST_F(LayoutVideoTest, PosterSizeWithZoom) { | ||
SetBodyInnerHTML(R"HTML( | ||
<style> | ||
video {zoom:1.5} | ||
</style> | ||
<video id='video' /> | ||
)HTML"); | ||
|
||
CreateAndSetImage("video", 10, 10); | ||
UpdateAllLifecyclePhasesForTest(); | ||
|
||
int width = ((LayoutBox*)GetLayoutObjectByElementId("video")) | ||
->AbsoluteBoundingBoxRect() | ||
.Width(); | ||
EXPECT_EQ(width, 15); | ||
} | ||
|
||
} // namespace blink |