Bug 773296 - Part 15: Factor out mapping of a single property from an nsCSSCompressedDataBlock to an nsRuleData. r=dbaron
authorCameron McCormack <cam@mcc.id.au>
Thu, 12 Dec 2013 13:09:43 +1100
changeset 160109 ec31b9795a5df73092f822b5d315a0c56ad7460e
parent 160108 39833de60ed769bedb8bd05ae272059ebeb8488c
child 160110 f5acf7d3cd8f8caaa3c17734d529ba78e5e5efc7
push id3938
push usercbook@mozilla.com
push dateThu, 12 Dec 2013 15:09:56 +0000
treeherderfx-team@0cf1107e2791 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersdbaron
bugs773296
milestone29.0a1
Bug 773296 - Part 15: Factor out mapping of a single property from an nsCSSCompressedDataBlock to an nsRuleData. r=dbaron This factors out the part of nsCSSCompressedDataBlock::MapRuleInfoInto that starts image loading and maybe-copies an nsCSSValue into an nsRuleData. We will need this functionality for mapping re-parsed properties that had variable references into an nsRuleData, which will be done from an nsCSSExpandedDataBlock.
layout/style/nsCSSDataBlock.cpp
--- a/layout/style/nsCSSDataBlock.cpp
+++ b/layout/style/nsCSSDataBlock.cpp
@@ -99,56 +99,64 @@ ShouldStartImageLoads(nsRuleData *aRuleD
   //  (2) in some cases we'd start the image load on a style change
   //      where we wouldn't have started the load initially, which makes
   //      which links are visited detectable to Web pages (see bug
   //      557287)
   return !aRuleData->mStyleContext->IsStyleIfVisited() &&
          nsCSSProps::PropHasFlags(aProperty, CSS_PROPERTY_START_IMAGE_LOADS);
 }
 
+static void
+MapSinglePropertyInto(nsCSSProperty aProp,
+                      const nsCSSValue* aValue,
+                      nsCSSValue* aTarget,
+                      nsRuleData* aRuleData)
+{
+    NS_ABORT_IF_FALSE(aValue->GetUnit() != eCSSUnit_Null, "oops");
+    if (ShouldStartImageLoads(aRuleData, aProp)) {
+        nsIDocument* doc = aRuleData->mPresContext->Document();
+        TryToStartImageLoad(*aValue, doc, aProp);
+    }
+    *aTarget = *aValue;
+    if (nsCSSProps::PropHasFlags(aProp,
+            CSS_PROPERTY_IGNORED_WHEN_COLORS_DISABLED) &&
+        ShouldIgnoreColors(aRuleData))
+    {
+        if (aProp == eCSSProperty_background_color) {
+            // Force non-'transparent' background
+            // colors to the user's default.
+            if (aTarget->IsNonTransparentColor()) {
+                aTarget->SetColorValue(aRuleData->mPresContext->
+                                       DefaultBackgroundColor());
+            }
+        } else {
+            // Ignore 'color', 'border-*-color', etc.
+            *aTarget = nsCSSValue();
+        }
+    }
+}
+
 void
 nsCSSCompressedDataBlock::MapRuleInfoInto(nsRuleData *aRuleData) const
 {
     // If we have no data for these structs, then return immediately.
     // This optimization should make us return most of the time, so we
     // have to worry much less (although still some) about the speed of
     // the rest of the function.
     if (!(aRuleData->mSIDs & mStyleBits))
         return;
 
-    nsIDocument* doc = aRuleData->mPresContext->Document();
-
     for (uint32_t i = 0; i < mNumProps; i++) {
         nsCSSProperty iProp = PropertyAtIndex(i);
         if (nsCachedStyleData::GetBitForSID(nsCSSProps::kSIDTable[iProp]) &
             aRuleData->mSIDs) {
             nsCSSValue* target = aRuleData->ValueFor(iProp);
             if (target->GetUnit() == eCSSUnit_Null) {
                 const nsCSSValue *val = ValueAtIndex(i);
-                NS_ABORT_IF_FALSE(val->GetUnit() != eCSSUnit_Null, "oops");
-                if (ShouldStartImageLoads(aRuleData, iProp)) {
-                    TryToStartImageLoad(*val, doc, iProp);
-                }
-                *target = *val;
-                if (nsCSSProps::PropHasFlags(iProp,
-                        CSS_PROPERTY_IGNORED_WHEN_COLORS_DISABLED) &&
-                    ShouldIgnoreColors(aRuleData))
-                {
-                    if (iProp == eCSSProperty_background_color) {
-                        // Force non-'transparent' background
-                        // colors to the user's default.
-                        if (target->IsNonTransparentColor()) {
-                            target->SetColorValue(aRuleData->mPresContext->
-                                                  DefaultBackgroundColor());
-                        }
-                    } else {
-                        // Ignore 'color', 'border-*-color', etc.
-                        *target = nsCSSValue();
-                    }
-                }
+                MapSinglePropertyInto(iProp, val, target, aRuleData);
             }
         }
     }
 }
 
 const nsCSSValue*
 nsCSSCompressedDataBlock::ValueFor(nsCSSProperty aProperty) const
 {