Bug 1269975 part 1 - Move nsCSSProps::EnabledState to a top level enum class mozilla::CSSEnabledState. r=heycam

MozReview-Commit-ID: 3KH5cqDFzUI

--HG--
extra : rebase_source : 3c8355f7807982152a16a913b31cbcdd6ef78030
extra : source : 73e89d25a34ca5587f306b848b0b801342f9432f
This commit is contained in:
Xidorn Quan 2016-05-10 18:44:05 +10:00
parent a0d82b351a
commit fa7ba2cb82
24 changed files with 137 additions and 135 deletions

View File

@ -101,7 +101,7 @@ public:
if (mSubpropertyCount[aProperty] == 0) { if (mSubpropertyCount[aProperty] == 0) {
uint32_t count = 0; uint32_t count = 0;
CSSPROPS_FOR_SHORTHAND_SUBPROPERTIES( CSSPROPS_FOR_SHORTHAND_SUBPROPERTIES(
p, aProperty, nsCSSProps::eEnabledForAllContent) { p, aProperty, CSSEnabledState::eForAllContent) {
++count; ++count;
} }
mSubpropertyCount[aProperty] = count; mSubpropertyCount[aProperty] = count;
@ -492,13 +492,13 @@ KeyframeUtils::GetAnimationPropertiesFromKeyframes(
if (nsCSSProps::IsShorthand(pair.mProperty)) { if (nsCSSProps::IsShorthand(pair.mProperty)) {
nsCSSValueTokenStream* tokenStream = pair.mValue.GetTokenStreamValue(); nsCSSValueTokenStream* tokenStream = pair.mValue.GetTokenStreamValue();
if (!StyleAnimationValue::ComputeValues(pair.mProperty, if (!StyleAnimationValue::ComputeValues(pair.mProperty,
nsCSSProps::eEnabledForAllContent, aElement, aStyleContext, CSSEnabledState::eForAllContent, aElement, aStyleContext,
tokenStream->mTokenStream, /* aUseSVGMode */ false, values)) { tokenStream->mTokenStream, /* aUseSVGMode */ false, values)) {
continue; continue;
} }
} else { } else {
if (!StyleAnimationValue::ComputeValues(pair.mProperty, if (!StyleAnimationValue::ComputeValues(pair.mProperty,
nsCSSProps::eEnabledForAllContent, aElement, aStyleContext, CSSEnabledState::eForAllContent, aElement, aStyleContext,
pair.mValue, /* aUseSVGMode */ false, values)) { pair.mValue, /* aUseSVGMode */ false, values)) {
continue; continue;
} }
@ -695,7 +695,7 @@ GetPropertyValuesPairs(JSContext* aCx,
} }
nsCSSProperty property = nsCSSProperty property =
nsCSSProps::LookupPropertyByIDLName(propName, nsCSSProps::LookupPropertyByIDLName(propName,
nsCSSProps::eEnabledForAllContent); CSSEnabledState::eForAllContent);
if (property != eCSSProperty_UNKNOWN && if (property != eCSSProperty_UNKNOWN &&
(nsCSSProps::IsShorthand(property) || (nsCSSProps::IsShorthand(property) ||
nsCSSProps::kAnimTypeTable[property] != eStyleAnimType_None)) { nsCSSProps::kAnimTypeTable[property] != eStyleAnimType_None)) {
@ -1110,7 +1110,7 @@ RequiresAdditiveAnimation(const nsTArray<Keyframe>& aKeyframes,
continue; continue;
} }
CSSPROPS_FOR_SHORTHAND_SUBPROPERTIES( CSSPROPS_FOR_SHORTHAND_SUBPROPERTIES(
prop, pair.mProperty, nsCSSProps::eEnabledForAllContent) { prop, pair.mProperty, CSSEnabledState::eForAllContent) {
addToPropertySets(*prop, offsetToUse); addToPropertySets(*prop, offsetToUse);
} }
} else { } else {

View File

@ -2503,7 +2503,7 @@ nsDOMWindowUtils::ComputeAnimationDistance(nsIDOMElement* aElement,
NS_ENSURE_SUCCESS(rv, rv); NS_ENSURE_SUCCESS(rv, rv);
nsCSSProperty property = nsCSSProperty property =
nsCSSProps::LookupProperty(aProperty, nsCSSProps::eIgnoreEnabledState); nsCSSProps::LookupProperty(aProperty, CSSEnabledState::eIgnoreEnabledState);
if (property != eCSSProperty_UNKNOWN && nsCSSProps::IsShorthand(property)) { if (property != eCSSProperty_UNKNOWN && nsCSSProps::IsShorthand(property)) {
property = eCSSProperty_UNKNOWN; property = eCSSProperty_UNKNOWN;
} }

View File

@ -686,7 +686,7 @@ nsSMILAnimationController::GetTargetIdentifierForAnimation(
} else { } else {
nsCSSProperty prop = nsCSSProperty prop =
nsCSSProps::LookupProperty(nsDependentAtomString(attributeName), nsCSSProps::LookupProperty(nsDependentAtomString(attributeName),
nsCSSProps::eEnabledForAllContent); CSSEnabledState::eForAllContent);
isCSS = nsSMILCSSProperty::IsPropertyAnimatable(prop); isCSS = nsSMILCSSProperty::IsPropertyAnimatable(prop);
} }
} }

View File

@ -126,7 +126,7 @@ nsSMILCompositor::CreateSMILAttr()
if (mKey.mIsCSS) { if (mKey.mIsCSS) {
nsCSSProperty propId = nsCSSProperty propId =
nsCSSProps::LookupProperty(nsDependentAtomString(mKey.mAttributeName), nsCSSProps::LookupProperty(nsDependentAtomString(mKey.mAttributeName),
nsCSSProps::eEnabledForAllContent); CSSEnabledState::eForAllContent);
if (nsSMILCSSProperty::IsPropertyAnimatable(propId)) { if (nsSMILCSSProperty::IsPropertyAnimatable(propId)) {
return new nsSMILCSSProperty(propId, mKey.mElement.get()); return new nsSMILCSSProperty(propId, mKey.mElement.get());
} }

View File

@ -1186,7 +1186,7 @@ MappedAttrParser::ParseMappedAttrValue(nsIAtom* aMappedAttrName,
// Get the nsCSSProperty ID for our mapped attribute. // Get the nsCSSProperty ID for our mapped attribute.
nsCSSProperty propertyID = nsCSSProperty propertyID =
nsCSSProps::LookupProperty(nsDependentAtomString(aMappedAttrName), nsCSSProps::LookupProperty(nsDependentAtomString(aMappedAttrName),
nsCSSProps::eEnabledForAllContent); CSSEnabledState::eForAllContent);
if (propertyID != eCSSProperty_UNKNOWN) { if (propertyID != eCSSProperty_UNKNOWN) {
bool changed = false; // outparam for ParseProperty. bool changed = false; // outparam for ParseProperty.
mParser.ParseProperty(propertyID, aMappedAttrValue, mDocURI, mBaseURI, mParser.ParseProperty(propertyID, aMappedAttrValue, mDocURI, mBaseURI,
@ -1196,7 +1196,7 @@ MappedAttrParser::ParseMappedAttrValue(nsIAtom* aMappedAttrName,
// since it doesn't have a sheet. // since it doesn't have a sheet.
if (nsCSSProps::IsShorthand(propertyID)) { if (nsCSSProps::IsShorthand(propertyID)) {
CSSPROPS_FOR_SHORTHAND_SUBPROPERTIES(subprop, propertyID, CSSPROPS_FOR_SHORTHAND_SUBPROPERTIES(subprop, propertyID,
nsCSSProps::eEnabledForAllContent) { CSSEnabledState::eForAllContent) {
UseCounter useCounter = nsCSSProps::UseCounterFor(*subprop); UseCounter useCounter = nsCSSProps::UseCounterFor(*subprop);
if (useCounter != eUseCounter_UNKNOWN) { if (useCounter != eUseCounter_UNKNOWN) {
mElement->OwnerDoc()->SetDocumentAndPageUseCounter(useCounter); mElement->OwnerDoc()->SetDocumentAndPageUseCounter(useCounter);
@ -2544,7 +2544,7 @@ nsSVGElement::GetAnimatedAttr(int32_t aNamespaceID, nsIAtom* aName)
if (IsAttributeMapped(aName)) { if (IsAttributeMapped(aName)) {
nsCSSProperty prop = nsCSSProperty prop =
nsCSSProps::LookupProperty(nsDependentAtomString(aName), nsCSSProps::LookupProperty(nsDependentAtomString(aName),
nsCSSProps::eEnabledForAllContent); CSSEnabledState::eForAllContent);
// Check IsPropertyAnimatable to avoid attributes that... // Check IsPropertyAnimatable to avoid attributes that...
// - map to explicitly unanimatable properties (e.g. 'direction') // - map to explicitly unanimatable properties (e.g. 'direction')
// - map to unsupported attributes (e.g. 'glyph-orientation-horizontal') // - map to unsupported attributes (e.g. 'glyph-orientation-horizontal')

View File

@ -522,7 +522,7 @@ nsHTMLCSSUtils::GetCSSInlinePropertyBase(nsINode* aNode, nsIAtom* aProperty,
} }
nsCSSProperty prop = nsCSSProperty prop =
nsCSSProps::LookupProperty(nsDependentAtomString(aProperty), nsCSSProps::LookupProperty(nsDependentAtomString(aProperty),
nsCSSProps::eEnabledForAllContent); CSSEnabledState::eForAllContent);
MOZ_ASSERT(prop != eCSSProperty_UNKNOWN); MOZ_ASSERT(prop != eCSSProperty_UNKNOWN);
decl->GetValue(prop, aValue); decl->GetValue(prop, aValue);

View File

@ -224,7 +224,7 @@ inCSSValueSearch::AddPropertyCriteria(const char16_t *aPropName)
{ {
nsCSSProperty prop = nsCSSProperty prop =
nsCSSProps::LookupProperty(nsDependentString(aPropName), nsCSSProps::LookupProperty(nsDependentString(aPropName),
nsCSSProps::eIgnoreEnabledState); CSSEnabledState::eIgnoreEnabledState);
mProperties[mPropertyCount] = prop; mProperties[mPropertyCount] = prop;
mPropertyCount++; mPropertyCount++;
return NS_OK; return NS_OK;

View File

@ -485,8 +485,8 @@ inDOMUtils::SelectorMatchesElement(nsIDOMElement* aElement,
NS_IMETHODIMP NS_IMETHODIMP
inDOMUtils::IsInheritedProperty(const nsAString &aPropertyName, bool *_retval) inDOMUtils::IsInheritedProperty(const nsAString &aPropertyName, bool *_retval)
{ {
nsCSSProperty prop = nsCSSProperty prop = nsCSSProps::
nsCSSProps::LookupProperty(aPropertyName, nsCSSProps::eIgnoreEnabledState); LookupProperty(aPropertyName, CSSEnabledState::eIgnoreEnabledState);
if (prop == eCSSProperty_UNKNOWN) { if (prop == eCSSProperty_UNKNOWN) {
*_retval = false; *_retval = false;
return NS_OK; return NS_OK;
@ -528,14 +528,14 @@ inDOMUtils::GetCSSPropertyNames(uint32_t aFlags, uint32_t* aCount,
char16_t** props = char16_t** props =
static_cast<char16_t**>(moz_xmalloc(maxCount * sizeof(char16_t*))); static_cast<char16_t**>(moz_xmalloc(maxCount * sizeof(char16_t*)));
#define DO_PROP(_prop) \ #define DO_PROP(_prop) \
PR_BEGIN_MACRO \ PR_BEGIN_MACRO \
nsCSSProperty cssProp = nsCSSProperty(_prop); \ nsCSSProperty cssProp = nsCSSProperty(_prop); \
if (nsCSSProps::IsEnabled(cssProp, nsCSSProps::eEnabledForAllContent)) { \ if (nsCSSProps::IsEnabled(cssProp, CSSEnabledState::eForAllContent)) { \
props[propCount] = \ props[propCount] = \
ToNewUnicode(nsDependentCString(kCSSRawProperties[_prop])); \ ToNewUnicode(nsDependentCString(kCSSRawProperties[_prop])); \
++propCount; \ ++propCount; \
} \ } \
PR_END_MACRO PR_END_MACRO
// prop is the property id we're considering; propCount is how many properties // prop is the property id we're considering; propCount is how many properties
@ -674,7 +674,7 @@ inDOMUtils::GetSubpropertiesForCSSProperty(const nsAString& aProperty,
char16_t*** aValues) char16_t*** aValues)
{ {
nsCSSProperty propertyID = nsCSSProperty propertyID =
nsCSSProps::LookupProperty(aProperty, nsCSSProps::eEnabledForAllContent); nsCSSProps::LookupProperty(aProperty, CSSEnabledState::eForAllContent);
if (propertyID == eCSSProperty_UNKNOWN) { if (propertyID == eCSSProperty_UNKNOWN) {
return NS_ERROR_FAILURE; return NS_ERROR_FAILURE;
@ -716,7 +716,7 @@ NS_IMETHODIMP
inDOMUtils::CssPropertyIsShorthand(const nsAString& aProperty, bool *_retval) inDOMUtils::CssPropertyIsShorthand(const nsAString& aProperty, bool *_retval)
{ {
nsCSSProperty propertyID = nsCSSProperty propertyID =
nsCSSProps::LookupProperty(aProperty, nsCSSProps::eEnabledForAllContent); nsCSSProps::LookupProperty(aProperty, CSSEnabledState::eForAllContent);
if (propertyID == eCSSProperty_UNKNOWN) { if (propertyID == eCSSProperty_UNKNOWN) {
return NS_ERROR_FAILURE; return NS_ERROR_FAILURE;
} }
@ -861,7 +861,7 @@ inDOMUtils::CssPropertySupportsType(const nsAString& aProperty, uint32_t aType,
bool *_retval) bool *_retval)
{ {
nsCSSProperty propertyID = nsCSSProperty propertyID =
nsCSSProps::LookupProperty(aProperty, nsCSSProps::eEnabledForAllContent); nsCSSProps::LookupProperty(aProperty, CSSEnabledState::eForAllContent);
if (propertyID == eCSSProperty_UNKNOWN) { if (propertyID == eCSSProperty_UNKNOWN) {
return NS_ERROR_FAILURE; return NS_ERROR_FAILURE;
} }
@ -921,8 +921,8 @@ inDOMUtils::GetCSSValuesForProperty(const nsAString& aProperty,
uint32_t* aLength, uint32_t* aLength,
char16_t*** aValues) char16_t*** aValues)
{ {
nsCSSProperty propertyID = nsCSSProps::LookupProperty(aProperty, nsCSSProperty propertyID = nsCSSProps::
nsCSSProps::eEnabledForAllContent); LookupProperty(aProperty, CSSEnabledState::eForAllContent);
if (propertyID == eCSSProperty_UNKNOWN) { if (propertyID == eCSSProperty_UNKNOWN) {
return NS_ERROR_FAILURE; return NS_ERROR_FAILURE;
} }
@ -944,7 +944,7 @@ inDOMUtils::GetCSSValuesForProperty(const nsAString& aProperty,
} else { } else {
// Property is shorthand. // Property is shorthand.
CSSPROPS_FOR_SHORTHAND_SUBPROPERTIES(subproperty, propertyID, CSSPROPS_FOR_SHORTHAND_SUBPROPERTIES(subproperty, propertyID,
nsCSSProps::eEnabledForAllContent) { CSSEnabledState::eForAllContent) {
// Get colors (once) first. // Get colors (once) first.
uint32_t propertyParserVariant = nsCSSProps::ParserVariant(*subproperty); uint32_t propertyParserVariant = nsCSSProps::ParserVariant(*subproperty);
if (propertyParserVariant & VARIANT_COLOR) { if (propertyParserVariant & VARIANT_COLOR) {
@ -953,7 +953,7 @@ inDOMUtils::GetCSSValuesForProperty(const nsAString& aProperty,
} }
} }
CSSPROPS_FOR_SHORTHAND_SUBPROPERTIES(subproperty, propertyID, CSSPROPS_FOR_SHORTHAND_SUBPROPERTIES(subproperty, propertyID,
nsCSSProps::eEnabledForAllContent) { CSSEnabledState::eForAllContent) {
uint32_t propertyParserVariant = nsCSSProps::ParserVariant(*subproperty); uint32_t propertyParserVariant = nsCSSProps::ParserVariant(*subproperty);
if (propertyParserVariant & VARIANT_KEYWORD) { if (propertyParserVariant & VARIANT_KEYWORD) {
GetKeywordsForProperty(*subproperty, array); GetKeywordsForProperty(*subproperty, array);
@ -1056,8 +1056,8 @@ inDOMUtils::CssPropertyIsValid(const nsAString& aPropertyName,
const nsAString& aPropertyValue, const nsAString& aPropertyValue,
bool *_retval) bool *_retval)
{ {
nsCSSProperty propertyID = nsCSSProperty propertyID = nsCSSProps::
nsCSSProps::LookupProperty(aPropertyName, nsCSSProps::eIgnoreEnabledState); LookupProperty(aPropertyName, CSSEnabledState::eIgnoreEnabledState);
if (propertyID == eCSSProperty_UNKNOWN) { if (propertyID == eCSSProperty_UNKNOWN) {
*_retval = false; *_retval = false;

View File

@ -0,0 +1,39 @@
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
/*
* enum for whether a CSS feature (property, pseudo-class, etc.) is
* enabled in a specific context
*/
#ifndef mozilla_CSSEnabledState_h
#define mozilla_CSSEnabledState_h
#include "mozilla/TypedEnumBits.h"
namespace mozilla {
enum class CSSEnabledState
{
// The default CSSEnabledState: only enable what's enabled for all
// content, given the current values of preferences.
eForAllContent = 0,
// Enable features available in UA sheets.
eInUASheets = 0x01,
// Enable features available in chrome code.
eInChrome = 0x02,
// Special value to unconditionally enable everything. This implies
// all the bits above, but is strictly more than just their OR-ed
// union. This just skips any test so a feature will be enabled even
// if it would have been disabled with all the bits above set.
eIgnoreEnabledState = 0xff
};
MOZ_MAKE_ENUM_CLASS_BITWISE_OPERATORS(CSSEnabledState)
} // namespace mozilla
#endif // mozilla_CSSEnabledState_h

View File

@ -146,7 +146,7 @@ Declaration::RemoveProperty(nsCSSProperty aProperty)
if (nsCSSProps::IsShorthand(aProperty)) { if (nsCSSProps::IsShorthand(aProperty)) {
CSSPROPS_FOR_SHORTHAND_SUBPROPERTIES(p, aProperty, CSSPROPS_FOR_SHORTHAND_SUBPROPERTIES(p, aProperty,
nsCSSProps::eEnabledForAllContent) { CSSEnabledState::eForAllContent) {
data.ClearLonghandProperty(*p); data.ClearLonghandProperty(*p);
mOrder.RemoveElement(static_cast<uint32_t>(*p)); mOrder.RemoveElement(static_cast<uint32_t>(*p));
} }
@ -512,7 +512,7 @@ Declaration::GetValue(nsCSSProperty aProperty, nsAString& aValue,
initialCount = 0, inheritCount = 0, unsetCount = 0, initialCount = 0, inheritCount = 0, unsetCount = 0,
matchingTokenStreamCount = 0, nonMatchingTokenStreamCount = 0; matchingTokenStreamCount = 0, nonMatchingTokenStreamCount = 0;
CSSPROPS_FOR_SHORTHAND_SUBPROPERTIES(p, aProperty, CSSPROPS_FOR_SHORTHAND_SUBPROPERTIES(p, aProperty,
nsCSSProps::eEnabledForAllContent) { CSSEnabledState::eForAllContent) {
if (*p == eCSSProperty__x_system_font) { if (*p == eCSSProperty__x_system_font) {
// The system-font subproperty doesn't count. // The system-font subproperty doesn't count.
continue; continue;
@ -1432,8 +1432,8 @@ Declaration::GetValue(nsCSSProperty aProperty, nsAString& aValue,
bool bool
Declaration::GetValueIsImportant(const nsAString& aProperty) const Declaration::GetValueIsImportant(const nsAString& aProperty) const
{ {
nsCSSProperty propID = nsCSSProperty propID = nsCSSProps::
nsCSSProps::LookupProperty(aProperty, nsCSSProps::eIgnoreEnabledState); LookupProperty(aProperty, CSSEnabledState::eIgnoreEnabledState);
if (propID == eCSSProperty_UNKNOWN) { if (propID == eCSSProperty_UNKNOWN) {
return false; return false;
} }
@ -1458,7 +1458,7 @@ Declaration::GetValueIsImportant(nsCSSProperty aProperty) const
} }
CSSPROPS_FOR_SHORTHAND_SUBPROPERTIES(p, aProperty, CSSPROPS_FOR_SHORTHAND_SUBPROPERTIES(p, aProperty,
nsCSSProps::eEnabledForAllContent) { CSSEnabledState::eForAllContent) {
if (*p == eCSSProperty__x_system_font) { if (*p == eCSSProperty__x_system_font) {
// The system_font subproperty doesn't count. // The system_font subproperty doesn't count.
continue; continue;
@ -1572,7 +1572,7 @@ Declaration::ToString(nsAString& aString) const
continue; continue;
} }
if (!nsCSSProps::IsEnabled(property, nsCSSProps::eEnabledForAllContent)) { if (!nsCSSProps::IsEnabled(property, CSSEnabledState::eForAllContent)) {
continue; continue;
} }
bool doneProperty = false; bool doneProperty = false;

View File

@ -2821,7 +2821,7 @@ BuildStyleRule(nsCSSProperty aProperty,
static bool static bool
ComputeValuesFromStyleRule(nsCSSProperty aProperty, ComputeValuesFromStyleRule(nsCSSProperty aProperty,
nsCSSProps::EnabledState aEnabledState, CSSEnabledState aEnabledState,
dom::Element* aTargetElement, dom::Element* aTargetElement,
nsStyleContext* aStyleContext, nsStyleContext* aStyleContext,
css::StyleRule* aStyleRule, css::StyleRule* aStyleRule,
@ -2942,7 +2942,7 @@ StyleAnimationValue::ComputeValue(nsCSSProperty aProperty,
AutoTArray<PropertyStyleAnimationValuePair,1> values; AutoTArray<PropertyStyleAnimationValuePair,1> values;
bool ok = ComputeValuesFromStyleRule(aProperty, bool ok = ComputeValuesFromStyleRule(aProperty,
nsCSSProps::eIgnoreEnabledState, CSSEnabledState::eIgnoreEnabledState,
aTargetElement, aStyleContext, styleRule, aTargetElement, aStyleContext, styleRule,
values, aIsContextSensitive); values, aIsContextSensitive);
if (!ok) { if (!ok) {
@ -2960,7 +2960,7 @@ template <class T>
bool bool
ComputeValuesFromSpecifiedValue( ComputeValuesFromSpecifiedValue(
nsCSSProperty aProperty, nsCSSProperty aProperty,
nsCSSProps::EnabledState aEnabledState, CSSEnabledState aEnabledState,
dom::Element* aTargetElement, dom::Element* aTargetElement,
nsStyleContext* aStyleContext, nsStyleContext* aStyleContext,
T& aSpecifiedValue, T& aSpecifiedValue,
@ -2988,7 +2988,7 @@ ComputeValuesFromSpecifiedValue(
/* static */ bool /* static */ bool
StyleAnimationValue::ComputeValues( StyleAnimationValue::ComputeValues(
nsCSSProperty aProperty, nsCSSProperty aProperty,
nsCSSProps::EnabledState aEnabledState, CSSEnabledState aEnabledState,
dom::Element* aTargetElement, dom::Element* aTargetElement,
nsStyleContext* aStyleContext, nsStyleContext* aStyleContext,
const nsAString& aSpecifiedValue, const nsAString& aSpecifiedValue,
@ -3004,7 +3004,7 @@ StyleAnimationValue::ComputeValues(
/* static */ bool /* static */ bool
StyleAnimationValue::ComputeValues( StyleAnimationValue::ComputeValues(
nsCSSProperty aProperty, nsCSSProperty aProperty,
nsCSSProps::EnabledState aEnabledState, CSSEnabledState aEnabledState,
dom::Element* aTargetElement, dom::Element* aTargetElement,
nsStyleContext* aStyleContext, nsStyleContext* aStyleContext,
const nsCSSValue& aSpecifiedValue, const nsCSSValue& aSpecifiedValue,

View File

@ -176,7 +176,7 @@ public:
* in it. * in it.
*/ */
static bool ComputeValues(nsCSSProperty aProperty, static bool ComputeValues(nsCSSProperty aProperty,
nsCSSProps::EnabledState aEnabledState, mozilla::CSSEnabledState aEnabledState,
mozilla::dom::Element* aTargetElement, mozilla::dom::Element* aTargetElement,
nsStyleContext* aStyleContext, nsStyleContext* aStyleContext,
const nsAString& aSpecifiedValue, const nsAString& aSpecifiedValue,
@ -188,7 +188,7 @@ public:
* value. Only longhand properties are supported. * value. Only longhand properties are supported.
*/ */
static bool ComputeValues(nsCSSProperty aProperty, static bool ComputeValues(nsCSSProperty aProperty,
nsCSSProps::EnabledState aEnabledState, mozilla::CSSEnabledState aEnabledState,
mozilla::dom::Element* aTargetElement, mozilla::dom::Element* aTargetElement,
nsStyleContext* aStyleContext, nsStyleContext* aStyleContext,
const nsCSSValue& aSpecifiedValue, const nsCSSValue& aSpecifiedValue,

View File

@ -81,6 +81,7 @@ EXPORTS += [
EXPORTS.mozilla += [ EXPORTS.mozilla += [
'AnimationCollection.h', 'AnimationCollection.h',
'CSSEnabledState.h',
'CSSStyleSheet.h', 'CSSStyleSheet.h',
'CSSVariableDeclarations.h', 'CSSVariableDeclarations.h',
'CSSVariableResolver.h', 'CSSVariableResolver.h',

View File

@ -623,8 +623,8 @@ void
nsCSSExpandedDataBlock::ClearProperty(nsCSSProperty aPropID) nsCSSExpandedDataBlock::ClearProperty(nsCSSProperty aPropID)
{ {
if (nsCSSProps::IsShorthand(aPropID)) { if (nsCSSProps::IsShorthand(aPropID)) {
CSSPROPS_FOR_SHORTHAND_SUBPROPERTIES(p, aPropID, CSSPROPS_FOR_SHORTHAND_SUBPROPERTIES(
nsCSSProps::eIgnoreEnabledState) { p, aPropID, CSSEnabledState::eIgnoreEnabledState) {
ClearLonghandProperty(*p); ClearLonghandProperty(*p);
} }
} else { } else {
@ -645,7 +645,7 @@ nsCSSExpandedDataBlock::ClearLonghandProperty(nsCSSProperty aPropID)
bool bool
nsCSSExpandedDataBlock::TransferFromBlock(nsCSSExpandedDataBlock& aFromBlock, nsCSSExpandedDataBlock::TransferFromBlock(nsCSSExpandedDataBlock& aFromBlock,
nsCSSProperty aPropID, nsCSSProperty aPropID,
nsCSSProps::EnabledState aEnabledState, CSSEnabledState aEnabledState,
bool aIsImportant, bool aIsImportant,
bool aOverrideImportant, bool aOverrideImportant,
bool aMustCallValueAppended, bool aMustCallValueAppended,
@ -659,11 +659,11 @@ nsCSSExpandedDataBlock::TransferFromBlock(nsCSSExpandedDataBlock& aFromBlock,
aSheetDocument); aSheetDocument);
} }
// We can pass eIgnoreEnabledState (here, and in ClearProperty above) rather // We can pass CSSEnabledState::eIgnore (here, and in ClearProperty
// than a value corresponding to whether we're parsing a UA style sheet or // above) rather than a value corresponding to whether we're parsing
// certified app because we assert in nsCSSProps::AddRefTable that shorthand // a UA style sheet or certified app because we assert in nsCSSProps::
// properties available in these contexts also have all of their // AddRefTable that shorthand properties available in these contexts
// subproperties available in these contexts. // also have all of their subproperties available in these contexts.
bool changed = false; bool changed = false;
CSSPROPS_FOR_SHORTHAND_SUBPROPERTIES(p, aPropID, aEnabledState) { CSSPROPS_FOR_SHORTHAND_SUBPROPERTIES(p, aPropID, aEnabledState) {
changed |= DoTransferFromBlock(aFromBlock, *p, changed |= DoTransferFromBlock(aFromBlock, *p,

View File

@ -264,7 +264,7 @@ public:
*/ */
bool TransferFromBlock(nsCSSExpandedDataBlock& aFromBlock, bool TransferFromBlock(nsCSSExpandedDataBlock& aFromBlock,
nsCSSProperty aPropID, nsCSSProperty aPropID,
nsCSSProps::EnabledState aEnabledState, mozilla::CSSEnabledState aEnabledState,
bool aIsImportant, bool aIsImportant,
bool aOverrideImportant, bool aOverrideImportant,
bool aMustCallValueAppended, bool aMustCallValueAppended,

View File

@ -356,16 +356,16 @@ public:
mParsingMode == css::eUserSheetFeatures; mParsingMode == css::eUserSheetFeatures;
} }
nsCSSProps::EnabledState PropertyEnabledState() const { CSSEnabledState PropertyEnabledState() const {
static_assert(nsCSSProps::eEnabledForAllContent == 0, static_assert(int(CSSEnabledState::eForAllContent) == 0,
"nsCSSProps::eEnabledForAllContent should be zero for " "CSSEnabledState::eForAllContent should be zero for "
"this bitfield to work"); "this bitfield to work");
nsCSSProps::EnabledState enabledState = nsCSSProps::eEnabledForAllContent; CSSEnabledState enabledState = CSSEnabledState::eForAllContent;
if (AgentRulesEnabled()) { if (AgentRulesEnabled()) {
enabledState |= nsCSSProps::eEnabledInUASheets; enabledState |= CSSEnabledState::eInUASheets;
} }
if (mIsChrome) { if (mIsChrome) {
enabledState |= nsCSSProps::eEnabledInChrome; enabledState |= CSSEnabledState::eInChrome;
} }
return enabledState; return enabledState;
} }
@ -17017,7 +17017,7 @@ CSSParserImpl::ParseAll()
// instead of computing the correct EnabledState value we just expand out // instead of computing the correct EnabledState value we just expand out
// to all content-visible properties. // to all content-visible properties.
CSSPROPS_FOR_SHORTHAND_SUBPROPERTIES(p, eCSSProperty_all, CSSPROPS_FOR_SHORTHAND_SUBPROPERTIES(p, eCSSProperty_all,
nsCSSProps::eEnabledForAllContent) { CSSEnabledState::eForAllContent) {
AppendValue(*p, value); AppendValue(*p, value);
} }
return true; return true;

View File

@ -538,13 +538,14 @@ nsCSSProps::LookupProperty(const nsACString& aProperty,
} }
MOZ_ASSERT(eCSSAliasCount != 0, MOZ_ASSERT(eCSSAliasCount != 0,
"'res' must be an alias at this point so we better have some!"); "'res' must be an alias at this point so we better have some!");
// We intentionally don't support eEnabledInUASheets or eEnabledInChrome // We intentionally don't support CSSEnabledState::eInUASheets or
// for aliases yet because it's unlikely there will be a need for it. // CSSEnabledState::eInChrome for aliases yet because it's unlikely
if (IsEnabled(res) || aEnabled == eIgnoreEnabledState) { // there will be a need for it.
if (IsEnabled(res) || aEnabled == CSSEnabledState::eIgnoreEnabledState) {
res = gAliases[res - eCSSProperty_COUNT]; res = gAliases[res - eCSSProperty_COUNT];
MOZ_ASSERT(0 <= res && res < eCSSProperty_COUNT, MOZ_ASSERT(0 <= res && res < eCSSProperty_COUNT,
"aliases must not point to other aliases"); "aliases must not point to other aliases");
if (IsEnabled(res) || aEnabled == eIgnoreEnabledState) { if (IsEnabled(res) || aEnabled == CSSEnabledState::eIgnoreEnabledState) {
return res; return res;
} }
} }
@ -572,13 +573,14 @@ nsCSSProps::LookupProperty(const nsAString& aProperty, EnabledState aEnabled)
} }
MOZ_ASSERT(eCSSAliasCount != 0, MOZ_ASSERT(eCSSAliasCount != 0,
"'res' must be an alias at this point so we better have some!"); "'res' must be an alias at this point so we better have some!");
// We intentionally don't support eEnabledInUASheets or eEnabledInChrome // We intentionally don't support CSSEnabledState::eInUASheets or
// for aliases yet because it's unlikely there will be a need for it. // CSSEnabledState::eInChrome for aliases yet because it's unlikely
if (IsEnabled(res) || aEnabled == eIgnoreEnabledState) { // there will be a need for it.
if (IsEnabled(res) || aEnabled == CSSEnabledState::eIgnoreEnabledState) {
res = gAliases[res - eCSSProperty_COUNT]; res = gAliases[res - eCSSProperty_COUNT];
MOZ_ASSERT(0 <= res && res < eCSSProperty_COUNT, MOZ_ASSERT(0 <= res && res < eCSSProperty_COUNT,
"aliases must not point to other aliases"); "aliases must not point to other aliases");
if (IsEnabled(res) || aEnabled == eIgnoreEnabledState) { if (IsEnabled(res) || aEnabled == CSSEnabledState::eIgnoreEnabledState) {
return res; return res;
} }
} }

View File

@ -15,6 +15,7 @@
#include "nsCSSProperty.h" #include "nsCSSProperty.h"
#include "nsStyleStructFwd.h" #include "nsStyleStructFwd.h"
#include "nsCSSKeywords.h" #include "nsCSSKeywords.h"
#include "mozilla/CSSEnabledState.h"
#include "mozilla/UseCounter.h" #include "mozilla/UseCounter.h"
// Length of the "--" prefix on custom names (such as custom property names, // Length of the "--" prefix on custom names (such as custom property names,
@ -330,6 +331,8 @@ enum nsStyleAnimType {
class nsCSSProps { class nsCSSProps {
public: public:
typedef mozilla::CSSEnabledState EnabledState;
struct KTableEntry { struct KTableEntry {
nsCSSKeyword mKeyword; nsCSSKeyword mKeyword;
int16_t mValue; int16_t mValue;
@ -338,21 +341,6 @@ public:
static void AddRefTable(void); static void AddRefTable(void);
static void ReleaseTable(void); static void ReleaseTable(void);
enum EnabledState {
// The default EnabledState: only enable what's enabled for all content,
// given the current values of preferences.
eEnabledForAllContent = 0,
// Enable a property in UA sheets.
eEnabledInUASheets = 0x01,
// Enable a property in chrome code.
eEnabledInChrome = 0x02,
// Special value to unconditionally enable a property. This implies all the
// bits above, but is strictly more than just their OR-ed union.
// This just skips any test so a property will be enabled even if it would
// have been disabled with all the bits above set.
eIgnoreEnabledState = 0xff
};
// Looks up the property with name aProperty and returns its corresponding // Looks up the property with name aProperty and returns its corresponding
// nsCSSProperty value. If aProperty is the name of a custom property, // nsCSSProperty value. If aProperty is the name of a custom property,
// then eCSSPropertyExtra_variable will be returned. // then eCSSPropertyExtra_variable will be returned.
@ -624,15 +612,15 @@ public:
if (IsEnabled(aProperty)) { if (IsEnabled(aProperty)) {
return true; return true;
} }
if (aEnabled == eIgnoreEnabledState) { if (aEnabled == EnabledState::eIgnoreEnabledState) {
return true; return true;
} }
if ((aEnabled & eEnabledInUASheets) && if ((aEnabled & EnabledState::eInUASheets) &&
PropHasFlags(aProperty, CSS_PROPERTY_ENABLED_IN_UA_SHEETS)) PropHasFlags(aProperty, CSS_PROPERTY_ENABLED_IN_UA_SHEETS))
{ {
return true; return true;
} }
if ((aEnabled & eEnabledInChrome) && if ((aEnabled & EnabledState::eInChrome) &&
PropHasFlags(aProperty, CSS_PROPERTY_ENABLED_IN_CHROME)) PropHasFlags(aProperty, CSS_PROPERTY_ENABLED_IN_CHROME))
{ {
return true; return true;
@ -644,13 +632,13 @@ public:
// Storing the enabledstate_ value in an nsCSSProperty variable is a small hack // Storing the enabledstate_ value in an nsCSSProperty variable is a small hack
// to avoid needing a separate variable declaration for its real type // to avoid needing a separate variable declaration for its real type
// (nsCSSProps::EnabledState), which would then require using a block and // (CSSEnabledState), which would then require using a block and
// therefore a pair of macros by consumers for the start and end of the loop. // therefore a pair of macros by consumers for the start and end of the loop.
#define CSSPROPS_FOR_SHORTHAND_SUBPROPERTIES(it_, prop_, enabledstate_) \ #define CSSPROPS_FOR_SHORTHAND_SUBPROPERTIES(it_, prop_, enabledstate_) \
for (const nsCSSProperty *it_ = nsCSSProps::SubpropertyEntryFor(prop_), \ for (const nsCSSProperty *it_ = nsCSSProps::SubpropertyEntryFor(prop_), \
es_ = (nsCSSProperty) (enabledstate_); \ es_ = (nsCSSProperty) (enabledstate_); \
*it_ != eCSSProperty_UNKNOWN; ++it_) \ *it_ != eCSSProperty_UNKNOWN; ++it_) \
if (nsCSSProps::IsEnabled(*it_, (nsCSSProps::EnabledState) es_)) if (nsCSSProps::IsEnabled(*it_, (mozilla::CSSEnabledState) es_))
// Keyword/Enum value tables // Keyword/Enum value tables
static const KTableEntry kAnimationDirectionKTable[]; static const KTableEntry kAnimationDirectionKTable[];
@ -840,28 +828,4 @@ public:
static const KTableEntry kWritingModeKTable[]; static const KTableEntry kWritingModeKTable[];
}; };
inline nsCSSProps::EnabledState operator|(nsCSSProps::EnabledState a,
nsCSSProps::EnabledState b)
{
return nsCSSProps::EnabledState(int(a) | int(b));
}
inline nsCSSProps::EnabledState operator&(nsCSSProps::EnabledState a,
nsCSSProps::EnabledState b)
{
return nsCSSProps::EnabledState(int(a) & int(b));
}
inline nsCSSProps::EnabledState& operator|=(nsCSSProps::EnabledState& a,
nsCSSProps::EnabledState b)
{
return a = a | b;
}
inline nsCSSProps::EnabledState& operator&=(nsCSSProps::EnabledState& a,
nsCSSProps::EnabledState b)
{
return a = a & b;
}
#endif /* nsCSSProps_h___ */ #endif /* nsCSSProps_h___ */

View File

@ -98,8 +98,7 @@ struct nsComputedStyleMap
bool IsEnabled() const bool IsEnabled() const
{ {
return nsCSSProps::IsEnabled(mProperty, return nsCSSProps::IsEnabled(mProperty, CSSEnabledState::eForAllContent);
nsCSSProps::eEnabledForAllContent);
} }
}; };
@ -765,8 +764,8 @@ nsComputedDOMStyle::ClearCurrentStyleSources()
already_AddRefed<CSSValue> already_AddRefed<CSSValue>
nsComputedDOMStyle::GetPropertyCSSValue(const nsAString& aPropertyName, ErrorResult& aRv) nsComputedDOMStyle::GetPropertyCSSValue(const nsAString& aPropertyName, ErrorResult& aRv)
{ {
nsCSSProperty prop = nsCSSProps::LookupProperty(aPropertyName, nsCSSProperty prop =
nsCSSProps::eEnabledForAllContent); nsCSSProps::LookupProperty(aPropertyName, CSSEnabledState::eForAllContent);
bool needsLayoutFlush; bool needsLayoutFlush;
nsComputedStyleMap::Entry::ComputeMethod getter; nsComputedStyleMap::Entry::ComputeMethod getter;

View File

@ -196,8 +196,7 @@ nsDOMCSSDeclaration::GetPropertyValue(const nsAString& aPropertyName,
nsAString& aReturn) nsAString& aReturn)
{ {
const nsCSSProperty propID = const nsCSSProperty propID =
nsCSSProps::LookupProperty(aPropertyName, nsCSSProps::LookupProperty(aPropertyName, CSSEnabledState::eForAllContent);
nsCSSProps::eEnabledForAllContent);
if (propID == eCSSProperty_UNKNOWN) { if (propID == eCSSProperty_UNKNOWN) {
aReturn.Truncate(); aReturn.Truncate();
return NS_OK; return NS_OK;
@ -216,8 +215,7 @@ nsDOMCSSDeclaration::GetAuthoredPropertyValue(const nsAString& aPropertyName,
nsAString& aReturn) nsAString& aReturn)
{ {
const nsCSSProperty propID = const nsCSSProperty propID =
nsCSSProps::LookupProperty(aPropertyName, nsCSSProps::LookupProperty(aPropertyName, CSSEnabledState::eForAllContent);
nsCSSProps::eEnabledForAllContent);
if (propID == eCSSProperty_UNKNOWN) { if (propID == eCSSProperty_UNKNOWN) {
aReturn.Truncate(); aReturn.Truncate();
return NS_OK; return NS_OK;
@ -258,8 +256,7 @@ nsDOMCSSDeclaration::SetProperty(const nsAString& aPropertyName,
{ {
// In the common (and fast) cases we can use the property id // In the common (and fast) cases we can use the property id
nsCSSProperty propID = nsCSSProperty propID =
nsCSSProps::LookupProperty(aPropertyName, nsCSSProps::LookupProperty(aPropertyName, CSSEnabledState::eForAllContent);
nsCSSProps::eEnabledForAllContent);
if (propID == eCSSProperty_UNKNOWN) { if (propID == eCSSProperty_UNKNOWN) {
return NS_OK; return NS_OK;
} }
@ -295,8 +292,7 @@ nsDOMCSSDeclaration::RemoveProperty(const nsAString& aPropertyName,
nsAString& aReturn) nsAString& aReturn)
{ {
const nsCSSProperty propID = const nsCSSProperty propID =
nsCSSProps::LookupProperty(aPropertyName, nsCSSProps::LookupProperty(aPropertyName, CSSEnabledState::eForAllContent);
nsCSSProps::eEnabledForAllContent);
if (propID == eCSSProperty_UNKNOWN) { if (propID == eCSSProperty_UNKNOWN) {
aReturn.Truncate(); aReturn.Truncate();
return NS_OK; return NS_OK;

View File

@ -5393,7 +5393,7 @@ nsRuleNode::ComputeDisplayData(void* aStartStruct,
propertyStr(property.list->mValue.GetStringBufferValue()); propertyStr(property.list->mValue.GetStringBufferValue());
nsCSSProperty prop = nsCSSProperty prop =
nsCSSProps::LookupProperty(propertyStr, nsCSSProps::LookupProperty(propertyStr,
nsCSSProps::eEnabledForAllContent); CSSEnabledState::eForAllContent);
if (prop == eCSSProperty_UNKNOWN || if (prop == eCSSProperty_UNKNOWN ||
prop == eCSSPropertyExtra_variable) { prop == eCSSPropertyExtra_variable) {
transition->SetUnknownProperty(prop, propertyStr); transition->SetUnknownProperty(prop, propertyStr);
@ -6197,8 +6197,7 @@ nsRuleNode::ComputeDisplayData(void* aStartStruct,
} }
nsCSSProperty prop = nsCSSProperty prop =
nsCSSProps::LookupProperty(buffer, nsCSSProps::LookupProperty(buffer, CSSEnabledState::eForAllContent);
nsCSSProps::eEnabledForAllContent);
if (prop != eCSSProperty_UNKNOWN && if (prop != eCSSProperty_UNKNOWN &&
prop != eCSSPropertyExtra_variable) { prop != eCSSPropertyExtra_variable) {
// If the property given is a shorthand, it indicates the expectation // If the property given is a shorthand, it indicates the expectation

View File

@ -2740,7 +2740,7 @@ mozilla::StyleTransition::SetUnknownProperty(nsCSSProperty aProperty,
const nsAString& aPropertyString) const nsAString& aPropertyString)
{ {
MOZ_ASSERT(nsCSSProps::LookupProperty(aPropertyString, MOZ_ASSERT(nsCSSProps::LookupProperty(aPropertyString,
nsCSSProps::eEnabledForAllContent) == CSSEnabledState::eForAllContent) ==
aProperty, aProperty,
"property and property string should match"); "property and property string should match");
MOZ_ASSERT(aProperty == eCSSProperty_UNKNOWN || MOZ_ASSERT(aProperty == eCSSProperty_UNKNOWN ||

View File

@ -414,7 +414,7 @@ nsTransitionManager::UpdateTransitions(
} }
} else if (nsCSSProps::IsShorthand(property)) { } else if (nsCSSProps::IsShorthand(property)) {
CSSPROPS_FOR_SHORTHAND_SUBPROPERTIES(subprop, property, CSSPROPS_FOR_SHORTHAND_SUBPROPERTIES(subprop, property,
nsCSSProps::eEnabledForAllContent) CSSEnabledState::eForAllContent)
{ {
ConsiderStartingTransition(*subprop, t, aElement, aElementTransitions, ConsiderStartingTransition(*subprop, t, aElement, aElementTransitions,
aOldStyleContext, aNewStyleContext, aOldStyleContext, aNewStyleContext,
@ -459,7 +459,7 @@ nsTransitionManager::UpdateTransitions(
} }
} else if (nsCSSProps::IsShorthand(property)) { } else if (nsCSSProps::IsShorthand(property)) {
CSSPROPS_FOR_SHORTHAND_SUBPROPERTIES( CSSPROPS_FOR_SHORTHAND_SUBPROPERTIES(
subprop, property, nsCSSProps::eEnabledForAllContent) { subprop, property, CSSEnabledState::eForAllContent) {
allTransitionProperties.AddProperty(*subprop); allTransitionProperties.AddProperty(*subprop);
} }
} else { } else {
@ -530,7 +530,7 @@ nsTransitionManager::ConsiderStartingTransition(
// Ignore disabled properties. We can arrive here if the transition-property // Ignore disabled properties. We can arrive here if the transition-property
// is 'all' and the disabled property has a default value which derives value // is 'all' and the disabled property has a default value which derives value
// from another property, e.g. color. // from another property, e.g. color.
if (!nsCSSProps::IsEnabled(aProperty, nsCSSProps::eEnabledForAllContent)) { if (!nsCSSProps::IsEnabled(aProperty, CSSEnabledState::eForAllContent)) {
return; return;
} }

View File

@ -9,6 +9,8 @@
#include "nsString.h" #include "nsString.h"
#include "nsXPCOM.h" #include "nsXPCOM.h"
using namespace mozilla;
static const char* const kJunkNames[] = { static const char* const kJunkNames[] = {
nullptr, nullptr,
"", "",
@ -41,7 +43,7 @@ TestProps()
index = nsCSSProperty(int32_t(index) + 1); index = nsCSSProperty(int32_t(index) + 1);
id = nsCSSProps::LookupProperty(nsCString(tagName), id = nsCSSProps::LookupProperty(nsCString(tagName),
nsCSSProps::eIgnoreEnabledState); CSSEnabledState::eIgnoreEnabledState);
if (id == eCSSProperty_UNKNOWN) { if (id == eCSSProperty_UNKNOWN) {
printf("bug: can't find '%s'\n", tagName); printf("bug: can't find '%s'\n", tagName);
success = false; success = false;
@ -56,7 +58,7 @@ TestProps()
tagName[0] = tagName[0] - 32; tagName[0] = tagName[0] - 32;
} }
id = nsCSSProps::LookupProperty(NS_ConvertASCIItoUTF16(tagName), id = nsCSSProps::LookupProperty(NS_ConvertASCIItoUTF16(tagName),
nsCSSProps::eIgnoreEnabledState); CSSEnabledState::eIgnoreEnabledState);
if (id < 0) { if (id < 0) {
printf("bug: can't find '%s'\n", tagName); printf("bug: can't find '%s'\n", tagName);
success = false; success = false;
@ -72,7 +74,7 @@ TestProps()
for (int i = 0; i < (int) (sizeof(kJunkNames) / sizeof(const char*)); i++) { for (int i = 0; i < (int) (sizeof(kJunkNames) / sizeof(const char*)); i++) {
const char* const tag = kJunkNames[i]; const char* const tag = kJunkNames[i];
id = nsCSSProps::LookupProperty(nsAutoCString(tag), id = nsCSSProps::LookupProperty(nsAutoCString(tag),
nsCSSProps::eIgnoreEnabledState); CSSEnabledState::eIgnoreEnabledState);
if (id >= 0) { if (id >= 0) {
printf("bug: found '%s'\n", tag ? tag : "(null)"); printf("bug: found '%s'\n", tag ? tag : "(null)");
success = false; success = false;