]> git.saurik.com Git - iphone-api.git/blob - WebCore/EventTarget.h
Adding the WebCore headers (for Cydget).
[iphone-api.git] / WebCore / EventTarget.h
1 /*
2 * Copyright (C) 1999 Lars Knoll (knoll@kde.org)
3 * (C) 1999 Antti Koivisto (koivisto@kde.org)
4 * (C) 2001 Dirk Mueller (mueller@kde.org)
5 * Copyright (C) 2004, 2005, 2006, 2007, 2008 Apple Inc. All rights reserved.
6 * Copyright (C) 2006 Alexey Proskuryakov (ap@webkit.org)
7 * (C) 2007, 2008 Nikolas Zimmermann <zimmermann@kde.org>
8 *
9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted provided that the following conditions
11 * are met:
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 * 2. Redistributions in binary form must reproduce the above copyright
15 * notice, this list of conditions and the following disclaimer in the
16 * documentation and/or other materials provided with the distribution.
17 *
18 * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY
19 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
21 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR
22 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
23 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
24 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
25 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
26 * 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
32 #ifndef EventTarget_h
33 #define EventTarget_h
34
35 #include <wtf/Forward.h>
36
37 namespace WebCore {
38
39 class AtomicString;
40 class DOMApplicationCache;
41 class Event;
42 class EventListener;
43 class EventTargetNode;
44 class MessagePort;
45 class ScriptExecutionContext;
46 class SVGElementInstance;
47 class Worker;
48 class WorkerContext;
49 class XMLHttpRequest;
50 class XMLHttpRequestUpload;
51
52 typedef int ExceptionCode;
53
54 class EventTarget {
55 public:
56 virtual MessagePort* toMessagePort();
57 virtual EventTargetNode* toNode();
58 virtual XMLHttpRequest* toXMLHttpRequest();
59 virtual XMLHttpRequestUpload* toXMLHttpRequestUpload();
60 #if ENABLE(OFFLINE_WEB_APPLICATIONS)
61 virtual DOMApplicationCache* toDOMApplicationCache();
62 #endif
63 #if ENABLE(SVG)
64 virtual SVGElementInstance* toSVGElementInstance();
65 #endif
66 #if ENABLE(WORKERS)
67 virtual Worker* toWorker();
68 virtual WorkerContext* toWorkerContext();
69 #endif
70
71 virtual ScriptExecutionContext* scriptExecutionContext() const = 0;
72
73 virtual void addEventListener(const AtomicString& eventType, PassRefPtr<EventListener>, bool useCapture) = 0;
74 virtual void removeEventListener(const AtomicString& eventType, EventListener*, bool useCapture) = 0;
75 virtual bool dispatchEvent(PassRefPtr<Event>, ExceptionCode&) = 0;
76
77 void ref() { refEventTarget(); }
78 void deref() { derefEventTarget(); }
79
80 // Handlers to do/undo actions on the target node before an event is dispatched to it and after the event
81 // has been dispatched. The data pointer is handed back by the preDispatch and passed to postDispatch.
82 virtual void* preDispatchEventHandler(Event*) { return 0; }
83 virtual void postDispatchEventHandler(Event*, void* /*dataFromPreDispatch*/) { }
84
85 protected:
86 virtual ~EventTarget();
87
88 private:
89 virtual void refEventTarget() = 0;
90 virtual void derefEventTarget() = 0;
91 };
92
93 void forbidEventDispatch();
94 void allowEventDispatch();
95
96 #ifndef NDEBUG
97 bool eventDispatchForbidden();
98 #else
99 inline void forbidEventDispatch() { }
100 inline void allowEventDispatch() { }
101 #endif
102
103 }
104
105 #endif