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