Bug 1418899 - Part 4: Move image layer filling function out of nsRuleNode. r=CJKu draft
authorCameron McCormack <cam@mcc.id.au>
Mon, 20 Nov 2017 13:53:58 +0800
changeset 701034 5c439fa42300c67fabea70131e59ef07f70a8177
parent 701033 2b7d7ff48c4d8cc06e82f8b5d76c65376d26d767
child 741061 c38a150aee50cde5e8de01dd1360ca8067ba05a1
push id90037
push userbmo:cam@mcc.id.au
push dateTue, 21 Nov 2017 04:39:57 +0000
reviewersCJKu
bugs1418899
milestone59.0a1
Bug 1418899 - Part 4: Move image layer filling function out of nsRuleNode. r=CJKu MozReview-Commit-ID: 2FXGFEkpIKE
layout/style/ServoBindings.cpp
layout/style/nsRuleNode.cpp
layout/style/nsRuleNode.h
layout/style/nsStyleStruct.cpp
layout/style/nsStyleStruct.h
--- a/layout/style/ServoBindings.cpp
+++ b/layout/style/ServoBindings.cpp
@@ -847,17 +847,17 @@ Gecko_StyleTransition_SetUnsupportedProp
   } else {
     aTransition->SetProperty(id);
   }
 }
 
 void
 Gecko_FillAllImageLayers(nsStyleImageLayers* aLayers, uint32_t aMaxLen)
 {
-  nsRuleNode::FillAllImageLayers(*aLayers, aMaxLen);
+  aLayers->FillAllLayers(aMaxLen);
 }
 
 bool
 Gecko_IsDocumentBody(RawGeckoElementBorrowed aElement)
 {
   nsIDocument* doc = aElement->GetUncomposedDoc();
   return doc && doc->GetBodyElement() == aElement;
 }
--- a/layout/style/nsRuleNode.cpp
+++ b/layout/style/nsRuleNode.cpp
@@ -7120,94 +7120,16 @@ SetImageLayerPairList(GeckoStyleContext*
   default:
     MOZ_ASSERT(false, "unexpected unit");
   }
 
   if (aItemCount > aMaxItemCount)
     aMaxItemCount = aItemCount;
 }
 
