зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1868049 - Use nsIMutationObserver's native callback optimisation mechanism r=emilio
Differential Revision: https://phabricator.services.mozilla.com/D195375
This commit is contained in:
Родитель
d70dc44cd5
Коммит
c0d1f6fce2
|
@ -50,6 +50,8 @@ SVGStyleElement::SVGStyleElement(
|
|||
already_AddRefed<mozilla::dom::NodeInfo>&& aNodeInfo)
|
||||
: SVGStyleElementBase(std::move(aNodeInfo)) {
|
||||
AddMutationObserver(this);
|
||||
SetEnabledCallbacks(kCharacterDataChanged | kContentAppended |
|
||||
kContentInserted | kContentRemoved);
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------
|
||||
|
|
|
@ -31,6 +31,8 @@ SVGTitleElement::SVGTitleElement(
|
|||
already_AddRefed<mozilla::dom::NodeInfo>&& aNodeInfo)
|
||||
: SVGTitleElementBase(std::move(aNodeInfo)) {
|
||||
AddMutationObserver(this);
|
||||
SetEnabledCallbacks(kCharacterDataChanged | kContentAppended |
|
||||
kContentInserted | kContentRemoved);
|
||||
}
|
||||
|
||||
void SVGTitleElement::CharacterDataChanged(nsIContent* aContent,
|
||||
|
|
|
@ -77,8 +77,11 @@ NS_IMPL_ISUPPORTS_CYCLE_COLLECTION_INHERITED(SVGUseElement, SVGUseElementBase,
|
|||
|
||||
SVGUseElement::SVGUseElement(
|
||||
already_AddRefed<mozilla::dom::NodeInfo>&& aNodeInfo)
|
||||
: SVGUseElementBase(std::move(aNodeInfo)),
|
||||
mReferencedElementTracker(this) {}
|
||||
: SVGUseElementBase(std::move(aNodeInfo)), mReferencedElementTracker(this) {
|
||||
SetEnabledCallbacks(kCharacterDataChanged | kAttributeChanged |
|
||||
kContentAppended | kContentInserted | kContentRemoved |
|
||||
kNodeWillBeDestroyed);
|
||||
}
|
||||
|
||||
SVGUseElement::~SVGUseElement() {
|
||||
UnlinkSource();
|
||||
|
|
|
@ -282,28 +282,20 @@ void SVGRenderingObserver::AttributeChanged(dom::Element* aElement,
|
|||
// observers and ourselves for all attribute changes? For non-ID changes
|
||||
// surely that is unnecessary.
|
||||
|
||||
if (mFlags & OBSERVE_ATTRIBUTE_CHANGES) {
|
||||
OnRenderingChange();
|
||||
}
|
||||
OnRenderingChange();
|
||||
}
|
||||
|
||||
void SVGRenderingObserver::ContentAppended(nsIContent* aFirstNewContent) {
|
||||
if (mFlags & OBSERVE_CONTENT_CHANGES) {
|
||||
OnRenderingChange();
|
||||
}
|
||||
OnRenderingChange();
|
||||
}
|
||||
|
||||
void SVGRenderingObserver::ContentInserted(nsIContent* aChild) {
|
||||
if (mFlags & OBSERVE_CONTENT_CHANGES) {
|
||||
OnRenderingChange();
|
||||
}
|
||||
OnRenderingChange();
|
||||
}
|
||||
|
||||
void SVGRenderingObserver::ContentRemoved(nsIContent* aChild,
|
||||
nsIContent* aPreviousSibling) {
|
||||
if (mFlags & OBSERVE_CONTENT_CHANGES) {
|
||||
OnRenderingChange();
|
||||
}
|
||||
OnRenderingChange();
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -325,7 +317,8 @@ class SVGIDRenderingObserver : public SVGRenderingObserver {
|
|||
SVGIDRenderingObserver(
|
||||
URLAndReferrerInfo* aURI, nsIContent* aObservingContent,
|
||||
bool aReferenceImage,
|
||||
uint32_t aFlags = OBSERVE_ATTRIBUTE_CHANGES | OBSERVE_CONTENT_CHANGES,
|
||||
uint32_t aCallbacks = kAttributeChanged | kContentAppended |
|
||||
kContentInserted | kContentRemoved,
|
||||
TargetIsValidCallback aTargetIsValidCallback = nullptr);
|
||||
|
||||
void Traverse(nsCycleCollectionTraversalCallback* aCB);
|
||||
|
@ -422,9 +415,9 @@ class SVGIDRenderingObserver : public SVGRenderingObserver {
|
|||
*/
|
||||
SVGIDRenderingObserver::SVGIDRenderingObserver(
|
||||
URLAndReferrerInfo* aURI, nsIContent* aObservingContent,
|
||||
bool aReferenceImage, uint32_t aFlags,
|
||||
bool aReferenceImage, uint32_t aCallbacks,
|
||||
TargetIsValidCallback aTargetIsValidCallback)
|
||||
: SVGRenderingObserver(aFlags),
|
||||
: SVGRenderingObserver(aCallbacks),
|
||||
mObservedElementTracker(this),
|
||||
mObservingContent(aObservingContent->AsElement()),
|
||||
mTargetIsValidCallback(aTargetIsValidCallback) {
|
||||
|
@ -462,10 +455,11 @@ class SVGRenderingObserverProperty : public SVGIDRenderingObserver {
|
|||
|
||||
SVGRenderingObserverProperty(
|
||||
URLAndReferrerInfo* aURI, nsIFrame* aFrame, bool aReferenceImage,
|
||||
uint32_t aFlags = OBSERVE_ATTRIBUTE_CHANGES | OBSERVE_CONTENT_CHANGES,
|
||||
uint32_t aCallbacks = kAttributeChanged | kContentAppended |
|
||||
kContentInserted | kContentRemoved,
|
||||
TargetIsValidCallback aTargetIsValidCallback = nullptr)
|
||||
: SVGIDRenderingObserver(aURI, aFrame->GetContent(), aReferenceImage,
|
||||
aFlags, aTargetIsValidCallback),
|
||||
aCallbacks, aTargetIsValidCallback),
|
||||
mFrameReference(aFrame) {}
|
||||
|
||||
protected:
|
||||
|
@ -508,8 +502,7 @@ class SVGTextPathObserver final : public SVGRenderingObserverProperty {
|
|||
SVGTextPathObserver(URLAndReferrerInfo* aURI, nsIFrame* aFrame,
|
||||
bool aReferenceImage)
|
||||
: SVGRenderingObserverProperty(aURI, aFrame, aReferenceImage,
|
||||
OBSERVE_ATTRIBUTE_CHANGES,
|
||||
IsSVGGeometryElement) {}
|
||||
kAttributeChanged, IsSVGGeometryElement) {}
|
||||
|
||||
protected:
|
||||
void OnRenderingChange() override;
|
||||
|
@ -558,8 +551,7 @@ class SVGMPathObserver final : public SVGIDRenderingObserver {
|
|||
|
||||
SVGMPathObserver(URLAndReferrerInfo* aURI, SVGMPathElement* aElement)
|
||||
: SVGIDRenderingObserver(aURI, aElement, /* aReferenceImage = */ false,
|
||||
OBSERVE_ATTRIBUTE_CHANGES,
|
||||
IsSVGGeometryElement) {}
|
||||
kAttributeChanged, IsSVGGeometryElement) {}
|
||||
|
||||
protected:
|
||||
virtual ~SVGMPathObserver() = default; // non-public
|
||||
|
@ -584,9 +576,9 @@ class SVGMarkerObserver final : public SVGRenderingObserverProperty {
|
|||
public:
|
||||
SVGMarkerObserver(URLAndReferrerInfo* aURI, nsIFrame* aFrame,
|
||||
bool aReferenceImage)
|
||||
: SVGRenderingObserverProperty(
|
||||
aURI, aFrame, aReferenceImage,
|
||||
OBSERVE_ATTRIBUTE_CHANGES | OBSERVE_CONTENT_CHANGES) {}
|
||||
: SVGRenderingObserverProperty(aURI, aFrame, aReferenceImage,
|
||||
kAttributeChanged | kContentAppended |
|
||||
kContentInserted | kContentRemoved) {}
|
||||
|
||||
protected:
|
||||
void OnRenderingChange() override;
|
||||
|
@ -731,10 +723,10 @@ class SVGFilterObserver final : public SVGIDRenderingObserver {
|
|||
public:
|
||||
SVGFilterObserver(URLAndReferrerInfo* aURI, nsIContent* aObservingContent,
|
||||
SVGFilterObserverList* aFilterChainObserver)
|
||||
: SVGIDRenderingObserver(
|
||||
aURI, aObservingContent, false,
|
||||
OBSERVE_ATTRIBUTE_CHANGES | OBSERVE_CONTENT_CHANGES,
|
||||
IsSVGFilterElement),
|
||||
: SVGIDRenderingObserver(aURI, aObservingContent, false,
|
||||
kAttributeChanged | kContentAppended |
|
||||
kContentInserted | kContentRemoved,
|
||||
IsSVGFilterElement),
|
||||
mFilterObserverList(aFilterChainObserver) {}
|
||||
|
||||
void DetachFromChainObserver() { mFilterObserverList = nullptr; }
|
||||
|
@ -1039,9 +1031,9 @@ class SVGTemplateElementObserver : public SVGIDRenderingObserver {
|
|||
|
||||
SVGTemplateElementObserver(URLAndReferrerInfo* aURI, nsIFrame* aFrame,
|
||||
bool aReferenceImage)
|
||||
: SVGIDRenderingObserver(
|
||||
aURI, aFrame->GetContent(), aReferenceImage,
|
||||
OBSERVE_ATTRIBUTE_CHANGES | OBSERVE_CONTENT_CHANGES),
|
||||
: SVGIDRenderingObserver(aURI, aFrame->GetContent(), aReferenceImage,
|
||||
kAttributeChanged | kContentAppended |
|
||||
kContentInserted | kContentRemoved),
|
||||
mFrameReference(aFrame) {}
|
||||
|
||||
protected:
|
||||
|
|
|
@ -99,15 +99,14 @@ class SVGRenderingObserver : public nsStubMutationObserver {
|
|||
virtual ~SVGRenderingObserver() = default;
|
||||
|
||||
public:
|
||||
enum Flags : uint32_t {
|
||||
OBSERVE_ATTRIBUTE_CHANGES = 0x01,
|
||||
OBSERVE_CONTENT_CHANGES = 0x02
|
||||
};
|
||||
using Element = dom::Element;
|
||||
|
||||
SVGRenderingObserver(uint32_t aFlags = OBSERVE_ATTRIBUTE_CHANGES |
|
||||
OBSERVE_CONTENT_CHANGES)
|
||||
: mInObserverSet(false), mFlags(aFlags) {}
|
||||
SVGRenderingObserver(uint32_t aCallbacks = kAttributeChanged |
|
||||
kContentAppended |
|
||||
kContentInserted |
|
||||
kContentRemoved) {
|
||||
SetEnabledCallbacks(aCallbacks);
|
||||
}
|
||||
|
||||
// nsIMutationObserver
|
||||
NS_DECL_NSIMUTATIONOBSERVER_ATTRIBUTECHANGED
|
||||
|
@ -167,10 +166,7 @@ class SVGRenderingObserver : public nsStubMutationObserver {
|
|||
#endif
|
||||
|
||||
// Whether we're in our observed element's observer set at this time.
|
||||
bool mInObserverSet;
|
||||
|
||||
// Flags to control what changes we notify about.
|
||||
uint32_t mFlags;
|
||||
bool mInObserverSet = false;
|
||||
};
|
||||
|
||||
class SVGObserverUtils {
|
||||
|
|
|
@ -364,6 +364,9 @@ class SVGTextFrame final : public SVGDisplayContainerFrame {
|
|||
explicit MutationObserver(SVGTextFrame* aFrame) : mFrame(aFrame) {
|
||||
MOZ_ASSERT(mFrame, "MutationObserver needs a non-null frame");
|
||||
mFrame->GetContent()->AddMutationObserver(this);
|
||||
SetEnabledCallbacks(kCharacterDataChanged | kAttributeChanged |
|
||||
kContentAppended | kContentInserted |
|
||||
kContentRemoved);
|
||||
}
|
||||
|
||||
// nsISupports
|
||||
|
|
Загрузка…
Ссылка в новой задаче