Home | History | Annotate | Download | only in svg
      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/SVGCircleElement.h"
     24 
     25 #include "core/rendering/svg/RenderSVGEllipse.h"
     26 #include "core/rendering/svg/RenderSVGResource.h"
     27 #include "core/svg/SVGElementInstance.h"
     28 #include "core/svg/SVGLength.h"
     29 
     30 namespace WebCore {
     31 
     32 // Animated property definitions
     33 DEFINE_ANIMATED_LENGTH(SVGCircleElement, SVGNames::cxAttr, Cx, cx)
     34 DEFINE_ANIMATED_LENGTH(SVGCircleElement, SVGNames::cyAttr, Cy, cy)
     35 DEFINE_ANIMATED_LENGTH(SVGCircleElement, SVGNames::rAttr, R, r)
     36 DEFINE_ANIMATED_BOOLEAN(SVGCircleElement, SVGNames::externalResourcesRequiredAttr, ExternalResourcesRequired, externalResourcesRequired)
     37 
     38 BEGIN_REGISTER_ANIMATED_PROPERTIES(SVGCircleElement)
     39     REGISTER_LOCAL_ANIMATED_PROPERTY(cx)
     40     REGISTER_LOCAL_ANIMATED_PROPERTY(cy)
     41     REGISTER_LOCAL_ANIMATED_PROPERTY(r)
     42     REGISTER_LOCAL_ANIMATED_PROPERTY(externalResourcesRequired)
     43     REGISTER_PARENT_ANIMATED_PROPERTIES(SVGGraphicsElement)
     44 END_REGISTER_ANIMATED_PROPERTIES
     45 
     46 inline SVGCircleElement::SVGCircleElement(Document& document)
     47     : SVGGeometryElement(SVGNames::circleTag, document)
     48     , m_cx(LengthModeWidth)
     49     , m_cy(LengthModeHeight)
     50     , m_r(LengthModeOther)
     51 {
     52     ScriptWrappable::init(this);
     53     registerAnimatedPropertiesForSVGCircleElement();
     54 }
     55 
     56 PassRefPtr<SVGCircleElement> SVGCircleElement::create(Document& document)
     57 {
     58     return adoptRef(new SVGCircleElement(document));
     59 }
     60 
     61 bool SVGCircleElement::isSupportedAttribute(const QualifiedName& attrName)
     62 {
     63     DEFINE_STATIC_LOCAL(HashSet<QualifiedName>, supportedAttributes, ());
     64     if (supportedAttributes.isEmpty()) {
     65         SVGExternalResourcesRequired::addSupportedAttributes(supportedAttributes);
     66         supportedAttributes.add(SVGNames::cxAttr);
     67         supportedAttributes.add(SVGNames::cyAttr);
     68         supportedAttributes.add(SVGNames::rAttr);
     69     }
     70     return supportedAttributes.contains<SVGAttributeHashTranslator>(attrName);
     71 }
     72 
     73 void SVGCircleElement::parseAttribute(const QualifiedName& name, const AtomicString& value)
     74 {
     75     SVGParsingError parseError = NoError;
     76 
     77     if (!isSupportedAttribute(name))
     78         SVGGeometryElement::parseAttribute(name, value);
     79     else if (name == SVGNames::cxAttr)
     80         setCxBaseValue(SVGLength::construct(LengthModeWidth, value, parseError));
     81     else if (name == SVGNames::cyAttr)
     82         setCyBaseValue(SVGLength::construct(LengthModeHeight, value, parseError));
     83     else if (name == SVGNames::rAttr)
     84         setRBaseValue(SVGLength::construct(LengthModeOther, value, parseError, ForbidNegativeLengths));
     85     else if (SVGExternalResourcesRequired::parseAttribute(name, value)) {
     86     } else
     87         ASSERT_NOT_REACHED();
     88 
     89     reportAttributeParsingError(parseError, name, value);
     90 }
     91 
     92 void SVGCircleElement::svgAttributeChanged(const QualifiedName& attrName)
     93 {
     94     if (!isSupportedAttribute(attrName)) {
     95         SVGGeometryElement::svgAttributeChanged(attrName);
     96         return;
     97     }
     98 
     99     SVGElementInstance::InvalidationGuard invalidationGuard(this);
    100 
    101     bool isLengthAttribute = attrName == SVGNames::cxAttr
    102                           || attrName == SVGNames::cyAttr
    103                           || attrName == SVGNames::rAttr;
    104 
    105     if (isLengthAttribute)
    106         updateRelativeLengthsInformation();
    107 
    108     RenderSVGShape* renderer = toRenderSVGShape(this->renderer());
    109     if (!renderer)
    110         return;
    111 
    112     if (isLengthAttribute) {
    113         renderer->setNeedsShapeUpdate();
    114         RenderSVGResource::markForLayoutAndParentResourceInvalidation(renderer);
    115         return;
    116     }
    117 
    118     if (SVGExternalResourcesRequired::isKnownAttribute(attrName)) {
    119         RenderSVGResource::markForLayoutAndParentResourceInvalidation(renderer);
    120         return;
    121     }
    122 
    123     ASSERT_NOT_REACHED();
    124 }
    125 
    126 bool SVGCircleElement::selfHasRelativeLengths() const
    127 {
    128     return cxCurrentValue().isRelative()
    129         || cyCurrentValue().isRelative()
    130         || rCurrentValue().isRelative();
    131 }
    132 
    133 RenderObject* SVGCircleElement::createRenderer(RenderStyle*)
    134 {
    135     return new RenderSVGEllipse(this);
    136 }
    137 
    138 }
    139