1/*
2 * Copyright (C) 2004, 2005, 2006, 2007, 2008 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 "SVGElement.h"
25#include "SVGExternalResourcesRequired.h"
26#include "SVGFitToViewBox.h"
27#include "SVGMarkerTypes.h"
28
29namespace WebCore {
30
31class SVGMarkerElement final : public SVGElement, public SVGExternalResourcesRequired, public SVGFitToViewBox {
32 WTF_MAKE_ISO_ALLOCATED(SVGMarkerElement);
33public:
34 // Forward declare enumerations in the W3C naming scheme, for IDL generation.
35 enum {
36 SVG_MARKERUNITS_UNKNOWN = SVGMarkerUnitsUnknown,
37 SVG_MARKERUNITS_USERSPACEONUSE = SVGMarkerUnitsUserSpaceOnUse,
38 SVG_MARKERUNITS_STROKEWIDTH = SVGMarkerUnitsStrokeWidth
39 };
40
41 enum {
42 SVG_MARKER_ORIENT_UNKNOWN = SVGMarkerOrientUnknown,
43 SVG_MARKER_ORIENT_AUTO = SVGMarkerOrientAuto,
44 SVG_MARKER_ORIENT_ANGLE = SVGMarkerOrientAngle,
45 SVG_MARKER_ORIENT_AUTOSTARTREVERSE = SVGMarkerOrientAutoStartReverse
46 };
47
48 static Ref<SVGMarkerElement> create(const QualifiedName&, Document&);
49
50 AffineTransform viewBoxToViewTransform(float viewWidth, float viewHeight) const;
51
52 void setOrientToAuto();
53 void setOrientToAngle(SVGAngle&);
54
55 const SVGLengthValue& refX() const { return m_refX->currentValue(); }
56 const SVGLengthValue& refY() const { return m_refY->currentValue(); }
57 const SVGLengthValue& markerWidth() const { return m_markerWidth->currentValue(); }
58 const SVGLengthValue& markerHeight() const { return m_markerHeight->currentValue(); }
59 SVGMarkerUnitsType markerUnits() const { return m_markerUnits->currentValue<SVGMarkerUnitsType>(); }
60 const SVGAngleValue& orientAngle() const { return m_orientAngle->currentValue(); }
61 SVGMarkerOrientType orientType() const { return m_orientType->currentValue<SVGMarkerOrientType>(); }
62
63 SVGAnimatedLength& refXAnimated() { return m_refX; }
64 SVGAnimatedLength& refYAnimated() { return m_refY; }
65 SVGAnimatedLength& markerWidthAnimated() { return m_markerWidth; }
66 SVGAnimatedLength& markerHeightAnimated() { return m_markerHeight; }
67 SVGAnimatedEnumeration& markerUnitsAnimated() { return m_markerUnits; }
68 SVGAnimatedAngle& orientAngleAnimated() { return m_orientAngle; }
69 Ref<SVGAnimatedEnumeration> orientTypeAnimated() { return m_orientType.copyRef(); }
70
71private:
72 SVGMarkerElement(const QualifiedName&, Document&);
73
74 using PropertyRegistry = SVGPropertyOwnerRegistry<SVGMarkerElement, SVGElement, SVGExternalResourcesRequired, SVGFitToViewBox>;
75 const SVGPropertyRegistry& propertyRegistry() const final { return m_propertyRegistry; }
76
77 void parseAttribute(const QualifiedName&, const AtomicString&) override;
78 void svgAttributeChanged(const QualifiedName&) override;
79 void childrenChanged(const ChildChange&) override;
80
81 RenderPtr<RenderElement> createElementRenderer(RenderStyle&&, const RenderTreePosition&) override;
82 bool rendererIsNeeded(const RenderStyle&) override { return true; }
83
84 bool needsPendingResourceHandling() const override { return false; }
85
86 bool selfHasRelativeLengths() const override;
87
88 void setOrient(SVGMarkerOrientType, const SVGAngleValue&);
89
90 PropertyRegistry m_propertyRegistry { *this };
91 Ref<SVGAnimatedLength> m_refX { SVGAnimatedLength::create(this, LengthModeWidth) };
92 Ref<SVGAnimatedLength> m_refY { SVGAnimatedLength::create(this, LengthModeHeight) };
93 Ref<SVGAnimatedLength> m_markerWidth { SVGAnimatedLength::create(this, LengthModeWidth, "3") };
94 Ref<SVGAnimatedLength> m_markerHeight { SVGAnimatedLength::create(this, LengthModeHeight, "3") };
95 Ref<SVGAnimatedEnumeration> m_markerUnits { SVGAnimatedEnumeration::create(this, SVGMarkerUnitsStrokeWidth) };
96 Ref<SVGAnimatedAngle> m_orientAngle { SVGAnimatedAngle::create(this) };
97 Ref<SVGAnimatedOrientType> m_orientType { SVGAnimatedOrientType::create(this, SVGMarkerOrientAngle) };
98};
99
100} // namespace WebCore
101