File indexing completed on 2024-05-12 15:39:12

0001 /*
0002  * Copyright (C) 2008 Apple Inc. All Rights Reserved.
0003  *
0004  * Redistribution and use in source and binary forms, with or without
0005  * modification, are permitted provided that the following conditions
0006  * are met:
0007  * 1. Redistributions of source code must retain the above copyright
0008  *    notice, this list of conditions and the following disclaimer.
0009  * 2. Redistributions in binary form must reproduce the above copyright
0010  *    notice, this list of conditions and the following disclaimer in the
0011  *    documentation and/or other materials provided with the distribution.
0012  *
0013  * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
0014  * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
0015  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
0016  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL APPLE INC. OR
0017  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
0018  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
0019  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
0020  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
0021  * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
0022  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
0023  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
0024  */
0025 
0026 #ifndef SMILTIMECONTAINER_H
0027 #define SMILTIMECONTAINER_H
0028 
0029 #if ENABLE(SVG)
0030 
0031 #include "PlatformString.h"
0032 #include "SMILTime.h"
0033 #include "StringHash.h"
0034 #include "Timer.h"
0035 #include <wtf/HashSet.h>
0036 #include <wtf/PassRefPtr.h>
0037 #include <wtf/RefCounted.h>
0038 
0039 namespace WebCore
0040 {
0041 
0042 class SVGElement;
0043 class SVGSMILElement;
0044 class SVGSVGElement;
0045 
0046 class SMILTimeContainer : public RefCounted<SMILTimeContainer>
0047 {
0048 public:
0049     static PassRefPtr<SMILTimeContainer> create(SVGSVGElement *owner)
0050     {
0051         return adoptRef(new SMILTimeContainer(owner));
0052     }
0053 
0054     void schedule(SVGSMILElement *);
0055     void unschedule(SVGSMILElement *);
0056 
0057     SMILTime elapsed() const;
0058 
0059     bool isActive() const;
0060     bool isPaused() const;
0061 
0062     void begin();
0063     void pause();
0064     void resume();
0065 
0066     void setDocumentOrderIndexesDirty()
0067     {
0068         m_documentOrderIndexesDirty = true;
0069     }
0070 
0071 private:
0072     SMILTimeContainer(SVGSVGElement *owner);
0073 
0074     void timerFired(Timer<SMILTimeContainer> *);
0075     void startTimer(SMILTime fireTime, SMILTime minimumDelay = 0);
0076     void updateAnimations(SMILTime elapsed);
0077 
0078     void updateDocumentOrderIndexes();
0079     void sortByPriority(Vector<SVGSMILElement *> &smilElements, SMILTime elapsed);
0080 
0081     typedef pair<SVGElement *, String> ElementAttributePair;
0082     String baseValueFor(ElementAttributePair);
0083 
0084     double m_beginTime;
0085     double m_pauseTime;
0086     double m_accumulatedPauseTime;
0087 
0088     bool m_documentOrderIndexesDirty;
0089 
0090     Timer<SMILTimeContainer> m_timer;
0091 
0092     typedef HashSet<SVGSMILElement *> TimingElementSet;
0093     TimingElementSet m_scheduledAnimations;
0094 
0095     typedef HashMap<ElementAttributePair, String> BaseValueMap;
0096     BaseValueMap m_savedBaseValues;
0097 
0098     SVGSVGElement *m_ownerSVGElement;
0099 };
0100 }
0101 
0102 #endif
0103 #endif