| 1 | /* |
| 2 | * Copyright (C) 2004, 2005, 2007, 2008 Nikolas Zimmermann <zimmermann@kde.org> |
| 3 | * Copyright (C) 2004, 2005, 2006, 2007, 2008 Rob Buis <buis@kde.org> |
| 4 | * Copyright (C) Research In Motion Limited 2009-2010. All rights reserved. |
| 5 | * Copyright (C) 2018 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 "SVGClipPathElement.h" |
| 25 | |
| 26 | #include "Document.h" |
| 27 | #include "RenderSVGResourceClipper.h" |
| 28 | #include "SVGNames.h" |
| 29 | #include "StyleResolver.h" |
| 30 | #include <wtf/IsoMallocInlines.h> |
| 31 | #include <wtf/NeverDestroyed.h> |
| 32 | |
| 33 | namespace WebCore { |
| 34 | |
| 35 | WTF_MAKE_ISO_ALLOCATED_IMPL(SVGClipPathElement); |
| 36 | |
| 37 | inline SVGClipPathElement::SVGClipPathElement(const QualifiedName& tagName, Document& document) |
| 38 | : SVGGraphicsElement(tagName, document) |
| 39 | , SVGExternalResourcesRequired(this) |
| 40 | { |
| 41 | ASSERT(hasTagName(SVGNames::clipPathTag)); |
| 42 | |
| 43 | static std::once_flag onceFlag; |
| 44 | std::call_once(onceFlag, [] { |
| 45 | PropertyRegistry::registerProperty<SVGNames::clipPathUnitsAttr, SVGUnitTypes::SVGUnitType, &SVGClipPathElement::m_clipPathUnits>(); |
| 46 | });} |
| 47 | |
| 48 | Ref<SVGClipPathElement> SVGClipPathElement::create(const QualifiedName& tagName, Document& document) |
| 49 | { |
| 50 | return adoptRef(*new SVGClipPathElement(tagName, document)); |
| 51 | } |
| 52 | |
| 53 | void SVGClipPathElement::parseAttribute(const QualifiedName& name, const AtomicString& value) |
| 54 | { |
| 55 | if (name == SVGNames::clipPathUnitsAttr) { |
| 56 | auto propertyValue = SVGPropertyTraits<SVGUnitTypes::SVGUnitType>::fromString(value); |
| 57 | if (propertyValue > 0) |
| 58 | m_clipPathUnits->setBaseValInternal<SVGUnitTypes::SVGUnitType>(propertyValue); |
| 59 | return; |
| 60 | } |
| 61 | |
| 62 | SVGGraphicsElement::parseAttribute(name, value); |
| 63 | SVGExternalResourcesRequired::parseAttribute(name, value); |
| 64 | } |
| 65 | |
| 66 | void SVGClipPathElement::svgAttributeChanged(const QualifiedName& attrName) |
| 67 | { |
| 68 | if (PropertyRegistry::isKnownAttribute(attrName)) { |
| 69 | InstanceInvalidationGuard guard(*this); |
| 70 | |
| 71 | if (RenderObject* object = renderer()) |
| 72 | object->setNeedsLayout(); |
| 73 | return; |
| 74 | } |
| 75 | |
| 76 | SVGGraphicsElement::svgAttributeChanged(attrName); |
| 77 | SVGExternalResourcesRequired::svgAttributeChanged(attrName); |
| 78 | } |
| 79 | |
| 80 | void SVGClipPathElement::childrenChanged(const ChildChange& change) |
| 81 | { |
| 82 | SVGGraphicsElement::childrenChanged(change); |
| 83 | |
| 84 | if (change.source == ChildChangeSource::Parser) |
| 85 | return; |
| 86 | |
| 87 | if (RenderObject* object = renderer()) |
| 88 | object->setNeedsLayout(); |
| 89 | } |
| 90 | |
| 91 | RenderPtr<RenderElement> SVGClipPathElement::createElementRenderer(RenderStyle&& style, const RenderTreePosition&) |
| 92 | { |
| 93 | return createRenderer<RenderSVGResourceClipper>(*this, WTFMove(style)); |
| 94 | } |
| 95 | |
| 96 | } |
| 97 | |