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#include "core/svg/SVGCircleElement.h" 24 25#include "core/rendering/svg/RenderSVGEllipse.h" 26#include "core/rendering/svg/RenderSVGResource.h" 27#include "core/svg/SVGLength.h" 28 29namespace blink { 30 31inline SVGCircleElement::SVGCircleElement(Document& document) 32 : SVGGeometryElement(SVGNames::circleTag, document) 33 , m_cx(SVGAnimatedLength::create(this, SVGNames::cxAttr, SVGLength::create(LengthModeWidth), AllowNegativeLengths)) 34 , m_cy(SVGAnimatedLength::create(this, SVGNames::cyAttr, SVGLength::create(LengthModeHeight), AllowNegativeLengths)) 35 , m_r(SVGAnimatedLength::create(this, SVGNames::rAttr, SVGLength::create(LengthModeOther), ForbidNegativeLengths)) 36{ 37 addToPropertyMap(m_cx); 38 addToPropertyMap(m_cy); 39 addToPropertyMap(m_r); 40} 41 42DEFINE_NODE_FACTORY(SVGCircleElement) 43 44bool SVGCircleElement::isSupportedAttribute(const QualifiedName& attrName) 45{ 46 DEFINE_STATIC_LOCAL(HashSet<QualifiedName>, supportedAttributes, ()); 47 if (supportedAttributes.isEmpty()) { 48 supportedAttributes.add(SVGNames::cxAttr); 49 supportedAttributes.add(SVGNames::cyAttr); 50 supportedAttributes.add(SVGNames::rAttr); 51 } 52 return supportedAttributes.contains<SVGAttributeHashTranslator>(attrName); 53} 54 55void SVGCircleElement::parseAttribute(const QualifiedName& name, const AtomicString& value) 56{ 57 parseAttributeNew(name, value); 58} 59 60void SVGCircleElement::svgAttributeChanged(const QualifiedName& attrName) 61{ 62 if (!isSupportedAttribute(attrName)) { 63 SVGGeometryElement::svgAttributeChanged(attrName); 64 return; 65 } 66 67 SVGElement::InvalidationGuard invalidationGuard(this); 68 69 bool isLengthAttribute = attrName == SVGNames::cxAttr 70 || attrName == SVGNames::cyAttr 71 || attrName == SVGNames::rAttr; 72 73 if (isLengthAttribute) 74 updateRelativeLengthsInformation(); 75 76 RenderSVGShape* renderer = toRenderSVGShape(this->renderer()); 77 if (!renderer) 78 return; 79 80 if (isLengthAttribute) { 81 renderer->setNeedsShapeUpdate(); 82 RenderSVGResource::markForLayoutAndParentResourceInvalidation(renderer); 83 return; 84 } 85 86 ASSERT_NOT_REACHED(); 87} 88 89bool SVGCircleElement::selfHasRelativeLengths() const 90{ 91 return m_cx->currentValue()->isRelative() 92 || m_cy->currentValue()->isRelative() 93 || m_r->currentValue()->isRelative(); 94} 95 96RenderObject* SVGCircleElement::createRenderer(RenderStyle*) 97{ 98 return new RenderSVGEllipse(this); 99} 100 101} 102