| 1 | /* |
| 2 | * Copyright (C) 2017 Aidan Holm <aidanholm@gmail.com> |
| 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 "WebKitDOMClientRect.h" |
| 22 | |
| 23 | #include "ConvertToUTF8String.h" |
| 24 | #include "DOMObjectCache.h" |
| 25 | #include "WebKitDOMClientRectPrivate.h" |
| 26 | #include "WebKitDOMPrivate.h" |
| 27 | #include <WebCore/CSSImportRule.h> |
| 28 | #include <WebCore/Document.h> |
| 29 | #include <WebCore/ExceptionCode.h> |
| 30 | #include <WebCore/JSExecState.h> |
| 31 | #include <wtf/GetPtr.h> |
| 32 | #include <wtf/RefPtr.h> |
| 33 | |
| 34 | #define WEBKIT_DOM_CLIENT_RECT_GET_PRIVATE(obj) G_TYPE_INSTANCE_GET_PRIVATE(obj, WEBKIT_DOM_TYPE_CLIENT_RECT, WebKitDOMClientRectPrivate) |
| 35 | |
| 36 | typedef struct _WebKitDOMClientRectPrivate { |
| 37 | RefPtr<WebCore::DOMRect> coreObject; |
| 38 | } WebKitDOMClientRectPrivate; |
| 39 | |
| 40 | G_GNUC_BEGIN_IGNORE_DEPRECATIONS; |
| 41 | |
| 42 | namespace WebKit { |
| 43 | |
| 44 | WebKitDOMClientRect* kit(WebCore::DOMRect* obj) |
| 45 | { |
| 46 | if (!obj) |
| 47 | return nullptr; |
| 48 | |
| 49 | if (gpointer ret = DOMObjectCache::get(obj)) |
| 50 | return WEBKIT_DOM_CLIENT_RECT(ret); |
| 51 | |
| 52 | return wrapClientRect(obj); |
| 53 | } |
| 54 | |
| 55 | WebCore::DOMRect* core(WebKitDOMClientRect* request) |
| 56 | { |
| 57 | return request ? static_cast<WebCore::DOMRect*>(WEBKIT_DOM_OBJECT(request)->coreObject) : nullptr; |
| 58 | } |
| 59 | |
| 60 | WebKitDOMClientRect* wrapClientRect(WebCore::DOMRect* coreObject) |
| 61 | { |
| 62 | ASSERT(coreObject); |
| 63 | return WEBKIT_DOM_CLIENT_RECT(g_object_new(WEBKIT_DOM_TYPE_CLIENT_RECT, "core-object" , coreObject, nullptr)); |
| 64 | } |
| 65 | |
| 66 | } // namespace WebKit |
| 67 | |
| 68 | G_DEFINE_TYPE(WebKitDOMClientRect, webkit_dom_client_rect, WEBKIT_DOM_TYPE_OBJECT) |
| 69 | |
| 70 | enum { |
| 71 | DOM_CLIENT_RECT_PROP_0, |
| 72 | DOM_CLIENT_RECT_PROP_TOP, |
| 73 | DOM_CLIENT_RECT_PROP_RIGHT, |
| 74 | DOM_CLIENT_RECT_PROP_BOTTOM, |
| 75 | DOM_CLIENT_RECT_PROP_LEFT, |
| 76 | DOM_CLIENT_RECT_PROP_WIDTH, |
| 77 | DOM_CLIENT_RECT_PROP_HEIGHT, |
| 78 | }; |
| 79 | |
| 80 | static void webkit_dom_client_rect_finalize(GObject* object) |
| 81 | { |
| 82 | WebKitDOMClientRectPrivate* priv = WEBKIT_DOM_CLIENT_RECT_GET_PRIVATE(object); |
| 83 | |
| 84 | WebKit::DOMObjectCache::forget(priv->coreObject.get()); |
| 85 | |
| 86 | priv->~WebKitDOMClientRectPrivate(); |
| 87 | G_OBJECT_CLASS(webkit_dom_client_rect_parent_class)->finalize(object); |
| 88 | } |
| 89 | |
| 90 | static void webkit_dom_client_rect_get_property(GObject* object, guint propertyId, GValue* value, GParamSpec* pspec) |
| 91 | { |
| 92 | WebKitDOMClientRect* self = WEBKIT_DOM_CLIENT_RECT(object); |
| 93 | |
| 94 | switch (propertyId) { |
| 95 | case DOM_CLIENT_RECT_PROP_TOP: |
| 96 | g_value_set_float(value, webkit_dom_client_rect_get_top(self)); |
| 97 | break; |
| 98 | case DOM_CLIENT_RECT_PROP_RIGHT: |
| 99 | g_value_set_float(value, webkit_dom_client_rect_get_right(self)); |
| 100 | break; |
| 101 | case DOM_CLIENT_RECT_PROP_BOTTOM: |
| 102 | g_value_set_float(value, webkit_dom_client_rect_get_bottom(self)); |
| 103 | break; |
| 104 | case DOM_CLIENT_RECT_PROP_LEFT: |
| 105 | g_value_set_float(value, webkit_dom_client_rect_get_left(self)); |
| 106 | break; |
| 107 | case DOM_CLIENT_RECT_PROP_WIDTH: |
| 108 | g_value_set_float(value, webkit_dom_client_rect_get_width(self)); |
| 109 | break; |
| 110 | case DOM_CLIENT_RECT_PROP_HEIGHT: |
| 111 | g_value_set_float(value, webkit_dom_client_rect_get_height(self)); |
| 112 | break; |
| 113 | default: |
| 114 | G_OBJECT_WARN_INVALID_PROPERTY_ID(object, propertyId, pspec); |
| 115 | break; |
| 116 | } |
| 117 | } |
| 118 | |
| 119 | static void webkit_dom_client_rect_constructed(GObject* object) |
| 120 | { |
| 121 | G_OBJECT_CLASS(webkit_dom_client_rect_parent_class)->constructed(object); |
| 122 | |
| 123 | WebKitDOMClientRectPrivate* priv = WEBKIT_DOM_CLIENT_RECT_GET_PRIVATE(object); |
| 124 | priv->coreObject = static_cast<WebCore::DOMRect*>(WEBKIT_DOM_OBJECT(object)->coreObject); |
| 125 | WebKit::DOMObjectCache::put(priv->coreObject.get(), object); |
| 126 | } |
| 127 | |
| 128 | static void webkit_dom_client_rect_class_init(WebKitDOMClientRectClass* requestClass) |
| 129 | { |
| 130 | GObjectClass* gobjectClass = G_OBJECT_CLASS(requestClass); |
| 131 | g_type_class_add_private(gobjectClass, sizeof(WebKitDOMClientRectPrivate)); |
| 132 | gobjectClass->constructed = webkit_dom_client_rect_constructed; |
| 133 | gobjectClass->finalize = webkit_dom_client_rect_finalize; |
| 134 | gobjectClass->get_property = webkit_dom_client_rect_get_property; |
| 135 | |
| 136 | g_object_class_install_property( |
| 137 | gobjectClass, |
| 138 | DOM_CLIENT_RECT_PROP_TOP, |
| 139 | g_param_spec_float( |
| 140 | "top" , |
| 141 | "ClientRect:top" , |
| 142 | "read-only gfloat ClientRect:top" , |
| 143 | -G_MAXFLOAT, G_MAXFLOAT, 0, |
| 144 | WEBKIT_PARAM_READABLE)); |
| 145 | |
| 146 | g_object_class_install_property( |
| 147 | gobjectClass, |
| 148 | DOM_CLIENT_RECT_PROP_RIGHT, |
| 149 | g_param_spec_float( |
| 150 | "right" , |
| 151 | "ClientRect:right" , |
| 152 | "read-only gfloat ClientRect:right" , |
| 153 | -G_MAXFLOAT, G_MAXFLOAT, 0, |
| 154 | WEBKIT_PARAM_READABLE)); |
| 155 | |
| 156 | g_object_class_install_property( |
| 157 | gobjectClass, |
| 158 | DOM_CLIENT_RECT_PROP_BOTTOM, |
| 159 | g_param_spec_float( |
| 160 | "bottom" , |
| 161 | "ClientRect:bottom" , |
| 162 | "read-only gfloat ClientRect:bottom" , |
| 163 | -G_MAXFLOAT, G_MAXFLOAT, 0, |
| 164 | WEBKIT_PARAM_READABLE)); |
| 165 | |
| 166 | g_object_class_install_property( |
| 167 | gobjectClass, |
| 168 | DOM_CLIENT_RECT_PROP_LEFT, |
| 169 | g_param_spec_float( |
| 170 | "left" , |
| 171 | "ClientRect:left" , |
| 172 | "read-only gfloat ClientRect:left" , |
| 173 | -G_MAXFLOAT, G_MAXFLOAT, 0, |
| 174 | WEBKIT_PARAM_READABLE)); |
| 175 | |
| 176 | g_object_class_install_property( |
| 177 | gobjectClass, |
| 178 | DOM_CLIENT_RECT_PROP_WIDTH, |
| 179 | g_param_spec_float( |
| 180 | "width" , |
| 181 | "ClientRect:width" , |
| 182 | "read-only gfloat ClientRect:width" , |
| 183 | 0, G_MAXFLOAT, 0, |
| 184 | WEBKIT_PARAM_READABLE)); |
| 185 | |
| 186 | g_object_class_install_property( |
| 187 | gobjectClass, |
| 188 | DOM_CLIENT_RECT_PROP_HEIGHT, |
| 189 | g_param_spec_float( |
| 190 | "height" , |
| 191 | "ClientRect:height" , |
| 192 | "read-only gfloat ClientRect:height" , |
| 193 | 0, G_MAXFLOAT, 0, |
| 194 | WEBKIT_PARAM_READABLE)); |
| 195 | |
| 196 | } |
| 197 | |
| 198 | static void webkit_dom_client_rect_init(WebKitDOMClientRect* request) |
| 199 | { |
| 200 | WebKitDOMClientRectPrivate* priv = WEBKIT_DOM_CLIENT_RECT_GET_PRIVATE(request); |
| 201 | new (priv) WebKitDOMClientRectPrivate(); |
| 202 | } |
| 203 | |
| 204 | gfloat webkit_dom_client_rect_get_top(WebKitDOMClientRect* self) |
| 205 | { |
| 206 | WebCore::JSMainThreadNullState state; |
| 207 | g_return_val_if_fail(WEBKIT_DOM_IS_CLIENT_RECT(self), 0); |
| 208 | return WebKit::core(self)->top(); |
| 209 | } |
| 210 | |
| 211 | gfloat webkit_dom_client_rect_get_right(WebKitDOMClientRect* self) |
| 212 | { |
| 213 | WebCore::JSMainThreadNullState state; |
| 214 | g_return_val_if_fail(WEBKIT_DOM_IS_CLIENT_RECT(self), 0); |
| 215 | return WebKit::core(self)->right(); |
| 216 | } |
| 217 | |
| 218 | gfloat webkit_dom_client_rect_get_bottom(WebKitDOMClientRect* self) |
| 219 | { |
| 220 | WebCore::JSMainThreadNullState state; |
| 221 | g_return_val_if_fail(WEBKIT_DOM_IS_CLIENT_RECT(self), 0); |
| 222 | return WebKit::core(self)->bottom(); |
| 223 | } |
| 224 | |
| 225 | gfloat webkit_dom_client_rect_get_left(WebKitDOMClientRect* self) |
| 226 | { |
| 227 | WebCore::JSMainThreadNullState state; |
| 228 | g_return_val_if_fail(WEBKIT_DOM_IS_CLIENT_RECT(self), 0); |
| 229 | return WebKit::core(self)->left(); |
| 230 | } |
| 231 | |
| 232 | gfloat webkit_dom_client_rect_get_width(WebKitDOMClientRect* self) |
| 233 | { |
| 234 | WebCore::JSMainThreadNullState state; |
| 235 | g_return_val_if_fail(WEBKIT_DOM_IS_CLIENT_RECT(self), 0); |
| 236 | return WebKit::core(self)->width(); |
| 237 | } |
| 238 | |
| 239 | gfloat webkit_dom_client_rect_get_height(WebKitDOMClientRect* self) |
| 240 | { |
| 241 | WebCore::JSMainThreadNullState state; |
| 242 | g_return_val_if_fail(WEBKIT_DOM_IS_CLIENT_RECT(self), 0); |
| 243 | return WebKit::core(self)->height(); |
| 244 | } |
| 245 | G_GNUC_END_IGNORE_DEPRECATIONS; |
| 246 | |