Bug 1341761 - Convert nsStyleImage::mElementId to use nsIAtom r?xidorn draft
authorNazım Can Altınova <canaltinova@gmail.com>
Sun, 09 Apr 2017 16:44:36 +0300
changeset 559285 94de1ab52757e9ed4c37dda605cf8b57d63ee646
parent 557688 10ea10d9993c9701e5525928257a589dea2c05d8
child 559286 f8f82a305be92d8629679f1338991999cfff50b1
child 559288 0e782d2bf1f7dcd5e2a07bb47e9c8c53f12735dc
push id53043
push userbmo:canaltinova@gmail.com
push dateSun, 09 Apr 2017 13:50:52 +0000
reviewersxidorn
bugs1341761
milestone55.0a1
Bug 1341761 - Convert nsStyleImage::mElementId to use nsIAtom r?xidorn MozReview-Commit-ID: 9YcbhMmXYoi
layout/painting/nsImageRenderer.cpp
layout/style/nsComputedDOMStyle.cpp
layout/style/nsRuleNode.cpp
layout/style/nsStyleStruct.cpp
layout/style/nsStyleStruct.h
--- a/layout/painting/nsImageRenderer.cpp
+++ b/layout/painting/nsImageRenderer.cpp
@@ -169,17 +169,17 @@ nsImageRenderer::PrepareImage()
     }
     case eStyleImageType_Gradient:
       mGradientData = mImage->GetGradientData();
       mPrepareResult = DrawResult::SUCCESS;
       break;
     case eStyleImageType_Element:
     {
       nsAutoString elementId =
-        NS_LITERAL_STRING("#") + nsDependentString(mImage->GetElementId());
+        NS_LITERAL_STRING("#") + nsDependentAtomString(mImage->GetElementId());
       nsCOMPtr<nsIURI> targetURI;
       nsCOMPtr<nsIURI> base = mForFrame->GetContent()->GetBaseURI();
       nsContentUtils::NewURIWithDocumentCharset(getter_AddRefs(targetURI), elementId,
                                                 mForFrame->GetContent()->GetUncomposedDoc(), base);
       nsSVGPaintingProperty* property = nsSVGEffects::GetPaintingPropertyForURI(
           targetURI, mForFrame->FirstContinuation(),
           nsSVGEffects::BackgroundImageProperty());
       if (!property) {
--- a/layout/style/nsComputedDOMStyle.cpp
+++ b/layout/style/nsComputedDOMStyle.cpp
@@ -2281,17 +2281,18 @@ nsComputedDOMStyle::SetValueToStyleImage
                            gradientString);
       aValue->SetString(gradientString);
       break;
     }
     case eStyleImageType_Element:
     {
       nsAutoString elementId;
       nsStyleUtil::AppendEscapedCSSIdent(
-        nsDependentString(aStyleImage.GetElementId()), elementId);
+        nsDependentAtomString(aStyleImage.GetElementId()),
+                              elementId);
       nsAutoString elementString = NS_LITERAL_STRING("-moz-element(#") +
                                    elementId +
                                    NS_LITERAL_STRING(")");
       aValue->SetString(elementString);
       break;
     }
     case eStyleImageType_Null:
       aValue->SetIdent(eCSSKeyword_none);
