Bug 1584859 - Make smooth scrolling conditional on reduced motion settings. r=dbaron

We could put this change itself behind a pref too, if we considered that worth
it. But probably not so.

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

--HG--
extra : moz-landing-system : lando
This commit is contained in:
Emilio Cobos Álvarez 2019-10-13 09:16:26 +00:00
Родитель 536c1bc0bb
Коммит 8657ceea27
9 изменённых файлов: 43 добавлений и 10 удалений

Просмотреть файл

@ -19,6 +19,7 @@
#include "mozilla/TouchEvents.h" // for WidgetTouchEvent
#include "mozilla/WheelHandlingHelper.h" // for WheelDeltaHorizontalizer,
// WheelDeltaAdjustmentStrategy
#include "nsLayoutUtils.h" // for IsSmoothScrollingEnabled
namespace mozilla {
namespace layers {
@ -116,7 +117,7 @@ APZEventResult APZInputBridge::ReceiveInputEvent(WidgetInputEvent& aEvent) {
if (Maybe<APZWheelAction> action = ActionForWheelEvent(&wheelEvent)) {
ScrollWheelInput::ScrollMode scrollMode =
ScrollWheelInput::SCROLLMODE_INSTANT;
if (StaticPrefs::general_smoothScroll() &&
if (nsLayoutUtils::IsSmoothScrollingEnabled() &&
((wheelEvent.mDeltaMode ==
dom::WheelEvent_Binding::DOM_DELTA_LINE &&
StaticPrefs::general_smoothScroll_mouseWheel()) ||

Просмотреть файл

@ -2006,7 +2006,7 @@ nsEventStatus AsyncPanZoomController::OnKeyboard(const KeyboardInput& aEvent) {
MaybeAdjustDestinationForScrollSnapping(aEvent, destination);
// If smooth scrolling is disabled, then scroll immediately to the destination
if (!StaticPrefs::general_smoothScroll()) {
if (!nsLayoutUtils::IsSmoothScrollingEnabled()) {
CancelAnimation();
ParentLayerPoint startPoint, endPoint;

Просмотреть файл

@ -27,6 +27,7 @@
#include "mozilla/StaticPrefs_apz.h"
#include "mozilla/StaticPrefs_dom.h"
#include "mozilla/StaticPrefs_font.h"
#include "mozilla/StaticPrefs_general.h"
#include "mozilla/StaticPrefs_gfx.h"
#include "mozilla/StaticPrefs_layers.h"
#include "mozilla/StaticPrefs_layout.h"
@ -7976,9 +7977,27 @@ size_t nsLayoutUtils::SizeOfTextRunsForFrames(nsIFrame* aFrame,
return total;
}
RelaxedAtomicBool nsLayoutUtils::gSmoothScrollingEnabled;
void nsLayoutUtils::RecomputeSmoothScrollingEnabled() {
MOZ_RELEASE_ASSERT(NS_IsMainThread(),
"You don't really want to call into widget "
"off the main thread, do you?");
gSmoothScrollingEnabled =
StaticPrefs::general_smoothScroll_DoNotUseDirectly() &&
!LookAndFeel::GetInt(LookAndFeel::eIntID_PrefersReducedMotion, 0);
}
static void SmoothScrollPrefChanged(const char*, void*) {
nsLayoutUtils::RecomputeSmoothScrollingEnabled();
}
/* static */
void nsLayoutUtils::Initialize() {
nsComputedDOMStyle::RegisterPrefChangeCallbacks();
Preferences::RegisterCallbackAndCall(
SmoothScrollPrefChanged,
nsDependentCString(StaticPrefs::GetPrefName_general_smoothScroll()));
}
/* static */

Просмотреть файл

@ -2998,7 +2998,16 @@ class nsLayoutUtils {
static bool FrameIsMostlyScrolledOutOfViewInCrossProcess(
const nsIFrame* aFrame, nscoord aMargin);
static bool IsSmoothScrollingEnabled() {
return gSmoothScrollingEnabled;
}
static void RecomputeSmoothScrollingEnabled();
private:
static mozilla::RelaxedAtomicBool gSmoothScrollingEnabled;
/**
* Helper function for LogTestDataForPaint().
*/

Просмотреть файл

@ -2026,10 +2026,6 @@ void ScrollFrameHelper::AsyncScroll::InitSmoothScroll(
mAnimationPhysics->Update(aTime, aDestination, aCurrentVelocity);
}
bool ScrollFrameHelper::IsSmoothScrollingEnabled() {
return StaticPrefs::general_smoothScroll();
}
class ScrollFrameActivityTracker final
: public nsExpirationTracker<ScrollFrameHelper, 4> {
public:
@ -2347,7 +2343,7 @@ void ScrollFrameHelper::ScrollToWithOrigin(
? presContext->RefreshDriver()->MostRecentRefresh()
: TimeStamp::Now();
bool isSmoothScroll =
aMode == ScrollMode::Smooth && IsSmoothScrollingEnabled();
aMode == ScrollMode::Smooth && nsLayoutUtils::IsSmoothScrollingEnabled();
nsSize currentVelocity(0, 0);
@ -7188,6 +7184,10 @@ bool ScrollFrameHelper::SmoothScrollVisual(
}
bool ScrollFrameHelper::IsSmoothScroll(dom::ScrollBehavior aBehavior) const {
if (!nsLayoutUtils::IsSmoothScrollingEnabled()) {
return false;
}
if (aBehavior == dom::ScrollBehavior::Smooth) {
return true;
}

Просмотреть файл

@ -116,8 +116,6 @@ class ScrollFrameHelper : public nsIReflowCallback {
void PostScrolledAreaEvent();
void FireScrolledAreaEvent();
bool IsSmoothScrollingEnabled();
/**
* @note This method might destroy the frame, pres shell and other objects.
*/

Просмотреть файл

@ -2959,10 +2959,12 @@
value: true
mirror: always
# Use nsLayoutUtils::SmoothScrollingEnabled() instead.
- name: general.smoothScroll
type: RelaxedAtomicBool
value: true
mirror: always
do_not_use_directly: true
# This pref and general.smoothScroll.stopDecelerationWeighting determine
# the timing function.

Просмотреть файл

@ -4705,7 +4705,8 @@ static gfx::IntPoint GetIntegerDeltaForEvent(NSEvent* aEvent) {
geckoChildDeathGrip->DispatchAPZWheelInputEvent(wheelEvent, false);
} else {
ScrollWheelInput::ScrollMode scrollMode = ScrollWheelInput::SCROLLMODE_INSTANT;
if (StaticPrefs::general_smoothScroll() && StaticPrefs::general_smoothScroll_mouseWheel()) {
if (nsLayoutUtils::IsSmoothScrollingEnabled() &&
StaticPrefs::general_smoothScroll_mouseWheel()) {
scrollMode = ScrollWheelInput::SCROLLMODE_SMOOTH;
}
ScrollWheelInput wheelEvent(eventIntervalTime, eventTimeStamp, modifiers, scrollMode,

Просмотреть файл

@ -11,6 +11,7 @@
#include "nsLookAndFeel.h"
#include "HeadlessLookAndFeel.h"
#include "nsCRT.h"
#include "nsLayoutUtils.h"
#include "nsFont.h"
#include "mozilla/dom/ContentChild.h"
#include "mozilla/Preferences.h"
@ -993,6 +994,8 @@ void nsXPLookAndFeel::RefreshImpl() {
for (i = 0; i < uint32_t(ColorID::End); ++i) {
InitColorFromPref(i);
}
nsLayoutUtils::RecomputeSmoothScrollingEnabled();
}
nsTArray<LookAndFeelInt> nsXPLookAndFeel::GetIntCacheImpl() {