1/* 2 * Copyright (C) 2007, 2008 Apple Inc. All rights reserved. 3 * 4 * Redistribution and use in source and binary forms, with or without 5 * modification, are permitted provided that the following conditions 6 * are met: 7 * 8 * 1. Redistributions of source code must retain the above copyright 9 * notice, this list of conditions and the following disclaimer. 10 * 2. Redistributions in binary form must reproduce the above copyright 11 * notice, this list of conditions and the following disclaimer in the 12 * documentation and/or other materials provided with the distribution. 13 * 3. Neither the name of Apple Computer, Inc. ("Apple") nor the names of 14 * its contributors may be used to endorse or promote products derived 15 * from this software without specific prior written permission. 16 * 17 * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY 18 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 19 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 20 * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY 21 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 22 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 23 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 24 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 */ 28 29#include "config.h" 30#include "JSEvent.h" 31 32#include "Clipboard.h" 33#include "CompositionEvent.h" 34#include "Event.h" 35#include "JSBeforeLoadEvent.h" 36#include "JSClipboard.h" 37#include "JSCompositionEvent.h" 38#include "JSErrorEvent.h" 39#include "JSKeyboardEvent.h" 40#include "JSMessageEvent.h" 41#include "JSMouseEvent.h" 42#include "JSMutationEvent.h" 43#include "JSOverflowEvent.h" 44#include "JSPageTransitionEvent.h" 45#include "JSPopStateEvent.h" 46#include "JSProgressEvent.h" 47#include "JSTextEvent.h" 48#include "JSUIEvent.h" 49#include "JSWebKitAnimationEvent.h" 50#include "JSWebKitTransitionEvent.h" 51#include "JSWheelEvent.h" 52#include "JSXMLHttpRequestProgressEvent.h" 53#include "BeforeLoadEvent.h" 54#include "ErrorEvent.h" 55#include "KeyboardEvent.h" 56#include "MessageEvent.h" 57#include "MouseEvent.h" 58#include "MutationEvent.h" 59#include "OverflowEvent.h" 60#include "PageTransitionEvent.h" 61#include "PopStateEvent.h" 62#include "ProgressEvent.h" 63#include "TextEvent.h" 64#include "UIEvent.h" 65#include "WebKitAnimationEvent.h" 66#include "WebKitTransitionEvent.h" 67#include "WheelEvent.h" 68#include "XMLHttpRequestProgressEvent.h" 69#include <runtime/JSLock.h> 70 71#if ENABLE(DOM_STORAGE) 72#include "JSStorageEvent.h" 73#include "StorageEvent.h" 74#endif 75 76#if ENABLE(SVG) 77#include "JSSVGZoomEvent.h" 78#include "SVGZoomEvent.h" 79#endif 80 81#if ENABLE(TOUCH_EVENTS) 82#include "JSTouchEvent.h" 83#include "TouchEvent.h" 84#endif 85 86using namespace JSC; 87 88namespace WebCore { 89 90JSValue JSEvent::clipboardData(ExecState* exec) const 91{ 92 return impl()->isClipboardEvent() ? toJS(exec, globalObject(), impl()->clipboardData()) : jsUndefined(); 93} 94 95JSValue toJS(ExecState* exec, JSDOMGlobalObject* globalObject, Event* event) 96{ 97 JSLock lock(SilenceAssertionsOnly); 98 99 if (!event) 100 return jsNull(); 101 102 DOMObject* wrapper = getCachedDOMObjectWrapper(exec, event); 103 if (wrapper) 104 return wrapper; 105 106 if (event->isUIEvent()) { 107 if (event->isKeyboardEvent()) 108 wrapper = CREATE_DOM_OBJECT_WRAPPER(exec, globalObject, KeyboardEvent, event); 109 else if (event->isTextEvent()) 110 wrapper = CREATE_DOM_OBJECT_WRAPPER(exec, globalObject, TextEvent, event); 111 else if (event->isMouseEvent()) 112 wrapper = CREATE_DOM_OBJECT_WRAPPER(exec, globalObject, MouseEvent, event); 113 else if (event->isWheelEvent()) 114 wrapper = CREATE_DOM_OBJECT_WRAPPER(exec, globalObject, WheelEvent, event); 115#if ENABLE(SVG) 116 else if (event->isSVGZoomEvent()) 117 wrapper = CREATE_DOM_OBJECT_WRAPPER(exec, globalObject, SVGZoomEvent, event); 118#endif 119 else if (event->isCompositionEvent()) 120 wrapper = CREATE_DOM_OBJECT_WRAPPER(exec, globalObject, CompositionEvent, event); 121#if ENABLE(TOUCH_EVENTS) 122 else if (event->isTouchEvent()) 123 wrapper = CREATE_DOM_OBJECT_WRAPPER(exec, globalObject, TouchEvent, event); 124#endif 125 else 126 wrapper = CREATE_DOM_OBJECT_WRAPPER(exec, globalObject, UIEvent, event); 127 } else if (event->isMutationEvent()) 128 wrapper = CREATE_DOM_OBJECT_WRAPPER(exec, globalObject, MutationEvent, event); 129 else if (event->isOverflowEvent()) 130 wrapper = CREATE_DOM_OBJECT_WRAPPER(exec, globalObject, OverflowEvent, event); 131 else if (event->isMessageEvent()) 132 wrapper = CREATE_DOM_OBJECT_WRAPPER(exec, globalObject, MessageEvent, event); 133 else if (event->isPageTransitionEvent()) 134 wrapper = CREATE_DOM_OBJECT_WRAPPER(exec, globalObject, PageTransitionEvent, event); 135 else if (event->isProgressEvent()) { 136 if (event->isXMLHttpRequestProgressEvent()) 137 wrapper = CREATE_DOM_OBJECT_WRAPPER(exec, globalObject, XMLHttpRequestProgressEvent, event); 138 else 139 wrapper = CREATE_DOM_OBJECT_WRAPPER(exec, globalObject, ProgressEvent, event); 140 } else if (event->isBeforeLoadEvent()) 141 wrapper = CREATE_DOM_OBJECT_WRAPPER(exec, globalObject, BeforeLoadEvent, event); 142#if ENABLE(DOM_STORAGE) 143 else if (event->isStorageEvent()) 144 wrapper = CREATE_DOM_OBJECT_WRAPPER(exec, globalObject, StorageEvent, event); 145#endif 146 else if (event->isWebKitAnimationEvent()) 147 wrapper = CREATE_DOM_OBJECT_WRAPPER(exec, globalObject, WebKitAnimationEvent, event); 148 else if (event->isWebKitTransitionEvent()) 149 wrapper = CREATE_DOM_OBJECT_WRAPPER(exec, globalObject, WebKitTransitionEvent, event); 150#if ENABLE(WORKERS) 151 else if (event->isErrorEvent()) 152 wrapper = CREATE_DOM_OBJECT_WRAPPER(exec, globalObject, ErrorEvent, event); 153#endif 154 else if (event->isPopStateEvent()) 155 wrapper = CREATE_DOM_OBJECT_WRAPPER(exec, globalObject, PopStateEvent, event); 156 else 157 wrapper = CREATE_DOM_OBJECT_WRAPPER(exec, globalObject, Event, event); 158 159 return wrapper; 160} 161 162} // namespace WebCore 163