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 "WebKitDOMHTMLTableSectionElement.h" |
22 | |
23 | #include <WebCore/CSSImportRule.h> |
24 | #include "DOMObjectCache.h" |
25 | #include <WebCore/DOMException.h> |
26 | #include <WebCore/Document.h> |
27 | #include "GObjectEventListener.h" |
28 | #include <WebCore/HTMLNames.h> |
29 | #include <WebCore/JSExecState.h> |
30 | #include "WebKitDOMEventPrivate.h" |
31 | #include "WebKitDOMEventTarget.h" |
32 | #include "WebKitDOMHTMLCollectionPrivate.h" |
33 | #include "WebKitDOMHTMLElementPrivate.h" |
34 | #include "WebKitDOMHTMLTableSectionElementPrivate.h" |
35 | #include "WebKitDOMNodePrivate.h" |
36 | #include "WebKitDOMPrivate.h" |
37 | #include "ConvertToUTF8String.h" |
38 | #include <wtf/GetPtr.h> |
39 | #include <wtf/RefPtr.h> |
40 | |
41 | G_GNUC_BEGIN_IGNORE_DEPRECATIONS; |
42 | |
43 | namespace WebKit { |
44 | |
45 | WebKitDOMHTMLTableSectionElement* kit(WebCore::HTMLTableSectionElement* obj) |
46 | { |
47 | return WEBKIT_DOM_HTML_TABLE_SECTION_ELEMENT(kit(static_cast<WebCore::Node*>(obj))); |
48 | } |
49 | |
50 | WebCore::HTMLTableSectionElement* core(WebKitDOMHTMLTableSectionElement* request) |
51 | { |
52 | return request ? static_cast<WebCore::HTMLTableSectionElement*>(WEBKIT_DOM_OBJECT(request)->coreObject) : 0; |
53 | } |
54 | |
55 | WebKitDOMHTMLTableSectionElement* wrapHTMLTableSectionElement(WebCore::HTMLTableSectionElement* coreObject) |
56 | { |
57 | ASSERT(coreObject); |
58 | return WEBKIT_DOM_HTML_TABLE_SECTION_ELEMENT(g_object_new(WEBKIT_DOM_TYPE_HTML_TABLE_SECTION_ELEMENT, "core-object" , coreObject, nullptr)); |
59 | } |
60 | |
61 | } // namespace WebKit |
62 | |
63 | static gboolean webkit_dom_html_table_section_element_dispatch_event(WebKitDOMEventTarget* target, WebKitDOMEvent* event, GError** error) |
64 | { |
65 | WebCore::Event* coreEvent = WebKit::core(event); |
66 | if (!coreEvent) |
67 | return false; |
68 | WebCore::HTMLTableSectionElement* coreTarget = static_cast<WebCore::HTMLTableSectionElement*>(WEBKIT_DOM_OBJECT(target)->coreObject); |
69 | |
70 | auto result = coreTarget->dispatchEventForBindings(*coreEvent); |
71 | if (result.hasException()) { |
72 | auto description = WebCore::DOMException::description(result.releaseException().code()); |
73 | g_set_error_literal(error, g_quark_from_string("WEBKIT_DOM" ), description.legacyCode, description.name); |
74 | return false; |
75 | } |
76 | return result.releaseReturnValue(); |
77 | } |
78 | |
79 | static gboolean webkit_dom_html_table_section_element_add_event_listener(WebKitDOMEventTarget* target, const char* eventName, GClosure* handler, gboolean useCapture) |
80 | { |
81 | WebCore::HTMLTableSectionElement* coreTarget = static_cast<WebCore::HTMLTableSectionElement*>(WEBKIT_DOM_OBJECT(target)->coreObject); |
82 | return WebKit::GObjectEventListener::addEventListener(G_OBJECT(target), coreTarget, eventName, handler, useCapture); |
83 | } |
84 | |
85 | static gboolean webkit_dom_html_table_section_element_remove_event_listener(WebKitDOMEventTarget* target, const char* eventName, GClosure* handler, gboolean useCapture) |
86 | { |
87 | WebCore::HTMLTableSectionElement* coreTarget = static_cast<WebCore::HTMLTableSectionElement*>(WEBKIT_DOM_OBJECT(target)->coreObject); |
88 | return WebKit::GObjectEventListener::removeEventListener(G_OBJECT(target), coreTarget, eventName, handler, useCapture); |
89 | } |
90 | |
91 | static void webkit_dom_html_table_section_element_dom_event_target_init(WebKitDOMEventTargetIface* iface) |
92 | { |
93 | iface->dispatch_event = webkit_dom_html_table_section_element_dispatch_event; |
94 | iface->add_event_listener = webkit_dom_html_table_section_element_add_event_listener; |
95 | iface->remove_event_listener = webkit_dom_html_table_section_element_remove_event_listener; |
96 | } |
97 | |
98 | G_DEFINE_TYPE_WITH_CODE(WebKitDOMHTMLTableSectionElement, webkit_dom_html_table_section_element, WEBKIT_DOM_TYPE_HTML_ELEMENT, G_IMPLEMENT_INTERFACE(WEBKIT_DOM_TYPE_EVENT_TARGET, webkit_dom_html_table_section_element_dom_event_target_init)) |
99 | |
100 | enum { |
101 | DOM_HTML_TABLE_SECTION_ELEMENT_PROP_0, |
102 | DOM_HTML_TABLE_SECTION_ELEMENT_PROP_ALIGN, |
103 | DOM_HTML_TABLE_SECTION_ELEMENT_PROP_CH, |
104 | DOM_HTML_TABLE_SECTION_ELEMENT_PROP_CH_OFF, |
105 | DOM_HTML_TABLE_SECTION_ELEMENT_PROP_V_ALIGN, |
106 | DOM_HTML_TABLE_SECTION_ELEMENT_PROP_ROWS, |
107 | }; |
108 | |
109 | static void webkit_dom_html_table_section_element_set_property(GObject* object, guint propertyId, const GValue* value, GParamSpec* pspec) |
110 | { |
111 | WebKitDOMHTMLTableSectionElement* self = WEBKIT_DOM_HTML_TABLE_SECTION_ELEMENT(object); |
112 | |
113 | switch (propertyId) { |
114 | case DOM_HTML_TABLE_SECTION_ELEMENT_PROP_ALIGN: |
115 | webkit_dom_html_table_section_element_set_align(self, g_value_get_string(value)); |
116 | break; |
117 | case DOM_HTML_TABLE_SECTION_ELEMENT_PROP_CH: |
118 | webkit_dom_html_table_section_element_set_ch(self, g_value_get_string(value)); |
119 | break; |
120 | case DOM_HTML_TABLE_SECTION_ELEMENT_PROP_CH_OFF: |
121 | webkit_dom_html_table_section_element_set_ch_off(self, g_value_get_string(value)); |
122 | break; |
123 | case DOM_HTML_TABLE_SECTION_ELEMENT_PROP_V_ALIGN: |
124 | webkit_dom_html_table_section_element_set_v_align(self, g_value_get_string(value)); |
125 | break; |
126 | default: |
127 | G_OBJECT_WARN_INVALID_PROPERTY_ID(object, propertyId, pspec); |
128 | break; |
129 | } |
130 | } |
131 | |
132 | static void webkit_dom_html_table_section_element_get_property(GObject* object, guint propertyId, GValue* value, GParamSpec* pspec) |
133 | { |
134 | WebKitDOMHTMLTableSectionElement* self = WEBKIT_DOM_HTML_TABLE_SECTION_ELEMENT(object); |
135 | |
136 | switch (propertyId) { |
137 | case DOM_HTML_TABLE_SECTION_ELEMENT_PROP_ALIGN: |
138 | g_value_take_string(value, webkit_dom_html_table_section_element_get_align(self)); |
139 | break; |
140 | case DOM_HTML_TABLE_SECTION_ELEMENT_PROP_CH: |
141 | g_value_take_string(value, webkit_dom_html_table_section_element_get_ch(self)); |
142 | break; |
143 | case DOM_HTML_TABLE_SECTION_ELEMENT_PROP_CH_OFF: |
144 | g_value_take_string(value, webkit_dom_html_table_section_element_get_ch_off(self)); |
145 | break; |
146 | case DOM_HTML_TABLE_SECTION_ELEMENT_PROP_V_ALIGN: |
147 | g_value_take_string(value, webkit_dom_html_table_section_element_get_v_align(self)); |
148 | break; |
149 | case DOM_HTML_TABLE_SECTION_ELEMENT_PROP_ROWS: |
150 | g_value_set_object(value, webkit_dom_html_table_section_element_get_rows(self)); |
151 | break; |
152 | default: |
153 | G_OBJECT_WARN_INVALID_PROPERTY_ID(object, propertyId, pspec); |
154 | break; |
155 | } |
156 | } |
157 | |
158 | static void webkit_dom_html_table_section_element_class_init(WebKitDOMHTMLTableSectionElementClass* requestClass) |
159 | { |
160 | GObjectClass* gobjectClass = G_OBJECT_CLASS(requestClass); |
161 | gobjectClass->set_property = webkit_dom_html_table_section_element_set_property; |
162 | gobjectClass->get_property = webkit_dom_html_table_section_element_get_property; |
163 | |
164 | g_object_class_install_property( |
165 | gobjectClass, |
166 | DOM_HTML_TABLE_SECTION_ELEMENT_PROP_ALIGN, |
167 | g_param_spec_string( |
168 | "align" , |
169 | "HTMLTableSectionElement:align" , |
170 | "read-write gchar* HTMLTableSectionElement:align" , |
171 | "" , |
172 | WEBKIT_PARAM_READWRITE)); |
173 | |
174 | g_object_class_install_property( |
175 | gobjectClass, |
176 | DOM_HTML_TABLE_SECTION_ELEMENT_PROP_CH, |
177 | g_param_spec_string( |
178 | "ch" , |
179 | "HTMLTableSectionElement:ch" , |
180 | "read-write gchar* HTMLTableSectionElement:ch" , |
181 | "" , |
182 | WEBKIT_PARAM_READWRITE)); |
183 | |
184 | g_object_class_install_property( |
185 | gobjectClass, |
186 | DOM_HTML_TABLE_SECTION_ELEMENT_PROP_CH_OFF, |
187 | g_param_spec_string( |
188 | "ch-off" , |
189 | "HTMLTableSectionElement:ch-off" , |
190 | "read-write gchar* HTMLTableSectionElement:ch-off" , |
191 | "" , |
192 | WEBKIT_PARAM_READWRITE)); |
193 | |
194 | g_object_class_install_property( |
195 | gobjectClass, |
196 | DOM_HTML_TABLE_SECTION_ELEMENT_PROP_V_ALIGN, |
197 | g_param_spec_string( |
198 | "v-align" , |
199 | "HTMLTableSectionElement:v-align" , |
200 | "read-write gchar* HTMLTableSectionElement:v-align" , |
201 | "" , |
202 | WEBKIT_PARAM_READWRITE)); |
203 | |
204 | g_object_class_install_property( |
205 | gobjectClass, |
206 | DOM_HTML_TABLE_SECTION_ELEMENT_PROP_ROWS, |
207 | g_param_spec_object( |
208 | "rows" , |
209 | "HTMLTableSectionElement:rows" , |
210 | "read-only WebKitDOMHTMLCollection* HTMLTableSectionElement:rows" , |
211 | WEBKIT_DOM_TYPE_HTML_COLLECTION, |
212 | WEBKIT_PARAM_READABLE)); |
213 | |
214 | } |
215 | |
216 | static void webkit_dom_html_table_section_element_init(WebKitDOMHTMLTableSectionElement* request) |
217 | { |
218 | UNUSED_PARAM(request); |
219 | } |
220 | |
221 | WebKitDOMHTMLElement* webkit_dom_html_table_section_element_insert_row(WebKitDOMHTMLTableSectionElement* self, glong index, GError** error) |
222 | { |
223 | WebCore::JSMainThreadNullState state; |
224 | g_return_val_if_fail(WEBKIT_DOM_IS_HTML_TABLE_SECTION_ELEMENT(self), 0); |
225 | g_return_val_if_fail(!error || !*error, 0); |
226 | WebCore::HTMLTableSectionElement* item = WebKit::core(self); |
227 | auto result = item->insertRow(index); |
228 | if (result.hasException()) { |
229 | auto description = WebCore::DOMException::description(result.releaseException().code()); |
230 | g_set_error_literal(error, g_quark_from_string("WEBKIT_DOM" ), description.legacyCode, description.name); |
231 | } |
232 | return WebKit::kit(result.releaseReturnValue().ptr()); |
233 | } |
234 | |
235 | void webkit_dom_html_table_section_element_delete_row(WebKitDOMHTMLTableSectionElement* self, glong index, GError** error) |
236 | { |
237 | WebCore::JSMainThreadNullState state; |
238 | g_return_if_fail(WEBKIT_DOM_IS_HTML_TABLE_SECTION_ELEMENT(self)); |
239 | g_return_if_fail(!error || !*error); |
240 | WebCore::HTMLTableSectionElement* item = WebKit::core(self); |
241 | auto result = item->deleteRow(index); |
242 | if (result.hasException()) { |
243 | auto description = WebCore::DOMException::description(result.releaseException().code()); |
244 | g_set_error_literal(error, g_quark_from_string("WEBKIT_DOM" ), description.legacyCode, description.name); |
245 | } |
246 | } |
247 | |
248 | gchar* webkit_dom_html_table_section_element_get_align(WebKitDOMHTMLTableSectionElement* self) |
249 | { |
250 | WebCore::JSMainThreadNullState state; |
251 | g_return_val_if_fail(WEBKIT_DOM_IS_HTML_TABLE_SECTION_ELEMENT(self), 0); |
252 | WebCore::HTMLTableSectionElement* item = WebKit::core(self); |
253 | gchar* result = convertToUTF8String(item->attributeWithoutSynchronization(WebCore::HTMLNames::alignAttr)); |
254 | return result; |
255 | } |
256 | |
257 | void webkit_dom_html_table_section_element_set_align(WebKitDOMHTMLTableSectionElement* self, const gchar* value) |
258 | { |
259 | WebCore::JSMainThreadNullState state; |
260 | g_return_if_fail(WEBKIT_DOM_IS_HTML_TABLE_SECTION_ELEMENT(self)); |
261 | g_return_if_fail(value); |
262 | WebCore::HTMLTableSectionElement* item = WebKit::core(self); |
263 | WTF::String convertedValue = WTF::String::fromUTF8(value); |
264 | item->setAttributeWithoutSynchronization(WebCore::HTMLNames::alignAttr, convertedValue); |
265 | } |
266 | |
267 | gchar* webkit_dom_html_table_section_element_get_ch(WebKitDOMHTMLTableSectionElement* self) |
268 | { |
269 | WebCore::JSMainThreadNullState state; |
270 | g_return_val_if_fail(WEBKIT_DOM_IS_HTML_TABLE_SECTION_ELEMENT(self), 0); |
271 | WebCore::HTMLTableSectionElement* item = WebKit::core(self); |
272 | gchar* result = convertToUTF8String(item->attributeWithoutSynchronization(WebCore::HTMLNames::charAttr)); |
273 | return result; |
274 | } |
275 | |
276 | void webkit_dom_html_table_section_element_set_ch(WebKitDOMHTMLTableSectionElement* self, const gchar* value) |
277 | { |
278 | WebCore::JSMainThreadNullState state; |
279 | g_return_if_fail(WEBKIT_DOM_IS_HTML_TABLE_SECTION_ELEMENT(self)); |
280 | g_return_if_fail(value); |
281 | WebCore::HTMLTableSectionElement* item = WebKit::core(self); |
282 | WTF::String convertedValue = WTF::String::fromUTF8(value); |
283 | item->setAttributeWithoutSynchronization(WebCore::HTMLNames::charAttr, convertedValue); |
284 | } |
285 | |
286 | gchar* webkit_dom_html_table_section_element_get_ch_off(WebKitDOMHTMLTableSectionElement* self) |
287 | { |
288 | WebCore::JSMainThreadNullState state; |
289 | g_return_val_if_fail(WEBKIT_DOM_IS_HTML_TABLE_SECTION_ELEMENT(self), 0); |
290 | WebCore::HTMLTableSectionElement* item = WebKit::core(self); |
291 | gchar* result = convertToUTF8String(item->attributeWithoutSynchronization(WebCore::HTMLNames::charoffAttr)); |
292 | return result; |
293 | } |
294 | |
295 | void webkit_dom_html_table_section_element_set_ch_off(WebKitDOMHTMLTableSectionElement* self, const gchar* value) |
296 | { |
297 | WebCore::JSMainThreadNullState state; |
298 | g_return_if_fail(WEBKIT_DOM_IS_HTML_TABLE_SECTION_ELEMENT(self)); |
299 | g_return_if_fail(value); |
300 | WebCore::HTMLTableSectionElement* item = WebKit::core(self); |
301 | WTF::String convertedValue = WTF::String::fromUTF8(value); |
302 | item->setAttributeWithoutSynchronization(WebCore::HTMLNames::charoffAttr, convertedValue); |
303 | } |
304 | |
305 | gchar* webkit_dom_html_table_section_element_get_v_align(WebKitDOMHTMLTableSectionElement* self) |
306 | { |
307 | WebCore::JSMainThreadNullState state; |
308 | g_return_val_if_fail(WEBKIT_DOM_IS_HTML_TABLE_SECTION_ELEMENT(self), 0); |
309 | WebCore::HTMLTableSectionElement* item = WebKit::core(self); |
310 | gchar* result = convertToUTF8String(item->attributeWithoutSynchronization(WebCore::HTMLNames::valignAttr)); |
311 | return result; |
312 | } |
313 | |
314 | void webkit_dom_html_table_section_element_set_v_align(WebKitDOMHTMLTableSectionElement* self, const gchar* value) |
315 | { |
316 | WebCore::JSMainThreadNullState state; |
317 | g_return_if_fail(WEBKIT_DOM_IS_HTML_TABLE_SECTION_ELEMENT(self)); |
318 | g_return_if_fail(value); |
319 | WebCore::HTMLTableSectionElement* item = WebKit::core(self); |
320 | WTF::String convertedValue = WTF::String::fromUTF8(value); |
321 | item->setAttributeWithoutSynchronization(WebCore::HTMLNames::valignAttr, convertedValue); |
322 | } |
323 | |
324 | WebKitDOMHTMLCollection* webkit_dom_html_table_section_element_get_rows(WebKitDOMHTMLTableSectionElement* self) |
325 | { |
326 | WebCore::JSMainThreadNullState state; |
327 | g_return_val_if_fail(WEBKIT_DOM_IS_HTML_TABLE_SECTION_ELEMENT(self), 0); |
328 | WebCore::HTMLTableSectionElement* item = WebKit::core(self); |
329 | RefPtr<WebCore::HTMLCollection> gobjectResult = WTF::getPtr(item->rows()); |
330 | return WebKit::kit(gobjectResult.get()); |
331 | } |
332 | |
333 | G_GNUC_END_IGNORE_DEPRECATIONS; |
334 | |