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