From 04fc1721e01d4ed43ff79cb6e404b3614930a0de Mon Sep 17 00:00:00 2001 From: Dorel Luca Date: Mon, 3 Aug 2020 01:20:49 +0300 Subject: [PATCH] Backed out changeset 07a20e5f68e3 (bug 1524314) for Build bustage in dom/svg/DOMSVGPointList.h. a=backout --- dom/svg/DOMSVGLength.cpp | 46 +++++++++-- dom/svg/DOMSVGLength.h | 10 +-- dom/svg/DOMSVGLengthList.cpp | 28 +++++++ dom/svg/DOMSVGLengthList.h | 32 -------- dom/svg/DOMSVGNumber.cpp | 34 ++++++++- dom/svg/DOMSVGNumber.h | 10 +-- dom/svg/DOMSVGNumberList.cpp | 28 +++++++ dom/svg/DOMSVGNumberList.h | 32 -------- dom/svg/DOMSVGPathSeg.cpp | 31 +++++++- dom/svg/DOMSVGPathSeg.h | 13 +--- dom/svg/DOMSVGPathSegList.cpp | 26 +++++++ dom/svg/DOMSVGPathSegList.h | 32 +------- dom/svg/DOMSVGPoint.cpp | 34 ++++++++- dom/svg/DOMSVGPoint.h | 10 +-- dom/svg/DOMSVGPointList.cpp | 26 +++++++ dom/svg/DOMSVGPointList.h | 30 -------- dom/svg/DOMSVGTransform.cpp | 46 +++++++++-- dom/svg/DOMSVGTransform.h | 11 +-- dom/svg/DOMSVGTransformList.cpp | 27 +++++++ dom/svg/DOMSVGTransformList.h | 43 ----------- dom/svg/SVGAnimatedBoolean.cpp | 42 ++-------- dom/svg/SVGAnimatedBoolean.h | 1 - dom/svg/SVGAnimatedEnumeration.cpp | 42 ++-------- dom/svg/SVGAnimatedEnumeration.h | 1 - dom/svg/SVGAnimatedInteger.cpp | 36 ++------- dom/svg/SVGAnimatedInteger.h | 1 - dom/svg/SVGAnimatedIntegerPair.cpp | 66 +++++----------- dom/svg/SVGAnimatedIntegerPair.h | 1 - dom/svg/SVGAnimatedLength.cpp | 89 ++++++++++------------ dom/svg/SVGAnimatedLength.h | 5 +- dom/svg/SVGAnimatedNumber.cpp | 28 +------ dom/svg/SVGAnimatedNumber.h | 1 - dom/svg/SVGAnimatedNumberPair.cpp | 61 ++++----------- dom/svg/SVGAnimatedNumberPair.h | 1 - dom/svg/SVGAnimatedOrient.cpp | 6 +- dom/svg/SVGAnimatedPreserveAspectRatio.cpp | 66 ++++++---------- dom/svg/SVGAnimatedPreserveAspectRatio.h | 2 - dom/svg/SVGAnimatedViewBox.cpp | 56 +++++--------- dom/svg/SVGAnimatedViewBox.h | 1 - 39 files changed, 458 insertions(+), 597 deletions(-) diff --git a/dom/svg/DOMSVGLength.cpp b/dom/svg/DOMSVGLength.cpp index c690602a623d..1665ab37cf60 100644 --- a/dom/svg/DOMSVGLength.cpp +++ b/dom/svg/DOMSVGLength.cpp @@ -8,6 +8,7 @@ #include "DOMSVGLengthList.h" #include "DOMSVGAnimatedLengthList.h" +#include "mozAutoDocUpdate.h" #include "nsError.h" #include "nsMathUtils.h" #include "SVGAnimatedLength.h" @@ -59,6 +60,37 @@ NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(DOMSVGLength) NS_INTERFACE_MAP_ENTRY(nsISupports) NS_INTERFACE_MAP_END +//---------------------------------------------------------------------- +// Helper class: AutoChangeLengthNotifier +// Stack-based helper class to pair calls to WillChangeLengthList and +// DidChangeLengthList. +class MOZ_RAII AutoChangeLengthNotifier : public mozAutoDocUpdate { + public: + explicit AutoChangeLengthNotifier(DOMSVGLength* aLength) + : mozAutoDocUpdate(aLength->Element()->GetComposedDoc(), true), + mLength(aLength) { + MOZ_ASSERT(mLength, "Expecting non-null length"); + MOZ_ASSERT(mLength->HasOwner(), + "Expecting list to have an owner for notification"); + mEmptyOrOldValue = + mLength->Element()->WillChangeLengthList(mLength->mAttrEnum, *this); + } + + ~AutoChangeLengthNotifier() { + mLength->Element()->DidChangeLengthList(mLength->mAttrEnum, + mEmptyOrOldValue, *this); + // Null check mLength->mList, since DidChangeLengthList can run script, + // potentially removing mLength from its list. + if (mLength->mList && mLength->mList->IsAnimating()) { + mLength->Element()->AnimationNeedsResample(); + } + } + + private: + DOMSVGLength* const mLength; + nsAttrValue mEmptyOrOldValue; +}; + DOMSVGLength::DOMSVGLength(DOMSVGLengthList* aList, uint8_t aAttrEnum, uint32_t aListIndex, bool aIsAnimValItem) : mList(aList), @@ -217,7 +249,7 @@ void DOMSVGLength::SetValue(float aUserUnitValue, ErrorResult& aRv) { if (uuPerUnit > 0) { float newValue = aUserUnitValue / uuPerUnit; if (IsFinite(newValue)) { - AutoChangeLengthListNotifier notifier(this); + AutoChangeLengthNotifier notifier(this); InternalItem().SetValueAndUnit(newValue, InternalItem().GetUnit()); return; } @@ -254,7 +286,9 @@ void DOMSVGLength::SetValueInSpecifiedUnits(float aValue, ErrorResult& aRv) { } if (mVal) { - mVal->SetBaseValueInSpecifiedUnits(aValue, mSVGElement, true); + MOZ_ASSERT(mSVGElement); + mozAutoDocUpdate updateBatch(mSVGElement->GetComposedDoc(), true); + mVal->SetBaseValueInSpecifiedUnits(aValue, mSVGElement, true, updateBatch); return; } @@ -262,7 +296,7 @@ void DOMSVGLength::SetValueInSpecifiedUnits(float aValue, ErrorResult& aRv) { if (InternalItem().GetValueInCurrentUnits() == aValue) { return; } - AutoChangeLengthListNotifier notifier(this); + AutoChangeLengthNotifier notifier(this); InternalItem().SetValueInCurrentUnits(aValue); return; } @@ -289,7 +323,7 @@ void DOMSVGLength::SetValueAsString(const nsAString& aValue, ErrorResult& aRv) { if (InternalItem() == value) { return; } - AutoChangeLengthListNotifier notifier(this); + AutoChangeLengthNotifier notifier(this); InternalItem() = value; return; } @@ -339,7 +373,7 @@ void DOMSVGLength::NewValueSpecifiedUnits(uint16_t aUnit, float aValue, InternalItem().GetValueInCurrentUnits() == aValue) { return; } - AutoChangeLengthListNotifier notifier(this); + AutoChangeLengthNotifier notifier(this); InternalItem().SetValueAndUnit(aValue, uint8_t(aUnit)); return; } @@ -369,7 +403,7 @@ void DOMSVGLength::ConvertToSpecifiedUnits(uint16_t aUnit, ErrorResult& aRv) { float val = InternalItem().GetValueInSpecifiedUnit(aUnit, Element(), Axis()); if (IsFinite(val)) { - AutoChangeLengthListNotifier notifier(this); + AutoChangeLengthNotifier notifier(this); InternalItem().SetValueAndUnit(val, aUnit); return; } diff --git a/dom/svg/DOMSVGLength.h b/dom/svg/DOMSVGLength.h index 18399ef47fd2..fff84e865357 100644 --- a/dom/svg/DOMSVGLength.h +++ b/dom/svg/DOMSVGLength.h @@ -79,10 +79,7 @@ class SVGElement; * https://bugzilla.mozilla.org/show_bug.cgi?id=571734 */ class DOMSVGLength final : public nsISupports, public nsWrapperCache { - template - friend class AutoChangeLengthListNotifier; - using AutoChangeLengthListNotifier = - AutoChangeLengthListNotifier; + friend class AutoChangeLengthNotifier; /** * Ctor for creating the object returned by @@ -122,11 +119,6 @@ class DOMSVGLength final : public nsISupports, public nsWrapperCache { bool IsInList() const { return !!mList; } - /** - * Returns true if our attribute is animating. - */ - bool IsAnimating() const { return mList && mList->IsAnimating(); } - /** * In future, if this class is used for non-list lengths, this will be * different to IsInList(). diff --git a/dom/svg/DOMSVGLengthList.cpp b/dom/svg/DOMSVGLengthList.cpp index 9cb9268427c0..b4642930cf7d 100644 --- a/dom/svg/DOMSVGLengthList.cpp +++ b/dom/svg/DOMSVGLengthList.cpp @@ -8,6 +8,7 @@ #include "SVGElement.h" #include "DOMSVGLength.h" +#include "mozAutoDocUpdate.h" #include "nsError.h" #include "SVGAnimatedLengthList.h" #include "nsCOMPtr.h" @@ -81,6 +82,33 @@ JSObject* DOMSVGLengthList::WrapObject(JSContext* cx, return mozilla::dom::SVGLengthList_Binding::Wrap(cx, this, aGivenProto); } +//---------------------------------------------------------------------- +// Helper class: AutoChangeLengthListNotifier +// Stack-based helper class to pair calls to WillChangeLengthList and +// DidChangeLengthList. +class MOZ_RAII AutoChangeLengthListNotifier : public mozAutoDocUpdate { + public: + explicit AutoChangeLengthListNotifier(DOMSVGLengthList* aLengthList) + : mozAutoDocUpdate(aLengthList->Element()->GetComposedDoc(), true), + mLengthList(aLengthList) { + MOZ_ASSERT(mLengthList, "Expecting non-null lengthList"); + mEmptyOrOldValue = mLengthList->Element()->WillChangeLengthList( + mLengthList->AttrEnum(), *this); + } + + ~AutoChangeLengthListNotifier() { + mLengthList->Element()->DidChangeLengthList(mLengthList->AttrEnum(), + mEmptyOrOldValue, *this); + if (mLengthList->IsAnimating()) { + mLengthList->Element()->AnimationNeedsResample(); + } + } + + private: + DOMSVGLengthList* const mLengthList; + nsAttrValue mEmptyOrOldValue; +}; + void DOMSVGLengthList::InternalListLengthWillChange(uint32_t aNewLength) { uint32_t oldLength = mItems.Length(); diff --git a/dom/svg/DOMSVGLengthList.h b/dom/svg/DOMSVGLengthList.h index d7aae58c0df6..a0d7699dd1c8 100644 --- a/dom/svg/DOMSVGLengthList.h +++ b/dom/svg/DOMSVGLengthList.h @@ -8,7 +8,6 @@ #define DOM_SVG_DOMSVGLENGTHLIST_H_ #include "DOMSVGAnimatedLengthList.h" -#include "mozAutoDocUpdate.h" #include "nsCycleCollectionParticipant.h" #include "nsDebug.h" #include "nsTArray.h" @@ -23,34 +22,6 @@ namespace dom { class DOMSVGLength; class SVGElement; -//---------------------------------------------------------------------- -// Helper class: AutoChangeLengthListNotifier -// Stack-based helper class to pair calls to WillChangeLengthList and -// DidChangeLengthList. Used by DOMSVGLength and DOMSVGLengthList. -template -class MOZ_RAII AutoChangeLengthListNotifier : public mozAutoDocUpdate { - public: - explicit AutoChangeLengthListNotifier(T* aValue) - : mozAutoDocUpdate(aValue->Element()->GetComposedDoc(), true), - mValue(aValue) { - MOZ_ASSERT(aValue, "Expecting non-null value"); - mEmptyOrOldValue = - mValue->Element()->WillChangeLengthList(mValue->AttrEnum(), *this); - } - - ~AutoChangeLengthListNotifier() { - mValue->Element()->DidChangeLengthList(mValue->AttrEnum(), mEmptyOrOldValue, - *this); - if (mValue->IsAnimating()) { - mValue->Element()->AnimationNeedsResample(); - } - } - - private: - T* const mValue; - nsAttrValue mEmptyOrOldValue; -}; - /** * Class DOMSVGLengthList * @@ -69,11 +40,8 @@ class MOZ_RAII AutoChangeLengthListNotifier : public mozAutoDocUpdate { * Our DOM items are created lazily on demand as and when script requests them. */ class DOMSVGLengthList final : public nsISupports, public nsWrapperCache { - template friend class AutoChangeLengthListNotifier; friend class DOMSVGLength; - using AutoChangeLengthListNotifier = - AutoChangeLengthListNotifier; ~DOMSVGLengthList() { // Our mAList's weak ref to us must be nulled out when we die. If GC has diff --git a/dom/svg/DOMSVGNumber.cpp b/dom/svg/DOMSVGNumber.cpp index 6e8235e9fd64..ed66a76bdbad 100644 --- a/dom/svg/DOMSVGNumber.cpp +++ b/dom/svg/DOMSVGNumber.cpp @@ -9,6 +9,7 @@ #include "DOMSVGAnimatedNumberList.h" #include "SVGAnimatedNumberList.h" #include "SVGElement.h" +#include "mozAutoDocUpdate.h" #include "nsError.h" #include "nsContentUtils.h" // for NS_ENSURE_FINITE #include "mozilla/dom/SVGNumberBinding.h" @@ -50,6 +51,37 @@ NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(DOMSVGNumber) NS_INTERFACE_MAP_ENTRY(nsISupports) NS_INTERFACE_MAP_END +//---------------------------------------------------------------------- +// Helper class: AutoChangeNumberNotifier +// Stack-based helper class to pair calls to WillChangeNumberList and +// DidChangeNumberList. +class MOZ_RAII AutoChangeNumberNotifier : public mozAutoDocUpdate { + public: + explicit AutoChangeNumberNotifier(DOMSVGNumber* aNumber) + : mozAutoDocUpdate(aNumber->Element()->GetComposedDoc(), true), + mNumber(aNumber) { + MOZ_ASSERT(mNumber, "Expecting non-null number"); + MOZ_ASSERT(mNumber->HasOwner(), + "Expecting list to have an owner for notification"); + mEmptyOrOldValue = + mNumber->Element()->WillChangeNumberList(mNumber->mAttrEnum, *this); + } + + ~AutoChangeNumberNotifier() { + mNumber->Element()->DidChangeNumberList(mNumber->mAttrEnum, + mEmptyOrOldValue, *this); + // Null check mNumber->mList, since DidChangeNumberList can run script, + // potentially removing mNumber from its list. + if (mNumber->mList && mNumber->mList->IsAnimating()) { + mNumber->Element()->AnimationNeedsResample(); + } + } + + private: + DOMSVGNumber* const mNumber; + nsAttrValue mEmptyOrOldValue; +}; + DOMSVGNumber::DOMSVGNumber(DOMSVGNumberList* aList, uint8_t aAttrEnum, uint32_t aListIndex, bool aIsAnimValItem) : mList(aList), @@ -98,7 +130,7 @@ void DOMSVGNumber::SetValue(float aValue, ErrorResult& aRv) { if (InternalItem() == aValue) { return; } - AutoChangeNumberListNotifier notifier(this); + AutoChangeNumberNotifier notifier(this); InternalItem() = aValue; return; } diff --git a/dom/svg/DOMSVGNumber.h b/dom/svg/DOMSVGNumber.h index fef6728d7027..50c66e9228fc 100644 --- a/dom/svg/DOMSVGNumber.h +++ b/dom/svg/DOMSVGNumber.h @@ -38,10 +38,7 @@ class SVGSVGElement; * See the comment in DOMSVGLength.h (yes, LENGTH), which applies here too. */ class DOMSVGNumber final : public nsISupports, public nsWrapperCache { - template - friend class AutoChangeNumberListNotifier; - using AutoChangeNumberListNotifier = - AutoChangeNumberListNotifier; + friend class AutoChangeNumberNotifier; ~DOMSVGNumber() { // Our mList's weak ref to us must be nulled out when we die. If GC has @@ -83,11 +80,6 @@ class DOMSVGNumber final : public nsISupports, public nsWrapperCache { bool IsInList() const { return !!mList; } - /** - * Returns true if our attribute is animating. - */ - bool IsAnimating() const { return mList && mList->IsAnimating(); } - /** * In future, if this class is used for non-list numbers, this will be * different to IsInList(). diff --git a/dom/svg/DOMSVGNumberList.cpp b/dom/svg/DOMSVGNumberList.cpp index ddd909fdb1a7..9d630e1fc44c 100644 --- a/dom/svg/DOMSVGNumberList.cpp +++ b/dom/svg/DOMSVGNumberList.cpp @@ -8,6 +8,7 @@ #include "SVGElement.h" #include "DOMSVGNumber.h" +#include "mozAutoDocUpdate.h" #include "nsError.h" #include "SVGAnimatedNumberList.h" #include "mozilla/dom/SVGNumberListBinding.h" @@ -74,6 +75,33 @@ JSObject* DOMSVGNumberList::WrapObject(JSContext* cx, return mozilla::dom::SVGNumberList_Binding::Wrap(cx, this, aGivenProto); } +//---------------------------------------------------------------------- +// Helper class: AutoChangeNumberListNotifier +// Stack-based helper class to pair calls to WillChangeNumberList and +// DidChangeNumberList. +class MOZ_RAII AutoChangeNumberListNotifier : public mozAutoDocUpdate { + public: + explicit AutoChangeNumberListNotifier(DOMSVGNumberList* aNumberList) + : mozAutoDocUpdate(aNumberList->Element()->GetComposedDoc(), true), + mNumberList(aNumberList) { + MOZ_ASSERT(mNumberList, "Expecting non-null numberList"); + mEmptyOrOldValue = mNumberList->Element()->WillChangeNumberList( + mNumberList->AttrEnum(), *this); + } + + ~AutoChangeNumberListNotifier() { + mNumberList->Element()->DidChangeNumberList(mNumberList->AttrEnum(), + mEmptyOrOldValue, *this); + if (mNumberList->IsAnimating()) { + mNumberList->Element()->AnimationNeedsResample(); + } + } + + private: + DOMSVGNumberList* const mNumberList; + nsAttrValue mEmptyOrOldValue; +}; + void DOMSVGNumberList::InternalListLengthWillChange(uint32_t aNewLength) { uint32_t oldLength = mItems.Length(); diff --git a/dom/svg/DOMSVGNumberList.h b/dom/svg/DOMSVGNumberList.h index 69c0420ccb34..625d02240e2c 100644 --- a/dom/svg/DOMSVGNumberList.h +++ b/dom/svg/DOMSVGNumberList.h @@ -8,7 +8,6 @@ #define DOM_SVG_DOMSVGNUMBERLIST_H_ #include "DOMSVGAnimatedNumberList.h" -#include "mozAutoDocUpdate.h" #include "nsCycleCollectionParticipant.h" #include "nsDebug.h" #include "nsTArray.h" @@ -23,34 +22,6 @@ namespace dom { class DOMSVGNumber; class SVGElement; -//---------------------------------------------------------------------- -// Helper class: AutoChangeNumberListNotifier -// Stack-based helper class to pair calls to WillChangeNumberList and -// DidChangeNumberList. Used by DOMSVGNumber and DOMSVGNumberList. -template -class MOZ_RAII AutoChangeNumberListNotifier : public mozAutoDocUpdate { - public: - explicit AutoChangeNumberListNotifier(T* aValue) - : mozAutoDocUpdate(aValue->Element()->GetComposedDoc(), true), - mValue(aValue) { - MOZ_ASSERT(mValue, "Expecting non-null value"); - mEmptyOrOldValue = - mValue->Element()->WillChangeNumberList(mValue->AttrEnum(), *this); - } - - ~AutoChangeNumberListNotifier() { - mValue->Element()->DidChangeNumberList(mValue->AttrEnum(), mEmptyOrOldValue, - *this); - if (mValue->IsAnimating()) { - mValue->Element()->AnimationNeedsResample(); - } - } - - private: - T* const mValue; - nsAttrValue mEmptyOrOldValue; -}; - /** * Class DOMSVGNumberList * @@ -69,11 +40,8 @@ class MOZ_RAII AutoChangeNumberListNotifier : public mozAutoDocUpdate { * Our DOM items are created lazily on demand as and when script requests them. */ class DOMSVGNumberList final : public nsISupports, public nsWrapperCache { - template friend class AutoChangeNumberListNotifier; friend class DOMSVGNumber; - using AutoChangeNumberListNotifier = - AutoChangeNumberListNotifier; ~DOMSVGNumberList() { // Our mAList's weak ref to us must be nulled out when we die. If GC has diff --git a/dom/svg/DOMSVGPathSeg.cpp b/dom/svg/DOMSVGPathSeg.cpp index 80b72730dc1c..dd78b10b9514 100644 --- a/dom/svg/DOMSVGPathSeg.cpp +++ b/dom/svg/DOMSVGPathSeg.cpp @@ -44,6 +44,35 @@ NS_IMPL_CYCLE_COLLECTION_TRACE_END NS_IMPL_CYCLE_COLLECTION_ROOT_NATIVE(DOMSVGPathSeg, AddRef) NS_IMPL_CYCLE_COLLECTION_UNROOT_NATIVE(DOMSVGPathSeg, Release) +//---------------------------------------------------------------------- +// Helper class: AutoChangePathSegNotifier +// Stack-based helper class to pair calls to WillChangePathSegList +// and DidChangePathSegList. +class MOZ_RAII AutoChangePathSegNotifier : public mozAutoDocUpdate { + public: + explicit AutoChangePathSegNotifier(DOMSVGPathSeg* aPathSeg) + : mozAutoDocUpdate(aPathSeg->Element()->GetComposedDoc(), true), + mPathSeg(aPathSeg) { + MOZ_ASSERT(mPathSeg, "Expecting non-null pathSeg"); + MOZ_ASSERT(mPathSeg->HasOwner(), + "Expecting list to have an owner for notification"); + mEmptyOrOldValue = mPathSeg->Element()->WillChangePathSegList(*this); + } + + ~AutoChangePathSegNotifier() { + mPathSeg->Element()->DidChangePathSegList(mEmptyOrOldValue, *this); + // Null check mPathSeg->mList, since DidChangePathSegList can run script, + // potentially removing mPathSeg from its list. + if (mPathSeg->mList && mPathSeg->mList->AttrIsAnimating()) { + mPathSeg->Element()->AnimationNeedsResample(); + } + } + + private: + DOMSVGPathSeg* const mPathSeg; + nsAttrValue mEmptyOrOldValue; +}; + DOMSVGPathSeg::DOMSVGPathSeg(DOMSVGPathSegList* aList, uint32_t aListIndex, bool aIsAnimValItem) : mList(aList), mListIndex(aListIndex), mIsAnimValItem(aIsAnimValItem) { @@ -122,7 +151,7 @@ bool DOMSVGPathSeg::IndexIsValid() { if (InternalItem()[1 + index] == float(a##propName)) { \ return; \ } \ - AutoChangePathSegListNotifier notifier(this); \ + AutoChangePathSegNotifier notifier(this); \ InternalItem()[1 + index] = float(a##propName); \ } else { \ mArgs[index] = float(a##propName); \ diff --git a/dom/svg/DOMSVGPathSeg.h b/dom/svg/DOMSVGPathSeg.h index dc401ba99081..9e7aaed4b21c 100644 --- a/dom/svg/DOMSVGPathSeg.h +++ b/dom/svg/DOMSVGPathSeg.h @@ -72,12 +72,7 @@ class SVGElement; * DOM wrapper for is a list of floats, not an instance of an internal class. */ class DOMSVGPathSeg : public nsWrapperCache { - template - friend class AutoChangePathSegListNotifier; - - protected: - using AutoChangePathSegListNotifier = - AutoChangePathSegListNotifier; + friend class AutoChangePathSegNotifier; public: NS_INLINE_DECL_CYCLE_COLLECTING_NATIVE_REFCOUNTING(DOMSVGPathSeg) @@ -99,12 +94,6 @@ class DOMSVGPathSeg : public nsWrapperCache { bool IsInList() const { return !!mList; } - /** - * Returns true if our attribute is animating (in which case our animVal is - * not simply a mirror of our baseVal). - */ - bool AttrIsAnimating() const { return mList && mList->AttrIsAnimating(); } - /** * In future, if this class is used for non-list segments, this will be * different to IsInList(). diff --git a/dom/svg/DOMSVGPathSegList.cpp b/dom/svg/DOMSVGPathSegList.cpp index c2bb57d9dabb..efb17491367e 100644 --- a/dom/svg/DOMSVGPathSegList.cpp +++ b/dom/svg/DOMSVGPathSegList.cpp @@ -7,6 +7,7 @@ #include "DOMSVGPathSegList.h" #include "DOMSVGPathSeg.h" +#include "mozAutoDocUpdate.h" #include "nsError.h" #include "SVGAnimatedPathSegList.h" #include "SVGAttrTearoffTable.h" @@ -50,6 +51,31 @@ NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(DOMSVGPathSegList) NS_INTERFACE_MAP_ENTRY(nsISupports) NS_INTERFACE_MAP_END +//---------------------------------------------------------------------- +// Helper class: AutoChangePathSegListNotifier +// Stack-based helper class to pair calls to WillChangePathSegList and +// DidChangePathSegList. +class MOZ_RAII AutoChangePathSegListNotifier : public mozAutoDocUpdate { + public: + explicit AutoChangePathSegListNotifier(DOMSVGPathSegList* aPathSegList) + : mozAutoDocUpdate(aPathSegList->Element()->GetComposedDoc(), true), + mPathSegList(aPathSegList) { + MOZ_ASSERT(mPathSegList, "Expecting non-null pathSegList"); + mEmptyOrOldValue = mPathSegList->Element()->WillChangePathSegList(*this); + } + + ~AutoChangePathSegListNotifier() { + mPathSegList->Element()->DidChangePathSegList(mEmptyOrOldValue, *this); + if (mPathSegList->AttrIsAnimating()) { + mPathSegList->Element()->AnimationNeedsResample(); + } + } + + private: + DOMSVGPathSegList* const mPathSegList; + nsAttrValue mEmptyOrOldValue; +}; + /* static */ already_AddRefed DOMSVGPathSegList::GetDOMWrapper( void* aList, SVGElement* aElement, bool aIsAnimValList) { diff --git a/dom/svg/DOMSVGPathSegList.h b/dom/svg/DOMSVGPathSegList.h index bd921e7ce986..b73a177aefb7 100644 --- a/dom/svg/DOMSVGPathSegList.h +++ b/dom/svg/DOMSVGPathSegList.h @@ -7,15 +7,14 @@ #ifndef DOM_SVG_DOMSVGPATHSEGLIST_H_ #define DOM_SVG_DOMSVGPATHSEGLIST_H_ -#include "mozAutoDocUpdate.h" #include "nsCycleCollectionParticipant.h" #include "nsDebug.h" +#include "SVGElement.h" #include "nsTArray.h" #include "SVGPathData.h" // IWYU pragma: keep #include "mozilla/Attributes.h" #include "mozilla/ErrorResult.h" #include "mozilla/RefPtr.h" -#include "mozilla/dom/SVGElement.h" namespace mozilla { @@ -25,32 +24,6 @@ namespace dom { class DOMSVGPathSeg; -//---------------------------------------------------------------------- -// Helper class: AutoChangePathSegListNotifier -// Stack-based helper class to pair calls to WillChangePathSegList and -// DidChangePathSegList. Used by DOMSVGPathSeg and DOMSVGPathSegList. -template -class MOZ_RAII AutoChangePathSegListNotifier : public mozAutoDocUpdate { - public: - explicit AutoChangePathSegListNotifier(T* aValue) - : mozAutoDocUpdate(aValue->Element()->GetComposedDoc(), true), - mValue(aValue) { - MOZ_ASSERT(mValue, "Expecting non-null value"); - mEmptyOrOldValue = mValue->Element()->WillChangePathSegList(*this); - } - - ~AutoChangePathSegListNotifier() { - mValue->Element()->DidChangePathSegList(mEmptyOrOldValue, *this); - if (mValue->AttrIsAnimating()) { - mValue->Element()->AnimationNeedsResample(); - } - } - - private: - T* const mValue; - nsAttrValue mEmptyOrOldValue; -}; - /** * Class DOMSVGPathSegList * @@ -77,11 +50,8 @@ class MOZ_RAII AutoChangePathSegListNotifier : public mozAutoDocUpdate { * Our DOM items are created lazily on demand as and when script requests them. */ class DOMSVGPathSegList final : public nsISupports, public nsWrapperCache { - template friend class AutoChangePathSegListNotifier; friend class DOMSVGPathSeg; - using AutoChangePathSegListNotifier = - AutoChangePathSegListNotifier; public: NS_DECL_CYCLE_COLLECTING_ISUPPORTS diff --git a/dom/svg/DOMSVGPoint.cpp b/dom/svg/DOMSVGPoint.cpp index 7e00b7425b6d..c6c3139335d8 100644 --- a/dom/svg/DOMSVGPoint.cpp +++ b/dom/svg/DOMSVGPoint.cpp @@ -8,6 +8,7 @@ #include "DOMSVGPointList.h" #include "gfx2DGlue.h" +#include "mozAutoDocUpdate.h" #include "nsCOMPtr.h" #include "nsError.h" #include "SVGPoint.h" @@ -21,6 +22,35 @@ using namespace mozilla::gfx; namespace mozilla { namespace dom { +//---------------------------------------------------------------------- +// Helper class: AutoChangePointNotifier +// Stack-based helper class to pair calls to WillChangePointList and +// DidChangePointList. +class MOZ_RAII AutoChangePointNotifier : public mozAutoDocUpdate { + public: + explicit AutoChangePointNotifier(DOMSVGPoint* aPoint) + : mozAutoDocUpdate(aPoint->Element()->GetComposedDoc(), true), + mPoint(aPoint) { + MOZ_ASSERT(mPoint, "Expecting non-null point"); + MOZ_ASSERT(mPoint->HasOwner(), + "Expecting list to have an owner for notification"); + mEmptyOrOldValue = mPoint->Element()->WillChangePointList(*this); + } + + ~AutoChangePointNotifier() { + mPoint->Element()->DidChangePointList(mEmptyOrOldValue, *this); + // Null check mPoint->mList, since DidChangePointList can run script, + // potentially removing mPoint from its list. + if (mPoint->mList && mPoint->mList->AttrIsAnimating()) { + mPoint->Element()->AnimationNeedsResample(); + } + } + + private: + DOMSVGPoint* const mPoint; + nsAttrValue mEmptyOrOldValue; +}; + float DOMSVGPoint::X() { if (mIsAnimValItem && HasOwner()) { Element()->FlushAnimations(); // May make HasOwner() == false @@ -38,7 +68,7 @@ void DOMSVGPoint::SetX(float aX, ErrorResult& rv) { if (InternalItem().mX == aX) { return; } - AutoChangePointListNotifier notifier(this); + AutoChangePointNotifier notifier(this); InternalItem().mX = aX; return; } @@ -62,7 +92,7 @@ void DOMSVGPoint::SetY(float aY, ErrorResult& rv) { if (InternalItem().mY == aY) { return; } - AutoChangePointListNotifier notifier(this); + AutoChangePointNotifier notifier(this); InternalItem().mY = aY; return; } diff --git a/dom/svg/DOMSVGPoint.h b/dom/svg/DOMSVGPoint.h index 32bfdcfd8966..eb1bd3d3cd9b 100644 --- a/dom/svg/DOMSVGPoint.h +++ b/dom/svg/DOMSVGPoint.h @@ -36,10 +36,8 @@ class SVGElement; * of the important points regarding how this specific class works. */ class DOMSVGPoint final : public nsISVGPoint { - template - friend class AutoChangePointListNotifier; + friend class AutoChangePointNotifier; - using AutoChangePointListNotifier = AutoChangePointListNotifier; using Point = gfx::Point; public: @@ -80,12 +78,6 @@ class DOMSVGPoint final : public nsISVGPoint { const DOMMatrix2DInit& aMatrix, ErrorResult& aRv) override; nsISupports* GetParentObject() override { return mList; } - /** - * Returns true if our attribute is animating (in which case our animVal is - * not simply a mirror of our baseVal). - */ - bool AttrIsAnimating() const { return mList && mList->AttrIsAnimating(); } - virtual DOMSVGPoint* Copy() override { return new DOMSVGPoint(this); } protected: diff --git a/dom/svg/DOMSVGPointList.cpp b/dom/svg/DOMSVGPointList.cpp index 5e5be83323d3..262601a8bf46 100644 --- a/dom/svg/DOMSVGPointList.cpp +++ b/dom/svg/DOMSVGPointList.cpp @@ -12,6 +12,7 @@ #include "nsError.h" #include "SVGAnimatedPointList.h" #include "SVGAttrTearoffTable.h" +#include "mozAutoDocUpdate.h" #include "mozilla/dom/SVGElement.h" #include "mozilla/dom/SVGPointListBinding.h" #include @@ -67,6 +68,31 @@ NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(DOMSVGPointList) NS_INTERFACE_MAP_ENTRY(nsISupports) NS_INTERFACE_MAP_END +//---------------------------------------------------------------------- +// Helper class: AutoChangePointListNotifier +// Stack-based helper class to pair calls to WillChangePointList and +// DidChangePointList. +class MOZ_RAII AutoChangePointListNotifier : public mozAutoDocUpdate { + public: + explicit AutoChangePointListNotifier(DOMSVGPointList* aPointList) + : mozAutoDocUpdate(aPointList->Element()->GetComposedDoc(), true), + mPointList(aPointList) { + MOZ_ASSERT(mPointList, "Expecting non-null pointList"); + mEmptyOrOldValue = mPointList->Element()->WillChangePointList(*this); + } + + ~AutoChangePointListNotifier() { + mPointList->Element()->DidChangePointList(mEmptyOrOldValue, *this); + if (mPointList->AttrIsAnimating()) { + mPointList->Element()->AnimationNeedsResample(); + } + } + + private: + DOMSVGPointList* const mPointList; + nsAttrValue mEmptyOrOldValue; +}; + /* static */ already_AddRefed DOMSVGPointList::GetDOMWrapper( void* aList, SVGElement* aElement, bool aIsAnimValList) { diff --git a/dom/svg/DOMSVGPointList.h b/dom/svg/DOMSVGPointList.h index b94370755d57..7b629aad6dba 100644 --- a/dom/svg/DOMSVGPointList.h +++ b/dom/svg/DOMSVGPointList.h @@ -7,7 +7,6 @@ #ifndef DOM_SVG_DOMSVGPOINTLIST_H_ #define DOM_SVG_DOMSVGPOINTLIST_H_ -#include "mozAutoDocUpdate.h" #include "nsCycleCollectionParticipant.h" #include "nsDebug.h" #include "SVGElement.h" @@ -26,32 +25,6 @@ namespace dom { class DOMSVGPoint; class nsISVGPoint; -//---------------------------------------------------------------------- -// Helper class: AutoChangePointListNotifier -// Stack-based helper class to pair calls to WillChangePointList and -// DidChangePointList. Used by DOMSVGPoint and DOMSVGPointList. -template -class MOZ_RAII AutoChangePointListNotifier : public mozAutoDocUpdate { - public: - explicit AutoChangePointListNotifier(T* aValue) - : mozAutoDocUpdate(aValue->Element()->GetComposedDoc(), true), - mValue(aValue) { - MOZ_ASSERT(mValue, "Expecting non-null value"); - mEmptyOrOldValue = mValue->Element()->WillChangePointList(*this); - } - - ~AutoChangePointListNotifier() { - mValue->Element()->DidChangePointList(mEmptyOrOldValue, *this); - if (mValue->AttrIsAnimating()) { - mValue->Element()->AnimationNeedsResample(); - } - } - - private: - T* const mValue; - nsAttrValue mEmptyOrOldValue; -}; - /** * Class DOMSVGPointList * @@ -78,12 +51,9 @@ class MOZ_RAII AutoChangePointListNotifier : public mozAutoDocUpdate { * Our DOM items are created lazily on demand as and when script requests them. */ class DOMSVGPointList final : public nsISupports, public nsWrapperCache { - template friend class AutoChangePointListNotifier; friend class nsISVGPoint; friend class DOMSVGPoint; - using AutoChangePointListNotifier = - AutoChangePointListNotifier; public: NS_DECL_CYCLE_COLLECTING_ISUPPORTS diff --git a/dom/svg/DOMSVGTransform.cpp b/dom/svg/DOMSVGTransform.cpp index 1010cfe11257..6deec0ceb762 100644 --- a/dom/svg/DOMSVGTransform.cpp +++ b/dom/svg/DOMSVGTransform.cpp @@ -68,6 +68,40 @@ JSObject* DOMSVGTransform::WrapObject(JSContext* aCx, return SVGTransform_Binding::Wrap(aCx, this, aGivenProto); } +//---------------------------------------------------------------------- +// Helper class: AutoChangeTransformNotifier +// Stack-based helper class to pair calls to WillChangeTransformList +// and DidChangeTransformList. +class MOZ_RAII AutoChangeTransformNotifier { + public: + explicit AutoChangeTransformNotifier(DOMSVGTransform* aTransform) + : mTransform(aTransform) { + MOZ_ASSERT(mTransform, "Expecting non-null transform"); + if (mTransform->HasOwner()) { + mUpdateBatch.emplace(mTransform->Element()->GetComposedDoc(), true); + mEmptyOrOldValue = + mTransform->Element()->WillChangeTransformList(mUpdateBatch.ref()); + } + } + + ~AutoChangeTransformNotifier() { + if (mTransform->HasOwner()) { + mTransform->Element()->DidChangeTransformList(mEmptyOrOldValue, + mUpdateBatch.ref()); + // Null check mTransform->mList, since DidChangeTransformList can run + // script, potentially removing mTransform from its list. + if (mTransform->mList && mTransform->mList->IsAnimating()) { + mTransform->Element()->AnimationNeedsResample(); + } + } + } + + private: + Maybe mUpdateBatch; + DOMSVGTransform* const mTransform; + nsAttrValue mEmptyOrOldValue; +}; + //---------------------------------------------------------------------- // Ctors: @@ -170,7 +204,7 @@ void DOMSVGTransform::SetTranslate(float tx, float ty, ErrorResult& rv) { return; } - AutoChangeTransformListNotifier notifier(this); + AutoChangeTransformNotifier notifier(this); Transform().SetTranslate(tx, ty); } @@ -184,7 +218,7 @@ void DOMSVGTransform::SetScale(float sx, float sy, ErrorResult& rv) { Matrixgfx()._22 == sy) { return; } - AutoChangeTransformListNotifier notifier(this); + AutoChangeTransformNotifier notifier(this); Transform().SetScale(sx, sy); } @@ -203,7 +237,7 @@ void DOMSVGTransform::SetRotate(float angle, float cx, float cy, } } - AutoChangeTransformListNotifier notifier(this); + AutoChangeTransformNotifier notifier(this); Transform().SetRotate(angle, cx, cy); } @@ -223,7 +257,7 @@ void DOMSVGTransform::SetSkewX(float angle, ErrorResult& rv) { return; } - AutoChangeTransformListNotifier notifier(this); + AutoChangeTransformNotifier notifier(this); DebugOnly result = Transform().SetSkewX(angle); MOZ_ASSERT(NS_SUCCEEDED(result), "SetSkewX unexpectedly failed"); } @@ -244,7 +278,7 @@ void DOMSVGTransform::SetSkewY(float angle, ErrorResult& rv) { return; } - AutoChangeTransformListNotifier notifier(this); + AutoChangeTransformNotifier notifier(this); DebugOnly result = Transform().SetSkewY(angle); MOZ_ASSERT(NS_SUCCEEDED(result), "SetSkewY unexpectedly failed"); } @@ -303,7 +337,7 @@ void DOMSVGTransform::SetMatrix(const gfxMatrix& aMatrix) { return; } - AutoChangeTransformListNotifier notifier(this); + AutoChangeTransformNotifier notifier(this); Transform().SetMatrix(aMatrix); } diff --git a/dom/svg/DOMSVGTransform.h b/dom/svg/DOMSVGTransform.h index 1b7280b893c5..a69502fd77ee 100644 --- a/dom/svg/DOMSVGTransform.h +++ b/dom/svg/DOMSVGTransform.h @@ -30,10 +30,7 @@ class SVGMatrix; * DOM wrapper for an SVG transform. See DOMSVGLength.h. */ class DOMSVGTransform final : public nsWrapperCache { - template - friend class AutoChangeTransformListNotifier; - using AutoChangeTransformListNotifier = - AutoChangeTransformListNotifier; + friend class AutoChangeTransformNotifier; public: NS_INLINE_DECL_CYCLE_COLLECTING_NATIVE_REFCOUNTING(DOMSVGTransform) @@ -72,12 +69,6 @@ class DOMSVGTransform final : public nsWrapperCache { bool IsInList() const { return !!mList; } - /** - * Returns true if our attribute is animating (in which case our animVal is - * not simply a mirror of our baseVal). - */ - bool IsAnimating() const { return mList && mList->IsAnimating(); } - /** * In future, if this class is used for non-list transforms, this will be * different to IsInList(). diff --git a/dom/svg/DOMSVGTransformList.cpp b/dom/svg/DOMSVGTransformList.cpp index 8a2777036f95..405f195447db 100644 --- a/dom/svg/DOMSVGTransformList.cpp +++ b/dom/svg/DOMSVGTransformList.cpp @@ -6,6 +6,7 @@ #include "DOMSVGTransformList.h" +#include "mozAutoDocUpdate.h" #include "mozilla/dom/SVGElement.h" #include "mozilla/dom/SVGMatrix.h" #include "mozilla/dom/SVGTransformListBinding.h" @@ -74,6 +75,32 @@ JSObject* DOMSVGTransformList::WrapObject(JSContext* cx, return mozilla::dom::SVGTransformList_Binding::Wrap(cx, this, aGivenProto); } +//---------------------------------------------------------------------- +// Helper class: AutoChangeTransformListNotifier +// Stack-based helper class to pair calls to WillChangeTransformList and +// DidChangeTransformList. +class MOZ_RAII AutoChangeTransformListNotifier : public mozAutoDocUpdate { + public: + explicit AutoChangeTransformListNotifier(DOMSVGTransformList* aTransformList) + : mozAutoDocUpdate(aTransformList->Element()->GetComposedDoc(), true), + mTransformList(aTransformList) { + MOZ_ASSERT(mTransformList, "Expecting non-null transformList"); + mEmptyOrOldValue = + mTransformList->Element()->WillChangeTransformList(*this); + } + + ~AutoChangeTransformListNotifier() { + mTransformList->Element()->DidChangeTransformList(mEmptyOrOldValue, *this); + if (mTransformList->IsAnimating()) { + mTransformList->Element()->AnimationNeedsResample(); + } + } + + private: + DOMSVGTransformList* const mTransformList; + nsAttrValue mEmptyOrOldValue; +}; + void DOMSVGTransformList::InternalListLengthWillChange(uint32_t aNewLength) { uint32_t oldLength = mItems.Length(); diff --git a/dom/svg/DOMSVGTransformList.h b/dom/svg/DOMSVGTransformList.h index 172ed1f3affa..ba8677bc0143 100644 --- a/dom/svg/DOMSVGTransformList.h +++ b/dom/svg/DOMSVGTransformList.h @@ -8,7 +8,6 @@ #define DOM_SVG_DOMSVGTRANSFORMLIST_H_ #include "DOMSVGAnimatedTransformList.h" -#include "mozAutoDocUpdate.h" #include "nsCycleCollectionParticipant.h" #include "nsDebug.h" #include "SVGTransformList.h" @@ -24,39 +23,6 @@ class DOMSVGTransform; class SVGElement; class SVGMatrix; -//---------------------------------------------------------------------- -// Helper class: AutoChangeTransformListNotifier -// Stack-based helper class to pair calls to WillChangeTransformList and -// DidChangeTransformList. Used by DOMSVGTransform and DOMSVGTransformList. -template -class MOZ_RAII AutoChangeTransformListNotifier { - public: - explicit AutoChangeTransformListNotifier(T* aValue) : mValue(aValue) { - MOZ_ASSERT(mValue, "Expecting non-null value"); - // If we don't have an owner then changes don't affect anything else. - if (mValue->HasOwner()) { - mUpdateBatch.emplace(mValue->Element()->GetComposedDoc(), true); - mEmptyOrOldValue = - mValue->Element()->WillChangeTransformList(mUpdateBatch.ref()); - } - } - - ~AutoChangeTransformListNotifier() { - if (mValue->HasOwner()) { - mValue->Element()->DidChangeTransformList(mEmptyOrOldValue, - mUpdateBatch.ref()); - if (mValue->IsAnimating()) { - mValue->Element()->AnimationNeedsResample(); - } - } - } - - private: - T* const mValue; - Maybe mUpdateBatch; - nsAttrValue mEmptyOrOldValue; -}; - /** * Class DOMSVGTransformList * @@ -66,11 +32,8 @@ class MOZ_RAII AutoChangeTransformListNotifier { * See the architecture comment in DOMSVGAnimatedTransformList.h. */ class DOMSVGTransformList final : public nsISupports, public nsWrapperCache { - template friend class AutoChangeTransformListNotifier; friend class dom::DOMSVGTransform; - using AutoChangeTransformListNotifier = - AutoChangeTransformListNotifier; ~DOMSVGTransformList() { // Our mAList's weak ref to us must be nulled out when we die. If GC has @@ -114,12 +77,6 @@ class DOMSVGTransformList final : public nsISupports, public nsWrapperCache { /// Called to notify us to synchronize our length and detach excess items. void InternalListLengthWillChange(uint32_t aNewLength); - /* - * List classes always have an owner. We need this so that templates that work - * on lists and elements can check ownership where elements may be unowned. - */ - bool HasOwner() const { return true; } - /** * Returns true if our attribute is animating (in which case our animVal is * not simply a mirror of our baseVal). diff --git a/dom/svg/SVGAnimatedBoolean.cpp b/dom/svg/SVGAnimatedBoolean.cpp index 16fff045eccd..91999696189e 100644 --- a/dom/svg/SVGAnimatedBoolean.cpp +++ b/dom/svg/SVGAnimatedBoolean.cpp @@ -18,33 +18,6 @@ namespace mozilla { /* Implementation */ -//---------------------------------------------------------------------- -// Helper class: AutoChangeBooleanNotifier -// Stack-based helper class to ensure DidChangeBoolean is called. -class MOZ_RAII AutoChangeBooleanNotifier { - public: - AutoChangeBooleanNotifier(SVGAnimatedBoolean* aBoolean, - SVGElement* aSVGElement, bool aDoSetAttr = true) - : mBoolean(aBoolean), mSVGElement(aSVGElement), mDoSetAttr(aDoSetAttr) { - MOZ_ASSERT(mBoolean, "Expecting non-null boolean"); - MOZ_ASSERT(mSVGElement, "Expecting non-null element"); - } - - ~AutoChangeBooleanNotifier() { - if (mDoSetAttr) { - mSVGElement->DidChangeBoolean(mBoolean->mAttrEnum); - } - if (mBoolean->mIsAnimated) { - mSVGElement->AnimationNeedsResample(); - } - } - - private: - SVGAnimatedBoolean* const mBoolean; - SVGElement* const mSVGElement; - bool mDoSetAttr; -}; - static inline SVGAttrTearoffTable& SVGAnimatedBooleanTearoffTable() { static SVGAttrTearoffTable @@ -85,16 +58,16 @@ nsresult SVGAnimatedBoolean::SetBaseValueAtom(const nsAtom* aValue, return rv; } - // We don't need to call DidChange* here - we're only called by - // SVGElement::ParseAttribute under Element::SetAttr, - // which takes care of notifying. - AutoChangeBooleanNotifier notifier(this, aSVGElement, false); - mBaseVal = val; if (!mIsAnimated) { mAnimVal = mBaseVal; + } else { + aSVGElement->AnimationNeedsResample(); } + // We don't need to call DidChange* here - we're only called by + // SVGElement::ParseAttribute under Element::SetAttr, + // which takes care of notifying. return NS_OK; } @@ -107,12 +80,13 @@ void SVGAnimatedBoolean::SetBaseValue(bool aValue, SVGElement* aSVGElement) { return; } - AutoChangeBooleanNotifier notifier(this, aSVGElement); - mBaseVal = aValue; if (!mIsAnimated) { mAnimVal = mBaseVal; + } else { + aSVGElement->AnimationNeedsResample(); } + aSVGElement->DidChangeBoolean(mAttrEnum); } void SVGAnimatedBoolean::SetAnimValue(bool aValue, SVGElement* aSVGElement) { diff --git a/dom/svg/SVGAnimatedBoolean.h b/dom/svg/SVGAnimatedBoolean.h index 8c1e57f3a200..a44e8d3a9f4a 100644 --- a/dom/svg/SVGAnimatedBoolean.h +++ b/dom/svg/SVGAnimatedBoolean.h @@ -27,7 +27,6 @@ class SVGElement; class SVGAnimatedBoolean { public: - friend class AutoChangeBooleanNotifier; using SVGElement = dom::SVGElement; void Init(uint8_t aAttrEnum = 0xff, bool aValue = false) { diff --git a/dom/svg/SVGAnimatedEnumeration.cpp b/dom/svg/SVGAnimatedEnumeration.cpp index 1dc35b16ace5..c6472aa38905 100644 --- a/dom/svg/SVGAnimatedEnumeration.cpp +++ b/dom/svg/SVGAnimatedEnumeration.cpp @@ -17,33 +17,6 @@ using namespace mozilla::dom; namespace mozilla { -//---------------------------------------------------------------------- -// Helper class: AutoChangeEnumNotifier -// Stack-based helper class to ensure DidChangeEnum is called. -class MOZ_RAII AutoChangeEnumNotifier { - public: - AutoChangeEnumNotifier(SVGAnimatedEnumeration* aEnum, SVGElement* aSVGElement, - bool aDoSetAttr = true) - : mEnum(aEnum), mSVGElement(aSVGElement), mDoSetAttr(aDoSetAttr) { - MOZ_ASSERT(mEnum, "Expecting non-null enum"); - MOZ_ASSERT(mSVGElement, "Expecting non-null element"); - } - - ~AutoChangeEnumNotifier() { - if (mDoSetAttr) { - mSVGElement->DidChangeEnum(mEnum->mAttrEnum); - } - if (mEnum->mIsAnimated) { - mSVGElement->AnimationNeedsResample(); - } - } - - private: - SVGAnimatedEnumeration* const mEnum; - SVGElement* const mSVGElement; - bool mDoSetAttr; -}; - static SVGAttrTearoffTable sSVGAnimatedEnumTearoffTable; @@ -66,15 +39,15 @@ bool SVGAnimatedEnumeration::SetBaseValueAtom(const nsAtom* aValue, if (aValue == mapping->mKey) { mIsBaseSet = true; if (mBaseVal != mapping->mVal) { - // We don't need to call DidChange* here - we're only called by - // SVGElement::ParseAttribute under Element::SetAttr, - // which takes care of notifying. - AutoChangeEnumNotifier notifier(this, aSVGElement, false); - mBaseVal = mapping->mVal; if (!mIsAnimated) { mAnimVal = mBaseVal; + } else { + aSVGElement->AnimationNeedsResample(); } + // We don't need to call DidChange* here - we're only called by + // SVGElement::ParseAttribute under Element::SetAttr, + // which takes care of notifying. } return true; } @@ -106,12 +79,13 @@ void SVGAnimatedEnumeration::SetBaseValue(uint16_t aValue, if (mapping->mVal == aValue) { mIsBaseSet = true; if (mBaseVal != uint8_t(aValue)) { - AutoChangeEnumNotifier notifier(this, aSVGElement); - mBaseVal = uint8_t(aValue); if (!mIsAnimated) { mAnimVal = mBaseVal; + } else { + aSVGElement->AnimationNeedsResample(); } + aSVGElement->DidChangeEnum(mAttrEnum); } return; } diff --git a/dom/svg/SVGAnimatedEnumeration.h b/dom/svg/SVGAnimatedEnumeration.h index 56482092b44c..fadb279c65ed 100644 --- a/dom/svg/SVGAnimatedEnumeration.h +++ b/dom/svg/SVGAnimatedEnumeration.h @@ -34,7 +34,6 @@ struct SVGEnumMapping { class SVGAnimatedEnumeration { public: - friend class AutoChangeEnumNotifier; using SVGElement = dom::SVGElement; void Init(uint8_t aAttrEnum, uint16_t aValue) { diff --git a/dom/svg/SVGAnimatedInteger.cpp b/dom/svg/SVGAnimatedInteger.cpp index 2815e4df110f..6e4e6db26e46 100644 --- a/dom/svg/SVGAnimatedInteger.cpp +++ b/dom/svg/SVGAnimatedInteger.cpp @@ -18,33 +18,6 @@ namespace mozilla { /* Implementation */ -//---------------------------------------------------------------------- -// Helper class: AutoChangeIntegerNotifier -// Stack-based helper class ensure DidChangeInteger is called. -class MOZ_RAII AutoChangeIntegerNotifier { - public: - AutoChangeIntegerNotifier(SVGAnimatedInteger* aInteger, - SVGElement* aSVGElement, bool aDoSetAttr = true) - : mInteger(aInteger), mSVGElement(aSVGElement), mDoSetAttr(aDoSetAttr) { - MOZ_ASSERT(mInteger, "Expecting non-null integer"); - MOZ_ASSERT(mSVGElement, "Expecting non-null element"); - } - - ~AutoChangeIntegerNotifier() { - if (mDoSetAttr) { - mSVGElement->DidChangeInteger(mInteger->mAttrEnum); - } - if (mInteger->mIsAnimated) { - mSVGElement->AnimationNeedsResample(); - } - } - - private: - SVGAnimatedInteger* const mInteger; - SVGElement* const mSVGElement; - bool mDoSetAttr; -}; - static SVGAttrTearoffTable sSVGAnimatedIntegerTearoffTable; @@ -64,12 +37,12 @@ nsresult SVGAnimatedInteger::SetBaseValueString(const nsAString& aValueAsString, return NS_ERROR_DOM_SYNTAX_ERR; } - AutoChangeIntegerNotifier notifier(this, aSVGElement, false); - mIsBaseSet = true; mBaseVal = value; if (!mIsAnimated) { mAnimVal = mBaseVal; + } else { + aSVGElement->AnimationNeedsResample(); } return NS_OK; } @@ -88,13 +61,14 @@ void SVGAnimatedInteger::SetBaseValue(int aValue, SVGElement* aSVGElement) { return; } - AutoChangeIntegerNotifier notifier(this, aSVGElement); - mBaseVal = aValue; mIsBaseSet = true; if (!mIsAnimated) { mAnimVal = mBaseVal; + } else { + aSVGElement->AnimationNeedsResample(); } + aSVGElement->DidChangeInteger(mAttrEnum); } void SVGAnimatedInteger::SetAnimValue(int aValue, SVGElement* aSVGElement) { diff --git a/dom/svg/SVGAnimatedInteger.h b/dom/svg/SVGAnimatedInteger.h index efdc1d2564be..7eac61154971 100644 --- a/dom/svg/SVGAnimatedInteger.h +++ b/dom/svg/SVGAnimatedInteger.h @@ -25,7 +25,6 @@ class SVGAnimationElement; class SVGAnimatedInteger { public: - friend class AutoChangeIntegerNotifier; using SVGElement = dom::SVGElement; void Init(uint8_t aAttrEnum = 0xff, int32_t aValue = 0) { diff --git a/dom/svg/SVGAnimatedIntegerPair.cpp b/dom/svg/SVGAnimatedIntegerPair.cpp index 2239c40b51b9..4d8f06c245e2 100644 --- a/dom/svg/SVGAnimatedIntegerPair.cpp +++ b/dom/svg/SVGAnimatedIntegerPair.cpp @@ -18,45 +18,6 @@ using namespace mozilla::dom; namespace mozilla { -//---------------------------------------------------------------------- -// Helper class: AutoChangeIntegerPairNotifier -// Stack-based helper class to pair calls to WillChangeIntegerPair and -// DidChangeIntegerPair. -class MOZ_RAII AutoChangeIntegerPairNotifier { - public: - AutoChangeIntegerPairNotifier(SVGAnimatedIntegerPair* aIntegerPair, - SVGElement* aSVGElement, bool aDoSetAttr = true) - : mIntegerPair(aIntegerPair), - mSVGElement(aSVGElement), - mDoSetAttr(aDoSetAttr) { - MOZ_ASSERT(mIntegerPair, "Expecting non-null integerPair"); - MOZ_ASSERT(mSVGElement, "Expecting non-null element"); - - if (mDoSetAttr) { - mUpdateBatch.emplace(aSVGElement->GetComposedDoc(), true); - mEmptyOrOldValue = mSVGElement->WillChangeIntegerPair( - mIntegerPair->mAttrEnum, mUpdateBatch.ref()); - } - } - - ~AutoChangeIntegerPairNotifier() { - if (mDoSetAttr) { - mSVGElement->DidChangeIntegerPair(mIntegerPair->mAttrEnum, - mEmptyOrOldValue, mUpdateBatch.ref()); - } - if (mIntegerPair->mIsAnimated) { - mSVGElement->AnimationNeedsResample(); - } - } - - private: - SVGAnimatedIntegerPair* const mIntegerPair; - SVGElement* const mSVGElement; - Maybe mUpdateBatch; - nsAttrValue mEmptyOrOldValue; - bool mDoSetAttr; -}; - static SVGAttrTearoffTable sSVGFirstAnimatedIntegerTearoffTable; @@ -99,18 +60,19 @@ nsresult SVGAnimatedIntegerPair::SetBaseValueString( return rv; } - // We don't need to call DidChange* here - we're only called by - // SVGElement::ParseAttribute under Element::SetAttr, - // which takes care of notifying. - AutoChangeIntegerPairNotifier notifier(this, aSVGElement, false); - mBaseVal[0] = val[0]; mBaseVal[1] = val[1]; mIsBaseSet = true; if (!mIsAnimated) { mAnimVal[0] = mBaseVal[0]; mAnimVal[1] = mBaseVal[1]; + } else { + aSVGElement->AnimationNeedsResample(); } + + // We don't need to call DidChange* here - we're only called by + // SVGElement::ParseAttribute under Element::SetAttr, + // which takes care of notifying. return NS_OK; } @@ -131,13 +93,17 @@ void SVGAnimatedIntegerPair::SetBaseValue(int32_t aValue, PairIndex aPairIndex, return; } - AutoChangeIntegerPairNotifier notifier(this, aSVGElement); - + mozAutoDocUpdate updateBatch(aSVGElement->GetComposedDoc(), true); + nsAttrValue emptyOrOldValue = + aSVGElement->WillChangeIntegerPair(mAttrEnum, updateBatch); mBaseVal[index] = aValue; mIsBaseSet = true; if (!mIsAnimated) { mAnimVal[index] = aValue; + } else { + aSVGElement->AnimationNeedsResample(); } + aSVGElement->DidChangeIntegerPair(mAttrEnum, emptyOrOldValue, updateBatch); } void SVGAnimatedIntegerPair::SetBaseValues(int32_t aValue1, int32_t aValue2, @@ -146,15 +112,19 @@ void SVGAnimatedIntegerPair::SetBaseValues(int32_t aValue1, int32_t aValue2, return; } - AutoChangeIntegerPairNotifier notifier(this, aSVGElement); - + mozAutoDocUpdate updateBatch(aSVGElement->GetComposedDoc(), true); + nsAttrValue emptyOrOldValue = + aSVGElement->WillChangeIntegerPair(mAttrEnum, updateBatch); mBaseVal[0] = aValue1; mBaseVal[1] = aValue2; mIsBaseSet = true; if (!mIsAnimated) { mAnimVal[0] = aValue1; mAnimVal[1] = aValue2; + } else { + aSVGElement->AnimationNeedsResample(); } + aSVGElement->DidChangeIntegerPair(mAttrEnum, emptyOrOldValue, updateBatch); } void SVGAnimatedIntegerPair::SetAnimValue(const int32_t aValue[2], diff --git a/dom/svg/SVGAnimatedIntegerPair.h b/dom/svg/SVGAnimatedIntegerPair.h index 748b0a8b6ecb..1033fd0ab22a 100644 --- a/dom/svg/SVGAnimatedIntegerPair.h +++ b/dom/svg/SVGAnimatedIntegerPair.h @@ -25,7 +25,6 @@ class SVGElement; class SVGAnimatedIntegerPair { public: - friend class AutoChangeIntegerPairNotifier; using SVGElement = dom::SVGElement; enum PairIndex { eFirst, eSecond }; diff --git a/dom/svg/SVGAnimatedLength.cpp b/dom/svg/SVGAnimatedLength.cpp index ae1d51d8137d..12f48e4c59f8 100644 --- a/dom/svg/SVGAnimatedLength.cpp +++ b/dom/svg/SVGAnimatedLength.cpp @@ -25,43 +25,6 @@ using namespace mozilla::dom; namespace mozilla { -//---------------------------------------------------------------------- -// Helper class: AutoChangeLengthNotifier -// Stack-based helper class to pair calls to WillChangeLength and -// DidChangeLength. -class MOZ_RAII AutoChangeLengthNotifier { - public: - AutoChangeLengthNotifier(SVGAnimatedLength* aLength, SVGElement* aSVGElement, - bool aDoSetAttr = true) - : mLength(aLength), mSVGElement(aSVGElement), mDoSetAttr(aDoSetAttr) { - MOZ_ASSERT(mLength, "Expecting non-null length"); - MOZ_ASSERT(mSVGElement, "Expecting non-null element"); - - if (mDoSetAttr) { - mUpdateBatch.emplace(aSVGElement->GetComposedDoc(), true); - mEmptyOrOldValue = - mSVGElement->WillChangeLength(mLength->mAttrEnum, mUpdateBatch.ref()); - } - } - - ~AutoChangeLengthNotifier() { - if (mDoSetAttr) { - mSVGElement->DidChangeLength(mLength->mAttrEnum, mEmptyOrOldValue, - mUpdateBatch.ref()); - } - if (mLength->mIsAnimated) { - mSVGElement->AnimationNeedsResample(); - } - } - - private: - SVGAnimatedLength* const mLength; - SVGElement* const mSVGElement; - Maybe mUpdateBatch; - nsAttrValue mEmptyOrOldValue; - bool mDoSetAttr; -}; - static const nsStaticAtom* const unitMap[] = { nullptr, /* SVG_LENGTHTYPE_UNKNOWN */ nullptr, /* SVG_LENGTHTYPE_NUMBER */ @@ -289,19 +252,26 @@ float SVGAnimatedLength::GetPixelsPerUnit(const UserSpaceMetrics& aMetrics, } } -void SVGAnimatedLength::SetBaseValueInSpecifiedUnits(float aValue, - SVGElement* aSVGElement, - bool aDoSetAttr) { +void SVGAnimatedLength::SetBaseValueInSpecifiedUnits( + float aValue, SVGElement* aSVGElement, bool aDoSetAttr, + const mozAutoDocUpdate& aProofOfUpdate) { if (mIsBaseSet && mBaseVal == aValue) { return; } - AutoChangeLengthNotifier notifier(this, aSVGElement, aDoSetAttr); - + nsAttrValue emptyOrOldValue; + if (aDoSetAttr) { + emptyOrOldValue = aSVGElement->WillChangeLength(mAttrEnum, aProofOfUpdate); + } mBaseVal = aValue; mIsBaseSet = true; if (!mIsAnimated) { mAnimVal = mBaseVal; + } else { + aSVGElement->AnimationNeedsResample(); + } + if (aDoSetAttr) { + aSVGElement->DidChangeLength(mAttrEnum, emptyOrOldValue, aProofOfUpdate); } } @@ -328,12 +298,17 @@ nsresult SVGAnimatedLength::ConvertToSpecifiedUnits(uint16_t unitType, // on the document, we still need to send out notifications in case we have // mutation listeners, since the actual string value of the attribute will // change. - AutoChangeLengthNotifier notifier(this, aSVGElement); + mozAutoDocUpdate updateBatch(aSVGElement->GetComposedDoc(), true); + nsAttrValue emptyOrOldValue = + aSVGElement->WillChangeLength(mAttrEnum, updateBatch); mSpecifiedUnitType = uint8_t(unitType); // Setting aDoSetAttr to false here will ensure we don't call // Will/DidChangeAngle a second time (and dispatch duplicate notifications). - SetBaseValueInSpecifiedUnits(valueInSpecifiedUnits, aSVGElement, false); + SetBaseValueInSpecifiedUnits(valueInSpecifiedUnits, aSVGElement, false, + updateBatch); + + aSVGElement->DidChangeLength(mAttrEnum, emptyOrOldValue, updateBatch); return NS_OK; } @@ -350,14 +325,18 @@ nsresult SVGAnimatedLength::NewValueSpecifiedUnits(uint16_t aUnitType, return NS_OK; } - AutoChangeLengthNotifier notifier(this, aSVGElement); - + mozAutoDocUpdate updateBatch(aSVGElement->GetComposedDoc(), true); + nsAttrValue emptyOrOldValue = + aSVGElement->WillChangeLength(mAttrEnum, updateBatch); mBaseVal = aValueInSpecifiedUnits; mIsBaseSet = true; mSpecifiedUnitType = uint8_t(aUnitType); if (!mIsAnimated) { mAnimVal = mBaseVal; + } else { + aSVGElement->AnimationNeedsResample(); } + aSVGElement->DidChangeLength(mAttrEnum, emptyOrOldValue, updateBatch); return NS_OK; } @@ -388,15 +367,25 @@ nsresult SVGAnimatedLength::SetBaseValueString(const nsAString& aValueAsString, return NS_OK; } - AutoChangeLengthNotifier notifier(this, aSVGElement, aDoSetAttr); - + Maybe updateBatch; + nsAttrValue emptyOrOldValue; + if (aDoSetAttr) { + updateBatch.emplace(aSVGElement->GetComposedDoc(), true); + emptyOrOldValue = + aSVGElement->WillChangeLength(mAttrEnum, updateBatch.ref()); + } mBaseVal = value; mIsBaseSet = true; mSpecifiedUnitType = uint8_t(unitType); if (!mIsAnimated) { mAnimVal = mBaseVal; + } else { + aSVGElement->AnimationNeedsResample(); } + if (aDoSetAttr) { + aSVGElement->DidChangeLength(mAttrEnum, emptyOrOldValue, updateBatch.ref()); + } return NS_OK; } @@ -420,7 +409,9 @@ nsresult SVGAnimatedLength::SetBaseValue(float aValue, SVGElement* aSVGElement, return NS_ERROR_ILLEGAL_VALUE; } - SetBaseValueInSpecifiedUnits(valueInSpecifiedUnits, aSVGElement, aDoSetAttr); + mozAutoDocUpdate updateBatch(aSVGElement->GetComposedDoc(), true); + SetBaseValueInSpecifiedUnits(valueInSpecifiedUnits, aSVGElement, aDoSetAttr, + updateBatch); return NS_OK; } diff --git a/dom/svg/SVGAnimatedLength.h b/dom/svg/SVGAnimatedLength.h index 285a860a5225..3a6b9587887b 100644 --- a/dom/svg/SVGAnimatedLength.h +++ b/dom/svg/SVGAnimatedLength.h @@ -24,7 +24,6 @@ class nsIFrame; namespace mozilla { -class AutoChangeLengthNotifier; class SMILValue; namespace dom { @@ -80,7 +79,6 @@ class NonSVGFrameUserSpaceMetrics : public UserSpaceMetricsWithSize { } // namespace dom class SVGAnimatedLength { - friend class AutoChangeLengthNotifier; friend class dom::DOMSVGAnimatedLength; friend class dom::DOMSVGLength; using DOMSVGLength = dom::DOMSVGLength; @@ -181,7 +179,8 @@ class SVGAnimatedLength { // perform unit conversion and are therefore infallible. nsresult SetBaseValue(float aValue, SVGElement* aSVGElement, bool aDoSetAttr); void SetBaseValueInSpecifiedUnits(float aValue, SVGElement* aSVGElement, - bool aDoSetAttr); + bool aDoSetAttr, + const mozAutoDocUpdate& aProofOfUpdate); nsresult SetAnimValue(float aValue, SVGElement* aSVGElement); void SetAnimValueInSpecifiedUnits(float aValue, SVGElement* aSVGElement); nsresult NewValueSpecifiedUnits(uint16_t aUnitType, diff --git a/dom/svg/SVGAnimatedNumber.cpp b/dom/svg/SVGAnimatedNumber.cpp index 246f49db74de..f50649b2632d 100644 --- a/dom/svg/SVGAnimatedNumber.cpp +++ b/dom/svg/SVGAnimatedNumber.cpp @@ -19,29 +19,6 @@ namespace mozilla { /* Implementation */ -//---------------------------------------------------------------------- -// Helper class: AutoChangeNumberNotifier -// Stack-based helper class to ensure DidChangeNumber is called. -class MOZ_RAII AutoChangeNumberNotifier { - public: - AutoChangeNumberNotifier(SVGAnimatedNumber* aNumber, SVGElement* aSVGElement) - : mNumber(aNumber), mSVGElement(aSVGElement) { - MOZ_ASSERT(mNumber, "Expecting non-null number"); - MOZ_ASSERT(mSVGElement, "Expecting non-null element"); - } - - ~AutoChangeNumberNotifier() { - mSVGElement->DidChangeNumber(mNumber->mAttrEnum); - if (mNumber->mIsAnimated) { - mSVGElement->AnimationNeedsResample(); - } - } - - private: - SVGAnimatedNumber* const mNumber; - SVGElement* const mSVGElement; -}; - static SVGAttrTearoffTable sSVGAnimatedNumberTearoffTable; @@ -107,13 +84,14 @@ void SVGAnimatedNumber::SetBaseValue(float aValue, SVGElement* aSVGElement) { return; } - AutoChangeNumberNotifier notifier(this, aSVGElement); - mBaseVal = aValue; mIsBaseSet = true; if (!mIsAnimated) { mAnimVal = mBaseVal; + } else { + aSVGElement->AnimationNeedsResample(); } + aSVGElement->DidChangeNumber(mAttrEnum); } void SVGAnimatedNumber::SetAnimValue(float aValue, SVGElement* aSVGElement) { diff --git a/dom/svg/SVGAnimatedNumber.h b/dom/svg/SVGAnimatedNumber.h index cee96ca49123..580f5fcfce0d 100644 --- a/dom/svg/SVGAnimatedNumber.h +++ b/dom/svg/SVGAnimatedNumber.h @@ -27,7 +27,6 @@ class SVGAnimationElement; class SVGAnimatedNumber { public: - friend class AutoChangeNumberNotifier; using SVGElement = dom::SVGElement; void Init(uint8_t aAttrEnum = 0xff, float aValue = 0) { diff --git a/dom/svg/SVGAnimatedNumberPair.cpp b/dom/svg/SVGAnimatedNumberPair.cpp index 7ff8a89d6e8e..aede1826add0 100644 --- a/dom/svg/SVGAnimatedNumberPair.cpp +++ b/dom/svg/SVGAnimatedNumberPair.cpp @@ -16,43 +16,6 @@ using namespace mozilla::dom; namespace mozilla { -//---------------------------------------------------------------------- -// Helper class: AutoChangeNumberPairNotifier -// Stack-based helper class to pair calls to WillChangeNumberPair and -// DidChangeNumberPair. -class MOZ_RAII AutoChangeNumberPairNotifier { - public: - AutoChangeNumberPairNotifier(SVGAnimatedNumberPair* aNumberPair, - SVGElement* aSVGElement, bool aDoSetAttr = true) - : mNumberPair(aNumberPair), - mSVGElement(aSVGElement), - mDoSetAttr(aDoSetAttr) { - MOZ_ASSERT(mNumberPair, "Expecting non-null numberPair"); - MOZ_ASSERT(mSVGElement, "Expecting non-null element"); - - if (mDoSetAttr) { - mEmptyOrOldValue = - mSVGElement->WillChangeNumberPair(mNumberPair->mAttrEnum); - } - } - - ~AutoChangeNumberPairNotifier() { - if (mDoSetAttr) { - mSVGElement->DidChangeNumberPair(mNumberPair->mAttrEnum, - mEmptyOrOldValue); - } - if (mNumberPair->mIsAnimated) { - mSVGElement->AnimationNeedsResample(); - } - } - - private: - SVGAnimatedNumberPair* const mNumberPair; - SVGElement* const mSVGElement; - nsAttrValue mEmptyOrOldValue; - bool mDoSetAttr; -}; - static SVGAttrTearoffTable sSVGFirstAnimatedNumberTearoffTable; @@ -92,19 +55,19 @@ nsresult SVGAnimatedNumberPair::SetBaseValueString( return rv; } - // We don't need to call Will/DidChange* here - we're only called by - // SVGElement::ParseAttribute under Element::SetAttr, - // which takes care of notifying. - AutoChangeNumberPairNotifier notifier(this, aSVGElement, false); - mBaseVal[0] = val[0]; mBaseVal[1] = val[1]; mIsBaseSet = true; if (!mIsAnimated) { mAnimVal[0] = mBaseVal[0]; mAnimVal[1] = mBaseVal[1]; + } else { + aSVGElement->AnimationNeedsResample(); } + // We don't need to call Will/DidChange* here - we're only called by + // SVGElement::ParseAttribute under Element::SetAttr, + // which takes care of notifying. return NS_OK; } @@ -124,14 +87,15 @@ void SVGAnimatedNumberPair::SetBaseValue(float aValue, PairIndex aPairIndex, if (mIsBaseSet && mBaseVal[index] == aValue) { return; } - - AutoChangeNumberPairNotifier notifier(this, aSVGElement); - + nsAttrValue emptyOrOldValue = aSVGElement->WillChangeNumberPair(mAttrEnum); mBaseVal[index] = aValue; mIsBaseSet = true; if (!mIsAnimated) { mAnimVal[index] = aValue; + } else { + aSVGElement->AnimationNeedsResample(); } + aSVGElement->DidChangeNumberPair(mAttrEnum, emptyOrOldValue); } void SVGAnimatedNumberPair::SetBaseValues(float aValue1, float aValue2, @@ -139,16 +103,17 @@ void SVGAnimatedNumberPair::SetBaseValues(float aValue1, float aValue2, if (mIsBaseSet && mBaseVal[0] == aValue1 && mBaseVal[1] == aValue2) { return; } - - AutoChangeNumberPairNotifier notifier(this, aSVGElement); - + nsAttrValue emptyOrOldValue = aSVGElement->WillChangeNumberPair(mAttrEnum); mBaseVal[0] = aValue1; mBaseVal[1] = aValue2; mIsBaseSet = true; if (!mIsAnimated) { mAnimVal[0] = aValue1; mAnimVal[1] = aValue2; + } else { + aSVGElement->AnimationNeedsResample(); } + aSVGElement->DidChangeNumberPair(mAttrEnum, emptyOrOldValue); } void SVGAnimatedNumberPair::SetAnimValue(const float aValue[2], diff --git a/dom/svg/SVGAnimatedNumberPair.h b/dom/svg/SVGAnimatedNumberPair.h index 1490594d45f5..c23db60ca37a 100644 --- a/dom/svg/SVGAnimatedNumberPair.h +++ b/dom/svg/SVGAnimatedNumberPair.h @@ -27,7 +27,6 @@ class SVGElement; class SVGAnimatedNumberPair { public: - friend class AutoChangeNumberPairNotifier; using SVGElement = dom::SVGElement; enum PairIndex { eFirst, eSecond }; diff --git a/dom/svg/SVGAnimatedOrient.cpp b/dom/svg/SVGAnimatedOrient.cpp index 153dfc2fe230..5d318547730f 100644 --- a/dom/svg/SVGAnimatedOrient.cpp +++ b/dom/svg/SVGAnimatedOrient.cpp @@ -49,9 +49,9 @@ static SVGAttrTearoffTable // DidChangeOrient with mozAutoDocUpdate. class MOZ_RAII AutoChangeOrientNotifier { public: - AutoChangeOrientNotifier( - SVGAnimatedOrient* aOrient, SVGElement* aSVGElement, - bool aDoSetAttr = true) + explicit AutoChangeOrientNotifier(SVGAnimatedOrient* aOrient, + SVGElement* aSVGElement, + bool aDoSetAttr = true) : mOrient(aOrient), mSVGElement(aSVGElement), mDoSetAttr(aDoSetAttr) { MOZ_ASSERT(mOrient, "Expecting non-null orient"); if (mSVGElement && mDoSetAttr) { diff --git a/dom/svg/SVGAnimatedPreserveAspectRatio.cpp b/dom/svg/SVGAnimatedPreserveAspectRatio.cpp index 56cced25e4b4..7ce4d987241b 100644 --- a/dom/svg/SVGAnimatedPreserveAspectRatio.cpp +++ b/dom/svg/SVGAnimatedPreserveAspectRatio.cpp @@ -39,45 +39,6 @@ JSObject* DOMSVGAnimatedPreserveAspectRatio::WrapObject( /* Implementation */ -//---------------------------------------------------------------------- -// Helper class: AutoChangePreserveAspectRatioNotifier -// Stack-based helper class to pair calls to WillChangePreserveAspectRatio and -// DidChangePreserveAspectRatio. -class MOZ_RAII AutoChangePreserveAspectRatioNotifier { - public: - AutoChangePreserveAspectRatioNotifier( - SVGAnimatedPreserveAspectRatio* aPreserveAspectRatio, - SVGElement* aSVGElement, bool aDoSetAttr = true) - : mPreserveAspectRatio(aPreserveAspectRatio), - mSVGElement(aSVGElement), - mDoSetAttr(aDoSetAttr) { - MOZ_ASSERT(mPreserveAspectRatio, "Expecting non-null preserveAspectRatio"); - MOZ_ASSERT(mSVGElement, "Expecting non-null element"); - if (mDoSetAttr) { - mUpdateBatch.emplace(aSVGElement->GetComposedDoc(), true); - mEmptyOrOldValue = - mSVGElement->WillChangePreserveAspectRatio(mUpdateBatch.ref()); - } - } - - ~AutoChangePreserveAspectRatioNotifier() { - if (mDoSetAttr) { - mSVGElement->DidChangePreserveAspectRatio(mEmptyOrOldValue, - mUpdateBatch.ref()); - } - if (mPreserveAspectRatio->mIsAnimated) { - mSVGElement->AnimationNeedsResample(); - } - } - - private: - SVGAnimatedPreserveAspectRatio* const mPreserveAspectRatio; - SVGElement* const mSVGElement; - Maybe mUpdateBatch; - nsAttrValue mEmptyOrOldValue; - bool mDoSetAttr; -}; - static SVGAttrTearoffTable sSVGAnimatedPAspectRatioTearoffTable; @@ -128,14 +89,27 @@ nsresult SVGAnimatedPreserveAspectRatio::SetBaseValueString( return res; } - AutoChangePreserveAspectRatioNotifier notifier(this, aSVGElement, aDoSetAttr); + Maybe updateBatch; + nsAttrValue emptyOrOldValue; + if (aDoSetAttr) { + updateBatch.emplace(aSVGElement->GetComposedDoc(), true); + emptyOrOldValue = + aSVGElement->WillChangePreserveAspectRatio(updateBatch.ref()); + } mBaseVal = val; mIsBaseSet = true; + if (!mIsAnimated) { mAnimVal = mBaseVal; } - + if (aDoSetAttr) { + aSVGElement->DidChangePreserveAspectRatio(emptyOrOldValue, + updateBatch.ref()); + } + if (mIsAnimated) { + aSVGElement->AnimationNeedsResample(); + } return NS_OK; } @@ -150,13 +124,19 @@ void SVGAnimatedPreserveAspectRatio::SetBaseValue( return; } - AutoChangePreserveAspectRatioNotifier notifier(this, aSVGElement); - + mozAutoDocUpdate updateBatch(aSVGElement->GetComposedDoc(), true); + nsAttrValue emptyOrOldValue = + aSVGElement->WillChangePreserveAspectRatio(updateBatch); mBaseVal = aValue; mIsBaseSet = true; + if (!mIsAnimated) { mAnimVal = mBaseVal; } + aSVGElement->DidChangePreserveAspectRatio(emptyOrOldValue, updateBatch); + if (mIsAnimated) { + aSVGElement->AnimationNeedsResample(); + } } static uint64_t PackPreserveAspectRatio(const SVGPreserveAspectRatio& par) { diff --git a/dom/svg/SVGAnimatedPreserveAspectRatio.h b/dom/svg/SVGAnimatedPreserveAspectRatio.h index 13271765bd73..43296fed1e25 100644 --- a/dom/svg/SVGAnimatedPreserveAspectRatio.h +++ b/dom/svg/SVGAnimatedPreserveAspectRatio.h @@ -25,8 +25,6 @@ class SVGAnimationElement; } // namespace dom class SVGAnimatedPreserveAspectRatio final { - friend class AutoChangePreserveAspectRatioNotifier; - public: void Init() { mBaseVal.mAlign = diff --git a/dom/svg/SVGAnimatedViewBox.cpp b/dom/svg/SVGAnimatedViewBox.cpp index 8d0eda8f1f3b..c708b82bc99b 100644 --- a/dom/svg/SVGAnimatedViewBox.cpp +++ b/dom/svg/SVGAnimatedViewBox.cpp @@ -72,41 +72,6 @@ static SVGAttrTearoffTable SVGAttrTearoffTable SVGAnimatedViewBox::sSVGAnimatedRectTearoffTable; -//---------------------------------------------------------------------- -// Helper class: AutoChangeViewBoxNotifier -// Stack-based helper class to pair calls to WillChangeViewBox and -// DidChangeViewBox. -class MOZ_RAII AutoChangeViewBoxNotifier { - public: - AutoChangeViewBoxNotifier(SVGAnimatedViewBox* aViewBox, - SVGElement* aSVGElement, bool aDoSetAttr = true) - : mViewBox(aViewBox), mSVGElement(aSVGElement), mDoSetAttr(aDoSetAttr) { - MOZ_ASSERT(mViewBox, "Expecting non-null viewBox"); - MOZ_ASSERT(mSVGElement, "Expecting non-null element"); - - if (mDoSetAttr) { - mUpdateBatch.emplace(aSVGElement->GetComposedDoc(), true); - mEmptyOrOldValue = mSVGElement->WillChangeViewBox(mUpdateBatch.ref()); - } - } - - ~AutoChangeViewBoxNotifier() { - if (mDoSetAttr) { - mSVGElement->DidChangeViewBox(mEmptyOrOldValue, mUpdateBatch.ref()); - } - if (mViewBox->mAnimVal) { - mSVGElement->AnimationNeedsResample(); - } - } - - private: - SVGAnimatedViewBox* const mViewBox; - SVGElement* const mSVGElement; - Maybe mUpdateBatch; - nsAttrValue mEmptyOrOldValue; - bool mDoSetAttr; -}; - /* Implementation of SVGAnimatedViewBox methods */ void SVGAnimatedViewBox::Init() { @@ -159,10 +124,16 @@ void SVGAnimatedViewBox::SetBaseValue(const SVGViewBox& aRect, return; } - AutoChangeViewBoxNotifier notifier(this, aSVGElement); + mozAutoDocUpdate updateBatch(aSVGElement->GetComposedDoc(), true); + nsAttrValue emptyOrOldValue = aSVGElement->WillChangeViewBox(updateBatch); mBaseVal = aRect; mHasBaseVal = true; + + aSVGElement->DidChangeViewBox(emptyOrOldValue, updateBatch); + if (mAnimVal) { + aSVGElement->AnimationNeedsResample(); + } } nsresult SVGAnimatedViewBox::SetBaseValueString(const nsAString& aValue, @@ -179,10 +150,21 @@ nsresult SVGAnimatedViewBox::SetBaseValueString(const nsAString& aValue, return NS_OK; } - AutoChangeViewBoxNotifier notifier(this, aSVGElement, aDoSetAttr); + Maybe updateBatch; + nsAttrValue emptyOrOldValue; + if (aDoSetAttr) { + updateBatch.emplace(aSVGElement->GetComposedDoc(), true); + emptyOrOldValue = aSVGElement->WillChangeViewBox(updateBatch.ref()); + } mHasBaseVal = true; mBaseVal = viewBox; + if (aDoSetAttr) { + aSVGElement->DidChangeViewBox(emptyOrOldValue, updateBatch.ref()); + } + if (mAnimVal) { + aSVGElement->AnimationNeedsResample(); + } return NS_OK; } diff --git a/dom/svg/SVGAnimatedViewBox.h b/dom/svg/SVGAnimatedViewBox.h index 9a3ff4096c01..a17aa351d6c3 100644 --- a/dom/svg/SVGAnimatedViewBox.h +++ b/dom/svg/SVGAnimatedViewBox.h @@ -40,7 +40,6 @@ struct SVGViewBox { class SVGAnimatedViewBox { public: - friend class AutoChangeViewBoxNotifier; using SVGElement = dom::SVGElement; void Init();