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"
26 #include "core/rendering/svg/RenderSVGResource.h"
27 #include "core/rendering/svg/RenderSVGText.h"
28 #include "core/svg/SVGElementInstance.h"
29 #include "core/svg/SVGLengthList.h"
30 #include "core/svg/SVGNumberList.h"
34 SVGTextPositioningElement::SVGTextPositioningElement(const QualifiedName& tagName, Document& document)
35 : SVGTextContentElement(tagName, document)
36 , m_x(SVGAnimatedLengthList::create(this, SVGNames::xAttr, SVGLengthList::create(LengthModeWidth)))
37 , m_y(SVGAnimatedLengthList::create(this, SVGNames::yAttr, SVGLengthList::create(LengthModeHeight)))
38 , m_dx(SVGAnimatedLengthList::create(this, SVGNames::dxAttr, SVGLengthList::create(LengthModeWidth)))
39 , m_dy(SVGAnimatedLengthList::create(this, SVGNames::dyAttr, SVGLengthList::create(LengthModeHeight)))
40 , m_rotate(SVGAnimatedNumberList::create(this, SVGNames::rotateAttr, SVGNumberList::create()))
42 ScriptWrappable::init(this);
44 addToPropertyMap(m_x);
45 addToPropertyMap(m_y);
46 addToPropertyMap(m_dx);
47 addToPropertyMap(m_dy);
48 addToPropertyMap(m_rotate);
51 bool SVGTextPositioningElement::isSupportedAttribute(const QualifiedName& attrName)
53 DEFINE_STATIC_LOCAL(HashSet<QualifiedName>, supportedAttributes, ());
54 if (supportedAttributes.isEmpty()) {
55 supportedAttributes.add(SVGNames::xAttr);
56 supportedAttributes.add(SVGNames::yAttr);
57 supportedAttributes.add(SVGNames::dxAttr);
58 supportedAttributes.add(SVGNames::dyAttr);
59 supportedAttributes.add(SVGNames::rotateAttr);
61 return supportedAttributes.contains<SVGAttributeHashTranslator>(attrName);
64 void SVGTextPositioningElement::parseAttribute(const QualifiedName& name, const AtomicString& value)
66 if (!isSupportedAttribute(name)) {
67 SVGTextContentElement::parseAttribute(name, value);
71 SVGParsingError parseError = NoError;
73 if (name == SVGNames::xAttr)
74 m_x->setBaseValueAsString(value, parseError);
75 else if (name == SVGNames::yAttr)
76 m_y->setBaseValueAsString(value, parseError);
77 else if (name == SVGNames::dxAttr)
78 m_dx->setBaseValueAsString(value, parseError);
79 else if (name == SVGNames::dyAttr)
80 m_dy->setBaseValueAsString(value, parseError);
81 else if (name == SVGNames::rotateAttr)
82 m_rotate->setBaseValueAsString(value, parseError);
86 reportAttributeParsingError(parseError, name, value);
89 void SVGTextPositioningElement::svgAttributeChanged(const QualifiedName& attrName)
91 if (!isSupportedAttribute(attrName)) {
92 SVGTextContentElement::svgAttributeChanged(attrName);
96 SVGElement::InvalidationGuard invalidationGuard(this);
98 bool updateRelativeLengths = attrName == SVGNames::xAttr
99 || attrName == SVGNames::yAttr
100 || attrName == SVGNames::dxAttr
101 || attrName == SVGNames::dyAttr;
103 if (updateRelativeLengths)
104 updateRelativeLengthsInformation();
106 RenderObject* renderer = this->renderer();
110 if (updateRelativeLengths || attrName == SVGNames::rotateAttr) {
111 if (RenderSVGText* textRenderer = RenderSVGText::locateRenderSVGTextAncestor(renderer))
112 textRenderer->setNeedsPositioningValuesUpdate();
113 RenderSVGResource::markForLayoutAndParentResourceInvalidation(renderer);
117 ASSERT_NOT_REACHED();
120 SVGTextPositioningElement* SVGTextPositioningElement::elementFromRenderer(RenderObject* renderer)
125 if (!renderer->isSVGText() && !renderer->isSVGInline())
128 Node* node = renderer->node();
130 ASSERT(node->isSVGElement());
132 return isSVGTextPositioningElement(*node) ? toSVGTextPositioningElement(node) : 0;