blob: f946f5a7ac7ba99286296ab126530ee820adb6d2 [file] [log] [blame]
/*
* Copyright (C) 2007 Nikolas Zimmermann <zimmermann@kde.org>
* Copyright (C) 2010 Rob Buis <rwlbuis@gmail.com>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public License
* along with this library; see the file COPYING.LIB. If not, write to
* the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301, USA.
*/
#include "config.h"
#if ENABLE(SVG)
#include "SVGTextPathElement.h"
#include "Attribute.h"
#include "RenderSVGResource.h"
#include "RenderSVGTextPath.h"
#include "SVGElementInstance.h"
#include "SVGNames.h"
namespace WebCore {
// Animated property definitions
DEFINE_ANIMATED_LENGTH(SVGTextPathElement, SVGNames::startOffsetAttr, StartOffset, startOffset)
DEFINE_ANIMATED_ENUMERATION(SVGTextPathElement, SVGNames::methodAttr, Method, method, SVGTextPathMethodType)
DEFINE_ANIMATED_ENUMERATION(SVGTextPathElement, SVGNames::spacingAttr, Spacing, spacing, SVGTextPathSpacingType)
DEFINE_ANIMATED_STRING(SVGTextPathElement, XLinkNames::hrefAttr, Href, href)
BEGIN_REGISTER_ANIMATED_PROPERTIES(SVGTextPathElement)
REGISTER_LOCAL_ANIMATED_PROPERTY(startOffset)
REGISTER_LOCAL_ANIMATED_PROPERTY(method)
REGISTER_LOCAL_ANIMATED_PROPERTY(spacing)
REGISTER_LOCAL_ANIMATED_PROPERTY(href)
REGISTER_PARENT_ANIMATED_PROPERTIES(SVGTextContentElement)
END_REGISTER_ANIMATED_PROPERTIES
inline SVGTextPathElement::SVGTextPathElement(const QualifiedName& tagName, Document* document)
: SVGTextContentElement(tagName, document)
, m_startOffset(LengthModeOther)
, m_method(SVGTextPathMethodAlign)
, m_spacing(SVGTextPathSpacingExact)
{
ASSERT(hasTagName(SVGNames::textPathTag));
registerAnimatedPropertiesForSVGTextPathElement();
}
PassRefPtr<SVGTextPathElement> SVGTextPathElement::create(const QualifiedName& tagName, Document* document)
{
return adoptRef(new SVGTextPathElement(tagName, document));
}
bool SVGTextPathElement::isSupportedAttribute(const QualifiedName& attrName)
{
DEFINE_STATIC_LOCAL(HashSet<QualifiedName>, supportedAttributes, ());
if (supportedAttributes.isEmpty()) {
SVGURIReference::addSupportedAttributes(supportedAttributes);
supportedAttributes.add(SVGNames::startOffsetAttr);
supportedAttributes.add(SVGNames::methodAttr);
supportedAttributes.add(SVGNames::spacingAttr);
}
return supportedAttributes.contains(attrName);
}
void SVGTextPathElement::parseMappedAttribute(Attribute* attr)
{
if (!isSupportedAttribute(attr->name())) {
SVGTextContentElement::parseMappedAttribute(attr);
return;
}
const AtomicString& value = attr->value();
if (attr->name() == SVGNames::startOffsetAttr) {
setStartOffsetBaseValue(SVGLength(LengthModeOther, value));
return;
}
if (attr->name() == SVGNames::methodAttr) {
SVGTextPathMethodType propertyValue = SVGPropertyTraits<SVGTextPathMethodType>::fromString(value);
if (propertyValue > 0)
setMethodBaseValue(propertyValue);
return;
}
if (attr->name() == SVGNames::spacingAttr) {
SVGTextPathSpacingType propertyValue = SVGPropertyTraits<SVGTextPathSpacingType>::fromString(value);
if (propertyValue > 0)
setSpacingBaseValue(propertyValue);
return;
}
if (SVGURIReference::parseMappedAttribute(attr))
return;
ASSERT_NOT_REACHED();
}
void SVGTextPathElement::svgAttributeChanged(const QualifiedName& attrName)
{
if (!isSupportedAttribute(attrName)) {
SVGTextContentElement::svgAttributeChanged(attrName);
return;
}
SVGElementInstance::InvalidationGuard invalidationGuard(this);
if (attrName == SVGNames::startOffsetAttr)
updateRelativeLengthsInformation();
if (RenderObject* object = renderer())
RenderSVGResource::markForLayoutAndParentResourceInvalidation(object);
}
RenderObject* SVGTextPathElement::createRenderer(RenderArena* arena, RenderStyle*)
{
return new (arena) RenderSVGTextPath(this);
}
bool SVGTextPathElement::childShouldCreateRenderer(Node* child) const
{
if (child->isTextNode()
|| child->hasTagName(SVGNames::aTag)
|| child->hasTagName(SVGNames::trefTag)
|| child->hasTagName(SVGNames::tspanTag))
return true;
return false;
}
bool SVGTextPathElement::rendererIsNeeded(const NodeRenderingContext& context)
{
if (parentNode()
&& (parentNode()->hasTagName(SVGNames::aTag)
|| parentNode()->hasTagName(SVGNames::textTag)))
return StyledElement::rendererIsNeeded(context);
return false;
}
void SVGTextPathElement::insertedIntoDocument()
{
SVGTextContentElement::insertedIntoDocument();
String id = SVGURIReference::getTarget(href());
Element* targetElement = treeScope()->getElementById(id);
if (!targetElement) {
document()->accessSVGExtensions()->addPendingResource(id, this);
return;
}
}
bool SVGTextPathElement::selfHasRelativeLengths() const
{
return startOffset().isRelative()
|| SVGTextContentElement::selfHasRelativeLengths();
}
}
#endif // ENABLE(SVG)