1 /*
2 Copyright (C) 2004, 2005, 2007 Nikolas Zimmermann <zimmermann@kde.org>
3 2004, 2005 Rob Buis <buis@kde.org>
4
5 This file is part of the KDE project
6
7 This library is free software; you can redistribute it and/or
8 modify it under the terms of the GNU Library General Public
9 License as published by the Free Software Foundation; either
10 version 2 of the License, or (at your option) any later version.
11
12 This library is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 Library General Public License for more details.
16
17 You should have received a copy of the GNU Library General Public License
18 along with this library; see the file COPYING.LIB. If not, write to
19 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
20 Boston, MA 02110-1301, USA.
21 */
22
23 #include "config.h"
24
25 #if ENABLE(SVG) && ENABLE(FILTERS)
26 #include "SVGFEImageElement.h"
27
28 #include "Attr.h"
29 #include "CachedImage.h"
30 #include "DocLoader.h"
31 #include "Document.h"
32 #include "MappedAttribute.h"
33 #include "SVGLength.h"
34 #include "SVGNames.h"
35 #include "SVGPreserveAspectRatio.h"
36 #include "SVGResourceFilter.h"
37
38 namespace WebCore {
39
SVGFEImageElement(const QualifiedName & tagName,Document * doc)40 SVGFEImageElement::SVGFEImageElement(const QualifiedName& tagName, Document* doc)
41 : SVGFilterPrimitiveStandardAttributes(tagName, doc)
42 , SVGURIReference()
43 , SVGLangSpace()
44 , SVGExternalResourcesRequired()
45 , m_preserveAspectRatio(this, SVGNames::preserveAspectRatioAttr, SVGPreserveAspectRatio::create())
46 {
47 }
48
~SVGFEImageElement()49 SVGFEImageElement::~SVGFEImageElement()
50 {
51 if (m_cachedImage)
52 m_cachedImage->removeClient(this);
53 }
54
parseMappedAttribute(MappedAttribute * attr)55 void SVGFEImageElement::parseMappedAttribute(MappedAttribute* attr)
56 {
57 const String& value = attr->value();
58 if (attr->name() == SVGNames::preserveAspectRatioAttr) {
59 const UChar* c = value.characters();
60 const UChar* end = c + value.length();
61 preserveAspectRatioBaseValue()->parsePreserveAspectRatio(c, end);
62 } else {
63 if (SVGURIReference::parseMappedAttribute(attr)) {
64 if (!href().startsWith("#")) {
65 // FIXME: this code needs to special-case url fragments and later look them up using getElementById instead of loading them here
66 if (m_cachedImage)
67 m_cachedImage->removeClient(this);
68 m_cachedImage = ownerDocument()->docLoader()->requestImage(href());
69 if (m_cachedImage)
70 m_cachedImage->addClient(this);
71 }
72 return;
73 }
74 if (SVGLangSpace::parseMappedAttribute(attr))
75 return;
76 if (SVGExternalResourcesRequired::parseMappedAttribute(attr))
77 return;
78
79 SVGFilterPrimitiveStandardAttributes::parseMappedAttribute(attr);
80 }
81 }
82
notifyFinished(CachedResource *)83 void SVGFEImageElement::notifyFinished(CachedResource*)
84 {
85 }
86
build(SVGResourceFilter * filterResource)87 bool SVGFEImageElement::build(SVGResourceFilter* filterResource)
88 {
89 if (!m_cachedImage)
90 return false;
91
92 RefPtr<FilterEffect> effect = FEImage::create(m_cachedImage.get());
93 filterResource->addFilterEffect(this, effect.release());
94
95 return true;
96 }
97
addSubresourceAttributeURLs(ListHashSet<KURL> & urls) const98 void SVGFEImageElement::addSubresourceAttributeURLs(ListHashSet<KURL>& urls) const
99 {
100 SVGFilterPrimitiveStandardAttributes::addSubresourceAttributeURLs(urls);
101
102 addSubresourceURL(urls, document()->completeURL(href()));
103 }
104
105 }
106
107 #endif // ENABLE(SVG)
108