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