1 | /* |
2 | * Copyright (C) Research In Motion Limited 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 | #include "config.h" |
21 | #include "RenderSVGResourceSolidColor.h" |
22 | |
23 | #include "Frame.h" |
24 | #include "FrameView.h" |
25 | #include "GraphicsContext.h" |
26 | #include "RenderStyle.h" |
27 | #include "RenderView.h" |
28 | |
29 | namespace WebCore { |
30 | |
31 | RenderSVGResourceSolidColor::RenderSVGResourceSolidColor() = default; |
32 | |
33 | RenderSVGResourceSolidColor::~RenderSVGResourceSolidColor() = default; |
34 | |
35 | bool RenderSVGResourceSolidColor::applyResource(RenderElement& renderer, const RenderStyle& style, GraphicsContext*& context, OptionSet<RenderSVGResourceMode> resourceMode) |
36 | { |
37 | ASSERT(context); |
38 | ASSERT(!resourceMode.isEmpty()); |
39 | |
40 | const SVGRenderStyle& svgStyle = style.svgStyle(); |
41 | |
42 | bool isRenderingMask = renderer.view().frameView().paintBehavior().contains(PaintBehavior::RenderingSVGMask); |
43 | |
44 | if (resourceMode.contains(RenderSVGResourceMode::ApplyToFill)) { |
45 | if (!isRenderingMask) |
46 | context->setAlpha(svgStyle.fillOpacity()); |
47 | else |
48 | context->setAlpha(1); |
49 | context->setFillColor(style.colorByApplyingColorFilter(m_color)); |
50 | if (!isRenderingMask) |
51 | context->setFillRule(svgStyle.fillRule()); |
52 | |
53 | if (resourceMode.contains(RenderSVGResourceMode::ApplyToText)) |
54 | context->setTextDrawingMode(TextModeFill); |
55 | } else if (resourceMode.contains(RenderSVGResourceMode::ApplyToStroke)) { |
56 | // When rendering the mask for a RenderSVGResourceClipper, the stroke code path is never hit. |
57 | ASSERT(!isRenderingMask); |
58 | context->setAlpha(svgStyle.strokeOpacity()); |
59 | context->setStrokeColor(style.colorByApplyingColorFilter(m_color)); |
60 | |
61 | SVGRenderSupport::applyStrokeStyleToContext(context, style, renderer); |
62 | |
63 | if (resourceMode.contains(RenderSVGResourceMode::ApplyToText)) |
64 | context->setTextDrawingMode(TextModeStroke); |
65 | } |
66 | |
67 | return true; |
68 | } |
69 | |
70 | void RenderSVGResourceSolidColor::postApplyResource(RenderElement&, GraphicsContext*& context, OptionSet<RenderSVGResourceMode> resourceMode, const Path* path, const RenderSVGShape* shape) |
71 | { |
72 | ASSERT(context); |
73 | ASSERT(!resourceMode.isEmpty()); |
74 | |
75 | if (resourceMode.contains(RenderSVGResourceMode::ApplyToFill)) { |
76 | if (path) |
77 | context->fillPath(*path); |
78 | else if (shape) |
79 | shape->fillShape(*context); |
80 | } |
81 | if (resourceMode.contains(RenderSVGResourceMode::ApplyToStroke)) { |
82 | if (path) |
83 | context->strokePath(*path); |
84 | else if (shape) |
85 | shape->strokeShape(*context); |
86 | } |
87 | } |
88 | |
89 | } |
90 | |