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