Bug 1486971 - Query NSWorkspace.accessibilityDisplayShouldReduceMotion only if it's on parent processes or it's the initial query on child processes. r=mstange
authorHiroyuki Ikezoe <hikezoe@mozilla.com>
Sat, 15 Sep 2018 00:59:54 +0000
changeset 492143 cea8a92452d58e492b4498e9387b743261146921
parent 492142 e92f3e990b354ba419bfc02206da0254595097a8
child 492144 67a5acf7363d9dd2c8532967ec1beb0c200abc2c
push id9984
push userffxbld-merge
push dateMon, 15 Oct 2018 21:07:35 +0000
treeherdermozilla-beta@183d27ea8570 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmstange
bugs1486971
milestone64.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1486971 - Query NSWorkspace.accessibilityDisplayShouldReduceMotion only if it's on parent processes or it's the initial query on child processes. r=mstange In child processes on MacOSX we don't spin native event loop at all. Without native event loops NSWorkspace.accessibilityDisplayShouldReduceMotion doesn't return up-to-date value when the system setting changed for some reasons. To workaround this we use NSWorkspace.accessibilityDisplayShouldReduceMotion only on the parent process which spins native event loop or when it's the initial query on the child process. And we give the up-to-date value to the child process via an IPC call just like other cached values do. Depends on D5002 Differential Revision: https://phabricator.services.mozilla.com/D5003
widget/cocoa/nsLookAndFeel.h
widget/cocoa/nsLookAndFeel.mm
--- a/widget/cocoa/nsLookAndFeel.h
+++ b/widget/cocoa/nsLookAndFeel.h
@@ -41,16 +41,19 @@ protected:
 
 private:
   int32_t mUseOverlayScrollbars;
   bool mUseOverlayScrollbarsCached;
 
   int32_t mAllowOverlayScrollbarsOverlap;
   bool mAllowOverlayScrollbarsOverlapCached;
 
+  int32_t mPrefersReducedMotion;
+  bool mPrefersReducedMotionCached;
+
   nscolor mColorTextSelectBackground;
   nscolor mColorTextSelectBackgroundDisabled;
   nscolor mColorHighlight;
   nscolor mColorMenuHover;
   nscolor mColorTextSelectForeground;
   nscolor mColorMenuHoverText;
   nscolor mColorButtonText;
   bool mHasColorButtonText;
--- a/widget/cocoa/nsLookAndFeel.mm
+++ b/widget/cocoa/nsLookAndFeel.mm
@@ -38,16 +38,18 @@ typedef NSInteger mozNSScrollerStyle;
 @end
 
 nsLookAndFeel::nsLookAndFeel()
  : nsXPLookAndFeel()
  , mUseOverlayScrollbars(-1)
  , mUseOverlayScrollbarsCached(false)
  , mAllowOverlayScrollbarsOverlap(-1)
  , mAllowOverlayScrollbarsOverlapCached(false)
+ , mPrefersReducedMotion(-1)
+ , mPrefersReducedMotionCached(false)
  , mColorTextSelectBackground(0)
  , mColorTextSelectBackgroundDisabled(0)
  , mColorHighlight(0)
  , mColorMenuHover(0)
  , mColorTextSelectForeground(0)
  , mColorMenuHoverText(0)
  , mColorButtonText(0)
  , mHasColorButtonText(false)
@@ -114,16 +116,17 @@ nsLookAndFeel::RefreshImpl()
   nsXPLookAndFeel::RefreshImpl();
 
   // We should only clear the cache if we're in the main browser process.
   // Otherwise, we should wait for the parent to inform us of new values
   // to cache via LookAndFeel::SetIntCache.
   if (XRE_IsParentProcess()) {
     mUseOverlayScrollbarsCached = false;
     mAllowOverlayScrollbarsOverlapCached = false;
+    mPrefersReducedMotionCached = false;
   }
 
   // Fetch colors next time they are requested.
   mInitialized = false;
 }
 
 nsresult
 nsLookAndFeel::NativeGetColor(ColorID aID, nscolor &aColor)
@@ -545,22 +548,30 @@ nsLookAndFeel::GetIntImpl(IntID aID, int
       break;
     case eIntID_ContextMenuOffsetHorizontal:
       aResult = 1;
       break;
     case eIntID_SystemUsesDarkTheme:
       aResult = SystemWantsDarkTheme();
       break;
     case eIntID_PrefersReducedMotion:
-      aResult = 0;
-      if ([[NSWorkspace sharedWorkspace] respondsToSelector:@selector(
-            accessibilityDisplayShouldReduceMotion)]) {
-        aResult =
-          [[NSWorkspace sharedWorkspace] accessibilityDisplayShouldReduceMotion] ? 1 : 0;
+      // Without native event loops,
+      // NSWorkspace.accessibilityDisplayShouldReduceMotion returns stale
+      // information, so we get the information only on the parent processes
+      // or when it's the initial query on child processes.  Otherwise we will
+      // get the info via LookAndFeel::SetIntCache on child processes.
+      if (!mPrefersReducedMotionCached &&
+          [[NSWorkspace sharedWorkspace] respondsToSelector:@selector(
+              accessibilityDisplayShouldReduceMotion)]) {
+        mPrefersReducedMotion =
+          [[NSWorkspace sharedWorkspace]
+            accessibilityDisplayShouldReduceMotion] ? 1 : 0;
+        mPrefersReducedMotionCached = true;
       }
+      aResult = mPrefersReducedMotion;
       break;
     default:
       aResult = 0;
       res = NS_ERROR_FAILURE;
   }
   return res;
 
   NS_OBJC_END_TRY_ABORT_BLOCK_NSRESULT;
@@ -656,32 +667,41 @@ nsLookAndFeel::GetIntCacheImpl()
   useOverlayScrollbars.value = GetInt(eIntID_UseOverlayScrollbars);
   lookAndFeelIntCache.AppendElement(useOverlayScrollbars);
 
   LookAndFeelInt allowOverlayScrollbarsOverlap;
   allowOverlayScrollbarsOverlap.id = eIntID_AllowOverlayScrollbarsOverlap;
   allowOverlayScrollbarsOverlap.value = GetInt(eIntID_AllowOverlayScrollbarsOverlap);
   lookAndFeelIntCache.AppendElement(allowOverlayScrollbarsOverlap);
 
+  LookAndFeelInt prefersReducedMotion;
+  prefersReducedMotion.id = eIntID_PrefersReducedMotion;
+  prefersReducedMotion.value = GetInt(eIntID_PrefersReducedMotion);
+  lookAndFeelIntCache.AppendElement(prefersReducedMotion);
+
   return lookAndFeelIntCache;
 }
 
 void
 nsLookAndFeel::SetIntCacheImpl(const nsTArray<LookAndFeelInt>& aLookAndFeelIntCache)
 {
   for (auto entry : aLookAndFeelIntCache) {
     switch(entry.id) {
       case eIntID_UseOverlayScrollbars:
         mUseOverlayScrollbars = entry.value;
         mUseOverlayScrollbarsCached = true;
         break;
       case eIntID_AllowOverlayScrollbarsOverlap:
         mAllowOverlayScrollbarsOverlap = entry.value;
         mAllowOverlayScrollbarsOverlapCached = true;
         break;
+      case eIntID_PrefersReducedMotion:
+        mPrefersReducedMotion = entry.value;
+        mPrefersReducedMotionCached = true;
+        break;
     }
   }
 }
 
 void
 nsLookAndFeel::EnsureInit()
 {
   if (mInitialized) {