| 1 | /* |
| 2 | * Copyright (C) 2004, 2005, 2007 Nikolas Zimmermann <zimmermann@kde.org> |
| 3 | * Copyright (C) 2004, 2005, 2006 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 "SVGComponentTransferFunctionElement.h" |
| 24 | |
| 25 | #include "SVGFEComponentTransferElement.h" |
| 26 | #include "SVGNames.h" |
| 27 | #include <wtf/IsoMallocInlines.h> |
| 28 | #include <wtf/NeverDestroyed.h> |
| 29 | |
| 30 | namespace WebCore { |
| 31 | |
| 32 | WTF_MAKE_ISO_ALLOCATED_IMPL(SVGComponentTransferFunctionElement); |
| 33 | |
| 34 | SVGComponentTransferFunctionElement::SVGComponentTransferFunctionElement(const QualifiedName& tagName, Document& document) |
| 35 | : SVGElement(tagName, document) |
| 36 | { |
| 37 | static std::once_flag onceFlag; |
| 38 | std::call_once(onceFlag, [] { |
| 39 | PropertyRegistry::registerProperty<SVGNames::typeAttr, ComponentTransferType, &SVGComponentTransferFunctionElement::m_type>(); |
| 40 | PropertyRegistry::registerProperty<SVGNames::tableValuesAttr, &SVGComponentTransferFunctionElement::m_tableValues>(); |
| 41 | PropertyRegistry::registerProperty<SVGNames::slopeAttr, &SVGComponentTransferFunctionElement::m_slope>(); |
| 42 | PropertyRegistry::registerProperty<SVGNames::interceptAttr, &SVGComponentTransferFunctionElement::m_intercept>(); |
| 43 | PropertyRegistry::registerProperty<SVGNames::amplitudeAttr, &SVGComponentTransferFunctionElement::m_amplitude>(); |
| 44 | PropertyRegistry::registerProperty<SVGNames::exponentAttr, &SVGComponentTransferFunctionElement::m_exponent>(); |
| 45 | PropertyRegistry::registerProperty<SVGNames::offsetAttr, &SVGComponentTransferFunctionElement::m_offset>(); |
| 46 | }); |
| 47 | } |
| 48 | |
| 49 | void SVGComponentTransferFunctionElement::parseAttribute(const QualifiedName& name, const AtomicString& value) |
| 50 | { |
| 51 | if (name == SVGNames::typeAttr) { |
| 52 | ComponentTransferType propertyValue = SVGPropertyTraits<ComponentTransferType>::fromString(value); |
| 53 | if (propertyValue > 0) |
| 54 | m_type->setBaseValInternal<ComponentTransferType>(propertyValue); |
| 55 | return; |
| 56 | } |
| 57 | |
| 58 | if (name == SVGNames::tableValuesAttr) { |
| 59 | m_tableValues->baseVal()->parse(value); |
| 60 | return; |
| 61 | } |
| 62 | |
| 63 | if (name == SVGNames::slopeAttr) { |
| 64 | m_slope->setBaseValInternal(value.toFloat()); |
| 65 | return; |
| 66 | } |
| 67 | |
| 68 | if (name == SVGNames::interceptAttr) { |
| 69 | m_intercept->setBaseValInternal(value.toFloat()); |
| 70 | return; |
| 71 | } |
| 72 | |
| 73 | if (name == SVGNames::amplitudeAttr) { |
| 74 | m_amplitude->setBaseValInternal(value.toFloat()); |
| 75 | return; |
| 76 | } |
| 77 | |
| 78 | if (name == SVGNames::exponentAttr) { |
| 79 | m_exponent->setBaseValInternal(value.toFloat()); |
| 80 | return; |
| 81 | } |
| 82 | |
| 83 | if (name == SVGNames::offsetAttr) { |
| 84 | m_offset->setBaseValInternal(value.toFloat()); |
| 85 | return; |
| 86 | } |
| 87 | |
| 88 | SVGElement::parseAttribute(name, value); |
| 89 | } |
| 90 | |
| 91 | void SVGComponentTransferFunctionElement::svgAttributeChanged(const QualifiedName& attrName) |
| 92 | { |
| 93 | if (isKnownAttribute(attrName)) { |
| 94 | InstanceInvalidationGuard guard(*this); |
| 95 | invalidateFilterPrimitiveParent(this); |
| 96 | return; |
| 97 | } |
| 98 | |
| 99 | SVGElement::svgAttributeChanged(attrName); |
| 100 | } |
| 101 | |
| 102 | ComponentTransferFunction SVGComponentTransferFunctionElement::transferFunction() const |
| 103 | { |
| 104 | return { |
| 105 | type(), |
| 106 | slope(), |
| 107 | intercept(), |
| 108 | amplitude(), |
| 109 | exponent(), |
| 110 | offset(), |
| 111 | tableValues() |
| 112 | }; |
| 113 | } |
| 114 | |
| 115 | } |
| 116 | |