-template <class ComputedValueItem>
-static void
-FillImageLayerList(
-    nsStyleAutoArray<nsStyleImageLayers::Layer>& aLayers,
-    ComputedValueItem nsStyleImageLayers::Layer::* aResultLocation,
-    uint32_t aItemCount, uint32_t aFillCount)
-{
-  NS_PRECONDITION(aFillCount <= aLayers.Length(), "unexpected array length");
-  for (uint32_t sourceLayer = 0, destLayer = aItemCount;
-       destLayer < aFillCount;
-       ++sourceLayer, ++destLayer) {
-    aLayers[destLayer].*aResultLocation =
-      aLayers[sourceLayer].*aResultLocation;
-  }
-}
-
-// The same as FillImageLayerList, but for values stored in
-// layer.mPosition.*aResultLocation instead of layer.*aResultLocation.
-static void
-FillImageLayerPositionCoordList(
-    nsStyleAutoArray<nsStyleImageLayers::Layer>& aLayers,
-    Position::Coord
-        Position::* aResultLocation,
-    uint32_t aItemCount, uint32_t aFillCount)
-{
-  NS_PRECONDITION(aFillCount <= aLayers.Length(), "unexpected array length");
-  for (uint32_t sourceLayer = 0, destLayer = aItemCount;
-       destLayer < aFillCount;
-       ++sourceLayer, ++destLayer) {
-    aLayers[destLayer].mPosition.*aResultLocation =
-      aLayers[sourceLayer].mPosition.*aResultLocation;
-  }
-}
-
-/* static */ void
-nsRuleNode::FillAllImageLayers(nsStyleImageLayers& aImage,
-                               uint32_t aMaxItemCount)
-{
-  // Delete any extra items.  We need to keep layers in which any
-  // property was specified.
-  aImage.mLayers.TruncateLengthNonZero(aMaxItemCount);
-
-  uint32_t fillCount = aImage.mImageCount;
-  FillImageLayerList(aImage.mLayers,
-                     &nsStyleImageLayers::Layer::mImage,
-                     aImage.mImageCount, fillCount);
-  FillImageLayerList(aImage.mLayers,
-                     &nsStyleImageLayers::Layer::mRepeat,
-                     aImage.mRepeatCount, fillCount);
-  FillImageLayerList(aImage.mLayers,
-                     &nsStyleImageLayers::Layer::mAttachment,
-                     aImage.mAttachmentCount, fillCount);
-  FillImageLayerList(aImage.mLayers,
-                     &nsStyleImageLayers::Layer::mClip,
-                     aImage.mClipCount, fillCount);
-  FillImageLayerList(aImage.mLayers,
-                     &nsStyleImageLayers::Layer::mBlendMode,
-                     aImage.mBlendModeCount, fillCount);
-  FillImageLayerList(aImage.mLayers,
-                     &nsStyleImageLayers::Layer::mOrigin,
-                     aImage.mOriginCount, fillCount);
-  FillImageLayerPositionCoordList(aImage.mLayers,
-                                  &Position::mXPosition,
-                                  aImage.mPositionXCount, fillCount);
-  FillImageLayerPositionCoordList(aImage.mLayers,
-                                  &Position::mYPosition,
-                                  aImage.mPositionYCount, fillCount);
-  FillImageLayerList(aImage.mLayers,
-                     &nsStyleImageLayers::Layer::mSize,
-                     aImage.mSizeCount, fillCount);
-  FillImageLayerList(aImage.mLayers,
-                     &nsStyleImageLayers::Layer::mMaskMode,
-                     aImage.mMaskModeCount, fillCount);
-  FillImageLayerList(aImage.mLayers,
-                     &nsStyleImageLayers::Layer::mComposite,
-                     aImage.mCompositeCount, fillCount);
-}
-
 const void*
 nsRuleNode::ComputeBackgroundData(void* aStartStruct,
                                   const nsRuleData* aRuleData,
                                   GeckoStyleContext* aContext,
                                   nsRuleNode* aHighestNode,
                                   const RuleDetail aRuleDetail,
                                   const RuleNodeCacheConditions aConditions)
 {
@@ -7313,17 +7235,17 @@ nsRuleNode::ComputeBackgroundData(void* 
                         bg->mImage.mLayers,
                         parentBG->mImage.mLayers,
                         &nsStyleImageLayers::Layer::mSize,
                         initialSize, parentBG->mImage.mSizeCount,
                         bg->mImage.mSizeCount, maxItemCount, rebuild,
                         conditions);
 
   if (rebuild) {
-    FillAllImageLayers(bg->mImage, maxItemCount);
+    bg->mImage.FillAllLayers(maxItemCount);
   }
 
   COMPUTE_END_RESET(Background, bg)
 }
 
 const void*
 nsRuleNode::ComputeMarginData(void* aStartStruct,
                               const nsRuleData* aRuleData,
@@ -9970,17 +9892,17 @@ nsRuleNode::ComputeSVGResetData(void* aS
                     svgReset->mMask.mLayers,
                     parentSVGReset->mMask.mLayers,
                     &nsStyleImageLayers::Layer::mComposite,
                     uint8_t(NS_STYLE_MASK_COMPOSITE_ADD),
                     parentSVGReset->mMask.mCompositeCount,
                     svgReset->mMask.mCompositeCount, maxItemCount, rebuild, conditions);
 
   if (rebuild) {
-    FillAllImageLayers(svgReset->mMask, maxItemCount);
+    svgReset->mMask.FillAllLayers(maxItemCount);
   }
 
   COMPUTE_END_RESET(SVGReset, svgReset)
 }
 
 const void*
 nsRuleNode::ComputeVariablesData(void* aStartStruct,
                                  const nsRuleData* aRuleData,
--- a/layout/style/nsRuleNode.h
+++ b/layout/style/nsRuleNode.h
@@ -1069,21 +1069,16 @@ public:
                            nsStyleContext* aStyleContext,
                            nscolor& aResult);
 
   static bool ParentHasPseudoElementData(mozilla::GeckoStyleContext* aContext);
 
   static void ComputeTimingFunction(const nsCSSValue& aValue,
                                     nsTimingFunction& aResult);
 
-  // Fill unspecified layers by cycling through their values
-  // till they all are of length aMaxItemCount
-  static void FillAllImageLayers(nsStyleImageLayers& aLayers,
-                                 uint32_t aMaxItemCount);
-
 private:
 #ifdef DEBUG
   // non-inline helper function to allow assertions without incomplete
   // type errors
   bool ContextHasCachedData(mozilla::GeckoStyleContext* aContext, nsStyleStructID aSID);
 #endif
 
   // Store style struct on the style context and tell the style context
--- a/layout/style/nsStyleStruct.cpp
+++ b/layout/style/nsStyleStruct.cpp
@@ -3172,16 +3172,93 @@ nsStyleImageLayers::Layer::operator==(co
          mBlendMode == aOther.mBlendMode &&
          mPosition == aOther.mPosition &&
          mSize == aOther.mSize &&
          mImage == aOther.mImage &&
          mMaskMode == aOther.mMaskMode &&
          mComposite == aOther.mComposite;
 }
 
