| 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 | #pragma once |
| 21 | |
| 22 | #include "RenderSVGShape.h" |
| 23 | #include "RenderStyleConstants.h" |
| 24 | #include <wtf/TypeCasts.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 class RenderSVGResourceMode { |
| 41 | ApplyToFill = 1 << 0, |
| 42 | ApplyToStroke = 1 << 1, |
| 43 | ApplyToText = 1 << 2 // used in combination with ApplyTo{Fill|Stroke}Mode |
| 44 | }; |
| 45 | |
| 46 | class Color; |
| 47 | class FloatRect; |
| 48 | class GraphicsContext; |
| 49 | class Path; |
| 50 | class RenderObject; |
| 51 | class RenderStyle; |
| 52 | class RenderSVGResourceSolidColor; |
| 53 | |
| 54 | class RenderSVGResource { |
| 55 | public: |
| 56 | RenderSVGResource() = default; |
| 57 | virtual ~RenderSVGResource() = default; |
| 58 | |
| 59 | virtual void removeAllClientsFromCache(bool markForInvalidation = true) = 0; |
| 60 | virtual void removeClientFromCache(RenderElement&, bool markForInvalidation = true) = 0; |
| 61 | |
| 62 | virtual bool applyResource(RenderElement&, const RenderStyle&, GraphicsContext*&, OptionSet<RenderSVGResourceMode>) = 0; |
| 63 | virtual void postApplyResource(RenderElement&, GraphicsContext*&, OptionSet<RenderSVGResourceMode>, const Path*, const RenderSVGShape*) { } |
| 64 | virtual FloatRect resourceBoundingBox(const RenderObject&) = 0; |
| 65 | |
| 66 | virtual RenderSVGResourceType resourceType() const = 0; |
| 67 | |
| 68 | // Helper utilities used in the render tree to access resources used for painting shapes/text (gradients & patterns & solid colors only) |
| 69 | static RenderSVGResource* fillPaintingResource(RenderElement&, const RenderStyle&, Color& fallbackColor); |
| 70 | static RenderSVGResource* strokePaintingResource(RenderElement&, const RenderStyle&, Color& fallbackColor); |
| 71 | static RenderSVGResourceSolidColor* sharedSolidPaintingResource(); |
| 72 | |
| 73 | static void markForLayoutAndParentResourceInvalidation(RenderObject&, bool needsLayout = true); |
| 74 | }; |
| 75 | |
| 76 | } // namespace WebCore |
| 77 | |
| 78 | #define SPECIALIZE_TYPE_TRAITS_RENDER_SVG_RESOURCE(ToValueTypeName, ResourceType) \ |
| 79 | SPECIALIZE_TYPE_TRAITS_BEGIN(WebCore::ToValueTypeName) \ |
| 80 | static bool isType(const WebCore::RenderSVGResource& resource) { return resource.resourceType() == WebCore::ResourceType; } \ |
| 81 | SPECIALIZE_TYPE_TRAITS_END() |
| 82 | |