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
This commit is contained in:
Hiroyuki Ikezoe 2020-01-14 02:17:47 +00:00
Родитель 60f73c8b99
Коммит 37f0cf306c
8 изменённых файлов: 34 добавлений и 42 удалений

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

@ -534,6 +534,10 @@ class LookAndFeel {
* or not.
*/
static void SetShouldRetainCacheForTest(bool aValue);
static void SetPrefersReducedMotionOverrideForTest(bool aValue);
static void ResetPrefersReducedMotionOverrideForTest();
};
} // namespace mozilla

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

@ -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<LookAndFeelInt, 1> 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;
}

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

@ -45,9 +45,6 @@ class nsLookAndFeel final : public nsXPLookAndFeel {
int32_t mAllowOverlayScrollbarsOverlap;
bool mAllowOverlayScrollbarsOverlapCached;
int32_t mPrefersReducedMotion;
bool mPrefersReducedMotionCached;
int32_t mSystemUsesDarkTheme;
bool mSystemUsesDarkThemeCached;

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

@ -40,8 +40,6 @@ nsLookAndFeel::nsLookAndFeel()
mUseOverlayScrollbarsCached(false),
mAllowOverlayScrollbarsOverlap(-1),
mAllowOverlayScrollbarsOverlapCached(false),
mPrefersReducedMotion(-1),
mPrefersReducedMotionCached(false),
mSystemUsesDarkTheme(-1),
mSystemUsesDarkThemeCached(false),
mColorTextSelectBackground(0),

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

@ -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();

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

@ -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<LookAndFeelInt, 1> 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;
}

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

@ -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<LookAndFeelInt, 1> lookAndFeelCache;
lookAndFeelCache.AppendElement(
LookAndFeelInt{eIntID_PrefersReducedMotion, .value = value});
SetIntCache(lookAndFeelCache);
}
// static
void LookAndFeel::ResetPrefersReducedMotionOverrideForTest() {
SetShouldRetainCacheForTest(false);
}
} // namespace mozilla

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

@ -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