diff options
Diffstat (limited to 'Source/WebCore/svg/properties/SVGPropertyTearOff.h')
-rw-r--r-- | Source/WebCore/svg/properties/SVGPropertyTearOff.h | 79 |
1 files changed, 44 insertions, 35 deletions
diff --git a/Source/WebCore/svg/properties/SVGPropertyTearOff.h b/Source/WebCore/svg/properties/SVGPropertyTearOff.h index e0f09b3a7..46f693568 100644 --- a/Source/WebCore/svg/properties/SVGPropertyTearOff.h +++ b/Source/WebCore/svg/properties/SVGPropertyTearOff.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,45 +18,57 @@ * Boston, MA 02110-1301, USA. */ -#ifndef SVGPropertyTearOff_h -#define SVGPropertyTearOff_h +#pragma once -#if ENABLE(SVG) +#include "ExceptionOr.h" #include "SVGAnimatedProperty.h" -#include "SVGElement.h" #include "SVGProperty.h" #include <wtf/WeakPtr.h> namespace WebCore { +class SVGElement; + class SVGPropertyTearOffBase : public SVGProperty { public: virtual void detachWrapper() = 0; }; -template<typename PropertyType> +template<typename T> class SVGPropertyTearOff : public SVGPropertyTearOffBase { public: - typedef SVGPropertyTearOff<PropertyType> Self; + using PropertyType = T; + using Self = SVGPropertyTearOff<PropertyType>; // Used for child types (baseVal/animVal) of a SVGAnimated* property (for example: SVGAnimatedLength::baseVal()). // Also used for list tear offs (for example: text.x.baseVal.getItem(0)). - static PassRefPtr<Self> create(SVGAnimatedProperty* animatedProperty, SVGPropertyRole role, PropertyType& value) + static Ref<Self> create(SVGAnimatedProperty& animatedProperty, SVGPropertyRole role, PropertyType& value) { - ASSERT(animatedProperty); - return adoptRef(new Self(animatedProperty, role, value)); + return adoptRef(*new Self(animatedProperty, role, value)); } // Used for non-animated POD types (for example: SVGSVGElement::createSVGLength()). - static PassRefPtr<Self> create(const PropertyType& initialValue) + static Ref<Self> create(const PropertyType& initialValue) { - return adoptRef(new Self(initialValue)); + return adoptRef(*new Self(initialValue)); } - PropertyType& propertyReference() { return *m_value; } - SVGAnimatedProperty* animatedProperty() const { return m_animatedProperty; } + static Ref<Self> create(const PropertyType* initialValue) + { + return adoptRef(*new Self(initialValue)); + } - void setValue(PropertyType& value) + template<typename U> static ExceptionOr<Ref<Self>> create(ExceptionOr<U>&& initialValue) + { + if (initialValue.hasException()) + return initialValue.releaseException(); + return create(initialValue.releaseReturnValue()); + } + + virtual PropertyType& propertyReference() { return *m_value; } + SVGAnimatedProperty* animatedProperty() const { return m_animatedProperty.get(); } + + virtual void setValue(PropertyType& value) { if (m_valueIsCopy) { detachChildren(); @@ -68,16 +81,13 @@ public: void setAnimatedProperty(SVGAnimatedProperty* animatedProperty) { m_animatedProperty = animatedProperty; - - if (m_animatedProperty) - m_contextElement = m_animatedProperty->contextElement(); } SVGElement* contextElement() const { if (!m_animatedProperty || m_valueIsCopy) - return 0; - return m_contextElement.get(); + return nullptr; + return m_animatedProperty->contextElement(); } void addChild(WeakPtr<SVGPropertyTearOffBase> child) @@ -85,7 +95,7 @@ public: m_childTearOffs.append(child); } - virtual void detachWrapper() override + void detachWrapper() override { if (m_valueIsCopy) return; @@ -101,17 +111,17 @@ public: // Whenever the XML DOM modifies the "x" attribute, all existing wrappers are detached, using this function. m_value = new PropertyType(*m_value); m_valueIsCopy = true; - m_animatedProperty = 0; + m_animatedProperty = nullptr; } - virtual void commitChange() override + void commitChange() override { if (!m_animatedProperty || m_valueIsCopy) return; m_animatedProperty->commitChange(); } - virtual bool isReadOnly() const override + bool isReadOnly() const override { if (m_role == AnimValRole) return true; @@ -127,17 +137,17 @@ protected: , m_value(&value) , m_valueIsCopy(false) { - // Using operator & is completely fine, as SVGAnimatedProperty owns this reference, - // and we're guaranteed to live as long as SVGAnimatedProperty does. - - if (m_animatedProperty) - m_contextElement = m_animatedProperty->contextElement(); } SVGPropertyTearOff(const PropertyType& initialValue) - : m_animatedProperty(0) + : SVGPropertyTearOff(&initialValue) + { + } + + SVGPropertyTearOff(const PropertyType* initialValue) + : m_animatedProperty(nullptr) , m_role(UndefinedRole) - , m_value(new PropertyType(initialValue)) + , m_value(initialValue ? new PropertyType(*initialValue) : nullptr) , m_valueIsCopy(true) { } @@ -148,6 +158,9 @@ protected: detachChildren(); delete m_value; } + + if (m_animatedProperty) + m_animatedProperty->propertyWillBeDeleted(*this); } void detachChildren() @@ -159,8 +172,7 @@ protected: m_childTearOffs.clear(); } - RefPtr<SVGElement> m_contextElement; - SVGAnimatedProperty* m_animatedProperty; + RefPtr<SVGAnimatedProperty> m_animatedProperty; SVGPropertyRole m_role; PropertyType* m_value; Vector<WeakPtr<SVGPropertyTearOffBase>> m_childTearOffs; @@ -168,6 +180,3 @@ protected: }; } - -#endif // ENABLE(SVG) -#endif // SVGPropertyTearOff_h |