Bug 1310404 part 1 - Convert SetImageRequest to CreateImageRequest. r=heycam
MozReview-Commit-ID: JEzRpSMJ6XY
--- 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;