Bug 1288797 - Replace nsAutoPtr with UniquePtr in nsStyleStruct.h (for variable "mCropRect") r?dholbert
MozReview-Commit-ID: 1UFbO0jgM1k
--- a/layout/style/nsComputedDOMStyle.cpp
+++ b/layout/style/nsComputedDOMStyle.cpp
@@ -2083,17 +2083,17 @@ nsComputedDOMStyle::SetValueToStyleImage
{
switch (aStyleImage.GetType()) {
case eStyleImageType_Image:
{
imgIRequest *req = aStyleImage.GetImageData();
nsCOMPtr<nsIURI> uri;
req->GetURI(getter_AddRefs(uri));
- const nsStyleSides* cropRect = aStyleImage.GetCropRect();
+ const UniquePtr<nsStyleSides>& cropRect = aStyleImage.GetCropRect();
if (cropRect) {
nsAutoString imageRectString;
GetImageRectString(uri, *cropRect, imageRectString);
aValue->SetString(imageRectString);
} else {
aValue->SetURI(uri);
}
break;
--- a/layout/style/nsRuleNode.cpp
+++ b/layout/style/nsRuleNode.cpp
@@ -1211,17 +1211,17 @@ static void SetStyleImageToImageRect(nsS
#ifdef DEBUG
bool unitOk =
#endif
SetAbsCoord(val, coord, SETCOORD_FACTOR | SETCOORD_PERCENT);
MOZ_ASSERT(unitOk, "Incorrect data structure created by CSS parser");
cropRect.Set(side, coord);
}
- aResult.SetCropRect(&cropRect);
+ aResult.SetCropRect(MakeUnique<nsStyleSides>(cropRect));
}
static void SetStyleImage(nsStyleContext* aStyleContext,
const nsCSSValue& aValue,
nsStyleImage& aResult,
RuleNodeCacheConditions& aConditions)
{
if (aValue.GetUnit() == eCSSUnit_Null) {
--- a/layout/style/nsStyleStruct.cpp
+++ b/layout/style/nsStyleStruct.cpp
@@ -1962,17 +1962,21 @@ nsStyleImage::DoCopy(const nsStyleImage&
if (aOther.mType == eStyleImageType_Image) {
SetImageData(aOther.mImage);
} else if (aOther.mType == eStyleImageType_Gradient) {
SetGradientData(aOther.mGradient);
} else if (aOther.mType == eStyleImageType_Element) {
SetElementId(aOther.mElementId);
}
- SetCropRect(aOther.mCropRect);
+ UniquePtr<nsStyleSides> cropRectCopy;
+ if (aOther.mCropRect) {
+ cropRectCopy = MakeUnique<nsStyleSides>(*aOther.mCropRect.get());
+ }
+ SetCropRect(Move(cropRectCopy));
}
void
nsStyleImage::SetNull()
{
MOZ_ASSERT(!mImageTracked,
"Calling SetNull() with image tracked!");
@@ -2073,24 +2077,19 @@ nsStyleImage::SetElementId(const char16_
if (aElementId) {
mElementId = NS_strdup(aElementId);
mType = eStyleImageType_Element;
}
}
void
-nsStyleImage::SetCropRect(nsStyleSides* aCropRect)
+nsStyleImage::SetCropRect(UniquePtr<nsStyleSides> aCropRect)
{
- if (aCropRect) {
- mCropRect = new nsStyleSides(*aCropRect);
- // There is really not much we can do if 'new' fails
- } else {
- mCropRect = nullptr;
- }
+ mCropRect = Move(aCropRect);
}
static int32_t
ConvertToPixelCoord(const nsStyleCoord& aCoord, int32_t aPercentScale)
{
double pixelValue;
switch (aCoord.GetUnit()) {
case eStyleUnit_Percent:
@@ -2232,17 +2231,17 @@ nsStyleImage::IsLoaded() const
}
default:
NS_NOTREACHED("unexpected image type");
return false;
}
}
static inline bool
-EqualRects(const nsStyleSides* aRect1, const nsStyleSides* aRect2)
+EqualRects(const UniquePtr<nsStyleSides>& aRect1, const UniquePtr<nsStyleSides>& aRect2)
{
return aRect1 == aRect2 || /* handles null== null, and optimize */
(aRect1 && aRect2 && *aRect1 == *aRect2);
}
bool
nsStyleImage::operator==(const nsStyleImage& aOther) const
{
--- a/layout/style/nsStyleStruct.h
+++ b/layout/style/nsStyleStruct.h
@@ -13,17 +13,17 @@
#define nsStyleStruct_h___
#include "mozilla/ArenaObjectID.h"
#include "mozilla/Attributes.h"
#include "mozilla/CSSVariableValues.h"
#include "mozilla/SheetType.h"
#include "mozilla/StaticPtr.h"
#include "mozilla/StyleStructContext.h"
-#include "nsAutoPtr.h"
+#include "mozilla/UniquePtr.h"
#include "nsColor.h"
#include "nsCoord.h"
#include "nsMargin.h"
#include "nsFont.h"
#include "nsStyleCoord.h"
#include "nsStyleConsts.h"
#include "nsChangeHint.h"
#include "nsPresContext.h"
@@ -264,17 +264,17 @@ struct nsStyleImage
nsStyleImage& operator=(const nsStyleImage& aOther);
void SetNull();
void SetImageData(imgRequestProxy* aImage);
void TrackImage(nsPresContext* aContext);
void UntrackImage(nsPresContext* aContext);
void SetGradientData(nsStyleGradient* aGradient);
void SetElementId(const char16_t* aElementId);
- void SetCropRect(nsStyleSides* aCropRect);
+ void SetCropRect(mozilla::UniquePtr<nsStyleSides> aCropRect);
nsStyleImageType GetType() const {
return mType;
}
imgRequestProxy* GetImageData() const {
MOZ_ASSERT(mType == eStyleImageType_Image, "Data is not an image!");
MOZ_ASSERT(mImageTracked,
"Should be tracking any image we're going to use!");
@@ -283,17 +283,17 @@ struct nsStyleImage
nsStyleGradient* GetGradientData() const {
NS_ASSERTION(mType == eStyleImageType_Gradient, "Data is not a gradient!");
return mGradient;
}
const char16_t* GetElementId() const {
NS_ASSERTION(mType == eStyleImageType_Element, "Data is not an element!");
return mElementId;
}
- nsStyleSides* GetCropRect() const {
+ const mozilla::UniquePtr<nsStyleSides>& GetCropRect() const {
NS_ASSERTION(mType == eStyleImageType_Image,
"Only image data can have a crop rect");
return mCropRect;
}
/**
* Compute the actual crop rect in pixels, using the source image bounds.
* The computation involves converting percentage unit to pixel unit and
@@ -368,17 +368,17 @@ private:
nsStyleImageType mType;
union {
imgRequestProxy* mImage;
nsStyleGradient* mGradient;
char16_t* mElementId;
};
// This is _currently_ used only in conjunction with eStyleImageType_Image.
- nsAutoPtr<nsStyleSides> mCropRect;
+ mozilla::UniquePtr<nsStyleSides> mCropRect;
#ifdef DEBUG
bool mImageTracked;
#endif
};
struct MOZ_NEEDS_MEMMOVABLE_MEMBERS nsStyleColor
{
explicit nsStyleColor(StyleStructContext aContext);