Bug 1310404 part 1 - Convert SetImageRequest to CreateImageRequest. r=heycam
authorXidorn Quan <me@upsuper.org>
Thu, 01 Dec 2016 13:40:00 +1100
changeset 324893 9166fe1b7814c5a6f3ca76c80d1f67895ae3ff3d
parent 324892 754947cc763ce9cee4574b04dd7a2c451163ebf8
child 324894 b393d76118f30a7e53fc43daa8b782aaca8445dd
push id24
push usermaklebus@msu.edu
push dateTue, 20 Dec 2016 03:11:33 +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
@@ -105,50 +105,45 @@ nsConditionalResetStyleData::GetConditio
 
       return data;
     }
     e = e->mNext;
   } while (e);
   return nullptr;
 }
 
-// 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(std::function<void(imgRequestProxy*)> aCallback,
-                nsPresContext* aPresContext,
-                const nsCSSValue& aValue)
+// Creates an imgRequestProxy based on the specified value in aValue and
+// returns 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.
+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(std::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,
@@ -8920,19 +8915,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;