bf32a87943571bcd5d9a9c209624951065490545
[WebKit-https.git] / Source / WebKit / WebProcess / InjectedBundle / API / gtk / DOM / WebKitDOMUIEvent.cpp
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 "WebKitDOMUIEvent.h"
22
23 #include <WebCore/CSSImportRule.h>
24 #include "DOMObjectCache.h"
25 #include <WebCore/Document.h>
26 #include <WebCore/ExceptionCode.h>
27 #include <WebCore/ExceptionCodeDescription.h>
28 #include <WebCore/JSMainThreadExecState.h>
29 #include <WebCore/KeyboardEvent.h>
30 #include "WebKitDOMDOMWindowPrivate.h"
31 #include "WebKitDOMEventPrivate.h"
32 #include "WebKitDOMPrivate.h"
33 #include "WebKitDOMUIEventPrivate.h"
34 #include "ConvertToUTF8String.h"
35 #include <wtf/GetPtr.h>
36 #include <wtf/RefPtr.h>
37
38 namespace WebKit {
39
40 WebKitDOMUIEvent* kit(WebCore::UIEvent* obj)
41 {
42     return WEBKIT_DOM_UI_EVENT(kit(static_cast<WebCore::Event*>(obj)));
43 }
44
45 WebCore::UIEvent* core(WebKitDOMUIEvent* request)
46 {
47     return request ? static_cast<WebCore::UIEvent*>(WEBKIT_DOM_OBJECT(request)->coreObject) : 0;
48 }
49
50 WebKitDOMUIEvent* wrapUIEvent(WebCore::UIEvent* coreObject)
51 {
52     ASSERT(coreObject);
53     return WEBKIT_DOM_UI_EVENT(g_object_new(WEBKIT_DOM_TYPE_UI_EVENT, "core-object", coreObject, nullptr));
54 }
55
56 } // namespace WebKit
57
58 G_DEFINE_TYPE(WebKitDOMUIEvent, webkit_dom_ui_event, WEBKIT_DOM_TYPE_EVENT)
59
60 enum {
61     PROP_0,
62     PROP_VIEW,
63     PROP_DETAIL,
64     PROP_KEY_CODE,
65     PROP_CHAR_CODE,
66     PROP_LAYER_X,
67     PROP_LAYER_Y,
68     PROP_PAGE_X,
69     PROP_PAGE_Y,
70 };
71
72 static void webkit_dom_ui_event_get_property(GObject* object, guint propertyId, GValue* value, GParamSpec* pspec)
73 {
74     WebKitDOMUIEvent* self = WEBKIT_DOM_UI_EVENT(object);
75
76     switch (propertyId) {
77     case PROP_VIEW:
78         g_value_set_object(value, webkit_dom_ui_event_get_view(self));
79         break;
80     case PROP_DETAIL:
81         g_value_set_long(value, webkit_dom_ui_event_get_detail(self));
82         break;
83     case PROP_KEY_CODE:
84         g_value_set_long(value, webkit_dom_ui_event_get_key_code(self));
85         break;
86     case PROP_CHAR_CODE:
87         g_value_set_long(value, webkit_dom_ui_event_get_char_code(self));
88         break;
89     case PROP_LAYER_X:
90         g_value_set_long(value, webkit_dom_ui_event_get_layer_x(self));
91         break;
92     case PROP_LAYER_Y:
93         g_value_set_long(value, webkit_dom_ui_event_get_layer_y(self));
94         break;
95     case PROP_PAGE_X:
96         g_value_set_long(value, webkit_dom_ui_event_get_page_x(self));
97         break;
98     case PROP_PAGE_Y:
99         g_value_set_long(value, webkit_dom_ui_event_get_page_y(self));
100         break;
101     default:
102         G_OBJECT_WARN_INVALID_PROPERTY_ID(object, propertyId, pspec);
103         break;
104     }
105 }
106
107 static void webkit_dom_ui_event_class_init(WebKitDOMUIEventClass* requestClass)
108 {
109     GObjectClass* gobjectClass = G_OBJECT_CLASS(requestClass);
110     gobjectClass->get_property = webkit_dom_ui_event_get_property;
111
112     g_object_class_install_property(
113         gobjectClass,
114         PROP_VIEW,
115         g_param_spec_object(
116             "view",
117             "UIEvent:view",
118             "read-only WebKitDOMDOMWindow* UIEvent:view",
119             WEBKIT_DOM_TYPE_DOM_WINDOW,
120             WEBKIT_PARAM_READABLE));
121
122     g_object_class_install_property(
123         gobjectClass,
124         PROP_DETAIL,
125         g_param_spec_long(
126             "detail",
127             "UIEvent:detail",
128             "read-only glong UIEvent:detail",
129             G_MINLONG, G_MAXLONG, 0,
130             WEBKIT_PARAM_READABLE));
131
132     g_object_class_install_property(
133         gobjectClass,
134         PROP_KEY_CODE,
135         g_param_spec_long(
136             "key-code",
137             "UIEvent:key-code",
138             "read-only glong UIEvent:key-code",
139             G_MINLONG, G_MAXLONG, 0,
140             WEBKIT_PARAM_READABLE));
141
142     g_object_class_install_property(
143         gobjectClass,
144         PROP_CHAR_CODE,
145         g_param_spec_long(
146             "char-code",
147             "UIEvent:char-code",
148             "read-only glong UIEvent:char-code",
149             G_MINLONG, G_MAXLONG, 0,
150             WEBKIT_PARAM_READABLE));
151
152     g_object_class_install_property(
153         gobjectClass,
154         PROP_LAYER_X,
155         g_param_spec_long(
156             "layer-x",
157             "UIEvent:layer-x",
158             "read-only glong UIEvent:layer-x",
159             G_MINLONG, G_MAXLONG, 0,
160             WEBKIT_PARAM_READABLE));
161
162     g_object_class_install_property(
163         gobjectClass,
164         PROP_LAYER_Y,
165         g_param_spec_long(
166             "layer-y",
167             "UIEvent:layer-y",
168             "read-only glong UIEvent:layer-y",
169             G_MINLONG, G_MAXLONG, 0,
170             WEBKIT_PARAM_READABLE));
171
172     g_object_class_install_property(
173         gobjectClass,
174         PROP_PAGE_X,
175         g_param_spec_long(
176             "page-x",
177             "UIEvent:page-x",
178             "read-only glong UIEvent:page-x",
179             G_MINLONG, G_MAXLONG, 0,
180             WEBKIT_PARAM_READABLE));
181
182     g_object_class_install_property(
183         gobjectClass,
184         PROP_PAGE_Y,
185         g_param_spec_long(
186             "page-y",
187             "UIEvent:page-y",
188             "read-only glong UIEvent:page-y",
189             G_MINLONG, G_MAXLONG, 0,
190             WEBKIT_PARAM_READABLE));
191 }
192
193 static void webkit_dom_ui_event_init(WebKitDOMUIEvent* request)
194 {
195     UNUSED_PARAM(request);
196 }
197
198 void webkit_dom_ui_event_init_ui_event(WebKitDOMUIEvent* self, const gchar* type, gboolean canBubble, gboolean cancelable, WebKitDOMDOMWindow* view, glong detail)
199 {
200     WebCore::JSMainThreadNullState state;
201     g_return_if_fail(WEBKIT_DOM_IS_UI_EVENT(self));
202     g_return_if_fail(type);
203     g_return_if_fail(WEBKIT_DOM_IS_DOM_WINDOW(view));
204     WebCore::UIEvent* item = WebKit::core(self);
205     WTF::String convertedType = WTF::String::fromUTF8(type);
206     WebCore::DOMWindow* convertedView = WebKit::core(view);
207     item->initUIEvent(convertedType, canBubble, cancelable, convertedView, detail);
208 }
209
210 WebKitDOMDOMWindow* webkit_dom_ui_event_get_view(WebKitDOMUIEvent* self)
211 {
212     WebCore::JSMainThreadNullState state;
213     g_return_val_if_fail(WEBKIT_DOM_IS_UI_EVENT(self), 0);
214     WebCore::UIEvent* item = WebKit::core(self);
215     RefPtr<WebCore::DOMWindow> gobjectResult = WTF::getPtr(item->view());
216     return WebKit::kit(gobjectResult.get());
217 }
218
219 glong webkit_dom_ui_event_get_detail(WebKitDOMUIEvent* self)
220 {
221     WebCore::JSMainThreadNullState state;
222     g_return_val_if_fail(WEBKIT_DOM_IS_UI_EVENT(self), 0);
223     WebCore::UIEvent* item = WebKit::core(self);
224     glong result = item->detail();
225     return result;
226 }
227
228 glong webkit_dom_ui_event_get_key_code(WebKitDOMUIEvent* self)
229 {
230     WebCore::JSMainThreadNullState state;
231     g_return_val_if_fail(WEBKIT_DOM_IS_UI_EVENT(self), 0);
232     WebCore::UIEvent* item = WebKit::core(self);
233     glong result = is<WebCore::KeyboardEvent>(*item) ? downcast<WebCore::KeyboardEvent>(*item).keyCode() : 0;
234     return result;
235 }
236
237 glong webkit_dom_ui_event_get_char_code(WebKitDOMUIEvent* self)
238 {
239     WebCore::JSMainThreadNullState state;
240     g_return_val_if_fail(WEBKIT_DOM_IS_UI_EVENT(self), 0);
241     WebCore::UIEvent* item = WebKit::core(self);
242     glong result = is<WebCore::KeyboardEvent>(*item) ? downcast<WebCore::KeyboardEvent>(*item).charCode() : 0;
243     return result;
244 }
245
246 glong webkit_dom_ui_event_get_layer_x(WebKitDOMUIEvent* self)
247 {
248     WebCore::JSMainThreadNullState state;
249     g_return_val_if_fail(WEBKIT_DOM_IS_UI_EVENT(self), 0);
250     WebCore::UIEvent* item = WebKit::core(self);
251     glong result = item->layerX();
252     return result;
253 }
254
255 glong webkit_dom_ui_event_get_layer_y(WebKitDOMUIEvent* self)
256 {
257     WebCore::JSMainThreadNullState state;
258     g_return_val_if_fail(WEBKIT_DOM_IS_UI_EVENT(self), 0);
259     WebCore::UIEvent* item = WebKit::core(self);
260     glong result = item->layerY();
261     return result;
262 }
263
264 glong webkit_dom_ui_event_get_page_x(WebKitDOMUIEvent* self)
265 {
266     WebCore::JSMainThreadNullState state;
267     g_return_val_if_fail(WEBKIT_DOM_IS_UI_EVENT(self), 0);
268     WebCore::UIEvent* item = WebKit::core(self);
269     glong result = item->pageX();
270     return result;
271 }
272
273 glong webkit_dom_ui_event_get_page_y(WebKitDOMUIEvent* self)
274 {
275     WebCore::JSMainThreadNullState state;
276     g_return_val_if_fail(WEBKIT_DOM_IS_UI_EVENT(self), 0);
277     WebCore::UIEvent* item = WebKit::core(self);
278     glong result = item->pageY();
279     return result;
280 }