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
29namespace WebCore {
30
31RenderSVGResourceType RenderSVGResourceSolidColor::s_resourceType = SolidColorResourceType;
32
33RenderSVGResourceSolidColor::RenderSVGResourceSolidColor()
34{
35}
36
37RenderSVGResourceSolidColor::~RenderSVGResourceSolidColor()
38{
39}
40
41bool RenderSVGResourceSolidColor::applyResource(RenderElement& renderer, const RenderStyle& style, GraphicsContext*& context, unsigned short resourceMode)
42{
43    ASSERT(context);
44    ASSERT(resourceMode != ApplyToDefaultMode);
45
46    const SVGRenderStyle& svgStyle = style.svgStyle();
47    ColorSpace colorSpace = style.colorSpace();
48
49    bool isRenderingMask = renderer.view().frameView().paintBehavior() & PaintBehaviorRenderingSVGMask;
50
51    if (resourceMode & ApplyToFillMode) {
52        if (!isRenderingMask)
53            context->setAlpha(svgStyle.fillOpacity());
54        else
55            context->setAlpha(1);
56        context->setFillColor(m_color, colorSpace);
57        if (!isRenderingMask)
58            context->setFillRule(svgStyle.fillRule());
59
60        if (resourceMode & ApplyToTextMode)
61            context->setTextDrawingMode(TextModeFill);
62    } else if (resourceMode & ApplyToStrokeMode) {
63        // When rendering the mask for a RenderSVGResourceClipper, the stroke code path is never hit.
64        ASSERT(!isRenderingMask);
65        context->setAlpha(svgStyle.strokeOpacity());
66        context->setStrokeColor(m_color, colorSpace);
67
68        SVGRenderSupport::applyStrokeStyleToContext(context, style, renderer);
69
70        if (resourceMode & ApplyToTextMode)
71            context->setTextDrawingMode(TextModeStroke);
72    }
73
74    return true;
75}
76
77void RenderSVGResourceSolidColor::postApplyResource(RenderElement&, GraphicsContext*& context, unsigned short resourceMode, const Path* path, const RenderSVGShape* shape)
78{
79    ASSERT(context);
80    ASSERT(resourceMode != ApplyToDefaultMode);
81
82    if (resourceMode & ApplyToFillMode) {
83        if (path)
84            context->fillPath(*path);
85        else if (shape)
86            shape->fillShape(context);
87    }
88    if (resourceMode & ApplyToStrokeMode) {
89        if (path)
90            context->strokePath(*path);
91        else if (shape)
92            shape->strokeShape(context);
93    }
94}
95
96}
97