gecko-dev/layout/base/ScrollStyles.cpp
Hiroyuki Ikezoe b14c7c928c Bug 1560237 - Don't propagate scroll-behavior from <body>. r=botond
From the CSSOM View spec[1];

 The scroll-behavior property of the HTML body element is not propagated to
 the viewport.

The reason why this change fixes the test case in this commit is that we don't
have two different scrollable frames for <html> and <body> respectively if we
don't propagate scroll-behavior property from <body> to <html> so that we can
properly find the `flow root` of sticky position elements.

In other words, in the case where both of <html> and <body> have properties
that are propagated from <body> but they are different we have two scrollable
frames as a candidate of the 'flow root' for the sticky position element in
the test case, one is the scrollable frame for <html> and the other is the
scrollable frame for <body>.  That means that
nsLayoutUtils::GetNearestScrollableFrame doesn't return what we want in some
places, for example we have a pretty similar issue in case of
overscroll-behavior which is bug 1561107.

Note that the test position-sticky-root-scroller-with-scroll-behavior.html is
almost copy-and-pasted from
/css/css-position/position-sticky-root-scroller.html [2] in wpt, the reason why
we put the test in /css/cssom-view is that there is a handy function to wait
for async scroll completion.

[1] https://drafts.csswg.org/cssom-view/#propdef-scroll-behavior
[2] https://searchfox.org/mozilla-central/rev/928742d3ea30e0eb4a8622d260041564d81a8468/testing/web-platform/tests/css/css-position/position-sticky-root-scroller.html

Differential Revision: https://phabricator.services.mozilla.com/D35739

--HG--
extra : moz-landing-system : lando
2019-06-26 20:57:05 +00:00

69 lines
2.5 KiB
C++

/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#include "mozilla/ScrollStyles.h"
#include "mozilla/WritingModes.h"
#include "nsStyleStruct.h" // for nsStyleDisplay & nsStyleBackground::Position
namespace mozilla {
void ScrollStyles::InitializeScrollSnapStrictness(
WritingMode aWritingMode, const nsStyleDisplay* aDisplay) {
mScrollSnapStrictnessX = StyleScrollSnapStrictness::None;
mScrollSnapStrictnessY = StyleScrollSnapStrictness::None;
if (aDisplay->mScrollSnapType.strictness == StyleScrollSnapStrictness::None) {
return;
}
switch (aDisplay->mScrollSnapType.axis) {
case StyleScrollSnapAxis::X:
mScrollSnapStrictnessX = aDisplay->mScrollSnapType.strictness;
break;
case StyleScrollSnapAxis::Y:
mScrollSnapStrictnessY = aDisplay->mScrollSnapType.strictness;
break;
case StyleScrollSnapAxis::Block:
if (aWritingMode.IsVertical()) {
mScrollSnapStrictnessX = aDisplay->mScrollSnapType.strictness;
} else {
mScrollSnapStrictnessY = aDisplay->mScrollSnapType.strictness;
}
break;
case StyleScrollSnapAxis::Inline:
if (aWritingMode.IsVertical()) {
mScrollSnapStrictnessY = aDisplay->mScrollSnapType.strictness;
} else {
mScrollSnapStrictnessX = aDisplay->mScrollSnapType.strictness;
}
break;
case StyleScrollSnapAxis::Both:
mScrollSnapStrictnessX = aDisplay->mScrollSnapType.strictness;
mScrollSnapStrictnessY = aDisplay->mScrollSnapType.strictness;
break;
}
}
ScrollStyles::ScrollStyles(WritingMode aWritingMode, StyleOverflow aH,
StyleOverflow aV, const nsStyleDisplay* aDisplay)
: mHorizontal(aH),
mVertical(aV),
mOverscrollBehaviorX(aDisplay->mOverscrollBehaviorX),
mOverscrollBehaviorY(aDisplay->mOverscrollBehaviorY) {
InitializeScrollSnapStrictness(aWritingMode, aDisplay);
}
ScrollStyles::ScrollStyles(WritingMode aWritingMode,
const nsStyleDisplay* aDisplay)
: mHorizontal(aDisplay->mOverflowX),
mVertical(aDisplay->mOverflowY),
mOverscrollBehaviorX(aDisplay->mOverscrollBehaviorX),
mOverscrollBehaviorY(aDisplay->mOverscrollBehaviorY) {
InitializeScrollSnapStrictness(aWritingMode, aDisplay);
}
} // namespace mozilla