| 1 | /* |
| 2 | * Copyright (C) 2006 Nikolas Zimmermann <zimmermann@kde.org> |
| 3 | * Copyright (C) Research In Motion Limited 2010. All rights reserved. |
| 4 | * Copyright (C) 2012 Adobe Systems Incorporated. All rights reserved. |
| 5 | * |
| 6 | * This library is free software; you can redistribute it and/or |
| 7 | * modify it under the terms of the GNU Library General Public |
| 8 | * License as published by the Free Software Foundation; either |
| 9 | * version 2 of the License, or (at your option) any later version. |
| 10 | * |
| 11 | * This library is distributed in the hope that it will be useful, |
| 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 14 | * Library General Public License for more details. |
| 15 | * |
| 16 | * You should have received a copy of the GNU Library General Public License |
| 17 | * along with this library; see the file COPYING.LIB. If not, write to |
| 18 | * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, |
| 19 | * Boston, MA 02110-1301, USA. |
| 20 | */ |
| 21 | |
| 22 | #include "config.h" |
| 23 | #include "RenderSVGResourceRadialGradient.h" |
| 24 | |
| 25 | #include <wtf/IsoMallocInlines.h> |
| 26 | |
| 27 | namespace WebCore { |
| 28 | |
| 29 | WTF_MAKE_ISO_ALLOCATED_IMPL(RenderSVGResourceRadialGradient); |
| 30 | |
| 31 | RenderSVGResourceRadialGradient::RenderSVGResourceRadialGradient(SVGRadialGradientElement& element, RenderStyle&& style) |
| 32 | : RenderSVGResourceGradient(element, WTFMove(style)) |
| 33 | { |
| 34 | } |
| 35 | |
| 36 | RenderSVGResourceRadialGradient::~RenderSVGResourceRadialGradient() = default; |
| 37 | |
| 38 | bool RenderSVGResourceRadialGradient::collectGradientAttributes() |
| 39 | { |
| 40 | m_attributes = RadialGradientAttributes(); |
| 41 | return radialGradientElement().collectGradientAttributes(m_attributes); |
| 42 | } |
| 43 | |
| 44 | FloatPoint RenderSVGResourceRadialGradient::centerPoint(const RadialGradientAttributes& attributes) const |
| 45 | { |
| 46 | return SVGLengthContext::resolvePoint(&radialGradientElement(), attributes.gradientUnits(), attributes.cx(), attributes.cy()); |
| 47 | } |
| 48 | |
| 49 | FloatPoint RenderSVGResourceRadialGradient::focalPoint(const RadialGradientAttributes& attributes) const |
| 50 | { |
| 51 | return SVGLengthContext::resolvePoint(&radialGradientElement(), attributes.gradientUnits(), attributes.fx(), attributes.fy()); |
| 52 | } |
| 53 | |
| 54 | float RenderSVGResourceRadialGradient::radius(const RadialGradientAttributes& attributes) const |
| 55 | { |
| 56 | return SVGLengthContext::resolveLength(&radialGradientElement(), attributes.gradientUnits(), attributes.r()); |
| 57 | } |
| 58 | |
| 59 | float RenderSVGResourceRadialGradient::focalRadius(const RadialGradientAttributes& attributes) const |
| 60 | { |
| 61 | return SVGLengthContext::resolveLength(&radialGradientElement(), attributes.gradientUnits(), attributes.fr()); |
| 62 | } |
| 63 | |
| 64 | void RenderSVGResourceRadialGradient::buildGradient(GradientData* gradientData, const RenderStyle& style) const |
| 65 | { |
| 66 | gradientData->gradient = Gradient::create(Gradient::RadialData { this->focalPoint(m_attributes), this->centerPoint(m_attributes), this->focalRadius(m_attributes), this->radius(m_attributes), 1 }); |
| 67 | gradientData->gradient->setSpreadMethod(platformSpreadMethodFromSVGType(m_attributes.spreadMethod())); |
| 68 | |
| 69 | addStops(gradientData, m_attributes.stops(), style); |
| 70 | } |
| 71 | |
| 72 | } |
| 73 | |