blob: 5bb1897230bcc6ea8742166be53fc501e02936ff [file] [log] [blame]
Torne (Richard Coles)53e740f2013-05-09 18:38:43 +01001/*
2 * Copyright (C) 2004, 2005, 2006, 2008 Nikolas Zimmermann <zimmermann@kde.org>
3 * Copyright (C) 2004, 2005, 2006, 2007 Rob Buis <buis@kde.org>
4 *
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.
9 *
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.
14 *
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.
19 */
20
21#include "config.h"
22
Torne (Richard Coles)53e740f2013-05-09 18:38:43 +010023#include "core/svg/SVGRectElement.h"
24
25#include "SVGNames.h"
Torne (Richard Coles)53e740f2013-05-09 18:38:43 +010026#include "core/rendering/svg/RenderSVGRect.h"
27#include "core/rendering/svg/RenderSVGResource.h"
28#include "core/svg/SVGElementInstance.h"
29#include "core/svg/SVGLength.h"
30
31namespace WebCore {
32
33// Animated property definitions
34DEFINE_ANIMATED_LENGTH(SVGRectElement, SVGNames::xAttr, X, x)
35DEFINE_ANIMATED_LENGTH(SVGRectElement, SVGNames::yAttr, Y, y)
36DEFINE_ANIMATED_LENGTH(SVGRectElement, SVGNames::widthAttr, Width, width)
37DEFINE_ANIMATED_LENGTH(SVGRectElement, SVGNames::heightAttr, Height, height)
38DEFINE_ANIMATED_LENGTH(SVGRectElement, SVGNames::rxAttr, Rx, rx)
39DEFINE_ANIMATED_LENGTH(SVGRectElement, SVGNames::ryAttr, Ry, ry)
40DEFINE_ANIMATED_BOOLEAN(SVGRectElement, SVGNames::externalResourcesRequiredAttr, ExternalResourcesRequired, externalResourcesRequired)
41
42BEGIN_REGISTER_ANIMATED_PROPERTIES(SVGRectElement)
43 REGISTER_LOCAL_ANIMATED_PROPERTY(x)
44 REGISTER_LOCAL_ANIMATED_PROPERTY(y)
45 REGISTER_LOCAL_ANIMATED_PROPERTY(width)
46 REGISTER_LOCAL_ANIMATED_PROPERTY(height)
47 REGISTER_LOCAL_ANIMATED_PROPERTY(rx)
48 REGISTER_LOCAL_ANIMATED_PROPERTY(ry)
49 REGISTER_LOCAL_ANIMATED_PROPERTY(externalResourcesRequired)
Ben Murdoch591b9582013-07-10 11:41:44 +010050 REGISTER_PARENT_ANIMATED_PROPERTIES(SVGGraphicsElement)
Torne (Richard Coles)53e740f2013-05-09 18:38:43 +010051END_REGISTER_ANIMATED_PROPERTIES
52
Torne (Richard Coles)51b29062013-11-28 11:56:03 +000053inline SVGRectElement::SVGRectElement(Document& document)
54 : SVGGeometryElement(SVGNames::rectTag, document)
Torne (Richard Coles)53e740f2013-05-09 18:38:43 +010055 , m_x(LengthModeWidth)
56 , m_y(LengthModeHeight)
57 , m_width(LengthModeWidth)
58 , m_height(LengthModeHeight)
59 , m_rx(LengthModeWidth)
60 , m_ry(LengthModeHeight)
61{
Torne (Richard Coles)53e740f2013-05-09 18:38:43 +010062 ScriptWrappable::init(this);
63 registerAnimatedPropertiesForSVGRectElement();
64}
65
Torne (Richard Coles)51b29062013-11-28 11:56:03 +000066PassRefPtr<SVGRectElement> SVGRectElement::create(Document& document)
Torne (Richard Coles)53e740f2013-05-09 18:38:43 +010067{
Torne (Richard Coles)51b29062013-11-28 11:56:03 +000068 return adoptRef(new SVGRectElement(document));
Torne (Richard Coles)53e740f2013-05-09 18:38:43 +010069}
70
71bool SVGRectElement::isSupportedAttribute(const QualifiedName& attrName)
72{
73 DEFINE_STATIC_LOCAL(HashSet<QualifiedName>, supportedAttributes, ());
74 if (supportedAttributes.isEmpty()) {
Torne (Richard Coles)53e740f2013-05-09 18:38:43 +010075 SVGLangSpace::addSupportedAttributes(supportedAttributes);
76 SVGExternalResourcesRequired::addSupportedAttributes(supportedAttributes);
77 supportedAttributes.add(SVGNames::xAttr);
78 supportedAttributes.add(SVGNames::yAttr);
79 supportedAttributes.add(SVGNames::widthAttr);
80 supportedAttributes.add(SVGNames::heightAttr);
81 supportedAttributes.add(SVGNames::rxAttr);
82 supportedAttributes.add(SVGNames::ryAttr);
83 }
Ben Murdoch591b9582013-07-10 11:41:44 +010084 return supportedAttributes.contains<SVGAttributeHashTranslator>(attrName);
Torne (Richard Coles)53e740f2013-05-09 18:38:43 +010085}
86
87void SVGRectElement::parseAttribute(const QualifiedName& name, const AtomicString& value)
88{
89 SVGParsingError parseError = NoError;
90
91 if (!isSupportedAttribute(name))
Torne (Richard Coles)51b29062013-11-28 11:56:03 +000092 SVGGeometryElement::parseAttribute(name, value);
Torne (Richard Coles)53e740f2013-05-09 18:38:43 +010093 else if (name == SVGNames::xAttr)
94 setXBaseValue(SVGLength::construct(LengthModeWidth, value, parseError));
95 else if (name == SVGNames::yAttr)
96 setYBaseValue(SVGLength::construct(LengthModeHeight, value, parseError));
97 else if (name == SVGNames::rxAttr)
98 setRxBaseValue(SVGLength::construct(LengthModeWidth, value, parseError, ForbidNegativeLengths));
99 else if (name == SVGNames::ryAttr)
100 setRyBaseValue(SVGLength::construct(LengthModeHeight, value, parseError, ForbidNegativeLengths));
101 else if (name == SVGNames::widthAttr)
102 setWidthBaseValue(SVGLength::construct(LengthModeWidth, value, parseError, ForbidNegativeLengths));
103 else if (name == SVGNames::heightAttr)
104 setHeightBaseValue(SVGLength::construct(LengthModeHeight, value, parseError, ForbidNegativeLengths));
Ben Murdoch591b9582013-07-10 11:41:44 +0100105 else if (SVGLangSpace::parseAttribute(name, value)
Torne (Richard Coles)53e740f2013-05-09 18:38:43 +0100106 || SVGExternalResourcesRequired::parseAttribute(name, value)) {
107 } else
108 ASSERT_NOT_REACHED();
109
110 reportAttributeParsingError(parseError, name, value);
111}
112
113void SVGRectElement::svgAttributeChanged(const QualifiedName& attrName)
114{
115 if (!isSupportedAttribute(attrName)) {
Torne (Richard Coles)51b29062013-11-28 11:56:03 +0000116 SVGGeometryElement::svgAttributeChanged(attrName);
Torne (Richard Coles)53e740f2013-05-09 18:38:43 +0100117 return;
118 }
119
120 SVGElementInstance::InvalidationGuard invalidationGuard(this);
Ben Murdoch02772c62013-07-26 10:21:05 +0100121
Torne (Richard Coles)53e740f2013-05-09 18:38:43 +0100122 bool isLengthAttribute = attrName == SVGNames::xAttr
123 || attrName == SVGNames::yAttr
124 || attrName == SVGNames::widthAttr
125 || attrName == SVGNames::heightAttr
126 || attrName == SVGNames::rxAttr
127 || attrName == SVGNames::ryAttr;
128
129 if (isLengthAttribute)
130 updateRelativeLengthsInformation();
131
Torne (Richard Coles)53e740f2013-05-09 18:38:43 +0100132 RenderSVGShape* renderer = toRenderSVGShape(this->renderer());
133 if (!renderer)
134 return;
135
136 if (isLengthAttribute) {
137 renderer->setNeedsShapeUpdate();
138 RenderSVGResource::markForLayoutAndParentResourceInvalidation(renderer);
139 return;
140 }
141
142 if (SVGLangSpace::isKnownAttribute(attrName) || SVGExternalResourcesRequired::isKnownAttribute(attrName)) {
143 RenderSVGResource::markForLayoutAndParentResourceInvalidation(renderer);
144 return;
145 }
146
147 ASSERT_NOT_REACHED();
148}
149
150bool SVGRectElement::selfHasRelativeLengths() const
151{
Ben Murdoche69819b2013-07-17 14:56:49 +0100152 return xCurrentValue().isRelative()
153 || yCurrentValue().isRelative()
154 || widthCurrentValue().isRelative()
155 || heightCurrentValue().isRelative()
156 || rxCurrentValue().isRelative()
157 || ryCurrentValue().isRelative();
Torne (Richard Coles)53e740f2013-05-09 18:38:43 +0100158}
159
Ben Murdoch591b9582013-07-10 11:41:44 +0100160RenderObject* SVGRectElement::createRenderer(RenderStyle*)
Torne (Richard Coles)53e740f2013-05-09 18:38:43 +0100161{
Torne (Richard Coles)f5e4ad52013-08-05 13:57:57 +0100162 return new RenderSVGRect(this);
Torne (Richard Coles)53e740f2013-05-09 18:38:43 +0100163}
164
165}