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 #include "core/svg/SVGStopElement.h" 24 25 #include "core/rendering/svg/RenderSVGGradientStop.h" 26 #include "core/rendering/svg/RenderSVGResource.h" 27 28 namespace WebCore { 29 30 inline SVGStopElement::SVGStopElement(Document& document) 31 : SVGElement(SVGNames::stopTag, document) 32 , m_offset(SVGAnimatedNumber::create(this, SVGNames::offsetAttr, SVGNumberAcceptPercentage::create())) 33 { 34 ScriptWrappable::init(this); 35 36 addToPropertyMap(m_offset); 37 } 38 39 DEFINE_NODE_FACTORY(SVGStopElement) 40 41 bool SVGStopElement::isSupportedAttribute(const QualifiedName& attrName) 42 { 43 DEFINE_STATIC_LOCAL(HashSet<QualifiedName>, supportedAttributes, ()); 44 if (supportedAttributes.isEmpty()) 45 supportedAttributes.add(SVGNames::offsetAttr); 46 return supportedAttributes.contains<SVGAttributeHashTranslator>(attrName); 47 } 48 49 void SVGStopElement::parseAttribute(const QualifiedName& name, const AtomicString& value) 50 { 51 if (!isSupportedAttribute(name)) { 52 SVGElement::parseAttribute(name, value); 53 return; 54 } 55 56 SVGParsingError parseError = NoError; 57 58 if (name == SVGNames::offsetAttr) 59 m_offset->setBaseValueAsString(value, parseError); 60 else 61 ASSERT_NOT_REACHED(); 62 63 reportAttributeParsingError(parseError, name, value); 64 } 65 66 void SVGStopElement::svgAttributeChanged(const QualifiedName& attrName) 67 { 68 if (!isSupportedAttribute(attrName)) { 69 SVGElement::svgAttributeChanged(attrName); 70 return; 71 } 72 73 SVGElement::InvalidationGuard invalidationGuard(this); 74 75 if (!renderer()) 76 return; 77 78 if (attrName == SVGNames::offsetAttr) { 79 RenderSVGResource::markForLayoutAndParentResourceInvalidation(renderer()); 80 return; 81 } 82 83 ASSERT_NOT_REACHED(); 84 } 85 86 RenderObject* SVGStopElement::createRenderer(RenderStyle*) 87 { 88 return new RenderSVGGradientStop(this); 89 } 90 91 bool SVGStopElement::rendererIsNeeded(const RenderStyle&) 92 { 93 return true; 94 } 95 96 Color SVGStopElement::stopColorIncludingOpacity() const 97 { 98 RenderStyle* style = renderer() ? renderer()->style() : 0; 99 // FIXME: This check for null style exists to address Bug WK 90814, a rare crash condition in 100 // which the renderer or style is null. This entire class is scheduled for removal (Bug WK 86941) 101 // and we will tolerate this null check until then. 102 if (!style || !style->svgStyle()) 103 return Color(Color::transparent); // Transparent black. 104 105 const SVGRenderStyle* svgStyle = style->svgStyle(); 106 return svgStyle->stopColor().combineWithAlpha(svgStyle->stopOpacity()); 107 } 108 109 } 110