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