1 /* 2 Copyright (C) 2006 Apple Computer, Inc. 3 2006 Nikolas Zimmermann <zimmermann (at) kde.org> 4 2007 Rob Buis <buis (at) 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 "SVGSMILElement.h" 38 #include "SVGSVGElement.h" 39 #include "SMILTimeContainer.h" 40 #include "XMLTokenizer.h" 41 #include "ScriptController.h" 42 43 namespace WebCore { 44 45 SVGDocumentExtensions::SVGDocumentExtensions(Document* doc) 46 : m_doc(doc) 47 { 48 } 49 50 SVGDocumentExtensions::~SVGDocumentExtensions() 51 { 52 deleteAllValues(m_pendingResources); 53 } 54 55 void SVGDocumentExtensions::addTimeContainer(SVGSVGElement* element) 56 { 57 m_timeContainers.add(element); 58 } 59 60 void SVGDocumentExtensions::removeTimeContainer(SVGSVGElement* element) 61 { 62 m_timeContainers.remove(element); 63 } 64 65 void SVGDocumentExtensions::startAnimations() 66 { 67 // FIXME: Eventually every "Time Container" will need a way to latch on to some global timer 68 // starting animations for a document will do this "latching" 69 #if ENABLE(SVG_ANIMATION) 70 HashSet<SVGSVGElement*>::iterator end = m_timeContainers.end(); 71 for (HashSet<SVGSVGElement*>::iterator itr = m_timeContainers.begin(); itr != end; ++itr) 72 (*itr)->timeContainer()->begin(); 73 #endif 74 } 75 76 void SVGDocumentExtensions::pauseAnimations() 77 { 78 HashSet<SVGSVGElement*>::iterator end = m_timeContainers.end(); 79 for (HashSet<SVGSVGElement*>::iterator itr = m_timeContainers.begin(); itr != end; ++itr) 80 (*itr)->pauseAnimations(); 81 } 82 83 void SVGDocumentExtensions::unpauseAnimations() 84 { 85 HashSet<SVGSVGElement*>::iterator end = m_timeContainers.end(); 86 for (HashSet<SVGSVGElement*>::iterator itr = m_timeContainers.begin(); itr != end; ++itr) 87 (*itr)->unpauseAnimations(); 88 } 89 90 bool SVGDocumentExtensions::sampleAnimationAtTime(const String& elementId, SVGSMILElement* element, double time) 91 { 92 ASSERT(element); 93 SMILTimeContainer* container = element->timeContainer(); 94 if (!container || container->isPaused()) 95 return false; 96 97 container->sampleAnimationAtTime(elementId, time); 98 return true; 99 } 100 101 void SVGDocumentExtensions::reportWarning(const String& message) 102 { 103 if (Frame* frame = m_doc->frame()) 104 frame->domWindow()->console()->addMessage(JSMessageSource, LogMessageType, ErrorMessageLevel, "Warning: " + message, m_doc->tokenizer() ? m_doc->tokenizer()->lineNumber() : 1, String()); 105 } 106 107 void SVGDocumentExtensions::reportError(const String& message) 108 { 109 if (Frame* frame = m_doc->frame()) 110 frame->domWindow()->console()->addMessage(JSMessageSource, LogMessageType, ErrorMessageLevel, "Error: " + message, m_doc->tokenizer() ? m_doc->tokenizer()->lineNumber() : 1, String()); 111 } 112 113 void SVGDocumentExtensions::addPendingResource(const AtomicString& id, SVGStyledElement* obj) 114 { 115 ASSERT(obj); 116 117 if (id.isEmpty()) 118 return; 119 120 if (m_pendingResources.contains(id)) 121 m_pendingResources.get(id)->add(obj); 122 else { 123 HashSet<SVGStyledElement*>* set = new HashSet<SVGStyledElement*>(); 124 set->add(obj); 125 126 m_pendingResources.add(id, set); 127 } 128 } 129 130 bool SVGDocumentExtensions::isPendingResource(const AtomicString& id) const 131 { 132 if (id.isEmpty()) 133 return false; 134 135 return m_pendingResources.contains(id); 136 } 137 138 std::auto_ptr<HashSet<SVGStyledElement*> > SVGDocumentExtensions::removePendingResource(const AtomicString& id) 139 { 140 ASSERT(m_pendingResources.contains(id)); 141 142 std::auto_ptr<HashSet<SVGStyledElement*> > set(m_pendingResources.get(id)); 143 m_pendingResources.remove(id); 144 return set; 145 } 146 147 } 148 149 #endif 150