Commit edc066c3 authored by Chris Harrelson's avatar Chris Harrelson Committed by Commit Bot

Apply fixed-position scroll offset if the containing block is ancestor.

An earlier patch (commit e931d2ae)
changed code in MapToVisualRectInAncestorSpace to omit fixed-position
scroll in cases where the containing block was the LayoutView and
a counter-scroll would have been applied in the LayoutView anyway.
This fixed a bug in which a clip was applied in-between in the
wrong space.

The CL introduced a bug, however, in the case when the LayoutView
was the desired ancestor passed to MapToVisualRectInAncestorSpace.
In this case we should apply the counter scroll in LayoutView, because
the results of MapToVisualRectInAncestorSpace are in the unscrolled
space of the LayoutView.

Note that
LayoutBox::MapToVisualRectInAncestorSpace already has code to
skip fixed-position scroll and clip if container == ancestor,
independent of the above commit.

Bug:841194

Change-Id: Ia05894dd94bdb3b0503cbb155728b0ef074b0227
Reviewed-on: https://chromium-review.googlesource.com/1058039Reviewed-by: default avatarPhilip Rogers <pdr@chromium.org>
Commit-Queue: Chris Harrelson <chrishtr@chromium.org>
Cr-Commit-Position: refs/heads/master@{#558473}
parent cafb944b
...@@ -2556,8 +2556,9 @@ bool LayoutBox::MapToVisualRectInAncestorSpaceInternal( ...@@ -2556,8 +2556,9 @@ bool LayoutBox::MapToVisualRectInAncestorSpaceInternal(
if (container->IsLayoutView()) { if (container->IsLayoutView()) {
bool use_fixed_position_adjustment = bool use_fixed_position_adjustment =
!RuntimeEnabledFeatures::RootLayerScrollingEnabled() && position == EPosition::kFixed &&
position == EPosition::kFixed; (!RuntimeEnabledFeatures::RootLayerScrollingEnabled() ||
container == ancestor);
return ToLayoutView(container)->MapToVisualRectInAncestorSpaceInternal( return ToLayoutView(container)->MapToVisualRectInAncestorSpaceInternal(
ancestor, transform_state, use_fixed_position_adjustment ? kIsFixed : 0, ancestor, transform_state, use_fixed_position_adjustment ? kIsFixed : 0,
visual_rect_flags); visual_rect_flags);
......
...@@ -1025,6 +1025,34 @@ TEST_P(VisualRectMappingTest, FixedContentsWithScrollOffset) { ...@@ -1025,6 +1025,34 @@ TEST_P(VisualRectMappingTest, FixedContentsWithScrollOffset) {
ancestor, kDefaultVisualRectFlags, true); ancestor, kDefaultVisualRectFlags, true);
} }
TEST_P(VisualRectMappingTest, FixedContentsUnderViewWithScrollOffset) {
GetDocument().GetFrame()->GetSettings()->SetPreferCompositingToLCDTextEnabled(
true);
SetBodyInnerHTML(R"HTML(
<style>body { margin:0; } ::-webkit-scrollbar { display:none; }</style>
<div id='fixed' style='
position:fixed; top:0; left:0; width:400px; height:300px;'>
</div>
<div id='forcescroll' style='height:1000px;'></div>
)HTML");
auto* fixed = GetDocument().getElementById("fixed")->GetLayoutObject();
CheckMapToVisualRectInAncestorSpace(
LayoutRect(0, 0, 400, 300), LayoutRect(0, 0, 400, 300), fixed,
fixed->View(), kDefaultVisualRectFlags, true);
GetDocument().View()->LayoutViewportScrollableArea()->SetScrollOffset(
ScrollOffset(0, 50), kProgrammaticScroll);
GetDocument().View()->UpdateAllLifecyclePhases();
// Results of mapping to ancestor are in absolute coordinates of the
// ancestor. Therefore a fixed-position element is (reverse) offset by scroll.
CheckMapToVisualRectInAncestorSpace(
LayoutRect(0, 0, 400, 300), LayoutRect(0, 50, 400, 300), fixed,
fixed->View(), kDefaultVisualRectFlags, true);
}
TEST_P(VisualRectMappingTest, InclusiveIntersect) { TEST_P(VisualRectMappingTest, InclusiveIntersect) {
GetDocument().SetBaseURLOverride(KURL("http://test.com")); GetDocument().SetBaseURLOverride(KURL("http://test.com"));
SetBodyInnerHTML(R"HTML( SetBodyInnerHTML(R"HTML(
......
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