• Skip to content
  • Skip to link menu
  • KDE API Reference
  • kdelibs-4.14.38 API Reference
  • KDE Home
  • Contact Us
 

KHTML

  • khtml
  • svg
SVGImageElement.cpp
Go to the documentation of this file.
1/*
2 Copyright (C) 2004, 2005, 2006, 2008 Nikolas Zimmermann <zimmermann@kde.org>
3 2004, 2005, 2006, 2007, 2008 Rob Buis <buis@kde.org>
4 2006 Alexander Kellett <lypanov@kde.org>
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#include "config.h"
25
26#if ENABLE(SVG)
27#include "SVGImageElement.h"
28
29#include "CSSPropertyNames.h"
30#include "RenderSVGImage.h"
31#include "SVGDocument.h"
32#include "SVGLength.h"
33#include "SVGNames.h"
34#include "SVGPreserveAspectRatio.h"
35#include "SVGSVGElement.h"
36#include "XLinkNames.h"
37
38namespace WebCore {
39
40SVGImageElement::SVGImageElement(const QualifiedName& tagName, Document* doc)
41 : SVGStyledTransformableElement(tagName, doc)
42 , SVGTests()
43 , SVGLangSpace()
44 , SVGExternalResourcesRequired()
45 , SVGURIReference()
46 , m_x(this, LengthModeWidth)
47 , m_y(this, LengthModeHeight)
48 , m_width(this, LengthModeWidth)
49 , m_height(this, LengthModeHeight)
50 , m_preserveAspectRatio(SVGPreserveAspectRatio::create())
51 , m_imageLoader(this)
52{
53}
54
55SVGImageElement::~SVGImageElement()
56{
57}
58
59ANIMATED_PROPERTY_DEFINITIONS(SVGImageElement, SVGLength, Length, length, X, x, SVGNames::xAttr, m_x)
60ANIMATED_PROPERTY_DEFINITIONS(SVGImageElement, SVGLength, Length, length, Y, y, SVGNames::yAttr, m_y)
61ANIMATED_PROPERTY_DEFINITIONS(SVGImageElement, SVGLength, Length, length, Width, width, SVGNames::widthAttr, m_width)
62ANIMATED_PROPERTY_DEFINITIONS(SVGImageElement, SVGLength, Length, length, Height, height, SVGNames::heightAttr, m_height)
63ANIMATED_PROPERTY_DEFINITIONS(SVGImageElement, SVGPreserveAspectRatio*, PreserveAspectRatio, preserveAspectRatio, PreserveAspectRatio, preserveAspectRatio, SVGNames::preserveAspectRatioAttr, m_preserveAspectRatio.get())
64
65void SVGImageElement::parseMappedAttribute(MappedAttribute *attr)
66{
67 if (attr->name() == SVGNames::xAttr)
68 setXBaseValue(SVGLength(this, LengthModeWidth, attr->value()));
69 else if (attr->name() == SVGNames::yAttr)
70 setYBaseValue(SVGLength(this, LengthModeHeight, attr->value()));
71 else if (attr->name() == SVGNames::preserveAspectRatioAttr) {
72 const UChar* c = attr->value().characters();
73 const UChar* end = c + attr->value().length();
74 preserveAspectRatioBaseValue()->parsePreserveAspectRatio(c, end);
75 } else if (attr->name() == SVGNames::widthAttr) {
76 setWidthBaseValue(SVGLength(this, LengthModeWidth, attr->value()));
77 addCSSProperty(attr, CSSPropertyWidth, attr->value());
78 if (width().value() < 0.0)
79 document()->accessSVGExtensions()->reportError("A negative value for image attribute <width> is not allowed");
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 } else {
86 if (SVGTests::parseMappedAttribute(attr))
87 return;
88 if (SVGLangSpace::parseMappedAttribute(attr))
89 return;
90 if (SVGExternalResourcesRequired::parseMappedAttribute(attr))
91 return;
92 if (SVGURIReference::parseMappedAttribute(attr))
93 return;
94 SVGStyledTransformableElement::parseMappedAttribute(attr);
95 }
96}
97
98void SVGImageElement::svgAttributeChanged(const QualifiedName& attrName)
99{
100 SVGStyledTransformableElement::svgAttributeChanged(attrName);
101
102 if (!renderer())
103 return;
104
105 bool isURIAttribute = SVGURIReference::isKnownAttribute(attrName);
106
107 if (attrName == SVGNames::xAttr || attrName == SVGNames::yAttr ||
108 attrName == SVGNames::widthAttr || attrName == SVGNames::heightAttr ||
109 SVGTests::isKnownAttribute(attrName) ||
110 SVGLangSpace::isKnownAttribute(attrName) ||
111 SVGExternalResourcesRequired::isKnownAttribute(attrName) ||
112 isURIAttribute ||
113 SVGStyledTransformableElement::isKnownAttribute(attrName)) {
114 renderer()->setNeedsLayout(true);
115
116 if (isURIAttribute)
117 m_imageLoader.updateFromElement();
118 }
119}
120
121bool SVGImageElement::hasRelativeValues() const
122{
123 return (x().isRelative() || width().isRelative() ||
124 y().isRelative() || height().isRelative());
125}
126
127RenderObject* SVGImageElement::createRenderer(RenderArena* arena, RenderStyle* style)
128{
129 return new (arena) RenderSVGImage(this);
130}
131
132bool SVGImageElement::haveLoadedRequiredResources()
133{
134 return !externalResourcesRequiredBaseValue() || m_imageLoader.haveFiredLoadEvent();
135}
136
137void SVGImageElement::attach()
138{
139 SVGStyledTransformableElement::attach();
140 m_imageLoader.updateFromElement();
141 if (RenderSVGImage* imageObj = static_cast<RenderSVGImage*>(renderer()))
142 imageObj->setCachedImage(m_imageLoader.image());
143}
144
145void SVGImageElement::getSubresourceAttributeStrings(Vector<String>& urls) const
146{
147 urls.append(href());
148}
149
150}
151
152#endif // ENABLE(SVG)
SVGDocument.h
SVGImageElement.h
SVGLength.h
SVGNames.h
SVGPreserveAspectRatio.h
SVGSVGElement.h
XLinkNames.h
create
KAction * create(StandardAction id, const QObject *recvr, const char *slot, QObject *parent)
end
const KShortcut & end()
WebCore
Definition: CSSHelper.h:7
X
This file is part of the KDE documentation.
Documentation copyright © 1996-2023 The KDE developers.
Generated on Mon Feb 20 2023 00:00:00 by doxygen 1.9.6 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

KHTML

Skip menu "KHTML"
  • Main Page
  • Namespace List
  • Namespace Members
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • File Members
  • Related Pages

kdelibs-4.14.38 API Reference

Skip menu "kdelibs-4.14.38 API Reference"
  • DNSSD
  • Interfaces
  •   KHexEdit
  •   KMediaPlayer
  •   KSpeech
  •   KTextEditor
  • kconf_update
  • KDE3Support
  •   KUnitTest
  • KDECore
  • KDED
  • KDEsu
  • KDEUI
  • KDEWebKit
  • KDocTools
  • KFile
  • KHTML
  • KImgIO
  • KInit
  • kio
  • KIOSlave
  • KJS
  •   KJS-API
  •   WTF
  • kjsembed
  • KNewStuff
  • KParts
  • KPty
  • Kross
  • KUnitConversion
  • KUtils
  • Nepomuk
  • Plasma
  • Solid
  • Sonnet
  • ThreadWeaver
Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal