Bug 1345739 - Implement nsStyleImageRequest::GetImageURI.
MozReview-Commit-ID: Jqhio1RaqG1
--- a/layout/style/nsComputedDOMStyle.cpp
+++ b/layout/style/nsComputedDOMStyle.cpp
@@ -2258,28 +2258,22 @@ nsComputedDOMStyle::GetImageRectString(n
void
nsComputedDOMStyle::SetValueToStyleImage(const nsStyleImage& aStyleImage,
nsROCSSPrimitiveValue* aValue)
{
switch (aStyleImage.GetType()) {
case eStyleImageType_Image:
{
- imgIRequest* req = aStyleImage.GetImageData();
- if (!req) {
- // XXXheycam If we had some problem resolving the imgRequestProxy,
- // maybe we should just use the URL stored in the nsStyleImage's
- // mImageValue? (Similarly in DoGetListStyleImage.)
+ nsCOMPtr<nsIURI> uri = aStyleImage.GetImageURI();
+ if (!uri) {
aValue->SetIdent(eCSSKeyword_none);
break;
}
- nsCOMPtr<nsIURI> uri;
- req->GetURI(getter_AddRefs(uri));
-
const UniquePtr<nsStyleSides>& cropRect = aStyleImage.GetCropRect();
if (cropRect) {
nsAutoString imageRectString;
GetImageRectString(uri, *cropRect, imageRectString);
aValue->SetString(imageRectString);
} else {
aValue->SetURI(uri);
}
@@ -3687,28 +3681,20 @@ nsComputedDOMStyle::DoGetZIndex()
return val.forget();
}
already_AddRefed<CSSValue>
nsComputedDOMStyle::DoGetListStyleImage()
{
RefPtr<nsROCSSPrimitiveValue> val = new nsROCSSPrimitiveValue;
- const nsStyleList* list = StyleList();
-
- // XXXheycam As in SetValueToStyleImage, we might want to use the
- // URL stored in the nsStyleImageRequest's mImageValue if we
- // failed to resolve the imgRequestProxy.
-
- imgRequestProxy* image = list->GetListStyleImage();
- if (!image) {
+ nsCOMPtr<nsIURI> uri = StyleList()->GetListStyleImageURI();
+ if (!uri) {
val->SetIdent(eCSSKeyword_none);
} else {
- nsCOMPtr<nsIURI> uri;
- image->GetURI(getter_AddRefs(uri));
val->SetURI(uri);
}
return val.forget();
}
already_AddRefed<CSSValue>
nsComputedDOMStyle::DoGetListStylePosition()
--- a/layout/style/nsStyleStruct.cpp
+++ b/layout/style/nsStyleStruct.cpp
@@ -711,16 +711,27 @@ nsStyleList::CalcDifference(const nsStyl
if (mImageRegion.width == aNewData.mImageRegion.width &&
mImageRegion.height == aNewData.mImageRegion.height) {
return NS_STYLE_HINT_VISUAL;
}
}
return NS_STYLE_HINT_REFLOW;
}
+already_AddRefed<nsIURI>
+nsStyleList::GetListStyleImageURI() const
+{
+ if (!mListStyleImage) {
+ return nullptr;
+ }
+
+ nsCOMPtr<nsIURI> uri = mListStyleImage->GetImageURI();
+ return uri.forget();
+}
+
StaticRefPtr<nsStyleQuoteValues>
nsStyleList::sInitialQuotes;
StaticRefPtr<nsStyleQuoteValues>
nsStyleList::sNoneQuotes;
// --------------------
@@ -2240,16 +2251,38 @@ ConvertToPixelCoord(const nsStyleCoord&
NS_NOTREACHED("unexpected unit for image crop rect");
return 0;
}
MOZ_ASSERT(pixelValue >= 0, "we ensured non-negative while parsing");
pixelValue = std::min(pixelValue, double(INT32_MAX)); // avoid overflow
return NS_lround(pixelValue);
}
+already_AddRefed<nsIURI>
+nsStyleImageRequest::GetImageURI() const
+{
+ nsCOMPtr<nsIURI> uri;
+
+ if (mRequestProxy) {
+ mRequestProxy->GetURI(getter_AddRefs(uri));
+ if (uri) {
+ return uri.forget();
+ }
+ }
+
+ // If we had some problem resolving the mRequestProxy, use the URL stored
+ // in the mImageValue.
+ if (!mImageValue) {
+ return nullptr;
+ }
+
+ uri = mImageValue->GetURI();
+ return uri.forget();
+}
+
bool
nsStyleImage::ComputeActualCropRect(nsIntRect& aActualCropRect,
bool* aIsEntireImage) const
{
if (mType != eStyleImageType_Image) {
return false;
}
@@ -2438,16 +2471,27 @@ nsStyleImage::PurgeCacheForViewportChang
// axis are fixed in this case.)
if (aSVGViewportSize != mCachedBIData->GetCachedSVGViewportSize() &&
!aHasIntrinsicRatio) {
mCachedBIData->PurgeCachedImages();
mCachedBIData->SetCachedSVGViewportSize(aSVGViewportSize);
}
}
+already_AddRefed<nsIURI>
+nsStyleImage::GetImageURI() const
+{
+ if (mType != eStyleImageType_Image) {
+ return nullptr;
+ }
+
+ nsCOMPtr<nsIURI> uri = mImage->GetImageURI();
+ return uri.forget();
+}
+
// --------------------
// nsStyleImageLayers
//
const nsCSSPropertyID nsStyleImageLayers::kBackgroundLayerTable[] = {
eCSSProperty_background, // shorthand
eCSSProperty_background_color, // color
eCSSProperty_background_image, // image
--- a/layout/style/nsStyleStruct.h
+++ b/layout/style/nsStyleStruct.h
@@ -365,16 +365,18 @@ public:
}
// Returns whether the ImageValue objects in the two nsStyleImageRequests
// return true from URLValueData::DefinitelyEqualURIs.
bool DefinitelyEquals(const nsStyleImageRequest& aOther) const;
mozilla::css::ImageValue* GetImageValue() const { return mImageValue; }
+ already_AddRefed<nsIURI> GetImageURI() const;
+
NS_INLINE_DECL_THREADSAFE_REFCOUNTING(nsStyleImageRequest);
private:
~nsStyleImageRequest();
nsStyleImageRequest& operator=(const nsStyleImageRequest& aOther) = delete;
void MaybeTrackAndLock();
@@ -463,16 +465,18 @@ struct nsStyleImage
return mElementId;
}
const mozilla::UniquePtr<nsStyleSides>& GetCropRect() const {
NS_ASSERTION(mType == eStyleImageType_Image,
"Only image data can have a crop rect");
return mCropRect;
}
+ already_AddRefed<nsIURI> GetImageURI() const;
+
/**
* Compute the actual crop rect in pixels, using the source image bounds.
* The computation involves converting percentage unit to pixel unit and
* clamping each side value to fit in the source image bounds.
* @param aActualCropRect the computed actual crop rect.
* @param aIsEntireImage true iff |aActualCropRect| is identical to the
* source image bounds.
* @return true iff |aActualCropRect| holds a meaningful value.
@@ -1590,16 +1594,18 @@ struct MOZ_NEEDS_MEMMOVABLE_MEMBERS nsSt
sNoneQuotes = nullptr;
}
imgRequestProxy* GetListStyleImage() const
{
return mListStyleImage ? mListStyleImage->get() : nullptr;
}
+ already_AddRefed<nsIURI> GetListStyleImageURI() const;
+
void GetListStyleType(nsSubstring& aType) const { mCounterStyle->GetStyleName(aType); }
mozilla::CounterStyle* GetCounterStyle() const
{
return mCounterStyle.get();
}
void SetCounterStyle(mozilla::CounterStyle* aStyle)
{
// NB: This function is called off-main-thread during parallel restyle, but