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#if ENABLE(SVG)
25#include "SVGAnimatedBoolean.h"
26#include "SVGAnimatedNumber.h"
27#include "SVGAnimatedPathSegListPropertyTearOff.h"
28#include "SVGExternalResourcesRequired.h"
29#include "SVGLangSpace.h"
30#include "SVGPathByteStream.h"
31#include "SVGStyledTransformableElement.h"
32#include "SVGTests.h"
33
34namespace WebCore {
35
36class SVGPathSegArcAbs;
37class SVGPathSegArcRel;
38class SVGPathSegClosePath;
39class SVGPathSegLinetoAbs;
40class SVGPathSegLinetoRel;
41class SVGPathSegMovetoAbs;
42class SVGPathSegMovetoRel;
43class SVGPathSegCurvetoCubicAbs;
44class SVGPathSegCurvetoCubicRel;
45class SVGPathSegLinetoVerticalAbs;
46class SVGPathSegLinetoVerticalRel;
47class SVGPathSegLinetoHorizontalAbs;
48class SVGPathSegLinetoHorizontalRel;
49class SVGPathSegCurvetoQuadraticAbs;
50class SVGPathSegCurvetoQuadraticRel;
51class SVGPathSegCurvetoCubicSmoothAbs;
52class SVGPathSegCurvetoCubicSmoothRel;
53class SVGPathSegCurvetoQuadraticSmoothAbs;
54class SVGPathSegCurvetoQuadraticSmoothRel;
55
56class SVGPathElement : public SVGStyledTransformableElement,
57                       public SVGTests,
58                       public SVGLangSpace,
59                       public SVGExternalResourcesRequired {
60public:
61    static PassRefPtr<SVGPathElement> create(const QualifiedName&, Document*);
62
63    float getTotalLength();
64    FloatPoint getPointAtLength(float distance);
65    unsigned long getPathSegAtLength(float distance);
66
67    PassRefPtr<SVGPathSegClosePath> createSVGPathSegClosePath(SVGPathSegRole role = PathSegUndefinedRole);
68    PassRefPtr<SVGPathSegMovetoAbs> createSVGPathSegMovetoAbs(float x, float y, SVGPathSegRole role = PathSegUndefinedRole);
69    PassRefPtr<SVGPathSegMovetoRel> createSVGPathSegMovetoRel(float x, float y, SVGPathSegRole role = PathSegUndefinedRole);
70    PassRefPtr<SVGPathSegLinetoAbs> createSVGPathSegLinetoAbs(float x, float y, SVGPathSegRole role = PathSegUndefinedRole);
71    PassRefPtr<SVGPathSegLinetoRel> createSVGPathSegLinetoRel(float x, float y, SVGPathSegRole role = PathSegUndefinedRole);
72    PassRefPtr<SVGPathSegCurvetoCubicAbs> createSVGPathSegCurvetoCubicAbs(float x, float y, float x1, float y1, float x2, float y2, SVGPathSegRole role = PathSegUndefinedRole);
73    PassRefPtr<SVGPathSegCurvetoCubicRel> createSVGPathSegCurvetoCubicRel(float x, float y, float x1, float y1, float x2, float y2, SVGPathSegRole role = PathSegUndefinedRole);
74    PassRefPtr<SVGPathSegCurvetoQuadraticAbs> createSVGPathSegCurvetoQuadraticAbs(float x, float y, float x1, float y1, SVGPathSegRole role = PathSegUndefinedRole);
75    PassRefPtr<SVGPathSegCurvetoQuadraticRel> createSVGPathSegCurvetoQuadraticRel(float x, float y, float x1, float y1, SVGPathSegRole role = PathSegUndefinedRole);
76    PassRefPtr<SVGPathSegArcAbs> createSVGPathSegArcAbs(float x, float y, float r1, float r2, float angle, bool largeArcFlag, bool sweepFlag, SVGPathSegRole role = PathSegUndefinedRole);
77    PassRefPtr<SVGPathSegArcRel> createSVGPathSegArcRel(float x, float y, float r1, float r2, float angle, bool largeArcFlag, bool sweepFlag, SVGPathSegRole role = PathSegUndefinedRole);
78    PassRefPtr<SVGPathSegLinetoHorizontalAbs> createSVGPathSegLinetoHorizontalAbs(float x, SVGPathSegRole role = PathSegUndefinedRole);
79    PassRefPtr<SVGPathSegLinetoHorizontalRel> createSVGPathSegLinetoHorizontalRel(float x, SVGPathSegRole role = PathSegUndefinedRole);
80    PassRefPtr<SVGPathSegLinetoVerticalAbs> createSVGPathSegLinetoVerticalAbs(float y, SVGPathSegRole role = PathSegUndefinedRole);
81    PassRefPtr<SVGPathSegLinetoVerticalRel> createSVGPathSegLinetoVerticalRel(float y, SVGPathSegRole role = PathSegUndefinedRole);
82    PassRefPtr<SVGPathSegCurvetoCubicSmoothAbs> createSVGPathSegCurvetoCubicSmoothAbs(float x, float y, float x2, float y2, SVGPathSegRole role = PathSegUndefinedRole);
83    PassRefPtr<SVGPathSegCurvetoCubicSmoothRel> createSVGPathSegCurvetoCubicSmoothRel(float x, float y, float x2, float y2, SVGPathSegRole role = PathSegUndefinedRole);
84    PassRefPtr<SVGPathSegCurvetoQuadraticSmoothAbs> createSVGPathSegCurvetoQuadraticSmoothAbs(float x, float y, SVGPathSegRole role = PathSegUndefinedRole);
85    PassRefPtr<SVGPathSegCurvetoQuadraticSmoothRel> createSVGPathSegCurvetoQuadraticSmoothRel(float x, float y, SVGPathSegRole role = PathSegUndefinedRole);
86
87    // Used in the bindings only.
88    SVGPathSegListPropertyTearOff* pathSegList();
89    SVGPathSegListPropertyTearOff* animatedPathSegList();
90    SVGPathSegListPropertyTearOff* normalizedPathSegList();
91    SVGPathSegListPropertyTearOff* animatedNormalizedPathSegList();
92
93    SVGPathByteStream* pathByteStream() const { return m_pathByteStream.get(); }
94    SVGAnimatedProperty* animatablePathSegList() const { return m_animatablePathSegList.get(); }
95
96    virtual void toPathData(Path&) const;
97    void pathSegListChanged(SVGPathSegRole);
98
99private:
100    SVGPathElement(const QualifiedName&, Document*);
101
102    virtual bool isValid() const { return SVGTests::isValid(); }
103
104    virtual void parseMappedAttribute(Attribute*);
105    virtual void synchronizeProperty(const QualifiedName&);
106    virtual void svgAttributeChanged(const QualifiedName&);
107    virtual void fillAttributeToPropertyTypeMap();
108    virtual AttributeToPropertyTypeMap& attributeToPropertyTypeMap();
109    virtual bool supportsMarkers() const { return true; }
110
111    // Animated property declarations
112    DECLARE_ANIMATED_NUMBER(PathLength, pathLength)
113
114    // SVGExternalResourcesRequired
115    DECLARE_ANIMATED_BOOLEAN(ExternalResourcesRequired, externalResourcesRequired)
116
117    void synchronizeD();
118
119protected:
120    OwnPtr<SVGPathByteStream> m_pathByteStream;
121    mutable SVGSynchronizableAnimatedProperty<SVGPathSegList> m_pathSegList;
122    RefPtr<SVGAnimatedPathSegListPropertyTearOff> m_animatablePathSegList;
123};
124
125} // namespace WebCore
126
127#endif // ENABLE(SVG)
128#endif
129