File indexing completed on 2024-04-28 15:24:29

0001 /*
0002     Copyright (C) 2006 Apple Computer, Inc.
0003                   2006 Nikolas Zimmermann <zimmermann@kde.org>
0004                   2007 Rob Buis <buis@kde.org>
0005 
0006     This file is part of the WebKit project
0007 
0008     This library is free software; you can redistribute it and/or
0009     modify it under the terms of the GNU Library General Public
0010     License as published by the Free Software Foundation; either
0011     version 2 of the License, or (at your option) any later version.
0012 
0013     This library is distributed in the hope that it will be useful,
0014     but WITHOUT ANY WARRANTY; without even the implied warranty of
0015     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
0016     Library General Public License for more details.
0017 
0018     You should have received a copy of the GNU Library General Public License
0019     along with this library; see the file COPYING.LIB.  If not, write to
0020     the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
0021     Boston, MA 02110-1301, USA.
0022 */
0023 
0024 #include <wtf/Platform.h>
0025 
0026 #if ENABLE(SVG)
0027 #include "SVGDocumentExtensions.h"
0028 
0029 /*#include "AtomicString.h"
0030 #include "Console.h"
0031 #include "DOMWindow.h"*/
0032 //#include "Document.h"
0033 //#include "EventListener.h"
0034 #include "dom/dom2_events.h"
0035 /*#include "Frame.h"
0036 #include "FrameLoader.h"
0037 #include "Page.h"*/
0038 #include "SVGSVGElement.h"
0039 /*#include "SMILTimeContainer.h"
0040 #include "XMLTokenizer.h"*/
0041 #include "kjs_proxy.h"
0042 #include "khtml_part.h"
0043 
0044 namespace WebCore
0045 {
0046 
0047 SVGDocumentExtensions::SVGDocumentExtensions(Document *doc)
0048     : m_doc(doc)
0049 {
0050 }
0051 
0052 SVGDocumentExtensions::~SVGDocumentExtensions()
0053 {
0054     /*deleteAllValues(m_pendingResources);*/
0055     deleteAllValues(m_elementInstances);
0056 }
0057 
0058 EventListener *SVGDocumentExtensions::createSVGEventListener(const DOMString &functionName, const DOMString &code, DOM::NodeImpl *node)
0059 {
0060     /*if (Frame* frame = m_doc->frame())
0061         if (frame->scriptProxy()->isEnabled())
0062             return frame->scriptProxy()->createSVGEventHandler(functionName, code, node);*/
0063     if (!m_doc || !m_doc->part()) {
0064         return nullptr;
0065     }
0066     // qCDebug(KHTML_LOG) << "create listener: (" << code << functionName << node << ")";
0067     return m_doc->part()->createHTMLEventListener(code.string(), functionName.string(), node, true/*svg*/);
0068 }
0069 
0070 void SVGDocumentExtensions::addTimeContainer(SVGSVGElement *element)
0071 {
0072     Q_UNUSED(element);
0073     /*m_timeContainers.add(element);*/
0074 }
0075 
0076 void SVGDocumentExtensions::removeTimeContainer(SVGSVGElement *element)
0077 {
0078     Q_UNUSED(element);
0079     /*m_timeContainers.remove(element);*/
0080 }
0081 
0082 void SVGDocumentExtensions::startAnimations()
0083 {
0084     // FIXME: Eventually every "Time Container" will need a way to latch on to some global timer
0085     // starting animations for a document will do this "latching"
0086 #if ENABLE(SVG_ANIMATION)
0087     HashSet<SVGSVGElement *>::iterator end = m_timeContainers.end();
0088     for (HashSet<SVGSVGElement *>::iterator itr = m_timeContainers.begin(); itr != end; ++itr) {
0089         (*itr)->timeContainer()->begin();
0090     }
0091 #endif
0092 }
0093 
0094 void SVGDocumentExtensions::pauseAnimations()
0095 {
0096     HashSet<SVGSVGElement *>::iterator end = m_timeContainers.end();
0097     for (HashSet<SVGSVGElement *>::iterator itr = m_timeContainers.begin(); itr != end; ++itr) {
0098         (*itr)->pauseAnimations();
0099     }
0100 }
0101 
0102 void SVGDocumentExtensions::unpauseAnimations()
0103 {
0104     HashSet<SVGSVGElement *>::iterator end = m_timeContainers.end();
0105     for (HashSet<SVGSVGElement *>::iterator itr = m_timeContainers.begin(); itr != end; ++itr) {
0106         (*itr)->unpauseAnimations();
0107     }
0108 }
0109 
0110 void SVGDocumentExtensions::reportWarning(const String &message)
0111 {
0112     Q_UNUSED(message);
0113     /*if (Frame* frame = m_doc->frame())
0114         frame->domWindow()->console()->addMessage(JSMessageSource, ErrorMessageLevel, "Warning: " + message, m_doc->tokenizer() ? m_doc->tokenizer()->lineNumber() : 1, String());*/
0115 }
0116 
0117 void SVGDocumentExtensions::reportError(const String &message)
0118 {
0119     Q_UNUSED(message);
0120     /*if (Frame* frame = m_doc->frame())
0121         frame->domWindow()->console()->addMessage(JSMessageSource, ErrorMessageLevel, "Error: " + message, m_doc->tokenizer() ? m_doc->tokenizer()->lineNumber() : 1, String());*/
0122 }
0123 
0124 void SVGDocumentExtensions::addPendingResource(const AtomicString &id, SVGStyledElement *obj)
0125 {
0126     ASSERT(obj);
0127     Q_UNUSED(obj);
0128 
0129     if (id.isEmpty()) {
0130         return;
0131     }
0132 
0133     /*if (m_pendingResources.contains(id))
0134         m_pendingResources.get(id)->add(obj);
0135     else {
0136         HashSet<SVGStyledElement*>* set = new HashSet<SVGStyledElement*>();
0137         set->add(obj);
0138 
0139         m_pendingResources.add(id, set);
0140     }*/
0141 }
0142 
0143 bool SVGDocumentExtensions::isPendingResource(const AtomicString &id) const
0144 {
0145     Q_UNUSED(id);
0146     /*if (id.isEmpty())
0147         return false;
0148 
0149     return m_pendingResources.contains(id);*/
0150     ASSERT(false);
0151     return false;
0152 }
0153 
0154 std::unique_ptr<HashSet<SVGStyledElement *> > SVGDocumentExtensions::removePendingResource(const AtomicString &id)
0155 {
0156     Q_UNUSED(id);
0157     /*ASSERT(m_pendingResources.contains(id));
0158 
0159     std::unique_ptr<HashSet<SVGStyledElement*> > set(m_pendingResources.get(id));
0160     m_pendingResources.remove(id);
0161     return set;*/
0162     ASSERT(false);
0163     return std::unique_ptr<HashSet<SVGStyledElement *> >();
0164 }
0165 
0166 void SVGDocumentExtensions::mapInstanceToElement(SVGElementInstance *instance, SVGElement *element)
0167 {
0168     ASSERT(instance);
0169     ASSERT(element);
0170 
0171     if (m_elementInstances.contains(element)) {
0172         m_elementInstances.get(element)->add(instance);
0173     } else {
0174         HashSet<SVGElementInstance *> *set = new HashSet<SVGElementInstance *>();
0175         set->add(instance);
0176 
0177         m_elementInstances.add(element, set);
0178     }
0179 }
0180 
0181 void SVGDocumentExtensions::removeInstanceMapping(SVGElementInstance *instance, SVGElement *element)
0182 {
0183     ASSERT(instance);
0184 
0185     if (!m_elementInstances.contains(element)) {
0186         return;
0187     }
0188 
0189     m_elementInstances.get(element)->remove(instance);
0190 }
0191 
0192 HashSet<SVGElementInstance *> *SVGDocumentExtensions::instancesForElement(SVGElement *element) const
0193 {
0194     ASSERT(element);
0195     return m_elementInstances.get(element);
0196 }
0197 
0198 }
0199 
0200 #endif