Bug 1121768 - Part 2: Give CSSPROPS_FOR_SHORTHAND_SUBPROPERTIES an nsCSSProps::EnabledState argument. r=dbaron
authorCameron McCormack <cam@mcc.id.au>
Sat, 17 Jan 2015 15:55:07 +1100
changeset 224390 9a6692c19d67d50cded6b118d057d5362afee622
parent 224389 be159d9f6d92779bb0d4a77a26c6f79536c16de9
child 224391 a1c3ce647646572441f5a17ad9a57ce1274920c4
push id54202
push usercmccormack@mozilla.com
push dateSat, 17 Jan 2015 04:56:55 +0000
treeherdermozilla-inbound@cf403ce5f085 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersdbaron
bugs1121768
milestone38.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 1121768 - Part 2: Give CSSPROPS_FOR_SHORTHAND_SUBPROPERTIES an nsCSSProps::EnabledState argument. r=dbaron
layout/inspector/inDOMUtils.cpp
layout/style/Declaration.cpp
layout/style/nsCSSDataBlock.cpp
layout/style/nsCSSParser.cpp
layout/style/nsCSSProps.h
layout/style/nsTransitionManager.cpp
--- a/layout/inspector/inDOMUtils.cpp
+++ b/layout/inspector/inDOMUtils.cpp
@@ -743,25 +743,27 @@ inDOMUtils::GetCSSValuesForProperty(cons
     // Get colors first.
     GetColorsForProperty(propertyParserVariant, array);
     if (propertyParserVariant & VARIANT_KEYWORD) {
       GetKeywordsForProperty(propertyID, array);
     }
     GetOtherValuesForProperty(propertyParserVariant, array);
   } else {
     // Property is shorthand.
-    CSSPROPS_FOR_SHORTHAND_SUBPROPERTIES(subproperty, propertyID) {
+    CSSPROPS_FOR_SHORTHAND_SUBPROPERTIES(subproperty, propertyID,
+                                         nsCSSProps::eEnabledForAllContent) {
       // Get colors (once) first.
       uint32_t propertyParserVariant = nsCSSProps::ParserVariant(*subproperty);
       if (propertyParserVariant & VARIANT_COLOR) {
         GetColorsForProperty(propertyParserVariant, array);
         break;
       }
     }
-    CSSPROPS_FOR_SHORTHAND_SUBPROPERTIES(subproperty, propertyID) {
+    CSSPROPS_FOR_SHORTHAND_SUBPROPERTIES(subproperty, propertyID,
+                                         nsCSSProps::eEnabledForAllContent) {
       uint32_t propertyParserVariant = nsCSSProps::ParserVariant(*subproperty);
       if (propertyParserVariant & VARIANT_KEYWORD) {
         GetKeywordsForProperty(*subproperty, array);
       }
       GetOtherValuesForProperty(propertyParserVariant, array);
     }
   }
   // All CSS properties take initial, inherit and unset.
--- a/layout/style/Declaration.cpp
+++ b/layout/style/Declaration.cpp
@@ -64,17 +64,18 @@ Declaration::RemoveProperty(nsCSSPropert
 {
   MOZ_ASSERT(0 <= aProperty && aProperty < eCSSProperty_COUNT);
 
   nsCSSExpandedDataBlock data;
   ExpandTo(&data);
   NS_ABORT_IF_FALSE(!mData && !mImportantData, "Expand didn't null things out");
 
   if (nsCSSProps::IsShorthand(aProperty)) {
-    CSSPROPS_FOR_SHORTHAND_SUBPROPERTIES(p, aProperty) {
+    CSSPROPS_FOR_SHORTHAND_SUBPROPERTIES(p, aProperty,
+                                         nsCSSProps::eEnabledForAllContent) {
       data.ClearLonghandProperty(*p);
       mOrder.RemoveElement(static_cast<uint32_t>(*p));
     }
   } else {
     data.ClearLonghandProperty(aProperty);
     mOrder.RemoveElement(static_cast<uint32_t>(aProperty));
   }
 
@@ -163,17 +164,18 @@ Declaration::GetValue(nsCSSProperty aPro
   // Additionally, if a shorthand property was set using a value with a
   // variable reference and none of its component longhand properties were
   // then overridden on the declaration, we return the token stream
   // assigned to the shorthand.
   const nsCSSValue* tokenStream = nullptr;
   uint32_t totalCount = 0, importantCount = 0,
            initialCount = 0, inheritCount = 0, unsetCount = 0,
            matchingTokenStreamCount = 0, nonMatchingTokenStreamCount = 0;
-  CSSPROPS_FOR_SHORTHAND_SUBPROPERTIES(p, aProperty) {
+  CSSPROPS_FOR_SHORTHAND_SUBPROPERTIES(p, aProperty,
+                                       nsCSSProps::eEnabledForAllContent) {
     if (*p == eCSSProperty__x_system_font) {
       // The system-font subproperty doesn't count.
       continue;
     }
     ++totalCount;
     const nsCSSValue *val = mData->ValueFor(*p);
     NS_ABORT_IF_FALSE(!val || !mImportantData || !mImportantData->ValueFor(*p),
                       "can't be in both blocks");
@@ -1117,17 +1119,18 @@ Declaration::GetValueIsImportant(nsCSSPr
     return false;
 
   // Calling ValueFor is inefficient, but we can assume '!important' is rare.
 
   if (!nsCSSProps::IsShorthand(aProperty)) {
     return mImportantData->ValueFor(aProperty) != nullptr;
   }
 
-  CSSPROPS_FOR_SHORTHAND_SUBPROPERTIES(p, aProperty) {
+  CSSPROPS_FOR_SHORTHAND_SUBPROPERTIES(p, aProperty,
+                                       nsCSSProps::eEnabledForAllContent) {
     if (*p == eCSSProperty__x_system_font) {
       // The system_font subproperty doesn't count.
       continue;
     }
     if (!mImportantData->ValueFor(*p)) {
       return false;
     }
   }
--- a/layout/style/nsCSSDataBlock.cpp
+++ b/layout/style/nsCSSDataBlock.cpp
@@ -582,17 +582,18 @@ nsCSSExpandedDataBlock::Clear()
 
     AssertInitialState();
 }
 
 void
 nsCSSExpandedDataBlock::ClearProperty(nsCSSProperty aPropID)
 {
   if (nsCSSProps::IsShorthand(aPropID)) {
-    CSSPROPS_FOR_SHORTHAND_SUBPROPERTIES(p, aPropID) {
+    CSSPROPS_FOR_SHORTHAND_SUBPROPERTIES(p, aPropID,
+                                         nsCSSProps::eEnabledForAllContent) {
       ClearLonghandProperty(*p);
     }
   } else {
     ClearLonghandProperty(aPropID);
   }
 }
 
 void
@@ -614,18 +615,24 @@ nsCSSExpandedDataBlock::TransferFromBloc
                                           css::Declaration* aDeclaration)
 {
     if (!nsCSSProps::IsShorthand(aPropID)) {
         return DoTransferFromBlock(aFromBlock, aPropID,
                                    aIsImportant, aOverrideImportant,
                                    aMustCallValueAppended, aDeclaration);
     }
 
+    // We can pass eIgnoreEnabledState (here, and in ClearProperty above) rather
+    // than a value corresponding to whether we're parsing a UA style sheet or
+    // certified app because we assert in nsCSSProps::AddRefTable that shorthand
+    // properties available in these contexts also have all of their
+    // subproperties available in these contexts.
     bool changed = false;
-    CSSPROPS_FOR_SHORTHAND_SUBPROPERTIES(p, aPropID) {
+    CSSPROPS_FOR_SHORTHAND_SUBPROPERTIES(p, aPropID,
+                                         nsCSSProps::eEnabledForAllContent) {
         changed |= DoTransferFromBlock(aFromBlock, *p,
                                        aIsImportant, aOverrideImportant,
                                        aMustCallValueAppended, aDeclaration);
     }
     return changed;
 }
 
 bool
--- a/layout/style/nsCSSParser.cpp
+++ b/layout/style/nsCSSParser.cpp
@@ -9639,17 +9639,18 @@ CSSParserImpl::ParseProperty(nsCSSProper
           propertyValue.Truncate(propertyValue.Length() - 1);
         }
       }
 
       if (!mInSupportsCondition) {
         if (nsCSSProps::IsShorthand(aPropID)) {
           // If this is a shorthand property, we store the token stream on each
           // of its corresponding longhand properties.
-          CSSPROPS_FOR_SHORTHAND_SUBPROPERTIES(p, aPropID) {
+          CSSPROPS_FOR_SHORTHAND_SUBPROPERTIES(p, aPropID,
+                                               nsCSSProps::eEnabledForAllContent) {
             nsCSSValueTokenStream* tokenStream = new nsCSSValueTokenStream;
             tokenStream->mPropertyID = *p;
             tokenStream->mShorthandPropertyID = aPropID;
             tokenStream->mTokenStream = propertyValue;
             tokenStream->mBaseURI = mBaseURI;
             tokenStream->mSheetURI = mSheetURI;
             tokenStream->mSheetPrincipal = mSheetPrincipal;
             tokenStream->mSheet = mSheet;
@@ -14738,17 +14739,21 @@ CSSParserImpl::AppendImpliedEOFCharacter
 bool
 CSSParserImpl::ParseAll()
 {
   nsCSSValue value;
   if (!ParseVariant(value, VARIANT_INHERIT, nullptr)) {
     return false;
   }
 
-  CSSPROPS_FOR_SHORTHAND_SUBPROPERTIES(p, eCSSProperty_all) {
+  // It's unlikely we'll want to use 'all' from within a UA style sheet, so
+  // instead of computing the correct EnabledState value we just expand out
+  // to all content-visible properties.
+  CSSPROPS_FOR_SHORTHAND_SUBPROPERTIES(p, eCSSProperty_all,
+                                       nsCSSProps::eEnabledForAllContent) {
     AppendValue(*p, value);
   }
   return true;
 }
 
 bool
 CSSParserImpl::ParseVariableDeclaration(CSSVariableDeclarations::Type* aType,
                                         nsString& aValue)
--- a/layout/style/nsCSSProps.h
+++ b/layout/style/nsCSSProps.h
@@ -535,20 +535,25 @@ public:
     {
       return true;
     }
     return false;
   }
 
 public:
 
-#define CSSPROPS_FOR_SHORTHAND_SUBPROPERTIES(iter_, prop_)                    \
-  for (const nsCSSProperty* iter_ = nsCSSProps::SubpropertyEntryFor(prop_);   \
-       *iter_ != eCSSProperty_UNKNOWN; ++iter_) \
-    if (nsCSSProps::IsEnabled(*iter_))
+// Storing the enabledstate_ value in an nsCSSProperty variable is a small hack
+// to avoid needing a separate variable declaration for its real type
+// (nsCSSProps::EnabledState), which would then require using a block and
+// therefore a pair of macros by consumers for the start and end of the loop.
+#define CSSPROPS_FOR_SHORTHAND_SUBPROPERTIES(it_, prop_, enabledstate_)       \
+  for (const nsCSSProperty *it_ = nsCSSProps::SubpropertyEntryFor(prop_),     \
+                            es_ = (nsCSSProperty) (enabledstate_);            \
+       *it_ != eCSSProperty_UNKNOWN; ++it_)                                   \
+    if (nsCSSProps::IsEnabled(*it_, (nsCSSProps::EnabledState) es_))
 
   // Keyword/Enum value tables
   static const KTableValue kAnimationDirectionKTable[];
   static const KTableValue kAnimationFillModeKTable[];
   static const KTableValue kAnimationIterationCountKTable[];
   static const KTableValue kAnimationPlayStateKTable[];
   static const KTableValue kAnimationTimingFunctionKTable[];
   static const KTableValue kAppearanceKTable[];
--- a/layout/style/nsTransitionManager.cpp
+++ b/layout/style/nsTransitionManager.cpp
@@ -224,17 +224,18 @@ nsTransitionManager::StyleContextChanged
         for (nsCSSProperty p = nsCSSProperty(0);
              p < eCSSProperty_COUNT_no_shorthands;
              p = nsCSSProperty(p + 1)) {
           ConsiderStartingTransition(p, t, aElement, collection,
                                      aOldStyleContext, aNewStyleContext,
                                      &startedAny, &whichStarted);
         }
       } else if (nsCSSProps::IsShorthand(property)) {
-        CSSPROPS_FOR_SHORTHAND_SUBPROPERTIES(subprop, property) {
+        CSSPROPS_FOR_SHORTHAND_SUBPROPERTIES(
+            subprop, property, nsCSSProps::eEnabledForAllContent) {
           ConsiderStartingTransition(*subprop, t, aElement, collection,
                                      aOldStyleContext, aNewStyleContext,
                                      &startedAny, &whichStarted);
         }
       } else {
         ConsiderStartingTransition(property, t, aElement, collection,
                                    aOldStyleContext, aNewStyleContext,
                                    &startedAny, &whichStarted);
@@ -263,17 +264,18 @@ nsTransitionManager::StyleContextChanged
           // Nothing to do, but need to exclude this from cases below.
         } else if (property == eCSSPropertyExtra_all_properties) {
           for (nsCSSProperty p = nsCSSProperty(0);
                p < eCSSProperty_COUNT_no_shorthands;
                p = nsCSSProperty(p + 1)) {
             allTransitionProperties.AddProperty(p);
           }
         } else if (nsCSSProps::IsShorthand(property)) {
-          CSSPROPS_FOR_SHORTHAND_SUBPROPERTIES(subprop, property) {
+          CSSPROPS_FOR_SHORTHAND_SUBPROPERTIES(
+              subprop, property, nsCSSProps::eEnabledForAllContent) {
             allTransitionProperties.AddProperty(*subprop);
           }
         } else {
           allTransitionProperties.AddProperty(property);
         }
       }
     }