This source file includes following definitions.
- m_offset
- create
- isSupportedAttribute
- parseAttribute
- svgAttributeChanged
- createRenderer
- rendererIsNeeded
- stopColorIncludingOpacity
#include "config.h"
#include "core/svg/SVGStopElement.h"
#include "core/rendering/svg/RenderSVGGradientStop.h"
#include "core/rendering/svg/RenderSVGResource.h"
#include "core/svg/SVGElementInstance.h"
namespace WebCore {
inline SVGStopElement::SVGStopElement(Document& document)
: SVGElement(SVGNames::stopTag, document)
, m_offset(SVGAnimatedNumber::create(this, SVGNames::offsetAttr, SVGNumberAcceptPercentage::create()))
{
ScriptWrappable::init(this);
addToPropertyMap(m_offset);
}
PassRefPtr<SVGStopElement> SVGStopElement::create(Document& document)
{
return adoptRef(new SVGStopElement(document));
}
bool SVGStopElement::isSupportedAttribute(const QualifiedName& attrName)
{
DEFINE_STATIC_LOCAL(HashSet<QualifiedName>, supportedAttributes, ());
if (supportedAttributes.isEmpty())
supportedAttributes.add(SVGNames::offsetAttr);
return supportedAttributes.contains<SVGAttributeHashTranslator>(attrName);
}
void SVGStopElement::parseAttribute(const QualifiedName& name, const AtomicString& value)
{
if (!isSupportedAttribute(name)) {
SVGElement::parseAttribute(name, value);
return;
}
SVGParsingError parseError = NoError;
if (name == SVGNames::offsetAttr)
m_offset->setBaseValueAsString(value, parseError);
else
ASSERT_NOT_REACHED();
reportAttributeParsingError(parseError, name, value);
}
void SVGStopElement::svgAttributeChanged(const QualifiedName& attrName)
{
if (!isSupportedAttribute(attrName)) {
SVGElement::svgAttributeChanged(attrName);
return;
}
SVGElementInstance::InvalidationGuard invalidationGuard(this);
if (!renderer())
return;
if (attrName == SVGNames::offsetAttr) {
RenderSVGResource::markForLayoutAndParentResourceInvalidation(renderer());
return;
}
ASSERT_NOT_REACHED();
}
RenderObject* SVGStopElement::createRenderer(RenderStyle*)
{
return new RenderSVGGradientStop(this);
}
bool SVGStopElement::rendererIsNeeded(const RenderStyle&)
{
return true;
}
Color SVGStopElement::stopColorIncludingOpacity() const
{
RenderStyle* style = renderer() ? renderer()->style() : 0;
if (!style || !style->svgStyle())
return Color(Color::transparent);
const SVGRenderStyle* svgStyle = style->svgStyle();
return svgStyle->stopColor().combineWithAlpha(svgStyle->stopOpacity());
}
}