+template <class ComputedValueItem>
+static void
+FillImageLayerList(
+    nsStyleAutoArray<nsStyleImageLayers::Layer>& aLayers,
+    ComputedValueItem nsStyleImageLayers::Layer::* aResultLocation,
+    uint32_t aItemCount, uint32_t aFillCount)
+{
+  NS_PRECONDITION(aFillCount <= aLayers.Length(), "unexpected array length");
+  for (uint32_t sourceLayer = 0, destLayer = aItemCount;
+       destLayer < aFillCount;
+       ++sourceLayer, ++destLayer) {
+    aLayers[destLayer].*aResultLocation =
+      aLayers[sourceLayer].*aResultLocation;
+  }
+}
+
+// The same as FillImageLayerList, but for values stored in
+// layer.mPosition.*aResultLocation instead of layer.*aResultLocation.
+static void
+FillImageLayerPositionCoordList(
+    nsStyleAutoArray<nsStyleImageLayers::Layer>& aLayers,
+    Position::Coord
+        Position::* aResultLocation,
+    uint32_t aItemCount, uint32_t aFillCount)
+{
+  NS_PRECONDITION(aFillCount <= aLayers.Length(), "unexpected array length");
+  for (uint32_t sourceLayer = 0, destLayer = aItemCount;
+       destLayer < aFillCount;
+       ++sourceLayer, ++destLayer) {
+    aLayers[destLayer].mPosition.*aResultLocation =
+      aLayers[sourceLayer].mPosition.*aResultLocation;
+  }
+}
+
+void
+nsStyleImageLayers::FillAllLayers(uint32_t aMaxItemCount)
+{
+  // Delete any extra items.  We need to keep layers in which any
+  // property was specified.
+  mLayers.TruncateLengthNonZero(aMaxItemCount);
+
+  uint32_t fillCount = mImageCount;
+  FillImageLayerList(mLayers,
+                     &nsStyleImageLayers::Layer::mImage,
+                     mImageCount, fillCount);
+  FillImageLayerList(mLayers,
+                     &nsStyleImageLayers::Layer::mRepeat,
+                     mRepeatCount, fillCount);
+  FillImageLayerList(mLayers,
+                     &nsStyleImageLayers::Layer::mAttachment,
+                     mAttachmentCount, fillCount);
+  FillImageLayerList(mLayers,
+                     &nsStyleImageLayers::Layer::mClip,
+                     mClipCount, fillCount);
+  FillImageLayerList(mLayers,
+                     &nsStyleImageLayers::Layer::mBlendMode,
+                     mBlendModeCount, fillCount);
+  FillImageLayerList(mLayers,
+                     &nsStyleImageLayers::Layer::mOrigin,
+                     mOriginCount, fillCount);
+  FillImageLayerPositionCoordList(mLayers,
+                                  &Position::mXPosition,
+                                  mPositionXCount, fillCount);
+  FillImageLayerPositionCoordList(mLayers,
+                                  &Position::mYPosition,
+                                  mPositionYCount, fillCount);
+  FillImageLayerList(mLayers,
+                     &nsStyleImageLayers::Layer::mSize,
+                     mSizeCount, fillCount);
+  FillImageLayerList(mLayers,
+                     &nsStyleImageLayers::Layer::mMaskMode,
+                     mMaskModeCount, fillCount);
+  FillImageLayerList(mLayers,
+                     &nsStyleImageLayers::Layer::mComposite,
+                     mCompositeCount, fillCount);
+}
+
 nsChangeHint
 nsStyleImageLayers::Layer::CalcDifference(const nsStyleImageLayers::Layer& aNewLayer) const
 {
   nsChangeHint hint = nsChangeHint(0);
   if (!DefinitelyEqualURIs(mImage.GetURLValue(),
                            aNewLayer.mImage.GetURLValue())) {
     hint |= nsChangeHint_RepaintFrame | nsChangeHint_UpdateEffects;
 
--- a/layout/style/nsStyleStruct.h
+++ b/layout/style/nsStyleStruct.h
@@ -836,16 +836,20 @@ struct nsStyleImageLayers {
   const Layer& BottomLayer() const { return mLayers[mImageCount - 1]; }
 
   void ResolveImages(nsPresContext* aContext) {
     for (uint32_t i = 0; i < mImageCount; ++i) {
       mLayers[i].ResolveImage(aContext);
     }
   }
 
+  // Fill unspecified layers by cycling through their values
+  // till they all are of length aMaxItemCount
+  void FillAllLayers(uint32_t aMaxItemCount);
+
   nsChangeHint CalcDifference(const nsStyleImageLayers& aNewLayers,
                               nsStyleImageLayers::LayerType aType) const;
 
   nsStyleImageLayers& operator=(const nsStyleImageLayers& aOther);
   nsStyleImageLayers& operator=(nsStyleImageLayers&& aOther);
   bool operator==(const nsStyleImageLayers& aOther) const;
 
   static const nsCSSPropertyID kBackgroundLayerTable[];