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) 2018-2019 Apple Inc. All rights reserved.
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Library General Public
8 * License as published by the Free Software Foundation; either
9 * version 2 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Library General Public License for more details.
16 * You should have received a copy of the GNU Library General Public License
17 * along with this library; see the file COPYING.LIB. If not, write to
18 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
19 * Boston, MA 02110-1301, USA.
23 #include "SVGLineElement.h"
25 #include "RenderSVGResource.h"
26 #include "SVGLengthValue.h"
27 #include <wtf/IsoMallocInlines.h>
31 WTF_MAKE_ISO_ALLOCATED_IMPL(SVGLineElement);
33 inline SVGLineElement::SVGLineElement(const QualifiedName& tagName, Document& document)
34 : SVGGeometryElement(tagName, document)
35 , SVGExternalResourcesRequired(this)
37 ASSERT(hasTagName(SVGNames::lineTag));
39 static std::once_flag onceFlag;
40 std::call_once(onceFlag, [] {
41 PropertyRegistry::registerProperty<SVGNames::x1Attr, &SVGLineElement::m_x1>();
42 PropertyRegistry::registerProperty<SVGNames::y1Attr, &SVGLineElement::m_y1>();
43 PropertyRegistry::registerProperty<SVGNames::x2Attr, &SVGLineElement::m_x2>();
44 PropertyRegistry::registerProperty<SVGNames::y2Attr, &SVGLineElement::m_y2>();
48 Ref<SVGLineElement> SVGLineElement::create(const QualifiedName& tagName, Document& document)
50 return adoptRef(*new SVGLineElement(tagName, document));
53 void SVGLineElement::parseAttribute(const QualifiedName& name, const AtomString& value)
55 SVGParsingError parseError = NoError;
57 if (name == SVGNames::x1Attr)
58 m_x1->setBaseValInternal(SVGLengthValue::construct(LengthModeWidth, value, parseError));
59 else if (name == SVGNames::y1Attr)
60 m_y1->setBaseValInternal(SVGLengthValue::construct(LengthModeHeight, value, parseError));
61 else if (name == SVGNames::x2Attr)
62 m_x2->setBaseValInternal(SVGLengthValue::construct(LengthModeWidth, value, parseError));
63 else if (name == SVGNames::y2Attr)
64 m_y2->setBaseValInternal(SVGLengthValue::construct(LengthModeHeight, value, parseError));
66 reportAttributeParsingError(parseError, name, value);
68 SVGGeometryElement::parseAttribute(name, value);
69 SVGExternalResourcesRequired::parseAttribute(name, value);
72 void SVGLineElement::svgAttributeChanged(const QualifiedName& attrName)
74 if (PropertyRegistry::isKnownAttribute(attrName)) {
75 InstanceInvalidationGuard guard(*this);
76 updateRelativeLengthsInformation();
78 if (auto* renderer = downcast<RenderSVGShape>(this->renderer())) {
79 renderer->setNeedsShapeUpdate();
80 RenderSVGResource::markForLayoutAndParentResourceInvalidation(*renderer);
85 SVGGeometryElement::svgAttributeChanged(attrName);
86 SVGExternalResourcesRequired::svgAttributeChanged(attrName);
89 bool SVGLineElement::selfHasRelativeLengths() const
91 return x1().isRelative()