KHtml

SVGImageElement.cpp
1 /*
2  Copyright (C) 2004, 2005, 2006, 2008 Nikolas Zimmermann <[email protected]>
3  2004, 2005, 2006, 2007, 2008 Rob Buis <[email protected]>
4  2006 Alexander Kellett <[email protected]>
5 
6  This file is part of the KDE project
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., 51 Franklin Street, Fifth Floor,
21  Boston, MA 02110-1301, USA.
22 */
23 
24 #if ENABLE(SVG)
25 #include "SVGImageElement.h"
26 
27 #include "CSSPropertyNames.h"
28 #include "RenderSVGImage.h"
29 #include "SVGDocument.h"
30 #include "SVGLength.h"
31 #include "SVGNames.h"
32 #include "SVGPreserveAspectRatio.h"
33 #include "SVGSVGElement.h"
34 #include "XLinkNames.h"
35 
36 namespace WebCore
37 {
38 
39 SVGImageElement::SVGImageElement(const QualifiedName &tagName, Document *doc)
40  : SVGStyledTransformableElement(tagName, doc)
41  , SVGTests()
42  , SVGLangSpace()
43  , SVGExternalResourcesRequired()
44  , SVGURIReference()
45  , m_x(this, LengthModeWidth)
46  , m_y(this, LengthModeHeight)
47  , m_width(this, LengthModeWidth)
48  , m_height(this, LengthModeHeight)
49  , m_preserveAspectRatio(SVGPreserveAspectRatio::create())
50  , m_imageLoader(this)
51 {
52 }
53 
54 SVGImageElement::~SVGImageElement()
55 {
56 }
57 
58 ANIMATED_PROPERTY_DEFINITIONS(SVGImageElement, SVGLength, Length, length, X, x, SVGNames::xAttr, m_x)
59 ANIMATED_PROPERTY_DEFINITIONS(SVGImageElement, SVGLength, Length, length, Y, y, SVGNames::yAttr, m_y)
60 ANIMATED_PROPERTY_DEFINITIONS(SVGImageElement, SVGLength, Length, length, Width, width, SVGNames::widthAttr, m_width)
61 ANIMATED_PROPERTY_DEFINITIONS(SVGImageElement, SVGLength, Length, length, Height, height, SVGNames::heightAttr, m_height)
62 ANIMATED_PROPERTY_DEFINITIONS(SVGImageElement, SVGPreserveAspectRatio *, PreserveAspectRatio, preserveAspectRatio, PreserveAspectRatio, preserveAspectRatio, SVGNames::preserveAspectRatioAttr, m_preserveAspectRatio.get())
63 
64 void SVGImageElement::parseMappedAttribute(MappedAttribute *attr)
65 {
66  if (attr->name() == SVGNames::xAttr) {
67  setXBaseValue(SVGLength(this, LengthModeWidth, attr->value()));
68  } else if (attr->name() == SVGNames::yAttr) {
69  setYBaseValue(SVGLength(this, LengthModeHeight, attr->value()));
70  } else if (attr->name() == SVGNames::preserveAspectRatioAttr) {
71  const UChar *c = attr->value().characters();
72  const UChar *end = c + attr->value().length();
73  preserveAspectRatioBaseValue()->parsePreserveAspectRatio(c, end);
74  } else if (attr->name() == SVGNames::widthAttr) {
75  setWidthBaseValue(SVGLength(this, LengthModeWidth, attr->value()));
76  addCSSProperty(attr, CSSPropertyWidth, attr->value());
77  if (width().value() < 0.0) {
78  document()->accessSVGExtensions()->reportError("A negative value for image attribute <width> is not allowed");
79  }
80  } else if (attr->name() == SVGNames::heightAttr) {
81  setHeightBaseValue(SVGLength(this, LengthModeHeight, attr->value()));
82  addCSSProperty(attr, CSSPropertyHeight, attr->value());
83  if (height().value() < 0.0) {
84  document()->accessSVGExtensions()->reportError("A negative value for image attribute <height> is not allowed");
85  }
86  } else {
87  if (SVGTests::parseMappedAttribute(attr)) {
88  return;
89  }
90  if (SVGLangSpace::parseMappedAttribute(attr)) {
91  return;
92  }
93  if (SVGExternalResourcesRequired::parseMappedAttribute(attr)) {
94  return;
95  }
96  if (SVGURIReference::parseMappedAttribute(attr)) {
97  return;
98  }
99  SVGStyledTransformableElement::parseMappedAttribute(attr);
100  }
101 }
102 
103 void SVGImageElement::svgAttributeChanged(const QualifiedName &attrName)
104 {
105  SVGStyledTransformableElement::svgAttributeChanged(attrName);
106 
107  if (!renderer()) {
108  return;
109  }
110 
111  bool isURIAttribute = SVGURIReference::isKnownAttribute(attrName);
112 
113  if (attrName == SVGNames::xAttr || attrName == SVGNames::yAttr ||
114  attrName == SVGNames::widthAttr || attrName == SVGNames::heightAttr ||
115  SVGTests::isKnownAttribute(attrName) ||
116  SVGLangSpace::isKnownAttribute(attrName) ||
117  SVGExternalResourcesRequired::isKnownAttribute(attrName) ||
118  isURIAttribute ||
119  SVGStyledTransformableElement::isKnownAttribute(attrName)) {
120  renderer()->setNeedsLayout(true);
121 
122  if (isURIAttribute) {
123  m_imageLoader.updateFromElement();
124  }
125  }
126 }
127 
128 bool SVGImageElement::hasRelativeValues() const
129 {
130  return (x().isRelative() || width().isRelative() ||
131  y().isRelative() || height().isRelative());
132 }
133 
134 RenderObject *SVGImageElement::createRenderer(RenderArena *arena, RenderStyle *style)
135 {
136  return new(arena) RenderSVGImage(this);
137 }
138 
139 bool SVGImageElement::haveLoadedRequiredResources()
140 {
141  return !externalResourcesRequiredBaseValue() || m_imageLoader.haveFiredLoadEvent();
142 }
143 
144 void SVGImageElement::attach()
145 {
146  SVGStyledTransformableElement::attach();
147  m_imageLoader.updateFromElement();
148  if (RenderSVGImage *imageObj = static_cast<RenderSVGImage *>(renderer())) {
149  imageObj->setCachedImage(m_imageLoader.image());
150  }
151 }
152 
153 void SVGImageElement::getSubresourceAttributeStrings(Vector<String> &urls) const
154 {
155  urls.append(href());
156 }
157 
158 }
159 
160 #endif // ENABLE(SVG)
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 Tue Oct 26 2021 22:48:10 by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.