KHTML
SVGSMILElement.h
Go to the documentation of this file.
00001 /* 00002 * Copyright (C) 2008 Apple Inc. All Rights Reserved. 00003 * 00004 * Redistribution and use in source and binary forms, with or without 00005 * modification, are permitted provided that the following conditions 00006 * are met: 00007 * 1. Redistributions of source code must retain the above copyright 00008 * notice, this list of conditions and the following disclaimer. 00009 * 2. Redistributions in binary form must reproduce the above copyright 00010 * notice, this list of conditions and the following disclaimer in the 00011 * documentation and/or other materials provided with the distribution. 00012 * 00013 * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY 00014 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 00015 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 00016 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR 00017 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 00018 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 00019 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 00020 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY 00021 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 00022 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 00023 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 00024 */ 00025 00026 00027 #ifndef SVGSMILElement_h 00028 #define SVGSMILElement_h 00029 #if ENABLE(SVG_ANIMATION) 00030 00031 #include "SVGElement.h" 00032 #include "SMILTime.h" 00033 #include <wtf/HashMap.h> 00034 00035 namespace WebCore { 00036 00037 class ConditionEventListener; 00038 class SMILTimeContainer; 00039 00040 // This class implements SMIL interval timing model as needed for SVG animation. 00041 class SVGSMILElement : public SVGElement 00042 { 00043 public: 00044 SVGSMILElement(const QualifiedName&, Document*); 00045 virtual ~SVGSMILElement(); 00046 00047 static bool isSMILElement(Node* node); 00048 00049 virtual void parseMappedAttribute(MappedAttribute*); 00050 virtual void attributeChanged(Attribute*, bool preserveDecls); 00051 virtual void insertedIntoDocument(); 00052 virtual void removedFromDocument(); 00053 virtual void finishParsingChildren(); 00054 00055 SMILTimeContainer* timeContainer() const { return m_timeContainer.get(); } 00056 00057 SVGElement* targetElement() const; 00058 String attributeName() const; 00059 00060 void beginByLinkActivation(); 00061 00062 enum Restart { RestartAlways, RestartWhenNotActive, RestartNever }; 00063 Restart restart() const; 00064 00065 enum FillMode { FillRemove, FillFreeze }; 00066 FillMode fill() const; 00067 00068 String xlinkHref() const; 00069 00070 SMILTime dur() const; 00071 SMILTime repeatDur() const; 00072 SMILTime repeatCount() const; 00073 SMILTime maxValue() const; 00074 SMILTime minValue() const; 00075 00076 SMILTime elapsed() const; 00077 00078 SMILTime intervalBegin() const { return m_intervalBegin; } 00079 SMILTime intervalEnd() const { return m_intervalEnd; } 00080 SMILTime previousIntervalBegin() const { return m_previousIntervalBegin; } 00081 SMILTime simpleDuration() const; 00082 00083 void progress(SMILTime elapsed, SVGSMILElement* resultsElement); 00084 SMILTime nextProgressTime() const; 00085 00086 static SMILTime parseClockValue(const String&); 00087 static SMILTime parseOffsetValue(const String&); 00088 00089 bool isContributing(SMILTime elapsed) const; 00090 bool isInactive() const; 00091 bool isFrozen() const; 00092 00093 unsigned documentOrderIndex() const { return m_documentOrderIndex; } 00094 void setDocumentOrderIndex(unsigned index) { m_documentOrderIndex = index; } 00095 00096 virtual bool isAdditive() const = 0; 00097 virtual void resetToBaseValue(const String&) = 0; 00098 virtual void applyResultsToTarget() = 0; 00099 00100 protected: 00101 void addBeginTime(SMILTime time); 00102 void addEndTime(SMILTime time); 00103 00104 private: 00105 virtual void startedActiveInterval() = 0; 00106 virtual void updateAnimation(float percent, unsigned repeat, SVGSMILElement* resultElement) = 0; 00107 virtual void endedActiveInterval() = 0; 00108 00109 enum BeginOrEnd { Begin, End }; 00110 SMILTime findInstanceTime(BeginOrEnd beginOrEnd, SMILTime minimumTime, bool equalsMinimumOK) const; 00111 void resolveFirstInterval(); 00112 void resolveNextInterval(); 00113 void resolveInterval(bool first, SMILTime& beginResult, SMILTime& endResult) const; 00114 SMILTime resolveActiveEnd(SMILTime resolvedBegin, SMILTime resolvedEnd) const; 00115 SMILTime repeatingDuration() const; 00116 void checkRestart(SMILTime elapsed); 00117 void beginListChanged(); 00118 void endListChanged(); 00119 void reschedule(); 00120 00121 // This represents conditions on elements begin or end list that need to be resolved on runtime 00122 // for example <animate begin="otherElement.begin + 8s; button.click" ... /> 00123 struct Condition { 00124 enum Type { EventBase, Syncbase, AccessKey }; 00125 Condition(Type, BeginOrEnd beginOrEnd, const String& baseID, const String& name, SMILTime offset, int repeats = -1); 00126 Type m_type; 00127 BeginOrEnd m_beginOrEnd; 00128 String m_baseID; 00129 String m_name; 00130 SMILTime m_offset; 00131 int m_repeats; 00132 RefPtr<Element> m_syncbase; 00133 RefPtr<ConditionEventListener> m_eventListener; 00134 }; 00135 bool parseCondition(const String&, BeginOrEnd beginOrEnd); 00136 void parseBeginOrEnd(const String&, BeginOrEnd beginOrEnd); 00137 00138 void connectConditions(); 00139 void disconnectConditions(); 00140 00141 // Event base timing 00142 void handleConditionEvent(Event*, Condition*); 00143 00144 // Syncbase timing 00145 enum NewOrExistingInterval { NewInterval, ExistingInterval }; 00146 void notifyDependentsIntervalChanged(NewOrExistingInterval); 00147 void createInstanceTimesFromSyncbase(SVGSMILElement* syncbase, NewOrExistingInterval); 00148 void addTimeDependent(SVGSMILElement*); 00149 void removeTimeDependent(SVGSMILElement*); 00150 00151 enum ActiveState { Inactive, Active, Frozen }; 00152 ActiveState determineActiveState(SMILTime elapsed) const; 00153 float calculateAnimationPercentAndRepeat(SMILTime elapsed, unsigned& repeat) const; 00154 SMILTime calculateNextProgressTime(SMILTime elapsed) const; 00155 00156 Vector<Condition> m_conditions; 00157 bool m_conditionsConnected; 00158 bool m_hasEndEventConditions; 00159 00160 typedef HashSet<SVGSMILElement*> TimeDependentSet; 00161 TimeDependentSet m_timeDependents; 00162 00163 // Instance time lists 00164 Vector<SMILTime> m_beginTimes; 00165 Vector<SMILTime> m_endTimes; 00166 00167 // This is the upcoming or current interval 00168 SMILTime m_intervalBegin; 00169 SMILTime m_intervalEnd; 00170 00171 SMILTime m_previousIntervalBegin; 00172 00173 bool m_isWaitingForFirstInterval; 00174 00175 ActiveState m_activeState; 00176 float m_lastPercent; 00177 unsigned m_lastRepeat; 00178 00179 SMILTime m_nextProgressTime; 00180 00181 RefPtr<SMILTimeContainer> m_timeContainer; 00182 unsigned m_documentOrderIndex; 00183 00184 mutable SMILTime m_cachedDur; 00185 mutable SMILTime m_cachedRepeatDur; 00186 mutable SMILTime m_cachedRepeatCount; 00187 mutable SMILTime m_cachedMin; 00188 mutable SMILTime m_cachedMax; 00189 00190 friend class ConditionEventListener; 00191 }; 00192 00193 } 00194 00195 #endif 00196 #endif 00197
KDE 4.6 API Reference