1 /*
2 * Copyright (C) 2006, 2007, 2008 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 "JSSVGPathSegList.h"
24
25 #include "Document.h"
26 #include "Frame.h"
27 #include "JSSVGPathSeg.h"
28 #include "SVGDocumentExtensions.h"
29 #include "SVGElement.h"
30 #include "SVGPathSegList.h"
31
32 #include <wtf/Assertions.h>
33
34 using namespace JSC;
35
36 namespace WebCore {
37
clear(ExecState * exec,const ArgList &)38 JSValue JSSVGPathSegList::clear(ExecState* exec, const ArgList&)
39 {
40 ExceptionCode ec = 0;
41
42 SVGPathSegList* imp = static_cast<SVGPathSegList*>(impl());
43 imp->clear(ec);
44
45 setDOMException(exec, ec);
46
47 m_context->svgAttributeChanged(imp->associatedAttributeName());
48 return jsUndefined();
49 }
50
initialize(ExecState * exec,const ArgList & args)51 JSValue JSSVGPathSegList::initialize(ExecState* exec, const ArgList& args)
52 {
53 ExceptionCode ec = 0;
54 SVGPathSeg* newItem = toSVGPathSeg(args.at(0));
55
56 SVGPathSegList* imp = static_cast<SVGPathSegList*>(impl());
57
58 SVGPathSeg* obj = WTF::getPtr(imp->initialize(newItem, ec));
59
60 JSC::JSValue result = toJS(exec, deprecatedGlobalObjectForPrototype(exec), obj, m_context.get());
61 setDOMException(exec, ec);
62
63 m_context->svgAttributeChanged(imp->associatedAttributeName());
64 return result;
65 }
66
getItem(ExecState * exec,const ArgList & args)67 JSValue JSSVGPathSegList::getItem(ExecState* exec, const ArgList& args)
68 {
69 ExceptionCode ec = 0;
70
71 bool indexOk;
72 unsigned index = args.at(0).toInt32(exec, indexOk);
73 if (!indexOk) {
74 setDOMException(exec, TYPE_MISMATCH_ERR);
75 return jsUndefined();
76 }
77
78 SVGPathSegList* imp = static_cast<SVGPathSegList*>(impl());
79 SVGPathSeg* obj = WTF::getPtr(imp->getItem(index, ec));
80
81 JSC::JSValue result = toJS(exec, deprecatedGlobalObjectForPrototype(exec), obj, m_context.get());
82 setDOMException(exec, ec);
83 return result;
84 }
85
insertItemBefore(ExecState * exec,const ArgList & args)86 JSValue JSSVGPathSegList::insertItemBefore(ExecState* exec, const ArgList& args)
87 {
88 ExceptionCode ec = 0;
89 SVGPathSeg* newItem = toSVGPathSeg(args.at(0));
90
91 bool indexOk;
92 unsigned index = args.at(1).toInt32(exec, indexOk);
93 if (!indexOk) {
94 setDOMException(exec, TYPE_MISMATCH_ERR);
95 return jsUndefined();
96 }
97
98 SVGPathSegList* imp = static_cast<SVGPathSegList*>(impl());
99
100 JSC::JSValue result = toJS(exec, deprecatedGlobalObjectForPrototype(exec), WTF::getPtr(imp->insertItemBefore(newItem, index, ec)), m_context.get());
101 setDOMException(exec, ec);
102
103 m_context->svgAttributeChanged(imp->associatedAttributeName());
104 return result;
105 }
106
replaceItem(ExecState * exec,const ArgList & args)107 JSValue JSSVGPathSegList::replaceItem(ExecState* exec, const ArgList& args)
108 {
109 ExceptionCode ec = 0;
110 SVGPathSeg* newItem = toSVGPathSeg(args.at(0));
111
112 bool indexOk;
113 unsigned index = args.at(1).toInt32(exec, indexOk);
114 if (!indexOk) {
115 setDOMException(exec, TYPE_MISMATCH_ERR);
116 return jsUndefined();
117 }
118
119 SVGPathSegList* imp = static_cast<SVGPathSegList*>(impl());
120
121 JSC::JSValue result = toJS(exec, deprecatedGlobalObjectForPrototype(exec), WTF::getPtr(imp->replaceItem(newItem, index, ec)), m_context.get());
122 setDOMException(exec, ec);
123
124 m_context->svgAttributeChanged(imp->associatedAttributeName());
125 return result;
126 }
127
removeItem(ExecState * exec,const ArgList & args)128 JSValue JSSVGPathSegList::removeItem(ExecState* exec, const ArgList& args)
129 {
130 ExceptionCode ec = 0;
131
132 bool indexOk;
133 unsigned index = args.at(0).toInt32(exec, indexOk);
134 if (!indexOk) {
135 setDOMException(exec, TYPE_MISMATCH_ERR);
136 return jsUndefined();
137 }
138
139 SVGPathSegList* imp = static_cast<SVGPathSegList*>(impl());
140
141 RefPtr<SVGPathSeg> obj(imp->removeItem(index, ec));
142
143 JSC::JSValue result = toJS(exec, deprecatedGlobalObjectForPrototype(exec), obj.get(), m_context.get());
144 setDOMException(exec, ec);
145
146 m_context->svgAttributeChanged(imp->associatedAttributeName());
147 return result;
148 }
149
appendItem(ExecState * exec,const ArgList & args)150 JSValue JSSVGPathSegList::appendItem(ExecState* exec, const ArgList& args)
151 {
152 ExceptionCode ec = 0;
153 SVGPathSeg* newItem = toSVGPathSeg(args.at(0));
154
155 SVGPathSegList* imp = static_cast<SVGPathSegList*>(impl());
156
157 JSC::JSValue result = toJS(exec, deprecatedGlobalObjectForPrototype(exec), WTF::getPtr(imp->appendItem(newItem, ec)), m_context.get());
158 setDOMException(exec, ec);
159
160 m_context->svgAttributeChanged(imp->associatedAttributeName());
161 return result;
162 }
163
164 }
165
166 #endif // ENABLE(SVG)
167