don't discard iframe children.
[kdelibs.git] / khtml / svg / animation / SVGSMILElement.h
blobfac102e6d3ecb21f671657fbb7ebe52f865397bf
1 /*
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
6 * are met:
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.
27 #ifndef SVGSMILElement_h
28 #define SVGSMILElement_h
29 #if ENABLE(SVG_ANIMATION)
31 #include "SVGElement.h"
32 #include "SMILTime.h"
33 #include <wtf/HashMap.h>
35 namespace WebCore {
37 class ConditionEventListener;
38 class SMILTimeContainer;
40 // This class implements SMIL interval timing model as needed for SVG animation.
41 class SVGSMILElement : public SVGElement
43 public:
44 SVGSMILElement(const QualifiedName&, Document*);
45 virtual ~SVGSMILElement();
47 static bool isSMILElement(Node* node);
49 virtual void parseMappedAttribute(MappedAttribute*);
50 virtual void attributeChanged(Attribute*, bool preserveDecls);
51 virtual void insertedIntoDocument();
52 virtual void removedFromDocument();
53 virtual void finishParsingChildren();
55 SMILTimeContainer* timeContainer() const { return m_timeContainer.get(); }
57 SVGElement* targetElement() const;
58 String attributeName() const;
60 void beginByLinkActivation();
62 enum Restart { RestartAlways, RestartWhenNotActive, RestartNever };
63 Restart restart() const;
65 enum FillMode { FillRemove, FillFreeze };
66 FillMode fill() const;
68 String xlinkHref() const;
70 SMILTime dur() const;
71 SMILTime repeatDur() const;
72 SMILTime repeatCount() const;
73 SMILTime maxValue() const;
74 SMILTime minValue() const;
76 SMILTime elapsed() const;
78 SMILTime intervalBegin() const { return m_intervalBegin; }
79 SMILTime intervalEnd() const { return m_intervalEnd; }
80 SMILTime previousIntervalBegin() const { return m_previousIntervalBegin; }
81 SMILTime simpleDuration() const;
83 void progress(SMILTime elapsed, SVGSMILElement* resultsElement);
84 SMILTime nextProgressTime() const;
86 static SMILTime parseClockValue(const String&);
87 static SMILTime parseOffsetValue(const String&);
89 bool isContributing(SMILTime elapsed) const;
90 bool isInactive() const;
91 bool isFrozen() const;
93 unsigned documentOrderIndex() const { return m_documentOrderIndex; }
94 void setDocumentOrderIndex(unsigned index) { m_documentOrderIndex = index; }
96 virtual bool isAdditive() const = 0;
97 virtual void resetToBaseValue(const String&) = 0;
98 virtual void applyResultsToTarget() = 0;
100 protected:
101 void addBeginTime(SMILTime time);
102 void addEndTime(SMILTime time);
104 private:
105 virtual void startedActiveInterval() = 0;
106 virtual void updateAnimation(float percent, unsigned repeat, SVGSMILElement* resultElement) = 0;
107 virtual void endedActiveInterval() = 0;
109 enum BeginOrEnd { Begin, End };
110 SMILTime findInstanceTime(BeginOrEnd beginOrEnd, SMILTime minimumTime, bool equalsMinimumOK) const;
111 void resolveFirstInterval();
112 void resolveNextInterval();
113 void resolveInterval(bool first, SMILTime& beginResult, SMILTime& endResult) const;
114 SMILTime resolveActiveEnd(SMILTime resolvedBegin, SMILTime resolvedEnd) const;
115 SMILTime repeatingDuration() const;
116 void checkRestart(SMILTime elapsed);
117 void beginListChanged();
118 void endListChanged();
119 void reschedule();
121 // This represents conditions on elements begin or end list that need to be resolved on runtime
122 // for example <animate begin="otherElement.begin + 8s; button.click" ... />
123 struct Condition {
124 enum Type { EventBase, Syncbase, AccessKey };
125 Condition(Type, BeginOrEnd beginOrEnd, const String& baseID, const String& name, SMILTime offset, int repeats = -1);
126 Type m_type;
127 BeginOrEnd m_beginOrEnd;
128 String m_baseID;
129 String m_name;
130 SMILTime m_offset;
131 int m_repeats;
132 RefPtr<Element> m_syncbase;
133 RefPtr<ConditionEventListener> m_eventListener;
135 bool parseCondition(const String&, BeginOrEnd beginOrEnd);
136 void parseBeginOrEnd(const String&, BeginOrEnd beginOrEnd);
138 void connectConditions();
139 void disconnectConditions();
141 // Event base timing
142 void handleConditionEvent(Event*, Condition*);
144 // Syncbase timing
145 enum NewOrExistingInterval { NewInterval, ExistingInterval };
146 void notifyDependentsIntervalChanged(NewOrExistingInterval);
147 void createInstanceTimesFromSyncbase(SVGSMILElement* syncbase, NewOrExistingInterval);
148 void addTimeDependent(SVGSMILElement*);
149 void removeTimeDependent(SVGSMILElement*);
151 enum ActiveState { Inactive, Active, Frozen };
152 ActiveState determineActiveState(SMILTime elapsed) const;
153 float calculateAnimationPercentAndRepeat(SMILTime elapsed, unsigned& repeat) const;
154 SMILTime calculateNextProgressTime(SMILTime elapsed) const;
156 Vector<Condition> m_conditions;
157 bool m_conditionsConnected;
158 bool m_hasEndEventConditions;
160 typedef HashSet<SVGSMILElement*> TimeDependentSet;
161 TimeDependentSet m_timeDependents;
163 // Instance time lists
164 Vector<SMILTime> m_beginTimes;
165 Vector<SMILTime> m_endTimes;
167 // This is the upcoming or current interval
168 SMILTime m_intervalBegin;
169 SMILTime m_intervalEnd;
171 SMILTime m_previousIntervalBegin;
173 bool m_isWaitingForFirstInterval;
175 ActiveState m_activeState;
176 float m_lastPercent;
177 unsigned m_lastRepeat;
179 SMILTime m_nextProgressTime;
181 RefPtr<SMILTimeContainer> m_timeContainer;
182 unsigned m_documentOrderIndex;
184 mutable SMILTime m_cachedDur;
185 mutable SMILTime m_cachedRepeatDur;
186 mutable SMILTime m_cachedRepeatCount;
187 mutable SMILTime m_cachedMin;
188 mutable SMILTime m_cachedMax;
190 friend class ConditionEventListener;
195 #endif
196 #endif