mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-10-09 19:35:51 +00:00
Bug 1596317 - Implement SetPrefersReducedMotionOverrideForTest backend for GTK. r=emilio
On GTK changing gtk-enable-animation in a process doesn't affect in different processes for some reasons. So we take the same approach as what we did for OSX[1] that is when SetPrefersReducedMotionOverrideForTest is called we set the given value as a cache in the parent process and send a notification to system as if the value changed thus the notification kicks PBroser.ThemeChanged to update the cache in the content process, thus we can use the cache value on querying the corresponding value in the content process. [1] https://hg.mozilla.org/mozilla-central/rev/67a5acf7363d Differential Revision: https://phabricator.services.mozilla.com/D57260 --HG-- extra : moz-landing-system : lando
This commit is contained in:
parent
ab48bc01da
commit
11f2716492
@ -1976,7 +1976,7 @@ interface nsIDOMWindowUtils : nsISupports {
|
||||
* Simulate the system setting corresponding to 'prefers-reduced-motion'
|
||||
* media queries feature is changed to 'on' or 'off'.
|
||||
*
|
||||
* Currently this function is available only on MacOSX.
|
||||
* This function doesn't work on Windows.
|
||||
*/
|
||||
void setPrefersReducedMotionOverrideForTest(in boolean aValue);
|
||||
/**
|
||||
|
@ -276,7 +276,7 @@ skip-if = verify
|
||||
[test_mq_any_hover_and_any_pointer.html]
|
||||
[test_mq_hover_and_pointer.html]
|
||||
[test_mq_prefers_reduced_motion_dynamic.html]
|
||||
run-if = (os == 'mac' || toolkit == 'android')
|
||||
run-if = !headless && (os == 'mac' || toolkit == 'android' || toolkit == 'gtk')
|
||||
[test_moz_device_pixel_ratio.html]
|
||||
[test_moz_prefixed_cursor.html]
|
||||
[test_namespace_rule.html]
|
||||
|
@ -263,6 +263,10 @@ nsresult nsLookAndFeel::InitCellHighlightColors() {
|
||||
void nsLookAndFeel::NativeInit() { EnsureInit(); }
|
||||
|
||||
void nsLookAndFeel::RefreshImpl() {
|
||||
if (mShouldRetainCacheForTest) {
|
||||
return;
|
||||
}
|
||||
|
||||
nsXPLookAndFeel::RefreshImpl();
|
||||
moz_gtk_refresh();
|
||||
|
||||
@ -270,6 +274,9 @@ void nsLookAndFeel::RefreshImpl() {
|
||||
mButtonFontCached = false;
|
||||
mFieldFontCached = false;
|
||||
mMenuFontCached = false;
|
||||
if (XRE_IsParentProcess()) {
|
||||
mPrefersReducedMotionCached = false;
|
||||
}
|
||||
|
||||
mInitialized = false;
|
||||
}
|
||||
@ -283,6 +290,12 @@ nsTArray<LookAndFeelInt> nsLookAndFeel::GetIntCacheImpl() {
|
||||
lafInt.value = GetInt(eIntID_SystemUsesDarkTheme);
|
||||
lookAndFeelIntCache.AppendElement(lafInt);
|
||||
|
||||
LookAndFeelInt prefersReducedMotion;
|
||||
prefersReducedMotion.id = eIntID_PrefersReducedMotion;
|
||||
prefersReducedMotion.value = GetInt(eIntID_PrefersReducedMotion);
|
||||
|
||||
lookAndFeelIntCache.AppendElement(prefersReducedMotion);
|
||||
|
||||
return lookAndFeelIntCache;
|
||||
}
|
||||
|
||||
@ -293,6 +306,10 @@ void nsLookAndFeel::SetIntCacheImpl(
|
||||
case eIntID_SystemUsesDarkTheme:
|
||||
mSystemUsesDarkTheme = entry.value;
|
||||
break;
|
||||
case eIntID_PrefersReducedMotion:
|
||||
mPrefersReducedMotion = entry.value;
|
||||
mPrefersReducedMotionCached = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -725,13 +742,14 @@ nsresult nsLookAndFeel::GetIntImpl(IntID aID, int32_t& aResult) {
|
||||
aResult = mCSDReversedPlacement;
|
||||
break;
|
||||
case eIntID_PrefersReducedMotion: {
|
||||
GtkSettings* settings;
|
||||
gboolean enableAnimations;
|
||||
|
||||
settings = gtk_settings_get_default();
|
||||
g_object_get(settings, "gtk-enable-animations", &enableAnimations,
|
||||
nullptr);
|
||||
aResult = enableAnimations ? 0 : 1;
|
||||
if (!mPrefersReducedMotionCached && XRE_IsParentProcess()) {
|
||||
gboolean enableAnimations;
|
||||
GtkSettings* settings = gtk_settings_get_default();
|
||||
g_object_get(settings, "gtk-enable-animations", &enableAnimations,
|
||||
nullptr);
|
||||
mPrefersReducedMotion = enableAnimations ? 0 : 1;
|
||||
}
|
||||
aResult = mPrefersReducedMotion;
|
||||
break;
|
||||
}
|
||||
case eIntID_SystemUsesDarkTheme: {
|
||||
|
@ -92,6 +92,7 @@ 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;
|
||||
@ -101,6 +102,7 @@ class nsLookAndFeel final : public nsXPLookAndFeel {
|
||||
bool mCSDReversedPlacement = false;
|
||||
bool mSystemUsesDarkTheme = false;
|
||||
bool mInitialized = false;
|
||||
bool mPrefersReducedMotionCached = false;
|
||||
|
||||
void EnsureInit();
|
||||
|
||||
|
@ -38,6 +38,7 @@
|
||||
#include "SystemTimeConverter.h"
|
||||
#include "nsViewManager.h"
|
||||
#include "nsMenuPopupFrame.h"
|
||||
#include "nsXPLookAndFeel.h"
|
||||
|
||||
#include "nsGtkKeyUtils.h"
|
||||
#include "nsGtkCursors.h"
|
||||
@ -7693,6 +7694,31 @@ void nsWindow::LockAspectRatio(bool aShouldLock) {
|
||||
ApplySizeConstraints();
|
||||
}
|
||||
|
||||
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);
|
||||
|
||||
// Notify as if the corresponding setting changed.
|
||||
g_object_notify(G_OBJECT(gtk_settings_get_default()),
|
||||
"gtk-enable-animations");
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
nsresult nsWindow::ResetPrefersReducedMotionOverrideForTest() {
|
||||
LookAndFeel::SetShouldRetainCacheForTest(false);
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
#ifdef MOZ_WAYLAND
|
||||
void nsWindow::SetEGLNativeWindowSize(
|
||||
const LayoutDeviceIntSize& aEGLWindowSize) {
|
||||
|
@ -392,6 +392,9 @@ class nsWindow final : public nsBaseWidget {
|
||||
nsresult SetSystemFont(const nsCString& aFontName) override;
|
||||
nsresult GetSystemFont(nsCString& aFontName) override;
|
||||
|
||||
nsresult SetPrefersReducedMotionOverrideForTest(bool aValue) final;
|
||||
nsresult ResetPrefersReducedMotionOverrideForTest() final;
|
||||
|
||||
typedef enum {
|
||||
CSD_SUPPORT_SYSTEM, // CSD including shadows
|
||||
CSD_SUPPORT_CLIENT, // CSD without shadows
|
||||
|
Loading…
Reference in New Issue
Block a user