| 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 "WebKitDOMWheelEvent.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 "WebKitDOMPrivate.h" |
| 31 | #include "WebKitDOMWheelEventPrivate.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 | WebKitDOMWheelEvent* kit(WebCore::WheelEvent* obj) |
| 41 | { |
| 42 | return WEBKIT_DOM_WHEEL_EVENT(kit(static_cast<WebCore::Event*>(obj))); |
| 43 | } |
| 44 | |
| 45 | WebCore::WheelEvent* core(WebKitDOMWheelEvent* request) |
| 46 | { |
| 47 | return request ? static_cast<WebCore::WheelEvent*>(WEBKIT_DOM_OBJECT(request)->coreObject) : 0; |
| 48 | } |
| 49 | |
| 50 | WebKitDOMWheelEvent* wrapWheelEvent(WebCore::WheelEvent* coreObject) |
| 51 | { |
| 52 | ASSERT(coreObject); |
| 53 | return WEBKIT_DOM_WHEEL_EVENT(g_object_new(WEBKIT_DOM_TYPE_WHEEL_EVENT, "core-object" , coreObject, nullptr)); |
| 54 | } |
| 55 | |
| 56 | } // namespace WebKit |
| 57 | |
| 58 | G_DEFINE_TYPE(WebKitDOMWheelEvent, webkit_dom_wheel_event, WEBKIT_DOM_TYPE_MOUSE_EVENT) |
| 59 | |
| 60 | enum { |
| 61 | DOM_WHEEL_EVENT_PROP_0, |
| 62 | DOM_WHEEL_EVENT_PROP_WHEEL_DELTA_X, |
| 63 | DOM_WHEEL_EVENT_PROP_WHEEL_DELTA_Y, |
| 64 | DOM_WHEEL_EVENT_PROP_WHEEL_DELTA, |
| 65 | }; |
| 66 | |
| 67 | static void webkit_dom_wheel_event_get_property(GObject* object, guint propertyId, GValue* value, GParamSpec* pspec) |
| 68 | { |
| 69 | WebKitDOMWheelEvent* self = WEBKIT_DOM_WHEEL_EVENT(object); |
| 70 | |
| 71 | switch (propertyId) { |
| 72 | case DOM_WHEEL_EVENT_PROP_WHEEL_DELTA_X: |
| 73 | g_value_set_long(value, webkit_dom_wheel_event_get_wheel_delta_x(self)); |
| 74 | break; |
| 75 | case DOM_WHEEL_EVENT_PROP_WHEEL_DELTA_Y: |
| 76 | g_value_set_long(value, webkit_dom_wheel_event_get_wheel_delta_y(self)); |
| 77 | break; |
| 78 | case DOM_WHEEL_EVENT_PROP_WHEEL_DELTA: |
| 79 | g_value_set_long(value, webkit_dom_wheel_event_get_wheel_delta(self)); |
| 80 | break; |
| 81 | default: |
| 82 | G_OBJECT_WARN_INVALID_PROPERTY_ID(object, propertyId, pspec); |
| 83 | break; |
| 84 | } |
| 85 | } |
| 86 | |
| 87 | static void webkit_dom_wheel_event_class_init(WebKitDOMWheelEventClass* requestClass) |
| 88 | { |
| 89 | GObjectClass* gobjectClass = G_OBJECT_CLASS(requestClass); |
| 90 | gobjectClass->get_property = webkit_dom_wheel_event_get_property; |
| 91 | |
| 92 | g_object_class_install_property( |
| 93 | gobjectClass, |
| 94 | DOM_WHEEL_EVENT_PROP_WHEEL_DELTA_X, |
| 95 | g_param_spec_long( |
| 96 | "wheel-delta-x" , |
| 97 | "WheelEvent:wheel-delta-x" , |
| 98 | "read-only glong WheelEvent:wheel-delta-x" , |
| 99 | G_MINLONG, G_MAXLONG, 0, |
| 100 | WEBKIT_PARAM_READABLE)); |
| 101 | |
| 102 | g_object_class_install_property( |
| 103 | gobjectClass, |
| 104 | DOM_WHEEL_EVENT_PROP_WHEEL_DELTA_Y, |
| 105 | g_param_spec_long( |
| 106 | "wheel-delta-y" , |
| 107 | "WheelEvent:wheel-delta-y" , |
| 108 | "read-only glong WheelEvent:wheel-delta-y" , |
| 109 | G_MINLONG, G_MAXLONG, 0, |
| 110 | WEBKIT_PARAM_READABLE)); |
| 111 | |
| 112 | g_object_class_install_property( |
| 113 | gobjectClass, |
| 114 | DOM_WHEEL_EVENT_PROP_WHEEL_DELTA, |
| 115 | g_param_spec_long( |
| 116 | "wheel-delta" , |
| 117 | "WheelEvent:wheel-delta" , |
| 118 | "read-only glong WheelEvent:wheel-delta" , |
| 119 | G_MINLONG, G_MAXLONG, 0, |
| 120 | WEBKIT_PARAM_READABLE)); |
| 121 | } |
| 122 | |
| 123 | static void webkit_dom_wheel_event_init(WebKitDOMWheelEvent* request) |
| 124 | { |
| 125 | UNUSED_PARAM(request); |
| 126 | } |
| 127 | |
| 128 | void webkit_dom_wheel_event_init_wheel_event(WebKitDOMWheelEvent* self, glong wheelDeltaX, glong wheelDeltaY, WebKitDOMDOMWindow* view, glong screenX, glong screenY, glong clientX, glong clientY, gboolean ctrlKey, gboolean altKey, gboolean shiftKey, gboolean metaKey) |
| 129 | { |
| 130 | WebCore::JSMainThreadNullState state; |
| 131 | g_return_if_fail(WEBKIT_DOM_IS_WHEEL_EVENT(self)); |
| 132 | g_return_if_fail(WEBKIT_DOM_IS_DOM_WINDOW(view)); |
| 133 | WebCore::WheelEvent* item = WebKit::core(self); |
| 134 | item->initWebKitWheelEvent(wheelDeltaX, wheelDeltaY, WebKit::toWindowProxy(view), screenX, screenY, clientX, clientY, ctrlKey, altKey, shiftKey, metaKey); |
| 135 | } |
| 136 | |
| 137 | glong webkit_dom_wheel_event_get_wheel_delta_x(WebKitDOMWheelEvent* self) |
| 138 | { |
| 139 | WebCore::JSMainThreadNullState state; |
| 140 | g_return_val_if_fail(WEBKIT_DOM_IS_WHEEL_EVENT(self), 0); |
| 141 | WebCore::WheelEvent* item = WebKit::core(self); |
| 142 | glong result = item->wheelDeltaX(); |
| 143 | return result; |
| 144 | } |
| 145 | |
| 146 | glong webkit_dom_wheel_event_get_wheel_delta_y(WebKitDOMWheelEvent* self) |
| 147 | { |
| 148 | WebCore::JSMainThreadNullState state; |
| 149 | g_return_val_if_fail(WEBKIT_DOM_IS_WHEEL_EVENT(self), 0); |
| 150 | WebCore::WheelEvent* item = WebKit::core(self); |
| 151 | glong result = item->wheelDeltaY(); |
| 152 | return result; |
| 153 | } |
| 154 | |
| 155 | glong webkit_dom_wheel_event_get_wheel_delta(WebKitDOMWheelEvent* self) |
| 156 | { |
| 157 | WebCore::JSMainThreadNullState state; |
| 158 | g_return_val_if_fail(WEBKIT_DOM_IS_WHEEL_EVENT(self), 0); |
| 159 | WebCore::WheelEvent* item = WebKit::core(self); |
| 160 | glong result = item->wheelDelta(); |
| 161 | return result; |
| 162 | } |
| 163 | G_GNUC_END_IGNORE_DEPRECATIONS; |
| 164 | |