JSSVGElementWrapperFactory.cpp [plain text]
#include "config.h"
#if SVG_SUPPORT
#include "JSSVGElementWrapperFactory.h"
#include "JSSVGSVGElement.h"
#include "SVGNames.h"
#include "SVGSVGElement.h"
using namespace KJS;
namespace WebCore {
using namespace SVGNames;
typedef DOMNode* (*CreateSVGElementWrapperFunction)(ExecState*, PassRefPtr<SVGElement>);
#define FOR_EACH_TAG(macro) \
macro(svg, SVG) \
#define CREATE_WRAPPER_FUNCTION(tag, name) \
static DOMNode* create##name##Wrapper(ExecState* exec, PassRefPtr<SVGElement> element) \
{ \
return new JSSVG##name##Element(exec, static_cast<SVG##name##Element*>(element.get())); \
}
FOR_EACH_TAG(CREATE_WRAPPER_FUNCTION)
#undef CREATE_WRAPPER_FUNCTION
DOMNode* createJSSVGWrapper(ExecState* exec, PassRefPtr<SVGElement> element)
{
static HashMap<WebCore::AtomicStringImpl*, CreateSVGElementWrapperFunction> map;
if (map.isEmpty()) {
#define ADD_TO_HASH_MAP(tag, name) map.set(tag##Tag.localName().impl(), create##name##Wrapper);
FOR_EACH_TAG(ADD_TO_HASH_MAP)
#undef ADD_TO_HASH_MAP
}
CreateSVGElementWrapperFunction createWrapperFunction = map.get(element->localName().impl());
if (createWrapperFunction)
return createWrapperFunction(exec, element);
return new JSSVGElement(exec, element.get());
}
}
#endif // SVG_SUPPORT