• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 "CustomEvent.h"
35 #include "DeviceMotionEvent.h"
36 #include "DeviceOrientationEvent.h"
37 #include "Event.h"
38 #include "JSBeforeLoadEvent.h"
39 #include "JSClipboard.h"
40 #include "JSCustomEvent.h"
41 #include "JSCompositionEvent.h"
42 #include "JSDeviceMotionEvent.h"
43 #include "JSDeviceOrientationEvent.h"
44 #include "JSErrorEvent.h"
45 #include "JSHashChangeEvent.h"
46 #include "JSKeyboardEvent.h"
47 #include "JSMessageEvent.h"
48 #include "JSMouseEvent.h"
49 #include "JSMutationEvent.h"
50 #include "JSOverflowEvent.h"
51 #include "JSPageTransitionEvent.h"
52 #include "JSPopStateEvent.h"
53 #include "JSProgressEvent.h"
54 #include "JSSpeechInputEvent.h"
55 #include "JSTextEvent.h"
56 #include "JSUIEvent.h"
57 #include "JSWebKitAnimationEvent.h"
58 #include "JSWebKitTransitionEvent.h"
59 #include "JSWheelEvent.h"
60 #include "JSXMLHttpRequestProgressEvent.h"
61 #include "BeforeLoadEvent.h"
62 #include "ErrorEvent.h"
63 #include "HashChangeEvent.h"
64 #include "KeyboardEvent.h"
65 #include "MessageEvent.h"
66 #include "MouseEvent.h"
67 #include "MutationEvent.h"
68 #include "OverflowEvent.h"
69 #include "PageTransitionEvent.h"
70 #include "PopStateEvent.h"
71 #include "ProgressEvent.h"
72 #include "SpeechInputEvent.h"
73 #include "TextEvent.h"
74 #include "UIEvent.h"
75 #include "WebKitAnimationEvent.h"
76 #include "WebKitTransitionEvent.h"
77 #include "WheelEvent.h"
78 #include "XMLHttpRequestProgressEvent.h"
79 #include <runtime/JSLock.h>
80 
81 #if ENABLE(DOM_STORAGE)
82 #include "JSStorageEvent.h"
83 #include "StorageEvent.h"
84 #endif
85 
86 #if ENABLE(SVG)
87 #include "JSSVGZoomEvent.h"
88 #include "SVGZoomEvent.h"
89 #endif
90 
91 #if ENABLE(TOUCH_EVENTS)
92 #include "JSTouchEvent.h"
93 #include "TouchEvent.h"
94 #endif
95 
96 #if ENABLE(INDEXED_DATABASE)
97 #include "IDBVersionChangeEvent.h"
98 #include "JSIDBVersionChangeEvent.h"
99 #endif
100 
101 #if ENABLE(WEB_AUDIO)
102 #include "AudioProcessingEvent.h"
103 #include "JSAudioProcessingEvent.h"
104 #include "JSOfflineAudioCompletionEvent.h"
105 #include "OfflineAudioCompletionEvent.h"
106 #endif
107 
108 using namespace JSC;
109 
110 namespace WebCore {
111 
clipboardData(ExecState * exec) const112 JSValue JSEvent::clipboardData(ExecState* exec) const
113 {
114     return impl()->isClipboardEvent() ? toJS(exec, globalObject(), impl()->clipboardData()) : jsUndefined();
115 }
116 
toJS(ExecState * exec,JSDOMGlobalObject * globalObject,Event * event)117 JSValue toJS(ExecState* exec, JSDOMGlobalObject* globalObject, Event* event)
118 {
119     JSLock lock(SilenceAssertionsOnly);
120 
121     if (!event)
122         return jsNull();
123 
124     JSDOMWrapper* wrapper = getCachedWrapper(currentWorld(exec), event);
125     if (wrapper)
126         return wrapper;
127 
128     if (event->isUIEvent()) {
129         if (event->isKeyboardEvent())
130             wrapper = CREATE_DOM_OBJECT_WRAPPER(exec, globalObject, KeyboardEvent, event);
131         else if (event->isTextEvent())
132             wrapper = CREATE_DOM_OBJECT_WRAPPER(exec, globalObject, TextEvent, event);
133         else if (event->isMouseEvent())
134             wrapper = CREATE_DOM_OBJECT_WRAPPER(exec, globalObject, MouseEvent, event);
135         else if (event->isWheelEvent())
136             wrapper = CREATE_DOM_OBJECT_WRAPPER(exec, globalObject, WheelEvent, event);
137 #if ENABLE(SVG)
138         else if (event->isSVGZoomEvent())
139             wrapper = CREATE_DOM_OBJECT_WRAPPER(exec, globalObject, SVGZoomEvent, event);
140 #endif
141         else if (event->isCompositionEvent())
142             wrapper = CREATE_DOM_OBJECT_WRAPPER(exec, globalObject, CompositionEvent, event);
143 #if ENABLE(TOUCH_EVENTS)
144         else if (event->isTouchEvent())
145             wrapper = CREATE_DOM_OBJECT_WRAPPER(exec, globalObject, TouchEvent, event);
146 #endif
147         else
148             wrapper = CREATE_DOM_OBJECT_WRAPPER(exec, globalObject, UIEvent, event);
149     } else if (event->isMutationEvent())
150         wrapper = CREATE_DOM_OBJECT_WRAPPER(exec, globalObject, MutationEvent, event);
151     else if (event->isOverflowEvent())
152         wrapper = CREATE_DOM_OBJECT_WRAPPER(exec, globalObject, OverflowEvent, event);
153     else if (event->isMessageEvent())
154         wrapper = CREATE_DOM_OBJECT_WRAPPER(exec, globalObject, MessageEvent, event);
155     else if (event->isPageTransitionEvent())
156         wrapper = CREATE_DOM_OBJECT_WRAPPER(exec, globalObject, PageTransitionEvent, event);
157     else if (event->isProgressEvent()) {
158         if (event->isXMLHttpRequestProgressEvent())
159             wrapper = CREATE_DOM_OBJECT_WRAPPER(exec, globalObject, XMLHttpRequestProgressEvent, event);
160         else
161             wrapper = CREATE_DOM_OBJECT_WRAPPER(exec, globalObject, ProgressEvent, event);
162     } else if (event->isBeforeLoadEvent())
163         wrapper = CREATE_DOM_OBJECT_WRAPPER(exec, globalObject, BeforeLoadEvent, event);
164 #if ENABLE(DOM_STORAGE)
165     else if (event->isStorageEvent())
166         wrapper = CREATE_DOM_OBJECT_WRAPPER(exec, globalObject, StorageEvent, event);
167 #endif
168 #if ENABLE(INDEXED_DATABASE)
169     else if (event->isIDBVersionChangeEvent())
170         wrapper = CREATE_DOM_OBJECT_WRAPPER(exec, globalObject, IDBVersionChangeEvent, event);
171 #endif
172     else if (event->isWebKitAnimationEvent())
173         wrapper = CREATE_DOM_OBJECT_WRAPPER(exec, globalObject, WebKitAnimationEvent, event);
174     else if (event->isWebKitTransitionEvent())
175         wrapper = CREATE_DOM_OBJECT_WRAPPER(exec, globalObject, WebKitTransitionEvent, event);
176 #if ENABLE(WORKERS)
177     else if (event->isErrorEvent())
178         wrapper = CREATE_DOM_OBJECT_WRAPPER(exec, globalObject, ErrorEvent, event);
179 #endif
180     else if (event->isHashChangeEvent())
181         wrapper = CREATE_DOM_OBJECT_WRAPPER(exec, globalObject, HashChangeEvent, event);
182     else if (event->isPopStateEvent())
183         wrapper = CREATE_DOM_OBJECT_WRAPPER(exec, globalObject, PopStateEvent, event);
184     else if (event->isCustomEvent())
185         wrapper = CREATE_DOM_OBJECT_WRAPPER(exec, globalObject, CustomEvent, event);
186 #if ENABLE(DEVICE_ORIENTATION)
187     else if (event->isDeviceMotionEvent())
188         wrapper = CREATE_DOM_OBJECT_WRAPPER(exec, globalObject, DeviceMotionEvent, event);
189     else if (event->isDeviceOrientationEvent())
190         wrapper = CREATE_DOM_OBJECT_WRAPPER(exec, globalObject, DeviceOrientationEvent, event);
191 #endif
192 #if ENABLE(WEB_AUDIO)
193     else if (event->isAudioProcessingEvent())
194         wrapper = CREATE_DOM_OBJECT_WRAPPER(exec, globalObject, AudioProcessingEvent, event);
195     else if (event->isOfflineAudioCompletionEvent())
196         wrapper = CREATE_DOM_OBJECT_WRAPPER(exec, globalObject, OfflineAudioCompletionEvent, event);
197 #endif
198 #if ENABLE(INPUT_SPEECH)
199     else if (event->isSpeechInputEvent())
200         wrapper = CREATE_DOM_OBJECT_WRAPPER(exec, globalObject, SpeechInputEvent, event);
201 #endif
202     else
203         wrapper = CREATE_DOM_OBJECT_WRAPPER(exec, globalObject, Event, event);
204 
205     return wrapper;
206 }
207 
208 } // namespace WebCore
209