Bug 1365045 - Introduce keywords for prefers-reduced-motion. r=heycam
authorHiroyuki Ikezoe <hikezoe@mozilla.com>
Tue, 24 Jul 2018 16:50:47 +0900
changeset 427926 bc2538dade14f83232b06ed2200ea63dcc32ead6
parent 427925 4460ece1444225fb5168d8a4d3e9e36b14cf0273
child 427927 786a2e4ea6ea4d64df18b820acd622cb271b2ac6
push id105590
push userhikezoe@mozilla.com
push dateTue, 24 Jul 2018 07:51:09 +0000
treeherdermozilla-inbound@928316e14923 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersheycam
bugs1365045
milestone63.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 1365045 - Introduce keywords for prefers-reduced-motion. r=heycam https://drafts.csswg.org/mediaqueries-5/#prefers-reduced-motion MozReview-Commit-ID: RQUo1DBR0W
layout/style/nsCSSKeywordList.h
layout/style/nsMediaFeatures.cpp
layout/style/nsStyleConsts.h
testing/profiles/reftest/user.js
widget/LookAndFeel.h
widget/nsXPLookAndFeel.cpp
xpcom/ds/nsGkAtomList.h
--- a/layout/style/nsCSSKeywordList.h
+++ b/layout/style/nsCSSKeywordList.h
@@ -167,16 +167,17 @@ CSS_KEY(matrix3d, matrix3d)
 CSS_KEY(max-content, max_content)
 CSS_KEY(middle, middle)
 CSS_KEY(min-content, min_content)
 CSS_KEY(move, move)
 CSS_KEY(n-resize, n_resize)
 CSS_KEY(ne-resize, ne_resize)
 CSS_KEY(nesw-resize, nesw_resize)
 CSS_KEY(no-drop, no_drop)
+CSS_KEY(no-preference, no_preference)
 CSS_KEY(no-repeat, no_repeat)
 CSS_KEY(none, none)
 CSS_KEY(normal, normal)
 CSS_KEY(not-allowed, not_allowed)
 CSS_KEY(ns-resize, ns_resize)
 CSS_KEY(nw-resize, nw_resize)
 CSS_KEY(nwse-resize, nwse_resize)
 CSS_KEY(opacity, opacity)
@@ -192,16 +193,17 @@ CSS_KEY(pan-y, pan_y)
 CSS_KEY(perspective, perspective)
 CSS_KEY(pointer, pointer)
 CSS_KEY(polygon, polygon)
 CSS_KEY(portrait, portrait)
 CSS_KEY(preserve-3d, preserve_3d)
 CSS_KEY(progress, progress)
 CSS_KEY(progressive, progressive)
 CSS_KEY(proximity, proximity)
+CSS_KEY(reduce, reduce)
 CSS_KEY(repeat, repeat)
 CSS_KEY(repeat-x, repeat_x)
 CSS_KEY(repeat-y, repeat_y)
 CSS_KEY(ridge, ridge)
 CSS_KEY(right, right)
 CSS_KEY(rotate, rotate)
 CSS_KEY(rotate3d, rotate3d)
 CSS_KEY(rotatex, rotatex)
--- a/layout/style/nsMediaFeatures.cpp
+++ b/layout/style/nsMediaFeatures.cpp
@@ -47,16 +47,23 @@ static const nsCSSKTableEntry kScanKeywo
 static const nsCSSKTableEntry kDisplayModeKeywords[] = {
   { eCSSKeyword_browser,                 StyleDisplayMode::Browser },
   { eCSSKeyword_minimal_ui,              StyleDisplayMode::MinimalUi },
   { eCSSKeyword_standalone,              StyleDisplayMode::Standalone },
   { eCSSKeyword_fullscreen,              StyleDisplayMode::Fullscreen },
   { eCSSKeyword_UNKNOWN,                 -1 }
 };
 
