1/*
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 * Copyright (C) 2014 Adobe Systems Incorporated. All rights reserved.
5 * Copyright (C) 2018-2019 Apple Inc. All rights reserved.
6 *
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Library General Public
9 * License as published by the Free Software Foundation; either
10 * version 2 of the License, or (at your option) any later version.
11 *
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Library General Public License for more details.
16 *
17 * You should have received a copy of the GNU Library General Public License
18 * along with this library; see the file COPYING.LIB. If not, write to
19 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
20 * Boston, MA 02110-1301, USA.
21 */
22
23#include "config.h"
24#include "SVGRectElement.h"
25
26#include "RenderSVGRect.h"
27#include "RenderSVGResource.h"
28#include <wtf/IsoMallocInlines.h>
29
30namespace WebCore {
31
32WTF_MAKE_ISO_ALLOCATED_IMPL(SVGRectElement);
33
34inline SVGRectElement::SVGRectElement(const QualifiedName& tagName, Document& document)
35 : SVGGeometryElement(tagName, document)
36 , SVGExternalResourcesRequired(this)
37{
38 ASSERT(hasTagName(SVGNames::rectTag));
39
40 static std::once_flag onceFlag;
41 std::call_once(onceFlag, [] {
42 PropertyRegistry::registerProperty<SVGNames::xAttr, &SVGRectElement::m_x>();
43 PropertyRegistry::registerProperty<SVGNames::yAttr, &SVGRectElement::m_y>();
44 PropertyRegistry::registerProperty<SVGNames::widthAttr, &SVGRectElement::m_width>();
45 PropertyRegistry::registerProperty<SVGNames::heightAttr, &SVGRectElement::m_height>();
46 PropertyRegistry::registerProperty<SVGNames::rxAttr, &SVGRectElement::m_rx>();
47 PropertyRegistry::registerProperty<SVGNames::ryAttr, &SVGRectElement::m_ry>();
48 });
49}
50
51Ref<SVGRectElement> SVGRectElement::create(const QualifiedName& tagName, Document& document)
52{
53 return adoptRef(*new SVGRectElement(tagName, document));
54}
55
56void SVGRectElement::parseAttribute(const QualifiedName& name, const AtomicString& value)
57{
58 SVGParsingError parseError = NoError;
59
60 if (name == SVGNames::xAttr)
61 m_x->setBaseValInternal(SVGLengthValue::construct(LengthModeWidth, value, parseError));
62 else if (name == SVGNames::yAttr)
63 m_y->setBaseValInternal(SVGLengthValue::construct(LengthModeHeight, value, parseError));
64 else if (name == SVGNames::rxAttr)
65 m_rx->setBaseValInternal(SVGLengthValue::construct(LengthModeWidth, value, parseError, ForbidNegativeLengths));
66 else if (name == SVGNames::ryAttr)
67 m_ry->setBaseValInternal(SVGLengthValue::construct(LengthModeHeight, value, parseError, ForbidNegativeLengths));
68 else if (name == SVGNames::widthAttr)
69 m_width->setBaseValInternal(SVGLengthValue::construct(LengthModeWidth, value, parseError, ForbidNegativeLengths));
70 else if (name == SVGNames::heightAttr)
71 m_height->setBaseValInternal(SVGLengthValue::construct(LengthModeHeight, value, parseError, ForbidNegativeLengths));
72
73 reportAttributeParsingError(parseError, name, value);
74
75 SVGGeometryElement::parseAttribute(name, value);
76 SVGExternalResourcesRequired::parseAttribute(name, value);
77}
78
79void SVGRectElement::svgAttributeChanged(const QualifiedName& attrName)
80{
81 if (PropertyRegistry::isKnownAttribute(attrName)) {
82 InstanceInvalidationGuard guard(*this);
83 invalidateSVGPresentationAttributeStyle();
84 return;
85 }
86
87 SVGGeometryElement::svgAttributeChanged(attrName);
88 SVGExternalResourcesRequired::svgAttributeChanged(attrName);
89}
90
91RenderPtr<RenderElement> SVGRectElement::createElementRenderer(RenderStyle&& style, const RenderTreePosition&)
92{
93 return createRenderer<RenderSVGRect>(*this, WTFMove(style));
94}
95
96}
97