| 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 | #pragma once |
| 23 | |
| 24 | #include "FEColorMatrix.h" |
| 25 | #include "SVGFilterPrimitiveStandardAttributes.h" |
| 26 | |
| 27 | namespace WebCore { |
| 28 | |
| 29 | template<> |
| 30 | struct SVGPropertyTraits<ColorMatrixType> { |
| 31 | static unsigned highestEnumValue() { return FECOLORMATRIX_TYPE_LUMINANCETOALPHA; } |
| 32 | |
| 33 | static String toString(ColorMatrixType type) |
| 34 | { |
| 35 | switch (type) { |
| 36 | case FECOLORMATRIX_TYPE_UNKNOWN: |
| 37 | return emptyString(); |
| 38 | case FECOLORMATRIX_TYPE_MATRIX: |
| 39 | return "matrix"_s ; |
| 40 | case FECOLORMATRIX_TYPE_SATURATE: |
| 41 | return "saturate"_s ; |
| 42 | case FECOLORMATRIX_TYPE_HUEROTATE: |
| 43 | return "hueRotate"_s ; |
| 44 | case FECOLORMATRIX_TYPE_LUMINANCETOALPHA: |
| 45 | return "luminanceToAlpha"_s ; |
| 46 | } |
| 47 | |
| 48 | ASSERT_NOT_REACHED(); |
| 49 | return emptyString(); |
| 50 | } |
| 51 | |
| 52 | static ColorMatrixType fromString(const String& value) |
| 53 | { |
| 54 | if (value == "matrix" ) |
| 55 | return FECOLORMATRIX_TYPE_MATRIX; |
| 56 | if (value == "saturate" ) |
| 57 | return FECOLORMATRIX_TYPE_SATURATE; |
| 58 | if (value == "hueRotate" ) |
| 59 | return FECOLORMATRIX_TYPE_HUEROTATE; |
| 60 | if (value == "luminanceToAlpha" ) |
| 61 | return FECOLORMATRIX_TYPE_LUMINANCETOALPHA; |
| 62 | return FECOLORMATRIX_TYPE_UNKNOWN; |
| 63 | } |
| 64 | }; |
| 65 | |
| 66 | class SVGFEColorMatrixElement final : public SVGFilterPrimitiveStandardAttributes { |
| 67 | WTF_MAKE_ISO_ALLOCATED(SVGFEColorMatrixElement); |
| 68 | public: |
| 69 | static Ref<SVGFEColorMatrixElement> create(const QualifiedName&, Document&); |
| 70 | |
| 71 | String in1() const { return m_in1->currentValue(); } |
| 72 | ColorMatrixType type() const { return m_type->currentValue<ColorMatrixType>(); } |
| 73 | const SVGNumberList& values() const { return m_values->currentValue(); } |
| 74 | |
| 75 | SVGAnimatedString& in1Animated() { return m_in1; } |
| 76 | SVGAnimatedEnumeration& typeAnimated() { return m_type; } |
| 77 | SVGAnimatedNumberList& valuesAnimated() { return m_values; } |
| 78 | |
| 79 | private: |
| 80 | SVGFEColorMatrixElement(const QualifiedName&, Document&); |
| 81 | |
| 82 | using PropertyRegistry = SVGPropertyOwnerRegistry<SVGFEColorMatrixElement, SVGFilterPrimitiveStandardAttributes>; |
| 83 | const SVGPropertyRegistry& propertyRegistry() const final { return m_propertyRegistry; } |
| 84 | |
| 85 | void parseAttribute(const QualifiedName&, const AtomicString&) override; |
| 86 | void svgAttributeChanged(const QualifiedName&) override; |
| 87 | |
| 88 | bool setFilterEffectAttribute(FilterEffect*, const QualifiedName&) override; |
| 89 | RefPtr<FilterEffect> build(SVGFilterBuilder*, Filter&) const override; |
| 90 | |
| 91 | PropertyRegistry m_propertyRegistry { *this }; |
| 92 | Ref<SVGAnimatedString> m_in1 { SVGAnimatedString::create(this) }; |
| 93 | Ref<SVGAnimatedEnumeration> m_type { SVGAnimatedEnumeration::create(this, FECOLORMATRIX_TYPE_MATRIX) }; |
| 94 | Ref<SVGAnimatedNumberList> m_values { SVGAnimatedNumberList::create(this) }; |
| 95 | }; |
| 96 | |
| 97 | } // namespace WebCore |
| 98 | |