diff options
Diffstat (limited to 'Source/WebCore/svg/properties/SVGAnimatedPropertyTearOff.h')
-rw-r--r-- | Source/WebCore/svg/properties/SVGAnimatedPropertyTearOff.h | 91 |
1 files changed, 45 insertions, 46 deletions
diff --git a/Source/WebCore/svg/properties/SVGAnimatedPropertyTearOff.h b/Source/WebCore/svg/properties/SVGAnimatedPropertyTearOff.h index d406ff5d0..fc62c9da4 100644 --- a/Source/WebCore/svg/properties/SVGAnimatedPropertyTearOff.h +++ b/Source/WebCore/svg/properties/SVGAnimatedPropertyTearOff.h @@ -1,5 +1,6 @@ /* * Copyright (C) Research In Motion Limited 2010. All rights reserved. + * Copyright (C) 2016 Apple Inc. All rights reserved. * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Library General Public @@ -17,58 +18,60 @@ * Boston, MA 02110-1301, USA. */ -#ifndef SVGAnimatedPropertyTearOff_h -#define SVGAnimatedPropertyTearOff_h +#pragma once -#if ENABLE(SVG) #include "SVGAnimatedProperty.h" #include "SVGPropertyTearOff.h" namespace WebCore { -template<typename PropertyType> -class SVGAnimatedPropertyTearOff : public SVGAnimatedProperty { +template<typename T> +class SVGAnimatedPropertyTearOff final : public SVGAnimatedProperty { public: - typedef SVGPropertyTearOff<PropertyType> PropertyTearOff; - typedef PropertyType ContentType; + using PropertyTearOff = T; + using PropertyType = typename PropertyTearOff::PropertyType; + using ContentType = PropertyType; - virtual ~SVGAnimatedPropertyTearOff() + static Ref<SVGAnimatedPropertyTearOff<PropertyTearOff>> create(SVGElement* contextElement, const QualifiedName& attributeName, AnimatedPropertyType animatedPropertyType, PropertyType& property) { - if (m_baseVal) { - ASSERT(m_baseVal->animatedProperty() == this); - m_baseVal->setAnimatedProperty(0); - } - if (m_animVal) { - ASSERT(m_animVal->animatedProperty() == this); - m_animVal->setAnimatedProperty(0); - } + ASSERT(contextElement); + return adoptRef(*new SVGAnimatedPropertyTearOff<PropertyTearOff>(contextElement, attributeName, animatedPropertyType, property)); } - PropertyTearOff* baseVal() + Ref<PropertyTearOff> baseVal() { - if (!m_baseVal) - m_baseVal = PropertyTearOff::create(this, BaseValRole, m_property); - return m_baseVal.get(); + if (m_baseVal) + return *m_baseVal; + + auto property = PropertyTearOff::create(*this, BaseValRole, m_property); + m_baseVal = property.ptr(); + return property; } - PropertyTearOff* animVal() + Ref<PropertyTearOff> animVal() { - if (!m_animVal) - m_animVal = PropertyTearOff::create(this, AnimValRole, m_property); - return m_animVal.get(); + if (m_animVal) + return *m_animVal; + + auto property = PropertyTearOff::create(*this, AnimValRole, m_property); + m_animVal = property.ptr(); + return property; } - static PassRefPtr<SVGAnimatedPropertyTearOff<PropertyType>> create(SVGElement* contextElement, const QualifiedName& attributeName, AnimatedPropertyType animatedPropertyType, PropertyType& property) + bool isAnimating() const final { return m_animatedProperty; } + + void propertyWillBeDeleted(const SVGProperty& property) final { - ASSERT(contextElement); - return adoptRef(new SVGAnimatedPropertyTearOff<PropertyType>(contextElement, attributeName, animatedPropertyType, property)); + if (&property == m_baseVal) + m_baseVal = nullptr; + else if (&property == m_animVal) + m_animVal = nullptr; } PropertyType& currentAnimatedValue() { - ASSERT(m_isAnimating); - ASSERT(m_animVal); - return m_animVal->propertyReference(); + ASSERT(isAnimating()); + return m_animatedProperty->propertyReference(); } const PropertyType& currentBaseValue() const @@ -78,32 +81,29 @@ public: void animationStarted(PropertyType* newAnimVal) { - ASSERT(!m_isAnimating); + ASSERT(!isAnimating()); ASSERT(newAnimVal); - animVal()->setValue(*newAnimVal); - m_isAnimating = true; + m_animatedProperty = animVal(); + m_animatedProperty->setValue(*newAnimVal); } void animationEnded() { - ASSERT(m_isAnimating); - ASSERT(m_animVal); - m_animVal->setValue(m_property); - m_isAnimating = false; + ASSERT(isAnimating()); + m_animatedProperty->setValue(m_property); + m_animatedProperty = nullptr; } void animValWillChange() { // no-op for non list types. - ASSERT(m_isAnimating); - ASSERT(m_animVal); + ASSERT(isAnimating()); } void animValDidChange() { // no-op for non list types. - ASSERT(m_isAnimating); - ASSERT(m_animVal); + ASSERT(isAnimating()); } private: @@ -114,11 +114,10 @@ private: } PropertyType& m_property; - RefPtr<PropertyTearOff> m_baseVal; - RefPtr<PropertyTearOff> m_animVal; + PropertyTearOff* m_baseVal { nullptr }; + PropertyTearOff* m_animVal { nullptr }; + + RefPtr<PropertyTearOff> m_animatedProperty; }; } - -#endif // ENABLE(SVG) -#endif // SVGAnimatedPropertyTearOff_h |