webengine/osswebengine/WebCore/ksvg2/misc/SVGDocumentExtensions.cpp
changeset 0 dd21522fd290
equal deleted inserted replaced
-1:000000000000 0:dd21522fd290
       
     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 "Chrome.h"
       
    31 #include "Document.h"
       
    32 #include "EventListener.h"
       
    33 #include "Frame.h"
       
    34 #include "FrameLoader.h"
       
    35 #include "Page.h"
       
    36 #include "SVGSVGElement.h"
       
    37 #include "TimeScheduler.h"
       
    38 #include "XMLTokenizer.h"
       
    39 #include "kjs_proxy.h"
       
    40 
       
    41 namespace WebCore {
       
    42 
       
    43 SVGDocumentExtensions::SVGDocumentExtensions(Document* doc)
       
    44     : m_doc(doc)
       
    45 {
       
    46 }
       
    47 
       
    48 SVGDocumentExtensions::~SVGDocumentExtensions()
       
    49 {
       
    50     deleteAllValues(m_pendingResources);
       
    51     deleteAllValues(m_elementInstances);
       
    52 }
       
    53 
       
    54 PassRefPtr<EventListener> SVGDocumentExtensions::createSVGEventListener(const String& functionName, const String& code, Node *node)
       
    55 {
       
    56     if (Frame* frame = m_doc->frame())
       
    57         if (KJSProxy* proxy = frame->scriptProxy())
       
    58             return proxy->createSVGEventHandler(functionName, code, node);
       
    59     return 0;
       
    60 }
       
    61 
       
    62 void SVGDocumentExtensions::addTimeContainer(SVGSVGElement* element)
       
    63 {
       
    64     m_timeContainers.add(element);
       
    65 }
       
    66 
       
    67 void SVGDocumentExtensions::removeTimeContainer(SVGSVGElement* element)
       
    68 {
       
    69     m_timeContainers.remove(element);
       
    70 }
       
    71 
       
    72 void SVGDocumentExtensions::startAnimations()
       
    73 {
       
    74     // FIXME: Eventually every "Time Container" will need a way to latch on to some global timer
       
    75     // starting animations for a document will do this "latching"
       
    76 #if ENABLE(SVG_EXPERIMENTAL_FEATURES)    
       
    77     HashSet<SVGSVGElement*>::iterator end = m_timeContainers.end();
       
    78     for (HashSet<SVGSVGElement*>::iterator itr = m_timeContainers.begin(); itr != end; ++itr)
       
    79         (*itr)->timeScheduler()->startAnimations();
       
    80 #endif
       
    81 }
       
    82     
       
    83 void SVGDocumentExtensions::pauseAnimations()
       
    84 {
       
    85     HashSet<SVGSVGElement*>::iterator end = m_timeContainers.end();
       
    86     for (HashSet<SVGSVGElement*>::iterator itr = m_timeContainers.begin(); itr != end; ++itr)
       
    87         (*itr)->pauseAnimations();
       
    88 }
       
    89 
       
    90 void SVGDocumentExtensions::unpauseAnimations()
       
    91 {
       
    92     HashSet<SVGSVGElement*>::iterator end = m_timeContainers.end();
       
    93     for (HashSet<SVGSVGElement*>::iterator itr = m_timeContainers.begin(); itr != end; ++itr)
       
    94         (*itr)->unpauseAnimations();
       
    95 }
       
    96 
       
    97 void SVGDocumentExtensions::reportWarning(const String& message)
       
    98 {
       
    99     if (Frame* frame = m_doc->frame())
       
   100         if (Page* page = frame->page())
       
   101             page->chrome()->addMessageToConsole(JSMessageSource, ErrorMessageLevel, "Warning: " + message, m_doc->tokenizer() ? m_doc->tokenizer()->lineNumber() : 1, String());
       
   102 }
       
   103 
       
   104 void SVGDocumentExtensions::reportError(const String& message)
       
   105 {
       
   106     if (Frame* frame = m_doc->frame())
       
   107         if (Page* page = frame->page())
       
   108             page->chrome()->addMessageToConsole(JSMessageSource, ErrorMessageLevel, "Error: " + message, m_doc->tokenizer() ? m_doc->tokenizer()->lineNumber() : 1, String());
       
   109 }
       
   110 
       
   111 void SVGDocumentExtensions::addPendingResource(const AtomicString& id, SVGStyledElement* obj)
       
   112 {
       
   113     ASSERT(obj);
       
   114 
       
   115     if (id.isEmpty())
       
   116         return;
       
   117 
       
   118     if (m_pendingResources.contains(id))
       
   119         m_pendingResources.get(id)->add(obj);
       
   120     else {
       
   121         HashSet<SVGStyledElement*>* set = new HashSet<SVGStyledElement*>();
       
   122         set->add(obj);
       
   123 
       
   124         m_pendingResources.add(id, set);
       
   125     }
       
   126 }
       
   127 
       
   128 bool SVGDocumentExtensions::isPendingResource(const AtomicString& id) const
       
   129 {
       
   130     if (id.isEmpty())
       
   131         return false;
       
   132 
       
   133     return m_pendingResources.contains(id);
       
   134 }
       
   135 
       
   136 std::auto_ptr<HashSet<SVGStyledElement*> > SVGDocumentExtensions::removePendingResource(const AtomicString& id)
       
   137 {
       
   138     ASSERT(m_pendingResources.contains(id));
       
   139 
       
   140     std::auto_ptr<HashSet<SVGStyledElement*> > set(m_pendingResources.get(id));
       
   141     m_pendingResources.remove(id);
       
   142     return set;
       
   143 }
       
   144 
       
   145 void SVGDocumentExtensions::mapInstanceToElement(SVGElementInstance* instance, SVGElement* element)
       
   146 {
       
   147     ASSERT(instance);
       
   148     ASSERT(element);
       
   149 
       
   150     if (m_elementInstances.contains(element))
       
   151         m_elementInstances.get(element)->add(instance);
       
   152     else {
       
   153         HashSet<SVGElementInstance*>* set = new HashSet<SVGElementInstance*>();;
       
   154         set->add(instance);
       
   155 
       
   156         m_elementInstances.add(element, set);
       
   157     }
       
   158 }
       
   159 
       
   160 void SVGDocumentExtensions::removeInstanceMapping(SVGElementInstance* instance, SVGElement* element)
       
   161 {
       
   162     ASSERT(instance);
       
   163 
       
   164     if (!m_elementInstances.contains(element))
       
   165         return;
       
   166 
       
   167     m_elementInstances.get(element)->remove(instance);
       
   168 }
       
   169 
       
   170 HashSet<SVGElementInstance*>* SVGDocumentExtensions::instancesForElement(SVGElement* element) const
       
   171 {
       
   172     ASSERT(element);
       
   173     return m_elementInstances.get(element);
       
   174 }
       
   175 
       
   176 }
       
   177 
       
   178 #endif