• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2     Copyright (C) 2006 Apple Computer, Inc.
3                   2006 Nikolas Zimmermann <zimmermann@kde.org>
4                   2007 Rob Buis <buis@kde.org>
5 
6     This file is part of the WebKit project
7 
8     This library is free software; you can redistribute it and/or
9     modify it under the terms of the GNU Library General Public
10     License as published by the Free Software Foundation; either
11     version 2 of the License, or (at your option) any later version.
12 
13     This library is distributed in the hope that it will be useful,
14     but WITHOUT ANY WARRANTY; without even the implied warranty of
15     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
16     Library General Public License for more details.
17 
18     You should have received a copy of the GNU Library General Public License
19     along with this library; see the file COPYING.LIB.  If not, write to
20     the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
21     Boston, MA 02110-1301, USA.
22 */
23 
24 #include "config.h"
25 
26 #if ENABLE(SVG)
27 #include "SVGDocumentExtensions.h"
28 
29 #include "AtomicString.h"
30 #include "Console.h"
31 #include "DOMWindow.h"
32 #include "Document.h"
33 #include "EventListener.h"
34 #include "Frame.h"
35 #include "FrameLoader.h"
36 #include "Page.h"
37 #include "SVGSVGElement.h"
38 #include "SMILTimeContainer.h"
39 #include "XMLTokenizer.h"
40 #include "ScriptController.h"
41 
42 namespace WebCore {
43 
SVGDocumentExtensions(Document * doc)44 SVGDocumentExtensions::SVGDocumentExtensions(Document* doc)
45     : m_doc(doc)
46 {
47 }
48 
~SVGDocumentExtensions()49 SVGDocumentExtensions::~SVGDocumentExtensions()
50 {
51     deleteAllValues(m_pendingResources);
52 }
53 
addTimeContainer(SVGSVGElement * element)54 void SVGDocumentExtensions::addTimeContainer(SVGSVGElement* element)
55 {
56     m_timeContainers.add(element);
57 }
58 
removeTimeContainer(SVGSVGElement * element)59 void SVGDocumentExtensions::removeTimeContainer(SVGSVGElement* element)
60 {
61     m_timeContainers.remove(element);
62 }
63 
startAnimations()64 void SVGDocumentExtensions::startAnimations()
65 {
66     // FIXME: Eventually every "Time Container" will need a way to latch on to some global timer
67     // starting animations for a document will do this "latching"
68 #if ENABLE(SVG_ANIMATION)
69     HashSet<SVGSVGElement*>::iterator end = m_timeContainers.end();
70     for (HashSet<SVGSVGElement*>::iterator itr = m_timeContainers.begin(); itr != end; ++itr)
71         (*itr)->timeContainer()->begin();
72 #endif
73 }
74 
pauseAnimations()75 void SVGDocumentExtensions::pauseAnimations()
76 {
77     HashSet<SVGSVGElement*>::iterator end = m_timeContainers.end();
78     for (HashSet<SVGSVGElement*>::iterator itr = m_timeContainers.begin(); itr != end; ++itr)
79         (*itr)->pauseAnimations();
80 }
81 
unpauseAnimations()82 void SVGDocumentExtensions::unpauseAnimations()
83 {
84     HashSet<SVGSVGElement*>::iterator end = m_timeContainers.end();
85     for (HashSet<SVGSVGElement*>::iterator itr = m_timeContainers.begin(); itr != end; ++itr)
86         (*itr)->unpauseAnimations();
87 }
88 
reportWarning(const String & message)89 void SVGDocumentExtensions::reportWarning(const String& message)
90 {
91     if (Frame* frame = m_doc->frame())
92         frame->domWindow()->console()->addMessage(JSMessageSource, ErrorMessageLevel, "Warning: " + message, m_doc->tokenizer() ? m_doc->tokenizer()->lineNumber() : 1, String());
93 }
94 
reportError(const String & message)95 void SVGDocumentExtensions::reportError(const String& message)
96 {
97     if (Frame* frame = m_doc->frame())
98         frame->domWindow()->console()->addMessage(JSMessageSource, ErrorMessageLevel, "Error: " + message, m_doc->tokenizer() ? m_doc->tokenizer()->lineNumber() : 1, String());
99 }
100 
addPendingResource(const AtomicString & id,SVGStyledElement * obj)101 void SVGDocumentExtensions::addPendingResource(const AtomicString& id, SVGStyledElement* obj)
102 {
103     ASSERT(obj);
104 
105     if (id.isEmpty())
106         return;
107 
108     if (m_pendingResources.contains(id))
109         m_pendingResources.get(id)->add(obj);
110     else {
111         HashSet<SVGStyledElement*>* set = new HashSet<SVGStyledElement*>();
112         set->add(obj);
113 
114         m_pendingResources.add(id, set);
115     }
116 }
117 
isPendingResource(const AtomicString & id) const118 bool SVGDocumentExtensions::isPendingResource(const AtomicString& id) const
119 {
120     if (id.isEmpty())
121         return false;
122 
123     return m_pendingResources.contains(id);
124 }
125 
removePendingResource(const AtomicString & id)126 std::auto_ptr<HashSet<SVGStyledElement*> > SVGDocumentExtensions::removePendingResource(const AtomicString& id)
127 {
128     ASSERT(m_pendingResources.contains(id));
129 
130     std::auto_ptr<HashSet<SVGStyledElement*> > set(m_pendingResources.get(id));
131     m_pendingResources.remove(id);
132     return set;
133 }
134 
135 }
136 
137 #endif
138