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