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