Bug 1310404 part 1 - Convert SetImageRequest to CreateImageRequest. r?heycam draft
authorXidorn Quan <me@upsuper.org>
Wed, 30 Nov 2016 16:48:49 +1100
changeset 445732 58c2fe58f17475431ff1e07157ec6c3239bae3d8
parent 443737 e72c77a318b7bfcb8252754acbdd1a2f84ef849a
child 445733 ac41e83b005649c094bb2990588ddb77b4766802
push id37598
push userxquan@mozilla.com
push dateWed, 30 Nov 2016 06:04:22 +0000
reviewersheycam
bugs1310404
milestone53.0a1
Bug 1310404 part 1 - Convert SetImageRequest to CreateImageRequest. r?heycam MozReview-Commit-ID: JEzRpSMJ6XY
layout/style/nsRuleNode.cpp
layout/style/nsStyleStruct.h
--- a/layout/style/nsRuleNode.cpp
+++ b/layout/style/nsRuleNode.cpp
@@ -110,44 +110,41 @@ nsConditionalResetStyleData::GetConditio
 }
 
 // Creates an imgRequestProxy based on the specified value in
 // aValue and calls aCallback with it.  If the nsPresContext
 // is static (e.g. for printing), then a static request (i.e.
 // showing the first frame, without animation) will be created.
 // (The expectation is then that aCallback will set the resulting
 // imgRequestProxy in a style struct somewhere.)
-static void
-SetImageRequest(function<void(imgRequestProxy*)> aCallback,
-                nsPresContext* aPresContext,
-                const nsCSSValue& aValue)
+static already_AddRefed<imgRequestProxy>
+CreateImageRequest(nsPresContext* aPresContext, const nsCSSValue& aValue)
 {
   RefPtr<imgRequestProxy> req =
     aValue.GetPossiblyStaticImageValue(aPresContext->Document(),
                                        aPresContext);
-  aCallback(req);
+  return req.forget();
 }
 
 static void
 SetStyleImageRequest(function<void(nsStyleImageRequest*)> aCallback,
                      nsPresContext* aPresContext,
                      const nsCSSValue& aValue,
                      nsStyleImageRequest::Mode aModeFlags =
                        nsStyleImageRequest::Mode::Track)
 {
-  SetImageRequest([&](imgRequestProxy* aProxy) {
-    css::ImageValue* imageValue = aValue.GetImageStructValue();
-    ImageTracker* imageTracker =
-      (aModeFlags & nsStyleImageRequest::Mode::Track)
-      ? aPresContext->Document()->ImageTracker()
-      : nullptr;
-    RefPtr<nsStyleImageRequest> request =
-      new nsStyleImageRequest(aModeFlags, aProxy, imageValue, imageTracker);
-    aCallback(request);
-  }, aPresContext, aValue);
+  css::ImageValue* imageValue = aValue.GetImageStructValue();
+  ImageTracker* imageTracker =
+    (aModeFlags & nsStyleImageRequest::Mode::Track)
+    ? aPresContext->Document()->ImageTracker()
+    : nullptr;
+  RefPtr<imgRequestProxy> proxy = CreateImageRequest(aPresContext, aValue);
+  RefPtr<nsStyleImageRequest> request =
+    new nsStyleImageRequest(aModeFlags, proxy, imageValue, imageTracker);
+  aCallback(request);
 }
 
 template<typename ReferenceBox>
 static void
 SetStyleShapeSourceToCSSValue(StyleShapeSource<ReferenceBox>* aShapeSource,
                               const nsCSSValue* aValue,
                               nsStyleContext* aStyleContext,
                               nsPresContext* aPresContext,
@@ -8865,19 +8862,17 @@ nsRuleNode::ComputeContentData(void* aSt
         }
         break;
       default:
         NS_ERROR("bad content type");
         type = eStyleContentType_Uninitialized;
       }
       data.mType = type;
       if (type == eStyleContentType_Image) {
-        SetImageRequest([&](imgRequestProxy* req) {
-          data.SetImage(req);
-        }, mPresContext, value);
+        data.SetImage(CreateImageRequest(mPresContext, value));
       } else if (type <= eStyleContentType_Attr) {
         value.GetStringValue(buffer);
         data.mContent.mString = NS_strdup(buffer.get());
       } else if (type <= eStyleContentType_Counters) {
         data.mContent.mCounters = value.GetArrayValue();
         data.mContent.mCounters->AddRef();
       } else {
         data.mContent.mString = nullptr;
--- a/layout/style/nsStyleStruct.h
+++ b/layout/style/nsStyleStruct.h
@@ -3185,22 +3185,22 @@ struct nsStyleContentData
 
   bool operator!=(const nsStyleContentData& aOther) const {
     return !(*this == aOther);
   }
 
   void TrackImage(mozilla::dom::ImageTracker* aImageTracker);
   void UntrackImage(mozilla::dom::ImageTracker* aImageTracker);
 
-  void SetImage(imgRequestProxy* aRequest)
+  void SetImage(already_AddRefed<imgRequestProxy> aRequest)
   {
     MOZ_ASSERT(!mImageTracked,
                "Setting a new image without untracking the old one!");
     MOZ_ASSERT(mType == eStyleContentType_Image, "Wrong type!");
-    NS_IF_ADDREF(mContent.mImage = aRequest);
+    mContent.mImage = aRequest.take();
   }
 };
 
 struct nsStyleCounterData
 {
   nsString  mCounter;
   int32_t   mValue;