KHtml

SVGSMILElement.h
1 /*
2  * Copyright (C) 2008 Apple Inc. All Rights Reserved.
3  *
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.
12  *
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.
24  */
25 
26 #ifndef SVGSMILElement_h
27 #define SVGSMILElement_h
28 #if ENABLE(SVG_ANIMATION)
29 
30 #include "SVGElement.h"
31 #include "SMILTime.h"
32 #include <wtf/HashMap.h>
33 
34 namespace WebCore
35 {
36 
37 class ConditionEventListener;
38 class SMILTimeContainer;
39 
40 // This class implements SMIL interval timing model as needed for SVG animation.
41 class SVGSMILElement : public SVGElement
42 {
43 public:
44  SVGSMILElement(const QualifiedName &, Document *);
45  virtual ~SVGSMILElement();
46 
47  static bool isSMILElement(Node *node);
48 
49  virtual void parseMappedAttribute(MappedAttribute *);
50  virtual void attributeChanged(Attribute *, bool preserveDecls);
51  virtual void insertedIntoDocument();
52  virtual void removedFromDocument();
53  virtual void finishParsingChildren();
54 
55  SMILTimeContainer *timeContainer() const
56  {
57  return m_timeContainer.get();
58  }
59 
60  SVGElement *targetElement() const;
61  String attributeName() const;
62 
63  void beginByLinkActivation();
64 
65  enum Restart { RestartAlways, RestartWhenNotActive, RestartNever };
66  Restart restart() const;
67 
68  enum FillMode { FillRemove, FillFreeze };
69  FillMode fill() const;
70 
71  String xlinkHref() const;
72 
73  SMILTime dur() const;
74  SMILTime repeatDur() const;
75  SMILTime repeatCount() const;
76  SMILTime maxValue() const;
77  SMILTime minValue() const;
78 
79  SMILTime elapsed() const;
80 
81  SMILTime intervalBegin() const
82  {
83  return m_intervalBegin;
84  }
85  SMILTime intervalEnd() const
86  {
87  return m_intervalEnd;
88  }
89  SMILTime previousIntervalBegin() const
90  {
91  return m_previousIntervalBegin;
92  }
93  SMILTime simpleDuration() const;
94 
95  void progress(SMILTime elapsed, SVGSMILElement *resultsElement);
96  SMILTime nextProgressTime() const;
97 
98  static SMILTime parseClockValue(const String &);
99  static SMILTime parseOffsetValue(const String &);
100 
101  bool isContributing(SMILTime elapsed) const;
102  bool isInactive() const;
103  bool isFrozen() const;
104 
105  unsigned documentOrderIndex() const
106  {
107  return m_documentOrderIndex;
108  }
109  void setDocumentOrderIndex(unsigned index)
110  {
111  m_documentOrderIndex = index;
112  }
113 
114  virtual bool isAdditive() const = 0;
115  virtual void resetToBaseValue(const String &) = 0;
116  virtual void applyResultsToTarget() = 0;
117 
118 protected:
119  void addBeginTime(SMILTime time);
120  void addEndTime(SMILTime time);
121 
122 private:
123  virtual void startedActiveInterval() = 0;
124  virtual void updateAnimation(float percent, unsigned repeat, SVGSMILElement *resultElement) = 0;
125  virtual void endedActiveInterval() = 0;
126 
127  enum BeginOrEnd { Begin, End };
128  SMILTime findInstanceTime(BeginOrEnd beginOrEnd, SMILTime minimumTime, bool equalsMinimumOK) const;
129  void resolveFirstInterval();
130  void resolveNextInterval();
131  void resolveInterval(bool first, SMILTime &beginResult, SMILTime &endResult) const;
132  SMILTime resolveActiveEnd(SMILTime resolvedBegin, SMILTime resolvedEnd) const;
133  SMILTime repeatingDuration() const;
134  void checkRestart(SMILTime elapsed);
135  void beginListChanged();
136  void endListChanged();
137  void reschedule();
138 
139  // This represents conditions on elements begin or end list that need to be resolved on runtime
140  // for example <animate begin="otherElement.begin + 8s; button.click" ... />
141  struct Condition {
142  enum Type { EventBase, Syncbase, AccessKey };
143  Condition(Type, BeginOrEnd beginOrEnd, const String &baseID, const String &name, SMILTime offset, int repeats = -1);
144  Type m_type;
145  BeginOrEnd m_beginOrEnd;
146  String m_baseID;
147  String m_name;
148  SMILTime m_offset;
149  int m_repeats;
150  RefPtr<Element> m_syncbase;
151  RefPtr<ConditionEventListener> m_eventListener;
152  };
153  bool parseCondition(const String &, BeginOrEnd beginOrEnd);
154  void parseBeginOrEnd(const String &, BeginOrEnd beginOrEnd);
155 
156  void connectConditions();
157  void disconnectConditions();
158 
159  // Event base timing
160  void handleConditionEvent(Event *, Condition *);
161 
162  // Syncbase timing
163  enum NewOrExistingInterval { NewInterval, ExistingInterval };
164  void notifyDependentsIntervalChanged(NewOrExistingInterval);
165  void createInstanceTimesFromSyncbase(SVGSMILElement *syncbase, NewOrExistingInterval);
166  void addTimeDependent(SVGSMILElement *);
167  void removeTimeDependent(SVGSMILElement *);
168 
169  enum ActiveState { Inactive, Active, Frozen };
170  ActiveState determineActiveState(SMILTime elapsed) const;
171  float calculateAnimationPercentAndRepeat(SMILTime elapsed, unsigned &repeat) const;
172  SMILTime calculateNextProgressTime(SMILTime elapsed) const;
173 
174  Vector<Condition> m_conditions;
175  bool m_conditionsConnected;
176  bool m_hasEndEventConditions;
177 
178  typedef HashSet<SVGSMILElement *> TimeDependentSet;
179  TimeDependentSet m_timeDependents;
180 
181  // Instance time lists
182  Vector<SMILTime> m_beginTimes;
183  Vector<SMILTime> m_endTimes;
184 
185  // This is the upcoming or current interval
186  SMILTime m_intervalBegin;
187  SMILTime m_intervalEnd;
188 
189  SMILTime m_previousIntervalBegin;
190 
191  bool m_isWaitingForFirstInterval;
192 
193  ActiveState m_activeState;
194  float m_lastPercent;
195  unsigned m_lastRepeat;
196 
197  SMILTime m_nextProgressTime;
198 
199  RefPtr<SMILTimeContainer> m_timeContainer;
200  unsigned m_documentOrderIndex;
201 
202  mutable SMILTime m_cachedDur;
203  mutable SMILTime m_cachedRepeatDur;
204  mutable SMILTime m_cachedRepeatCount;
205  mutable SMILTime m_cachedMin;
206  mutable SMILTime m_cachedMax;
207 
208  friend class ConditionEventListener;
209 };
210 
211 }
212 
213 #endif
214 #endif
215 
QAction * restart(const QObject *recvr, const char *slot, QObject *parent)
This file is part of the KDE documentation.
Documentation copyright © 1996-2021 The KDE developers.
Generated on Tue Oct 26 2021 22:48:10 by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.