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 "WebKitDOMClientRectList.h" |
22 | |
23 | #include "ConvertToUTF8String.h" |
24 | #include "DOMObjectCache.h" |
25 | #include "WebKitDOMClientRectListPrivate.h" |
26 | #include "WebKitDOMClientRectPrivate.h" |
27 | #include "WebKitDOMPrivate.h" |
28 | #include <WebCore/CSSImportRule.h> |
29 | #include <WebCore/Document.h> |
30 | #include <WebCore/ExceptionCode.h> |
31 | #include <WebCore/JSExecState.h> |
32 | #include <wtf/GetPtr.h> |
33 | #include <wtf/RefPtr.h> |
34 | |
35 | #define WEBKIT_DOM_CLIENT_RECT_LIST_GET_PRIVATE(obj) G_TYPE_INSTANCE_GET_PRIVATE(obj, WEBKIT_DOM_TYPE_CLIENT_RECT_LIST, WebKitDOMClientRectListPrivate) |
36 | |
37 | typedef struct _WebKitDOMClientRectListPrivate { |
38 | RefPtr<WebCore::DOMRectList> coreObject; |
39 | } WebKitDOMClientRectListPrivate; |
40 | |
41 | G_GNUC_BEGIN_IGNORE_DEPRECATIONS; |
42 | |
43 | namespace WebKit { |
44 | |
45 | WebKitDOMClientRectList* kit(WebCore::DOMRectList* obj) |
46 | { |
47 | if (!obj) |
48 | return nullptr; |
49 | |
50 | if (gpointer ret = DOMObjectCache::get(obj)) |
51 | return WEBKIT_DOM_CLIENT_RECT_LIST(ret); |
52 | |
53 | return wrapDOMRectList(obj); |
54 | } |
55 | |
56 | WebCore::DOMRectList* core(WebKitDOMClientRectList* request) |
57 | { |
58 | return request ? static_cast<WebCore::DOMRectList*>(WEBKIT_DOM_OBJECT(request)->coreObject) : nullptr; |
59 | } |
60 | |
61 | WebKitDOMClientRectList* wrapDOMRectList(WebCore::DOMRectList* coreObject) |
62 | { |
63 | return WEBKIT_DOM_CLIENT_RECT_LIST(g_object_new(WEBKIT_DOM_TYPE_CLIENT_RECT_LIST, "core-object" , coreObject, nullptr)); |
64 | } |
65 | |
66 | } // namespace WebKit |
67 | |
68 | G_DEFINE_TYPE(WebKitDOMClientRectList, webkit_dom_client_rect_list, WEBKIT_DOM_TYPE_OBJECT) |
69 | |
70 | enum { |
71 | DOM_CLIENT_RECT_LIST_PROP_0, |
72 | DOM_CLIENT_RECT_LIST_PROP_LENGTH, |
73 | }; |
74 | |
75 | static void webkit_dom_client_rect_list_finalize(GObject* object) |
76 | { |
77 | WebKitDOMClientRectListPrivate* priv = WEBKIT_DOM_CLIENT_RECT_LIST_GET_PRIVATE(object); |
78 | |
79 | WebKit::DOMObjectCache::forget(priv->coreObject.get()); |
80 | |
81 | priv->~WebKitDOMClientRectListPrivate(); |
82 | G_OBJECT_CLASS(webkit_dom_client_rect_list_parent_class)->finalize(object); |
83 | } |
84 | |
85 | static void webkit_dom_client_rect_list_get_property(GObject* object, guint propertyId, GValue* value, GParamSpec* pspec) |
86 | { |
87 | WebKitDOMClientRectList* self = WEBKIT_DOM_CLIENT_RECT_LIST(object); |
88 | |
89 | switch (propertyId) { |
90 | case DOM_CLIENT_RECT_LIST_PROP_LENGTH: |
91 | g_value_set_ulong(value, webkit_dom_client_rect_list_get_length(self)); |
92 | break; |
93 | default: |
94 | G_OBJECT_WARN_INVALID_PROPERTY_ID(object, propertyId, pspec); |
95 | break; |
96 | } |
97 | } |
98 | |
99 | static void webkit_dom_client_rect_list_constructed(GObject* object) |
100 | { |
101 | G_OBJECT_CLASS(webkit_dom_client_rect_list_parent_class)->constructed(object); |
102 | |
103 | WebKitDOMClientRectListPrivate* priv = WEBKIT_DOM_CLIENT_RECT_LIST_GET_PRIVATE(object); |
104 | priv->coreObject = static_cast<WebCore::DOMRectList*>(WEBKIT_DOM_OBJECT(object)->coreObject); |
105 | WebKit::DOMObjectCache::put(priv->coreObject.get(), object); |
106 | } |
107 | |
108 | static void webkit_dom_client_rect_list_class_init(WebKitDOMClientRectListClass* requestClass) |
109 | { |
110 | GObjectClass* gobjectClass = G_OBJECT_CLASS(requestClass); |
111 | g_type_class_add_private(gobjectClass, sizeof(WebKitDOMClientRectListPrivate)); |
112 | gobjectClass->constructed = webkit_dom_client_rect_list_constructed; |
113 | gobjectClass->finalize = webkit_dom_client_rect_list_finalize; |
114 | gobjectClass->get_property = webkit_dom_client_rect_list_get_property; |
115 | |
116 | g_object_class_install_property( |
117 | gobjectClass, |
118 | DOM_CLIENT_RECT_LIST_PROP_LENGTH, |
119 | g_param_spec_ulong( |
120 | "length" , |
121 | "ClientRectList:length" , |
122 | "read-only gulong ClientRectList:length" , |
123 | 0, G_MAXULONG, 0, |
124 | WEBKIT_PARAM_READABLE)); |
125 | |
126 | } |
127 | |
128 | static void webkit_dom_client_rect_list_init(WebKitDOMClientRectList* request) |
129 | { |
130 | WebKitDOMClientRectListPrivate* priv = WEBKIT_DOM_CLIENT_RECT_LIST_GET_PRIVATE(request); |
131 | new (priv) WebKitDOMClientRectListPrivate(); |
132 | } |
133 | |
134 | WebKitDOMClientRect* webkit_dom_client_rect_list_item(WebKitDOMClientRectList* self, gulong index) |
135 | { |
136 | WebCore::JSMainThreadNullState state; |
137 | g_return_val_if_fail(WEBKIT_DOM_IS_CLIENT_RECT_LIST(self), nullptr); |
138 | auto* list = WebKit::core(self); |
139 | RefPtr<WebCore::DOMRect> gobjectResult = WTF::getPtr(list->item(index)); |
140 | return WebKit::kit(gobjectResult.get()); |
141 | } |
142 | |
143 | gulong webkit_dom_client_rect_list_get_length(WebKitDOMClientRectList* self) |
144 | { |
145 | WebCore::JSMainThreadNullState state; |
146 | g_return_val_if_fail(WEBKIT_DOM_IS_CLIENT_RECT_LIST(self), 0); |
147 | return WebKit::core(self)->length(); |
148 | } |
149 | G_GNUC_END_IGNORE_DEPRECATIONS; |
150 | |