+2006-09-26 Eric Seidel <eric@eseidel.com>
+
+ Reviewed by mitz.
+
+ Bring animation back to life
+ http://bugzilla.opendarwin.org/show_bug.cgi?id=11021
+
+ Register/unregister SVGSVGElements as time containers on insertion/removal.
+ Replace uses of DeprecatedString with String in SVGAnimationElement
+ Various whitespace clean-up.
+
+ * ksvg2/misc/KSVGTimeScheduler.cpp:
+ (WebCore::SVGTimer::notifyAll):
+ * ksvg2/misc/SVGDocumentExtensions.cpp:
+ (WebCore::SVGDocumentExtensions::startAnimations):
+ (WebCore::SVGDocumentExtensions::pauseAnimations):
+ (WebCore::SVGDocumentExtensions::unpauseAnimations):
+ * ksvg2/svg/SVGAnimateTransformElement.cpp:
+ (WebCore::SVGAnimateTransformElement::handleTimerEvent):
+ (WebCore::SVGAnimateTransformElement::parseTransformValue):
+ * ksvg2/svg/SVGAnimateTransformElement.h:
+ * ksvg2/svg/SVGAnimationElement.cpp:
+ (WebCore::SVGAnimationElement::SVGAnimationElement):
+ (WebCore::SVGAnimationElement::parseMappedAttribute):
+ (WebCore::SVGAnimationElement::parseClockValue):
+ (WebCore::SVGAnimationElement::targetAttribute):
+ (WebCore::SVGAnimationElement::setTargetAttribute):
+ (WebCore::SVGAnimationElement::attributeName):
+ * ksvg2/svg/SVGAnimationElement.h:
+ (WebCore::SVGAnimationElement::rendererIsNeeded):
+ * ksvg2/svg/SVGSVGElement.cpp:
+ (WebCore::SVGSVGElement::getScreenCTM):
+ (WebCore::SVGSVGElement::createRenderer):
+ (WebCore::SVGSVGElement::insertedIntoDocument): added, calls addTimeContainer(this)
+ (WebCore::SVGSVGElement::removedFromDocument): added, calls removeTimeContainer(this)
+ * ksvg2/svg/SVGSVGElement.h:
+ * ksvg2/svg/SVGSetElement.cpp:
+ (WebCore::SVGSetElement::handleTimerEvent):
+ * ksvg2/svg/SVGURIReference.cpp:
+ (WebCore::SVGURIReference::getTarget):
+ * ksvg2/svg/SVGURIReference.h:
+
2006-09-26 Graham Dennis <graham.dennis@gmail.com>
Reviewed by mitzpettel.
}
else
#endif
- if(animation->hasTagName(SVGNames::animateColorTag))
- {
- SVGAnimateColorElement *animColor = static_cast<SVGAnimateColorElement *>(animation);
- if(!animColor)
+ if (animation->hasTagName(SVGNames::animateColorTag)) {
+ SVGAnimateColorElement* animColor = static_cast<SVGAnimateColorElement*>(animation);
+ if (!animColor)
continue;
String name = animColor->attributeName();
Color color = animColor->color();
- if(!targetColor.contains(name))
- {
- if(animation->isAdditive())
- {
+ if (!targetColor.contains(name)) {
+ if (animation->isAdditive()) {
int r = animColor->initialColor().red() + color.red();
int g = animColor->initialColor().green() + color.green();
int b = animColor->initialColor().blue() + color.blue();
targetColor.set(name, animColor->clampColor(r, g, b));
- }
- else
+ } else
targetColor.set(name, color);
- }
- else
- {
- if(!animation->isAdditive())
+ } else {
+ if (!animation->isAdditive())
targetColor.set(name, color);
- else
- {
+ else {
Color baseColor = targetColor.get(name);
int r = baseColor.red() + color.red();
int g = baseColor.green() + color.green();
if (targetTransforms) {
SVGElement* key = targetIterator->first;
if (key && key->isStyled() && key->isStyledTransformable()) {
- SVGStyledTransformableElement *transform = static_cast<SVGStyledTransformableElement *>(key);
+ SVGStyledTransformableElement* transform = static_cast<SVGStyledTransformableElement*>(key);
transform->setTransform(targetTransforms.get());
transform->updateLocalTransform(transform->transform());
}
// Handle <animateColor>.
HashMap<String, Color>::iterator cend = targetColor.end();
- for(HashMap<String, Color>::iterator cit = targetColor.begin(); cit != cend; ++cit)
- {
- if(cit->second.isValid())
- {
- SVGAnimationElement::setTargetAttribute(targetIterator->first,
- cit->first.impl(),
- String(cit->second.name()).impl());
- }
+ for (HashMap<String, Color>::iterator cit = targetColor.begin(); cit != cend; ++cit) {
+ if (cit->second.isValid())
+ SVGAnimationElement::setTargetAttribute(targetIterator->first, cit->first, cit->second.name());
}
}
// Make a second pass through the map to avoid multiple setChanged calls on the same element.
for (targetIterator = targetMap.begin(); targetIterator != tend; ++targetIterator) {
- SVGElement *key = targetIterator->first;
+ SVGElement* key = targetIterator->first;
if (key && key->isStyled())
- static_cast<SVGStyledElement *>(key)->setChanged(true);
+ static_cast<SVGStyledElement*>(key)->setChanged(true);
}
}
// FIXME: Eventually every "Time Container" will need a way to latch on to some global timer
// starting animations for a document will do this "latching"
- HashSet<SVGSVGElement*>::iterator end = m_timeContainers.begin();
+ HashSet<SVGSVGElement*>::iterator end = m_timeContainers.end();
for (HashSet<SVGSVGElement*>::iterator itr = m_timeContainers.begin(); itr != end; ++itr)
(*itr)->timeScheduler()->startAnimations();
}
void SVGDocumentExtensions::pauseAnimations()
{
- HashSet<SVGSVGElement*>::iterator end = m_timeContainers.begin();
+ HashSet<SVGSVGElement*>::iterator end = m_timeContainers.end();
for (HashSet<SVGSVGElement*>::iterator itr = m_timeContainers.begin(); itr != end; ++itr)
(*itr)->pauseAnimations();
}
void SVGDocumentExtensions::unpauseAnimations()
{
- HashSet<SVGSVGElement*>::iterator end = m_timeContainers.begin();
+ HashSet<SVGSVGElement*>::iterator end = m_timeContainers.end();
for (HashSet<SVGSVGElement*>::iterator itr = m_timeContainers.begin(); itr != end; ++itr)
(*itr)->unpauseAnimations();
}
useTimePercentage = 1.0;
}
- m_toTransform = parseTransformValue(value2.deprecatedString());
+ m_toTransform = parseTransformValue(value2);
m_toRotateSpecialCase = m_rotateSpecialCase;
- m_fromTransform = parseTransformValue(value1.deprecatedString());
+ m_fromTransform = parseTransformValue(value1);
m_fromRotateSpecialCase = m_rotateSpecialCase;
m_currentItem = itemByPercentage;
}
}
-RefPtr<SVGTransform> SVGAnimateTransformElement::parseTransformValue(const DeprecatedString &data) const
+RefPtr<SVGTransform> SVGAnimateTransformElement::parseTransformValue(const String& data) const
{
- DeprecatedString parse = data.stripWhiteSpace();
+ DeprecatedString parse = data.deprecatedString().stripWhiteSpace();
if (parse.isEmpty())
return 0;
Boston, MA 02111-1307, USA.
*/
-#ifndef KSVG_SVGAnimateTransformElementImpl_H
-#define KSVG_SVGAnimateTransformElementImpl_H
+#ifndef SVGAnimateTransformElement_H
+#define SVGAnimateTransformElement_H
#ifdef SVG_SUPPORT
#include "SVGTransform.h"
SVGAnimateTransformElement(const QualifiedName&, Document*);
virtual ~SVGAnimateTransformElement();
- virtual void parseMappedAttribute(MappedAttribute *attr);
+ virtual void parseMappedAttribute(MappedAttribute*);
virtual void handleTimerEvent(double timePercentage);
// Helpers
- RefPtr<SVGTransform> parseTransformValue(const DeprecatedString &data) const;
- void calculateRotationFromMatrix(const AffineTransform &matrix, double &angle, double &cx, double &cy) const;
+ RefPtr<SVGTransform> parseTransformValue(const String&) const;
+ void calculateRotationFromMatrix(const AffineTransform&, double &angle, double &cx, double &cy) const;
- SVGMatrix *initialMatrix() const;
- SVGMatrix *transformMatrix() const;
+ SVGMatrix* initialMatrix() const;
+ SVGMatrix* transformMatrix() const;
protected:
virtual const SVGElement* contextElement() const { return this; }
} // namespace WebCore
#endif // SVG_SUPPORT
-#endif // KSVG_SVGAnimateTransformElementImpl_H
+#endif // SVGAnimateTransformElement_H
// vim:ts=4:noet
#include <math.h>
#include <wtf/Vector.h>
-using namespace WebCore;
using namespace std;
-SVGAnimationElement::SVGAnimationElement(const QualifiedName& tagName, Document *doc)
-: SVGElement(tagName, doc), SVGTests(), SVGExternalResourcesRequired()
+namespace WebCore {
+
+SVGAnimationElement::SVGAnimationElement(const QualifiedName& tagName, Document* doc)
+ : SVGElement(tagName, doc)
+ , SVGTests()
+ , SVGExternalResourcesRequired()
+ , m_targetElement(0)
+ , m_connected(false)
+ , m_currentTime(0.0)
+ , m_simpleDuration(0.0)
+ , m_fill(FILL_REMOVE)
+ , m_restart(RESTART_ALWAYS)
+ , m_calcMode(CALCMODE_LINEAR)
+ , m_additive(ADDITIVE_REPLACE)
+ , m_accumulate(ACCUMULATE_NONE)
+ , m_attributeType(ATTRIBUTETYPE_AUTO)
+ , m_max(0.0)
+ , m_min(0.0)
+ , m_end(0.0)
+ , m_begin(0.0)
+ , m_repeations(0)
+ , m_repeatCount(0)
{
- m_connected = false;
- m_targetElement = 0;
-
- m_currentTime = 0.0;
- m_simpleDuration = 0.0;
-
- // Initialize shared properties...
- m_end = 0.0;
- m_min = 0.0;
- m_max = 0.0;
- m_begin = 0.0;
-
- m_repeations = 0;
- m_repeatCount = 0;
-
- m_fill = FILL_REMOVE;
- m_restart = RESTART_ALWAYS;
- m_calcMode = CALCMODE_LINEAR;
- m_additive = ADDITIVE_REPLACE;
- m_accumulate = ACCUMULATE_NONE;
- m_attributeType = ATTRIBUTETYPE_AUTO;
}
SVGAnimationElement::~SVGAnimationElement()
{
const String& value = attr->value();
if (attr->name().matches(XLinkNames::hrefAttr))
- m_href = value.deprecatedString();
+ m_href = value;
else if (attr->name() == SVGNames::attributeNameAttr)
- m_attributeName = value.deprecatedString();
+ m_attributeName = value;
else if (attr->name() == SVGNames::attributeTypeAttr)
{
if (value == "CSS")
// Parse data
for (unsigned int i = 0; i < temp->numberOfItems(); i++) {
- DeprecatedString current = String(temp->getItem(i, ec)).deprecatedString();
+ String current = temp->getItem(i, ec);
if (current.startsWith("accessKey")) {
// Register keyDownEventListener for the character
- DeprecatedString character = current.mid(current.length() - 2, 1);
+ String character = current.substring(current.length() - 2, 1);
// FIXME: Not implemented! Supposed to register accessKey character
} else if (current.startsWith("wallclock")) {
int firstBrace = current.find('(');
int secondBrace = current.find(')');
- DeprecatedString wallclockValue = current.mid(firstBrace + 1, secondBrace - firstBrace - 2);
+ String wallclockValue = current.substring(firstBrace + 1, secondBrace - firstBrace - 2);
// FIXME: Not implemented! Supposed to use wallClock value
} else if (current.contains('.')) {
int dotPosition = current.find('.');
- DeprecatedString element = current.mid(0, dotPosition);
- DeprecatedString clockValue;
+ String element = current.substring(0, dotPosition);
+ String clockValue;
if (current.contains("begin"))
- clockValue = current.mid(dotPosition + 6);
+ clockValue = current.substring(dotPosition + 6);
else if (current.contains("end"))
- clockValue = current.mid(dotPosition + 4);
+ clockValue = current.substring(dotPosition + 4);
else if (current.contains("repeat"))
- clockValue = current.mid(dotPosition + 7);
+ clockValue = current.substring(dotPosition + 7);
else // DOM2 Event Reference
{
int plusMinusPosition = -1;
else if (current.contains('-'))
plusMinusPosition = current.find('-');
- DeprecatedString event = current.mid(dotPosition + 1, plusMinusPosition - dotPosition - 1);
- clockValue = current.mid(dotPosition + event.length() + 1);
+ String event = current.substring(dotPosition + 1, plusMinusPosition - dotPosition - 1);
+ clockValue = current.substring(dotPosition + event.length() + 1);
// FIXME: supposed to use DOM Event
}
} else {
}
else if (attr->name() == SVGNames::durAttr)
{
- m_simpleDuration = parseClockValue(value.deprecatedString());
+ m_simpleDuration = parseClockValue(value);
if (!isIndefinite(m_simpleDuration))
m_simpleDuration *= 1000.0;
}
else if (attr->name() == SVGNames::minAttr)
{
- m_min = parseClockValue(value.deprecatedString());
+ m_min = parseClockValue(value);
if (!isIndefinite(m_min))
m_min *= 1000.0;
}
else if (attr->name() == SVGNames::maxAttr)
{
- m_max = parseClockValue(value.deprecatedString());
+ m_max = parseClockValue(value);
if (!isIndefinite(m_max))
m_max *= 1000.0;
}
m_repeatCount = value.toDouble();
}
else if (attr->name() == SVGNames::repeatDurAttr)
- m_repeatDur = value.deprecatedString();
+ m_repeatDur = value;
else if (attr->name() == SVGNames::fillAttr)
{
if (value == "freeze")
SVGHelper::parseSeparatedList(m_keySplines.get(), value, ';');
}
else if (attr->name() == SVGNames::fromAttr)
- m_from = value.deprecatedString();
+ m_from = value;
else if (attr->name() == SVGNames::toAttr)
- m_to = value.deprecatedString();
+ m_to = value;
else if (attr->name() == SVGNames::byAttr)
- m_by = value.deprecatedString();
+ m_by = value;
else if (attr->name() == SVGNames::additiveAttr)
{
if (value == "sum")
}
}
-double SVGAnimationElement::parseClockValue(const DeprecatedString &data) const
+double SVGAnimationElement::parseClockValue(const String& data) const
{
- DeprecatedString parse = data.stripWhiteSpace();
+ DeprecatedString parse = data.deprecatedString().stripWhiteSpace();
if (parse == "indefinite") // Saves some time...
return DBL_MAX;
}
if (attributeType == ATTRIBUTETYPE_XML || ret.isEmpty())
- ret = targetElement()->getAttribute(String(m_attributeName).impl());
+ ret = targetElement()->getAttribute(m_attributeName);
return ret;
}
-void SVGAnimationElement::setTargetAttribute(StringImpl *value)
+void SVGAnimationElement::setTargetAttribute(const String& value)
{
- SVGAnimationElement::setTargetAttribute(targetElement(), String(m_attributeName).impl(), value, static_cast<EAttributeType>(m_attributeType));
+ SVGAnimationElement::setTargetAttribute(targetElement(), m_attributeName, value, static_cast<EAttributeType>(m_attributeType));
}
-void SVGAnimationElement::setTargetAttribute(SVGElement *target, StringImpl *nameImpl, StringImpl *value, EAttributeType type)
+void SVGAnimationElement::setTargetAttribute(SVGElement* target, const String& name, const String& value, EAttributeType type)
{
- if (!target || !nameImpl || !value)
+ if (!target || name.isNull() || value.isNull())
return;
- String name(nameImpl);
- SVGStyledElement *styled = NULL;
- if (target && target->isStyled())
- styled = static_cast<SVGStyledElement *>(target);
+ SVGStyledElement* styled = (target && target->isStyled()) ? static_cast<SVGStyledElement*>(target) : 0;
EAttributeType attributeType = type;
- if (type == ATTRIBUTETYPE_AUTO)
- {
- attributeType = ATTRIBUTETYPE_XML;
-
+ if (type == ATTRIBUTETYPE_AUTO) {
// Spec: The implementation should match the attributeName to an attribute
// for the target element. The implementation must first search through the
// list of CSS properties for a matching property name, and if none is found,
// search the default XML namespace for the element.
- if (styled && styled->style()) {
- if (styled->style()->getPropertyCSSValue(name))
- attributeType = ATTRIBUTETYPE_CSS;
- }
+ if (styled && styled->style() && styled->style()->getPropertyCSSValue(name))
+ attributeType = ATTRIBUTETYPE_CSS;
+ else
+ attributeType = ATTRIBUTETYPE_XML;
}
ExceptionCode ec = 0;
if (attributeType == ATTRIBUTETYPE_CSS && styled && styled->style())
styled->style()->setProperty(name, value, "", ec);
else if (attributeType == ATTRIBUTETYPE_XML)
- target->setAttribute(nameImpl, value, ec);
+ target->setAttribute(name, value, ec);
}
-DeprecatedString SVGAnimationElement::attributeName() const
+String SVGAnimationElement::attributeName() const
{
return m_attributeName;
}
return (value == DBL_MAX);
}
+}
+
// vim:ts=4:noet
#endif // SVG_SUPPORT
Boston, MA 02111-1307, USA.
*/
-#ifndef KSVG_SVGAnimationElementImpl_H
-#define KSVG_SVGAnimationElementImpl_H
+#ifndef SVGAnimationElement_H
+#define SVGAnimationElement_H
#ifdef SVG_SUPPORT
#include "SVGExternalResourcesRequired.h"
virtual ~SVGAnimationElement();
// 'SVGAnimationElement' functions
- SVGElement *targetElement() const;
+ SVGElement* targetElement() const;
virtual bool isValid() const { return SVGTests::isValid(); }
double getSimpleDuration(ExceptionCode&) const;
virtual void parseMappedAttribute(MappedAttribute *attr);
- virtual bool rendererIsNeeded(RenderStyle *) { return false; }
+ virtual bool rendererIsNeeded(RenderStyle*) { return false; }
virtual void closeRenderer();
// Helpers
virtual void handleTimerEvent(double timePercentage) = 0;
- double parseClockValue(const DeprecatedString &data) const;
+ double parseClockValue(const String&) const;
String targetAttribute() const;
- void setTargetAttribute(StringImpl *value);
+ void setTargetAttribute(const String&);
- static void setTargetAttribute(SVGElement *target,
- StringImpl *name,
- StringImpl *value,
- EAttributeType type = ATTRIBUTETYPE_AUTO);
+ static void setTargetAttribute(SVGElement* target, const String& name, const String& value, EAttributeType = ATTRIBUTETYPE_AUTO);
- DeprecatedString attributeName() const;
+ String attributeName() const;
bool connected() const;
bool isIndefinite(double value) const;
protected:
- mutable SVGElement *m_targetElement;
+ mutable SVGElement* m_targetElement;
ANIMATED_PROPERTY_FORWARD_DECLARATIONS(SVGExternalResourcesRequired, bool, ExternalResourcesRequired, externalResourcesRequired)
unsigned m_accumulate : 1; // EAccumulateMode
unsigned m_attributeType : 2; // EAttributeType
- DeprecatedString m_to;
- DeprecatedString m_by;
- DeprecatedString m_from;
- DeprecatedString m_href;
- DeprecatedString m_repeatDur;
- DeprecatedString m_attributeName;
+ String m_to;
+ String m_by;
+ String m_from;
+ String m_href;
+ String m_repeatDur;
+ String m_attributeName;
double m_max;
double m_min;
} // namespace WebCore
#endif // SVG_SUPPORT
-#endif // KSVG_SVGAnimationElementImpl_H
+#endif // SVGAnimationElement_H
// vim:ts=4:noet
SVGMatrix *SVGSVGElement::getScreenCTM() const
{
SVGMatrix *mat = SVGStyledLocatableElement::getScreenCTM();
- if(mat)
- {
+ if(mat) {
mat->translate(x()->value(), y()->value());
- if(attributes()->getNamedItem(SVGNames::viewBoxAttr))
- {
+ if (attributes()->getNamedItem(SVGNames::viewBoxAttr)) {
RefPtr<SVGMatrix> viewBox = viewBoxToViewTransform(width()->value(), height()->value());
mat->multiply(viewBox.get());
}
RenderObject* SVGSVGElement::createRenderer(RenderArena* arena, RenderStyle*)
{
- RenderSVGContainer *rootContainer = new (arena) RenderSVGContainer(this);
+ RenderSVGContainer* rootContainer = new (arena) RenderSVGContainer(this);
// FIXME: all this setup should be done after attributesChanged, not here.
- float _x = x()->value();
- float _y = y()->value();
- float _width = width()->value();
- float _height = height()->value();
-
- rootContainer->setViewport(FloatRect(_x, _y, _width, _height));
+ rootContainer->setViewport(FloatRect(x()->value(), y()->value(), width()->value(), height()->value()));
rootContainer->setViewBox(viewBox());
rootContainer->setAlign(KCAlign(preserveAspectRatio()->align() - 1));
rootContainer->setSlice(preserveAspectRatio()->meetOrSlice() == SVGPreserveAspectRatio::SVG_MEETORSLICE_SLICE);
return rootContainer;
}
+void SVGSVGElement::insertedIntoDocument()
+{
+ document()->accessSVGExtensions()->addTimeContainer(this);
+ SVGStyledLocatableElement::insertedIntoDocument();
+}
+
+void SVGSVGElement::removedFromDocument()
+{
+ document()->accessSVGExtensions()->removeTimeContainer(this);
+ SVGStyledLocatableElement::removedFromDocument();
+}
+
void SVGSVGElement::setZoomAndPan(unsigned short zoomAndPan)
{
SVGZoomAndPan::setZoomAndPan(zoomAndPan);
virtual bool rendererIsNeeded(RenderStyle *style) { return StyledElement::rendererIsNeeded(style); }
virtual RenderObject* createRenderer(RenderArena *arena, RenderStyle *style);
+
+ virtual void insertedIntoDocument();
+ virtual void removedFromDocument();
// 'virtual SVGZoomAndPan functions
virtual void setZoomAndPan(unsigned short zoomAndPan);
// Commit change now...
if (m_savedTo.isEmpty()) {
- String attr(targetAttribute());
- m_savedTo = attr.deprecatedString();
- setTargetAttribute(String(m_to).impl());
+ m_savedTo = targetAttribute().deprecatedString();
+ setTargetAttribute(m_to);
}
// End condition.
m_connected = false;
if (!isFrozen())
- setTargetAttribute(String(m_savedTo).impl());
+ setTargetAttribute(m_savedTo);
m_savedTo = DeprecatedString();
}
return false;
}
-DeprecatedString SVGURIReference::getTarget(const DeprecatedString &url)
+String SVGURIReference::getTarget(const String& url)
{
- if (url.startsWith("url(")) { // URI References, ie. fill:url(#target)
- unsigned int start = url.find('#') + 1;
- unsigned int end = url.findRev(')');
+ DeprecatedString urlDeprecated = url.deprecatedString(); // FIXME: Needed until findRev exists for String
+ if (urlDeprecated.startsWith("url(")) { // URI References, ie. fill:url(#target)
+ unsigned int start = urlDeprecated.find('#') + 1;
+ unsigned int end = urlDeprecated.findRev(')');
- return url.mid(start, end - start);
+ return urlDeprecated.mid(start, end - start);
} else if (url.find('#') > -1) { // format is #target
unsigned int start = url.find('#') + 1;
- return url.mid(start, url.length() - start);
+ return url.substring(start, url.length() - start);
} else // Normal Reference, ie. style="color-profile:changeColor"
return url;
}
#ifdef SVG_SUPPORT
#include "SVGElement.h"
-#include "DeprecatedString.h"
namespace WebCore {
virtual ~SVGURIReference();
// 'SVGURIReference' functions
- bool parseMappedAttribute(MappedAttribute *attr);
+ bool parseMappedAttribute(MappedAttribute*);
// Helpers
- static DeprecatedString getTarget(const DeprecatedString &url);
+ static String getTarget(const String& url);
protected:
virtual const SVGElement* contextElement() const = 0;