1/*
2 * Copyright (C) 2004, 2005, 2006, 2008 Nikolas Zimmermann <zimmermann@kde.org>
3 * Copyright (C) 2004, 2005, 2006, 2008 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 SVGPathSeg_h
22#define SVGPathSeg_h
23
24#include "bindings/core/v8/ScriptWrappable.h"
25#include "wtf/RefCounted.h"
26#include "wtf/text/WTFString.h"
27
28namespace blink {
29
30enum ListModification {
31    ListModificationUnknown = 0,
32    ListModificationInsert = 1,
33    ListModificationReplace = 2,
34    ListModificationRemove = 3,
35    ListModificationAppend = 4
36};
37
38enum SVGPathSegType {
39    PathSegUnknown = 0,
40    PathSegClosePath = 1,
41    PathSegMoveToAbs = 2,
42    PathSegMoveToRel = 3,
43    PathSegLineToAbs = 4,
44    PathSegLineToRel = 5,
45    PathSegCurveToCubicAbs = 6,
46    PathSegCurveToCubicRel = 7,
47    PathSegCurveToQuadraticAbs = 8,
48    PathSegCurveToQuadraticRel = 9,
49    PathSegArcAbs = 10,
50    PathSegArcRel = 11,
51    PathSegLineToHorizontalAbs = 12,
52    PathSegLineToHorizontalRel = 13,
53    PathSegLineToVerticalAbs = 14,
54    PathSegLineToVerticalRel = 15,
55    PathSegCurveToCubicSmoothAbs = 16,
56    PathSegCurveToCubicSmoothRel = 17,
57    PathSegCurveToQuadraticSmoothAbs = 18,
58    PathSegCurveToQuadraticSmoothRel = 19
59};
60
61class SVGPropertyBase;
62class SVGPathElement;
63class SVGElement;
64
65class SVGPathSeg : public RefCounted<SVGPathSeg>, public ScriptWrappable {
66    DEFINE_WRAPPERTYPEINFO();
67public:
68    // SVGPathSeg itself is used as a tear-off type.
69    // FIXME: A tear-off type should be introduced to distinguish animVal/baseVal
70    typedef SVGPathSeg TearOffType;
71
72    explicit SVGPathSeg(SVGPathElement* contextElement);
73
74    virtual ~SVGPathSeg() { }
75
76    // Forward declare these enums in the w3c naming scheme, for IDL generation
77    enum {
78        PATHSEG_UNKNOWN = PathSegUnknown,
79        PATHSEG_CLOSEPATH = PathSegClosePath,
80        PATHSEG_MOVETO_ABS = PathSegMoveToAbs,
81        PATHSEG_MOVETO_REL = PathSegMoveToRel,
82        PATHSEG_LINETO_ABS = PathSegLineToAbs,
83        PATHSEG_LINETO_REL = PathSegLineToRel,
84        PATHSEG_CURVETO_CUBIC_ABS = PathSegCurveToCubicAbs,
85        PATHSEG_CURVETO_CUBIC_REL = PathSegCurveToCubicRel,
86        PATHSEG_CURVETO_QUADRATIC_ABS = PathSegCurveToQuadraticAbs,
87        PATHSEG_CURVETO_QUADRATIC_REL = PathSegCurveToQuadraticRel,
88        PATHSEG_ARC_ABS = PathSegArcAbs,
89        PATHSEG_ARC_REL = PathSegArcRel,
90        PATHSEG_LINETO_HORIZONTAL_ABS = PathSegLineToHorizontalAbs,
91        PATHSEG_LINETO_HORIZONTAL_REL = PathSegLineToHorizontalRel,
92        PATHSEG_LINETO_VERTICAL_ABS = PathSegLineToVerticalAbs,
93        PATHSEG_LINETO_VERTICAL_REL = PathSegLineToVerticalRel,
94        PATHSEG_CURVETO_CUBIC_SMOOTH_ABS = PathSegCurveToCubicSmoothAbs,
95        PATHSEG_CURVETO_CUBIC_SMOOTH_REL = PathSegCurveToCubicSmoothRel,
96        PATHSEG_CURVETO_QUADRATIC_SMOOTH_ABS = PathSegCurveToQuadraticSmoothAbs,
97        PATHSEG_CURVETO_QUADRATIC_SMOOTH_REL = PathSegCurveToQuadraticSmoothRel
98    };
99
100    virtual unsigned short pathSegType() const = 0;
101    virtual String pathSegTypeAsLetter() const = 0;
102
103    SVGPropertyBase* ownerList() const
104    {
105        return m_ownerList;
106    }
107
108    void setOwnerList(SVGPropertyBase* ownerList)
109    {
110        // Previous owner list must be cleared before setting new owner list.
111        ASSERT((!ownerList && m_ownerList) || (ownerList && !m_ownerList));
112
113        m_ownerList = ownerList;
114    }
115
116    void setContextElement(SVGElement* contextElement)
117    {
118        m_contextElement = contextElement;
119    }
120
121    static PassRefPtr<SVGPathSeg> create() { ASSERT_NOT_REACHED(); return nullptr; }
122    PassRefPtr<SVGPathSeg> clone() { ASSERT_NOT_REACHED(); return nullptr; }
123
124protected:
125    void commitChange();
126
127private:
128    // FIXME: oilpan: These are kept as raw ptrs to break reference cycle. Should be Member in oilpan.
129    SVGPropertyBase* m_ownerList;
130    SVGElement* m_contextElement;
131};
132
133} // namespace blink
134
135#endif // SVGPathSeg_h
136