Bug 1791883 - Ignore scroll-snap-align properties on scrollIntoView operations in the case where the scroll container equals to the target frame. r=emilio

Differential Revision: https://phabricator.services.mozilla.com/D159009
This commit is contained in:
Hiroyuki Ikezoe 2022-10-14 09:42:05 +00:00
parent 0d149a51c5
commit 37cf82422c
3 changed files with 38 additions and 7 deletions

View File

@ -3518,8 +3518,20 @@ static nscoord ComputeWhereToScroll(WhereToScroll aWhereToScroll,
}
static WhereToScroll GetApplicableWhereToScroll(
StyleScrollSnapAlignKeyword aAlign, WhereToScroll aOriginal) {
switch (aAlign) {
const nsIScrollableFrame* aFrameAsScrollable,
const nsIFrame* aScrollableFrame, const nsIFrame* aTarget,
ScrollDirection aScrollDirection, WhereToScroll aOriginal) {
MOZ_ASSERT(do_QueryFrame(aFrameAsScrollable) == aScrollableFrame);
if (aTarget == aScrollableFrame) {
return aOriginal;
}
StyleScrollSnapAlignKeyword align =
aScrollDirection == ScrollDirection::eHorizontal
? aFrameAsScrollable->GetScrollSnapAlignFor(aTarget).first
: aFrameAsScrollable->GetScrollSnapAlignFor(aTarget).second;
switch (align) {
case StyleScrollSnapAlignKeyword::None:
return aOriginal;
case StyleScrollSnapAlignKeyword::Start:
@ -3541,6 +3553,7 @@ static WhereToScroll GetApplicableWhereToScroll(
* This needs to work even if aRect has a width or height of zero.
*/
static void ScrollToShowRect(nsIScrollableFrame* aFrameAsScrollable,
const nsIFrame* aScrollableFrame,
const nsIFrame* aTarget, const nsRect& aRect,
const nsMargin& aMargin, ScrollAxis aVertical,
ScrollAxis aHorizontal, ScrollFlags aScrollFlags) {
@ -3581,8 +3594,8 @@ static void ScrollToShowRect(nsIScrollableFrame* aFrameAsScrollable,
visibleRect.YMost() - padding.bottom)) {
// If the scroll-snap-align on the frame is valid, we need to respect it.
WhereToScroll whereToScroll = GetApplicableWhereToScroll(
aFrameAsScrollable->GetScrollSnapAlignFor(aTarget).second,
aVertical.mWhereToScroll);
aFrameAsScrollable, aScrollableFrame, aTarget,
ScrollDirection::eVertical, aVertical.mWhereToScroll);
nscoord maxHeight;
scrollPt.y = ComputeWhereToScroll(
@ -3602,8 +3615,8 @@ static void ScrollToShowRect(nsIScrollableFrame* aFrameAsScrollable,
visibleRect.XMost() - padding.right)) {
// If the scroll-snap-align on the frame is valid, we need to respect it.
WhereToScroll whereToScroll = GetApplicableWhereToScroll(
aFrameAsScrollable->GetScrollSnapAlignFor(aTarget).first,
aHorizontal.mWhereToScroll);
aFrameAsScrollable, aScrollableFrame, aTarget,
ScrollDirection::eHorizontal, aHorizontal.mWhereToScroll);
nscoord maxWidth;
scrollPt.x = ComputeWhereToScroll(
@ -3838,7 +3851,7 @@ bool PresShell::ScrollFrameRectIntoView(nsIFrame* aFrame, const nsRect& aRect,
{
AutoWeakFrame wf(container);
ScrollToShowRect(sf, target, targetRect, aMargin, aVertical,
ScrollToShowRect(sf, container, target, targetRect, aMargin, aVertical,
aHorizontal, aScrollFlags);
if (!wf.IsAlive()) {
return didScroll;

View File

@ -0,0 +1,17 @@
<!DOCTYPE html>
<html>
<head>
<style>
* {
scroll-snap-type: y mandatory;
scroll-snap-align: none end;
}
</style>
<script>
document.addEventListener('DOMContentLoaded', () => {
document.documentElement.contentEditable = true
document.execCommand('insertHorizontalRule', false, null)
})
</script>
</head>
</html>

View File

@ -569,3 +569,4 @@ load 1753779.html
pref(layout.css.backdrop-filter.enabled,true) load 1755790.html
load 1771503.html
load 1789934.html
load 1791883.html