Update To 11.40.268.0
[platform/framework/web/crosswalk.git] / src / third_party / WebKit / Source / core / svg / SVGStopElement.cpp
1 /*
2  * Copyright (C) 2004, 2005, 2007, 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 #include "core/svg/SVGStopElement.h"
23
24 #include "core/rendering/svg/RenderSVGGradientStop.h"
25
26 namespace blink {
27
28 inline SVGStopElement::SVGStopElement(Document& document)
29     : SVGElement(SVGNames::stopTag, document)
30     , m_offset(SVGAnimatedNumber::create(this, SVGNames::offsetAttr, SVGNumberAcceptPercentage::create()))
31 {
32     addToPropertyMap(m_offset);
33 }
34
35 DEFINE_NODE_FACTORY(SVGStopElement)
36
37 void SVGStopElement::parseAttribute(const QualifiedName& name, const AtomicString& value)
38 {
39     parseAttributeNew(name, value);
40 }
41
42 void SVGStopElement::svgAttributeChanged(const QualifiedName& attrName)
43 {
44     if (attrName == SVGNames::offsetAttr) {
45         SVGElement::InvalidationGuard invalidationGuard(this);
46
47         if (renderer())
48             markForLayoutAndParentResourceInvalidation(renderer());
49         return;
50     }
51
52     SVGElement::svgAttributeChanged(attrName);
53 }
54
55 RenderObject* SVGStopElement::createRenderer(RenderStyle*)
56 {
57     return new RenderSVGGradientStop(this);
58 }
59
60 bool SVGStopElement::rendererIsNeeded(const RenderStyle&)
61 {
62     return true;
63 }
64
65 Color SVGStopElement::stopColorIncludingOpacity() const
66 {
67     RenderStyle* style = renderer() ? renderer()->style() : 0;
68     // FIXME: This check for null style exists to address Bug WK 90814, a rare crash condition in
69     // which the renderer or style is null. This entire class is scheduled for removal (Bug WK 86941)
70     // and we will tolerate this null check until then.
71     if (!style)
72         return Color(Color::transparent); // Transparent black.
73
74     const SVGRenderStyle& svgStyle = style->svgStyle();
75     return svgStyle.stopColor().combineWithAlpha(svgStyle.stopOpacity());
76 }
77
78 } // namespace blink