initial import
[vuplus_webkit] / Source / WebCore / bindings / v8 / custom / V8EventCustom.cpp
1 /*
2  * Copyright (C) 2010 Google 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 are
6  * met:
7  *
8  *     * Redistributions of source code must retain the above copyright
9  * notice, this list of conditions and the following disclaimer.
10  *     * Redistributions in binary form must reproduce the above
11  * copyright notice, this list of conditions and the following disclaimer
12  * in the documentation and/or other materials provided with the
13  * distribution.
14  *     * Neither the name of Google Inc. nor the names of its
15  * contributors may be used to endorse or promote products derived from
16  * this software without specific prior written permission.
17  *
18  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
21  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
22  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
24  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29  */
30
31 #include "config.h"
32 #include "V8Event.h"
33
34 #include "Clipboard.h"
35 #include "ClipboardEvent.h"
36 #include "CustomEvent.h"
37 #include "Event.h"
38 #include "V8BeforeLoadEvent.h"
39 #include "V8Binding.h"
40 #include "V8Clipboard.h"
41 #include "V8CloseEvent.h"
42 #include "V8CompositionEvent.h"
43 #include "V8CustomEvent.h"
44 #include "V8DeviceMotionEvent.h"
45 #include "V8DeviceOrientationEvent.h"
46 #include "V8ErrorEvent.h"
47 #include "V8HashChangeEvent.h"
48 #include "V8IDBVersionChangeEvent.h"
49 #include "V8KeyboardEvent.h"
50 #include "V8MessageEvent.h"
51 #include "V8MouseEvent.h"
52 #include "V8MutationEvent.h"
53 #include "V8OverflowEvent.h"
54 #include "V8PageTransitionEvent.h"
55 #include "V8PopStateEvent.h"
56 #include "V8ProgressEvent.h"
57 #include "V8Proxy.h"
58 #include "V8SpeechInputEvent.h"
59 #include "V8StorageEvent.h"
60 #include "V8TextEvent.h"
61 #include "V8TouchEvent.h"
62 #include "V8UIEvent.h"
63 #include "V8WebKitAnimationEvent.h"
64 #include "V8WebKitTransitionEvent.h"
65 #include "V8WheelEvent.h"
66 #include "V8XMLHttpRequestProgressEvent.h"
67
68 #if ENABLE(SVG)
69 #include "V8SVGZoomEvent.h"
70 #endif
71
72 #if ENABLE(WEB_AUDIO)
73 #include "V8AudioProcessingEvent.h"
74 #include "V8OfflineAudioCompletionEvent.h"
75 #endif
76
77 #if ENABLE(MEDIA_STREAM)
78 #include "V8MediaStreamEvent.h"
79 #endif
80
81 namespace WebCore {
82
83 void V8Event::valueAccessorSetter(v8::Local<v8::String> name, v8::Local<v8::Value> value, const v8::AccessorInfo& info)
84 {
85     Event* event = V8Event::toNative(info.Holder());
86     event->setDefaultPrevented(!value->BooleanValue());
87 }
88
89 v8::Handle<v8::Value> V8Event::dataTransferAccessorGetter(v8::Local<v8::String> name, const v8::AccessorInfo& info)
90 {
91     Event* event = V8Event::toNative(info.Holder());
92
93     if (event->isDragEvent())
94         return toV8(static_cast<MouseEvent*>(event)->clipboard());
95
96     return v8::Undefined();
97 }
98
99 v8::Handle<v8::Value> V8Event::clipboardDataAccessorGetter(v8::Local<v8::String> name, const v8::AccessorInfo& info)
100 {
101     Event* event = V8Event::toNative(info.Holder());
102
103     if (event->isClipboardEvent())
104         return toV8(static_cast<ClipboardEvent*>(event)->clipboard());
105
106     return v8::Undefined();
107 }
108
109 v8::Handle<v8::Value> toV8(Event* impl)
110 {
111     if (!impl)
112         return v8::Null();
113     if (impl->isUIEvent()) {
114         if (impl->isKeyboardEvent())
115             return toV8(static_cast<KeyboardEvent*>(impl));
116         if (impl->isTextEvent())
117             return toV8(static_cast<TextEvent*>(impl));
118         if (impl->isMouseEvent())
119             return toV8(static_cast<MouseEvent*>(impl));
120         if (impl->isWheelEvent())
121             return toV8(static_cast<WheelEvent*>(impl));
122 #if ENABLE(SVG)
123         if (impl->isSVGZoomEvent())
124             return toV8(static_cast<SVGZoomEvent*>(impl));
125 #endif
126         if (impl->isCompositionEvent())
127             return toV8(static_cast<CompositionEvent*>(impl));
128 #if ENABLE(TOUCH_EVENTS)
129         if (impl->isTouchEvent())
130             return toV8(static_cast<TouchEvent*>(impl));
131 #endif
132         return toV8(static_cast<UIEvent*>(impl));
133     }
134     if (impl->isHashChangeEvent())
135         return toV8(static_cast<HashChangeEvent*>(impl));
136     if (impl->isMutationEvent())
137         return toV8(static_cast<MutationEvent*>(impl));
138     if (impl->isOverflowEvent())
139         return toV8(static_cast<OverflowEvent*>(impl));
140     if (impl->isMessageEvent())
141         return toV8(static_cast<MessageEvent*>(impl));
142     if (impl->isPageTransitionEvent())
143         return toV8(static_cast<PageTransitionEvent*>(impl));
144     if (impl->isPopStateEvent())
145         return toV8(static_cast<PopStateEvent*>(impl));
146     if (impl->isProgressEvent()) {
147         if (impl->isXMLHttpRequestProgressEvent())
148             return toV8(static_cast<XMLHttpRequestProgressEvent*>(impl));
149         return toV8(static_cast<ProgressEvent*>(impl));
150     }
151     if (impl->isWebKitAnimationEvent())
152         return toV8(static_cast<WebKitAnimationEvent*>(impl));
153     if (impl->isWebKitTransitionEvent())
154         return toV8(static_cast<WebKitTransitionEvent*>(impl));
155 #if ENABLE(WORKERS)
156     if (impl->isErrorEvent())
157         return toV8(static_cast<ErrorEvent*>(impl));
158 #endif
159 #if ENABLE(DOM_STORAGE)
160     if (impl->isStorageEvent())
161         return toV8(static_cast<StorageEvent*>(impl));
162 #endif
163 #if ENABLE(INDEXED_DATABASE)
164     if (impl->isIDBVersionChangeEvent())
165         return toV8(static_cast<IDBVersionChangeEvent*>(impl));
166 #endif
167     if (impl->isBeforeLoadEvent())
168         return toV8(static_cast<BeforeLoadEvent*>(impl));
169 #if ENABLE(DEVICE_ORIENTATION)
170     if (impl->isDeviceMotionEvent())
171         return toV8(static_cast<DeviceMotionEvent*>(impl));
172     if (impl->isDeviceOrientationEvent())
173         return toV8(static_cast<DeviceOrientationEvent*>(impl));
174 #endif
175 #if ENABLE(WEB_AUDIO)
176     if (impl->isAudioProcessingEvent())
177         return toV8(static_cast<AudioProcessingEvent*>(impl));
178     if (impl->isOfflineAudioCompletionEvent())
179         return toV8(static_cast<OfflineAudioCompletionEvent*>(impl));
180 #endif
181 #if ENABLE(INPUT_SPEECH)
182     if (impl->isSpeechInputEvent())
183         return toV8(static_cast<SpeechInputEvent*>(impl));
184 #endif
185     if (impl->isCustomEvent())
186         return toV8(static_cast<CustomEvent*>(impl));
187 #if ENABLE(WEB_SOCKETS)
188     if (impl->isCloseEvent())
189         return toV8(static_cast<CloseEvent*>(impl));
190 #endif
191 #if ENABLE(MEDIA_STREAM)
192     if (impl->isMediaStreamEvent())
193         return toV8(static_cast<MediaStreamEvent*>(impl));
194 #endif
195     return V8Event::wrap(impl);
196 }
197 } // namespace WebCore