Bug 1288302 - Part 2: Pass ImageTracker to style struct image tracking methods instead of nsPresContext. r=xidorn
MozReview-Commit-ID: AsGfXliHLRf
--- a/layout/base/nsCSSRendering.cpp
+++ b/layout/base/nsCSSRendering.cpp
@@ -665,32 +665,32 @@ nsCSSRendering::PaintBorder(nsPresContex
aDirtyRect, aBorderArea, *styleBorder,
aStyleContext, aFlags, aSkipSides);
}
nsStyleBorder newStyleBorder(*styleBorder);
// We could do something fancy to avoid the TrackImage/UntrackImage
// work, but it doesn't seem worth it. (We need to call TrackImage
// since we're not going through nsRuleNode::ComputeBorderData.)
- newStyleBorder.TrackImage(aPresContext);
+ newStyleBorder.TrackImage(aPresContext->Document()->ImageTracker());
NS_FOR_CSS_SIDES(side) {
nscolor color = aStyleContext->GetVisitedDependentColor(
nsCSSProps::SubpropertyEntryFor(eCSSProperty_border_color)[side]);
newStyleBorder.mBorderColor[side] = StyleComplexColor::FromColor(color);
}
DrawResult result =
PaintBorderWithStyleBorder(aPresContext, aRenderingContext, aForFrame,
aDirtyRect, aBorderArea, newStyleBorder,
aStyleContext, aFlags, aSkipSides);
// We could do something fancy to avoid the TrackImage/UntrackImage
// work, but it doesn't seem worth it. (We need to call UntrackImage
// since we're not going through nsStyleBorder::Destroy.)
- newStyleBorder.UntrackImage(aPresContext);
+ newStyleBorder.UntrackImage(aPresContext->Document()->ImageTracker());
return result;
}
DrawResult
nsCSSRendering::PaintBorderWithStyleBorder(nsPresContext* aPresContext,
nsRenderingContext& aRenderingContext,
nsIFrame* aForFrame,
--- a/layout/style/nsRuleNode.cpp
+++ b/layout/style/nsRuleNode.cpp
@@ -7324,17 +7324,17 @@ nsRuleNode::ComputeBackgroundData(void*
bg->mImage.mSizeCount, maxItemCount, rebuild,
conditions);
if (rebuild) {
FillAllBackgroundLists(bg->mImage, maxItemCount);
}
// Now that the dust has settled, register the images with the document
- bg->mImage.TrackImages(aContext->PresContext());
+ bg->mImage.TrackImages(aContext->PresContext()->Document()->ImageTracker());
COMPUTE_END_RESET(Background, bg)
}
const void*
nsRuleNode::ComputeMarginData(void* aStartStruct,
const nsRuleData* aRuleData,
nsStyleContext* aContext,
@@ -7712,17 +7712,17 @@ nsRuleNode::ComputeBorderData(void* aSta
SetValue(borderImageRepeat.mYValue,
border->mBorderImageRepeatV,
conditions,
SETVAL_ENUMERATED | SETVAL_UNSET_INITIAL,
parentBorder->mBorderImageRepeatV,
NS_STYLE_BORDER_IMAGE_REPEAT_STRETCH);
- border->TrackImage(aContext->PresContext());
+ border->TrackImage(aContext->PresContext()->Document()->ImageTracker());
COMPUTE_END_RESET(Border, border)
}
const void*
nsRuleNode::ComputePaddingData(void* aStartStruct,
const nsRuleData* aRuleData,
nsStyleContext* aContext,
@@ -8980,17 +8980,18 @@ nsRuleNode::ComputeContentData(void* aSt
SETCOORD_LH | SETCOORD_AUTO | SETCOORD_INITIAL_AUTO |
SETCOORD_CALC_LENGTH_ONLY | SETCOORD_UNSET_INITIAL,
aContext, mPresContext, conditions);
// If we ended up with an image, track it.
for (uint32_t i = 0; i < content->ContentCount(); ++i) {
if ((content->ContentAt(i).mType == eStyleContentType_Image) &&
content->ContentAt(i).mContent.mImage) {
- content->ContentAt(i).TrackImage(aContext->PresContext());
+ content->ContentAt(i).TrackImage(
+ aContext->PresContext()->Document()->ImageTracker());
}
}
COMPUTE_END_RESET(Content, content)
}
const void*
nsRuleNode::ComputeXULData(void* aStartStruct,
@@ -10049,17 +10050,17 @@ nsRuleNode::ComputeSVGResetData(void* aS
svgReset->mMask.mLayers[0].mSourceURI.SetNull();
} else if (eCSSUnit_Inherit == maskValue->GetUnit()) {
conditions.SetUncacheable();
svgReset->mMask.mLayers[0].mSourceURI =
parentSVGReset->mMask.mLayers[0].mSourceURI;
}
#endif
- svgReset->mMask.TrackImages(aContext->PresContext());
+ svgReset->mMask.TrackImages(aContext->PresContext()->Document()->ImageTracker());
COMPUTE_END_RESET(SVGReset, svgReset)
}
const void*
nsRuleNode::ComputeVariablesData(void* aStartStruct,
const nsRuleData* aRuleData,
nsStyleContext* aContext,
--- a/layout/style/nsStyleStruct.cpp
+++ b/layout/style/nsStyleStruct.cpp
@@ -459,18 +459,20 @@ nsStyleBorder::GetImageOutset() const
break;
}
outset.Side(s) = value;
}
return outset;
}
void
-nsStyleBorder::Destroy(nsPresContext* aContext) {
- UntrackImage(aContext);
+nsStyleBorder::Destroy(nsPresContext* aContext)
+{
+ UntrackImage(aContext->Document()->ImageTracker());
+
this->~nsStyleBorder();
aContext->PresShell()->
FreeByObjectID(eArenaObjectID_nsStyleBorder, this);
}
nsChangeHint
nsStyleBorder::CalcDifference(const nsStyleBorder& aNewData) const
{
@@ -1164,17 +1166,17 @@ nsStyleSVGReset::nsStyleSVGReset(const n
, mMaskType(aSource.mMaskType)
{
MOZ_COUNT_CTOR(nsStyleSVGReset);
}
void
nsStyleSVGReset::Destroy(nsPresContext* aContext)
{
- mMask.UntrackImages(aContext);
+ mMask.UntrackImages(aContext->Document()->ImageTracker());
this->~nsStyleSVGReset();
aContext->PresShell()->
FreeByObjectID(mozilla::eArenaObjectID_nsStyleSVGReset, this);
}
nsChangeHint
nsStyleSVGReset::CalcDifference(const nsStyleSVGReset& aNewData) const
@@ -2006,48 +2008,40 @@ nsStyleImage::SetImageData(imgRequestPro
mType = eStyleImageType_Image;
}
if (mCachedBIData) {
mCachedBIData->PurgeCachedImages();
}
}
void
-nsStyleImage::TrackImage(nsPresContext* aContext)
+nsStyleImage::TrackImage(ImageTracker* aImageTracker)
{
// Sanity
MOZ_ASSERT(!mImageTracked, "Already tracking image!");
MOZ_ASSERT(mType == eStyleImageType_Image,
"Can't track image when there isn't one!");
- // Register the image with the document
- nsIDocument* doc = aContext->Document();
- if (doc) {
- doc->ImageTracker()->Add(mImage);
- }
+ aImageTracker->Add(mImage);
// Mark state
#ifdef DEBUG
mImageTracked = true;
#endif
}
void
-nsStyleImage::UntrackImage(nsPresContext* aContext)
+nsStyleImage::UntrackImage(ImageTracker* aImageTracker)
{
// Sanity
MOZ_ASSERT(mImageTracked, "Image not tracked!");
MOZ_ASSERT(mType == eStyleImageType_Image,
"Can't untrack image when there isn't one!");
- // Unregister the image with the document
- nsIDocument* doc = aContext->Document();
- if (doc) {
- doc->ImageTracker()->Remove(mImage);
- }
+ aImageTracker->Remove(mImage);
// Mark state
#ifdef DEBUG
mImageTracked = false;
#endif
}
void
@@ -2764,17 +2758,17 @@ nsStyleBackground::~nsStyleBackground()
{
MOZ_COUNT_DTOR(nsStyleBackground);
}
void
nsStyleBackground::Destroy(nsPresContext* aContext)
{
// Untrack all the images stored in our layers
- mImage.UntrackImages(aContext);
+ mImage.UntrackImages(aContext->Document()->ImageTracker());
this->~nsStyleBackground();
aContext->PresShell()->
FreeByObjectID(eArenaObjectID_nsStyleBackground, this);
}
nsChangeHint
nsStyleBackground::CalcDifference(const nsStyleBackground& aNewData) const
@@ -3422,52 +3416,44 @@ nsStyleContentData::operator==(const nsS
if (mType == eStyleContentType_Counter ||
mType == eStyleContentType_Counters) {
return *mContent.mCounters == *aOther.mContent.mCounters;
}
return safe_strcmp(mContent.mString, aOther.mContent.mString) == 0;
}
void
-nsStyleContentData::TrackImage(nsPresContext* aContext)
+nsStyleContentData::TrackImage(ImageTracker* aImageTracker)
{
// Sanity
MOZ_ASSERT(!mImageTracked, "Already tracking image!");
MOZ_ASSERT(mType == eStyleContentType_Image,
"Trying to do image tracking on non-image!");
MOZ_ASSERT(mContent.mImage,
"Can't track image when there isn't one!");
- // Register the image with the document
- nsIDocument* doc = aContext->Document();
- if (doc) {
- doc->ImageTracker()->Add(mContent.mImage);
- }
+ aImageTracker->Add(mContent.mImage);
// Mark state
#ifdef DEBUG
mImageTracked = true;
#endif
}
void
-nsStyleContentData::UntrackImage(nsPresContext* aContext)
+nsStyleContentData::UntrackImage(ImageTracker* aImageTracker)
{
// Sanity
MOZ_ASSERT(mImageTracked, "Image not tracked!");
MOZ_ASSERT(mType == eStyleContentType_Image,
"Trying to do image tracking on non-image!");
MOZ_ASSERT(mContent.mImage,
"Can't untrack image when there isn't one!");
- // Unregister the image with the document
- nsIDocument* doc = aContext->Document();
- if (doc) {
- doc->ImageTracker()->Remove(mContent.mImage);
- }
+ aImageTracker->Remove(mContent.mImage);
// Mark state
#ifdef DEBUG
mImageTracked = false;
#endif
}
@@ -3487,17 +3473,17 @@ nsStyleContent::~nsStyleContent()
}
void
nsStyleContent::Destroy(nsPresContext* aContext)
{
// Unregister any images we might have with the document.
for (auto& content : mContents) {
if (content.mType == eStyleContentType_Image && content.mContent.mImage) {
- content.UntrackImage(aContext);
+ content.UntrackImage(aContext->Document()->ImageTracker());
}
}
this->~nsStyleContent();
aContext->PresShell()->FreeByObjectID(eArenaObjectID_nsStyleContent, this);
}
nsStyleContent::nsStyleContent(const nsStyleContent& aSource)
--- a/layout/style/nsStyleStruct.h
+++ b/layout/style/nsStyleStruct.h
@@ -41,16 +41,21 @@
#include "X11UndefineNone.h"
class nsIFrame;
class nsIURI;
class nsStyleContext;
class nsTextFrame;
class imgIContainer;
struct nsStyleVisibility;
+namespace mozilla {
+namespace dom {
+class ImageTracker;
+} // namespace dom
+} // namespace mozilla
typedef nsINode RawGeckoNode;
typedef mozilla::dom::Element RawGeckoElement;
typedef nsIDocument RawGeckoDocument;
struct ServoNodeData;
// Includes nsStyleStructID.
#include "nsStyleStructFwd.h"
@@ -321,18 +326,18 @@ struct nsStyleImage
{
nsStyleImage();
~nsStyleImage();
nsStyleImage(const nsStyleImage& aOther);
nsStyleImage& operator=(const nsStyleImage& aOther);
void SetNull();
void SetImageData(imgRequestProxy* aImage);
- void TrackImage(nsPresContext* aContext);
- void UntrackImage(nsPresContext* aContext);
+ void TrackImage(mozilla::dom::ImageTracker* aImageTracker);
+ void UntrackImage(mozilla::dom::ImageTracker* aImageTracker);
void SetGradientData(nsStyleGradient* aGradient);
void SetElementId(const char16_t* aElementId);
void SetCropRect(mozilla::UniquePtr<nsStyleSides> aCropRect);
nsStyleImageType GetType() const {
return mType;
}
imgRequestProxy* GetImageData() const {
@@ -716,24 +721,24 @@ struct nsStyleImageLayers {
Layer();
~Layer();
// Initialize mRepeat and mOrigin by specified layer type
void Initialize(LayerType aType);
// Register/unregister images with the document. We do this only
// after the dust has settled in ComputeBackgroundData.
- void TrackImages(nsPresContext* aContext) {
+ void TrackImages(mozilla::dom::ImageTracker* aImageTracker) {
if (mImage.GetType() == eStyleImageType_Image) {
- mImage.TrackImage(aContext);
+ mImage.TrackImage(aImageTracker);
}
}
- void UntrackImages(nsPresContext* aContext) {
+ void UntrackImages(mozilla::dom::ImageTracker* aImageTracker) {
if (mImage.GetType() == eStyleImageType_Image) {
- mImage.UntrackImage(aContext);
+ mImage.UntrackImage(aImageTracker);
}
}
// True if the rendering of this layer might change when the size
// of the background positioning area changes. This is true for any
// non-solid-color background whose position or size depends on
// the size of the positioning area. It's also true for SVG images
// whose root <svg> node has a viewBox.
@@ -773,24 +778,24 @@ struct nsStyleImageLayers {
// background-clip applies to the background-color) may not be last
// layer. In layers below the bottom layer, properties will be
// uninitialized unless their count, above, indicates that they are
// present.
nsStyleAutoArray<Layer> mLayers;
const Layer& BottomLayer() const { return mLayers[mImageCount - 1]; }
- void TrackImages(nsPresContext* aContext) {
+ void TrackImages(mozilla::dom::ImageTracker* aImageTracker) {
for (uint32_t i = 0; i < mImageCount; ++i) {
- mLayers[i].TrackImages(aContext);
+ mLayers[i].TrackImages(aImageTracker);
}
}
- void UntrackImages(nsPresContext* aContext) {
+ void UntrackImages(mozilla::dom::ImageTracker* aImageTracker) {
for (uint32_t i = 0; i < mImageCount; ++i)
- mLayers[i].UntrackImages(aContext);
+ mLayers[i].UntrackImages(aImageTracker);
}
nsChangeHint CalcDifference(const nsStyleImageLayers& aNewLayers,
nsStyleImageLayers::LayerType aType) const;
bool HasLayerWithImage() const;
static const nsCSSPropertyID kBackgroundLayerTable[];
@@ -1212,26 +1217,26 @@ struct MOZ_NEEDS_MEMMOVABLE_MEMBERS nsSt
(HasVisibleStyle(aSide) ? mBorder.Side(aSide) : 0);
}
inline bool IsBorderImageLoaded() const
{
return mBorderImageSource.IsLoaded();
}
- void TrackImage(nsPresContext* aContext)
+ void TrackImage(mozilla::dom::ImageTracker* aImageTracker)
{
if (mBorderImageSource.GetType() == eStyleImageType_Image) {
- mBorderImageSource.TrackImage(aContext);
+ mBorderImageSource.TrackImage(aImageTracker);
}
}
- void UntrackImage(nsPresContext* aContext)
+ void UntrackImage(mozilla::dom::ImageTracker* aImageTracker)
{
if (mBorderImageSource.GetType() == eStyleImageType_Image) {
- mBorderImageSource.UntrackImage(aContext);
+ mBorderImageSource.UntrackImage(aImageTracker);
}
}
nsMargin GetImageOutset() const;
void GetCompositeColors(int32_t aIndex, nsBorderColors** aColors) const
{
if (!mBorderColors) {
@@ -3068,18 +3073,18 @@ struct nsStyleContentData
~nsStyleContentData();
nsStyleContentData& operator=(const nsStyleContentData& aOther);
bool operator==(const nsStyleContentData& aOther) const;
bool operator!=(const nsStyleContentData& aOther) const {
return !(*this == aOther);
}
- void TrackImage(nsPresContext* aContext);
- void UntrackImage(nsPresContext* aContext);
+ void TrackImage(mozilla::dom::ImageTracker* aImageTracker);
+ void UntrackImage(mozilla::dom::ImageTracker* aImageTracker);
void SetImage(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);
}