Bug 1403500, part 1 - Document and do some renaming for SVGObserverUtils' SourceReference. r=longsonr

MozReview-Commit-ID: Hd7uzHltyMl
This commit is contained in:
Jonathan Watt 2017-09-12 09:36:08 +01:00
Родитель 4fa395cf9c
Коммит a9811eda2d
2 изменённых файлов: 21 добавлений и 14 удалений

Просмотреть файл

@ -180,10 +180,10 @@ nsSVGRenderingObserver::ContentRemoved(nsIDocument* aDocument,
nsSVGIDRenderingObserver::nsSVGIDRenderingObserver(nsIURI* aURI,
nsIContent* aObservingContent,
bool aReferenceImage)
: mElement(this)
: mObservedElementTracker(this)
{
// Start watching the target element
mElement.Reset(aObservingContent, aURI, true, aReferenceImage);
mObservedElementTracker.Reset(aObservingContent, aURI, true, aReferenceImage);
StartListening();
}
@ -195,8 +195,8 @@ nsSVGIDRenderingObserver::~nsSVGIDRenderingObserver()
void
nsSVGIDRenderingObserver::DoUpdate()
{
if (mElement.get() && mInObserverList) {
SVGObserverUtils::RemoveRenderingObserver(mElement.get(), this);
if (mObservedElementTracker.get() && mInObserverList) {
SVGObserverUtils::RemoveRenderingObserver(mObservedElementTracker.get(), this);
mInObserverList = false;
}
}
@ -242,12 +242,12 @@ NS_IMPL_CYCLE_COLLECTING_RELEASE(nsSVGFilterReference)
NS_IMPL_CYCLE_COLLECTION_CLASS(nsSVGFilterReference)
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN(nsSVGFilterReference)
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mElement)
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mObservedElementTracker)
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END
NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN(nsSVGFilterReference)
tmp->StopListening();
NS_IMPL_CYCLE_COLLECTION_UNLINK(mElement);
NS_IMPL_CYCLE_COLLECTION_UNLINK(mObservedElementTracker);
NS_IMPL_CYCLE_COLLECTION_UNLINK_END
NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(nsSVGFilterReference)

Просмотреть файл

@ -120,21 +120,28 @@ public:
virtual ~nsSVGIDRenderingObserver();
protected:
Element* GetTarget() override { return mElement.get(); }
Element* GetTarget() override { return mObservedElementTracker.get(); }
// This is called when the referenced resource changes.
virtual void DoUpdate() override;
class SourceReference : public IDTracker
/**
* Helper that provides a reference to the element with the ID that our
* observer wants to observe, and that will invalidate our observer if the
* element that that ID identifies changes to a different element (or none).
*/
class ElementTracker final : public IDTracker
{
public:
explicit SourceReference(nsSVGIDRenderingObserver* aContainer) : mContainer(aContainer) {}
explicit ElementTracker(nsSVGIDRenderingObserver* aOwningObserver)
: mOwningObserver(aOwningObserver)
{}
protected:
virtual void ElementChanged(Element* aFrom, Element* aTo) override {
mContainer->StopListening();
mOwningObserver->StopListening(); // stop observing the old element
IDTracker::ElementChanged(aFrom, aTo);
mContainer->StartListening();
mContainer->DoUpdate();
mOwningObserver->StartListening(); // start observing the new element
mOwningObserver->DoUpdate();
}
/**
* Override IsPersistent because we want to keep tracking the element
@ -142,10 +149,10 @@ protected:
*/
virtual bool IsPersistent() override { return true; }
private:
nsSVGIDRenderingObserver* mContainer;
nsSVGIDRenderingObserver* mOwningObserver;
};
SourceReference mElement;
ElementTracker mObservedElementTracker;
};
struct nsSVGFrameReferenceFromProperty