summaryrefslogtreecommitdiffstats
path: root/WebCore/bindings/cpp/WebDOMEventTarget.cpp
blob: 2eaef006c8684f9f85740d1fe4957d62ce0ab30e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
/*
 * Copyright (C) Research In Motion Limited 2010. All rights reserved.
 * Copyright (C) 2008 Apple Inc. All Rights Reserved.
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Library General Public
 * License as published by the Free Software Foundation; either
 * version 2 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Library General Public License for more details.
 *
 * You should have received a copy of the GNU Library General Public License
 * along with this library; see the file COPYING.LIB.  If not, write to
 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
 * Boston, MA 02110-1301, USA.
 */

#include "config.h"
#include "WebDOMEventTarget.h"

#include "DOMApplicationCache.h"
#include "DedicatedWorkerContext.h"
#include "EventSource.h"
#include "MessagePort.h"
#include "Node.h"
#include "Notification.h"
#include "SharedWorker.h"
#include "SharedWorkerContext.h"
#include "ThreadCheck.h"
#include "WebDOMDOMApplicationCache.h"
#include "WebDOMDedicatedWorkerContext.h"
#include "WebDOMEventSource.h"
#include "WebDOMMessagePort.h"
#include "WebDOMNode.h"
#include "WebDOMNotification.h"
#include "WebDOMSharedWorker.h"
#include "WebDOMSharedWorkerContext.h"
#include "WebDOMWebSocket.h"
#include "WebDOMWorker.h"
#include "WebDOMXMLHttpRequest.h"
#include "WebDOMXMLHttpRequestUpload.h"
#include "WebExceptionHandler.h"
#include "WebSocket.h"
#include "Worker.h"
#include "XMLHttpRequest.h"
#include "XMLHttpRequestUpload.h"

#include <wtf/RefPtr.h>

struct WebDOMEventTarget::WebDOMEventTargetPrivate {
    WebDOMEventTargetPrivate(WebCore::EventTarget* object = 0)
        : impl(object)
    {
    }

    RefPtr<WebCore::EventTarget> impl;
};

WebDOMEventTarget::WebDOMEventTarget()
    : WebDOMObject()
    , m_impl(0)
{
}

WebDOMEventTarget::WebDOMEventTarget(WebCore::EventTarget* impl)
    : WebDOMObject()
    , m_impl(new WebDOMEventTargetPrivate(impl))
{
}

WebDOMEventTarget::WebDOMEventTarget(const WebDOMEventTarget& copy)
    : WebDOMObject()
{
    m_impl = copy.impl() ? new WebDOMEventTargetPrivate(copy.impl()) : 0;
}

WebDOMEventTarget::~WebDOMEventTarget()
{
    delete m_impl;
    m_impl = 0;
}

WebCore::EventTarget* WebDOMEventTarget::impl() const
{
    return m_impl ? m_impl->impl.get() : 0;
}

WebCore::EventTarget* toWebCore(const WebDOMEventTarget& wrapper)
{
    return wrapper.impl();
}

WebDOMEventTarget toWebKit(WebCore::EventTarget* value)
{
#if ENABLE(EVENTSOURCE)
    if (WebCore::EventSource* eventSource = value->toEventSource())
        return toWebKit(eventSource);
#endif

#if ENABLE(SVG) && 0
    // FIXME: Enable once SVG bindings are generated.
    // SVGElementInstance supports both toSVGElementInstance and toNode since so much mouse handling code depends on toNode returning a valid node.
    if (WebCore::SVGElementInstance* instance = value->toSVGElementInstance())
        return toWebKit(instance);
#endif

    if (WebCore::Node* node = value->toNode())
        return toWebKit(node);

    if (WebCore::XMLHttpRequest* xhr = value->toXMLHttpRequest())
        return toWebKit(xhr);

    if (WebCore::XMLHttpRequestUpload* upload = value->toXMLHttpRequestUpload())
        return toWebKit(upload);

#if ENABLE(OFFLINE_WEB_APPLICATIONS)
    if (WebCore::DOMApplicationCache* cache = value->toDOMApplicationCache())
        return toWebKit(cache);
#endif

    if (WebCore::MessagePort* messagePort = value->toMessagePort())
        return toWebKit(messagePort);

#if ENABLE(WORKERS)
    if (WebCore::Worker* worker = value->toWorker())
        return toWebKit(worker);

    if (WebCore::DedicatedWorkerContext* workerContext = value->toDedicatedWorkerContext())
        return toWebKit(workerContext);
#endif

#if ENABLE(SHARED_WORKERS)
    if (WebCore::SharedWorker* sharedWorker = value->toSharedWorker())
        return toWebKit(sharedWorker);

    if (WebCore::SharedWorkerContext* workerContext = value->toSharedWorkerContext())
        return toWebKit(workerContext);
#endif

#if ENABLE(NOTIFICATIONS)
    if (WebCore::Notification* notification = value->toNotification())
        return toWebKit(notification);
#endif

#if ENABLE(WEB_SOCKETS)
    if (WebCore::WebSocket* webSocket = value->toWebSocket())
        return toWebKit(webSocket);
#endif

    ASSERT_NOT_REACHED();
    return WebDOMEventTarget();
}