| 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 "SVGPolyElement.h" |
| 24 | |
| 25 | #include "Document.h" |
| 26 | #include "RenderSVGPath.h" |
| 27 | #include "RenderSVGResource.h" |
| 28 | #include "SVGDocumentExtensions.h" |
| 29 | #include "SVGParserUtilities.h" |
| 30 | #include <wtf/IsoMallocInlines.h> |
| 31 | |
| 32 | namespace WebCore { |
| 33 | |
| 34 | WTF_MAKE_ISO_ALLOCATED_IMPL(SVGPolyElement); |
| 35 | |
| 36 | SVGPolyElement::SVGPolyElement(const QualifiedName& tagName, Document& document) |
| 37 | : SVGGeometryElement(tagName, document) |
| 38 | , SVGExternalResourcesRequired(this) |
| 39 | { |
| 40 | static std::once_flag onceFlag; |
| 41 | std::call_once(onceFlag, [] { |
| 42 | PropertyRegistry::registerProperty<SVGNames::pointsAttr, &SVGPolyElement::m_points>(); |
| 43 | }); |
| 44 | } |
| 45 | |
| 46 | void SVGPolyElement::parseAttribute(const QualifiedName& name, const AtomicString& value) |
| 47 | { |
| 48 | if (name == SVGNames::pointsAttr) { |
| 49 | if (!m_points->baseVal()->parse(value)) |
| 50 | document().accessSVGExtensions().reportError("Problem parsing points=\"" + value + "\"" ); |
| 51 | return; |
| 52 | } |
| 53 | |
| 54 | SVGGeometryElement::parseAttribute(name, value); |
| 55 | SVGExternalResourcesRequired::parseAttribute(name, value); |
| 56 | } |
| 57 | |
| 58 | void SVGPolyElement::svgAttributeChanged(const QualifiedName& attrName) |
| 59 | { |
| 60 | if (attrName == SVGNames::pointsAttr) { |
| 61 | if (auto* renderer = downcast<RenderSVGPath>(this->renderer())) { |
| 62 | InstanceInvalidationGuard guard(*this); |
| 63 | renderer->setNeedsShapeUpdate(); |
| 64 | RenderSVGResource::markForLayoutAndParentResourceInvalidation(*renderer); |
| 65 | } |
| 66 | return; |
| 67 | } |
| 68 | |
| 69 | SVGGeometryElement::svgAttributeChanged(attrName); |
| 70 | SVGExternalResourcesRequired::svgAttributeChanged(attrName); |
| 71 | } |
| 72 | |
| 73 | size_t SVGPolyElement::approximateMemoryCost() const |
| 74 | { |
| 75 | size_t pointsCost = m_points->baseVal()->items().size() * sizeof(FloatPoint); |
| 76 | // We need to account for the memory which is allocated by the RenderSVGPath::m_path. |
| 77 | return sizeof(*this) + (renderer() ? pointsCost * 2 + sizeof(RenderSVGPath) : pointsCost); |
| 78 | } |
| 79 | |
| 80 | } |
| 81 | |