• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 AbstractWorker;
40     class AtomicString;
41     class DedicatedWorkerContext;
42     class DOMApplicationCache;
43     class DOMWindow;
44     class Event;
45     class EventListener;
46     class MessagePort;
47     class Node;
48     class SVGElementInstance;
49     class ScriptExecutionContext;
50     class SharedWorker;
51     class SharedWorkerContext;
52     class Worker;
53     class XMLHttpRequest;
54     class XMLHttpRequestUpload;
55 
56     typedef int ExceptionCode;
57 
58     class EventTarget {
59     public:
60         virtual MessagePort* toMessagePort();
61         virtual Node* toNode();
62         virtual DOMWindow* toDOMWindow();
63         virtual XMLHttpRequest* toXMLHttpRequest();
64         virtual XMLHttpRequestUpload* toXMLHttpRequestUpload();
65 #if ENABLE(OFFLINE_WEB_APPLICATIONS)
66         virtual DOMApplicationCache* toDOMApplicationCache();
67 #endif
68 #if ENABLE(SVG)
69         virtual SVGElementInstance* toSVGElementInstance();
70 #endif
71 #if ENABLE(WORKERS)
72         virtual Worker* toWorker();
73         virtual DedicatedWorkerContext* toDedicatedWorkerContext();
74 #endif
75 
76 #if ENABLE(SHARED_WORKERS)
77         virtual SharedWorker* toSharedWorker();
78         virtual SharedWorkerContext* toSharedWorkerContext();
79 #endif
80 
81         virtual ScriptExecutionContext* scriptExecutionContext() const = 0;
82 
83         virtual void addEventListener(const AtomicString& eventType, PassRefPtr<EventListener>, bool useCapture) = 0;
84         virtual void removeEventListener(const AtomicString& eventType, EventListener*, bool useCapture) = 0;
85         virtual bool dispatchEvent(PassRefPtr<Event>, ExceptionCode&) = 0;
86 
ref()87         void ref() { refEventTarget(); }
deref()88         void deref() { derefEventTarget(); }
89 
90         // Handlers to do/undo actions on the target node before an event is dispatched to it and after the event
91         // has been dispatched.  The data pointer is handed back by the preDispatch and passed to postDispatch.
preDispatchEventHandler(Event *)92         virtual void* preDispatchEventHandler(Event*) { return 0; }
postDispatchEventHandler(Event *,void *)93         virtual void postDispatchEventHandler(Event*, void* /*dataFromPreDispatch*/) { }
94 
95     protected:
96         virtual ~EventTarget();
97 
98     private:
99         virtual void refEventTarget() = 0;
100         virtual void derefEventTarget() = 0;
101     };
102 
103     void forbidEventDispatch();
104     void allowEventDispatch();
105 
106 #ifndef NDEBUG
107     bool eventDispatchForbidden();
108 #else
forbidEventDispatch()109     inline void forbidEventDispatch() { }
allowEventDispatch()110     inline void allowEventDispatch() { }
111 #endif
112 
113 }
114 
115 #endif
116