2 * Copyright (C) 2008 Apple Inc. All rights reserved.
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
13 * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
14 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
16 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR
17 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
18 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
19 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
20 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
21 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
23 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 #ifndef SVGSMILElement_h
27 #define SVGSMILElement_h
28 #if ENABLE(SVG_ANIMATION)
30 #include "SVGElement.h"
32 #include <wtf/HashMap.h>
36 class ConditionEventListener;
37 class SMILTimeContainer;
39 // This class implements SMIL interval timing model as needed for SVG animation.
40 class SVGSMILElement : public SVGElement {
42 SVGSMILElement(const QualifiedName&, Document*);
43 virtual ~SVGSMILElement();
45 static bool isSMILElement(Node*);
47 virtual void parseMappedAttribute(Attribute*);
48 virtual void attributeChanged(Attribute*, bool preserveDecls);
49 virtual void insertedIntoDocument();
50 virtual void removedFromDocument();
52 virtual bool hasValidAttributeType() = 0;
54 SMILTimeContainer* timeContainer() const { return m_timeContainer.get(); }
56 SVGElement* targetElement();
57 void resetTargetElement() { m_targetElement = 0; }
58 const QualifiedName& attributeName() const { return m_attributeName; }
60 void beginByLinkActivation();
68 Restart restart() const;
75 FillMode fill() const;
77 String xlinkHref() const;
80 SMILTime repeatDur() const;
81 SMILTime repeatCount() const;
82 SMILTime maxValue() const;
83 SMILTime minValue() const;
85 SMILTime elapsed() const;
87 SMILTime intervalBegin() const { return m_intervalBegin; }
88 SMILTime intervalEnd() const { return m_intervalEnd; }
89 SMILTime previousIntervalBegin() const { return m_previousIntervalBegin; }
90 SMILTime simpleDuration() const;
92 void progress(SMILTime elapsed, SVGSMILElement* resultsElement);
93 SMILTime nextProgressTime() const;
95 static SMILTime parseClockValue(const String&);
96 static SMILTime parseOffsetValue(const String&);
98 bool isContributing(SMILTime elapsed) const;
99 bool isInactive() const;
100 bool isFrozen() const;
102 unsigned documentOrderIndex() const { return m_documentOrderIndex; }
103 void setDocumentOrderIndex(unsigned index) { m_documentOrderIndex = index; }
105 virtual bool isAdditive() const = 0;
106 virtual void resetToBaseValue(const String&) = 0;
107 virtual void applyResultsToTarget() = 0;
110 void addBeginTime(SMILTime eventTime, SMILTime endTime);
111 void addEndTime(SMILTime eventTime, SMILTime endTime);
113 void setInactive() { m_activeState = Inactive; }
116 virtual void startedActiveInterval() = 0;
117 virtual void updateAnimation(float percent, unsigned repeat, SVGSMILElement* resultElement) = 0;
118 virtual void endedActiveInterval() = 0;
125 SMILTime findInstanceTime(BeginOrEnd, SMILTime minimumTime, bool equalsMinimumOK) const;
126 void resolveFirstInterval();
127 void resolveNextInterval();
128 void resolveInterval(bool first, SMILTime& beginResult, SMILTime& endResult) const;
129 SMILTime resolveActiveEnd(SMILTime resolvedBegin, SMILTime resolvedEnd) const;
130 SMILTime repeatingDuration() const;
131 void checkRestart(SMILTime elapsed);
132 void beginListChanged(SMILTime eventTime);
133 void endListChanged(SMILTime eventTime);
136 // This represents conditions on elements begin or end list that need to be resolved on runtime
137 // for example <animate begin="otherElement.begin + 8s; button.click" ... />
145 Condition(Type, BeginOrEnd, const String& baseID, const String& name, SMILTime offset, int repeats = -1);
147 BeginOrEnd m_beginOrEnd;
152 RefPtr<Element> m_syncbase;
153 RefPtr<ConditionEventListener> m_eventListener;
155 bool parseCondition(const String&, BeginOrEnd beginOrEnd);
156 void parseBeginOrEnd(const String&, BeginOrEnd beginOrEnd);
157 Element* eventBaseFor(const Condition&);
159 void connectConditions();
160 void disconnectConditions();
163 void handleConditionEvent(Event*, Condition*);
166 enum NewOrExistingInterval {
171 void notifyDependentsIntervalChanged(NewOrExistingInterval);
172 void createInstanceTimesFromSyncbase(SVGSMILElement* syncbase, NewOrExistingInterval);
173 void addTimeDependent(SVGSMILElement*);
174 void removeTimeDependent(SVGSMILElement*);
182 QualifiedName m_attributeName;
184 ActiveState determineActiveState(SMILTime elapsed) const;
185 float calculateAnimationPercentAndRepeat(SMILTime elapsed, unsigned& repeat) const;
186 SMILTime calculateNextProgressTime(SMILTime elapsed) const;
188 mutable SVGElement* m_targetElement;
190 Vector<Condition> m_conditions;
191 bool m_conditionsConnected;
192 bool m_hasEndEventConditions;
194 bool m_isWaitingForFirstInterval;
196 typedef HashSet<SVGSMILElement*> TimeDependentSet;
197 TimeDependentSet m_timeDependents;
199 // Instance time lists
200 Vector<SMILTime> m_beginTimes;
201 Vector<SMILTime> m_endTimes;
203 // This is the upcoming or current interval
204 SMILTime m_intervalBegin;
205 SMILTime m_intervalEnd;
207 SMILTime m_previousIntervalBegin;
209 ActiveState m_activeState;
211 unsigned m_lastRepeat;
213 SMILTime m_nextProgressTime;
215 RefPtr<SMILTimeContainer> m_timeContainer;
216 unsigned m_documentOrderIndex;
218 mutable SMILTime m_cachedDur;
219 mutable SMILTime m_cachedRepeatDur;
220 mutable SMILTime m_cachedRepeatCount;
221 mutable SMILTime m_cachedMin;
222 mutable SMILTime m_cachedMax;
224 friend class ConditionEventListener;
229 #endif // ENABLE(SVG)
230 #endif // SVGSMILElement_h