Drop ExceptionCodeDescription class
[WebKit-https.git] / Source / WebKit / WebProcess / InjectedBundle / API / gtk / DOM / WebKitDOMHTMLTableSectionElement.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 "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/JSMainThreadExecState.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 namespace WebKit {
42
43 WebKitDOMHTMLTableSectionElement* kit(WebCore::HTMLTableSectionElement* obj)
44 {
45     return WEBKIT_DOM_HTML_TABLE_SECTION_ELEMENT(kit(static_cast<WebCore::Node*>(obj)));
46 }
47
48 WebCore::HTMLTableSectionElement* core(WebKitDOMHTMLTableSectionElement* request)
49 {
50     return request ? static_cast<WebCore::HTMLTableSectionElement*>(WEBKIT_DOM_OBJECT(request)->coreObject) : 0;
51 }
52
53 WebKitDOMHTMLTableSectionElement* wrapHTMLTableSectionElement(WebCore::HTMLTableSectionElement* coreObject)
54 {
55     ASSERT(coreObject);
56     return WEBKIT_DOM_HTML_TABLE_SECTION_ELEMENT(g_object_new(WEBKIT_DOM_TYPE_HTML_TABLE_SECTION_ELEMENT, "core-object", coreObject, nullptr));
57 }
58
59 } // namespace WebKit
60
61 static gboolean webkit_dom_html_table_section_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::HTMLTableSectionElement* coreTarget = static_cast<WebCore::HTMLTableSectionElement*>(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_section_element_add_event_listener(WebKitDOMEventTarget* target, const char* eventName, GClosure* handler, gboolean useCapture)
78 {
79     WebCore::HTMLTableSectionElement* coreTarget = static_cast<WebCore::HTMLTableSectionElement*>(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_section_element_remove_event_listener(WebKitDOMEventTarget* target, const char* eventName, GClosure* handler, gboolean useCapture)
84 {
85     WebCore::HTMLTableSectionElement* coreTarget = static_cast<WebCore::HTMLTableSectionElement*>(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_section_element_dispatch_event;
92     iface->add_event_listener = webkit_dom_html_table_section_element_add_event_listener;
93     iface->remove_event_listener = webkit_dom_html_table_section_element_remove_event_listener;
94 }
95
96 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_event_target_init))
97
98 enum {
99     PROP_0,
100     PROP_ALIGN,
101     PROP_CH,
102     PROP_CH_OFF,
103     PROP_V_ALIGN,
104     PROP_ROWS,
105 };
106
107 static void webkit_dom_html_table_section_element_set_property(GObject* object, guint propertyId, const GValue* value, GParamSpec* pspec)
108 {
109     WebKitDOMHTMLTableSectionElement* self = WEBKIT_DOM_HTML_TABLE_SECTION_ELEMENT(object);
110
111     switch (propertyId) {
112     case PROP_ALIGN:
113         webkit_dom_html_table_section_element_set_align(self, g_value_get_string(value));
114         break;
115     case PROP_CH:
116         webkit_dom_html_table_section_element_set_ch(self, g_value_get_string(value));
117         break;
118     case PROP_CH_OFF:
119         webkit_dom_html_table_section_element_set_ch_off(self, g_value_get_string(value));
120         break;
121     case PROP_V_ALIGN:
122         webkit_dom_html_table_section_element_set_v_align(self, g_value_get_string(value));
123         break;
124     default:
125         G_OBJECT_WARN_INVALID_PROPERTY_ID(object, propertyId, pspec);
126         break;
127     }
128 }
129
130 static void webkit_dom_html_table_section_element_get_property(GObject* object, guint propertyId, GValue* value, GParamSpec* pspec)
131 {
132     WebKitDOMHTMLTableSectionElement* self = WEBKIT_DOM_HTML_TABLE_SECTION_ELEMENT(object);
133
134     switch (propertyId) {
135     case PROP_ALIGN:
136         g_value_take_string(value, webkit_dom_html_table_section_element_get_align(self));
137         break;
138     case PROP_CH:
139         g_value_take_string(value, webkit_dom_html_table_section_element_get_ch(self));
140         break;
141     case PROP_CH_OFF:
142         g_value_take_string(value, webkit_dom_html_table_section_element_get_ch_off(self));
143         break;
144     case PROP_V_ALIGN:
145         g_value_take_string(value, webkit_dom_html_table_section_element_get_v_align(self));
146         break;
147     case PROP_ROWS:
148         g_value_set_object(value, webkit_dom_html_table_section_element_get_rows(self));
149         break;
150     default:
151         G_OBJECT_WARN_INVALID_PROPERTY_ID(object, propertyId, pspec);
152         break;
153     }
154 }
155
156 static void webkit_dom_html_table_section_element_class_init(WebKitDOMHTMLTableSectionElementClass* requestClass)
157 {
158     GObjectClass* gobjectClass = G_OBJECT_CLASS(requestClass);
159     gobjectClass->set_property = webkit_dom_html_table_section_element_set_property;
160     gobjectClass->get_property = webkit_dom_html_table_section_element_get_property;
161
162     g_object_class_install_property(
163         gobjectClass,
164         PROP_ALIGN,
165         g_param_spec_string(
166             "align",
167             "HTMLTableSectionElement:align",
168             "read-write gchar* HTMLTableSectionElement:align",
169             "",
170             WEBKIT_PARAM_READWRITE));
171
172     g_object_class_install_property(
173         gobjectClass,
174         PROP_CH,
175         g_param_spec_string(
176             "ch",
177             "HTMLTableSectionElement:ch",
178             "read-write gchar* HTMLTableSectionElement:ch",
179             "",
180             WEBKIT_PARAM_READWRITE));
181
182     g_object_class_install_property(
183         gobjectClass,
184         PROP_CH_OFF,
185         g_param_spec_string(
186             "ch-off",
187             "HTMLTableSectionElement:ch-off",
188             "read-write gchar* HTMLTableSectionElement:ch-off",
189             "",
190             WEBKIT_PARAM_READWRITE));
191
192     g_object_class_install_property(
193         gobjectClass,
194         PROP_V_ALIGN,
195         g_param_spec_string(
196             "v-align",
197             "HTMLTableSectionElement:v-align",
198             "read-write gchar* HTMLTableSectionElement:v-align",
199             "",
200             WEBKIT_PARAM_READWRITE));
201
202     g_object_class_install_property(
203         gobjectClass,
204         PROP_ROWS,
205         g_param_spec_object(
206             "rows",
207             "HTMLTableSectionElement:rows",
208             "read-only WebKitDOMHTMLCollection* HTMLTableSectionElement:rows",
209             WEBKIT_DOM_TYPE_HTML_COLLECTION,
210             WEBKIT_PARAM_READABLE));
211
212 }
213
214 static void webkit_dom_html_table_section_element_init(WebKitDOMHTMLTableSectionElement* request)
215 {
216     UNUSED_PARAM(request);
217 }
218
219 WebKitDOMHTMLElement* webkit_dom_html_table_section_element_insert_row(WebKitDOMHTMLTableSectionElement* self, glong index, GError** error)
220 {
221     WebCore::JSMainThreadNullState state;
222     g_return_val_if_fail(WEBKIT_DOM_IS_HTML_TABLE_SECTION_ELEMENT(self), 0);
223     g_return_val_if_fail(!error || !*error, 0);
224     WebCore::HTMLTableSectionElement* item = WebKit::core(self);
225     auto result = item->insertRow(index);
226     if (result.hasException()) {
227         auto description = WebCore::DOMException::description(result.releaseException().code());
228         g_set_error_literal(error, g_quark_from_string("WEBKIT_DOM"), description.legacyCode, description.name);
229     }
230     return WebKit::kit(result.releaseReturnValue().ptr());
231 }
232
233 void webkit_dom_html_table_section_element_delete_row(WebKitDOMHTMLTableSectionElement* self, glong index, GError** error)
234 {
235     WebCore::JSMainThreadNullState state;
236     g_return_if_fail(WEBKIT_DOM_IS_HTML_TABLE_SECTION_ELEMENT(self));
237     g_return_if_fail(!error || !*error);
238     WebCore::HTMLTableSectionElement* item = WebKit::core(self);
239     auto result = item->deleteRow(index);
240     if (result.hasException()) {
241         auto description = WebCore::DOMException::description(result.releaseException().code());
242         g_set_error_literal(error, g_quark_from_string("WEBKIT_DOM"), description.legacyCode, description.name);
243     }
244 }
245
246 gchar* webkit_dom_html_table_section_element_get_align(WebKitDOMHTMLTableSectionElement* self)
247 {
248     WebCore::JSMainThreadNullState state;
249     g_return_val_if_fail(WEBKIT_DOM_IS_HTML_TABLE_SECTION_ELEMENT(self), 0);
250     WebCore::HTMLTableSectionElement* item = WebKit::core(self);
251     gchar* result = convertToUTF8String(item->attributeWithoutSynchronization(WebCore::HTMLNames::alignAttr));
252     return result;
253 }
254
255 void webkit_dom_html_table_section_element_set_align(WebKitDOMHTMLTableSectionElement* self, const gchar* value)
256 {
257     WebCore::JSMainThreadNullState state;
258     g_return_if_fail(WEBKIT_DOM_IS_HTML_TABLE_SECTION_ELEMENT(self));
259     g_return_if_fail(value);
260     WebCore::HTMLTableSectionElement* item = WebKit::core(self);
261     WTF::String convertedValue = WTF::String::fromUTF8(value);
262     item->setAttributeWithoutSynchronization(WebCore::HTMLNames::alignAttr, convertedValue);
263 }
264
265 gchar* webkit_dom_html_table_section_element_get_ch(WebKitDOMHTMLTableSectionElement* self)
266 {
267     WebCore::JSMainThreadNullState state;
268     g_return_val_if_fail(WEBKIT_DOM_IS_HTML_TABLE_SECTION_ELEMENT(self), 0);
269     WebCore::HTMLTableSectionElement* item = WebKit::core(self);
270     gchar* result = convertToUTF8String(item->attributeWithoutSynchronization(WebCore::HTMLNames::charAttr));
271     return result;
272 }
273
274 void webkit_dom_html_table_section_element_set_ch(WebKitDOMHTMLTableSectionElement* self, const gchar* value)
275 {
276     WebCore::JSMainThreadNullState state;
277     g_return_if_fail(WEBKIT_DOM_IS_HTML_TABLE_SECTION_ELEMENT(self));
278     g_return_if_fail(value);
279     WebCore::HTMLTableSectionElement* item = WebKit::core(self);
280     WTF::String convertedValue = WTF::String::fromUTF8(value);
281     item->setAttributeWithoutSynchronization(WebCore::HTMLNames::charAttr, convertedValue);
282 }
283
284 gchar* webkit_dom_html_table_section_element_get_ch_off(WebKitDOMHTMLTableSectionElement* self)
285 {
286     WebCore::JSMainThreadNullState state;
287     g_return_val_if_fail(WEBKIT_DOM_IS_HTML_TABLE_SECTION_ELEMENT(self), 0);
288     WebCore::HTMLTableSectionElement* item = WebKit::core(self);
289     gchar* result = convertToUTF8String(item->attributeWithoutSynchronization(WebCore::HTMLNames::charoffAttr));
290     return result;
291 }
292
293 void webkit_dom_html_table_section_element_set_ch_off(WebKitDOMHTMLTableSectionElement* self, const gchar* value)
294 {
295     WebCore::JSMainThreadNullState state;
296     g_return_if_fail(WEBKIT_DOM_IS_HTML_TABLE_SECTION_ELEMENT(self));
297     g_return_if_fail(value);
298     WebCore::HTMLTableSectionElement* item = WebKit::core(self);
299     WTF::String convertedValue = WTF::String::fromUTF8(value);
300     item->setAttributeWithoutSynchronization(WebCore::HTMLNames::charoffAttr, convertedValue);
301 }
302
303 gchar* webkit_dom_html_table_section_element_get_v_align(WebKitDOMHTMLTableSectionElement* self)
304 {
305     WebCore::JSMainThreadNullState state;
306     g_return_val_if_fail(WEBKIT_DOM_IS_HTML_TABLE_SECTION_ELEMENT(self), 0);
307     WebCore::HTMLTableSectionElement* item = WebKit::core(self);
308     gchar* result = convertToUTF8String(item->attributeWithoutSynchronization(WebCore::HTMLNames::valignAttr));
309     return result;
310 }
311
312 void webkit_dom_html_table_section_element_set_v_align(WebKitDOMHTMLTableSectionElement* self, const gchar* value)
313 {
314     WebCore::JSMainThreadNullState state;
315     g_return_if_fail(WEBKIT_DOM_IS_HTML_TABLE_SECTION_ELEMENT(self));
316     g_return_if_fail(value);
317     WebCore::HTMLTableSectionElement* item = WebKit::core(self);
318     WTF::String convertedValue = WTF::String::fromUTF8(value);
319     item->setAttributeWithoutSynchronization(WebCore::HTMLNames::valignAttr, convertedValue);
320 }
321
322 WebKitDOMHTMLCollection* webkit_dom_html_table_section_element_get_rows(WebKitDOMHTMLTableSectionElement* self)
323 {
324     WebCore::JSMainThreadNullState state;
325     g_return_val_if_fail(WEBKIT_DOM_IS_HTML_TABLE_SECTION_ELEMENT(self), 0);
326     WebCore::HTMLTableSectionElement* item = WebKit::core(self);
327     RefPtr<WebCore::HTMLCollection> gobjectResult = WTF::getPtr(item->rows());
328     return WebKit::kit(gobjectResult.get());
329 }
330