1 /*
2 * Copyright (C) 2007 Eric Seidel <eric@webkit.org>
3 *
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Library General Public
6 * License as published by the Free Software Foundation; either
7 * version 2 of the License, or (at your option) any later version.
8 *
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Library General Public License for more details.
13 *
14 * You should have received a copy of the GNU Library General Public License
15 * along with this library; see the file COPYING.LIB. If not, write to
16 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17 * Boston, MA 02110-1301, USA.
18 */
19
20 #include "config.h"
21
22 #if ENABLE(SVG)
23 #include "RenderSVGGradientStop.h"
24
25 #include "RenderSVGResourceContainer.h"
26 #include "SVGGradientElement.h"
27 #include "SVGNames.h"
28 #include "SVGResourcesCache.h"
29 #include "SVGStopElement.h"
30
31 namespace WebCore {
32
33 using namespace SVGNames;
34
RenderSVGGradientStop(SVGStopElement * element)35 RenderSVGGradientStop::RenderSVGGradientStop(SVGStopElement* element)
36 : RenderObject(element)
37 {
38 }
39
~RenderSVGGradientStop()40 RenderSVGGradientStop::~RenderSVGGradientStop()
41 {
42 }
43
styleDidChange(StyleDifference diff,const RenderStyle * oldStyle)44 void RenderSVGGradientStop::styleDidChange(StyleDifference diff, const RenderStyle* oldStyle)
45 {
46 RenderObject::styleDidChange(diff, oldStyle);
47 if (diff == StyleDifferenceEqual)
48 return;
49
50 // <stop> elements should only be allowed to make renderers under gradient elements
51 // but I can imagine a few cases we might not be catching, so let's not crash if our parent isn't a gradient.
52 SVGGradientElement* gradient = gradientElement();
53 if (!gradient)
54 return;
55
56 RenderObject* renderer = gradient->renderer();
57 if (!renderer)
58 return;
59
60 ASSERT(renderer->isSVGResourceContainer());
61 RenderSVGResourceContainer* container = renderer->toRenderSVGResourceContainer();
62 container->removeAllClientsFromCache();
63 }
64
layout()65 void RenderSVGGradientStop::layout()
66 {
67 setNeedsLayout(false);
68 }
69
gradientElement() const70 SVGGradientElement* RenderSVGGradientStop::gradientElement() const
71 {
72 ContainerNode* parentNode = node()->parentNode();
73 if (parentNode->hasTagName(linearGradientTag) || parentNode->hasTagName(radialGradientTag))
74 return static_cast<SVGGradientElement*>(parentNode);
75 return 0;
76 }
77
78 }
79
80 #endif // ENABLE(SVG)
81