1/*
2 * Copyright (C) 2006 Nikolas Zimmermann <zimmermann@kde.org>
3 *
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Library General Public
6 * License as published by the Free Software Foundation; either
7 * version 2 of the License, or (at your option) any later version.
8 *
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12 * Library General Public License for more details.
13 *
14 * You should have received a copy of the GNU Library General Public License
15 * along with this library; see the file COPYING.LIB.  If not, write to
16 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17 * Boston, MA 02110-1301, USA.
18 */
19
20#include "config.h"
21
22#if ENABLE(SVG)
23#include "JSSVGPathSeg.h"
24
25#include "JSDOMBinding.h"
26#include "JSSVGPathSegArcAbs.h"
27#include "JSSVGPathSegArcRel.h"
28#include "JSSVGPathSegClosePath.h"
29#include "JSSVGPathSegCurvetoCubicAbs.h"
30#include "JSSVGPathSegCurvetoCubicRel.h"
31#include "JSSVGPathSegCurvetoCubicSmoothAbs.h"
32#include "JSSVGPathSegCurvetoCubicSmoothRel.h"
33#include "JSSVGPathSegCurvetoQuadraticAbs.h"
34#include "JSSVGPathSegCurvetoQuadraticRel.h"
35#include "JSSVGPathSegCurvetoQuadraticSmoothAbs.h"
36#include "JSSVGPathSegCurvetoQuadraticSmoothRel.h"
37#include "JSSVGPathSegLinetoAbs.h"
38#include "JSSVGPathSegLinetoRel.h"
39#include "JSSVGPathSegLinetoHorizontalAbs.h"
40#include "JSSVGPathSegLinetoHorizontalRel.h"
41#include "JSSVGPathSegLinetoVerticalAbs.h"
42#include "JSSVGPathSegLinetoVerticalRel.h"
43#include "JSSVGPathSegMovetoAbs.h"
44#include "JSSVGPathSegMovetoRel.h"
45#include "SVGPathSeg.h"
46#include "SVGPathSegArc.h"
47#include "SVGPathSegClosePath.h"
48#include "SVGPathSegCurvetoCubic.h"
49#include "SVGPathSegCurvetoCubicSmooth.h"
50#include "SVGPathSegCurvetoQuadratic.h"
51#include "SVGPathSegCurvetoQuadraticSmooth.h"
52#include "SVGPathSegLineto.h"
53#include "SVGPathSegLinetoHorizontal.h"
54#include "SVGPathSegLinetoVertical.h"
55#include "SVGPathSegMoveto.h"
56
57using namespace JSC;
58
59namespace WebCore {
60
61JSValue toJS(ExecState* exec, JSDOMGlobalObject* globalObject, SVGPathSeg* object, SVGElement* context)
62{
63    if (!object)
64        return jsNull();
65
66    if (DOMObject* wrapper = getCachedDOMObjectWrapper(exec, object)) {
67        ASSERT(JSSVGContextCache::svgContextForDOMObject(wrapper) == context);
68        return wrapper;
69    }
70
71    switch (object->pathSegType()) {
72    case SVGPathSeg::PATHSEG_CLOSEPATH:
73        return CREATE_SVG_OBJECT_WRAPPER(exec, globalObject, SVGPathSegClosePath, object, context);
74    case SVGPathSeg::PATHSEG_MOVETO_ABS:
75        return CREATE_SVG_OBJECT_WRAPPER(exec, globalObject, SVGPathSegMovetoAbs, object, context);
76    case SVGPathSeg::PATHSEG_MOVETO_REL:
77        return CREATE_SVG_OBJECT_WRAPPER(exec, globalObject, SVGPathSegMovetoRel, object, context);
78    case SVGPathSeg::PATHSEG_LINETO_ABS:
79        return CREATE_SVG_OBJECT_WRAPPER(exec, globalObject, SVGPathSegLinetoAbs, object, context);
80    case SVGPathSeg::PATHSEG_LINETO_REL:
81        return CREATE_SVG_OBJECT_WRAPPER(exec, globalObject, SVGPathSegLinetoRel, object, context);
82    case SVGPathSeg::PATHSEG_CURVETO_CUBIC_ABS:
83        return CREATE_SVG_OBJECT_WRAPPER(exec, globalObject, SVGPathSegCurvetoCubicAbs, object, context);
84    case SVGPathSeg::PATHSEG_CURVETO_CUBIC_REL:
85        return CREATE_SVG_OBJECT_WRAPPER(exec, globalObject, SVGPathSegCurvetoCubicRel, object, context);
86    case SVGPathSeg::PATHSEG_CURVETO_QUADRATIC_ABS:
87        return CREATE_SVG_OBJECT_WRAPPER(exec, globalObject, SVGPathSegCurvetoQuadraticAbs, object, context);
88    case SVGPathSeg::PATHSEG_CURVETO_QUADRATIC_REL:
89        return CREATE_SVG_OBJECT_WRAPPER(exec, globalObject, SVGPathSegCurvetoQuadraticRel, object, context);
90    case SVGPathSeg::PATHSEG_ARC_ABS:
91        return CREATE_SVG_OBJECT_WRAPPER(exec, globalObject, SVGPathSegArcAbs, object, context);
92    case SVGPathSeg::PATHSEG_ARC_REL:
93        return CREATE_SVG_OBJECT_WRAPPER(exec, globalObject, SVGPathSegArcRel, object, context);
94    case SVGPathSeg::PATHSEG_LINETO_HORIZONTAL_ABS:
95        return CREATE_SVG_OBJECT_WRAPPER(exec, globalObject, SVGPathSegLinetoHorizontalAbs, object, context);
96    case SVGPathSeg::PATHSEG_LINETO_HORIZONTAL_REL:
97        return CREATE_SVG_OBJECT_WRAPPER(exec, globalObject, SVGPathSegLinetoHorizontalRel, object, context);
98    case SVGPathSeg::PATHSEG_LINETO_VERTICAL_ABS:
99        return CREATE_SVG_OBJECT_WRAPPER(exec, globalObject, SVGPathSegLinetoVerticalAbs, object, context);
100    case SVGPathSeg::PATHSEG_LINETO_VERTICAL_REL:
101        return CREATE_SVG_OBJECT_WRAPPER(exec, globalObject, SVGPathSegLinetoVerticalRel, object, context);
102    case SVGPathSeg::PATHSEG_CURVETO_CUBIC_SMOOTH_ABS:
103        return CREATE_SVG_OBJECT_WRAPPER(exec, globalObject, SVGPathSegCurvetoCubicSmoothAbs, object, context);
104    case SVGPathSeg::PATHSEG_CURVETO_CUBIC_SMOOTH_REL:
105        return CREATE_SVG_OBJECT_WRAPPER(exec, globalObject, SVGPathSegCurvetoCubicSmoothRel, object, context);
106    case SVGPathSeg::PATHSEG_CURVETO_QUADRATIC_SMOOTH_ABS:
107        return CREATE_SVG_OBJECT_WRAPPER(exec, globalObject, SVGPathSegCurvetoQuadraticSmoothAbs, object, context);
108    case SVGPathSeg::PATHSEG_CURVETO_QUADRATIC_SMOOTH_REL:
109        return CREATE_SVG_OBJECT_WRAPPER(exec, globalObject, SVGPathSegCurvetoQuadraticSmoothRel, object, context);
110    case SVGPathSeg::PATHSEG_UNKNOWN:
111    default:
112        return CREATE_SVG_OBJECT_WRAPPER(exec, globalObject, SVGPathSeg, object, context);
113    }
114}
115
116}
117
118#endif // ENABLE(SVG)
119