Home | History | Annotate | Download | only in svg
      1 /*
      2  * Copyright (C) 2006 Apple Inc. All rights reserved.
      3  * Copyright (C) 2006, 2008 Nikolas Zimmermann <zimmermann (at) kde.org>
      4  *
      5  * This library is free software; you can redistribute it and/or
      6  * modify it under the terms of the GNU Library General Public
      7  * License as published by the Free Software Foundation; either
      8  * version 2 of the License, or (at your option) any later version.
      9  *
     10  * This library is distributed in the hope that it will be useful,
     11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
     12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
     13  * Library General Public License for more details.
     14  *
     15  * You should have received a copy of the GNU Library General Public License
     16  * along with this library; see the file COPYING.LIB.  If not, write to
     17  * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
     18  * Boston, MA 02110-1301, USA.
     19  */
     20 
     21 #ifndef SVGDocumentExtensions_h
     22 #define SVGDocumentExtensions_h
     23 
     24 #include "wtf/Forward.h"
     25 #include "wtf/HashMap.h"
     26 #include "wtf/HashSet.h"
     27 #include "wtf/text/AtomicStringHash.h"
     28 
     29 namespace WebCore {
     30 
     31 class Document;
     32 class RenderSVGResourceContainer;
     33 class SVGElement;
     34 #if ENABLE(SVG_FONTS)
     35 class SVGFontFaceElement;
     36 #endif
     37 class SVGResourcesCache;
     38 class SVGSMILElement;
     39 class SVGSVGElement;
     40 class Element;
     41 
     42 class SVGDocumentExtensions {
     43     WTF_MAKE_NONCOPYABLE(SVGDocumentExtensions); WTF_MAKE_FAST_ALLOCATED;
     44 public:
     45     typedef HashSet<Element*> SVGPendingElements;
     46     SVGDocumentExtensions(Document*);
     47     ~SVGDocumentExtensions();
     48 
     49     void addTimeContainer(SVGSVGElement*);
     50     void removeTimeContainer(SVGSVGElement*);
     51 
     52     void addResource(const AtomicString& id, RenderSVGResourceContainer*);
     53     void removeResource(const AtomicString& id);
     54     RenderSVGResourceContainer* resourceById(const AtomicString& id) const;
     55 
     56     void startAnimations();
     57     void pauseAnimations();
     58     void unpauseAnimations();
     59     void dispatchSVGLoadEventToOutermostSVGElements();
     60 
     61     void reportWarning(const String&);
     62     void reportError(const String&);
     63 
     64     SVGResourcesCache* resourcesCache() const { return m_resourcesCache.get(); }
     65 
     66     HashSet<SVGElement*>* setOfElementsReferencingTarget(SVGElement* referencedElement) const;
     67     void addElementReferencingTarget(SVGElement* referencingElement, SVGElement* referencedElement);
     68     void removeAllTargetReferencesForElement(SVGElement*);
     69     void rebuildAllElementReferencesForTarget(SVGElement*);
     70     void removeAllElementReferencesForTarget(SVGElement*);
     71 
     72 #if ENABLE(SVG_FONTS)
     73     const HashSet<SVGFontFaceElement*>& svgFontFaceElements() const { return m_svgFontFaceElements; }
     74     void registerSVGFontFaceElement(SVGFontFaceElement*);
     75     void unregisterSVGFontFaceElement(SVGFontFaceElement*);
     76 #endif
     77 
     78 private:
     79     Document* m_document; // weak reference
     80     HashSet<SVGSVGElement*> m_timeContainers; // For SVG 1.2 support this will need to be made more general.
     81 #if ENABLE(SVG_FONTS)
     82     HashSet<SVGFontFaceElement*> m_svgFontFaceElements;
     83 #endif
     84     HashMap<AtomicString, RenderSVGResourceContainer*> m_resources;
     85     HashMap<AtomicString, OwnPtr<SVGPendingElements> > m_pendingResources; // Resources that are pending.
     86     HashMap<AtomicString, OwnPtr<SVGPendingElements> > m_pendingResourcesForRemoval; // Resources that are pending and scheduled for removal.
     87     HashMap<SVGElement*, OwnPtr<HashSet<SVGElement*> > > m_elementDependencies;
     88     OwnPtr<SVGResourcesCache> m_resourcesCache;
     89 
     90 public:
     91     // This HashMap contains a list of pending resources. Pending resources, are such
     92     // which are referenced by any object in the SVG document, but do NOT exist yet.
     93     // For instance, dynamically build gradients / patterns / clippers...
     94     void addPendingResource(const AtomicString& id, Element*);
     95     bool hasPendingResource(const AtomicString& id) const;
     96     bool isElementPendingResources(Element*) const;
     97     bool isElementPendingResource(Element*, const AtomicString& id) const;
     98     void clearHasPendingResourcesIfPossible(Element*);
     99     void removeElementFromPendingResources(Element*);
    100     PassOwnPtr<SVGPendingElements> removePendingResource(const AtomicString& id);
    101 
    102     // The following two functions are used for scheduling a pending resource to be removed.
    103     void markPendingResourcesForRemoval(const AtomicString&);
    104     Element* removeElementFromPendingResourcesForRemoval(const AtomicString&);
    105 
    106 private:
    107     PassOwnPtr<SVGPendingElements> removePendingResourceForRemoval(const AtomicString&);
    108 };
    109 
    110 }
    111 
    112 #endif
    113