Bug 1239799 part 1: Make check for -webkit-device-pixel-ratio pref more targeted, so we can support other webkit-prefixed media queries. r=heycam
authorDaniel Holbert <dholbert@cs.stanford.edu>
Mon, 18 Jan 2016 09:24:16 -0800
changeset 317413 a1674bc106ab2af7d7caa5226899d8c0d0181c90
parent 317412 a5472dd5fafded59961360da30e166e0c1bf27fd
child 317414 5c6accc2386666ec9361024db8f6db8779ea788e
push id1079
push userjlund@mozilla.com
push dateFri, 15 Apr 2016 21:02:33 +0000
treeherdermozilla-release@575fbf6786d5 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersheycam
bugs1239799
milestone46.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 1239799 part 1: Make check for -webkit-device-pixel-ratio pref more targeted, so we can support other webkit-prefixed media queries. r=heycam
layout/style/nsCSSParser.cpp
layout/style/nsMediaFeatures.cpp
layout/style/nsMediaFeatures.h
--- a/layout/style/nsCSSParser.cpp
+++ b/layout/style/nsCSSParser.cpp
@@ -3478,42 +3478,38 @@ CSSParserImpl::ParseMediaQueryExpression
 
   // case insensitive from CSS - must be lower cased
   nsContentUtils::ASCIIToLower(mToken.mIdent);
   nsDependentString featureString(mToken.mIdent, 0);
   uint8_t satisfiedReqFlags = 0;
 
   // Strip off "-webkit-" prefix from featureString:
   if (sWebkitPrefixedAliasesEnabled &&
-      sWebkitDevicePixelRatioEnabled &&
       StringBeginsWith(featureString, NS_LITERAL_STRING("-webkit-"))) {
     satisfiedReqFlags |= nsMediaFeature::eHasWebkitPrefix;
     featureString.Rebind(featureString, 8);
   }
+  if (sWebkitDevicePixelRatioEnabled) {
+    satisfiedReqFlags |= nsMediaFeature::eWebkitDevicePixelRatioPrefEnabled;
+  }
 
   // Strip off "min-"/"max-" prefix from featureString:
   if (StringBeginsWith(featureString, NS_LITERAL_STRING("min-"))) {
     expr->mRange = nsMediaExpression::eMin;
     featureString.Rebind(featureString, 4);
   } else if (StringBeginsWith(featureString, NS_LITERAL_STRING("max-"))) {
     expr->mRange = nsMediaExpression::eMax;
     featureString.Rebind(featureString, 4);
   } else {
     expr->mRange = nsMediaExpression::eEqual;
   }
 
   nsCOMPtr<nsIAtom> mediaFeatureAtom = do_GetAtom(featureString);
   const nsMediaFeature *feature = nsMediaFeatures::features;
   for (; feature->mName; ++feature) {
-    MOZ_ASSERT(!(feature->mReqFlags & nsMediaFeature::eHasWebkitPrefix) ||
-               *(feature->mName) == nsGkAtoms::devicePixelRatio,
-               "If we add support for a webkit-prefixed media-query feature "
-               "*other than* device-pixel-ratio, we need to adjust logic "
-               "above around sWebkitDevicePixelRatioEnabled.");
-
     // See if name matches & all requirement flags are satisfied:
     // (We check requirements by turning off all of the flags that have been
     // satisfied, and then see if the result is 0.)
     if (*(feature->mName) == mediaFeatureAtom &&
         !(feature->mReqFlags & ~satisfiedReqFlags)) {
       break;
     }
   }
--- a/layout/style/nsMediaFeatures.cpp
+++ b/layout/style/nsMediaFeatures.cpp
@@ -518,22 +518,23 @@ nsMediaFeatures::features[] = {
     nsMediaFeature::eMinMaxNotAllowed,
     nsMediaFeature::eBoolInteger,
     nsMediaFeature::eNoRequirements,
     { nullptr },
     GetGrid
   },
 
   // Webkit extensions that we support for de-facto web compatibility
-  // -webkit-{min|max}-device-pixel-ratio:
+  // -webkit-{min|max}-device-pixel-ratio (controlled with its own pref):
   {
     &nsGkAtoms::devicePixelRatio,
     nsMediaFeature::eMinMaxAllowed,
     nsMediaFeature::eFloat,
-    nsMediaFeature::eHasWebkitPrefix,
+    nsMediaFeature::eHasWebkitPrefix |
+      nsMediaFeature::eWebkitDevicePixelRatioPrefEnabled,
     { nullptr },
     GetDevicePixelRatio
   },
 
   // Mozilla extensions
   {
     &nsGkAtoms::_moz_device_pixel_ratio,
     nsMediaFeature::eMinMaxAllowed,
--- a/layout/style/nsMediaFeatures.h
+++ b/layout/style/nsMediaFeatures.h
@@ -47,18 +47,23 @@ struct nsMediaFeature
     // not allow zeros in eIntRatio types.
   };
   ValueType mValueType;
 
   enum RequirementFlags : uint8_t {
     // Bitfield of requirements that must be satisfied in order for this
     // media feature to be active.
     eNoRequirements = 0,
-    eHasWebkitPrefix = 1 // Feature name must start w/ "-webkit-", even
-                         // before any "min-"/"max-" qualifier.
+    eHasWebkitPrefix = 1 << 0, // Feature name must start w/ "-webkit-", even
+                               // before any "min-"/"max-" qualifier.
+
+    // Feature is only supported if the pref
+    // "layout.css.prefixes.device-pixel-ratio-webkit" is enabled.
+    // (Should only be used for -webkit-device-pixel-ratio.)
+    eWebkitDevicePixelRatioPrefEnabled = 1 << 1
   };
   uint8_t mReqFlags;
 
   union {
     // In static arrays, it's the first member that's initialized.  We
     // need that to be void* so we can initialize both other types.
     // This member should never be accessed by name.
     const void* mInitializer_;