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.
27 #ifndef SVGSMILElement_h
28 #define SVGSMILElement_h
29 #if ENABLE(SVG_ANIMATION)
31 #include "SVGElement.h"
33 #include <wtf/HashMap.h>
37 class ConditionEventListener
;
38 class SMILTimeContainer
;
40 // This class implements SMIL interval timing model as needed for SVG animation.
41 class SVGSMILElement
: public SVGElement
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;
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;
101 void addBeginTime(SMILTime time
);
102 void addEndTime(SMILTime time
);
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();
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" ... />
124 enum Type
{ EventBase
, Syncbase
, AccessKey
};
125 Condition(Type
, BeginOrEnd beginOrEnd
, const String
& baseID
, const String
& name
, SMILTime offset
, int repeats
= -1);
127 BeginOrEnd m_beginOrEnd
;
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();
142 void handleConditionEvent(Event
*, Condition
*);
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
;
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
;