1/**
2 * This file is part of the DOM implementation for WebKit.
3 *
4 * Copyright (C) 2007 Rob Buis <buis@kde.org>
5 * (C) 2007 Nikolas Zimmermann <zimmermann@kde.org>
6 * (C) 2007 Eric Seidel <eric@webkit.org>
7 *
8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Library General Public
10 * License as published by the Free Software Foundation; either
11 * version 2 of the License, or (at your option) any later version.
12 *
13 * This library is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Library General Public License for more details.
17 *
18 * You should have received a copy of the GNU Library General Public License
19 * along with this library; see the file COPYING.LIB. If not, write to
20 * the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
21 * Boston, MA 02111-1307, USA.
22 *
23 */
24
25#include "config.h"
26
27#if ENABLE(SVG)
28
29#include "AffineTransform.h"
30#include "RenderObject.h"
31#include "SVGResourceClipper.h"
32#include "SVGResourceFilter.h"
33#include "SVGResourceMasker.h"
34#include "SVGStyledElement.h"
35#include "SVGURIReference.h"
36
37namespace WebCore {
38
39#if ENABLE(SVG_EXPERIMENTAL_FEATURES)
40void prepareToRenderSVGContent(RenderObject* object, RenderObject::PaintInfo& paintInfo, const FloatRect& boundingBox, SVGResourceFilter*& filter)
41#else
42void prepareToRenderSVGContent(RenderObject* object, RenderObject::PaintInfo& paintInfo, const FloatRect& boundingBox, void*)
43#endif
44{
45 SVGElement* svgElement = static_cast<SVGElement*>(object->element());
46 ASSERT(svgElement && svgElement->document() && svgElement->isStyled());
47
48 SVGStyledElement* styledElement = static_cast<SVGStyledElement*>(svgElement);
49 const SVGRenderStyle* svgStyle = object->style()->svgStyle();
50
51 AtomicString filterId(SVGURIReference::getTarget(svgStyle->filter()));
52 AtomicString clipperId(SVGURIReference::getTarget(svgStyle->clipPath()));
53 AtomicString maskerId(SVGURIReference::getTarget(svgStyle->maskElement()));
54
55 Document* document = object->document();
56#if ENABLE(SVG_EXPERIMENTAL_FEATURES)
57 filter = getFilterById(document, filterId);
58#endif
59 SVGResourceClipper* clipper = getClipperById(document, clipperId);
60 SVGResourceMasker* masker = getMaskerById(document, maskerId);
61
62#if ENABLE(SVG_EXPERIMENTAL_FEATURES)
63 if (filter)
64 filter->prepareFilter(paintInfo.context, boundingBox);
65 else if (!filterId.isEmpty())
66 svgElement->document()->accessSVGExtensions()->addPendingResource(filterId, styledElement);
67#endif
68
69 if (clipper) {
70 clipper->addClient(styledElement);
71 clipper->applyClip(paintInfo.context, boundingBox);
72 } else if (!clipperId.isEmpty())
73 svgElement->document()->accessSVGExtensions()->addPendingResource(clipperId, styledElement);
74
75 if (masker) {
76 masker->addClient(styledElement);
77 masker->applyMask(paintInfo.context, boundingBox);
78 } else if (!maskerId.isEmpty())
79 svgElement->document()->accessSVGExtensions()->addPendingResource(maskerId, styledElement);
80}
81
82} // namespace WebCore
83
84#endif // ENABLE(SVG)