1/*
2 * Copyright (C) 2007-2009 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 "Event.h"
37#include "V8BeforeLoadEvent.h"
38#include "V8Binding.h"
39#include "V8Clipboard.h"
40#include "V8CompositionEvent.h"
41#include "V8ErrorEvent.h"
42#include "V8KeyboardEvent.h"
43#include "V8MessageEvent.h"
44#include "V8MouseEvent.h"
45#include "V8MutationEvent.h"
46#include "V8OverflowEvent.h"
47#include "V8PageTransitionEvent.h"
48#include "V8PopStateEvent.h"
49#include "V8ProgressEvent.h"
50#include "V8Proxy.h"
51#include "V8SVGZoomEvent.h"
52#include "V8StorageEvent.h"
53#include "V8TextEvent.h"
54#include "V8TouchEvent.h"
55#include "V8UIEvent.h"
56#include "V8WebKitAnimationEvent.h"
57#include "V8WebKitTransitionEvent.h"
58#include "V8WheelEvent.h"
59#include "V8XMLHttpRequestProgressEvent.h"
60
61namespace WebCore {
62
63void V8Event::valueAccessorSetter(v8::Local<v8::String> name, v8::Local<v8::Value> value, const v8::AccessorInfo& info)
64{
65    Event* event = V8Event::toNative(info.Holder());
66    event->setDefaultPrevented(!value->BooleanValue());
67}
68
69v8::Handle<v8::Value> V8Event::dataTransferAccessorGetter(v8::Local<v8::String> name, const v8::AccessorInfo& info)
70{
71    Event* event = V8Event::toNative(info.Holder());
72
73    if (event->isDragEvent())
74        return toV8(static_cast<MouseEvent*>(event)->clipboard());
75
76    return v8::Undefined();
77}
78
79v8::Handle<v8::Value> V8Event::clipboardDataAccessorGetter(v8::Local<v8::String> name, const v8::AccessorInfo& info)
80{
81    Event* event = V8Event::toNative(info.Holder());
82
83    if (event->isClipboardEvent())
84        return toV8(static_cast<ClipboardEvent*>(event)->clipboard());
85
86    return v8::Undefined();
87}
88
89v8::Handle<v8::Value> toV8(Event* impl)
90{
91    if (!impl)
92        return v8::Null();
93    if (impl->isUIEvent()) {
94        if (impl->isKeyboardEvent())
95            return toV8(static_cast<KeyboardEvent*>(impl));
96        if (impl->isTextEvent())
97            return toV8(static_cast<TextEvent*>(impl));
98        if (impl->isMouseEvent())
99            return toV8(static_cast<MouseEvent*>(impl));
100        if (impl->isWheelEvent())
101            return toV8(static_cast<WheelEvent*>(impl));
102#if ENABLE(SVG)
103        if (impl->isSVGZoomEvent())
104            return toV8(static_cast<SVGZoomEvent*>(impl));
105#endif
106        if (impl->isCompositionEvent())
107            return toV8(static_cast<CompositionEvent*>(impl));
108#if ENABLE(TOUCH_EVENTS)
109        if (impl->isTouchEvent())
110            return toV8(static_cast<TouchEvent*>(impl));
111#endif
112        return toV8(static_cast<UIEvent*>(impl));
113    }
114    if (impl->isMutationEvent())
115        return toV8(static_cast<MutationEvent*>(impl));
116    if (impl->isOverflowEvent())
117        return toV8(static_cast<OverflowEvent*>(impl));
118    if (impl->isMessageEvent())
119        return toV8(static_cast<MessageEvent*>(impl));
120    if (impl->isPageTransitionEvent())
121        return toV8(static_cast<PageTransitionEvent*>(impl));
122    if (impl->isPopStateEvent())
123        return toV8(static_cast<PopStateEvent*>(impl));
124    if (impl->isProgressEvent()) {
125        if (impl->isXMLHttpRequestProgressEvent())
126            return toV8(static_cast<XMLHttpRequestProgressEvent*>(impl));
127        return toV8(static_cast<ProgressEvent*>(impl));
128    }
129    if (impl->isWebKitAnimationEvent())
130        return toV8(static_cast<WebKitAnimationEvent*>(impl));
131    if (impl->isWebKitTransitionEvent())
132        return toV8(static_cast<WebKitTransitionEvent*>(impl));
133#if ENABLE(WORKERS)
134    if (impl->isErrorEvent())
135        return toV8(static_cast<ErrorEvent*>(impl));
136#endif
137#if ENABLE(DOM_STORAGE)
138    if (impl->isStorageEvent())
139        return toV8(static_cast<StorageEvent*>(impl));
140#endif
141    if (impl->isBeforeLoadEvent())
142        return toV8(static_cast<BeforeLoadEvent*>(impl));
143    return V8Event::wrap(impl);
144}
145} // namespace WebCore
146