1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206
|
/*
* Copyright (C) Research In Motion Limited 2010. 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
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public License
* along with this library; see the file COPYING.LIB. If not, write to
* the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301, USA.
*/
#ifndef SVGAnimatedListPropertyTearOff_h
#define SVGAnimatedListPropertyTearOff_h
#if ENABLE(SVG)
#include "SVGAnimatedProperty.h"
#include "SVGListPropertyTearOff.h"
#include "SVGStaticListPropertyTearOff.h"
namespace WebCore {
template<typename PropertyType>
class SVGPropertyTearOff;
template<typename PropertyType>
class SVGAnimatedListPropertyTearOff : public SVGAnimatedProperty {
public:
typedef typename SVGPropertyTraits<PropertyType>::ListItemType ListItemType;
typedef SVGPropertyTearOff<ListItemType> ListItemTearOff;
typedef Vector<RefPtr<ListItemTearOff> > ListWrapperCache;
typedef SVGListProperty<PropertyType> ListProperty;
typedef SVGListPropertyTearOff<PropertyType> ListPropertyTearOff;
typedef PropertyType ContentType;
virtual PassRefPtr<ListProperty> baseVal()
{
if (m_baseVal)
return m_baseVal;
RefPtr<ListProperty> property = ListPropertyTearOff::create(this, BaseValRole, m_values, m_wrappers).get();
m_baseVal = property.get();
return property.release();
}
virtual PassRefPtr<ListProperty> animVal()
{
if (m_animVal)
return m_animVal;
RefPtr<ListProperty> property = ListPropertyTearOff::create(this, AnimValRole, m_values, m_wrappers).get();
m_animVal = property.get();
return property.release();
}
void propertyWillBeDeleted(const ListProperty& property)
{
if (&property == m_baseVal)
m_baseVal = 0;
else if (&property == m_animVal)
m_animVal = 0;
}
virtual bool isAnimatedListTearOff() const { return true; }
int findItem(SVGProperty* property)
{
// This should ever be called for our baseVal, as animVal can't modify the list.
// It's safe to cast to ListPropertyTearOff here as all classes inheriting from us supply their own removeItemFromList() method.
typedef SVGPropertyTearOff<typename SVGPropertyTraits<PropertyType>::ListItemType> ListItemTearOff;
return static_pointer_cast<ListPropertyTearOff>(baseVal())->findItem(static_cast<ListItemTearOff*>(property));
}
void removeItemFromList(size_t itemIndex, bool shouldSynchronizeWrappers)
{
// This should ever be called for our baseVal, as animVal can't modify the list.
// It's safe to cast to ListPropertyTearOff here as all classes inheriting from us supply their own removeItemFromList() method.
static_pointer_cast<ListPropertyTearOff>(baseVal())->removeItemFromList(itemIndex, shouldSynchronizeWrappers);
}
void detachListWrappers(unsigned newListSize)
{
ListProperty::detachListWrappersAndResize(&m_wrappers, newListSize);
}
PropertyType& currentAnimatedValue()
{
ASSERT(m_isAnimating);
ASSERT(m_animatingAnimVal);
return static_pointer_cast<ListProperty>(m_animatingAnimVal)->values();
}
const PropertyType& currentBaseValue() const
{
return m_values;
}
void animationStarted(PropertyType* newAnimVal, bool shouldOwnValues = false)
{
ASSERT(!m_isAnimating);
ASSERT(!m_animatingAnimVal);
ASSERT(newAnimVal);
ASSERT(m_values.size() == m_wrappers.size());
ASSERT(m_animatedWrappers.isEmpty());
// Switch to new passed in value type & new wrappers list. The new wrappers list must be created for the new value.
if (!newAnimVal->isEmpty())
m_animatedWrappers.fill(0, newAnimVal->size());
m_animatingAnimVal = animVal();
m_animatingAnimVal->setValuesAndWrappers(newAnimVal, &m_animatedWrappers, shouldOwnValues);
ASSERT(m_animatingAnimVal->values().size() == m_animatingAnimVal->wrappers().size());
ASSERT(m_animatingAnimVal->wrappers().size() == m_animatedWrappers.size());
m_isAnimating = true;
}
void animationEnded()
{
ASSERT(m_isAnimating);
ASSERT(m_animatingAnimVal);
ASSERT(m_values.size() == m_wrappers.size());
ASSERT(m_animatingAnimVal->values().size() == m_animatingAnimVal->wrappers().size());
ASSERT(m_animatingAnimVal->wrappers().size() == m_animatedWrappers.size());
m_animatingAnimVal->setValuesAndWrappers(&m_values, &m_wrappers, false);
ASSERT(m_animatingAnimVal->values().size() == m_animatingAnimVal->wrappers().size());
ASSERT(m_animatingAnimVal->wrappers().size() == m_wrappers.size());
m_animatedWrappers.clear();
m_animatingAnimVal = 0;
m_isAnimating = false;
}
void synchronizeWrappersIfNeeded()
{
ASSERT(m_isAnimating);
ASSERT(m_animatingAnimVal);
// Eventually the wrapper list needs synchronization because any SVGAnimateLengthList::calculateAnimatedValue() call may
// mutate the length of our values() list, and thus the wrapper() cache needs synchronization, to have the same size.
// Also existing wrappers which point directly at elements in the existing SVGLengthList have to be detached (so a copy
// of them is created, so existing animVal variables in JS are kept-alive). If we'd detach them later the underlying
// SVGLengthList was already mutated, and our list item wrapper tear offs would point nowhere. Assertions would fire.
m_animatingAnimVal->detachListWrappers(m_animatingAnimVal->values().size());
ASSERT(m_animatingAnimVal->values().size() == m_animatingAnimVal->wrappers().size());
ASSERT(m_animatingAnimVal->wrappers().size() == m_animatedWrappers.size());
}
void animValWillChange()
{
ASSERT(m_values.size() == m_wrappers.size());
synchronizeWrappersIfNeeded();
}
void animValDidChange()
{
ASSERT(m_isAnimating);
ASSERT(m_animVal);
ASSERT(m_values.size() == m_wrappers.size());
synchronizeWrappersIfNeeded();
}
static PassRefPtr<SVGAnimatedListPropertyTearOff<PropertyType> > create(SVGElement* contextElement, const QualifiedName& attributeName, AnimatedPropertyType animatedPropertyType, PropertyType& values)
{
ASSERT(contextElement);
return adoptRef(new SVGAnimatedListPropertyTearOff<PropertyType>(contextElement, attributeName, animatedPropertyType, values));
}
protected:
SVGAnimatedListPropertyTearOff(SVGElement* contextElement, const QualifiedName& attributeName, AnimatedPropertyType animatedPropertyType, PropertyType& values)
: SVGAnimatedProperty(contextElement, attributeName, animatedPropertyType)
, m_values(values)
, m_baseVal(0)
, m_animVal(0)
{
if (!values.isEmpty())
m_wrappers.fill(0, values.size());
}
PropertyType& m_values;
ListWrapperCache m_wrappers;
ListWrapperCache m_animatedWrappers;
// Cache the raw pointer but return a RefPtr<>. This will break the cyclic reference
// between SVGListPropertyTearOff and SVGAnimatedListPropertyTearOff once the property
// pointer is not needed.
ListProperty* m_baseVal;
ListProperty* m_animVal;
RefPtr<ListProperty> m_animatingAnimVal;
};
}
#endif // ENABLE(SVG)
#endif // SVGAnimatedListPropertyTearOff_h
|