+static const nsCSSKeywordAndBoolTableEntry kPrefersReducedMotionKeywords[] = {
+  // NOTE: The third boolean value is the value in the Boolean Context.
+  { eCSSKeyword_no_preference, StylePrefersReducedMotion::NoPreference, false },
+  { eCSSKeyword_reduce,        StylePrefersReducedMotion::Reduce,       true },
+  { eCSSKeyword_UNKNOWN,       -1 }
+};
+
 #ifdef XP_WIN
 struct WindowsThemeName {
   LookAndFeel::WindowsTheme mId;
   nsStaticAtom** mName;
 };
 
 // Windows theme identities used in the -moz-windows-theme media query.
 const WindowsThemeName kThemeStrings[] = {
@@ -508,16 +515,38 @@ GetOperatingSystemVersion(nsIDocument* a
 static void
 GetIsGlyph(nsIDocument* aDocument, const nsMediaFeature* aFeature,
            nsCSSValue& aResult)
 {
   MOZ_ASSERT(aFeature->mReqFlags & nsMediaFeature::eUserAgentAndChromeOnly);
   aResult.SetIntValue(aDocument->IsSVGGlyphsDocument() ? 1 : 0, eCSSUnit_Integer);
 }
 
+static void
+GetPrefersReducedMotion(nsIDocument* aDocument,
+                        const nsMediaFeature* aFeature,
+                        nsCSSValue& aResult)
+{
+  StylePrefersReducedMotion prefersReducedMotion =
+    StylePrefersReducedMotion::NoPreference;
+
+  switch (LookAndFeel::GetInt(LookAndFeel::eIntID_PrefersReducedMotion, 0)) {
+    case 0:
+      prefersReducedMotion = StylePrefersReducedMotion::NoPreference;
+      break;
+    case 1:
+      prefersReducedMotion = StylePrefersReducedMotion::Reduce;
+      break;
+    default:
+      return;
+  }
+
+  aResult.SetEnumValue(prefersReducedMotion);
+}
+
 /* static */ void
 nsMediaFeatures::InitSystemMetrics()
 {
   if (sSystemMetrics)
     return;
 
   MOZ_ASSERT(NS_IsMainThread());
 
@@ -803,16 +832,24 @@ nsMediaFeatures::features[] = {
   {
     &nsGkAtoms::displayMode,
     nsMediaFeature::eMinMaxNotAllowed,
     nsMediaFeature::eEnumerated,
     nsMediaFeature::eNoRequirements,
     { kDisplayModeKeywords },
     GetDisplayMode
   },
+  {
+    &nsGkAtoms::prefersReducedMotion,
+    nsMediaFeature::eMinMaxNotAllowed,
+    nsMediaFeature::eBoolEnumerated,
+    nsMediaFeature::eNoRequirements,
+    { kPrefersReducedMotionKeywords },
+    GetPrefersReducedMotion
+  },
 
   // Webkit extensions that we support for de-facto web compatibility
   // -webkit-{min|max}-device-pixel-ratio (controlled with its own pref):
   {
     &nsGkAtoms::devicePixelRatio,
     nsMediaFeature::eMinMaxAllowed,
     nsMediaFeature::eFloat,
     nsMediaFeature::eHasWebkitPrefix |
--- a/layout/style/nsStyleConsts.h
+++ b/layout/style/nsStyleConsts.h
@@ -312,16 +312,21 @@ enum class StyleImageLayerRepeat : uint8
   NoRepeat = 0x00,
   RepeatX,
   RepeatY,
   Repeat,
   Space,
   Round
 };
 
+enum class StylePrefersReducedMotion : uint8_t {
+  NoPreference,
+  Reduce,
+};
+
 
 // See nsStyleImageLayers
 #define NS_STYLE_IMAGELAYER_SIZE_CONTAIN             0
 #define NS_STYLE_IMAGELAYER_SIZE_COVER               1
 
 // Mask mode
 #define NS_STYLE_MASK_MODE_ALPHA                0
 #define NS_STYLE_MASK_MODE_LUMINANCE            1
--- a/testing/profiles/reftest/user.js
+++ b/testing/profiles/reftest/user.js
@@ -95,10 +95,11 @@ user_pref("startup.homepage_welcome_url.
 // A fake bool pref for "@supports -moz-bool-pref" sanify test.
 user_pref("testing.supports.moz-bool-pref", false);
 // Ensure that telemetry is disabled, so we don't connect to the telemetry
 // server in the middle of the tests.
 user_pref("toolkit.telemetry.enabled", false);
 user_pref("toolkit.telemetry.server", "https://%(server)s/telemetry-dummy/");
 user_pref("ui.caretBlinkTime", -1);
 user_pref("ui.caretWidth", 1);
+user_pref("ui.prefersReducedMotion", 0);
 // Turn off the Push service.
 user_pref("dom.push.serverURL", "");
--- a/widget/LookAndFeel.h
+++ b/widget/LookAndFeel.h
@@ -432,17 +432,25 @@ public:
       * contain a close button.
       */
      eIntID_GTKCSDCloseButton,
 
      /*
       * A boolean value indicating whether or not the OS is using a dark theme,
       * which we may want to switch to as well if not overridden by the user.
       */
-     eIntID_SystemUsesDarkTheme
+     eIntID_SystemUsesDarkTheme,
+
+     /**
+      * Corresponding to prefers-reduced-motion.
+      * https://drafts.csswg.org/mediaqueries-5/#prefers-reduced-motion
+      * 0: no-preference
+      * 1: reduce
+      */
+     eIntID_PrefersReducedMotion,
   };
 
   /**
    * Windows themes we currently detect.
    */
   enum WindowsTheme {
     eWindowsTheme_Generic = 0, // unrecognized theme
     eWindowsTheme_Classic,
--- a/widget/nsXPLookAndFeel.cpp
+++ b/widget/nsXPLookAndFeel.cpp
@@ -132,17 +132,20 @@ nsLookAndFeelIntPref nsXPLookAndFeel::sI
   { "ui.GtkCSDMaximizeButton",
     eIntID_GTKCSDMaximizeButton,
     false, 0 },
   { "ui.GtkCSDCloseButton",
     eIntID_GTKCSDCloseButton,
     false, 0 },
   { "ui.systemUsesDarkTheme",
     eIntID_SystemUsesDarkTheme,
-    false, 0 }
+    false, 0 },
+  { "ui.prefersReducedMotion",
+    eIntID_PrefersReducedMotion,
+    false, 0 },
 };
 
 nsLookAndFeelFloatPref nsXPLookAndFeel::sFloatPrefs[] =
 {
   { "ui.IMEUnderlineRelativeSize",
     eFloatID_IMEUnderlineRelativeSize,
     false, 0 },
   { "ui.SpellCheckerUnderlineRelativeSize",
--- a/xpcom/ds/nsGkAtomList.h
+++ b/xpcom/ds/nsGkAtomList.h
@@ -908,16 +908,17 @@ GK_ATOM(popupanchor, "popupanchor")
 GK_ATOM(popupgroup, "popupgroup")
 GK_ATOM(popupset, "popupset")
 GK_ATOM(popupsinherittooltip, "popupsinherittooltip")
 GK_ATOM(position, "position")
 GK_ATOM(poster, "poster")
 GK_ATOM(pre, "pre")
 GK_ATOM(preceding, "preceding")
 GK_ATOM(precedingSibling, "preceding-sibling")
+GK_ATOM(prefersReducedMotion, "prefers-reduced-motion")
 GK_ATOM(prefix, "prefix")
 GK_ATOM(preload, "preload")
 GK_ATOM(mozpresentation, "mozpresentation")
 GK_ATOM(preserve, "preserve")
 GK_ATOM(preserveSpace, "preserve-space")
 GK_ATOM(preventdefault, "preventdefault")
 GK_ATOM(primary, "primary")
 GK_ATOM(print, "print")