Skip to content

Commit 6fbd2cd

Browse files
committed
Bug 1753565 - Default disable smooth scrolls if prefers-reduced-motion. r=botond
If the user has the prefers-reduced-motion system setting enabled, do not enable smooth scrolls by default. Differential Revision: https://phabricator.services.mozilla.com/D172446 UltraBlame original commit: a2f066123f3c6b76e43c5f09b154d838f1ba798b
1 parent d3132de commit 6fbd2cd

File tree

6 files changed

+43
-10
lines changed

6 files changed

+43
-10
lines changed

gfx/layers/apz/test/gtest/TestBasic.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -310,6 +310,7 @@ TEST_F(APZCBasicTester, RelativeScrollOffset) {
310310
}
311311

312312
TEST_F(APZCBasicTester, MultipleSmoothScrollsSmooth) {
313+
SCOPED_GFX_PREF_BOOL("general.smoothScroll", true);
313314

314315

315316

@@ -450,11 +451,13 @@ class APZCSmoothScrollTester : public APZCBasicTester {
450451
};
451452

452453
TEST_F(APZCSmoothScrollTester, SmoothScrollDestinationUpdateBezier) {
454+
SCOPED_GFX_PREF_BOOL("general.smoothScroll", true);
453455
SCOPED_GFX_PREF_BOOL("general.smoothScroll.msdPhysics.enabled", false);
454456
TestSmoothScrollDestinationUpdate();
455457
}
456458

457459
TEST_F(APZCSmoothScrollTester, SmoothScrollDestinationUpdateMsd) {
460+
SCOPED_GFX_PREF_BOOL("general.smoothScroll", true);
458461
SCOPED_GFX_PREF_BOOL("general.smoothScroll.msdPhysics.enabled", true);
459462
TestSmoothScrollDestinationUpdate();
460463
}

layout/base/nsLayoutUtils.cpp

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@
8585
#include "mozilla/StaticPrefs_apz.h"
8686
#include "mozilla/StaticPrefs_dom.h"
8787
#include "mozilla/StaticPrefs_font.h"
88+
#include "mozilla/StaticPrefs_general.h"
8889
#include "mozilla/StaticPrefs_gfx.h"
8990
#include "mozilla/StaticPrefs_image.h"
9091
#include "mozilla/StaticPrefs_layers.h"
@@ -7770,6 +7771,22 @@ size_t nsLayoutUtils::SizeOfTextRunsForFrames(nsIFrame* aFrame,
77707771
}
77717772

77727773

7774+
void nsLayoutUtils::RecomputeSmoothScrollDefault() {
7775+
7776+
7777+
7778+
Preferences::SetBool(
7779+
"general.smoothScroll",
7780+
!LookAndFeel::GetInt(LookAndFeel::IntID::PrefersReducedMotion, 0),
7781+
PrefValueKind::Default);
7782+
}
7783+
7784+
7785+
bool nsLayoutUtils::IsSmoothScrollingEnabled() {
7786+
return StaticPrefs::general_smoothScroll();
7787+
}
7788+
7789+
77737790
void nsLayoutUtils::Initialize() {
77747791
nsComputedDOMStyle::RegisterPrefChangeCallbacks();
77757792
}

layout/base/nsLayoutUtils.h

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3039,6 +3039,19 @@ class nsLayoutUtils {
30393039

30403040
static nsIFrame* GetNearestOverflowClipFrame(nsIFrame* aFrame);
30413041

3042+
3043+
3044+
3045+
static bool IsSmoothScrollingEnabled();
3046+
3047+
3048+
3049+
3050+
3051+
3052+
3053+
static void RecomputeSmoothScrollDefault();
3054+
30423055
private:
30433056

30443057

layout/generic/nsGfxScrollFrame.cpp

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2235,11 +2235,6 @@ void nsHTMLScrollFrame::AsyncScroll::InitSmoothScroll(
22352235
}
22362236

22372237

2238-
bool nsHTMLScrollFrame::IsSmoothScrollingEnabled() {
2239-
return StaticPrefs::general_smoothScroll();
2240-
}
2241-
2242-
22432238

22442239

22452240

@@ -2560,7 +2555,8 @@ void nsHTMLScrollFrame::ScrollToWithOrigin(nsPoint aScrollPosition,
25602555
mAsyncScroll->SetRefreshObserver(this);
25612556
}
25622557

2563-
const bool isSmoothScroll = aParams.IsSmooth() && IsSmoothScrollingEnabled();
2558+
const bool isSmoothScroll =
2559+
aParams.IsSmooth() && nsLayoutUtils::IsSmoothScrollingEnabled();
25642560
if (isSmoothScroll) {
25652561
mAsyncScroll->InitSmoothScroll(now, GetScrollPosition(), mDestination,
25662562
aParams.mOrigin, range, currentVelocity);
@@ -7903,7 +7899,7 @@ bool nsHTMLScrollFrame::IsSmoothScroll(dom::ScrollBehavior aBehavior) const {
79037899

79047900

79057901
if (aBehavior == dom::ScrollBehavior::Instant ||
7906-
!nsHTMLScrollFrame::IsSmoothScrollingEnabled()) {
7902+
!nsLayoutUtils::IsSmoothScrollingEnabled()) {
79077903
return false;
79087904
}
79097905

layout/generic/nsGfxScrollFrame.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -538,8 +538,6 @@ class nsHTMLScrollFrame : public nsContainerFrame,
538538
void PostScrolledAreaEvent();
539539
MOZ_CAN_RUN_SCRIPT void FireScrolledAreaEvent();
540540

541-
static bool IsSmoothScrollingEnabled();
542-
543541

544542

545543

widget/nsXPLookAndFeel.cpp

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
#include "nsFont.h"
1818
#include "nsIFrame.h"
1919
#include "nsIXULRuntime.h"
20+
#include "nsLayoutUtils.h"
2021
#include "Theme.h"
2122
#include "SurfaceCacheUtils.h"
2223
#include "mozilla/dom/ContentParent.h"
@@ -549,6 +550,10 @@ void nsXPLookAndFeel::Init() {
549550

550551
RecomputeColorSchemes();
551552

553+
if (XRE_IsParentProcess()) {
554+
nsLayoutUtils::RecomputeSmoothScrollDefault();
555+
}
556+
552557

553558

554559

@@ -1170,8 +1175,9 @@ void nsXPLookAndFeel::RefreshImpl() {
11701175
sIntCache.Clear();
11711176
RecomputeColorSchemes();
11721177

1173-
11741178
if (XRE_IsParentProcess()) {
1179+
nsLayoutUtils::RecomputeSmoothScrollDefault();
1180+
11751181
widget::RemoteLookAndFeel::ClearCachedData();
11761182
}
11771183
}

0 commit comments

Comments
 (0)