File indexing completed on 2024-05-12 15:37:26

0001 /*
0002  * Copyright (C) 2006, 2007, 2008 Nikolas Zimmermann <zimmermann@kde.org>
0003  *
0004  * This library is free software; you can redistribute it and/or
0005  * modify it under the terms of the GNU Library General Public
0006  * License as published by the Free Software Foundation; either
0007  * version 2 of the License, or (at your option) any later version.
0008  *
0009  * This library is distributed in the hope that it will be useful,
0010  * but WITHOUT ANY WARRANTY; without even the implied warranty of
0011  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
0012  * Library General Public License for more details.
0013  *
0014  * You should have received a copy of the GNU Library General Public License
0015  * along with this library; see the file COPYING.LIB.  If not, write to
0016  * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
0017  * Boston, MA 02110-1301, USA.
0018  */
0019 
0020 #include "wtf/Platform.h"
0021 
0022 #if ENABLE(SVG)
0023 #include "JSSVGPathSegList.h"
0024 
0025 #include "Document.h"
0026 #include "Frame.h"
0027 #include "JSSVGPathSeg.h"
0028 #include "SVGDocumentExtensions.h"
0029 #include "SVGElement.h"
0030 #include "SVGPathSegList.h"
0031 
0032 #include <wtf/Assertions.h>
0033 
0034 using namespace KJS;
0035 using namespace DOM;
0036 
0037 namespace khtml
0038 {
0039 
0040 KJS::JSValue *JSSVGPathSegList::clear(ExecState *exec, const List &args)
0041 {
0042     ExceptionCode ec = 0;
0043 
0044     SVGPathSegList *imp = static_cast<SVGPathSegList *>(impl());
0045     imp->clear(ec);
0046 
0047     setDOMException(exec, ec);
0048 
0049     m_context->svgAttributeChanged(imp->associatedAttributeName());
0050     return jsUndefined();
0051 }
0052 
0053 KJS::JSValue *JSSVGPathSegList::initialize(ExecState *exec, const List &args)
0054 {
0055     ExceptionCode ec = 0;
0056     SVGPathSeg *newItem = toSVGPathSeg(args[0]);
0057 
0058     SVGPathSegList *imp = static_cast<SVGPathSegList *>(impl());
0059 
0060     SVGPathSeg *obj = WTF::getPtr(imp->initialize(newItem, ec));
0061 
0062     KJS::JSValue *result = toJS(exec, obj, m_context.get());
0063     setDOMException(exec, ec);
0064 
0065     m_context->svgAttributeChanged(imp->associatedAttributeName());
0066     return result;
0067 }
0068 
0069 KJS::JSValue *JSSVGPathSegList::getItem(ExecState *exec, const List &args)
0070 {
0071     ExceptionCode ec = 0;
0072 
0073     bool indexOk;
0074     unsigned index = args[0]->toInt32(exec, indexOk);
0075     if (!indexOk) {
0076         setDOMException(exec, DOMException::TYPE_MISMATCH_ERR);
0077         return jsUndefined();
0078     }
0079 
0080     SVGPathSegList *imp = static_cast<SVGPathSegList *>(impl());
0081     SVGPathSeg *obj = WTF::getPtr(imp->getItem(index, ec));
0082 
0083     KJS::JSValue *result = toJS(exec, obj, m_context.get());
0084     setDOMException(exec, ec);
0085     return result;
0086 }
0087 
0088 KJS::JSValue *JSSVGPathSegList::insertItemBefore(ExecState *exec, const List &args)
0089 {
0090     ExceptionCode ec = 0;
0091     SVGPathSeg *newItem = toSVGPathSeg(args[0]);
0092 
0093     bool indexOk;
0094     unsigned index = args[1]->toInt32(exec, indexOk);
0095     if (!indexOk) {
0096         setDOMException(exec, DOMException::TYPE_MISMATCH_ERR);
0097         return jsUndefined();
0098     }
0099 
0100     SVGPathSegList *imp = static_cast<SVGPathSegList *>(impl());
0101 
0102     KJS::JSValue *result = toJS(exec, WTF::getPtr(imp->insertItemBefore(newItem, index, ec)), m_context.get());
0103     setDOMException(exec, ec);
0104 
0105     m_context->svgAttributeChanged(imp->associatedAttributeName());
0106     return result;
0107 }
0108 
0109 KJS::JSValue *JSSVGPathSegList::replaceItem(ExecState *exec, const List &args)
0110 {
0111     ExceptionCode ec = 0;
0112     SVGPathSeg *newItem = toSVGPathSeg(args[0]);
0113 
0114     bool indexOk;
0115     unsigned index = args[1]->toInt32(exec, indexOk);
0116     if (!indexOk) {
0117         setDOMException(exec, DOMException::TYPE_MISMATCH_ERR);
0118         return jsUndefined();
0119     }
0120 
0121     SVGPathSegList *imp = static_cast<SVGPathSegList *>(impl());
0122 
0123     KJS::JSValue *result = toJS(exec, WTF::getPtr(imp->replaceItem(newItem, index, ec)), m_context.get());
0124     setDOMException(exec, ec);
0125 
0126     m_context->svgAttributeChanged(imp->associatedAttributeName());
0127     return result;
0128 }
0129 
0130 KJS::JSValue *JSSVGPathSegList::removeItem(ExecState *exec, const List &args)
0131 {
0132     ExceptionCode ec = 0;
0133 
0134     bool indexOk;
0135     unsigned index = args[0]->toInt32(exec, indexOk);
0136     if (!indexOk) {
0137         setDOMException(exec, DOMException::TYPE_MISMATCH_ERR);
0138         return jsUndefined();
0139     }
0140 
0141     SVGPathSegList *imp = static_cast<SVGPathSegList *>(impl());
0142 
0143     RefPtr<SVGPathSeg> obj(imp->removeItem(index, ec));
0144 
0145     KJS::JSValue *result = toJS(exec, obj.get(), m_context.get());
0146     setDOMException(exec, ec);
0147 
0148     m_context->svgAttributeChanged(imp->associatedAttributeName());
0149     return result;
0150 }
0151 
0152 KJS::JSValue *JSSVGPathSegList::appendItem(ExecState *exec, const List &args)
0153 {
0154     ExceptionCode ec = 0;
0155     SVGPathSeg *newItem = toSVGPathSeg(args[0]);
0156 
0157     SVGPathSegList *imp = static_cast<SVGPathSegList *>(impl());
0158 
0159     KJS::JSValue *result = toJS(exec, WTF::getPtr(imp->appendItem(newItem, ec)), m_context.get());
0160     setDOMException(exec, ec);
0161 
0162     m_context->svgAttributeChanged(imp->associatedAttributeName());
0163     return result;
0164 }
0165 
0166 }
0167 
0168 #endif // ENABLE(SVG)