1/*
2 * Copyright (C) 2005 Alexander Kellett <lypanov@kde.org>
3 * Copyright (C) 2018-2019 Apple Inc. All rights reserved.
4 *
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Library General Public
7 * License as published by the Free Software Foundation; either
8 * version 2 of the License, or (at your option) any later version.
9 *
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Library General Public License for more details.
14 *
15 * You should have received a copy of the GNU Library General Public License
16 * along with this library; see the file COPYING.LIB. If not, write to
17 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18 * Boston, MA 02110-1301, USA.
19 */
20
21#pragma once
22
23#include "SVGElement.h"
24#include "SVGExternalResourcesRequired.h"
25#include "SVGNames.h"
26#include "SVGTests.h"
27#include "SVGUnitTypes.h"
28
29namespace WebCore {
30
31class SVGMaskElement final : public SVGElement, public SVGExternalResourcesRequired, public SVGTests {
32 WTF_MAKE_ISO_ALLOCATED(SVGMaskElement);
33public:
34 static Ref<SVGMaskElement> create(const QualifiedName&, Document&);
35
36 const SVGLengthValue& x() const { return m_x->currentValue(); }
37 const SVGLengthValue& y() const { return m_y->currentValue(); }
38 const SVGLengthValue& width() const { return m_width->currentValue(); }
39 const SVGLengthValue& height() const { return m_height->currentValue(); }
40 SVGUnitTypes::SVGUnitType maskUnits() const { return m_maskUnits->currentValue<SVGUnitTypes::SVGUnitType>(); }
41 SVGUnitTypes::SVGUnitType maskContentUnits() const { return m_maskContentUnits->currentValue<SVGUnitTypes::SVGUnitType>(); }
42
43 SVGAnimatedLength& xAnimated() { return m_x; }
44 SVGAnimatedLength& yAnimated() { return m_y; }
45 SVGAnimatedLength& widthAnimated() { return m_width; }
46 SVGAnimatedLength& heightAnimated() { return m_height; }
47 SVGAnimatedEnumeration& maskUnitsAnimated() { return m_maskUnits; }
48 SVGAnimatedEnumeration& maskContentUnitsAnimated() { return m_maskContentUnits; }
49
50private:
51 SVGMaskElement(const QualifiedName&, Document&);
52
53 using PropertyRegistry = SVGPropertyOwnerRegistry<SVGMaskElement, SVGElement, SVGExternalResourcesRequired, SVGTests>;
54 const SVGPropertyRegistry& propertyRegistry() const final { return m_propertyRegistry; }
55
56 void parseAttribute(const QualifiedName&, const AtomicString&) final;
57 void svgAttributeChanged(const QualifiedName&) final;
58 void childrenChanged(const ChildChange&) final;
59
60 RenderPtr<RenderElement> createElementRenderer(RenderStyle&&, const RenderTreePosition&) final;
61
62 bool isValid() const final { return SVGTests::isValid(); }
63 bool needsPendingResourceHandling() const final { return false; }
64 bool selfHasRelativeLengths() const final { return true; }
65
66 PropertyRegistry m_propertyRegistry { *this };
67 Ref<SVGAnimatedLength> m_x { SVGAnimatedLength::create(this, LengthModeWidth, "-10%") };
68 Ref<SVGAnimatedLength> m_y { SVGAnimatedLength::create(this, LengthModeHeight, "-10%") };
69 Ref<SVGAnimatedLength> m_width { SVGAnimatedLength::create(this, LengthModeWidth, "120%") };
70 Ref<SVGAnimatedLength> m_height { SVGAnimatedLength::create(this, LengthModeHeight, "120%") };
71 Ref<SVGAnimatedEnumeration> m_maskUnits { SVGAnimatedEnumeration::create(this, SVGUnitTypes::SVG_UNIT_TYPE_OBJECTBOUNDINGBOX) };
72 Ref<SVGAnimatedEnumeration> m_maskContentUnits { SVGAnimatedEnumeration::create(this, SVGUnitTypes::SVG_UNIT_TYPE_USERSPACEONUSE) };
73};
74
75} // namespace WebCore
76