SVGMarkerElement.cpp [plain text]
#include "config.h"
#if ENABLE(SVG)
#include "SVGMarkerElement.h"
#include "Attribute.h"
#include "RenderSVGResourceMarker.h"
#include "SVGElementInstance.h"
#include "SVGFitToViewBox.h"
#include "SVGNames.h"
#include "SVGSVGElement.h"
namespace WebCore {
const SVGPropertyInfo* SVGMarkerElement::orientTypePropertyInfo()
{
static const SVGPropertyInfo* s_propertyInfo = 0;
if (!s_propertyInfo) {
s_propertyInfo = new SVGPropertyInfo(AnimatedEnumeration,
SVGNames::orientAttr,
orientTypeIdentifier(),
&SVGMarkerElement::synchronizeOrientType,
&SVGMarkerElement::lookupOrCreateOrientTypeWrapper);
}
return s_propertyInfo;
}
DEFINE_ANIMATED_LENGTH(SVGMarkerElement, SVGNames::refXAttr, RefX, refX)
DEFINE_ANIMATED_LENGTH(SVGMarkerElement, SVGNames::refYAttr, RefY, refY)
DEFINE_ANIMATED_LENGTH(SVGMarkerElement, SVGNames::markerWidthAttr, MarkerWidth, markerWidth)
DEFINE_ANIMATED_LENGTH(SVGMarkerElement, SVGNames::markerHeightAttr, MarkerHeight, markerHeight)
DEFINE_ANIMATED_ENUMERATION(SVGMarkerElement, SVGNames::markerUnitsAttr, MarkerUnits, markerUnits, SVGMarkerUnitsType)
DEFINE_ANIMATED_ANGLE_AND_ENUMERATION(SVGMarkerElement, SVGNames::orientAttr, orientAngleIdentifier(), OrientAngle, orientAngle)
DEFINE_ANIMATED_BOOLEAN(SVGMarkerElement, SVGNames::externalResourcesRequiredAttr, ExternalResourcesRequired, externalResourcesRequired)
DEFINE_ANIMATED_RECT(SVGMarkerElement, SVGNames::viewBoxAttr, ViewBox, viewBox)
DEFINE_ANIMATED_PRESERVEASPECTRATIO(SVGMarkerElement, SVGNames::preserveAspectRatioAttr, PreserveAspectRatio, preserveAspectRatio)
BEGIN_REGISTER_ANIMATED_PROPERTIES(SVGMarkerElement)
REGISTER_LOCAL_ANIMATED_PROPERTY(refX)
REGISTER_LOCAL_ANIMATED_PROPERTY(refY)
REGISTER_LOCAL_ANIMATED_PROPERTY(markerWidth)
REGISTER_LOCAL_ANIMATED_PROPERTY(markerHeight)
REGISTER_LOCAL_ANIMATED_PROPERTY(markerUnits)
REGISTER_LOCAL_ANIMATED_PROPERTY(orientAngle)
REGISTER_LOCAL_ANIMATED_PROPERTY(orientType)
REGISTER_LOCAL_ANIMATED_PROPERTY(externalResourcesRequired)
REGISTER_LOCAL_ANIMATED_PROPERTY(viewBox)
REGISTER_LOCAL_ANIMATED_PROPERTY(preserveAspectRatio)
REGISTER_PARENT_ANIMATED_PROPERTIES(SVGStyledElement)
END_REGISTER_ANIMATED_PROPERTIES
inline SVGMarkerElement::SVGMarkerElement(const QualifiedName& tagName, Document* document)
: SVGStyledElement(tagName, document)
, m_refX(LengthModeWidth)
, m_refY(LengthModeHeight)
, m_markerWidth(LengthModeWidth, "3")
, m_markerHeight(LengthModeHeight, "3")
, m_markerUnits(SVGMarkerUnitsStrokeWidth)
, m_orientType(SVGMarkerOrientAngle)
{
ASSERT(hasTagName(SVGNames::markerTag));
registerAnimatedPropertiesForSVGMarkerElement();
}
PassRefPtr<SVGMarkerElement> SVGMarkerElement::create(const QualifiedName& tagName, Document* document)
{
return adoptRef(new SVGMarkerElement(tagName, document));
}
const AtomicString& SVGMarkerElement::orientTypeIdentifier()
{
DEFINE_STATIC_LOCAL(AtomicString, s_identifier, ("SVGOrientType"));
return s_identifier;
}
const AtomicString& SVGMarkerElement::orientAngleIdentifier()
{
DEFINE_STATIC_LOCAL(AtomicString, s_identifier, ("SVGOrientAngle"));
return s_identifier;
}
AffineTransform SVGMarkerElement::viewBoxToViewTransform(float viewWidth, float viewHeight) const
{
return SVGFitToViewBox::viewBoxToViewTransform(viewBox(), preserveAspectRatio(), viewWidth, viewHeight);
}
bool SVGMarkerElement::isSupportedAttribute(const QualifiedName& attrName)
{
DEFINE_STATIC_LOCAL(HashSet<QualifiedName>, supportedAttributes, ());
if (supportedAttributes.isEmpty()) {
SVGLangSpace::addSupportedAttributes(supportedAttributes);
SVGExternalResourcesRequired::addSupportedAttributes(supportedAttributes);
SVGFitToViewBox::addSupportedAttributes(supportedAttributes);
supportedAttributes.add(SVGNames::markerUnitsAttr);
supportedAttributes.add(SVGNames::refXAttr);
supportedAttributes.add(SVGNames::refYAttr);
supportedAttributes.add(SVGNames::markerWidthAttr);
supportedAttributes.add(SVGNames::markerHeightAttr);
supportedAttributes.add(SVGNames::orientAttr);
}
return supportedAttributes.contains<QualifiedName, SVGAttributeHashTranslator>(attrName);
}
void SVGMarkerElement::parseAttribute(Attribute* attr)
{
SVGParsingError parseError = NoError;
const AtomicString& value = attr->value();
if (!isSupportedAttribute(attr->name()))
SVGStyledElement::parseAttribute(attr);
else if (attr->name() == SVGNames::markerUnitsAttr) {
SVGMarkerUnitsType propertyValue = SVGPropertyTraits<SVGMarkerUnitsType>::fromString(value);
if (propertyValue > 0)
setMarkerUnitsBaseValue(propertyValue);
} else if (attr->name() == SVGNames::refXAttr)
setRefXBaseValue(SVGLength::construct(LengthModeWidth, value, parseError));
else if (attr->name() == SVGNames::refYAttr)
setRefYBaseValue(SVGLength::construct(LengthModeHeight, value, parseError));
else if (attr->name() == SVGNames::markerWidthAttr)
setMarkerWidthBaseValue(SVGLength::construct(LengthModeWidth, value, parseError));
else if (attr->name() == SVGNames::markerHeightAttr)
setMarkerHeightBaseValue(SVGLength::construct(LengthModeHeight, value, parseError));
else if (attr->name() == SVGNames::orientAttr) {
SVGAngle angle;
SVGMarkerOrientType orientType = SVGPropertyTraits<SVGMarkerOrientType>::fromString(value, angle);
if (orientType > 0)
setOrientTypeBaseValue(orientType);
if (orientType == SVGMarkerOrientAngle)
setOrientAngleBaseValue(angle);
} else if (SVGLangSpace::parseAttribute(attr)
|| SVGExternalResourcesRequired::parseAttribute(attr)
|| SVGFitToViewBox::parseAttribute(document(), attr)) {
} else
ASSERT_NOT_REACHED();
reportAttributeParsingError(parseError, attr);
}
void SVGMarkerElement::svgAttributeChanged(const QualifiedName& attrName)
{
if (!isSupportedAttribute(attrName)) {
SVGStyledElement::svgAttributeChanged(attrName);
return;
}
SVGElementInstance::InvalidationGuard invalidationGuard(this);
if (attrName == SVGNames::refXAttr
|| attrName == SVGNames::refYAttr
|| attrName == SVGNames::markerWidthAttr
|| attrName == SVGNames::markerHeightAttr)
updateRelativeLengthsInformation();
if (RenderObject* object = renderer())
object->setNeedsLayout(true);
}
void SVGMarkerElement::childrenChanged(bool changedByParser, Node* beforeChange, Node* afterChange, int childCountDelta)
{
SVGStyledElement::childrenChanged(changedByParser, beforeChange, afterChange, childCountDelta);
if (changedByParser)
return;
if (RenderObject* object = renderer())
object->setNeedsLayout(true);
}
void SVGMarkerElement::setOrientToAuto()
{
setOrientTypeBaseValue(SVGMarkerOrientAuto);
setOrientAngleBaseValue(SVGAngle());
m_orientAngle.shouldSynchronize = true;
m_orientType.shouldSynchronize = true;
invalidateSVGAttributes();
svgAttributeChanged(orientAnglePropertyInfo()->attributeName);
}
void SVGMarkerElement::setOrientToAngle(const SVGAngle& angle)
{
setOrientTypeBaseValue(SVGMarkerOrientAngle);
setOrientAngleBaseValue(angle);
m_orientAngle.shouldSynchronize = true;
m_orientType.shouldSynchronize = true;
invalidateSVGAttributes();
svgAttributeChanged(orientAnglePropertyInfo()->attributeName);
}
RenderObject* SVGMarkerElement::createRenderer(RenderArena* arena, RenderStyle*)
{
return new (arena) RenderSVGResourceMarker(this);
}
bool SVGMarkerElement::selfHasRelativeLengths() const
{
return refX().isRelative()
|| refY().isRelative()
|| markerWidth().isRelative()
|| markerHeight().isRelative();
}
void SVGMarkerElement::synchronizeOrientType(void* contextElement)
{
ASSERT(contextElement);
SVGMarkerElement* ownerType = static_cast<SVGMarkerElement*>(contextElement);
if (!ownerType->m_orientType.shouldSynchronize)
return;
if (ownerType->m_orientType.value != SVGMarkerOrientAuto)
return;
DEFINE_STATIC_LOCAL(AtomicString, autoString, ("auto"));
SVGAnimatedPropertySynchronizer<true>::synchronize(ownerType, orientTypePropertyInfo()->attributeName, autoString);
}
PassRefPtr<SVGAnimatedProperty> SVGMarkerElement::lookupOrCreateOrientTypeWrapper(void* contextElement)
{
ASSERT(contextElement);
SVGMarkerElement* ownerType = static_cast<SVGMarkerElement*>(contextElement);
return SVGAnimatedProperty::lookupOrCreateWrapper<SVGMarkerElement, SVGAnimatedEnumerationPropertyTearOff<SVGMarkerOrientType>, SVGMarkerOrientType, true>
(ownerType, orientTypePropertyInfo(), ownerType->m_orientType.value);
}
PassRefPtr<SVGAnimatedEnumerationPropertyTearOff<SVGMarkerOrientType> > SVGMarkerElement::orientTypeAnimated()
{
m_orientType.shouldSynchronize = true;
return static_pointer_cast<SVGAnimatedEnumerationPropertyTearOff<SVGMarkerOrientType> >(lookupOrCreateOrientTypeWrapper(this));
}
}
#endif