1/* 2 * Copyright (C) 2004, 2005, 2006, 2008 Nikolas Zimmermann <zimmermann@kde.org> 3 * Copyright (C) 2004, 2005, 2006, 2007 Rob Buis <buis@kde.org> 4 * 5 * This library is free software; you can redistribute it and/or 6 * modify it under the terms of the GNU Library General Public 7 * License as published by the Free Software Foundation; either 8 * version 2 of the License, or (at your option) any later version. 9 * 10 * This library is distributed in the hope that it will be useful, 11 * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 * Library General Public License for more details. 14 * 15 * You should have received a copy of the GNU Library General Public License 16 * along with this library; see the file COPYING.LIB. If not, write to 17 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 18 * Boston, MA 02110-1301, USA. 19 */ 20 21#include "config.h" 22 23#if ENABLE(SVG) 24#include "SVGLineElement.h" 25 26#include "Attribute.h" 27#include "FloatPoint.h" 28#include "RenderSVGPath.h" 29#include "RenderSVGResource.h" 30#include "SVGLength.h" 31#include "SVGNames.h" 32 33namespace WebCore { 34 35// Animated property definitions 36DEFINE_ANIMATED_LENGTH(SVGLineElement, SVGNames::x1Attr, X1, x1) 37DEFINE_ANIMATED_LENGTH(SVGLineElement, SVGNames::y1Attr, Y1, y1) 38DEFINE_ANIMATED_LENGTH(SVGLineElement, SVGNames::x2Attr, X2, x2) 39DEFINE_ANIMATED_LENGTH(SVGLineElement, SVGNames::y2Attr, Y2, y2) 40DEFINE_ANIMATED_BOOLEAN(SVGLineElement, SVGNames::externalResourcesRequiredAttr, ExternalResourcesRequired, externalResourcesRequired) 41 42inline SVGLineElement::SVGLineElement(const QualifiedName& tagName, Document* document) 43 : SVGStyledTransformableElement(tagName, document) 44 , m_x1(LengthModeWidth) 45 , m_y1(LengthModeHeight) 46 , m_x2(LengthModeWidth) 47 , m_y2(LengthModeHeight) 48{ 49} 50 51PassRefPtr<SVGLineElement> SVGLineElement::create(const QualifiedName& tagName, Document* document) 52{ 53 return adoptRef(new SVGLineElement(tagName, document)); 54} 55 56void SVGLineElement::parseMappedAttribute(Attribute* attr) 57{ 58 if (attr->name() == SVGNames::x1Attr) 59 setX1BaseValue(SVGLength(LengthModeWidth, attr->value())); 60 else if (attr->name() == SVGNames::y1Attr) 61 setY1BaseValue(SVGLength(LengthModeHeight, attr->value())); 62 else if (attr->name() == SVGNames::x2Attr) 63 setX2BaseValue(SVGLength(LengthModeWidth, attr->value())); 64 else if (attr->name() == SVGNames::y2Attr) 65 setY2BaseValue(SVGLength(LengthModeHeight, attr->value())); 66 else { 67 if (SVGTests::parseMappedAttribute(attr)) 68 return; 69 if (SVGLangSpace::parseMappedAttribute(attr)) 70 return; 71 if (SVGExternalResourcesRequired::parseMappedAttribute(attr)) 72 return; 73 SVGStyledTransformableElement::parseMappedAttribute(attr); 74 } 75} 76 77void SVGLineElement::svgAttributeChanged(const QualifiedName& attrName) 78{ 79 SVGStyledTransformableElement::svgAttributeChanged(attrName); 80 81 bool isLengthAttribute = attrName == SVGNames::x1Attr 82 || attrName == SVGNames::y1Attr 83 || attrName == SVGNames::x2Attr 84 || attrName == SVGNames::y2Attr; 85 86 if (isLengthAttribute) 87 updateRelativeLengthsInformation(); 88 89 if (SVGTests::handleAttributeChange(this, attrName)) 90 return; 91 92 RenderSVGPath* renderer = static_cast<RenderSVGPath*>(this->renderer()); 93 if (!renderer) 94 return; 95 96 if (isLengthAttribute) { 97 renderer->setNeedsPathUpdate(); 98 RenderSVGResource::markForLayoutAndParentResourceInvalidation(renderer); 99 return; 100 } 101 102 if (SVGLangSpace::isKnownAttribute(attrName) 103 || SVGExternalResourcesRequired::isKnownAttribute(attrName)) 104 RenderSVGResource::markForLayoutAndParentResourceInvalidation(renderer); 105} 106 107void SVGLineElement::synchronizeProperty(const QualifiedName& attrName) 108{ 109 SVGStyledTransformableElement::synchronizeProperty(attrName); 110 111 if (attrName == anyQName()) { 112 synchronizeX1(); 113 synchronizeY1(); 114 synchronizeX2(); 115 synchronizeY2(); 116 synchronizeExternalResourcesRequired(); 117 SVGTests::synchronizeProperties(this, attrName); 118 return; 119 } 120 121 if (attrName == SVGNames::x1Attr) 122 synchronizeX1(); 123 else if (attrName == SVGNames::y1Attr) 124 synchronizeY1(); 125 else if (attrName == SVGNames::x2Attr) 126 synchronizeX2(); 127 else if (attrName == SVGNames::y2Attr) 128 synchronizeY2(); 129 else if (SVGExternalResourcesRequired::isKnownAttribute(attrName)) 130 synchronizeExternalResourcesRequired(); 131 else if (SVGTests::isKnownAttribute(attrName)) 132 SVGTests::synchronizeProperties(this, attrName); 133} 134 135AttributeToPropertyTypeMap& SVGLineElement::attributeToPropertyTypeMap() 136{ 137 DEFINE_STATIC_LOCAL(AttributeToPropertyTypeMap, s_attributeToPropertyTypeMap, ()); 138 return s_attributeToPropertyTypeMap; 139} 140 141void SVGLineElement::fillAttributeToPropertyTypeMap() 142{ 143 AttributeToPropertyTypeMap& attributeToPropertyTypeMap = this->attributeToPropertyTypeMap(); 144 145 SVGStyledTransformableElement::fillPassedAttributeToPropertyTypeMap(attributeToPropertyTypeMap); 146 attributeToPropertyTypeMap.set(SVGNames::x1Attr, AnimatedLength); 147 attributeToPropertyTypeMap.set(SVGNames::y1Attr, AnimatedLength); 148 attributeToPropertyTypeMap.set(SVGNames::x2Attr, AnimatedLength); 149 attributeToPropertyTypeMap.set(SVGNames::y2Attr, AnimatedLength); 150} 151 152void SVGLineElement::toPathData(Path& path) const 153{ 154 ASSERT(path.isEmpty()); 155 156 path.moveTo(FloatPoint(x1().value(this), y1().value(this))); 157 path.addLineTo(FloatPoint(x2().value(this), y2().value(this))); 158} 159 160bool SVGLineElement::selfHasRelativeLengths() const 161{ 162 return x1().isRelative() 163 || y1().isRelative() 164 || x2().isRelative() 165 || y2().isRelative(); 166} 167 168} 169 170#endif // ENABLE(SVG) 171