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

This commit is contained in:
Daniel Holbert 2016-01-18 09:24:16 -08:00
parent 697212b502
commit e037620319
3 changed files with 13 additions and 11 deletions

View File

@ -3483,11 +3483,13 @@ CSSParserImpl::ParseMediaQueryExpression(nsMediaQuery* aQuery)
// 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-"))) {
@ -3503,12 +3505,6 @@ CSSParserImpl::ParseMediaQueryExpression(nsMediaQuery* aQuery)
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.)

View File

@ -523,12 +523,13 @@ nsMediaFeatures::features[] = {
},
// 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
},

View File

@ -52,8 +52,13 @@ struct nsMediaFeature
// 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;