Upstream version 7.36.149.0
[platform/framework/web/crosswalk.git] / src / third_party / WebKit / Source / core / rendering / svg / RenderSVGResource.h
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 "core/rendering/svg/RenderSVGShape.h"
24 #include "core/svg/SVGDocumentExtensions.h"
25
26 namespace WebCore {
27
28 enum RenderSVGResourceType {
29     MaskerResourceType,
30     MarkerResourceType,
31     PatternResourceType,
32     LinearGradientResourceType,
33     RadialGradientResourceType,
34     SolidColorResourceType,
35     FilterResourceType,
36     ClipperResourceType
37 };
38
39 // If this enum changes change the unsigned bitfields using it.
40 enum RenderSVGResourceMode {
41     ApplyToDefaultMode = 1 << 0, // used for all resources except gradient/pattern
42     ApplyToFillMode    = 1 << 1,
43     ApplyToStrokeMode  = 1 << 2,
44     ApplyToTextMode    = 1 << 3 // used in combination with ApplyTo{Fill|Stroke}Mode
45 };
46 typedef unsigned RenderSVGResourceModeFlags;
47
48 class Color;
49 class FloatRect;
50 class GraphicsContext;
51 class Path;
52 class RenderObject;
53 class RenderStyle;
54 class RenderSVGResourceSolidColor;
55
56 class RenderSVGResource {
57 public:
58     RenderSVGResource() { }
59     virtual ~RenderSVGResource() { }
60
61     virtual void removeAllClientsFromCache(bool markForInvalidation = true) = 0;
62     virtual void removeClientFromCache(RenderObject*, bool markForInvalidation = true) = 0;
63
64     virtual bool applyResource(RenderObject*, RenderStyle*, GraphicsContext*&, unsigned short resourceMode) = 0;
65     virtual void postApplyResource(RenderObject*, GraphicsContext*&, unsigned short, const Path*, const RenderSVGShape*) { }
66
67     virtual RenderSVGResourceType resourceType() const = 0;
68
69     template<class Renderer>
70     Renderer* cast()
71     {
72         if (Renderer::s_resourceType == resourceType())
73             return static_cast<Renderer*>(this);
74
75         return 0;
76     }
77
78     // Helper utilities used in the render tree to access resources used for painting shapes/text (gradients & patterns & solid colors only)
79     // If hasFallback gets set to true, the sharedSolidPaintingResource is set to a fallback color.
80     static RenderSVGResource* fillPaintingResource(RenderObject*, const RenderStyle*, bool& hasFallback);
81     static RenderSVGResource* strokePaintingResource(RenderObject*, const RenderStyle*, bool& hasFallback);
82     static RenderSVGResourceSolidColor* sharedSolidPaintingResource();
83
84     static void markForLayoutAndParentResourceInvalidation(RenderObject*, bool needsLayout = true);
85 };
86
87 #define DEFINE_RENDER_SVG_RESOURCE_TYPE_CASTS(thisType, typeName) \
88     DEFINE_TYPE_CASTS(thisType, RenderSVGResource, resource, resource->resourceType() == typeName, resource.resourceType() == typeName)
89
90 }
91
92 #endif