KHtml

SVGFEImageElement.cpp
1 /*
2  Copyright (C) 2004, 2005, 2007 Nikolas Zimmermann <[email protected]>
3  2004, 2005 Rob Buis <[email protected]>
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 #if ENABLE(SVG) && ENABLE(SVG_FILTERS)
24 #include "SVGFEImageElement.h"
25 
26 #include "Attr.h"
27 #include "CachedImage.h"
28 #include "DocLoader.h"
29 #include "Document.h"
30 #include "SVGLength.h"
31 #include "SVGNames.h"
32 #include "SVGPreserveAspectRatio.h"
33 #include "SVGResourceFilter.h"
34 
35 namespace WebCore
36 {
37 
38 SVGFEImageElement::SVGFEImageElement(const QualifiedName &tagName, Document *doc)
39  : SVGFilterPrimitiveStandardAttributes(tagName, doc)
40  , SVGURIReference()
41  , SVGLangSpace()
42  , SVGExternalResourcesRequired()
43  , m_preserveAspectRatio(SVGPreserveAspectRatio::create())
44  , m_cachedImage(0)
45  , m_filterEffect(0)
46 {
47 }
48 
49 SVGFEImageElement::~SVGFEImageElement()
50 {
51  delete m_filterEffect;
52  if (m_cachedImage) {
53  m_cachedImage->removeClient(this);
54  }
55 }
56 
57 ANIMATED_PROPERTY_DEFINITIONS(SVGFEImageElement, SVGPreserveAspectRatio *, PreserveAspectRatio, preserveAspectRatio, PreserveAspectRatio, preserveAspectRatio, SVGNames::preserveAspectRatioAttr, m_preserveAspectRatio.get())
58 
59 void SVGFEImageElement::parseMappedAttribute(MappedAttribute *attr)
60 {
61  const String &value = attr->value();
62  if (attr->name() == SVGNames::preserveAspectRatioAttr) {
63  const UChar *c = value.characters();
64  const UChar *end = c + value.length();
65  preserveAspectRatioBaseValue()->parsePreserveAspectRatio(c, end);
66  } else {
67  if (SVGURIReference::parseMappedAttribute(attr)) {
68  if (!href().startsWith("#")) {
69  // FIXME: this code needs to special-case url fragments and later look them up using getElementById instead of loading them here
70  if (m_cachedImage) {
71  m_cachedImage->removeClient(this);
72  }
73  m_cachedImage = ownerDocument()->docLoader()->requestImage(href());
74  if (m_cachedImage) {
75  m_cachedImage->addClient(this);
76  }
77  }
78  return;
79  }
80  if (SVGLangSpace::parseMappedAttribute(attr)) {
81  return;
82  }
83  if (SVGExternalResourcesRequired::parseMappedAttribute(attr)) {
84  return;
85  }
86 
87  SVGFilterPrimitiveStandardAttributes::parseMappedAttribute(attr);
88  }
89 }
90 
91 void SVGFEImageElement::notifyFinished(CachedResource *finishedObj)
92 {
93  if (finishedObj == m_cachedImage && m_filterEffect) {
94  m_filterEffect->setCachedImage(m_cachedImage);
95  }
96 }
97 
98 SVGFEImage *SVGFEImageElement::filterEffect(SVGResourceFilter *filter) const
99 {
100  if (!m_filterEffect) {
101  m_filterEffect = new SVGFEImage(filter);
102  }
103 
104  // The resource may already be loaded!
105  if (m_cachedImage) {
106  m_filterEffect->setCachedImage(m_cachedImage);
107  }
108 
109  setStandardAttributes(m_filterEffect);
110  return m_filterEffect;
111 }
112 
113 void SVGFEImageElement::getSubresourceAttributeStrings(Vector<String> &urls) const
114 {
115  urls.append(href());
116 }
117 
118 }
119 
120 #endif // ENABLE(SVG)
121 
QAction * create(StandardAction id, const QObject *recvr, Func slot, QObject *parent)
const QList< QKeySequence > & end()
This file is part of the KDE documentation.
Documentation copyright © 1996-2021 The KDE developers.
Generated on Mon Oct 25 2021 22:48:22 by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.