Commit 2a5d4a46 authored by Chris Harrelson's avatar Chris Harrelson Committed by Commit Bot

Fix bug in CalculateBackgroundClipRectWithGeometryMapper

Previously, we did not map into the scrolled space when requested.
This was implemented correctly in the non-GeometryMapper case by (*).
It was only tested by unittests, and those unittests ran in
non-GeometryMapper mode. This CL also implements those unittests in
GeometryMapper mode.

(*) https://chromium-review.googlesource.com/c/chromium/src/+/961643/

Change-Id: I43fd9907f3dda2a72c4da9bdadd6dc370c0d6874
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2347073
Commit-Queue: Xianzhu Wang <wangxianzhu@chromium.org>
Reviewed-by: default avatarXianzhu Wang <wangxianzhu@chromium.org>
Cr-Commit-Position: refs/heads/master@{#796602}
parent be310d90
......@@ -67,6 +67,10 @@ bool ClipRectsContext::ShouldRespectRootLayerClip() const {
return respect_overflow_clip == kRespectOverflowClip;
}
bool ClipRectsContext::ShouldIgnoreRootLayerClipAndScroll() const {
return respect_overflow_clip == kIgnoreOverflowClipAndScroll;
}
static void AdjustClipRectsForChildren(
const LayoutBoxModelObject& layout_object,
ClipRects& clip_rects) {
......@@ -458,6 +462,9 @@ void PaintLayerClipper::CalculateBackgroundClipRectWithGeometryMapper(
context.root_fragment->LocalBorderBoxProperties();
if (context.ShouldRespectRootLayerClip()) {
destination_property_tree_state.SetClip(context.root_fragment->PreClip());
} else if (context.ShouldIgnoreRootLayerClipAndScroll()) {
destination_property_tree_state =
context.root_fragment->ContentsProperties();
} else {
destination_property_tree_state.SetClip(
context.root_fragment->PostOverflowClip());
......
......@@ -87,6 +87,7 @@ class ClipRectsContext {
ClipRectsCacheSlot CacheSlot() const { return cache_slot_; }
bool ShouldRespectRootLayerClip() const;
bool ShouldIgnoreRootLayerClipAndScroll() const;
const PaintLayer* root_layer;
const FragmentData* root_fragment;
......
......@@ -899,6 +899,35 @@ TEST_F(PaintLayerClipperTest, ScrollbarClipBehaviorParent) {
EXPECT_EQ(PhysicalRect(0, 0, 200, 300), layer_bounds);
}
static void CheckBackgroundRects(const PaintLayer& target_layer,
const PhysicalRect& expected_rect) {
{
ClipRect clip_rect;
target_layer.Clipper(PaintLayer::GeometryMapperOption::kUseGeometryMapper)
.CalculateBackgroundClipRect(
ClipRectsContext(
target_layer.GetLayoutObject().View()->Layer(),
&target_layer.GetLayoutObject().View()->FirstFragment(),
kUncachedClipRects, kIgnorePlatformOverlayScrollbarSize,
kIgnoreOverflowClipAndScroll),
clip_rect);
EXPECT_EQ(expected_rect, clip_rect.Rect());
}
{
ClipRect clip_rect;
target_layer
.Clipper(PaintLayer::GeometryMapperOption::kDoNotUseGeometryMapper)
.CalculateBackgroundClipRect(
ClipRectsContext(
target_layer.GetLayoutObject().View()->Layer(),
&target_layer.GetLayoutObject().View()->FirstFragment(),
kUncachedClipRects, kIgnorePlatformOverlayScrollbarSize,
kIgnoreOverflowClipAndScroll),
clip_rect);
EXPECT_EQ(expected_rect, clip_rect.Rect());
}
}
TEST_F(PaintLayerClipperTest, FixedLayerClipRectInDocumentSpace) {
SetBodyInnerHTML(R"HTML(
<div style="position:fixed; left:100px; top:200px; width:300px; height:400px; overflow:hidden;">
......@@ -912,41 +941,14 @@ TEST_F(PaintLayerClipperTest, FixedLayerClipRectInDocumentSpace) {
ToLayoutBoxModelObject(target->GetLayoutObject())->Layer();
GetDocument().domWindow()->scrollTo(0, 50);
GetDocument()
.GetLayoutView()
->Layer()
->Clipper(PaintLayer::GeometryMapperOption::kDoNotUseGeometryMapper)
.ClearClipRectsIncludingDescendants();
UpdateAllLifecyclePhasesForTest();
{
ClipRect clip_rect;
target_layer
->Clipper(PaintLayer::GeometryMapperOption::kDoNotUseGeometryMapper)
.CalculateBackgroundClipRect(
ClipRectsContext(GetDocument().GetLayoutView()->Layer(),
&GetDocument().GetLayoutView()->FirstFragment(),
kAbsoluteClipRectsIgnoringViewportClip,
kIgnorePlatformOverlayScrollbarSize,
kIgnoreOverflowClipAndScroll),
clip_rect);
EXPECT_EQ(PhysicalRect(100, 250, 300, 400), clip_rect.Rect());
}
CheckBackgroundRects(*target_layer, PhysicalRect(100, 250, 300, 400));
GetDocument().domWindow()->scrollTo(0, 100);
UpdateAllLifecyclePhasesForTest();
{
ClipRect clip_rect;
target_layer
->Clipper(PaintLayer::GeometryMapperOption::kDoNotUseGeometryMapper)
.CalculateBackgroundClipRect(
ClipRectsContext(GetDocument().GetLayoutView()->Layer(),
&GetDocument().GetLayoutView()->FirstFragment(),
kAbsoluteClipRectsIgnoringViewportClip,
kIgnorePlatformOverlayScrollbarSize,
kIgnoreOverflowClipAndScroll),
clip_rect);
EXPECT_EQ(PhysicalRect(100, 300, 300, 400), clip_rect.Rect());
}
CheckBackgroundRects(*target_layer, PhysicalRect(100, 300, 300, 400));
}
TEST_F(PaintLayerClipperTest,
......@@ -966,41 +968,14 @@ TEST_F(PaintLayerClipperTest,
ToLayoutBoxModelObject(target->GetLayoutObject())->Layer();
GetDocument().domWindow()->scrollTo(0, 50);
GetDocument()
.GetLayoutView()
->Layer()
->Clipper(PaintLayer::GeometryMapperOption::kDoNotUseGeometryMapper)
.ClearClipRectsIncludingDescendants();
UpdateAllLifecyclePhasesForTest();
{
ClipRect clip_rect;
target_layer
->Clipper(PaintLayer::GeometryMapperOption::kDoNotUseGeometryMapper)
.CalculateBackgroundClipRect(
ClipRectsContext(GetDocument().GetLayoutView()->Layer(),
&GetDocument().GetLayoutView()->FirstFragment(),
kAbsoluteClipRectsIgnoringViewportClip,
kIgnorePlatformOverlayScrollbarSize,
kIgnoreOverflowClipAndScroll),
clip_rect);
EXPECT_EQ(PhysicalRect(100, 250, 200, 300), clip_rect.Rect());
}
CheckBackgroundRects(*target_layer, PhysicalRect(100, 250, 200, 300));
GetDocument().domWindow()->scrollTo(0, 100);
UpdateAllLifecyclePhasesForTest();
{
ClipRect clip_rect;
target_layer
->Clipper(PaintLayer::GeometryMapperOption::kDoNotUseGeometryMapper)
.CalculateBackgroundClipRect(
ClipRectsContext(GetDocument().GetLayoutView()->Layer(),
&GetDocument().GetLayoutView()->FirstFragment(),
kAbsoluteClipRectsIgnoringViewportClip,
kIgnorePlatformOverlayScrollbarSize,
kIgnoreOverflowClipAndScroll),
clip_rect);
EXPECT_EQ(PhysicalRect(100, 300, 200, 300), clip_rect.Rect());
}
CheckBackgroundRects(*target_layer, PhysicalRect(100, 300, 200, 300));
}
TEST_F(PaintLayerClipperTest,
......@@ -1027,68 +1002,24 @@ TEST_F(PaintLayerClipperTest,
->Layer()
->Clipper(PaintLayer::GeometryMapperOption::kDoNotUseGeometryMapper)
.ClearClipRectsIncludingDescendants();
UpdateAllLifecyclePhasesForTest();
{
ClipRect clip_rect;
target_layer
->Clipper(PaintLayer::GeometryMapperOption::kDoNotUseGeometryMapper)
.CalculateBackgroundClipRect(
ClipRectsContext(GetDocument().GetLayoutView()->Layer(),
&GetDocument().GetLayoutView()->FirstFragment(),
kUncachedClipRects,
kIgnorePlatformOverlayScrollbarSize,
kIgnoreOverflowClipAndScroll),
clip_rect);
EXPECT_EQ(PhysicalRect(100, 208, 200, 300), clip_rect.Rect());
}
CheckBackgroundRects(*target_layer, PhysicalRect(100, 208, 200, 300));
// At 50, target is still scrolling - clip_rect shouldn't change.
GetDocument().domWindow()->scrollTo(0, 50);
{
ClipRect clip_rect;
target_layer
->Clipper(PaintLayer::GeometryMapperOption::kDoNotUseGeometryMapper)
.CalculateBackgroundClipRect(
ClipRectsContext(GetDocument().GetLayoutView()->Layer(),
&GetDocument().GetLayoutView()->FirstFragment(),
kUncachedClipRects,
kIgnorePlatformOverlayScrollbarSize,
kIgnoreOverflowClipAndScroll),
clip_rect);
EXPECT_EQ(PhysicalRect(100, 208, 200, 300), clip_rect.Rect());
}
UpdateAllLifecyclePhasesForTest();
CheckBackgroundRects(*target_layer, PhysicalRect(100, 208, 200, 300));
// At 150, target is fixed - clip_rect should now increase.
GetDocument().domWindow()->scrollTo(0, 150);
{
ClipRect clip_rect;
target_layer
->Clipper(PaintLayer::GeometryMapperOption::kDoNotUseGeometryMapper)
.CalculateBackgroundClipRect(
ClipRectsContext(GetDocument().GetLayoutView()->Layer(),
&GetDocument().GetLayoutView()->FirstFragment(),
kUncachedClipRects,
kIgnorePlatformOverlayScrollbarSize,
kIgnoreOverflowClipAndScroll),
clip_rect);
EXPECT_EQ(PhysicalRect(100, 250, 200, 300), clip_rect.Rect());
}
UpdateAllLifecyclePhasesForTest();
CheckBackgroundRects(*target_layer, PhysicalRect(100, 250, 200, 300));
// At 250, target is still fixed - clip_rect should keep increasing.
GetDocument().domWindow()->scrollTo(0, 250);
{
ClipRect clip_rect;
target_layer
->Clipper(PaintLayer::GeometryMapperOption::kDoNotUseGeometryMapper)
.CalculateBackgroundClipRect(
ClipRectsContext(GetDocument().GetLayoutView()->Layer(),
&GetDocument().GetLayoutView()->FirstFragment(),
kUncachedClipRects,
kIgnorePlatformOverlayScrollbarSize,
kIgnoreOverflowClipAndScroll),
clip_rect);
EXPECT_EQ(PhysicalRect(100, 350, 200, 300), clip_rect.Rect());
}
UpdateAllLifecyclePhasesForTest();
CheckBackgroundRects(*target_layer, PhysicalRect(100, 350, 200, 300));
}
} // namespace blink
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