Commit 00feab09 authored by Emilio Cobos Álvarez's avatar Emilio Cobos Álvarez
Browse files

Bug 1538537 - When suppressing anchoring on an scrollframe, forward to the...

Bug 1538537 - When suppressing anchoring on an scrollframe, forward to the frame that actually maintains the anchor as needed. r=dholbert, a=RyanVM

The test-case is position-change-heuristic.html but with body and #space
having overflow: hidden, which makes it fail on Nightly.

Differential Revision: https://phabricator.services.mozilla.com/D75825
parent 07d44d20
......@@ -366,6 +366,20 @@ void ScrollAnchorContainer::AdjustmentMade(nscoord aAdjustment) {
void ScrollAnchorContainer::SuppressAdjustments() {
ANCHOR_LOG("Received a scroll anchor suppression for %p.\n", this);
mSuppressAnchorAdjustment = true;
// Forward to our parent if appropriate, that is, if we don't maintain an
// anchor, and we can't maintain one.
//
// Note that we need to check !CanMaintainAnchor(), instead of just whether
// our frame is in the anchor chain of our ancestor as InvalidateAnchor()
// does, given some suppression triggers apply even for nodes that are not in
// the anchor chain.
if (!mAnchorNode && !CanMaintainAnchor()) {
if (ScrollAnchorContainer* container = FindFor(Frame())) {
ANCHOR_LOG(" > Forwarding to parent anchor\n");
container->SuppressAdjustments();
}
}
}
void ScrollAnchorContainer::InvalidateAnchor(ScheduleSelection aSchedule) {
......@@ -374,6 +388,7 @@ void ScrollAnchorContainer::InvalidateAnchor(ScheduleSelection aSchedule) {
if (mAnchorNode) {
SetAnchorFlags(mScrollFrame->mScrolledFrame, mAnchorNode, false);
} else if (mScrollFrame->mScrolledFrame->IsInScrollAnchorChain()) {
ANCHOR_LOG(" > Forwarding to parent anchor\n");
// We don't maintain an anchor, and our scrolled frame is in the anchor
// chain of an ancestor. Invalidate that anchor.
//
......
<!DOCTYPE html>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<link rel="help" href="https://drafts.csswg.org/css-scroll-anchoring/#suppression-triggers">
<style>
#space {
height: 4000px;
overflow: hidden;
}
#header {
background-color: #F5B335;
height: 50px;
width: 100%;
}
#content {
background-color: #D3D3D3;
height: 400px;
}
.scroller {
overflow: scroll;
position: relative;
width: 600px;
height: 600px;
}
body {
overflow: hidden;
}
</style>
<div id="maybeScroller">
<div id="space">
<div id="header"></div>
<div id="before"></div>
<div id="content"></div>
</div>
</div>
<script>
// Tests that scroll anchoring is suppressed when an element in the scroller
// changes its in-flow state.
var scroller;
function runCase(oldPos, newPos, expectSuppression, skipInverse) {
var header = document.querySelector("#header");
var before = document.querySelector("#before");
header.style.position = oldPos;
before.style.height = "0";
scroller.scrollTop = 200;
header.style.position = newPos;
before.style.height = "25px";
var expectedTop = expectSuppression ? 200 : 225;
assert_equals(scroller.scrollTop, expectedTop);
if (!skipInverse)
runCase(newPos, oldPos, expectSuppression, true);
}
test(() => {
scroller = document.scrollingElement;
document.querySelector("#maybeScroller").className = "";
runCase("static", "fixed", true);
runCase("static", "absolute", true);
runCase("static", "relative", false);
runCase("fixed", "absolute", false);
runCase("fixed", "relative", true);
runCase("absolute", "relative", true);
}, "Position changes in document scroller.");
test(() => {
scroller = document.querySelector("#maybeScroller");
scroller.className = "scroller";
runCase("static", "fixed", true);
runCase("static", "absolute", true);
runCase("static", "relative", false);
runCase("fixed", "absolute", false);
runCase("fixed", "relative", true);
runCase("absolute", "relative", true);
}, "Position changes in scrollable <div>.");
</script>
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