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 "WebKitDOMHTMLTableRowElement.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 "WebKitDOMHTMLTableRowElementPrivate.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 | WebKitDOMHTMLTableRowElement* kit(WebCore::HTMLTableRowElement* obj) |
46 | { |
47 | return WEBKIT_DOM_HTML_TABLE_ROW_ELEMENT(kit(static_cast<WebCore::Node*>(obj))); |
48 | } |
49 | |
50 | WebCore::HTMLTableRowElement* core(WebKitDOMHTMLTableRowElement* request) |
51 | { |
52 | return request ? static_cast<WebCore::HTMLTableRowElement*>(WEBKIT_DOM_OBJECT(request)->coreObject) : 0; |
53 | } |
54 | |
55 | WebKitDOMHTMLTableRowElement* wrapHTMLTableRowElement(WebCore::HTMLTableRowElement* coreObject) |
56 | { |
57 | ASSERT(coreObject); |
58 | return WEBKIT_DOM_HTML_TABLE_ROW_ELEMENT(g_object_new(WEBKIT_DOM_TYPE_HTML_TABLE_ROW_ELEMENT, "core-object" , coreObject, nullptr)); |
59 | } |
60 | |
61 | } // namespace WebKit |
62 | |
63 | static gboolean webkit_dom_html_table_row_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::HTMLTableRowElement* coreTarget = static_cast<WebCore::HTMLTableRowElement*>(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_row_element_add_event_listener(WebKitDOMEventTarget* target, const char* eventName, GClosure* handler, gboolean useCapture) |
80 | { |
81 | WebCore::HTMLTableRowElement* coreTarget = static_cast<WebCore::HTMLTableRowElement*>(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_row_element_remove_event_listener(WebKitDOMEventTarget* target, const char* eventName, GClosure* handler, gboolean useCapture) |
86 | { |
87 | WebCore::HTMLTableRowElement* coreTarget = static_cast<WebCore::HTMLTableRowElement*>(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_row_element_dom_event_target_init(WebKitDOMEventTargetIface* iface) |
92 | { |
93 | iface->dispatch_event = webkit_dom_html_table_row_element_dispatch_event; |
94 | iface->add_event_listener = webkit_dom_html_table_row_element_add_event_listener; |
95 | iface->remove_event_listener = webkit_dom_html_table_row_element_remove_event_listener; |
96 | } |
97 | |
98 | G_DEFINE_TYPE_WITH_CODE(WebKitDOMHTMLTableRowElement, webkit_dom_html_table_row_element, WEBKIT_DOM_TYPE_HTML_ELEMENT, G_IMPLEMENT_INTERFACE(WEBKIT_DOM_TYPE_EVENT_TARGET, webkit_dom_html_table_row_element_dom_event_target_init)) |
99 | |
100 | enum { |
101 | DOM_HTML_TABLE_ROW_ELEMENT_PROP_0, |
102 | DOM_HTML_TABLE_ROW_ELEMENT_PROP_ROW_INDEX, |
103 | DOM_HTML_TABLE_ROW_ELEMENT_PROP_SECTION_ROW_INDEX, |
104 | DOM_HTML_TABLE_ROW_ELEMENT_PROP_CELLS, |
105 | DOM_HTML_TABLE_ROW_ELEMENT_PROP_ALIGN, |
106 | DOM_HTML_TABLE_ROW_ELEMENT_PROP_BG_COLOR, |
107 | DOM_HTML_TABLE_ROW_ELEMENT_PROP_CH, |
108 | DOM_HTML_TABLE_ROW_ELEMENT_PROP_CH_OFF, |
109 | DOM_HTML_TABLE_ROW_ELEMENT_PROP_V_ALIGN, |
110 | }; |
111 | |
112 | static void webkit_dom_html_table_row_element_set_property(GObject* object, guint propertyId, const GValue* value, GParamSpec* pspec) |
113 | { |
114 | WebKitDOMHTMLTableRowElement* self = WEBKIT_DOM_HTML_TABLE_ROW_ELEMENT(object); |
115 | |
116 | switch (propertyId) { |
117 | case DOM_HTML_TABLE_ROW_ELEMENT_PROP_ALIGN: |
118 | webkit_dom_html_table_row_element_set_align(self, g_value_get_string(value)); |
119 | break; |
120 | case DOM_HTML_TABLE_ROW_ELEMENT_PROP_BG_COLOR: |
121 | webkit_dom_html_table_row_element_set_bg_color(self, g_value_get_string(value)); |
122 | break; |
123 | case DOM_HTML_TABLE_ROW_ELEMENT_PROP_CH: |
124 | webkit_dom_html_table_row_element_set_ch(self, g_value_get_string(value)); |
125 | break; |
126 | case DOM_HTML_TABLE_ROW_ELEMENT_PROP_CH_OFF: |
127 | webkit_dom_html_table_row_element_set_ch_off(self, g_value_get_string(value)); |
128 | break; |
129 | case DOM_HTML_TABLE_ROW_ELEMENT_PROP_V_ALIGN: |
130 | webkit_dom_html_table_row_element_set_v_align(self, g_value_get_string(value)); |
131 | break; |
132 | default: |
133 | G_OBJECT_WARN_INVALID_PROPERTY_ID(object, propertyId, pspec); |
134 | break; |
135 | } |
136 | } |
137 | |
138 | static void webkit_dom_html_table_row_element_get_property(GObject* object, guint propertyId, GValue* value, GParamSpec* pspec) |
139 | { |
140 | WebKitDOMHTMLTableRowElement* self = WEBKIT_DOM_HTML_TABLE_ROW_ELEMENT(object); |
141 | |
142 | switch (propertyId) { |
143 | case DOM_HTML_TABLE_ROW_ELEMENT_PROP_ROW_INDEX: |
144 | g_value_set_long(value, webkit_dom_html_table_row_element_get_row_index(self)); |
145 | break; |
146 | case DOM_HTML_TABLE_ROW_ELEMENT_PROP_SECTION_ROW_INDEX: |
147 | g_value_set_long(value, webkit_dom_html_table_row_element_get_section_row_index(self)); |
148 | break; |
149 | case DOM_HTML_TABLE_ROW_ELEMENT_PROP_CELLS: |
150 | g_value_set_object(value, webkit_dom_html_table_row_element_get_cells(self)); |
151 | break; |
152 | case DOM_HTML_TABLE_ROW_ELEMENT_PROP_ALIGN: |
153 | g_value_take_string(value, webkit_dom_html_table_row_element_get_align(self)); |
154 | break; |
155 | case DOM_HTML_TABLE_ROW_ELEMENT_PROP_BG_COLOR: |
156 | g_value_take_string(value, webkit_dom_html_table_row_element_get_bg_color(self)); |
157 | break; |
158 | case DOM_HTML_TABLE_ROW_ELEMENT_PROP_CH: |
159 | g_value_take_string(value, webkit_dom_html_table_row_element_get_ch(self)); |
160 | break; |
161 | case DOM_HTML_TABLE_ROW_ELEMENT_PROP_CH_OFF: |
162 | g_value_take_string(value, webkit_dom_html_table_row_element_get_ch_off(self)); |
163 | break; |
164 | case DOM_HTML_TABLE_ROW_ELEMENT_PROP_V_ALIGN: |
165 | g_value_take_string(value, webkit_dom_html_table_row_element_get_v_align(self)); |
166 | break; |
167 | default: |
168 | G_OBJECT_WARN_INVALID_PROPERTY_ID(object, propertyId, pspec); |
169 | break; |
170 | } |
171 | } |
172 | |
173 | static void webkit_dom_html_table_row_element_class_init(WebKitDOMHTMLTableRowElementClass* requestClass) |
174 | { |
175 | GObjectClass* gobjectClass = G_OBJECT_CLASS(requestClass); |
176 | gobjectClass->set_property = webkit_dom_html_table_row_element_set_property; |
177 | gobjectClass->get_property = webkit_dom_html_table_row_element_get_property; |
178 | |
179 | g_object_class_install_property( |
180 | gobjectClass, |
181 | DOM_HTML_TABLE_ROW_ELEMENT_PROP_ROW_INDEX, |
182 | g_param_spec_long( |
183 | "row-index" , |
184 | "HTMLTableRowElement:row-index" , |
185 | "read-only glong HTMLTableRowElement:row-index" , |
186 | G_MINLONG, G_MAXLONG, 0, |
187 | WEBKIT_PARAM_READABLE)); |
188 | |
189 | g_object_class_install_property( |
190 | gobjectClass, |
191 | DOM_HTML_TABLE_ROW_ELEMENT_PROP_SECTION_ROW_INDEX, |
192 | g_param_spec_long( |
193 | "section-row-index" , |
194 | "HTMLTableRowElement:section-row-index" , |
195 | "read-only glong HTMLTableRowElement:section-row-index" , |
196 | G_MINLONG, G_MAXLONG, 0, |
197 | WEBKIT_PARAM_READABLE)); |
198 | |
199 | g_object_class_install_property( |
200 | gobjectClass, |
201 | DOM_HTML_TABLE_ROW_ELEMENT_PROP_CELLS, |
202 | g_param_spec_object( |
203 | "cells" , |
204 | "HTMLTableRowElement:cells" , |
205 | "read-only WebKitDOMHTMLCollection* HTMLTableRowElement:cells" , |
206 | WEBKIT_DOM_TYPE_HTML_COLLECTION, |
207 | WEBKIT_PARAM_READABLE)); |
208 | |
209 | g_object_class_install_property( |
210 | gobjectClass, |
211 | DOM_HTML_TABLE_ROW_ELEMENT_PROP_ALIGN, |
212 | g_param_spec_string( |
213 | "align" , |
214 | "HTMLTableRowElement:align" , |
215 | "read-write gchar* HTMLTableRowElement:align" , |
216 | "" , |
217 | WEBKIT_PARAM_READWRITE)); |
218 | |
219 | g_object_class_install_property( |
220 | gobjectClass, |
221 | DOM_HTML_TABLE_ROW_ELEMENT_PROP_BG_COLOR, |
222 | g_param_spec_string( |
223 | "bg-color" , |
224 | "HTMLTableRowElement:bg-color" , |
225 | "read-write gchar* HTMLTableRowElement:bg-color" , |
226 | "" , |
227 | WEBKIT_PARAM_READWRITE)); |
228 | |
229 | g_object_class_install_property( |
230 | gobjectClass, |
231 | DOM_HTML_TABLE_ROW_ELEMENT_PROP_CH, |
232 | g_param_spec_string( |
233 | "ch" , |
234 | "HTMLTableRowElement:ch" , |
235 | "read-write gchar* HTMLTableRowElement:ch" , |
236 | "" , |
237 | WEBKIT_PARAM_READWRITE)); |
238 | |
239 | g_object_class_install_property( |
240 | gobjectClass, |
241 | DOM_HTML_TABLE_ROW_ELEMENT_PROP_CH_OFF, |
242 | g_param_spec_string( |
243 | "ch-off" , |
244 | "HTMLTableRowElement:ch-off" , |
245 | "read-write gchar* HTMLTableRowElement:ch-off" , |
246 | "" , |
247 | WEBKIT_PARAM_READWRITE)); |
248 | |
249 | g_object_class_install_property( |
250 | gobjectClass, |
251 | DOM_HTML_TABLE_ROW_ELEMENT_PROP_V_ALIGN, |
252 | g_param_spec_string( |
253 | "v-align" , |
254 | "HTMLTableRowElement:v-align" , |
255 | "read-write gchar* HTMLTableRowElement:v-align" , |
256 | "" , |
257 | WEBKIT_PARAM_READWRITE)); |
258 | |
259 | } |
260 | |
261 | static void webkit_dom_html_table_row_element_init(WebKitDOMHTMLTableRowElement* request) |
262 | { |
263 | UNUSED_PARAM(request); |
264 | } |
265 | |
266 | WebKitDOMHTMLElement* webkit_dom_html_table_row_element_insert_cell(WebKitDOMHTMLTableRowElement* self, glong index, GError** error) |
267 | { |
268 | WebCore::JSMainThreadNullState state; |
269 | g_return_val_if_fail(WEBKIT_DOM_IS_HTML_TABLE_ROW_ELEMENT(self), 0); |
270 | g_return_val_if_fail(!error || !*error, 0); |
271 | WebCore::HTMLTableRowElement* item = WebKit::core(self); |
272 | auto result = item->insertCell(index); |
273 | if (result.hasException()) { |
274 | auto description = WebCore::DOMException::description(result.releaseException().code()); |
275 | g_set_error_literal(error, g_quark_from_string("WEBKIT_DOM" ), description.legacyCode, description.name); |
276 | return nullptr; |
277 | } |
278 | return WEBKIT_DOM_HTML_ELEMENT(WebKit::kit(result.releaseReturnValue().ptr())); |
279 | } |
280 | |
281 | void webkit_dom_html_table_row_element_delete_cell(WebKitDOMHTMLTableRowElement* self, glong index, GError** error) |
282 | { |
283 | WebCore::JSMainThreadNullState state; |
284 | g_return_if_fail(WEBKIT_DOM_IS_HTML_TABLE_ROW_ELEMENT(self)); |
285 | g_return_if_fail(!error || !*error); |
286 | WebCore::HTMLTableRowElement* item = WebKit::core(self); |
287 | auto result = item->deleteCell(index); |
288 | if (result.hasException()) { |
289 | auto description = WebCore::DOMException::description(result.releaseException().code()); |
290 | g_set_error_literal(error, g_quark_from_string("WEBKIT_DOM" ), description.legacyCode, description.name); |
291 | } |
292 | } |
293 | |
294 | glong webkit_dom_html_table_row_element_get_row_index(WebKitDOMHTMLTableRowElement* self) |
295 | { |
296 | WebCore::JSMainThreadNullState state; |
297 | g_return_val_if_fail(WEBKIT_DOM_IS_HTML_TABLE_ROW_ELEMENT(self), 0); |
298 | WebCore::HTMLTableRowElement* item = WebKit::core(self); |
299 | glong result = item->rowIndex(); |
300 | return result; |
301 | } |
302 | |
303 | glong webkit_dom_html_table_row_element_get_section_row_index(WebKitDOMHTMLTableRowElement* self) |
304 | { |
305 | WebCore::JSMainThreadNullState state; |
306 | g_return_val_if_fail(WEBKIT_DOM_IS_HTML_TABLE_ROW_ELEMENT(self), 0); |
307 | WebCore::HTMLTableRowElement* item = WebKit::core(self); |
308 | glong result = item->sectionRowIndex(); |
309 | return result; |
310 | } |
311 | |
312 | WebKitDOMHTMLCollection* webkit_dom_html_table_row_element_get_cells(WebKitDOMHTMLTableRowElement* self) |
313 | { |
314 | WebCore::JSMainThreadNullState state; |
315 | g_return_val_if_fail(WEBKIT_DOM_IS_HTML_TABLE_ROW_ELEMENT(self), 0); |
316 | WebCore::HTMLTableRowElement* item = WebKit::core(self); |
317 | RefPtr<WebCore::HTMLCollection> gobjectResult = WTF::getPtr(item->cells()); |
318 | return WebKit::kit(gobjectResult.get()); |
319 | } |
320 | |
321 | gchar* webkit_dom_html_table_row_element_get_align(WebKitDOMHTMLTableRowElement* self) |
322 | { |
323 | WebCore::JSMainThreadNullState state; |
324 | g_return_val_if_fail(WEBKIT_DOM_IS_HTML_TABLE_ROW_ELEMENT(self), 0); |
325 | WebCore::HTMLTableRowElement* item = WebKit::core(self); |
326 | gchar* result = convertToUTF8String(item->attributeWithoutSynchronization(WebCore::HTMLNames::alignAttr)); |
327 | return result; |
328 | } |
329 | |
330 | void webkit_dom_html_table_row_element_set_align(WebKitDOMHTMLTableRowElement* self, const gchar* value) |
331 | { |
332 | WebCore::JSMainThreadNullState state; |
333 | g_return_if_fail(WEBKIT_DOM_IS_HTML_TABLE_ROW_ELEMENT(self)); |
334 | g_return_if_fail(value); |
335 | WebCore::HTMLTableRowElement* item = WebKit::core(self); |
336 | WTF::String convertedValue = WTF::String::fromUTF8(value); |
337 | item->setAttributeWithoutSynchronization(WebCore::HTMLNames::alignAttr, convertedValue); |
338 | } |
339 | |
340 | gchar* webkit_dom_html_table_row_element_get_bg_color(WebKitDOMHTMLTableRowElement* self) |
341 | { |
342 | WebCore::JSMainThreadNullState state; |
343 | g_return_val_if_fail(WEBKIT_DOM_IS_HTML_TABLE_ROW_ELEMENT(self), 0); |
344 | WebCore::HTMLTableRowElement* item = WebKit::core(self); |
345 | gchar* result = convertToUTF8String(item->attributeWithoutSynchronization(WebCore::HTMLNames::bgcolorAttr)); |
346 | return result; |
347 | } |
348 | |
349 | void webkit_dom_html_table_row_element_set_bg_color(WebKitDOMHTMLTableRowElement* self, const gchar* value) |
350 | { |
351 | WebCore::JSMainThreadNullState state; |
352 | g_return_if_fail(WEBKIT_DOM_IS_HTML_TABLE_ROW_ELEMENT(self)); |
353 | g_return_if_fail(value); |
354 | WebCore::HTMLTableRowElement* item = WebKit::core(self); |
355 | WTF::String convertedValue = WTF::String::fromUTF8(value); |
356 | item->setAttributeWithoutSynchronization(WebCore::HTMLNames::bgcolorAttr, convertedValue); |
357 | } |
358 | |
359 | gchar* webkit_dom_html_table_row_element_get_ch(WebKitDOMHTMLTableRowElement* self) |
360 | { |
361 | WebCore::JSMainThreadNullState state; |
362 | g_return_val_if_fail(WEBKIT_DOM_IS_HTML_TABLE_ROW_ELEMENT(self), 0); |
363 | WebCore::HTMLTableRowElement* item = WebKit::core(self); |
364 | gchar* result = convertToUTF8String(item->attributeWithoutSynchronization(WebCore::HTMLNames::charAttr)); |
365 | return result; |
366 | } |
367 | |
368 | void webkit_dom_html_table_row_element_set_ch(WebKitDOMHTMLTableRowElement* self, const gchar* value) |
369 | { |
370 | WebCore::JSMainThreadNullState state; |
371 | g_return_if_fail(WEBKIT_DOM_IS_HTML_TABLE_ROW_ELEMENT(self)); |
372 | g_return_if_fail(value); |
373 | WebCore::HTMLTableRowElement* item = WebKit::core(self); |
374 | WTF::String convertedValue = WTF::String::fromUTF8(value); |
375 | item->setAttributeWithoutSynchronization(WebCore::HTMLNames::charAttr, convertedValue); |
376 | } |
377 | |
378 | gchar* webkit_dom_html_table_row_element_get_ch_off(WebKitDOMHTMLTableRowElement* self) |
379 | { |
380 | WebCore::JSMainThreadNullState state; |
381 | g_return_val_if_fail(WEBKIT_DOM_IS_HTML_TABLE_ROW_ELEMENT(self), 0); |
382 | WebCore::HTMLTableRowElement* item = WebKit::core(self); |
383 | gchar* result = convertToUTF8String(item->attributeWithoutSynchronization(WebCore::HTMLNames::charoffAttr)); |
384 | return result; |
385 | } |
386 | |
387 | void webkit_dom_html_table_row_element_set_ch_off(WebKitDOMHTMLTableRowElement* self, const gchar* value) |
388 | { |
389 | WebCore::JSMainThreadNullState state; |
390 | g_return_if_fail(WEBKIT_DOM_IS_HTML_TABLE_ROW_ELEMENT(self)); |
391 | g_return_if_fail(value); |
392 | WebCore::HTMLTableRowElement* item = WebKit::core(self); |
393 | WTF::String convertedValue = WTF::String::fromUTF8(value); |
394 | item->setAttributeWithoutSynchronization(WebCore::HTMLNames::charoffAttr, convertedValue); |
395 | } |
396 | |
397 | gchar* webkit_dom_html_table_row_element_get_v_align(WebKitDOMHTMLTableRowElement* self) |
398 | { |
399 | WebCore::JSMainThreadNullState state; |
400 | g_return_val_if_fail(WEBKIT_DOM_IS_HTML_TABLE_ROW_ELEMENT(self), 0); |
401 | WebCore::HTMLTableRowElement* item = WebKit::core(self); |
402 | gchar* result = convertToUTF8String(item->attributeWithoutSynchronization(WebCore::HTMLNames::valignAttr)); |
403 | return result; |
404 | } |
405 | |
406 | void webkit_dom_html_table_row_element_set_v_align(WebKitDOMHTMLTableRowElement* self, const gchar* value) |
407 | { |
408 | WebCore::JSMainThreadNullState state; |
409 | g_return_if_fail(WEBKIT_DOM_IS_HTML_TABLE_ROW_ELEMENT(self)); |
410 | g_return_if_fail(value); |
411 | WebCore::HTMLTableRowElement* item = WebKit::core(self); |
412 | WTF::String convertedValue = WTF::String::fromUTF8(value); |
413 | item->setAttributeWithoutSynchronization(WebCore::HTMLNames::valignAttr, convertedValue); |
414 | } |
415 | |
416 | G_GNUC_END_IGNORE_DEPRECATIONS; |
417 | |