2 * Copyright (C) 2004, 2005, 2008 Nikolas Zimmermann <zimmermann@kde.org>
3 * Copyright (C) 2004, 2005, 2006, 2007, 2008 Rob Buis <buis@kde.org>
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Library General Public
7 * License as published by the Free Software Foundation; either
8 * version 2 of the License, or (at your option) any later version.
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Library General Public License for more details.
15 * You should have received a copy of the GNU Library General Public License
16 * along with this library; see the file COPYING.LIB. If not, write to
17 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18 * Boston, MA 02110-1301, USA.
23 #include "core/svg/SVGTextPositioningElement.h"
25 #include "core/SVGNames.h"
26 #include "core/rendering/svg/RenderSVGResource.h"
27 #include "core/rendering/svg/RenderSVGText.h"
28 #include "core/svg/SVGLengthList.h"
29 #include "core/svg/SVGNumberList.h"
33 SVGTextPositioningElement::SVGTextPositioningElement(const QualifiedName& tagName, Document& document)
34 : SVGTextContentElement(tagName, document)
35 , m_x(SVGAnimatedLengthList::create(this, SVGNames::xAttr, SVGLengthList::create(LengthModeWidth)))
36 , m_y(SVGAnimatedLengthList::create(this, SVGNames::yAttr, SVGLengthList::create(LengthModeHeight)))
37 , m_dx(SVGAnimatedLengthList::create(this, SVGNames::dxAttr, SVGLengthList::create(LengthModeWidth)))
38 , m_dy(SVGAnimatedLengthList::create(this, SVGNames::dyAttr, SVGLengthList::create(LengthModeHeight)))
39 , m_rotate(SVGAnimatedNumberList::create(this, SVGNames::rotateAttr, SVGNumberList::create()))
41 addToPropertyMap(m_x);
42 addToPropertyMap(m_y);
43 addToPropertyMap(m_dx);
44 addToPropertyMap(m_dy);
45 addToPropertyMap(m_rotate);
48 bool SVGTextPositioningElement::isSupportedAttribute(const QualifiedName& attrName)
50 DEFINE_STATIC_LOCAL(HashSet<QualifiedName>, supportedAttributes, ());
51 if (supportedAttributes.isEmpty()) {
52 supportedAttributes.add(SVGNames::xAttr);
53 supportedAttributes.add(SVGNames::yAttr);
54 supportedAttributes.add(SVGNames::dxAttr);
55 supportedAttributes.add(SVGNames::dyAttr);
56 supportedAttributes.add(SVGNames::rotateAttr);
58 return supportedAttributes.contains<SVGAttributeHashTranslator>(attrName);
61 void SVGTextPositioningElement::parseAttribute(const QualifiedName& name, const AtomicString& value)
63 if (!isSupportedAttribute(name)) {
64 SVGTextContentElement::parseAttribute(name, value);
68 SVGParsingError parseError = NoError;
70 if (name == SVGNames::xAttr)
71 m_x->setBaseValueAsString(value, parseError);
72 else if (name == SVGNames::yAttr)
73 m_y->setBaseValueAsString(value, parseError);
74 else if (name == SVGNames::dxAttr)
75 m_dx->setBaseValueAsString(value, parseError);
76 else if (name == SVGNames::dyAttr)
77 m_dy->setBaseValueAsString(value, parseError);
78 else if (name == SVGNames::rotateAttr)
79 m_rotate->setBaseValueAsString(value, parseError);
83 reportAttributeParsingError(parseError, name, value);
86 void SVGTextPositioningElement::svgAttributeChanged(const QualifiedName& attrName)
88 if (!isSupportedAttribute(attrName)) {
89 SVGTextContentElement::svgAttributeChanged(attrName);
93 SVGElement::InvalidationGuard invalidationGuard(this);
95 bool updateRelativeLengths = attrName == SVGNames::xAttr
96 || attrName == SVGNames::yAttr
97 || attrName == SVGNames::dxAttr
98 || attrName == SVGNames::dyAttr;
100 if (updateRelativeLengths)
101 updateRelativeLengthsInformation();
103 RenderObject* renderer = this->renderer();
107 if (updateRelativeLengths || attrName == SVGNames::rotateAttr) {
108 if (RenderSVGText* textRenderer = RenderSVGText::locateRenderSVGTextAncestor(renderer))
109 textRenderer->setNeedsPositioningValuesUpdate();
110 RenderSVGResource::markForLayoutAndParentResourceInvalidation(renderer);
114 ASSERT_NOT_REACHED();
117 SVGTextPositioningElement* SVGTextPositioningElement::elementFromRenderer(RenderObject* renderer)
122 if (!renderer->isSVGText() && !renderer->isSVGInline())
125 Node* node = renderer->node();
127 ASSERT(node->isSVGElement());
129 return isSVGTextPositioningElement(*node) ? toSVGTextPositioningElement(node) : 0;