1/* 2 * Copyright (C) 2004, 2005, 2006, 2008 Nikolas Zimmermann <zimmermann@kde.org> 3 * Copyright (C) 2004, 2005, 2006, 2007 Rob Buis <buis@kde.org> 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#ifndef SVGPathElement_h 22#define SVGPathElement_h 23 24#include "SVGAnimatedBoolean.h" 25#include "SVGAnimatedNumber.h" 26#include "SVGExternalResourcesRequired.h" 27#include "SVGGraphicsElement.h" 28#include "SVGNames.h" 29#include "SVGPathByteStream.h" 30#include "SVGPathSegList.h" 31 32namespace WebCore { 33 34class SVGPathSegArcAbs; 35class SVGPathSegArcRel; 36class SVGPathSegClosePath; 37class SVGPathSegLinetoAbs; 38class SVGPathSegLinetoRel; 39class SVGPathSegMovetoAbs; 40class SVGPathSegMovetoRel; 41class SVGPathSegCurvetoCubicAbs; 42class SVGPathSegCurvetoCubicRel; 43class SVGPathSegLinetoVerticalAbs; 44class SVGPathSegLinetoVerticalRel; 45class SVGPathSegLinetoHorizontalAbs; 46class SVGPathSegLinetoHorizontalRel; 47class SVGPathSegCurvetoQuadraticAbs; 48class SVGPathSegCurvetoQuadraticRel; 49class SVGPathSegCurvetoCubicSmoothAbs; 50class SVGPathSegCurvetoCubicSmoothRel; 51class SVGPathSegCurvetoQuadraticSmoothAbs; 52class SVGPathSegCurvetoQuadraticSmoothRel; 53class SVGPathSegListPropertyTearOff; 54 55class SVGPathElement final : public SVGGraphicsElement, 56 public SVGExternalResourcesRequired { 57public: 58 static PassRefPtr<SVGPathElement> create(const QualifiedName&, Document&); 59 60 float getTotalLength(); 61 SVGPoint getPointAtLength(float distance); 62 unsigned getPathSegAtLength(float distance); 63 64 PassRefPtr<SVGPathSegClosePath> createSVGPathSegClosePath(SVGPathSegRole role = PathSegUndefinedRole); 65 PassRefPtr<SVGPathSegMovetoAbs> createSVGPathSegMovetoAbs(float x, float y, SVGPathSegRole role = PathSegUndefinedRole); 66 PassRefPtr<SVGPathSegMovetoRel> createSVGPathSegMovetoRel(float x, float y, SVGPathSegRole role = PathSegUndefinedRole); 67 PassRefPtr<SVGPathSegLinetoAbs> createSVGPathSegLinetoAbs(float x, float y, SVGPathSegRole role = PathSegUndefinedRole); 68 PassRefPtr<SVGPathSegLinetoRel> createSVGPathSegLinetoRel(float x, float y, SVGPathSegRole role = PathSegUndefinedRole); 69 PassRefPtr<SVGPathSegCurvetoCubicAbs> createSVGPathSegCurvetoCubicAbs(float x, float y, float x1, float y1, float x2, float y2, SVGPathSegRole role = PathSegUndefinedRole); 70 PassRefPtr<SVGPathSegCurvetoCubicRel> createSVGPathSegCurvetoCubicRel(float x, float y, float x1, float y1, float x2, float y2, SVGPathSegRole role = PathSegUndefinedRole); 71 PassRefPtr<SVGPathSegCurvetoQuadraticAbs> createSVGPathSegCurvetoQuadraticAbs(float x, float y, float x1, float y1, SVGPathSegRole role = PathSegUndefinedRole); 72 PassRefPtr<SVGPathSegCurvetoQuadraticRel> createSVGPathSegCurvetoQuadraticRel(float x, float y, float x1, float y1, SVGPathSegRole role = PathSegUndefinedRole); 73 PassRefPtr<SVGPathSegArcAbs> createSVGPathSegArcAbs(float x, float y, float r1, float r2, float angle, bool largeArcFlag, bool sweepFlag, SVGPathSegRole role = PathSegUndefinedRole); 74 PassRefPtr<SVGPathSegArcRel> createSVGPathSegArcRel(float x, float y, float r1, float r2, float angle, bool largeArcFlag, bool sweepFlag, SVGPathSegRole role = PathSegUndefinedRole); 75 PassRefPtr<SVGPathSegLinetoHorizontalAbs> createSVGPathSegLinetoHorizontalAbs(float x, SVGPathSegRole role = PathSegUndefinedRole); 76 PassRefPtr<SVGPathSegLinetoHorizontalRel> createSVGPathSegLinetoHorizontalRel(float x, SVGPathSegRole role = PathSegUndefinedRole); 77 PassRefPtr<SVGPathSegLinetoVerticalAbs> createSVGPathSegLinetoVerticalAbs(float y, SVGPathSegRole role = PathSegUndefinedRole); 78 PassRefPtr<SVGPathSegLinetoVerticalRel> createSVGPathSegLinetoVerticalRel(float y, SVGPathSegRole role = PathSegUndefinedRole); 79 PassRefPtr<SVGPathSegCurvetoCubicSmoothAbs> createSVGPathSegCurvetoCubicSmoothAbs(float x, float y, float x2, float y2, SVGPathSegRole role = PathSegUndefinedRole); 80 PassRefPtr<SVGPathSegCurvetoCubicSmoothRel> createSVGPathSegCurvetoCubicSmoothRel(float x, float y, float x2, float y2, SVGPathSegRole role = PathSegUndefinedRole); 81 PassRefPtr<SVGPathSegCurvetoQuadraticSmoothAbs> createSVGPathSegCurvetoQuadraticSmoothAbs(float x, float y, SVGPathSegRole role = PathSegUndefinedRole); 82 PassRefPtr<SVGPathSegCurvetoQuadraticSmoothRel> createSVGPathSegCurvetoQuadraticSmoothRel(float x, float y, SVGPathSegRole role = PathSegUndefinedRole); 83 84 // Used in the bindings only. 85 SVGPathSegListPropertyTearOff* pathSegList(); 86 SVGPathSegListPropertyTearOff* animatedPathSegList(); 87 SVGPathSegListPropertyTearOff* normalizedPathSegList(); 88 SVGPathSegListPropertyTearOff* animatedNormalizedPathSegList(); 89 90 SVGPathByteStream* pathByteStream() const; 91 92 void pathSegListChanged(SVGPathSegRole, ListModification = ListModificationUnknown); 93 94 virtual FloatRect getBBox(StyleUpdateStrategy = AllowStyleUpdate) override; 95 96 static const SVGPropertyInfo* dPropertyInfo(); 97 98 bool isAnimValObserved() const { return m_isAnimValObserved; } 99 100private: 101 SVGPathElement(const QualifiedName&, Document&); 102 103 virtual bool isValid() const override { return SVGTests::isValid(); } 104 105 bool isSupportedAttribute(const QualifiedName&); 106 virtual void parseAttribute(const QualifiedName&, const AtomicString&) override; 107 virtual void svgAttributeChanged(const QualifiedName&) override; 108 virtual bool supportsMarkers() const override { return true; } 109 110 // Custom 'd' property 111 static void synchronizeD(SVGElement* contextElement); 112 static PassRefPtr<SVGAnimatedProperty> lookupOrCreateDWrapper(SVGElement* contextElement); 113 114 BEGIN_DECLARE_ANIMATED_PROPERTIES(SVGPathElement) 115 DECLARE_ANIMATED_NUMBER(PathLength, pathLength) 116 DECLARE_ANIMATED_BOOLEAN(ExternalResourcesRequired, externalResourcesRequired) 117 END_DECLARE_ANIMATED_PROPERTIES 118 119 virtual RenderPtr<RenderElement> createElementRenderer(PassRef<RenderStyle>) override; 120 121 virtual Node::InsertionNotificationRequest insertedInto(ContainerNode&) override; 122 virtual void removedFrom(ContainerNode&) override; 123 124 void invalidateMPathDependencies(); 125 126private: 127 std::unique_ptr<SVGPathByteStream> m_pathByteStream; 128 mutable SVGSynchronizableAnimatedProperty<SVGPathSegList> m_pathSegList; 129 bool m_isAnimValObserved; 130}; 131 132NODE_TYPE_CASTS(SVGPathElement) 133 134} // namespace WebCore 135 136#endif 137