tizen beta release
[framework/web/webkit-efl.git] / Source / WebKit / chromium / src / WebDOMEvent.cpp
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 "WebDOMEvent.h"
33
34 #include "Event.h"
35 #include "EventNames.h"
36 #include "Node.h"
37 #include <wtf/PassRefPtr.h>
38
39 using WebCore::eventNames;
40
41 namespace WebKit {
42
43 class WebDOMEventPrivate : public WebCore::Event {
44 };
45
46 void WebDOMEvent::reset()
47 {
48     assign(0);
49 }
50
51 void WebDOMEvent::assign(const WebDOMEvent& other)
52 {
53     WebDOMEventPrivate* p = const_cast<WebDOMEventPrivate*>(other.m_private);
54     if (p)
55         p->ref();
56     assign(p);
57 }
58
59 void WebDOMEvent::assign(WebDOMEventPrivate* p)
60 {
61     // p is already ref'd for us by the caller
62     if (m_private)
63         m_private->deref();
64     m_private = p;
65 }
66
67 WebDOMEvent::WebDOMEvent(const WTF::PassRefPtr<WebCore::Event>& event)
68     : m_private(static_cast<WebDOMEventPrivate*>(event.leakRef()))
69 {
70 }
71
72 WebDOMEvent::operator WTF::PassRefPtr<WebCore::Event>() const
73 {
74     return static_cast<WebCore::Event*>(m_private);
75 }
76
77 WebString WebDOMEvent::type() const
78 {
79     ASSERT(m_private);
80     return m_private->type();
81 }
82
83 WebNode WebDOMEvent::target() const
84 {
85     ASSERT(m_private);
86     return WebNode(m_private->target()->toNode());
87 }
88
89 WebNode WebDOMEvent::currentTarget() const
90 {
91     ASSERT(m_private);
92     return WebNode(m_private->currentTarget()->toNode());
93 }
94
95 WebDOMEvent::PhaseType WebDOMEvent::eventPhase() const
96 {
97     ASSERT(m_private);
98     return static_cast<WebDOMEvent::PhaseType>(m_private->eventPhase());
99 }
100
101 bool WebDOMEvent::bubbles() const
102 {
103     ASSERT(m_private);
104     return m_private->bubbles();
105 }
106
107 bool WebDOMEvent::cancelable() const
108 {
109     ASSERT(m_private);
110     return m_private->cancelable();
111 }
112
113 bool WebDOMEvent::isUIEvent() const
114 {
115     ASSERT(m_private);
116     return m_private->isUIEvent();
117 }
118
119 bool WebDOMEvent::isMouseEvent() const
120 {
121     ASSERT(m_private);
122     return m_private->isMouseEvent();
123 }
124
125 bool WebDOMEvent::isKeyboardEvent() const
126 {
127     ASSERT(m_private);
128     return m_private->isKeyboardEvent();
129 }
130
131 bool WebDOMEvent::isMutationEvent() const
132 {
133     ASSERT(m_private);
134     return m_private->hasInterface(WebCore::eventNames().interfaceForMutationEvent);
135 }
136
137 bool WebDOMEvent::isTextEvent() const
138 {
139     ASSERT(m_private);
140     return m_private->hasInterface(eventNames().interfaceForTextEvent);
141 }
142
143 bool WebDOMEvent::isCompositionEvent() const
144 {
145     ASSERT(m_private);
146     return m_private->hasInterface(eventNames().interfaceForCompositionEvent);
147 }
148
149 bool WebDOMEvent::isDragEvent() const
150 {
151     ASSERT(m_private);
152     return m_private->isDragEvent();
153 }
154
155 bool WebDOMEvent::isClipboardEvent() const
156 {
157     ASSERT(m_private);
158     return m_private->isClipboardEvent();
159 }
160
161 bool WebDOMEvent::isMessageEvent() const
162 {
163     ASSERT(m_private);
164     return m_private->hasInterface(eventNames().interfaceForMessageEvent);
165 }
166
167 bool WebDOMEvent::isWheelEvent() const
168 {
169     ASSERT(m_private);
170     return m_private->hasInterface(eventNames().interfaceForWheelEvent);
171 }
172
173 bool WebDOMEvent::isBeforeTextInsertedEvent() const
174 {
175     ASSERT(m_private);
176     return m_private->isBeforeTextInsertedEvent();
177 }
178
179 bool WebDOMEvent::isOverflowEvent() const
180 {
181     ASSERT(m_private);
182     return m_private->hasInterface(eventNames().interfaceForOverflowEvent);
183 }
184
185 bool WebDOMEvent::isPageTransitionEvent() const
186 {
187     ASSERT(m_private);
188     return m_private->hasInterface(eventNames().interfaceForPageTransitionEvent);
189 }
190
191 bool WebDOMEvent::isPopStateEvent() const
192 {
193     ASSERT(m_private);
194     return m_private->hasInterface(eventNames().interfaceForPopStateEvent);
195 }
196
197 bool WebDOMEvent::isProgressEvent() const
198 {
199     ASSERT(m_private);
200     return m_private->hasInterface(eventNames().interfaceForProgressEvent);
201 }
202
203 bool WebDOMEvent::isXMLHttpRequestProgressEvent() const
204 {
205     ASSERT(m_private);
206     return m_private->hasInterface(eventNames().interfaceForXMLHttpRequestProgressEvent);
207 }
208
209 bool WebDOMEvent::isWebKitAnimationEvent() const
210 {
211     ASSERT(m_private);
212     return m_private->hasInterface(eventNames().interfaceForWebKitAnimationEvent);
213 }
214
215 bool WebDOMEvent::isWebKitTransitionEvent() const
216 {
217     ASSERT(m_private);
218     return m_private->hasInterface(eventNames().interfaceForWebKitTransitionEvent);
219 }
220
221 bool WebDOMEvent::isBeforeLoadEvent() const
222 {
223     ASSERT(m_private);
224     return m_private->hasInterface(eventNames().interfaceForBeforeLoadEvent);
225 }
226
227 } // namespace WebKit