File indexing completed on 2024-04-28 15:24:35

0001 /*
0002     Copyright (C) 2004, 2005, 2006, 2008 Nikolas Zimmermann <zimmermann@kde.org>
0003                   2004, 2005, 2006, 2007 Rob Buis <buis@kde.org>
0004 
0005     This file is part of the KDE project
0006 
0007     This library is free software; you can redistribute it and/or
0008     modify it under the terms of the GNU Library General Public
0009     License as published by the Free Software Foundation; either
0010     version 2 of the License, or (at your option) any later version.
0011 
0012     This library is distributed in the hope that it will be useful,
0013     but WITHOUT ANY WARRANTY; without even the implied warranty of
0014     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
0015     Library General Public License for more details.
0016 
0017     You should have received a copy of the GNU Library General Public License
0018     along with this library; see the file COPYING.LIB.  If not, write to
0019     the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
0020     Boston, MA 02110-1301, USA.
0021 */
0022 
0023 #include "wtf/Platform.h"
0024 
0025 #if ENABLE(SVG)
0026 #include "SVGLineElement.h"
0027 
0028 #include "FloatPoint.h"
0029 #include "RenderPath.h"
0030 #include "SVGLength.h"
0031 #include "SVGNames.h"
0032 
0033 namespace WebCore
0034 {
0035 
0036 SVGLineElement::SVGLineElement(const QualifiedName &tagName, Document *doc)
0037     : SVGStyledTransformableElement(tagName, doc)
0038     , SVGTests()
0039     , SVGLangSpace()
0040     , SVGExternalResourcesRequired()
0041     , m_x1(this, LengthModeWidth)
0042     , m_y1(this, LengthModeHeight)
0043     , m_x2(this, LengthModeWidth)
0044     , m_y2(this, LengthModeHeight)
0045 {
0046 }
0047 
0048 SVGLineElement::~SVGLineElement()
0049 {
0050 }
0051 
0052 ANIMATED_PROPERTY_DEFINITIONS(SVGLineElement, SVGLength, Length, length, X1, x1, SVGNames::x1Attr, m_x1)
0053 ANIMATED_PROPERTY_DEFINITIONS(SVGLineElement, SVGLength, Length, length, Y1, y1, SVGNames::y1Attr, m_y1)
0054 ANIMATED_PROPERTY_DEFINITIONS(SVGLineElement, SVGLength, Length, length, X2, x2, SVGNames::x2Attr, m_x2)
0055 ANIMATED_PROPERTY_DEFINITIONS(SVGLineElement, SVGLength, Length, length, Y2, y2, SVGNames::y2Attr, m_y2)
0056 
0057 void SVGLineElement::parseMappedAttribute(MappedAttribute *attr)
0058 {
0059     if (attr->name() == SVGNames::x1Attr) {
0060         setX1BaseValue(SVGLength(this, LengthModeWidth, attr->value()));
0061     } else if (attr->name() == SVGNames::y1Attr) {
0062         setY1BaseValue(SVGLength(this, LengthModeHeight, attr->value()));
0063     } else if (attr->name() == SVGNames::x2Attr) {
0064         setX2BaseValue(SVGLength(this, LengthModeWidth, attr->value()));
0065     } else if (attr->name() == SVGNames::y2Attr) {
0066         setY2BaseValue(SVGLength(this, LengthModeHeight, attr->value()));
0067     } else {
0068         if (SVGTests::parseMappedAttribute(attr)) {
0069             return;
0070         }
0071         if (SVGLangSpace::parseMappedAttribute(attr)) {
0072             return;
0073         }
0074         if (SVGExternalResourcesRequired::parseMappedAttribute(attr)) {
0075             return;
0076         }
0077         SVGStyledTransformableElement::parseMappedAttribute(attr);
0078     }
0079 }
0080 
0081 void SVGLineElement::svgAttributeChanged(const QualifiedName &attrName)
0082 {
0083     SVGStyledTransformableElement::svgAttributeChanged(attrName);
0084 
0085     if (!renderer()) {
0086         return;
0087     }
0088 
0089     if (attrName == SVGNames::x1Attr || attrName == SVGNames::y1Attr ||
0090             attrName == SVGNames::x2Attr || attrName == SVGNames::y2Attr ||
0091             SVGTests::isKnownAttribute(attrName) ||
0092             SVGLangSpace::isKnownAttribute(attrName) ||
0093             SVGExternalResourcesRequired::isKnownAttribute(attrName) ||
0094             SVGStyledTransformableElement::isKnownAttribute(attrName)) {
0095         renderer()->setNeedsLayout(true);
0096     }
0097 }
0098 
0099 Path SVGLineElement::toPathData() const
0100 {
0101     return Path::createLine(FloatPoint(x1().value(), y1().value()),
0102                             FloatPoint(x2().value(), y2().value()));
0103 }
0104 
0105 bool SVGLineElement::hasRelativeValues() const
0106 {
0107     return (x1().isRelative() || y1().isRelative() ||
0108             x2().isRelative() || y2().isRelative());
0109 }
0110 
0111 }
0112 
0113 #endif // ENABLE(SVG)