| 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 | #include "RenderSVGGradientStop.h" |
| 22 | |
| 23 | #include "RenderSVGResourceContainer.h" |
| 24 | #include "SVGGradientElement.h" |
| 25 | #include "SVGNames.h" |
| 26 | #include "SVGResourcesCache.h" |
| 27 | #include "SVGStopElement.h" |
| 28 | #include <wtf/IsoMallocInlines.h> |
| 29 | #include <wtf/StackStats.h> |
| 30 | |
| 31 | namespace WebCore { |
| 32 | |
| 33 | using namespace SVGNames; |
| 34 | |
| 35 | WTF_MAKE_ISO_ALLOCATED_IMPL(RenderSVGGradientStop); |
| 36 | |
| 37 | RenderSVGGradientStop::RenderSVGGradientStop(SVGStopElement& element, RenderStyle&& style) |
| 38 | : RenderElement(element, WTFMove(style), 0) |
| 39 | { |
| 40 | } |
| 41 | |
| 42 | RenderSVGGradientStop::~RenderSVGGradientStop() = default; |
| 43 | |
| 44 | void RenderSVGGradientStop::styleDidChange(StyleDifference diff, const RenderStyle* oldStyle) |
| 45 | { |
| 46 | RenderElement::styleDidChange(diff, oldStyle); |
| 47 | if (diff == StyleDifference::Equal) |
| 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 | const auto* gradient = gradientElement(); |
| 53 | if (!gradient) |
| 54 | return; |
| 55 | |
| 56 | RenderElement* renderer = gradient->renderer(); |
| 57 | if (!renderer) |
| 58 | return; |
| 59 | |
| 60 | downcast<RenderSVGResourceContainer>(*renderer).removeAllClientsFromCache(); |
| 61 | } |
| 62 | |
| 63 | void RenderSVGGradientStop::layout() |
| 64 | { |
| 65 | StackStats::LayoutCheckPoint layoutCheckPoint; |
| 66 | clearNeedsLayout(); |
| 67 | } |
| 68 | |
| 69 | SVGGradientElement* RenderSVGGradientStop::gradientElement() |
| 70 | { |
| 71 | if (is<SVGGradientElement>(element().parentElement())) |
| 72 | return downcast<SVGGradientElement>(element().parentElement()); |
| 73 | return nullptr; |
| 74 | } |
| 75 | |
| 76 | } |
| 77 | |