Commit 0ea138d6 authored by Tien-Ren Chen's avatar Tien-Ren Chen Committed by Commit Bot

[Blink] Unify pre-snapping of <video> to match <iframe>

This CL changes the pre-snapping policy of <video> so that only the size
of the contents is pre-snapped, while the location will exactly match the
content box's final location.

BUG=730284

Change-Id: Id10bd0fbd8021a11b7db4a2950a908f3d1b50ac0
Reviewed-on: https://chromium-review.googlesource.com/1141328Reviewed-by: default avatarChris Harrelson <chrishtr@chromium.org>
Commit-Queue: Tien-Ren Chen <trchen@chromium.org>
Cr-Commit-Position: refs/heads/master@{#576317}
parent ff71f764
......@@ -292,19 +292,16 @@ CursorDirective LayoutEmbeddedContent::GetCursor(const LayoutPoint& point,
}
LayoutRect LayoutEmbeddedContent::ReplacedContentRect() const {
LayoutRect content_rect = ContentBoxRect();
// IFrames set as the root scroller should get their size from their parent.
if (ChildFrameView() && View() && RootScrollerUtil::IsEffective(*this))
content_rect = LayoutRect(LayoutPoint(), View()->ViewRect().Size());
// We don't propagate sub-pixel into sub-frame layout, in other words, the
// rect is snapped at the document boundary, and sub-pixel movement could
// cause the sub-frame to layout due to the 1px snap difference. In order to
// avoid that, the size of sub-frame is rounded in advance.
LayoutRect size_rounded_rect = ContentBoxRect();
// IFrames set as the root scroller should get their size from their parent.
if (ChildFrameView() && View() && RootScrollerUtil::IsEffective(*this))
size_rounded_rect = LayoutRect(LayoutPoint(), View()->ViewRect().Size());
size_rounded_rect.SetSize(
LayoutSize(RoundedIntSize(size_rounded_rect.Size())));
return size_rounded_rect;
return PreSnappedRectForPersistentSizing(content_rect);
}
void LayoutEmbeddedContent::UpdateOnEmbeddedContentViewChange() {
......
......@@ -636,6 +636,11 @@ LayoutRect LayoutReplaced::ReplacedContentRect() const {
return ComputeObjectFit();
}
LayoutRect LayoutReplaced::PreSnappedRectForPersistentSizing(LayoutRect rect) {
rect.SetSize(LayoutSize(RoundedIntSize(rect.Size())));
return rect;
}
void LayoutReplaced::ComputeIntrinsicSizingInfo(
IntrinsicSizingInfo& intrinsic_sizing_info) const {
if (ShouldApplySizeContainment()) {
......
......@@ -63,6 +63,12 @@ class CORE_EXPORT LayoutReplaced : public LayoutBox {
// This function returns the local rect of the replaced content.
virtual LayoutRect ReplacedContentRect() const;
// This is used by a few special elements, e.g. <video>, <iframe> to ensure
// a persistent sizing under different subpixel offset, because these
// elements have a high cost to resize. The drawback is that we may overflow
// or underflow the final content box by 1px.
static LayoutRect PreSnappedRectForPersistentSizing(LayoutRect);
bool NeedsPreferredWidthsRecalculation() const override;
// These values are specified to be 300 and 150 pixels in the CSS 2.1 spec.
......
......@@ -171,10 +171,7 @@ LayoutRect LayoutVideo::ReplacedContentRect() const {
if (ShouldDisplayVideo()) {
// Video codecs may need to restart from an I-frame when the output is
// resized. Round size in advance to avoid 1px snap difference.
// TODO(trchen): The way of rounding is different from LayoutEmbeddedContent
// just to match existing behavior. This is probably a bug and We should
// unify it with LayoutEmbeddedContent.
return LayoutRect(PixelSnappedIntRect(ComputeObjectFit()));
return PreSnappedRectForPersistentSizing(ComputeObjectFit());
}
// If we are displaying the poster image no pre-rounding is needed, but the
// size of the image should be used for fitting instead.
......
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