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

KHTML

SVGRectElement.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 Rob Buis <buis@kde.org>
00004 
00005     This file is part of the KDE project
00006 
00007     This library is free software; you can redistribute it and/or
00008     modify it under the terms of the GNU Library General Public
00009     License as published by the Free Software Foundation; either
00010     version 2 of the License, or (at your option) any later version.
00011 
00012     This library is distributed in the hope that it will be useful,
00013     but WITHOUT ANY WARRANTY; without even the implied warranty of
00014     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00015     Library General Public License for more details.
00016 
00017     You should have received a copy of the GNU Library General Public License
00018     along with this library; see the file COPYING.LIB.  If not, write to
00019     the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
00020     Boston, MA 02110-1301, USA.
00021 */
00022 
00023 #include "config.h"
00024 #include "wtf/Platform.h"
00025 
00026 #if ENABLE(SVG)
00027 #include "SVGRectElement.h"
00028 
00029 #include "RenderPath.h"
00030 #include "SVGLength.h"
00031 #include "SVGNames.h"
00032 
00033 namespace WebCore {
00034 
00035 SVGRectElement::SVGRectElement(const QualifiedName& tagName, Document *doc)
00036     : SVGStyledTransformableElement(tagName, doc)
00037     , SVGTests()
00038     , SVGLangSpace()
00039     , SVGExternalResourcesRequired()
00040     , m_x(this, LengthModeWidth)
00041     , m_y(this, LengthModeHeight)
00042     , m_width(this, LengthModeWidth)
00043     , m_height(this, LengthModeHeight)
00044     , m_rx(this, LengthModeWidth)
00045     , m_ry(this, LengthModeHeight)
00046 {
00047 }
00048 
00049 SVGRectElement::~SVGRectElement()
00050 {
00051 }
00052 
00053 ANIMATED_PROPERTY_DEFINITIONS(SVGRectElement, SVGLength, Length, length, X, x, SVGNames::xAttr, m_x)
00054 ANIMATED_PROPERTY_DEFINITIONS(SVGRectElement, SVGLength, Length, length, Y, y, SVGNames::yAttr, m_y)
00055 ANIMATED_PROPERTY_DEFINITIONS(SVGRectElement, SVGLength, Length, length, Width, width, SVGNames::widthAttr, m_width)
00056 ANIMATED_PROPERTY_DEFINITIONS(SVGRectElement, SVGLength, Length, length, Height, height, SVGNames::heightAttr, m_height)
00057 ANIMATED_PROPERTY_DEFINITIONS(SVGRectElement, SVGLength, Length, length, Rx, rx, SVGNames::rxAttr, m_rx)
00058 ANIMATED_PROPERTY_DEFINITIONS(SVGRectElement, SVGLength, Length, length, Ry, ry, SVGNames::ryAttr, m_ry)
00059 
00060 void SVGRectElement::parseMappedAttribute(MappedAttribute* attr)
00061 {
00062     kDebug() << "called with" << attr->localName() << attr->value() << endl;
00063     if (attr->name() == SVGNames::xAttr)
00064         setXBaseValue(SVGLength(this, LengthModeWidth, attr->value()));
00065     else if (attr->name() == SVGNames::yAttr)
00066         setYBaseValue(SVGLength(this, LengthModeHeight, attr->value()));
00067     else if (attr->name() == SVGNames::rxAttr) {
00068         setRxBaseValue(SVGLength(this, LengthModeWidth, attr->value()));
00069         if (rx().value() < 0.0)
00070             document()->accessSVGExtensions()->reportError("A negative value for rect <rx> is not allowed");
00071     } else if (attr->name() == SVGNames::ryAttr) {
00072         setRyBaseValue(SVGLength(this, LengthModeHeight, attr->value()));
00073         if (ry().value() < 0.0)
00074             document()->accessSVGExtensions()->reportError("A negative value for rect <ry> is not allowed");
00075     } else if (attr->name() == SVGNames::widthAttr) {
00076         setWidthBaseValue(SVGLength(this, LengthModeWidth, attr->value()));
00077         if (width().value() < 0.0)
00078             document()->accessSVGExtensions()->reportError("A negative value for rect <width> is not allowed");
00079     } else if (attr->name() == SVGNames::heightAttr) {
00080         setHeightBaseValue(SVGLength(this, LengthModeHeight, attr->value()));
00081         if (height().value() < 0.0)
00082             document()->accessSVGExtensions()->reportError("A negative value for rect <height> is not allowed");
00083     } else {
00084         if (SVGTests::parseMappedAttribute(attr))
00085             return;
00086         if (SVGLangSpace::parseMappedAttribute(attr))
00087             return;
00088         if (SVGExternalResourcesRequired::parseMappedAttribute(attr))
00089             return;
00090         SVGStyledTransformableElement::parseMappedAttribute(attr);
00091     }
00092 }
00093 
00094 void SVGRectElement::svgAttributeChanged(const QualifiedName& attrName)
00095 {
00096     SVGStyledTransformableElement::svgAttributeChanged(attrName);
00097 
00098     if (!renderer())
00099         return;
00100 
00101     if (attrName == SVGNames::xAttr || attrName == SVGNames::yAttr ||
00102         attrName == SVGNames::widthAttr || attrName == SVGNames::heightAttr ||
00103         attrName == SVGNames::rxAttr || attrName == SVGNames::ryAttr ||
00104         SVGTests::isKnownAttribute(attrName) ||
00105         SVGLangSpace::isKnownAttribute(attrName) ||
00106         SVGExternalResourcesRequired::isKnownAttribute(attrName) ||
00107         SVGStyledTransformableElement::isKnownAttribute(attrName))
00108         renderer()->setNeedsLayout(true);
00109 }
00110 
00111 Path SVGRectElement::toPathData() const
00112 {
00113     FloatRect rect(x().value(), y().value(), width().value(), height().value());
00114 
00115     bool hasRx = hasAttribute(SVGNames::rxAttr);
00116     bool hasRy = hasAttribute(SVGNames::ryAttr);
00117     if (hasRx || hasRy) {
00118         float _rx = hasRx ? rx().value() : ry().value();
00119         float _ry = hasRy ? ry().value() : rx().value();
00120         return Path::createRoundedRectangle(rect, FloatSize(_rx, _ry));
00121     }
00122 
00123     return Path::createRectangle(rect);
00124 }
00125 
00126 bool SVGRectElement::hasRelativeValues() const
00127 {
00128     return (x().isRelative() || width().isRelative() ||
00129             y().isRelative() || height().isRelative() ||
00130             rx().isRelative() || ry().isRelative());
00131 }
00132 
00133 // KHTML ElementImpl pure virtual method
00134 quint32 SVGRectElement::id() const
00135 {
00136     return SVGNames::rectTag.id();
00137 }
00138 
00139 DOMString SVGRectElement::tagName() const
00140 {
00141     return SVGNames::rectTag.tagName();
00142 }
00143 
00144 }
00145 
00146 #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