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 "V8CompositionEvent.h"
42#include "V8CustomEvent.h"
43#include "V8DeviceMotionEvent.h"
44#include "V8DeviceOrientationEvent.h"
45#include "V8ErrorEvent.h"
46#include "V8HashChangeEvent.h"
47#include "V8IDBVersionChangeEvent.h"
48#include "V8KeyboardEvent.h"
49#include "V8MessageEvent.h"
50#include "V8MouseEvent.h"
51#include "V8MutationEvent.h"
52#include "V8OverflowEvent.h"
53#include "V8PageTransitionEvent.h"
54#include "V8PopStateEvent.h"
55#include "V8ProgressEvent.h"
56#include "V8Proxy.h"
57#include "V8SpeechInputEvent.h"
58#include "V8StorageEvent.h"
59#include "V8TextEvent.h"
60#include "V8TouchEvent.h"
61#include "V8UIEvent.h"
62#include "V8WebKitAnimationEvent.h"
63#include "V8WebKitTransitionEvent.h"
64#include "V8WheelEvent.h"
65#include "V8XMLHttpRequestProgressEvent.h"
66
67#if ENABLE(SVG)
68#include "V8SVGZoomEvent.h"
69#endif
70
71#if ENABLE(WEB_AUDIO)
72#include "V8AudioProcessingEvent.h"
73#include "V8OfflineAudioCompletionEvent.h"
74#endif
75
76namespace WebCore {
77
78void V8Event::valueAccessorSetter(v8::Local<v8::String> name, v8::Local<v8::Value> value, const v8::AccessorInfo& info)
79{
80    Event* event = V8Event::toNative(info.Holder());
81    event->setDefaultPrevented(!value->BooleanValue());
82}
83
84v8::Handle<v8::Value> V8Event::dataTransferAccessorGetter(v8::Local<v8::String> name, const v8::AccessorInfo& info)
85{
86    Event* event = V8Event::toNative(info.Holder());
87
88    if (event->isDragEvent())
89        return toV8(static_cast<MouseEvent*>(event)->clipboard());
90
91    return v8::Undefined();
92}
93
94v8::Handle<v8::Value> V8Event::clipboardDataAccessorGetter(v8::Local<v8::String> name, const v8::AccessorInfo& info)
95{
96    Event* event = V8Event::toNative(info.Holder());
97
98    if (event->isClipboardEvent())
99        return toV8(static_cast<ClipboardEvent*>(event)->clipboard());
100
101    return v8::Undefined();
102}
103
104v8::Handle<v8::Value> toV8(Event* impl)
105{
106    if (!impl)
107        return v8::Null();
108    if (impl->isUIEvent()) {
109        if (impl->isKeyboardEvent())
110            return toV8(static_cast<KeyboardEvent*>(impl));
111        if (impl->isTextEvent())
112            return toV8(static_cast<TextEvent*>(impl));
113        if (impl->isMouseEvent())
114            return toV8(static_cast<MouseEvent*>(impl));
115        if (impl->isWheelEvent())
116            return toV8(static_cast<WheelEvent*>(impl));
117#if ENABLE(SVG)
118        if (impl->isSVGZoomEvent())
119            return toV8(static_cast<SVGZoomEvent*>(impl));
120#endif
121        if (impl->isCompositionEvent())
122            return toV8(static_cast<CompositionEvent*>(impl));
123#if ENABLE(TOUCH_EVENTS)
124        if (impl->isTouchEvent())
125            return toV8(static_cast<TouchEvent*>(impl));
126#endif
127        return toV8(static_cast<UIEvent*>(impl));
128    }
129    if (impl->isHashChangeEvent())
130        return toV8(static_cast<HashChangeEvent*>(impl));
131    if (impl->isMutationEvent())
132        return toV8(static_cast<MutationEvent*>(impl));
133    if (impl->isOverflowEvent())
134        return toV8(static_cast<OverflowEvent*>(impl));
135    if (impl->isMessageEvent())
136        return toV8(static_cast<MessageEvent*>(impl));
137    if (impl->isPageTransitionEvent())
138        return toV8(static_cast<PageTransitionEvent*>(impl));
139    if (impl->isPopStateEvent())
140        return toV8(static_cast<PopStateEvent*>(impl));
141    if (impl->isProgressEvent()) {
142        if (impl->isXMLHttpRequestProgressEvent())
143            return toV8(static_cast<XMLHttpRequestProgressEvent*>(impl));
144        return toV8(static_cast<ProgressEvent*>(impl));
145    }
146    if (impl->isWebKitAnimationEvent())
147        return toV8(static_cast<WebKitAnimationEvent*>(impl));
148    if (impl->isWebKitTransitionEvent())
149        return toV8(static_cast<WebKitTransitionEvent*>(impl));
150#if ENABLE(WORKERS)
151    if (impl->isErrorEvent())
152        return toV8(static_cast<ErrorEvent*>(impl));
153#endif
154#if ENABLE(DOM_STORAGE)
155    if (impl->isStorageEvent())
156        return toV8(static_cast<StorageEvent*>(impl));
157#endif
158#if ENABLE(INDEXED_DATABASE)
159    if (impl->isIDBVersionChangeEvent())
160        return toV8(static_cast<IDBVersionChangeEvent*>(impl));
161#endif
162    if (impl->isBeforeLoadEvent())
163        return toV8(static_cast<BeforeLoadEvent*>(impl));
164#if ENABLE(DEVICE_ORIENTATION)
165    if (impl->isDeviceMotionEvent())
166        return toV8(static_cast<DeviceMotionEvent*>(impl));
167    if (impl->isDeviceOrientationEvent())
168        return toV8(static_cast<DeviceOrientationEvent*>(impl));
169#endif
170#if ENABLE(WEB_AUDIO)
171    if (impl->isAudioProcessingEvent())
172        return toV8(static_cast<AudioProcessingEvent*>(impl));
173    if (impl->isOfflineAudioCompletionEvent())
174        return toV8(static_cast<OfflineAudioCompletionEvent*>(impl));
175#endif
176#if ENABLE(INPUT_SPEECH)
177    if (impl->isSpeechInputEvent())
178        return toV8(static_cast<SpeechInputEvent*>(impl));
179#endif
180    if (impl->isCustomEvent())
181        return toV8(static_cast<CustomEvent*>(impl));
182    return V8Event::wrap(impl);
183}
184} // namespace WebCore
185