Home | History | Annotate | Download | only in svg
      1 /*
      2  * Copyright (C) Research In Motion Limited 2010. All rights reserved.
      3  *
      4  * This library is free software; you can redistribute it and/or
      5  * modify it under the terms of the GNU Library General Public
      6  * License as published by the Free Software Foundation; either
      7  * version 2 of the License, or (at your option) any later version.
      8  *
      9  * This library is distributed in the hope that it will be useful,
     10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
     11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
     12  * Library General Public License for more details.
     13  *
     14  * You should have received a copy of the GNU Library General Public License
     15  * along with this library; see the file COPYING.LIB.  If not, write to
     16  * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
     17  * Boston, MA 02110-1301, USA.
     18  */
     19 
     20 #ifndef SVGResources_h
     21 #define SVGResources_h
     22 
     23 #include "wtf/HashSet.h"
     24 #include "wtf/Noncopyable.h"
     25 #include "wtf/OwnPtr.h"
     26 #include "wtf/PassOwnPtr.h"
     27 
     28 namespace WebCore {
     29 
     30 class Document;
     31 class RenderObject;
     32 class RenderSVGResourceClipper;
     33 class RenderSVGResourceContainer;
     34 class RenderSVGResourceFilter;
     35 class RenderSVGResourceMarker;
     36 class RenderSVGResourceMasker;
     37 class SVGRenderStyle;
     38 
     39 // Holds a set of resources associated with a RenderObject
     40 class SVGResources {
     41     WTF_MAKE_NONCOPYABLE(SVGResources); WTF_MAKE_FAST_ALLOCATED;
     42 public:
     43     SVGResources();
     44 
     45     bool buildResources(const RenderObject*, const SVGRenderStyle*);
     46 
     47     // Ordinary resources
     48     RenderSVGResourceClipper* clipper() const { return m_clipperFilterMaskerData ? m_clipperFilterMaskerData->clipper : 0; }
     49     RenderSVGResourceMarker* markerStart() const { return m_markerData ? m_markerData->markerStart : 0; }
     50     RenderSVGResourceMarker* markerMid() const { return m_markerData ? m_markerData->markerMid : 0; }
     51     RenderSVGResourceMarker* markerEnd() const { return m_markerData ? m_markerData->markerEnd : 0; }
     52     RenderSVGResourceMasker* masker() const { return m_clipperFilterMaskerData ? m_clipperFilterMaskerData->masker : 0; }
     53 
     54     RenderSVGResourceFilter* filter() const
     55     {
     56         if (m_clipperFilterMaskerData)
     57             return m_clipperFilterMaskerData->filter;
     58         return 0;
     59     }
     60 
     61     // Paint servers
     62     RenderSVGResourceContainer* fill() const { return m_fillStrokeData ? m_fillStrokeData->fill : 0; }
     63     RenderSVGResourceContainer* stroke() const { return m_fillStrokeData ? m_fillStrokeData->stroke : 0; }
     64 
     65     // Chainable resources - linked through xlink:href
     66     RenderSVGResourceContainer* linkedResource() const { return m_linkedResource; }
     67 
     68     void buildSetOfResources(HashSet<RenderSVGResourceContainer*>&);
     69 
     70     // Methods operating on all cached resources
     71     void removeClientFromCache(RenderObject*, bool markForInvalidation = true) const;
     72     void resourceDestroyed(RenderSVGResourceContainer*);
     73 
     74 #ifndef NDEBUG
     75     void dump(const RenderObject*);
     76 #endif
     77 
     78 private:
     79     friend class SVGResourcesCycleSolver;
     80 
     81     // Only used by SVGResourcesCache cycle detection logic
     82     void resetClipper();
     83     void resetFilter();
     84     void resetMarkerStart();
     85     void resetMarkerMid();
     86     void resetMarkerEnd();
     87     void resetMasker();
     88     void resetFill();
     89     void resetStroke();
     90     void resetLinkedResource();
     91 
     92 private:
     93     bool setClipper(RenderSVGResourceClipper*);
     94     bool setFilter(RenderSVGResourceFilter*);
     95     bool setMarkerStart(RenderSVGResourceMarker*);
     96     bool setMarkerMid(RenderSVGResourceMarker*);
     97     bool setMarkerEnd(RenderSVGResourceMarker*);
     98     bool setMasker(RenderSVGResourceMasker*);
     99     bool setFill(RenderSVGResourceContainer*);
    100     bool setStroke(RenderSVGResourceContainer*);
    101     bool setLinkedResource(RenderSVGResourceContainer*);
    102 
    103     // From SVG 1.1 2nd Edition
    104     // clipper: 'container elements' and 'graphics elements'
    105     // filter:  'container elements' and 'graphics elements'
    106     // masker:  'container elements' and 'graphics elements'
    107     // -> a, circle, defs, ellipse, glyph, g, image, line, marker, mask, missing-glyph, path, pattern, polygon, polyline, rect, svg, switch, symbol, text, use
    108     struct ClipperFilterMaskerData {
    109         WTF_MAKE_FAST_ALLOCATED;
    110     public:
    111         ClipperFilterMaskerData()
    112             : clipper(0)
    113             , filter(0)
    114             , masker(0)
    115         {
    116         }
    117 
    118         static PassOwnPtr<ClipperFilterMaskerData> create()
    119         {
    120             return adoptPtr(new ClipperFilterMaskerData);
    121         }
    122 
    123         RenderSVGResourceClipper* clipper;
    124         RenderSVGResourceFilter* filter;
    125         RenderSVGResourceMasker* masker;
    126     };
    127 
    128     // From SVG 1.1 2nd Edition
    129     // marker: line, path, polygon, polyline
    130     struct MarkerData {
    131         WTF_MAKE_FAST_ALLOCATED;
    132     public:
    133         MarkerData()
    134             : markerStart(0)
    135             , markerMid(0)
    136             , markerEnd(0)
    137         {
    138         }
    139 
    140         static PassOwnPtr<MarkerData> create()
    141         {
    142             return adoptPtr(new MarkerData);
    143         }
    144 
    145         RenderSVGResourceMarker* markerStart;
    146         RenderSVGResourceMarker* markerMid;
    147         RenderSVGResourceMarker* markerEnd;
    148     };
    149 
    150     // From SVG 1.1 2nd Edition
    151     // fill:       'shapes' and 'text content elements'
    152     // stroke:     'shapes' and 'text content elements'
    153     // -> altGlyph, circle, ellipse, line, path, polygon, polyline, rect, text, textPath, tref, tspan
    154     struct FillStrokeData {
    155         WTF_MAKE_FAST_ALLOCATED;
    156     public:
    157         FillStrokeData()
    158             : fill(0)
    159             , stroke(0)
    160         {
    161         }
    162 
    163         static PassOwnPtr<FillStrokeData> create()
    164         {
    165             return adoptPtr(new FillStrokeData);
    166         }
    167 
    168         RenderSVGResourceContainer* fill;
    169         RenderSVGResourceContainer* stroke;
    170     };
    171 
    172     OwnPtr<ClipperFilterMaskerData> m_clipperFilterMaskerData;
    173     OwnPtr<MarkerData> m_markerData;
    174     OwnPtr<FillStrokeData> m_fillStrokeData;
    175     RenderSVGResourceContainer* m_linkedResource;
    176 };
    177 
    178 }
    179 
    180 #endif
    181