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 "platform/geometry/FloatPoint.h"
     25 #include "platform/heap/Handle.h"
     26 #include "wtf/Forward.h"
     27 #include "wtf/HashMap.h"
     28 #include "wtf/HashSet.h"
     29 #include "wtf/text/AtomicStringHash.h"
     30 
     31 namespace blink {
     32 
     33 class Document;
     34 class RenderSVGResourceContainer;
     35 class SubtreeLayoutScope;
     36 #if ENABLE(SVG_FONTS)
     37 class SVGFontFaceElement;
     38 #endif
     39 class SVGResourcesCache;
     40 class SVGSVGElement;
     41 class Element;
     42 
     43 class SVGDocumentExtensions : public NoBaseWillBeGarbageCollectedFinalized<SVGDocumentExtensions> {
     44     WTF_MAKE_NONCOPYABLE(SVGDocumentExtensions); WTF_MAKE_FAST_ALLOCATED_WILL_BE_REMOVED;
     45 public:
     46     typedef WillBeHeapHashSet<RawPtrWillBeMember<Element> > SVGPendingElements;
     47     explicit SVGDocumentExtensions(Document*);
     48     ~SVGDocumentExtensions();
     49 
     50     void addTimeContainer(SVGSVGElement*);
     51     void removeTimeContainer(SVGSVGElement*);
     52 
     53     void addResource(const AtomicString& id, RenderSVGResourceContainer*);
     54     void removeResource(const AtomicString& id);
     55     RenderSVGResourceContainer* resourceById(const AtomicString& id) const;
     56 
     57     static void serviceOnAnimationFrame(Document&, double monotonicAnimationStartTime);
     58 
     59     void startAnimations();
     60     void pauseAnimations();
     61     void dispatchSVGLoadEventToOutermostSVGElements();
     62 
     63     void reportWarning(const String&);
     64     void reportError(const String&);
     65 
     66     SVGResourcesCache* resourcesCache() const { return m_resourcesCache.get(); }
     67 
     68     void addSVGRootWithRelativeLengthDescendents(SVGSVGElement*);
     69     void removeSVGRootWithRelativeLengthDescendents(SVGSVGElement*);
     70     bool isSVGRootWithRelativeLengthDescendents(SVGSVGElement*) const;
     71     void invalidateSVGRootsWithRelativeLengthDescendents(SubtreeLayoutScope*);
     72 
     73 #if ENABLE(SVG_FONTS)
     74     const WillBeHeapHashSet<RawPtrWillBeMember<SVGFontFaceElement> >& svgFontFaceElements() const { return m_svgFontFaceElements; }
     75     void registerSVGFontFaceElement(SVGFontFaceElement*);
     76     void unregisterSVGFontFaceElement(SVGFontFaceElement*);
     77 
     78     void registerPendingSVGFontFaceElementsForRemoval(PassRefPtrWillBeRawPtr<SVGFontFaceElement>);
     79     void removePendingSVGFontFaceElementsForRemoval();
     80 #endif
     81 
     82     bool zoomAndPanEnabled() const;
     83 
     84     void startPan(const FloatPoint& start);
     85     void updatePan(const FloatPoint& pos) const;
     86 
     87     static SVGSVGElement* rootElement(const Document&);
     88     SVGSVGElement* rootElement() const;
     89 
     90     void trace(Visitor*);
     91 
     92 private:
     93     RawPtrWillBeMember<Document> m_document;
     94     WillBeHeapHashSet<RawPtrWillBeMember<SVGSVGElement> > m_timeContainers; // For SVG 1.2 support this will need to be made more general.
     95 #if ENABLE(SVG_FONTS)
     96     WillBeHeapHashSet<RawPtrWillBeMember<SVGFontFaceElement> > m_svgFontFaceElements;
     97     // SVGFontFaceElements that are pending and scheduled for removal.
     98     WillBeHeapHashSet<RefPtrWillBeMember<SVGFontFaceElement> > m_pendingSVGFontFaceElementsForRemoval;
     99 #endif
    100     HashMap<AtomicString, RenderSVGResourceContainer*> m_resources;
    101     WillBeHeapHashMap<AtomicString, OwnPtrWillBeMember<SVGPendingElements> > m_pendingResources; // Resources that are pending.
    102     WillBeHeapHashMap<AtomicString, OwnPtrWillBeMember<SVGPendingElements> > m_pendingResourcesForRemoval; // Resources that are pending and scheduled for removal.
    103     OwnPtr<SVGResourcesCache> m_resourcesCache;
    104     WillBeHeapHashSet<RawPtrWillBeMember<SVGSVGElement> > m_relativeLengthSVGRoots; // Root SVG elements with relative length descendants.
    105     FloatPoint m_translate;
    106 #if ENABLE(ASSERT)
    107     bool m_inRelativeLengthSVGRootsInvalidation;
    108 #endif
    109 
    110 public:
    111     // This HashMap contains a list of pending resources. Pending resources, are such
    112     // which are referenced by any object in the SVG document, but do NOT exist yet.
    113     // For instance, dynamically build gradients / patterns / clippers...
    114     void addPendingResource(const AtomicString& id, Element*);
    115     bool hasPendingResource(const AtomicString& id) const;
    116     bool isElementPendingResources(Element*) const;
    117     bool isElementPendingResource(Element*, const AtomicString& id) const;
    118     void clearHasPendingResourcesIfPossible(Element*);
    119     void removeElementFromPendingResources(Element*);
    120     PassOwnPtrWillBeRawPtr<SVGPendingElements> removePendingResource(const AtomicString& id);
    121 
    122     void serviceAnimations(double monotonicAnimationStartTime);
    123 
    124     // The following two functions are used for scheduling a pending resource to be removed.
    125     void markPendingResourcesForRemoval(const AtomicString&);
    126     Element* removeElementFromPendingResourcesForRemoval(const AtomicString&);
    127 
    128 private:
    129     PassOwnPtrWillBeRawPtr<SVGPendingElements> removePendingResourceForRemoval(const AtomicString&);
    130 };
    131 
    132 }
    133 
    134 #endif
    135