From 37f0cf306cb9a1f91d2629f8a155f04dd5c2cd77 Mon Sep 17 00:00:00 2001 From: Hiroyuki Ikezoe Date: Tue, 14 Jan 2020 02:17:47 +0000 Subject: [PATCH] Bug 1606503 - Move prefers-reduced-motion bits for testing into LookAndFeel. r=emilio Now both of GTK and MacOSX backends use the same machinery, LookAndFeelInt, for prefers-reduced-motion. And we are going to use it on Android as well so it'd make sense to move the code into there. On Windows we can also use the same LookAndFeelInt machinery and probably all we have to do is to call SendNotifyMessage with SPI_SETCLIENTAREAANIMATION in SetPrefersReducedMotionOverrideForTest. Differential Revision: https://phabricator.services.mozilla.com/D59022 --HG-- extra : moz-landing-system : lando --- widget/LookAndFeel.h | 4 ++++ widget/cocoa/nsChildView.mm | 21 ++------------------- widget/cocoa/nsLookAndFeel.h | 3 --- widget/cocoa/nsLookAndFeel.mm | 2 -- widget/gtk/nsLookAndFeel.h | 2 -- widget/gtk/nsWindow.cpp | 13 ++----------- widget/nsXPLookAndFeel.cpp | 25 ++++++++++++++++++++++--- widget/nsXPLookAndFeel.h | 6 ++++-- 8 files changed, 34 insertions(+), 42 deletions(-) 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..739ecda0ed4f 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{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