| 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 "WebKitDOMKeyboardEvent.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 "WebKitDOMKeyboardEventPrivate.h" |
| 31 | #include "WebKitDOMPrivate.h" |
| 32 | #include "ConvertToUTF8String.h" |
| 33 | #include <wtf/GetPtr.h> |
| 34 | #include <wtf/RefPtr.h> |
| 35 | |
| 36 | G_GNUC_BEGIN_IGNORE_DEPRECATIONS; |
| 37 | |
| 38 | namespace WebKit { |
| 39 | |
| 40 | WebKitDOMKeyboardEvent* kit(WebCore::KeyboardEvent* obj) |
| 41 | { |
| 42 | return WEBKIT_DOM_KEYBOARD_EVENT(kit(static_cast<WebCore::Event*>(obj))); |
| 43 | } |
| 44 | |
| 45 | WebCore::KeyboardEvent* core(WebKitDOMKeyboardEvent* request) |
| 46 | { |
| 47 | return request ? static_cast<WebCore::KeyboardEvent*>(WEBKIT_DOM_OBJECT(request)->coreObject) : 0; |
| 48 | } |
| 49 | |
| 50 | WebKitDOMKeyboardEvent* wrapKeyboardEvent(WebCore::KeyboardEvent* coreObject) |
| 51 | { |
| 52 | ASSERT(coreObject); |
| 53 | return WEBKIT_DOM_KEYBOARD_EVENT(g_object_new(WEBKIT_DOM_TYPE_KEYBOARD_EVENT, "core-object" , coreObject, nullptr)); |
| 54 | } |
| 55 | |
| 56 | } // namespace WebKit |
| 57 | |
| 58 | G_DEFINE_TYPE(WebKitDOMKeyboardEvent, webkit_dom_keyboard_event, WEBKIT_DOM_TYPE_UI_EVENT) |
| 59 | |
| 60 | enum { |
| 61 | DOM_KEYBOARD_EVENT_PROP_0, |
| 62 | DOM_KEYBOARD_EVENT_PROP_KEY_IDENTIFIER, |
| 63 | DOM_KEYBOARD_EVENT_PROP_KEY_LOCATION, |
| 64 | DOM_KEYBOARD_EVENT_PROP_CTRL_KEY, |
| 65 | DOM_KEYBOARD_EVENT_PROP_SHIFT_KEY, |
| 66 | DOM_KEYBOARD_EVENT_PROP_ALT_KEY, |
| 67 | DOM_KEYBOARD_EVENT_PROP_META_KEY, |
| 68 | DOM_KEYBOARD_EVENT_PROP_ALT_GRAPH_KEY, |
| 69 | }; |
| 70 | |
| 71 | static void webkit_dom_keyboard_event_get_property(GObject* object, guint propertyId, GValue* value, GParamSpec* pspec) |
| 72 | { |
| 73 | WebKitDOMKeyboardEvent* self = WEBKIT_DOM_KEYBOARD_EVENT(object); |
| 74 | |
| 75 | switch (propertyId) { |
| 76 | case DOM_KEYBOARD_EVENT_PROP_KEY_IDENTIFIER: |
| 77 | g_value_take_string(value, webkit_dom_keyboard_event_get_key_identifier(self)); |
| 78 | break; |
| 79 | case DOM_KEYBOARD_EVENT_PROP_KEY_LOCATION: |
| 80 | g_value_set_ulong(value, webkit_dom_keyboard_event_get_key_location(self)); |
| 81 | break; |
| 82 | case DOM_KEYBOARD_EVENT_PROP_CTRL_KEY: |
| 83 | g_value_set_boolean(value, webkit_dom_keyboard_event_get_ctrl_key(self)); |
| 84 | break; |
| 85 | case DOM_KEYBOARD_EVENT_PROP_SHIFT_KEY: |
| 86 | g_value_set_boolean(value, webkit_dom_keyboard_event_get_shift_key(self)); |
| 87 | break; |
| 88 | case DOM_KEYBOARD_EVENT_PROP_ALT_KEY: |
| 89 | g_value_set_boolean(value, webkit_dom_keyboard_event_get_alt_key(self)); |
| 90 | break; |
| 91 | case DOM_KEYBOARD_EVENT_PROP_META_KEY: |
| 92 | g_value_set_boolean(value, webkit_dom_keyboard_event_get_meta_key(self)); |
| 93 | break; |
| 94 | case DOM_KEYBOARD_EVENT_PROP_ALT_GRAPH_KEY: |
| 95 | g_value_set_boolean(value, webkit_dom_keyboard_event_get_alt_graph_key(self)); |
| 96 | break; |
| 97 | default: |
| 98 | G_OBJECT_WARN_INVALID_PROPERTY_ID(object, propertyId, pspec); |
| 99 | break; |
| 100 | } |
| 101 | } |
| 102 | |
| 103 | static void webkit_dom_keyboard_event_class_init(WebKitDOMKeyboardEventClass* requestClass) |
| 104 | { |
| 105 | GObjectClass* gobjectClass = G_OBJECT_CLASS(requestClass); |
| 106 | gobjectClass->get_property = webkit_dom_keyboard_event_get_property; |
| 107 | |
| 108 | g_object_class_install_property( |
| 109 | gobjectClass, |
| 110 | DOM_KEYBOARD_EVENT_PROP_KEY_IDENTIFIER, |
| 111 | g_param_spec_string( |
| 112 | "key-identifier" , |
| 113 | "KeyboardEvent:key-identifier" , |
| 114 | "read-only gchar* KeyboardEvent:key-identifier" , |
| 115 | "" , |
| 116 | WEBKIT_PARAM_READABLE)); |
| 117 | |
| 118 | g_object_class_install_property( |
| 119 | gobjectClass, |
| 120 | DOM_KEYBOARD_EVENT_PROP_KEY_LOCATION, |
| 121 | g_param_spec_ulong( |
| 122 | "key-location" , |
| 123 | "KeyboardEvent:key-location" , |
| 124 | "read-only gulong KeyboardEvent:key-location" , |
| 125 | 0, G_MAXULONG, 0, |
| 126 | WEBKIT_PARAM_READABLE)); |
| 127 | |
| 128 | g_object_class_install_property( |
| 129 | gobjectClass, |
| 130 | DOM_KEYBOARD_EVENT_PROP_CTRL_KEY, |
| 131 | g_param_spec_boolean( |
| 132 | "ctrl-key" , |
| 133 | "KeyboardEvent:ctrl-key" , |
| 134 | "read-only gboolean KeyboardEvent:ctrl-key" , |
| 135 | FALSE, |
| 136 | WEBKIT_PARAM_READABLE)); |
| 137 | |
| 138 | g_object_class_install_property( |
| 139 | gobjectClass, |
| 140 | DOM_KEYBOARD_EVENT_PROP_SHIFT_KEY, |
| 141 | g_param_spec_boolean( |
| 142 | "shift-key" , |
| 143 | "KeyboardEvent:shift-key" , |
| 144 | "read-only gboolean KeyboardEvent:shift-key" , |
| 145 | FALSE, |
| 146 | WEBKIT_PARAM_READABLE)); |
| 147 | |
| 148 | g_object_class_install_property( |
| 149 | gobjectClass, |
| 150 | DOM_KEYBOARD_EVENT_PROP_ALT_KEY, |
| 151 | g_param_spec_boolean( |
| 152 | "alt-key" , |
| 153 | "KeyboardEvent:alt-key" , |
| 154 | "read-only gboolean KeyboardEvent:alt-key" , |
| 155 | FALSE, |
| 156 | WEBKIT_PARAM_READABLE)); |
| 157 | |
| 158 | g_object_class_install_property( |
| 159 | gobjectClass, |
| 160 | DOM_KEYBOARD_EVENT_PROP_META_KEY, |
| 161 | g_param_spec_boolean( |
| 162 | "meta-key" , |
| 163 | "KeyboardEvent:meta-key" , |
| 164 | "read-only gboolean KeyboardEvent:meta-key" , |
| 165 | FALSE, |
| 166 | WEBKIT_PARAM_READABLE)); |
| 167 | |
| 168 | g_object_class_install_property( |
| 169 | gobjectClass, |
| 170 | DOM_KEYBOARD_EVENT_PROP_ALT_GRAPH_KEY, |
| 171 | g_param_spec_boolean( |
| 172 | "alt-graph-key" , |
| 173 | "KeyboardEvent:alt-graph-key" , |
| 174 | "read-only gboolean KeyboardEvent:alt-graph-key" , |
| 175 | FALSE, |
| 176 | WEBKIT_PARAM_READABLE)); |
| 177 | |
| 178 | } |
| 179 | |
| 180 | static void webkit_dom_keyboard_event_init(WebKitDOMKeyboardEvent* request) |
| 181 | { |
| 182 | UNUSED_PARAM(request); |
| 183 | } |
| 184 | |
| 185 | gboolean webkit_dom_keyboard_event_get_modifier_state(WebKitDOMKeyboardEvent* self, const gchar* keyIdentifierArg) |
| 186 | { |
| 187 | WebCore::JSMainThreadNullState state; |
| 188 | g_return_val_if_fail(WEBKIT_DOM_IS_KEYBOARD_EVENT(self), FALSE); |
| 189 | g_return_val_if_fail(keyIdentifierArg, FALSE); |
| 190 | WebCore::KeyboardEvent* item = WebKit::core(self); |
| 191 | WTF::String convertedKeyIdentifierArg = WTF::String::fromUTF8(keyIdentifierArg); |
| 192 | gboolean result = item->getModifierState(convertedKeyIdentifierArg); |
| 193 | return result; |
| 194 | } |
| 195 | |
| 196 | void webkit_dom_keyboard_event_init_keyboard_event(WebKitDOMKeyboardEvent* self, const gchar* type, gboolean canBubble, gboolean cancelable, WebKitDOMDOMWindow* view, const gchar* keyIdentifier, gulong location, gboolean ctrlKey, gboolean altKey, gboolean shiftKey, gboolean metaKey, gboolean altGraphKey) |
| 197 | { |
| 198 | WebCore::JSMainThreadNullState state; |
| 199 | g_return_if_fail(WEBKIT_DOM_IS_KEYBOARD_EVENT(self)); |
| 200 | g_return_if_fail(type); |
| 201 | g_return_if_fail(WEBKIT_DOM_IS_DOM_WINDOW(view)); |
| 202 | g_return_if_fail(keyIdentifier); |
| 203 | WebCore::KeyboardEvent* item = WebKit::core(self); |
| 204 | WTF::String convertedType = WTF::String::fromUTF8(type); |
| 205 | WTF::String convertedKeyIdentifier = WTF::String::fromUTF8(keyIdentifier); |
| 206 | item->initKeyboardEvent(convertedType, canBubble, cancelable, WebKit::toWindowProxy(view), convertedKeyIdentifier, location, ctrlKey, altKey, shiftKey, metaKey, altGraphKey); |
| 207 | } |
| 208 | |
| 209 | gchar* webkit_dom_keyboard_event_get_key_identifier(WebKitDOMKeyboardEvent* self) |
| 210 | { |
| 211 | WebCore::JSMainThreadNullState state; |
| 212 | g_return_val_if_fail(WEBKIT_DOM_IS_KEYBOARD_EVENT(self), 0); |
| 213 | WebCore::KeyboardEvent* item = WebKit::core(self); |
| 214 | gchar* result = convertToUTF8String(item->keyIdentifier()); |
| 215 | return result; |
| 216 | } |
| 217 | |
| 218 | gulong webkit_dom_keyboard_event_get_key_location(WebKitDOMKeyboardEvent* self) |
| 219 | { |
| 220 | WebCore::JSMainThreadNullState state; |
| 221 | g_return_val_if_fail(WEBKIT_DOM_IS_KEYBOARD_EVENT(self), 0); |
| 222 | WebCore::KeyboardEvent* item = WebKit::core(self); |
| 223 | gulong result = item->location(); |
| 224 | return result; |
| 225 | } |
| 226 | |
| 227 | gboolean webkit_dom_keyboard_event_get_ctrl_key(WebKitDOMKeyboardEvent* self) |
| 228 | { |
| 229 | WebCore::JSMainThreadNullState state; |
| 230 | g_return_val_if_fail(WEBKIT_DOM_IS_KEYBOARD_EVENT(self), FALSE); |
| 231 | WebCore::KeyboardEvent* item = WebKit::core(self); |
| 232 | gboolean result = item->ctrlKey(); |
| 233 | return result; |
| 234 | } |
| 235 | |
| 236 | gboolean webkit_dom_keyboard_event_get_shift_key(WebKitDOMKeyboardEvent* self) |
| 237 | { |
| 238 | WebCore::JSMainThreadNullState state; |
| 239 | g_return_val_if_fail(WEBKIT_DOM_IS_KEYBOARD_EVENT(self), FALSE); |
| 240 | WebCore::KeyboardEvent* item = WebKit::core(self); |
| 241 | gboolean result = item->shiftKey(); |
| 242 | return result; |
| 243 | } |
| 244 | |
| 245 | gboolean webkit_dom_keyboard_event_get_alt_key(WebKitDOMKeyboardEvent* self) |
| 246 | { |
| 247 | WebCore::JSMainThreadNullState state; |
| 248 | g_return_val_if_fail(WEBKIT_DOM_IS_KEYBOARD_EVENT(self), FALSE); |
| 249 | WebCore::KeyboardEvent* item = WebKit::core(self); |
| 250 | gboolean result = item->altKey(); |
| 251 | return result; |
| 252 | } |
| 253 | |
| 254 | gboolean webkit_dom_keyboard_event_get_meta_key(WebKitDOMKeyboardEvent* self) |
| 255 | { |
| 256 | WebCore::JSMainThreadNullState state; |
| 257 | g_return_val_if_fail(WEBKIT_DOM_IS_KEYBOARD_EVENT(self), FALSE); |
| 258 | WebCore::KeyboardEvent* item = WebKit::core(self); |
| 259 | gboolean result = item->metaKey(); |
| 260 | return result; |
| 261 | } |
| 262 | |
| 263 | gboolean webkit_dom_keyboard_event_get_alt_graph_key(WebKitDOMKeyboardEvent* self) |
| 264 | { |
| 265 | WebCore::JSMainThreadNullState state; |
| 266 | g_return_val_if_fail(WEBKIT_DOM_IS_KEYBOARD_EVENT(self), FALSE); |
| 267 | WebCore::KeyboardEvent* item = WebKit::core(self); |
| 268 | gboolean result = item->altGraphKey(); |
| 269 | return result; |
| 270 | } |
| 271 | |
| 272 | G_GNUC_END_IGNORE_DEPRECATIONS; |
| 273 | |