• Skip to content
  • Skip to link menu
KDE 4.2 API Reference
  • KDE API Reference
  • kdelibs
  • Sitemap
  • Contact Us
 

KHTML

SVGImageElement.cpp

Go to the documentation of this file.
00001 /*
00002     Copyright (C) 2004, 2005, 2006, 2008 Nikolas Zimmermann <zimmermann@kde.org>
00003                   2004, 2005, 2006, 2007, 2008 Rob Buis <buis@kde.org>
00004                   2006 Alexander Kellett <lypanov@kde.org>
00005 
00006     This file is part of the KDE project
00007 
00008     This library is free software; you can redistribute it and/or
00009     modify it under the terms of the GNU Library General Public
00010     License as published by the Free Software Foundation; either
00011     version 2 of the License, or (at your option) any later version.
00012 
00013     This library is distributed in the hope that it will be useful,
00014     but WITHOUT ANY WARRANTY; without even the implied warranty of
00015     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00016     Library General Public License for more details.
00017 
00018     You should have received a copy of the GNU Library General Public License
00019     along with this library; see the file COPYING.LIB.  If not, write to
00020     the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
00021     Boston, MA 02110-1301, USA.
00022 */
00023 
00024 #include "config.h"
00025 
00026 #if ENABLE(SVG)
00027 #include "SVGImageElement.h"
00028 
00029 #include "CSSPropertyNames.h"
00030 #include "RenderSVGImage.h"
00031 #include "SVGDocument.h"
00032 #include "SVGLength.h"
00033 #include "SVGNames.h"
00034 #include "SVGPreserveAspectRatio.h"
00035 #include "SVGSVGElement.h"
00036 #include "XLinkNames.h"
00037 
00038 namespace WebCore {
00039 
00040 SVGImageElement::SVGImageElement(const QualifiedName& tagName, Document* doc)
00041     : SVGStyledTransformableElement(tagName, doc)
00042     , SVGTests()
00043     , SVGLangSpace()
00044     , SVGExternalResourcesRequired()
00045     , SVGURIReference()
00046     , m_x(this, LengthModeWidth)
00047     , m_y(this, LengthModeHeight)
00048     , m_width(this, LengthModeWidth)
00049     , m_height(this, LengthModeHeight)
00050     , m_preserveAspectRatio(SVGPreserveAspectRatio::create())
00051     , m_imageLoader(this)
00052 {
00053 }
00054 
00055 SVGImageElement::~SVGImageElement()
00056 {
00057 }
00058 
00059 ANIMATED_PROPERTY_DEFINITIONS(SVGImageElement, SVGLength, Length, length, X, x, SVGNames::xAttr, m_x)
00060 ANIMATED_PROPERTY_DEFINITIONS(SVGImageElement, SVGLength, Length, length, Y, y, SVGNames::yAttr, m_y)
00061 ANIMATED_PROPERTY_DEFINITIONS(SVGImageElement, SVGLength, Length, length, Width, width, SVGNames::widthAttr, m_width)
00062 ANIMATED_PROPERTY_DEFINITIONS(SVGImageElement, SVGLength, Length, length, Height, height, SVGNames::heightAttr, m_height)
00063 ANIMATED_PROPERTY_DEFINITIONS(SVGImageElement, SVGPreserveAspectRatio*, PreserveAspectRatio, preserveAspectRatio, PreserveAspectRatio, preserveAspectRatio, SVGNames::preserveAspectRatioAttr, m_preserveAspectRatio.get())
00064 
00065 void SVGImageElement::parseMappedAttribute(MappedAttribute *attr)
00066 {
00067     if (attr->name() == SVGNames::xAttr)
00068         setXBaseValue(SVGLength(this, LengthModeWidth, attr->value()));
00069     else if (attr->name() == SVGNames::yAttr)
00070         setYBaseValue(SVGLength(this, LengthModeHeight, attr->value()));
00071     else if (attr->name() == SVGNames::preserveAspectRatioAttr) {
00072         const UChar* c = attr->value().characters();
00073         const UChar* end = c + attr->value().length();
00074         preserveAspectRatioBaseValue()->parsePreserveAspectRatio(c, end);
00075     } else if (attr->name() == SVGNames::widthAttr) {
00076         setWidthBaseValue(SVGLength(this, LengthModeWidth, attr->value()));
00077         addCSSProperty(attr, CSSPropertyWidth, attr->value());
00078         if (width().value() < 0.0)
00079             document()->accessSVGExtensions()->reportError("A negative value for image attribute <width> is not allowed");
00080     } else if (attr->name() == SVGNames::heightAttr) {
00081         setHeightBaseValue(SVGLength(this, LengthModeHeight, attr->value()));
00082         addCSSProperty(attr, CSSPropertyHeight, attr->value());
00083         if (height().value() < 0.0)
00084             document()->accessSVGExtensions()->reportError("A negative value for image attribute <height> is not allowed");
00085     } else {
00086         if (SVGTests::parseMappedAttribute(attr))
00087             return;
00088         if (SVGLangSpace::parseMappedAttribute(attr))
00089             return;
00090         if (SVGExternalResourcesRequired::parseMappedAttribute(attr))
00091             return;
00092         if (SVGURIReference::parseMappedAttribute(attr))
00093             return;
00094         SVGStyledTransformableElement::parseMappedAttribute(attr);
00095     }
00096 }
00097 
00098 void SVGImageElement::svgAttributeChanged(const QualifiedName& attrName)
00099 {
00100     SVGStyledTransformableElement::svgAttributeChanged(attrName);
00101 
00102     if (!renderer())
00103         return;
00104 
00105     bool isURIAttribute = SVGURIReference::isKnownAttribute(attrName);
00106 
00107     if (attrName == SVGNames::xAttr || attrName == SVGNames::yAttr ||
00108         attrName == SVGNames::widthAttr || attrName == SVGNames::heightAttr ||
00109         SVGTests::isKnownAttribute(attrName) ||
00110         SVGLangSpace::isKnownAttribute(attrName) ||
00111         SVGExternalResourcesRequired::isKnownAttribute(attrName) ||
00112         isURIAttribute ||
00113         SVGStyledTransformableElement::isKnownAttribute(attrName)) {
00114         renderer()->setNeedsLayout(true);
00115 
00116         if (isURIAttribute)
00117             m_imageLoader.updateFromElement();
00118     }
00119 }
00120 
00121 bool SVGImageElement::hasRelativeValues() const
00122 {
00123     return (x().isRelative() || width().isRelative() ||
00124             y().isRelative() || height().isRelative());
00125 }
00126 
00127 RenderObject* SVGImageElement::createRenderer(RenderArena* arena, RenderStyle* style)
00128 {
00129     return new (arena) RenderSVGImage(this);
00130 }
00131 
00132 bool SVGImageElement::haveLoadedRequiredResources()
00133 {
00134     return !externalResourcesRequiredBaseValue() || m_imageLoader.haveFiredLoadEvent();
00135 }
00136 
00137 void SVGImageElement::attach()
00138 {
00139     SVGStyledTransformableElement::attach();
00140     m_imageLoader.updateFromElement();
00141     if (RenderSVGImage* imageObj = static_cast<RenderSVGImage*>(renderer()))
00142         imageObj->setCachedImage(m_imageLoader.image());
00143 }
00144 
00145 void SVGImageElement::getSubresourceAttributeStrings(Vector<String>& urls) const
00146 {
00147     urls.append(href());
00148 }
00149 
00150 }
00151 
00152 #endif // ENABLE(SVG)

KHTML

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

kdelibs

Skip menu "kdelibs"
  • DNSSD
  • Interfaces
  •   KHexEdit
  •   KMediaPlayer
  •   KSpeech
  •   KTextEditor
  • Kate
  • kconf_update
  • KDE3Support
  •   KUnitTest
  • KDECore
  • KDED
  • KDEsu
  • KDEUI
  • KDocTools
  • KFile
  • KHTML
  • KImgIO
  • KInit
  • kio
  • KIOSlave
  • KJS
  •   KJS-API
  •   WTF
  • kjsembed
  • KNewStuff
  • KParts
  • Kross
  • KUtils
  • Nepomuk
  • Plasma
  • Solid
  • Sonnet
  • ThreadWeaver
Generated for kdelibs by doxygen 1.5.7
This website is maintained by Adriaan de Groot and Allen Winter.
KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal