File indexing completed on 2024-04-28 15:24:31
0001 /* 0002 Copyright (C) 2004, 2005, 2007 Nikolas Zimmermann <zimmermann@kde.org> 0003 2004, 2005 Rob Buis <buis@kde.org> 0004 0005 This file is part of the KDE project 0006 0007 This library is free software; you can redistribute it and/or 0008 modify it under the terms of the GNU Library General Public 0009 License as published by the Free Software Foundation; either 0010 version 2 of the License, or (at your option) any later version. 0011 0012 This library is distributed in the hope that it will be useful, 0013 but WITHOUT ANY WARRANTY; without even the implied warranty of 0014 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 0015 Library General Public License for more details. 0016 0017 You should have received a copy of the GNU Library General Public License 0018 along with this library; see the file COPYING.LIB. If not, write to 0019 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 0020 Boston, MA 02110-1301, USA. 0021 */ 0022 0023 #if ENABLE(SVG) && ENABLE(SVG_FILTERS) 0024 #include "SVGFEImageElement.h" 0025 0026 #include "Attr.h" 0027 #include "CachedImage.h" 0028 #include "DocLoader.h" 0029 #include "Document.h" 0030 #include "SVGLength.h" 0031 #include "SVGNames.h" 0032 #include "SVGPreserveAspectRatio.h" 0033 #include "SVGResourceFilter.h" 0034 0035 namespace WebCore 0036 { 0037 0038 SVGFEImageElement::SVGFEImageElement(const QualifiedName &tagName, Document *doc) 0039 : SVGFilterPrimitiveStandardAttributes(tagName, doc) 0040 , SVGURIReference() 0041 , SVGLangSpace() 0042 , SVGExternalResourcesRequired() 0043 , m_preserveAspectRatio(SVGPreserveAspectRatio::create()) 0044 , m_cachedImage(0) 0045 , m_filterEffect(0) 0046 { 0047 } 0048 0049 SVGFEImageElement::~SVGFEImageElement() 0050 { 0051 delete m_filterEffect; 0052 if (m_cachedImage) { 0053 m_cachedImage->removeClient(this); 0054 } 0055 } 0056 0057 ANIMATED_PROPERTY_DEFINITIONS(SVGFEImageElement, SVGPreserveAspectRatio *, PreserveAspectRatio, preserveAspectRatio, PreserveAspectRatio, preserveAspectRatio, SVGNames::preserveAspectRatioAttr, m_preserveAspectRatio.get()) 0058 0059 void SVGFEImageElement::parseMappedAttribute(MappedAttribute *attr) 0060 { 0061 const String &value = attr->value(); 0062 if (attr->name() == SVGNames::preserveAspectRatioAttr) { 0063 const UChar *c = value.characters(); 0064 const UChar *end = c + value.length(); 0065 preserveAspectRatioBaseValue()->parsePreserveAspectRatio(c, end); 0066 } else { 0067 if (SVGURIReference::parseMappedAttribute(attr)) { 0068 if (!href().startsWith("#")) { 0069 // FIXME: this code needs to special-case url fragments and later look them up using getElementById instead of loading them here 0070 if (m_cachedImage) { 0071 m_cachedImage->removeClient(this); 0072 } 0073 m_cachedImage = ownerDocument()->docLoader()->requestImage(href()); 0074 if (m_cachedImage) { 0075 m_cachedImage->addClient(this); 0076 } 0077 } 0078 return; 0079 } 0080 if (SVGLangSpace::parseMappedAttribute(attr)) { 0081 return; 0082 } 0083 if (SVGExternalResourcesRequired::parseMappedAttribute(attr)) { 0084 return; 0085 } 0086 0087 SVGFilterPrimitiveStandardAttributes::parseMappedAttribute(attr); 0088 } 0089 } 0090 0091 void SVGFEImageElement::notifyFinished(CachedResource *finishedObj) 0092 { 0093 if (finishedObj == m_cachedImage && m_filterEffect) { 0094 m_filterEffect->setCachedImage(m_cachedImage); 0095 } 0096 } 0097 0098 SVGFEImage *SVGFEImageElement::filterEffect(SVGResourceFilter *filter) const 0099 { 0100 if (!m_filterEffect) { 0101 m_filterEffect = new SVGFEImage(filter); 0102 } 0103 0104 // The resource may already be loaded! 0105 if (m_cachedImage) { 0106 m_filterEffect->setCachedImage(m_cachedImage); 0107 } 0108 0109 setStandardAttributes(m_filterEffect); 0110 return m_filterEffect; 0111 } 0112 0113 void SVGFEImageElement::getSubresourceAttributeStrings(Vector<String> &urls) const 0114 { 0115 urls.append(href()); 0116 } 0117 0118 } 0119 0120 #endif // ENABLE(SVG) 0121