Bug 1365045 - Introduce keywords for prefers-reduced-motion. r?heycam draft
authorHiroyuki Ikezoe <hikezoe@mozilla.com>
Tue, 17 Jul 2018 11:05:35 +0900
changeset 819060 8a4637b34c6f67321aa5dc9b288915a63010ddd6
parent 819019 f6df6a982ee9510ca32dd3afa52dfe9f8c3586a3
child 819061 6a07681204272788a15290d7f023d1feedb7aef1
push id116425
push userbmo:hikezoe@mozilla.com
push dateTue, 17 Jul 2018 02:07:15 +0000
reviewersheycam
bugs1365045
milestone63.0a1
Bug 1365045 - Introduce keywords for prefers-reduced-motion. r?heycam https://drafts.csswg.org/mediaqueries-5/#prefers-reduced-motion I didn't intentionally add any test cases here since WebKit has already good test cases and they should be uplifted to wpt. MozReview-Commit-ID: 8KCMwlaDOrL
layout/style/nsCSSKeywordList.h
layout/style/nsMediaFeatures.cpp
layout/style/nsStyleConsts.h
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,22 @@ 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 nsCSSProps::KTableEntry kPrefersReducedMotionKeywords[] = {
+  { eCSSKeyword_no_preference, StylePrefersReducedMotion::NoPreference },
+  { eCSSKeyword_reduce,        StylePrefersReducedMotion::Reduce },
+  { 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 +514,37 @@ 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:
+      return;
+    case 1:
+      prefersReducedMotion = StylePrefersReducedMotion::Reduce;
+      break;
+    default:
+      return;
+  }
+
+  aResult.SetEnumValue(prefersReducedMotion);
+}
+
 /* static */ void
 nsMediaFeatures::InitSystemMetrics()
 {
   if (sSystemMetrics)
     return;
 
   MOZ_ASSERT(NS_IsMainThread());
 
@@ -803,16 +830,24 @@ nsMediaFeatures::features[] = {
   {
     &nsGkAtoms::displayMode,
     nsMediaFeature::eMinMaxNotAllowed,
     nsMediaFeature::eEnumerated,
     nsMediaFeature::eNoRequirements,
     { kDisplayModeKeywords },
     GetDisplayMode
   },
+  {
+    &nsGkAtoms::prefersReducedMotion,
+    nsMediaFeature::eMinMaxNotAllowed,
+    nsMediaFeature::eEnumerated,
+    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
@@ -303,16 +303,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/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
@@ -913,16 +913,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")