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

0001 /*
0002  * Copyright (C) 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 "JSSVGTransformList.h"
0024 
0025 #include "Document.h"
0026 #include "Frame.h"
0027 #include "JSSVGTransform.h"
0028 #include "SVGDocumentExtensions.h"
0029 #include "SVGTransformList.h"
0030 #include "SVGStyledElement.h"
0031 
0032 #include <wtf/Assertions.h>
0033 
0034 using namespace KJS;
0035 using namespace WebCore;
0036 
0037 namespace khtml
0038 {
0039 
0040 JSValue *JSSVGTransformList::clear(ExecState *exec, const List &)
0041 {
0042     ExceptionCode ec = 0;
0043 
0044     SVGTransformList *imp = static_cast<SVGTransformList *>(impl());
0045     imp->clear(ec);
0046     setDOMException(exec, ec);
0047 
0048     m_context->svgAttributeChanged(imp->associatedAttributeName());
0049 
0050     return jsUndefined();
0051 }
0052 
0053 JSValue *JSSVGTransformList::initialize(ExecState *exec, const List &args)
0054 {
0055     ExceptionCode ec = 0;
0056     SVGTransform newItem = toSVGTransform(args[0]);
0057 
0058     SVGTransformList *imp = static_cast<SVGTransformList *>(impl());
0059     SVGList<RefPtr<SVGPODListItem<SVGTransform> > > *listImp = imp;
0060 
0061     SVGPODListItem<SVGTransform> *listItem = listImp->initialize(SVGPODListItem<SVGTransform>::copy(newItem), ec).get();
0062     JSSVGPODTypeWrapperCreatorForList<SVGTransform> *obj = new JSSVGPODTypeWrapperCreatorForList<SVGTransform>(listItem, imp->associatedAttributeName());
0063 
0064     KJS::JSValue *result = toJS(exec, obj, m_context.get());
0065     setDOMException(exec, ec);
0066 
0067     m_context->svgAttributeChanged(imp->associatedAttributeName());
0068 
0069     return result;
0070 }
0071 
0072 JSValue *JSSVGTransformList::getItem(ExecState *exec, const List &args)
0073 {
0074     ExceptionCode ec = 0;
0075 
0076     bool indexOk;
0077     unsigned index = args[0]->toInt32(exec, indexOk);
0078     if (!indexOk) {
0079         setDOMException(exec, DOMException::TYPE_MISMATCH_ERR);
0080         return jsUndefined();
0081     }
0082 
0083     SVGTransformList *imp = static_cast<SVGTransformList *>(impl());
0084     SVGList<RefPtr<SVGPODListItem<SVGTransform> > > *listImp = imp;
0085 
0086     SVGPODListItem<SVGTransform> *listItem = listImp->getItem(index, ec).get();
0087     JSSVGPODTypeWrapperCreatorForList<SVGTransform> *obj = new JSSVGPODTypeWrapperCreatorForList<SVGTransform>(listItem, imp->associatedAttributeName());
0088 
0089     KJS::JSValue *result = toJS(exec, obj, m_context.get());
0090     setDOMException(exec, ec);
0091     return result;
0092 }
0093 
0094 JSValue *JSSVGTransformList::insertItemBefore(ExecState *exec, const List &args)
0095 {
0096     ExceptionCode ec = 0;
0097     SVGTransform newItem = toSVGTransform(args[0]);
0098 
0099     bool indexOk;
0100     unsigned index = args[1]->toInt32(exec, indexOk);
0101     if (!indexOk) {
0102         setDOMException(exec, DOMException::TYPE_MISMATCH_ERR);
0103         return jsUndefined();
0104     }
0105 
0106     SVGTransformList *imp = static_cast<SVGTransformList *>(impl());
0107     SVGList<RefPtr<SVGPODListItem<SVGTransform> > > *listImp = imp;
0108 
0109     SVGPODListItem<SVGTransform> *listItem = listImp->insertItemBefore(SVGPODListItem<SVGTransform>::copy(newItem), index, ec).get();
0110     JSSVGPODTypeWrapperCreatorForList<SVGTransform> *obj = new JSSVGPODTypeWrapperCreatorForList<SVGTransform>(listItem, imp->associatedAttributeName());
0111 
0112     KJS::JSValue *result = toJS(exec, obj, m_context.get());
0113     setDOMException(exec, ec);
0114 
0115     m_context->svgAttributeChanged(imp->associatedAttributeName());
0116 
0117     return result;
0118 }
0119 
0120 JSValue *JSSVGTransformList::replaceItem(ExecState *exec, const List &args)
0121 {
0122     ExceptionCode ec = 0;
0123     SVGTransform newItem = toSVGTransform(args[0]);
0124 
0125     bool indexOk;
0126     unsigned index = args[1]->toInt32(exec, indexOk);
0127     if (!indexOk) {
0128         setDOMException(exec, DOMException::TYPE_MISMATCH_ERR);
0129         return jsUndefined();
0130     }
0131 
0132     SVGTransformList *imp = static_cast<SVGTransformList *>(impl());
0133     SVGList<RefPtr<SVGPODListItem<SVGTransform> > > *listImp = imp;
0134 
0135     SVGPODListItem<SVGTransform> *listItem = listImp->replaceItem(SVGPODListItem<SVGTransform>::copy(newItem), index, ec).get();
0136     JSSVGPODTypeWrapperCreatorForList<SVGTransform> *obj = new JSSVGPODTypeWrapperCreatorForList<SVGTransform>(listItem, imp->associatedAttributeName());
0137 
0138     KJS::JSValue *result = toJS(exec, obj, m_context.get());
0139     setDOMException(exec, ec);
0140 
0141     m_context->svgAttributeChanged(imp->associatedAttributeName());
0142 
0143     return result;
0144 }
0145 
0146 JSValue *JSSVGTransformList::removeItem(ExecState *exec, const List &args)
0147 {
0148     ExceptionCode ec = 0;
0149 
0150     bool indexOk;
0151     unsigned index = args[0]->toInt32(exec, indexOk);
0152     if (!indexOk) {
0153         setDOMException(exec, DOMException::TYPE_MISMATCH_ERR);
0154         return jsUndefined();
0155     }
0156 
0157     SVGTransformList *imp = static_cast<SVGTransformList *>(impl());
0158     SVGList<RefPtr<SVGPODListItem<SVGTransform> > > *listImp = imp;
0159 
0160     RefPtr<SVGPODListItem<SVGTransform> > listItem(listImp->removeItem(index, ec));
0161     JSSVGPODTypeWrapper<SVGTransform> *obj = new JSSVGPODTypeWrapperCreatorReadOnly<SVGTransform>(*listItem.get());
0162 
0163     KJS::JSValue *result = toJS(exec, obj, m_context.get());
0164     setDOMException(exec, ec);
0165 
0166     m_context->svgAttributeChanged(imp->associatedAttributeName());
0167 
0168     return result;
0169 }
0170 
0171 JSValue *JSSVGTransformList::appendItem(ExecState *exec, const List &args)
0172 {
0173     ExceptionCode ec = 0;
0174     SVGTransform newItem = toSVGTransform(args[0]);
0175 
0176     SVGTransformList *imp = static_cast<SVGTransformList *>(impl());
0177     SVGList<RefPtr<SVGPODListItem<SVGTransform> > > *listImp = imp;
0178 
0179     SVGPODListItem<SVGTransform> *listItem = listImp->appendItem(SVGPODListItem<SVGTransform>::copy(newItem), ec).get();
0180     JSSVGPODTypeWrapperCreatorForList<SVGTransform> *obj = new JSSVGPODTypeWrapperCreatorForList<SVGTransform>(listItem, imp->associatedAttributeName());
0181 
0182     KJS::JSValue *result = toJS(exec, obj, m_context.get());
0183     setDOMException(exec, ec);
0184 
0185     m_context->svgAttributeChanged(imp->associatedAttributeName());
0186 
0187     return result;
0188 }
0189 
0190 }
0191 
0192 #endif // ENABLE(SVG)