1/*
2 * This file is part of the WebKit open source project.
3 *
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Library General Public
6 * License as published by the Free Software Foundation; either
7 * version 2 of the License, or (at your option) any later version.
8 *
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Library General Public License for more details.
13 *
14 * You should have received a copy of the GNU Library General Public License
15 * along with this library; see the file COPYING.LIB. If not, write to
16 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17 * Boston, MA 02110-1301, USA.
18 */
19
20#include "config.h"
21#include "WebKitDOMMouseEvent.h"
22
23#include <WebCore/CSSImportRule.h>
24#include "DOMObjectCache.h"
25#include <WebCore/Document.h>
26#include <WebCore/ExceptionCode.h>
27#include <WebCore/JSExecState.h>
28#include "WebKitDOMDOMWindowPrivate.h"
29#include "WebKitDOMEventPrivate.h"
30#include "WebKitDOMEventTargetPrivate.h"
31#include "WebKitDOMMouseEventPrivate.h"
32#include "WebKitDOMNodePrivate.h"
33#include "WebKitDOMPrivate.h"
34#include "ConvertToUTF8String.h"
35#include <wtf/GetPtr.h>
36#include <wtf/RefPtr.h>
37
38G_GNUC_BEGIN_IGNORE_DEPRECATIONS;
39
40namespace WebKit {
41
42WebKitDOMMouseEvent* kit(WebCore::MouseEvent* obj)
43{
44 return WEBKIT_DOM_MOUSE_EVENT(kit(static_cast<WebCore::Event*>(obj)));
45}
46
47WebCore::MouseEvent* core(WebKitDOMMouseEvent* request)
48{
49 return request ? static_cast<WebCore::MouseEvent*>(WEBKIT_DOM_OBJECT(request)->coreObject) : 0;
50}
51
52WebKitDOMMouseEvent* wrapMouseEvent(WebCore::MouseEvent* coreObject)
53{
54 ASSERT(coreObject);
55 return WEBKIT_DOM_MOUSE_EVENT(g_object_new(WEBKIT_DOM_TYPE_MOUSE_EVENT, "core-object", coreObject, nullptr));
56}
57
58} // namespace WebKit
59
60G_DEFINE_TYPE(WebKitDOMMouseEvent, webkit_dom_mouse_event, WEBKIT_DOM_TYPE_UI_EVENT)
61
62enum {
63 DOM_MOUSE_EVENT_PROP_0,
64 DOM_MOUSE_EVENT_PROP_SCREEN_X,
65 DOM_MOUSE_EVENT_PROP_SCREEN_Y,
66 DOM_MOUSE_EVENT_PROP_CLIENT_X,
67 DOM_MOUSE_EVENT_PROP_CLIENT_Y,
68 DOM_MOUSE_EVENT_PROP_CTRL_KEY,
69 DOM_MOUSE_EVENT_PROP_SHIFT_KEY,
70 DOM_MOUSE_EVENT_PROP_ALT_KEY,
71 DOM_MOUSE_EVENT_PROP_META_KEY,
72 DOM_MOUSE_EVENT_PROP_BUTTON,
73 DOM_MOUSE_EVENT_PROP_RELATED_TARGET,
74 DOM_MOUSE_EVENT_PROP_OFFSET_X,
75 DOM_MOUSE_EVENT_PROP_OFFSET_Y,
76 DOM_MOUSE_EVENT_PROP_X,
77 DOM_MOUSE_EVENT_PROP_Y,
78 DOM_MOUSE_EVENT_PROP_FROM_ELEMENT,
79 DOM_MOUSE_EVENT_PROP_TO_ELEMENT,
80};
81
82static void webkit_dom_mouse_event_get_property(GObject* object, guint propertyId, GValue* value, GParamSpec* pspec)
83{
84 WebKitDOMMouseEvent* self = WEBKIT_DOM_MOUSE_EVENT(object);
85
86 switch (propertyId) {
87 case DOM_MOUSE_EVENT_PROP_SCREEN_X:
88 g_value_set_long(value, webkit_dom_mouse_event_get_screen_x(self));
89 break;
90 case DOM_MOUSE_EVENT_PROP_SCREEN_Y:
91 g_value_set_long(value, webkit_dom_mouse_event_get_screen_y(self));
92 break;
93 case DOM_MOUSE_EVENT_PROP_CLIENT_X:
94 g_value_set_long(value, webkit_dom_mouse_event_get_client_x(self));
95 break;
96 case DOM_MOUSE_EVENT_PROP_CLIENT_Y:
97 g_value_set_long(value, webkit_dom_mouse_event_get_client_y(self));
98 break;
99 case DOM_MOUSE_EVENT_PROP_CTRL_KEY:
100 g_value_set_boolean(value, webkit_dom_mouse_event_get_ctrl_key(self));
101 break;
102 case DOM_MOUSE_EVENT_PROP_SHIFT_KEY:
103 g_value_set_boolean(value, webkit_dom_mouse_event_get_shift_key(self));
104 break;
105 case DOM_MOUSE_EVENT_PROP_ALT_KEY:
106 g_value_set_boolean(value, webkit_dom_mouse_event_get_alt_key(self));
107 break;
108 case DOM_MOUSE_EVENT_PROP_META_KEY:
109 g_value_set_boolean(value, webkit_dom_mouse_event_get_meta_key(self));
110 break;
111 case DOM_MOUSE_EVENT_PROP_BUTTON:
112 g_value_set_uint(value, webkit_dom_mouse_event_get_button(self));
113 break;
114 case DOM_MOUSE_EVENT_PROP_RELATED_TARGET:
115 g_value_set_object(value, webkit_dom_mouse_event_get_related_target(self));
116 break;
117 case DOM_MOUSE_EVENT_PROP_OFFSET_X:
118 g_value_set_long(value, webkit_dom_mouse_event_get_offset_x(self));
119 break;
120 case DOM_MOUSE_EVENT_PROP_OFFSET_Y:
121 g_value_set_long(value, webkit_dom_mouse_event_get_offset_y(self));
122 break;
123 case DOM_MOUSE_EVENT_PROP_X:
124 g_value_set_long(value, webkit_dom_mouse_event_get_x(self));
125 break;
126 case DOM_MOUSE_EVENT_PROP_Y:
127 g_value_set_long(value, webkit_dom_mouse_event_get_y(self));
128 break;
129 case DOM_MOUSE_EVENT_PROP_FROM_ELEMENT:
130 g_value_set_object(value, webkit_dom_mouse_event_get_from_element(self));
131 break;
132 case DOM_MOUSE_EVENT_PROP_TO_ELEMENT:
133 g_value_set_object(value, webkit_dom_mouse_event_get_to_element(self));
134 break;
135 default:
136 G_OBJECT_WARN_INVALID_PROPERTY_ID(object, propertyId, pspec);
137 break;
138 }
139}
140
141static void webkit_dom_mouse_event_class_init(WebKitDOMMouseEventClass* requestClass)
142{
143 GObjectClass* gobjectClass = G_OBJECT_CLASS(requestClass);
144 gobjectClass->get_property = webkit_dom_mouse_event_get_property;
145
146 g_object_class_install_property(
147 gobjectClass,
148 DOM_MOUSE_EVENT_PROP_SCREEN_X,
149 g_param_spec_long(
150 "screen-x",
151 "MouseEvent:screen-x",
152 "read-only glong MouseEvent:screen-x",
153 G_MINLONG, G_MAXLONG, 0,
154 WEBKIT_PARAM_READABLE));
155
156 g_object_class_install_property(
157 gobjectClass,
158 DOM_MOUSE_EVENT_PROP_SCREEN_Y,
159 g_param_spec_long(
160 "screen-y",
161 "MouseEvent:screen-y",
162 "read-only glong MouseEvent:screen-y",
163 G_MINLONG, G_MAXLONG, 0,
164 WEBKIT_PARAM_READABLE));
165
166 g_object_class_install_property(
167 gobjectClass,
168 DOM_MOUSE_EVENT_PROP_CLIENT_X,
169 g_param_spec_long(
170 "client-x",
171 "MouseEvent:client-x",
172 "read-only glong MouseEvent:client-x",
173 G_MINLONG, G_MAXLONG, 0,
174 WEBKIT_PARAM_READABLE));
175
176 g_object_class_install_property(
177 gobjectClass,
178 DOM_MOUSE_EVENT_PROP_CLIENT_Y,
179 g_param_spec_long(
180 "client-y",
181 "MouseEvent:client-y",
182 "read-only glong MouseEvent:client-y",
183 G_MINLONG, G_MAXLONG, 0,
184 WEBKIT_PARAM_READABLE));
185
186 g_object_class_install_property(
187 gobjectClass,
188 DOM_MOUSE_EVENT_PROP_CTRL_KEY,
189 g_param_spec_boolean(
190 "ctrl-key",
191 "MouseEvent:ctrl-key",
192 "read-only gboolean MouseEvent:ctrl-key",
193 FALSE,
194 WEBKIT_PARAM_READABLE));
195
196 g_object_class_install_property(
197 gobjectClass,
198 DOM_MOUSE_EVENT_PROP_SHIFT_KEY,
199 g_param_spec_boolean(
200 "shift-key",
201 "MouseEvent:shift-key",
202 "read-only gboolean MouseEvent:shift-key",
203 FALSE,
204 WEBKIT_PARAM_READABLE));
205
206 g_object_class_install_property(
207 gobjectClass,
208 DOM_MOUSE_EVENT_PROP_ALT_KEY,
209 g_param_spec_boolean(
210 "alt-key",
211 "MouseEvent:alt-key",
212 "read-only gboolean MouseEvent:alt-key",
213 FALSE,
214 WEBKIT_PARAM_READABLE));
215
216 g_object_class_install_property(
217 gobjectClass,
218 DOM_MOUSE_EVENT_PROP_META_KEY,
219 g_param_spec_boolean(
220 "meta-key",
221 "MouseEvent:meta-key",
222 "read-only gboolean MouseEvent:meta-key",
223 FALSE,
224 WEBKIT_PARAM_READABLE));
225
226 g_object_class_install_property(
227 gobjectClass,
228 DOM_MOUSE_EVENT_PROP_BUTTON,
229 g_param_spec_uint(
230 "button",
231 "MouseEvent:button",
232 "read-only gushort MouseEvent:button",
233 0, G_MAXUINT, 0,
234 WEBKIT_PARAM_READABLE));
235
236 g_object_class_install_property(
237 gobjectClass,
238 DOM_MOUSE_EVENT_PROP_RELATED_TARGET,
239 g_param_spec_object(
240 "related-target",
241 "MouseEvent:related-target",
242 "read-only WebKitDOMEventTarget* MouseEvent:related-target",
243 WEBKIT_DOM_TYPE_EVENT_TARGET,
244 WEBKIT_PARAM_READABLE));
245
246 g_object_class_install_property(
247 gobjectClass,
248 DOM_MOUSE_EVENT_PROP_OFFSET_X,
249 g_param_spec_long(
250 "offset-x",
251 "MouseEvent:offset-x",
252 "read-only glong MouseEvent:offset-x",
253 G_MINLONG, G_MAXLONG, 0,
254 WEBKIT_PARAM_READABLE));
255
256 g_object_class_install_property(
257 gobjectClass,
258 DOM_MOUSE_EVENT_PROP_OFFSET_Y,
259 g_param_spec_long(
260 "offset-y",
261 "MouseEvent:offset-y",
262 "read-only glong MouseEvent:offset-y",
263 G_MINLONG, G_MAXLONG, 0,
264 WEBKIT_PARAM_READABLE));
265
266 g_object_class_install_property(
267 gobjectClass,
268 DOM_MOUSE_EVENT_PROP_X,
269 g_param_spec_long(
270 "x",
271 "MouseEvent:x",
272 "read-only glong MouseEvent:x",
273 G_MINLONG, G_MAXLONG, 0,
274 WEBKIT_PARAM_READABLE));
275
276 g_object_class_install_property(
277 gobjectClass,
278 DOM_MOUSE_EVENT_PROP_Y,
279 g_param_spec_long(
280 "y",
281 "MouseEvent:y",
282 "read-only glong MouseEvent:y",
283 G_MINLONG, G_MAXLONG, 0,
284 WEBKIT_PARAM_READABLE));
285
286 g_object_class_install_property(
287 gobjectClass,
288 DOM_MOUSE_EVENT_PROP_FROM_ELEMENT,
289 g_param_spec_object(
290 "from-element",
291 "MouseEvent:from-element",
292 "read-only WebKitDOMNode* MouseEvent:from-element",
293 WEBKIT_DOM_TYPE_NODE,
294 WEBKIT_PARAM_READABLE));
295
296 g_object_class_install_property(
297 gobjectClass,
298 DOM_MOUSE_EVENT_PROP_TO_ELEMENT,
299 g_param_spec_object(
300 "to-element",
301 "MouseEvent:to-element",
302 "read-only WebKitDOMNode* MouseEvent:to-element",
303 WEBKIT_DOM_TYPE_NODE,
304 WEBKIT_PARAM_READABLE));
305
306}
307
308static void webkit_dom_mouse_event_init(WebKitDOMMouseEvent* request)
309{
310 UNUSED_PARAM(request);
311}
312
313void webkit_dom_mouse_event_init_mouse_event(WebKitDOMMouseEvent* self, const gchar* type, gboolean canBubble, gboolean cancelable, WebKitDOMDOMWindow* view, glong detail, glong screenX, glong screenY, glong clientX, glong clientY, gboolean ctrlKey, gboolean altKey, gboolean shiftKey, gboolean metaKey, gushort button, WebKitDOMEventTarget* relatedTarget)
314{
315 WebCore::JSMainThreadNullState state;
316 g_return_if_fail(WEBKIT_DOM_IS_MOUSE_EVENT(self));
317 g_return_if_fail(type);
318 g_return_if_fail(WEBKIT_DOM_IS_DOM_WINDOW(view));
319 g_return_if_fail(WEBKIT_DOM_IS_EVENT_TARGET(relatedTarget));
320 WebCore::MouseEvent* item = WebKit::core(self);
321 WTF::String convertedType = WTF::String::fromUTF8(type);
322 WebCore::EventTarget* convertedRelatedTarget = WebKit::core(relatedTarget);
323 item->initMouseEvent(convertedType, canBubble, cancelable, WebKit::toWindowProxy(view), detail, screenX, screenY, clientX, clientY, ctrlKey, altKey, shiftKey, metaKey, button, convertedRelatedTarget);
324}
325
326glong webkit_dom_mouse_event_get_screen_x(WebKitDOMMouseEvent* self)
327{
328 WebCore::JSMainThreadNullState state;
329 g_return_val_if_fail(WEBKIT_DOM_IS_MOUSE_EVENT(self), 0);
330 WebCore::MouseEvent* item = WebKit::core(self);
331 glong result = item->screenX();
332 return result;
333}
334
335glong webkit_dom_mouse_event_get_screen_y(WebKitDOMMouseEvent* self)
336{
337 WebCore::JSMainThreadNullState state;
338 g_return_val_if_fail(WEBKIT_DOM_IS_MOUSE_EVENT(self), 0);
339 WebCore::MouseEvent* item = WebKit::core(self);
340 glong result = item->screenY();
341 return result;
342}
343
344glong webkit_dom_mouse_event_get_client_x(WebKitDOMMouseEvent* self)
345{
346 WebCore::JSMainThreadNullState state;
347 g_return_val_if_fail(WEBKIT_DOM_IS_MOUSE_EVENT(self), 0);
348 WebCore::MouseEvent* item = WebKit::core(self);
349 glong result = item->clientX();
350 return result;
351}
352
353glong webkit_dom_mouse_event_get_client_y(WebKitDOMMouseEvent* self)
354{
355 WebCore::JSMainThreadNullState state;
356 g_return_val_if_fail(WEBKIT_DOM_IS_MOUSE_EVENT(self), 0);
357 WebCore::MouseEvent* item = WebKit::core(self);
358 glong result = item->clientY();
359 return result;
360}
361
362gboolean webkit_dom_mouse_event_get_ctrl_key(WebKitDOMMouseEvent* self)
363{
364 WebCore::JSMainThreadNullState state;
365 g_return_val_if_fail(WEBKIT_DOM_IS_MOUSE_EVENT(self), FALSE);
366 WebCore::MouseEvent* item = WebKit::core(self);
367 gboolean result = item->ctrlKey();
368 return result;
369}
370
371gboolean webkit_dom_mouse_event_get_shift_key(WebKitDOMMouseEvent* self)
372{
373 WebCore::JSMainThreadNullState state;
374 g_return_val_if_fail(WEBKIT_DOM_IS_MOUSE_EVENT(self), FALSE);
375 WebCore::MouseEvent* item = WebKit::core(self);
376 gboolean result = item->shiftKey();
377 return result;
378}
379
380gboolean webkit_dom_mouse_event_get_alt_key(WebKitDOMMouseEvent* self)
381{
382 WebCore::JSMainThreadNullState state;
383 g_return_val_if_fail(WEBKIT_DOM_IS_MOUSE_EVENT(self), FALSE);
384 WebCore::MouseEvent* item = WebKit::core(self);
385 gboolean result = item->altKey();
386 return result;
387}
388
389gboolean webkit_dom_mouse_event_get_meta_key(WebKitDOMMouseEvent* self)
390{
391 WebCore::JSMainThreadNullState state;
392 g_return_val_if_fail(WEBKIT_DOM_IS_MOUSE_EVENT(self), FALSE);
393 WebCore::MouseEvent* item = WebKit::core(self);
394 gboolean result = item->metaKey();
395 return result;
396}
397
398gushort webkit_dom_mouse_event_get_button(WebKitDOMMouseEvent* self)
399{
400 WebCore::JSMainThreadNullState state;
401 g_return_val_if_fail(WEBKIT_DOM_IS_MOUSE_EVENT(self), 0);
402 WebCore::MouseEvent* item = WebKit::core(self);
403 gushort result = item->button();
404 return result;
405}
406
407WebKitDOMEventTarget* webkit_dom_mouse_event_get_related_target(WebKitDOMMouseEvent* self)
408{
409 WebCore::JSMainThreadNullState state;
410 g_return_val_if_fail(WEBKIT_DOM_IS_MOUSE_EVENT(self), 0);
411 WebCore::MouseEvent* item = WebKit::core(self);
412 RefPtr<WebCore::EventTarget> gobjectResult = WTF::getPtr(item->relatedTarget());
413 return WebKit::kit(gobjectResult.get());
414}
415
416glong webkit_dom_mouse_event_get_offset_x(WebKitDOMMouseEvent* self)
417{
418 WebCore::JSMainThreadNullState state;
419 g_return_val_if_fail(WEBKIT_DOM_IS_MOUSE_EVENT(self), 0);
420 WebCore::MouseEvent* item = WebKit::core(self);
421 glong result = item->offsetX();
422 return result;
423}
424
425glong webkit_dom_mouse_event_get_offset_y(WebKitDOMMouseEvent* self)
426{
427 WebCore::JSMainThreadNullState state;
428 g_return_val_if_fail(WEBKIT_DOM_IS_MOUSE_EVENT(self), 0);
429 WebCore::MouseEvent* item = WebKit::core(self);
430 glong result = item->offsetY();
431 return result;
432}
433
434glong webkit_dom_mouse_event_get_x(WebKitDOMMouseEvent* self)
435{
436 WebCore::JSMainThreadNullState state;
437 g_return_val_if_fail(WEBKIT_DOM_IS_MOUSE_EVENT(self), 0);
438 WebCore::MouseEvent* item = WebKit::core(self);
439 glong result = item->x();
440 return result;
441}
442
443glong webkit_dom_mouse_event_get_y(WebKitDOMMouseEvent* self)
444{
445 WebCore::JSMainThreadNullState state;
446 g_return_val_if_fail(WEBKIT_DOM_IS_MOUSE_EVENT(self), 0);
447 WebCore::MouseEvent* item = WebKit::core(self);
448 glong result = item->y();
449 return result;
450}
451
452WebKitDOMNode* webkit_dom_mouse_event_get_from_element(WebKitDOMMouseEvent* self)
453{
454 WebCore::JSMainThreadNullState state;
455 g_return_val_if_fail(WEBKIT_DOM_IS_MOUSE_EVENT(self), 0);
456 WebCore::MouseEvent* item = WebKit::core(self);
457 RefPtr<WebCore::Node> gobjectResult = WTF::getPtr(item->fromElement());
458 return WebKit::kit(gobjectResult.get());
459}
460
461WebKitDOMNode* webkit_dom_mouse_event_get_to_element(WebKitDOMMouseEvent* self)
462{
463 WebCore::JSMainThreadNullState state;
464 g_return_val_if_fail(WEBKIT_DOM_IS_MOUSE_EVENT(self), 0);
465 WebCore::MouseEvent* item = WebKit::core(self);
466 RefPtr<WebCore::Node> gobjectResult = WTF::getPtr(item->toElement());
467 return WebKit::kit(gobjectResult.get());
468}
469
470G_GNUC_END_IGNORE_DEPRECATIONS;
471