diff --git a/widget/LookAndFeel.h b/widget/LookAndFeel.h index 92c97fe0ae44..216c70fdb84d 100644 --- a/widget/LookAndFeel.h +++ b/widget/LookAndFeel.h @@ -534,6 +534,10 @@ class LookAndFeel { * or not. */ static void SetShouldRetainCacheForTest(bool aValue); + + static void SetPrefersReducedMotionOverrideForTest(bool aValue); + + static void ResetPrefersReducedMotionOverrideForTest(); }; } // namespace mozilla diff --git a/widget/cocoa/nsChildView.mm b/widget/cocoa/nsChildView.mm index 3a5e4252994a..30e3aa719952 100644 --- a/widget/cocoa/nsChildView.mm +++ b/widget/cocoa/nsChildView.mm @@ -2190,24 +2190,7 @@ void nsChildView::LookUpDictionary(const nsAString& aText, } nsresult nsChildView::SetPrefersReducedMotionOverrideForTest(bool aValue) { - // Tell that the cache value we are going to set isn't cleared via - // nsPresContext::ThemeChangedInternal which is called right before - // we queue the media feature value change for this prefers-reduced-motion - // change. - LookAndFeel::SetShouldRetainCacheForTest(true); - - LookAndFeelInt prefersReducedMotion; - prefersReducedMotion.id = LookAndFeel::eIntID_PrefersReducedMotion; - prefersReducedMotion.value = aValue ? 1 : 0; - - AutoTArray lookAndFeelCache; - lookAndFeelCache.AppendElement(prefersReducedMotion); - - // If we could have a way to modify - // NSWorkspace.accessibilityDisplayShouldReduceMotion, we could use it, but - // unfortunately there is no way, so we change the cache value instead as if - // it's set in the parent process. - LookAndFeel::SetIntCache(lookAndFeelCache); + LookAndFeel::SetPrefersReducedMotionOverrideForTest(aValue); if (nsCocoaFeatures::OnMojaveOrLater() && NSWorkspaceAccessibilityDisplayOptionsDidChangeNotification) { @@ -2227,7 +2210,7 @@ nsresult nsChildView::SetPrefersReducedMotionOverrideForTest(bool aValue) { } nsresult nsChildView::ResetPrefersReducedMotionOverrideForTest() { - LookAndFeel::SetShouldRetainCacheForTest(false); + LookAndFeel::ResetPrefersReducedMotionOverrideForTest(); return NS_OK; } diff --git a/widget/cocoa/nsLookAndFeel.h b/widget/cocoa/nsLookAndFeel.h index 6185c1d42934..718bc04b60da 100644 --- a/widget/cocoa/nsLookAndFeel.h +++ b/widget/cocoa/nsLookAndFeel.h @@ -45,9 +45,6 @@ class nsLookAndFeel final : public nsXPLookAndFeel { int32_t mAllowOverlayScrollbarsOverlap; bool mAllowOverlayScrollbarsOverlapCached; - int32_t mPrefersReducedMotion; - bool mPrefersReducedMotionCached; - int32_t mSystemUsesDarkTheme; bool mSystemUsesDarkThemeCached; diff --git a/widget/cocoa/nsLookAndFeel.mm b/widget/cocoa/nsLookAndFeel.mm index 182b640ca4a9..fe6fabd2648c 100644 --- a/widget/cocoa/nsLookAndFeel.mm +++ b/widget/cocoa/nsLookAndFeel.mm @@ -40,8 +40,6 @@ nsLookAndFeel::nsLookAndFeel() mUseOverlayScrollbarsCached(false), mAllowOverlayScrollbarsOverlap(-1), mAllowOverlayScrollbarsOverlapCached(false), - mPrefersReducedMotion(-1), - mPrefersReducedMotionCached(false), mSystemUsesDarkTheme(-1), mSystemUsesDarkThemeCached(false), mColorTextSelectBackground(0), diff --git a/widget/gtk/nsLookAndFeel.h b/widget/gtk/nsLookAndFeel.h index 5f68c8e52e15..8c0bffcc5312 100644 --- a/widget/gtk/nsLookAndFeel.h +++ b/widget/gtk/nsLookAndFeel.h @@ -92,7 +92,6 @@ class nsLookAndFeel final : public nsXPLookAndFeel { char16_t mInvisibleCharacter = 0; float mCaretRatio = 0.0f; int32_t mCaretBlinkTime = 0; - int32_t mPrefersReducedMotion = -1; bool mMenuSupportsDrag = false; bool mCSDAvailable = false; bool mCSDHideTitlebarByDefault = false; @@ -103,7 +102,6 @@ class nsLookAndFeel final : public nsXPLookAndFeel { bool mSystemUsesDarkTheme = false; bool mHighContrast = false; bool mInitialized = false; - bool mPrefersReducedMotionCached = false; void EnsureInit(); void ConfigureContentGtkTheme(); diff --git a/widget/gtk/nsWindow.cpp b/widget/gtk/nsWindow.cpp index 82b346e0a45a..da21967cf20b 100644 --- a/widget/gtk/nsWindow.cpp +++ b/widget/gtk/nsWindow.cpp @@ -7722,16 +7722,7 @@ void nsWindow::LockAspectRatio(bool aShouldLock) { } nsresult nsWindow::SetPrefersReducedMotionOverrideForTest(bool aValue) { - LookAndFeel::SetShouldRetainCacheForTest(true); - - LookAndFeelInt prefersReducedMotion; - prefersReducedMotion.id = LookAndFeel::eIntID_PrefersReducedMotion; - prefersReducedMotion.value = aValue ? 1 : 0; - - AutoTArray lookAndFeelCache; - lookAndFeelCache.AppendElement(prefersReducedMotion); - - LookAndFeel::SetIntCache(lookAndFeelCache); + LookAndFeel::SetPrefersReducedMotionOverrideForTest(aValue); // Notify as if the corresponding setting changed. g_object_notify(G_OBJECT(gtk_settings_get_default()), @@ -7741,7 +7732,7 @@ nsresult nsWindow::SetPrefersReducedMotionOverrideForTest(bool aValue) { } nsresult nsWindow::ResetPrefersReducedMotionOverrideForTest() { - LookAndFeel::SetShouldRetainCacheForTest(false); + LookAndFeel::ResetPrefersReducedMotionOverrideForTest(); return NS_OK; } diff --git a/widget/nsXPLookAndFeel.cpp b/widget/nsXPLookAndFeel.cpp index 8f771f6137f4..460c2dc629e1 100644 --- a/widget/nsXPLookAndFeel.cpp +++ b/widget/nsXPLookAndFeel.cpp @@ -258,9 +258,6 @@ void nsXPLookAndFeel::Shutdown() { sInstance = nullptr; } -nsXPLookAndFeel::nsXPLookAndFeel() - : LookAndFeel(), mShouldRetainCacheForTest(false) {} - // static void nsXPLookAndFeel::IntPrefChanged(nsLookAndFeelIntPref* data) { if (!data) { @@ -1093,4 +1090,26 @@ void LookAndFeel::SetShouldRetainCacheForTest(bool aValue) { nsLookAndFeel::GetInstance()->SetShouldRetainCacheImplForTest(aValue); } +// static +void LookAndFeel::SetPrefersReducedMotionOverrideForTest(bool aValue) { + // Tell that the cache value we are going to set isn't cleared via + // nsPresContext::ThemeChangedInternal which is called right before + // we queue the media feature value change for this prefers-reduced-motion + // change. + SetShouldRetainCacheForTest(true); + + int32_t value = aValue ? 1 : 0; + + AutoTArray lookAndFeelCache; + lookAndFeelCache.AppendElement( + LookAndFeelInt{.id = eIntID_PrefersReducedMotion, {.value = value}}); + + SetIntCache(lookAndFeelCache); +} + +// static +void LookAndFeel::ResetPrefersReducedMotionOverrideForTest() { + SetShouldRetainCacheForTest(false); +} + } // namespace mozilla diff --git a/widget/nsXPLookAndFeel.h b/widget/nsXPLookAndFeel.h index 2e0f9aff2266..5e31aa83ce63 100644 --- a/widget/nsXPLookAndFeel.h +++ b/widget/nsXPLookAndFeel.h @@ -91,7 +91,7 @@ class nsXPLookAndFeel : public mozilla::LookAndFeel { } protected: - nsXPLookAndFeel(); + nsXPLookAndFeel() = default; static void IntPrefChanged(nsLookAndFeelIntPref* data); static void FloatPrefChanged(nsLookAndFeelFloatPref* data); @@ -124,9 +124,11 @@ class nsXPLookAndFeel : public mozilla::LookAndFeel { static bool sIsInPrefersReducedMotionForTest; static bool sPrefersReducedMotionForTest; + int32_t mPrefersReducedMotion = -1; + bool mPrefersReducedMotionCached = false; // True if we shouldn't clear the cache value in RefreshImpl(). // NOTE: This should be used only for testing. - bool mShouldRetainCacheForTest; + bool mShouldRetainCacheForTest = false; }; #endif