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