| 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) 2018-2019 Apple Inc. All rights reserved. |
| 5 | * |
| 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. |
| 10 | * |
| 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. |
| 15 | * |
| 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. |
| 20 | */ |
| 21 | |
| 22 | #include "config.h" |
| 23 | #include "SVGLineElement.h" |
| 24 | |
| 25 | #include "RenderSVGResource.h" |
| 26 | #include "SVGLengthValue.h" |
| 27 | #include <wtf/IsoMallocInlines.h> |
| 28 | |
| 29 | namespace WebCore { |
| 30 | |
| 31 | WTF_MAKE_ISO_ALLOCATED_IMPL(SVGLineElement); |
| 32 | |
| 33 | inline SVGLineElement::SVGLineElement(const QualifiedName& tagName, Document& document) |
| 34 | : SVGGeometryElement(tagName, document) |
| 35 | , SVGExternalResourcesRequired(this) |
| 36 | { |
| 37 | ASSERT(hasTagName(SVGNames::lineTag)); |
| 38 | |
| 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>(); |
| 45 | }); |
| 46 | } |
| 47 | |
| 48 | Ref<SVGLineElement> SVGLineElement::create(const QualifiedName& tagName, Document& document) |
| 49 | { |
| 50 | return adoptRef(*new SVGLineElement(tagName, document)); |
| 51 | } |
| 52 | |
| 53 | void SVGLineElement::parseAttribute(const QualifiedName& name, const AtomicString& value) |
| 54 | { |
| 55 | SVGParsingError parseError = NoError; |
| 56 | |
| 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)); |
| 65 | |
| 66 | reportAttributeParsingError(parseError, name, value); |
| 67 | |
| 68 | SVGGeometryElement::parseAttribute(name, value); |
| 69 | SVGExternalResourcesRequired::parseAttribute(name, value); |
| 70 | } |
| 71 | |
| 72 | void SVGLineElement::svgAttributeChanged(const QualifiedName& attrName) |
| 73 | { |
| 74 | if (PropertyRegistry::isKnownAttribute(attrName)) { |
| 75 | InstanceInvalidationGuard guard(*this); |
| 76 | updateRelativeLengthsInformation(); |
| 77 | |
| 78 | if (auto* renderer = downcast<RenderSVGShape>(this->renderer())) { |
| 79 | renderer->setNeedsShapeUpdate(); |
| 80 | RenderSVGResource::markForLayoutAndParentResourceInvalidation(*renderer); |
| 81 | } |
| 82 | return; |
| 83 | } |
| 84 | |
| 85 | SVGGeometryElement::svgAttributeChanged(attrName); |
| 86 | SVGExternalResourcesRequired::svgAttributeChanged(attrName); |
| 87 | } |
| 88 | |
| 89 | bool SVGLineElement::selfHasRelativeLengths() const |
| 90 | { |
| 91 | return x1().isRelative() |
| 92 | || y1().isRelative() |
| 93 | || x2().isRelative() |
| 94 | || y2().isRelative(); |
| 95 | } |
| 96 | |
| 97 | } |
| 98 | |