Home | History | Annotate | Download | only in svg
      1 /*
      2  * Copyright (C) 2004, 2005, 2007, 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 #if ENABLE(SVG)
     24 #include "SVGStopElement.h"
     25 
     26 #include "Attribute.h"
     27 #include "Document.h"
     28 #include "RenderSVGGradientStop.h"
     29 #include "RenderSVGResource.h"
     30 #include "SVGGradientElement.h"
     31 #include "SVGNames.h"
     32 
     33 namespace WebCore {
     34 
     35 // Animated property definitions
     36 DEFINE_ANIMATED_NUMBER(SVGStopElement, SVGNames::offsetAttr, Offset, offset)
     37 
     38 inline SVGStopElement::SVGStopElement(const QualifiedName& tagName, Document* document)
     39     : SVGStyledElement(tagName, document)
     40     , m_offset(0)
     41 {
     42 }
     43 
     44 PassRefPtr<SVGStopElement> SVGStopElement::create(const QualifiedName& tagName, Document* document)
     45 {
     46     return adoptRef(new SVGStopElement(tagName, document));
     47 }
     48 
     49 void SVGStopElement::parseMappedAttribute(Attribute* attr)
     50 {
     51     if (attr->name() == SVGNames::offsetAttr) {
     52         const String& value = attr->value();
     53         if (value.endsWith("%"))
     54             setOffsetBaseValue(value.left(value.length() - 1).toFloat() / 100.0f);
     55         else
     56             setOffsetBaseValue(value.toFloat());
     57     } else
     58         SVGStyledElement::parseMappedAttribute(attr);
     59 }
     60 
     61 void SVGStopElement::svgAttributeChanged(const QualifiedName& attrName)
     62 {
     63     SVGStyledElement::svgAttributeChanged(attrName);
     64 
     65     if (!renderer())
     66         return;
     67 
     68     if (attrName == SVGNames::offsetAttr)
     69         RenderSVGResource::markForLayoutAndParentResourceInvalidation(renderer());
     70 }
     71 
     72 void SVGStopElement::synchronizeProperty(const QualifiedName& attrName)
     73 {
     74     SVGStyledElement::synchronizeProperty(attrName);
     75 
     76     if (attrName == anyQName() || attrName == SVGNames::offsetAttr)
     77         synchronizeOffset();
     78 }
     79 
     80 AttributeToPropertyTypeMap& SVGStopElement::attributeToPropertyTypeMap()
     81 {
     82     DEFINE_STATIC_LOCAL(AttributeToPropertyTypeMap, s_attributeToPropertyTypeMap, ());
     83     return s_attributeToPropertyTypeMap;
     84 }
     85 
     86 void SVGStopElement::fillAttributeToPropertyTypeMap()
     87 {
     88     AttributeToPropertyTypeMap& attributeToPropertyTypeMap = this->attributeToPropertyTypeMap();
     89 
     90     SVGStyledElement::fillPassedAttributeToPropertyTypeMap(attributeToPropertyTypeMap);
     91     attributeToPropertyTypeMap.set(SVGNames::offsetAttr, AnimatedLength);
     92 }
     93 
     94 RenderObject* SVGStopElement::createRenderer(RenderArena* arena, RenderStyle*)
     95 {
     96     return new (arena) RenderSVGGradientStop(this);
     97 }
     98 
     99 Color SVGStopElement::stopColorIncludingOpacity() const
    100 {
    101     ASSERT(renderer());
    102     ASSERT(renderer()->style());
    103 
    104     const SVGRenderStyle* svgStyle = renderer()->style()->svgStyle();
    105     return colorWithOverrideAlpha(svgStyle->stopColor().rgb(), svgStyle->stopOpacity());
    106 }
    107 
    108 }
    109 
    110 #endif // ENABLE(SVG)
    111