--- a/layout/style/nsRuleNode.cpp
+++ b/layout/style/nsRuleNode.cpp
@@ -1369,18 +1369,21 @@ static void SetStyleImage(nsStyleContext
     case eCSSUnit_Gradient:
     {
       nsStyleGradient* gradient = new nsStyleGradient();
       SetGradient(aValue, presContext, aStyleContext, *gradient, aConditions);
       aResult.SetGradientData(gradient);
       break;
     }
     case eCSSUnit_Element:
-      aResult.SetElementId(aValue.GetStringBufferValue());
-      break;
+    {
+      nsCOMPtr<nsIAtom> atom = NS_Atomize(aValue.GetStringBufferValue());
+      aResult.SetElementId(atom.forget());
+      break;
+    }
     case eCSSUnit_Initial:
     case eCSSUnit_Unset:
     case eCSSUnit_None:
       break;
     case eCSSUnit_URL:
     {
 #ifdef DEBUG
       // eCSSUnit_URL is expected only if
--- a/layout/style/nsStyleStruct.cpp
+++ b/layout/style/nsStyleStruct.cpp
@@ -2188,17 +2188,17 @@ nsStyleImage::DoCopy(const nsStyleImage&
 {
   SetNull();
 
   if (aOther.mType == eStyleImageType_Image) {
     SetImageRequest(do_AddRef(aOther.mImage));
   } else if (aOther.mType == eStyleImageType_Gradient) {
     SetGradientData(aOther.mGradient);
   } else if (aOther.mType == eStyleImageType_Element) {
-    SetElementId(aOther.mElementId);
+    SetElementId(do_AddRef(aOther.mElementId));
   }
 
   UniquePtr<nsStyleSides> cropRectCopy;
   if (aOther.mCropRect) {
     cropRectCopy = MakeUnique<nsStyleSides>(*aOther.mCropRect.get());
   }
   SetCropRect(Move(cropRectCopy));
 }
@@ -2206,17 +2206,17 @@ nsStyleImage::DoCopy(const nsStyleImage&
 void
 nsStyleImage::SetNull()
 {
   if (mType == eStyleImageType_Gradient) {
     mGradient->Release();
   } else if (mType == eStyleImageType_Image) {
     NS_RELEASE(mImage);
   } else if (mType == eStyleImageType_Element) {
-    free(mElementId);
+    NS_RELEASE(mElementId);
   }
 
   mType = eStyleImageType_Null;
   mCropRect = nullptr;
 }
 
 void
 nsStyleImage::SetImageRequest(already_AddRefed<nsStyleImageRequest> aImage)
@@ -2249,24 +2249,24 @@ nsStyleImage::SetGradientData(nsStyleGra
 
   if (aGradient) {
     mGradient = aGradient;
     mType = eStyleImageType_Gradient;
   }
 }
 
 void
-nsStyleImage::SetElementId(const char16_t* aElementId)
+nsStyleImage::SetElementId(already_AddRefed<nsIAtom> aElementId)
 {
   if (mType != eStyleImageType_Null) {
     SetNull();
   }
 
-  if (aElementId) {
-    mElementId = NS_strdup(aElementId);
+  if (nsCOMPtr<nsIAtom> atom = aElementId) {
+    mElementId = atom.forget().take();
     mType = eStyleImageType_Element;
   }
 }
 
 void
 nsStyleImage::SetCropRect(UniquePtr<nsStyleSides> aCropRect)
 {
     mCropRect = Move(aCropRect);
@@ -2481,17 +2481,17 @@ nsStyleImage::operator==(const nsStyleIm
     return DefinitelyEqualImages(mImage, aOther.mImage);
   }
 
   if (mType == eStyleImageType_Gradient) {
     return *mGradient == *aOther.mGradient;
   }
 
   if (mType == eStyleImageType_Element) {
-    return NS_strcmp(mElementId, aOther.mElementId) == 0;
+    return mElementId == aOther.mElementId;
   }
 
   return true;
 }
 
 void
 nsStyleImage::PurgeCacheForViewportChange(
   const mozilla::Maybe<nsSize>& aSVGViewportSize,
--- a/layout/style/nsStyleStruct.h
+++ b/layout/style/nsStyleStruct.h
@@ -422,17 +422,17 @@ struct nsStyleImage
   nsStyleImage();
   ~nsStyleImage();
   nsStyleImage(const nsStyleImage& aOther);
   nsStyleImage& operator=(const nsStyleImage& aOther);
 
   void SetNull();
   void SetImageRequest(already_AddRefed<nsStyleImageRequest> aImage);
   void SetGradientData(nsStyleGradient* aGradient);
-  void SetElementId(const char16_t* aElementId);
+  void SetElementId(already_AddRefed<nsIAtom> aElementId);
   void SetCropRect(mozilla::UniquePtr<nsStyleSides> aCropRect);
 
   void ResolveImage(nsPresContext* aContext) {
     MOZ_ASSERT(mType != eStyleImageType_Image || mImage);
     if (mType == eStyleImageType_Image && !mImage->IsResolved()) {
       mImage->Resolve(aContext);
     }
   }
@@ -447,17 +447,17 @@ struct nsStyleImage
   }
   imgRequestProxy* GetImageData() const {
     return GetImageRequest()->get();
   }
   nsStyleGradient* GetGradientData() const {
     NS_ASSERTION(mType == eStyleImageType_Gradient, "Data is not a gradient!");
     return mGradient;
   }
-  const char16_t* GetElementId() const {
+  const nsIAtom* GetElementId() const {
     NS_ASSERTION(mType == eStyleImageType_Element, "Data is not an element!");
     return mElementId;
   }
   const mozilla::UniquePtr<nsStyleSides>& GetCropRect() const {
     NS_ASSERTION(mType == eStyleImageType_Image,
                  "Only image data can have a crop rect");
     return mCropRect;
   }
@@ -542,17 +542,17 @@ private:
   // This variable keeps some cache data for border image and is lazily
   // allocated since it is only used in border image case.
   mozilla::UniquePtr<CachedBorderImageData> mCachedBIData;
 
   nsStyleImageType mType;
   union {
     nsStyleImageRequest* mImage;
     nsStyleGradient* mGradient;
-    char16_t* mElementId;
+    nsIAtom* mElementId;
   };
 
   // This is _currently_ used only in conjunction with eStyleImageType_Image.
   mozilla::UniquePtr<nsStyleSides> mCropRect;
 };
 
 struct MOZ_NEEDS_MEMMOVABLE_MEMBERS nsStyleColor
 {