1 /* 2 * Copyright (C) 2004, 2005, 2006, 2008 Nikolas Zimmermann <zimmermann (at) kde.org> 3 * Copyright (C) 2004, 2005, 2006, 2007 Rob Buis <buis (at) 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 #include "core/svg/SVGLineElement.h" 24 25 #include "core/rendering/svg/RenderSVGResource.h" 26 #include "core/svg/SVGLength.h" 27 28 namespace WebCore { 29 30 inline SVGLineElement::SVGLineElement(Document& document) 31 : SVGGeometryElement(SVGNames::lineTag, document) 32 , m_x1(SVGAnimatedLength::create(this, SVGNames::x1Attr, SVGLength::create(LengthModeWidth), AllowNegativeLengths)) 33 , m_y1(SVGAnimatedLength::create(this, SVGNames::y1Attr, SVGLength::create(LengthModeHeight), AllowNegativeLengths)) 34 , m_x2(SVGAnimatedLength::create(this, SVGNames::x2Attr, SVGLength::create(LengthModeWidth), AllowNegativeLengths)) 35 , m_y2(SVGAnimatedLength::create(this, SVGNames::y2Attr, SVGLength::create(LengthModeHeight), AllowNegativeLengths)) 36 { 37 ScriptWrappable::init(this); 38 39 addToPropertyMap(m_x1); 40 addToPropertyMap(m_y1); 41 addToPropertyMap(m_x2); 42 addToPropertyMap(m_y2); 43 } 44 45 DEFINE_NODE_FACTORY(SVGLineElement) 46 47 bool SVGLineElement::isSupportedAttribute(const QualifiedName& attrName) 48 { 49 DEFINE_STATIC_LOCAL(HashSet<QualifiedName>, supportedAttributes, ()); 50 if (supportedAttributes.isEmpty()) { 51 supportedAttributes.add(SVGNames::x1Attr); 52 supportedAttributes.add(SVGNames::x2Attr); 53 supportedAttributes.add(SVGNames::y1Attr); 54 supportedAttributes.add(SVGNames::y2Attr); 55 } 56 return supportedAttributes.contains<SVGAttributeHashTranslator>(attrName); 57 } 58 59 void SVGLineElement::parseAttribute(const QualifiedName& name, const AtomicString& value) 60 { 61 SVGParsingError parseError = NoError; 62 63 if (!isSupportedAttribute(name)) 64 SVGGeometryElement::parseAttribute(name, value); 65 else if (name == SVGNames::x1Attr) 66 m_x1->setBaseValueAsString(value, parseError); 67 else if (name == SVGNames::y1Attr) 68 m_y1->setBaseValueAsString(value, parseError); 69 else if (name == SVGNames::x2Attr) 70 m_x2->setBaseValueAsString(value, parseError); 71 else if (name == SVGNames::y2Attr) 72 m_y2->setBaseValueAsString(value, parseError); 73 else 74 ASSERT_NOT_REACHED(); 75 76 reportAttributeParsingError(parseError, name, value); 77 } 78 79 void SVGLineElement::svgAttributeChanged(const QualifiedName& attrName) 80 { 81 if (!isSupportedAttribute(attrName)) { 82 SVGGeometryElement::svgAttributeChanged(attrName); 83 return; 84 } 85 86 SVGElement::InvalidationGuard invalidationGuard(this); 87 88 bool isLengthAttribute = attrName == SVGNames::x1Attr 89 || attrName == SVGNames::y1Attr 90 || attrName == SVGNames::x2Attr 91 || attrName == SVGNames::y2Attr; 92 93 if (isLengthAttribute) 94 updateRelativeLengthsInformation(); 95 96 RenderSVGShape* renderer = toRenderSVGShape(this->renderer()); 97 if (!renderer) 98 return; 99 100 if (isLengthAttribute) { 101 renderer->setNeedsShapeUpdate(); 102 RenderSVGResource::markForLayoutAndParentResourceInvalidation(renderer); 103 return; 104 } 105 106 ASSERT_NOT_REACHED(); 107 } 108 109 bool SVGLineElement::selfHasRelativeLengths() const 110 { 111 return m_x1->currentValue()->isRelative() 112 || m_y1->currentValue()->isRelative() 113 || m_x2->currentValue()->isRelative() 114 || m_y2->currentValue()->isRelative(); 115 } 116 117 } 118