1/*
2 * Copyright (C) Research In Motion Limited 2009-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 RenderSVGResource_h
21#define RenderSVGResource_h
22
23#include "RenderSVGShape.h"
24#include "RenderStyleConstants.h"
25#include "SVGDocumentExtensions.h"
26
27namespace WebCore {
28
29enum RenderSVGResourceType {
30    MaskerResourceType,
31    MarkerResourceType,
32    PatternResourceType,
33    LinearGradientResourceType,
34    RadialGradientResourceType,
35    SolidColorResourceType,
36    FilterResourceType,
37    ClipperResourceType
38};
39
40// If this enum changes change the unsigned bitfields using it.
41enum RenderSVGResourceMode {
42    ApplyToDefaultMode = 1 << 0, // used for all resources except gradient/pattern
43    ApplyToFillMode    = 1 << 1,
44    ApplyToStrokeMode  = 1 << 2,
45    ApplyToTextMode    = 1 << 3 // used in combination with ApplyTo{Fill|Stroke}Mode
46};
47
48class Color;
49class FloatRect;
50class GraphicsContext;
51class Path;
52class RenderObject;
53class RenderStyle;
54class RenderSVGResourceSolidColor;
55
56class RenderSVGResource {
57public:
58    RenderSVGResource() { }
59    virtual ~RenderSVGResource() { }
60
61    virtual void removeAllClientsFromCache(bool markForInvalidation = true) = 0;
62    virtual void removeClientFromCache(RenderElement&, bool markForInvalidation = true) = 0;
63
64    virtual bool applyResource(RenderElement&, const RenderStyle&, GraphicsContext*&, unsigned short resourceMode) = 0;
65    virtual void postApplyResource(RenderElement&, GraphicsContext*&, unsigned short, const Path*, const RenderSVGShape*) { }
66    virtual FloatRect resourceBoundingBox(const RenderObject&) = 0;
67
68    virtual RenderSVGResourceType resourceType() const = 0;
69
70    template<class Renderer>
71    Renderer* cast()
72    {
73        if (Renderer::s_resourceType == resourceType())
74            return static_cast<Renderer*>(this);
75
76        return 0;
77    }
78
79    // Helper utilities used in the render tree to access resources used for painting shapes/text (gradients & patterns & solid colors only)
80    static RenderSVGResource* fillPaintingResource(RenderElement&, const RenderStyle&, Color& fallbackColor);
81    static RenderSVGResource* strokePaintingResource(RenderElement&, const RenderStyle&, Color& fallbackColor);
82    static RenderSVGResourceSolidColor* sharedSolidPaintingResource();
83
84    static void markForLayoutAndParentResourceInvalidation(RenderObject&, bool needsLayout = true);
85};
86
87}
88
89#endif
90