KHtml

JSSVGPathSegListCustom.cpp
1 /*
2  * Copyright (C) 2006, 2007, 2008 Nikolas Zimmermann <[email protected]>
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 "wtf/Platform.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 KJS;
35 using namespace DOM;
36 
37 namespace khtml
38 {
39 
40 KJS::JSValue *JSSVGPathSegList::clear(ExecState *exec, const List &args)
41 {
42  ExceptionCode ec = 0;
43 
44  SVGPathSegList *imp = static_cast<SVGPathSegList *>(impl());
45  imp->clear(ec);
46 
47  setDOMException(exec, ec);
48 
49  m_context->svgAttributeChanged(imp->associatedAttributeName());
50  return jsUndefined();
51 }
52 
53 KJS::JSValue *JSSVGPathSegList::initialize(ExecState *exec, const List &args)
54 {
55  ExceptionCode ec = 0;
56  SVGPathSeg *newItem = toSVGPathSeg(args[0]);
57 
58  SVGPathSegList *imp = static_cast<SVGPathSegList *>(impl());
59 
60  SVGPathSeg *obj = WTF::getPtr(imp->initialize(newItem, ec));
61 
62  KJS::JSValue *result = toJS(exec, obj, m_context.get());
63  setDOMException(exec, ec);
64 
65  m_context->svgAttributeChanged(imp->associatedAttributeName());
66  return result;
67 }
68 
69 KJS::JSValue *JSSVGPathSegList::getItem(ExecState *exec, const List &args)
70 {
71  ExceptionCode ec = 0;
72 
73  bool indexOk;
74  unsigned index = args[0]->toInt32(exec, indexOk);
75  if (!indexOk) {
76  setDOMException(exec, DOMException::TYPE_MISMATCH_ERR);
77  return jsUndefined();
78  }
79 
80  SVGPathSegList *imp = static_cast<SVGPathSegList *>(impl());
81  SVGPathSeg *obj = WTF::getPtr(imp->getItem(index, ec));
82 
83  KJS::JSValue *result = toJS(exec, obj, m_context.get());
84  setDOMException(exec, ec);
85  return result;
86 }
87 
88 KJS::JSValue *JSSVGPathSegList::insertItemBefore(ExecState *exec, const List &args)
89 {
90  ExceptionCode ec = 0;
91  SVGPathSeg *newItem = toSVGPathSeg(args[0]);
92 
93  bool indexOk;
94  unsigned index = args[1]->toInt32(exec, indexOk);
95  if (!indexOk) {
96  setDOMException(exec, DOMException::TYPE_MISMATCH_ERR);
97  return jsUndefined();
98  }
99 
100  SVGPathSegList *imp = static_cast<SVGPathSegList *>(impl());
101 
102  KJS::JSValue *result = toJS(exec, WTF::getPtr(imp->insertItemBefore(newItem, index, ec)), m_context.get());
103  setDOMException(exec, ec);
104 
105  m_context->svgAttributeChanged(imp->associatedAttributeName());
106  return result;
107 }
108 
109 KJS::JSValue *JSSVGPathSegList::replaceItem(ExecState *exec, const List &args)
110 {
111  ExceptionCode ec = 0;
112  SVGPathSeg *newItem = toSVGPathSeg(args[0]);
113 
114  bool indexOk;
115  unsigned index = args[1]->toInt32(exec, indexOk);
116  if (!indexOk) {
117  setDOMException(exec, DOMException::TYPE_MISMATCH_ERR);
118  return jsUndefined();
119  }
120 
121  SVGPathSegList *imp = static_cast<SVGPathSegList *>(impl());
122 
123  KJS::JSValue *result = toJS(exec, WTF::getPtr(imp->replaceItem(newItem, index, ec)), m_context.get());
124  setDOMException(exec, ec);
125 
126  m_context->svgAttributeChanged(imp->associatedAttributeName());
127  return result;
128 }
129 
130 KJS::JSValue *JSSVGPathSegList::removeItem(ExecState *exec, const List &args)
131 {
132  ExceptionCode ec = 0;
133 
134  bool indexOk;
135  unsigned index = args[0]->toInt32(exec, indexOk);
136  if (!indexOk) {
137  setDOMException(exec, DOMException::TYPE_MISMATCH_ERR);
138  return jsUndefined();
139  }
140 
141  SVGPathSegList *imp = static_cast<SVGPathSegList *>(impl());
142 
143  RefPtr<SVGPathSeg> obj(imp->removeItem(index, ec));
144 
145  KJS::JSValue *result = toJS(exec, obj.get(), m_context.get());
146  setDOMException(exec, ec);
147 
148  m_context->svgAttributeChanged(imp->associatedAttributeName());
149  return result;
150 }
151 
152 KJS::JSValue *JSSVGPathSegList::appendItem(ExecState *exec, const List &args)
153 {
154  ExceptionCode ec = 0;
155  SVGPathSeg *newItem = toSVGPathSeg(args[0]);
156 
157  SVGPathSegList *imp = static_cast<SVGPathSegList *>(impl());
158 
159  KJS::JSValue *result = toJS(exec, WTF::getPtr(imp->appendItem(newItem, ec)), m_context.get());
160  setDOMException(exec, ec);
161 
162  m_context->svgAttributeChanged(imp->associatedAttributeName());
163  return result;
164 }
165 
166 }
167 
168 #endif // ENABLE(SVG)
This file is part of the HTML rendering engine for KDE.
This library provides a full-featured HTML parser and widget.
This file is part of the KDE documentation.
Documentation copyright © 1996-2021 The KDE developers.
Generated on Mon Oct 25 2021 22:48:16 by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.