Drop ExceptionCodeDescription class
[WebKit-https.git] / Source / WebKit / WebProcess / InjectedBundle / API / gtk / DOM / WebKitDOMElement.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 "WebKitDOMElement.h"
22
23 #include <WebCore/CSSImportRule.h>
24 #include "DOMObjectCache.h"
25 #include <WebCore/DOMException.h>
26 #include <WebCore/DOMRect.h>
27 #include <WebCore/Document.h>
28 #include "GObjectEventListener.h"
29 #include <WebCore/HTMLNames.h>
30 #include <WebCore/JSMainThreadExecState.h>
31 #include <WebCore/StyledElement.h>
32 #include "WebKitDOMAttrPrivate.h"
33 #include "WebKitDOMCSSStyleDeclarationPrivate.h"
34 #include "WebKitDOMClientRectListPrivate.h"
35 #include "WebKitDOMClientRectPrivate.h"
36 #include "WebKitDOMDOMTokenListPrivate.h"
37 #include "WebKitDOMElementPrivate.h"
38 #include "WebKitDOMEventPrivate.h"
39 #include "WebKitDOMEventTarget.h"
40 #include "WebKitDOMHTMLCollectionPrivate.h"
41 #include "WebKitDOMNamedNodeMapPrivate.h"
42 #include "WebKitDOMNodeListPrivate.h"
43 #include "WebKitDOMNodePrivate.h"
44 #include "WebKitDOMPrivate.h"
45 #include "ConvertToUTF8String.h"
46 #include "WebKitDOMElementUnstable.h"
47 #include <wtf/GetPtr.h>
48 #include <wtf/RefPtr.h>
49
50 namespace WebKit {
51
52 WebKitDOMElement* kit(WebCore::Element* obj)
53 {
54     return WEBKIT_DOM_ELEMENT(kit(static_cast<WebCore::Node*>(obj)));
55 }
56
57 WebCore::Element* core(WebKitDOMElement* request)
58 {
59     return request ? static_cast<WebCore::Element*>(WEBKIT_DOM_OBJECT(request)->coreObject) : 0;
60 }
61
62 WebKitDOMElement* wrapElement(WebCore::Element* coreObject)
63 {
64     ASSERT(coreObject);
65     return WEBKIT_DOM_ELEMENT(g_object_new(WEBKIT_DOM_TYPE_ELEMENT, "core-object", coreObject, nullptr));
66 }
67
68 } // namespace WebKit
69
70 static gboolean webkit_dom_element_dispatch_event(WebKitDOMEventTarget* target, WebKitDOMEvent* event, GError** error)
71 {
72     WebCore::Event* coreEvent = WebKit::core(event);
73     if (!coreEvent)
74         return false;
75     WebCore::Element* coreTarget = static_cast<WebCore::Element*>(WEBKIT_DOM_OBJECT(target)->coreObject);
76
77     auto result = coreTarget->dispatchEventForBindings(*coreEvent);
78     if (result.hasException()) {
79         auto description = WebCore::DOMException::description(result.releaseException().code());
80         g_set_error_literal(error, g_quark_from_string("WEBKIT_DOM"), description.legacyCode, description.name);
81         return false;
82     }
83     return result.releaseReturnValue();
84 }
85
86 static gboolean webkit_dom_element_add_event_listener(WebKitDOMEventTarget* target, const char* eventName, GClosure* handler, gboolean useCapture)
87 {
88     WebCore::Element* coreTarget = static_cast<WebCore::Element*>(WEBKIT_DOM_OBJECT(target)->coreObject);
89     return WebKit::GObjectEventListener::addEventListener(G_OBJECT(target), coreTarget, eventName, handler, useCapture);
90 }
91
92 static gboolean webkit_dom_element_remove_event_listener(WebKitDOMEventTarget* target, const char* eventName, GClosure* handler, gboolean useCapture)
93 {
94     WebCore::Element* coreTarget = static_cast<WebCore::Element*>(WEBKIT_DOM_OBJECT(target)->coreObject);
95     return WebKit::GObjectEventListener::removeEventListener(G_OBJECT(target), coreTarget, eventName, handler, useCapture);
96 }
97
98 static void webkit_dom_event_target_init(WebKitDOMEventTargetIface* iface)
99 {
100     iface->dispatch_event = webkit_dom_element_dispatch_event;
101     iface->add_event_listener = webkit_dom_element_add_event_listener;
102     iface->remove_event_listener = webkit_dom_element_remove_event_listener;
103 }
104
105 G_DEFINE_TYPE_WITH_CODE(WebKitDOMElement, webkit_dom_element, WEBKIT_DOM_TYPE_NODE, G_IMPLEMENT_INTERFACE(WEBKIT_DOM_TYPE_EVENT_TARGET, webkit_dom_event_target_init))
106
107 enum {
108     PROP_0,
109     PROP_TAG_NAME,
110     PROP_ATTRIBUTES,
111     PROP_STYLE,
112     PROP_ID,
113     PROP_NAMESPACE_URI,
114     PROP_PREFIX,
115     PROP_LOCAL_NAME,
116     PROP_OFFSET_LEFT,
117     PROP_OFFSET_TOP,
118     PROP_OFFSET_WIDTH,
119     PROP_OFFSET_HEIGHT,
120     PROP_CLIENT_LEFT,
121     PROP_CLIENT_TOP,
122     PROP_CLIENT_WIDTH,
123     PROP_CLIENT_HEIGHT,
124     PROP_SCROLL_LEFT,
125     PROP_SCROLL_TOP,
126     PROP_SCROLL_WIDTH,
127     PROP_SCROLL_HEIGHT,
128     PROP_OFFSET_PARENT,
129     PROP_INNER_HTML,
130     PROP_OUTER_HTML,
131     PROP_CLASS_NAME,
132     PROP_CLASS_LIST,
133     PROP_WEBKIT_REGION_OVERSET,
134     PROP_PREVIOUS_ELEMENT_SIBLING,
135     PROP_NEXT_ELEMENT_SIBLING,
136     PROP_CHILDREN,
137     PROP_FIRST_ELEMENT_CHILD,
138     PROP_LAST_ELEMENT_CHILD,
139     PROP_CHILD_ELEMENT_COUNT,
140 };
141
142 static void webkit_dom_element_set_property(GObject* object, guint propertyId, const GValue* value, GParamSpec* pspec)
143 {
144     WebKitDOMElement* self = WEBKIT_DOM_ELEMENT(object);
145
146     switch (propertyId) {
147     case PROP_ID:
148         webkit_dom_element_set_id(self, g_value_get_string(value));
149         break;
150     case PROP_SCROLL_LEFT:
151         webkit_dom_element_set_scroll_left(self, g_value_get_long(value));
152         break;
153     case PROP_SCROLL_TOP:
154         webkit_dom_element_set_scroll_top(self, g_value_get_long(value));
155         break;
156     case PROP_INNER_HTML:
157         webkit_dom_element_set_inner_html(self, g_value_get_string(value), nullptr);
158         break;
159     case PROP_OUTER_HTML:
160         webkit_dom_element_set_outer_html(self, g_value_get_string(value), nullptr);
161         break;
162     case PROP_CLASS_NAME:
163         webkit_dom_element_set_class_name(self, g_value_get_string(value));
164         break;
165     default:
166         G_OBJECT_WARN_INVALID_PROPERTY_ID(object, propertyId, pspec);
167         break;
168     }
169 }
170
171 static void webkit_dom_element_get_property(GObject* object, guint propertyId, GValue* value, GParamSpec* pspec)
172 {
173     WebKitDOMElement* self = WEBKIT_DOM_ELEMENT(object);
174
175     switch (propertyId) {
176     case PROP_TAG_NAME:
177         g_value_take_string(value, webkit_dom_element_get_tag_name(self));
178         break;
179     case PROP_ATTRIBUTES:
180         g_value_set_object(value, webkit_dom_element_get_attributes(self));
181         break;
182     case PROP_STYLE:
183         g_value_set_object(value, webkit_dom_element_get_style(self));
184         break;
185     case PROP_ID:
186         g_value_take_string(value, webkit_dom_element_get_id(self));
187         break;
188     case PROP_NAMESPACE_URI:
189         g_value_take_string(value, webkit_dom_element_get_namespace_uri(self));
190         break;
191     case PROP_PREFIX:
192         g_value_take_string(value, webkit_dom_element_get_prefix(self));
193         break;
194     case PROP_LOCAL_NAME:
195         g_value_take_string(value, webkit_dom_element_get_local_name(self));
196         break;
197     case PROP_OFFSET_LEFT:
198         g_value_set_double(value, webkit_dom_element_get_offset_left(self));
199         break;
200     case PROP_OFFSET_TOP:
201         g_value_set_double(value, webkit_dom_element_get_offset_top(self));
202         break;
203     case PROP_OFFSET_WIDTH:
204         g_value_set_double(value, webkit_dom_element_get_offset_width(self));
205         break;
206     case PROP_OFFSET_HEIGHT:
207         g_value_set_double(value, webkit_dom_element_get_offset_height(self));
208         break;
209     case PROP_CLIENT_LEFT:
210         g_value_set_double(value, webkit_dom_element_get_client_left(self));
211         break;
212     case PROP_CLIENT_TOP:
213         g_value_set_double(value, webkit_dom_element_get_client_top(self));
214         break;
215     case PROP_CLIENT_WIDTH:
216         g_value_set_double(value, webkit_dom_element_get_client_width(self));
217         break;
218     case PROP_CLIENT_HEIGHT:
219         g_value_set_double(value, webkit_dom_element_get_client_height(self));
220         break;
221     case PROP_SCROLL_LEFT:
222         g_value_set_long(value, webkit_dom_element_get_scroll_left(self));
223         break;
224     case PROP_SCROLL_TOP:
225         g_value_set_long(value, webkit_dom_element_get_scroll_top(self));
226         break;
227     case PROP_SCROLL_WIDTH:
228         g_value_set_long(value, webkit_dom_element_get_scroll_width(self));
229         break;
230     case PROP_SCROLL_HEIGHT:
231         g_value_set_long(value, webkit_dom_element_get_scroll_height(self));
232         break;
233     case PROP_OFFSET_PARENT:
234         g_value_set_object(value, webkit_dom_element_get_offset_parent(self));
235         break;
236     case PROP_INNER_HTML:
237         g_value_take_string(value, webkit_dom_element_get_inner_html(self));
238         break;
239     case PROP_OUTER_HTML:
240         g_value_take_string(value, webkit_dom_element_get_outer_html(self));
241         break;
242     case PROP_CLASS_NAME:
243         g_value_take_string(value, webkit_dom_element_get_class_name(self));
244         break;
245     case PROP_CLASS_LIST:
246         g_value_set_object(value, webkit_dom_element_get_class_list(self));
247         break;
248     case PROP_WEBKIT_REGION_OVERSET:
249         g_value_take_string(value, webkit_dom_element_get_webkit_region_overset(self));
250         break;
251     case PROP_PREVIOUS_ELEMENT_SIBLING:
252         g_value_set_object(value, webkit_dom_element_get_previous_element_sibling(self));
253         break;
254     case PROP_NEXT_ELEMENT_SIBLING:
255         g_value_set_object(value, webkit_dom_element_get_next_element_sibling(self));
256         break;
257     case PROP_CHILDREN:
258         g_value_set_object(value, webkit_dom_element_get_children(self));
259         break;
260     case PROP_FIRST_ELEMENT_CHILD:
261         g_value_set_object(value, webkit_dom_element_get_first_element_child(self));
262         break;
263     case PROP_LAST_ELEMENT_CHILD:
264         g_value_set_object(value, webkit_dom_element_get_last_element_child(self));
265         break;
266     case PROP_CHILD_ELEMENT_COUNT:
267         g_value_set_ulong(value, webkit_dom_element_get_child_element_count(self));
268         break;
269     default:
270         G_OBJECT_WARN_INVALID_PROPERTY_ID(object, propertyId, pspec);
271         break;
272     }
273 }
274
275 static void webkit_dom_element_class_init(WebKitDOMElementClass* requestClass)
276 {
277     GObjectClass* gobjectClass = G_OBJECT_CLASS(requestClass);
278     gobjectClass->set_property = webkit_dom_element_set_property;
279     gobjectClass->get_property = webkit_dom_element_get_property;
280
281     g_object_class_install_property(
282         gobjectClass,
283         PROP_TAG_NAME,
284         g_param_spec_string(
285             "tag-name",
286             "Element:tag-name",
287             "read-only gchar* Element:tag-name",
288             "",
289             WEBKIT_PARAM_READABLE));
290
291     g_object_class_install_property(
292         gobjectClass,
293         PROP_ATTRIBUTES,
294         g_param_spec_object(
295             "attributes",
296             "Element:attributes",
297             "read-only WebKitDOMNamedNodeMap* Element:attributes",
298             WEBKIT_DOM_TYPE_NAMED_NODE_MAP,
299             WEBKIT_PARAM_READABLE));
300
301     g_object_class_install_property(
302         gobjectClass,
303         PROP_STYLE,
304         g_param_spec_object(
305             "style",
306             "Element:style",
307             "read-only WebKitDOMCSSStyleDeclaration* Element:style",
308             WEBKIT_DOM_TYPE_CSS_STYLE_DECLARATION,
309             WEBKIT_PARAM_READABLE));
310
311     g_object_class_install_property(
312         gobjectClass,
313         PROP_ID,
314         g_param_spec_string(
315             "id",
316             "Element:id",
317             "read-write gchar* Element:id",
318             "",
319             WEBKIT_PARAM_READWRITE));
320
321     g_object_class_install_property(
322         gobjectClass,
323         PROP_NAMESPACE_URI,
324         g_param_spec_string(
325             "namespace-uri",
326             "Element:namespace-uri",
327             "read-only gchar* Element:namespace-uri",
328             "",
329             WEBKIT_PARAM_READABLE));
330
331     g_object_class_install_property(
332         gobjectClass,
333         PROP_PREFIX,
334         g_param_spec_string(
335             "prefix",
336             "Element:prefix",
337             "read-only gchar* Element:prefix",
338             "",
339             WEBKIT_PARAM_READABLE));
340
341     g_object_class_install_property(
342         gobjectClass,
343         PROP_LOCAL_NAME,
344         g_param_spec_string(
345             "local-name",
346             "Element:local-name",
347             "read-only gchar* Element:local-name",
348             "",
349             WEBKIT_PARAM_READABLE));
350
351     g_object_class_install_property(
352         gobjectClass,
353         PROP_OFFSET_LEFT,
354         g_param_spec_double(
355             "offset-left",
356             "Element:offset-left",
357             "read-only gdouble Element:offset-left",
358             -G_MAXDOUBLE, G_MAXDOUBLE, 0,
359             WEBKIT_PARAM_READABLE));
360
361     g_object_class_install_property(
362         gobjectClass,
363         PROP_OFFSET_TOP,
364         g_param_spec_double(
365             "offset-top",
366             "Element:offset-top",
367             "read-only gdouble Element:offset-top",
368             -G_MAXDOUBLE, G_MAXDOUBLE, 0,
369             WEBKIT_PARAM_READABLE));
370
371     g_object_class_install_property(
372         gobjectClass,
373         PROP_OFFSET_WIDTH,
374         g_param_spec_double(
375             "offset-width",
376             "Element:offset-width",
377             "read-only gdouble Element:offset-width",
378             -G_MAXDOUBLE, G_MAXDOUBLE, 0,
379             WEBKIT_PARAM_READABLE));
380
381     g_object_class_install_property(
382         gobjectClass,
383         PROP_OFFSET_HEIGHT,
384         g_param_spec_double(
385             "offset-height",
386             "Element:offset-height",
387             "read-only gdouble Element:offset-height",
388             -G_MAXDOUBLE, G_MAXDOUBLE, 0,
389             WEBKIT_PARAM_READABLE));
390
391     g_object_class_install_property(
392         gobjectClass,
393         PROP_CLIENT_LEFT,
394         g_param_spec_double(
395             "client-left",
396             "Element:client-left",
397             "read-only gdouble Element:client-left",
398             -G_MAXDOUBLE, G_MAXDOUBLE, 0,
399             WEBKIT_PARAM_READABLE));
400
401     g_object_class_install_property(
402         gobjectClass,
403         PROP_CLIENT_TOP,
404         g_param_spec_double(
405             "client-top",
406             "Element:client-top",
407             "read-only gdouble Element:client-top",
408             -G_MAXDOUBLE, G_MAXDOUBLE, 0,
409             WEBKIT_PARAM_READABLE));
410
411     g_object_class_install_property(
412         gobjectClass,
413         PROP_CLIENT_WIDTH,
414         g_param_spec_double(
415             "client-width",
416             "Element:client-width",
417             "read-only gdouble Element:client-width",
418             -G_MAXDOUBLE, G_MAXDOUBLE, 0,
419             WEBKIT_PARAM_READABLE));
420
421     g_object_class_install_property(
422         gobjectClass,
423         PROP_CLIENT_HEIGHT,
424         g_param_spec_double(
425             "client-height",
426             "Element:client-height",
427             "read-only gdouble Element:client-height",
428             -G_MAXDOUBLE, G_MAXDOUBLE, 0,
429             WEBKIT_PARAM_READABLE));
430
431     g_object_class_install_property(
432         gobjectClass,
433         PROP_SCROLL_LEFT,
434         g_param_spec_long(
435             "scroll-left",
436             "Element:scroll-left",
437             "read-write glong Element:scroll-left",
438             G_MINLONG, G_MAXLONG, 0,
439             WEBKIT_PARAM_READWRITE));
440
441     g_object_class_install_property(
442         gobjectClass,
443         PROP_SCROLL_TOP,
444         g_param_spec_long(
445             "scroll-top",
446             "Element:scroll-top",
447             "read-write glong Element:scroll-top",
448             G_MINLONG, G_MAXLONG, 0,
449             WEBKIT_PARAM_READWRITE));
450
451     g_object_class_install_property(
452         gobjectClass,
453         PROP_SCROLL_WIDTH,
454         g_param_spec_long(
455             "scroll-width",
456             "Element:scroll-width",
457             "read-only glong Element:scroll-width",
458             G_MINLONG, G_MAXLONG, 0,
459             WEBKIT_PARAM_READABLE));
460
461     g_object_class_install_property(
462         gobjectClass,
463         PROP_SCROLL_HEIGHT,
464         g_param_spec_long(
465             "scroll-height",
466             "Element:scroll-height",
467             "read-only glong Element:scroll-height",
468             G_MINLONG, G_MAXLONG, 0,
469             WEBKIT_PARAM_READABLE));
470
471     g_object_class_install_property(
472         gobjectClass,
473         PROP_OFFSET_PARENT,
474         g_param_spec_object(
475             "offset-parent",
476             "Element:offset-parent",
477             "read-only WebKitDOMElement* Element:offset-parent",
478             WEBKIT_DOM_TYPE_ELEMENT,
479             WEBKIT_PARAM_READABLE));
480
481     g_object_class_install_property(
482         gobjectClass,
483         PROP_INNER_HTML,
484         g_param_spec_string(
485             "inner-html",
486             "Element:inner-html",
487             "read-write gchar* Element:inner-html",
488             "",
489             WEBKIT_PARAM_READWRITE));
490
491     g_object_class_install_property(
492         gobjectClass,
493         PROP_OUTER_HTML,
494         g_param_spec_string(
495             "outer-html",
496             "Element:outer-html",
497             "read-write gchar* Element:outer-html",
498             "",
499             WEBKIT_PARAM_READWRITE));
500
501     g_object_class_install_property(
502         gobjectClass,
503         PROP_CLASS_NAME,
504         g_param_spec_string(
505             "class-name",
506             "Element:class-name",
507             "read-write gchar* Element:class-name",
508             "",
509             WEBKIT_PARAM_READWRITE));
510
511     g_object_class_install_property(
512         gobjectClass,
513         PROP_CLASS_LIST,
514         g_param_spec_object(
515             "class-list",
516             "Element:class-list",
517             "read-only WebKitDOMDOMTokenList* Element:class-list",
518             WEBKIT_DOM_TYPE_DOM_TOKEN_LIST,
519             WEBKIT_PARAM_READABLE));
520
521     g_object_class_install_property(
522         gobjectClass,
523         PROP_WEBKIT_REGION_OVERSET,
524         g_param_spec_string(
525             "webkit-region-overset",
526             "Element:webkit-region-overset",
527             "read-only gchar* Element:webkit-region-overset",
528             "",
529             WEBKIT_PARAM_READABLE));
530
531     g_object_class_install_property(
532         gobjectClass,
533         PROP_PREVIOUS_ELEMENT_SIBLING,
534         g_param_spec_object(
535             "previous-element-sibling",
536             "Element:previous-element-sibling",
537             "read-only WebKitDOMElement* Element:previous-element-sibling",
538             WEBKIT_DOM_TYPE_ELEMENT,
539             WEBKIT_PARAM_READABLE));
540
541     g_object_class_install_property(
542         gobjectClass,
543         PROP_NEXT_ELEMENT_SIBLING,
544         g_param_spec_object(
545             "next-element-sibling",
546             "Element:next-element-sibling",
547             "read-only WebKitDOMElement* Element:next-element-sibling",
548             WEBKIT_DOM_TYPE_ELEMENT,
549             WEBKIT_PARAM_READABLE));
550
551     g_object_class_install_property(
552         gobjectClass,
553         PROP_CHILDREN,
554         g_param_spec_object(
555             "children",
556             "Element:children",
557             "read-only WebKitDOMHTMLCollection* Element:children",
558             WEBKIT_DOM_TYPE_HTML_COLLECTION,
559             WEBKIT_PARAM_READABLE));
560
561     g_object_class_install_property(
562         gobjectClass,
563         PROP_FIRST_ELEMENT_CHILD,
564         g_param_spec_object(
565             "first-element-child",
566             "Element:first-element-child",
567             "read-only WebKitDOMElement* Element:first-element-child",
568             WEBKIT_DOM_TYPE_ELEMENT,
569             WEBKIT_PARAM_READABLE));
570
571     g_object_class_install_property(
572         gobjectClass,
573         PROP_LAST_ELEMENT_CHILD,
574         g_param_spec_object(
575             "last-element-child",
576             "Element:last-element-child",
577             "read-only WebKitDOMElement* Element:last-element-child",
578             WEBKIT_DOM_TYPE_ELEMENT,
579             WEBKIT_PARAM_READABLE));
580
581     g_object_class_install_property(
582         gobjectClass,
583         PROP_CHILD_ELEMENT_COUNT,
584         g_param_spec_ulong(
585             "child-element-count",
586             "Element:child-element-count",
587             "read-only gulong Element:child-element-count",
588             0, G_MAXULONG, 0,
589             WEBKIT_PARAM_READABLE));
590
591 }
592
593 static void webkit_dom_element_init(WebKitDOMElement* request)
594 {
595     UNUSED_PARAM(request);
596 }
597
598 gchar* webkit_dom_element_get_attribute(WebKitDOMElement* self, const gchar* name)
599 {
600     WebCore::JSMainThreadNullState state;
601     g_return_val_if_fail(WEBKIT_DOM_IS_ELEMENT(self), 0);
602     g_return_val_if_fail(name, 0);
603     WebCore::Element* item = WebKit::core(self);
604     WTF::String convertedName = WTF::String::fromUTF8(name);
605     gchar* result = convertToUTF8String(item->getAttribute(convertedName));
606     return result;
607 }
608
609 void webkit_dom_element_set_attribute(WebKitDOMElement* self, const gchar* name, const gchar* value, GError** error)
610 {
611     WebCore::JSMainThreadNullState state;
612     g_return_if_fail(WEBKIT_DOM_IS_ELEMENT(self));
613     g_return_if_fail(name);
614     g_return_if_fail(value);
615     g_return_if_fail(!error || !*error);
616     WebCore::Element* item = WebKit::core(self);
617     WTF::String convertedName = WTF::String::fromUTF8(name);
618     WTF::String convertedValue = WTF::String::fromUTF8(value);
619     auto result = item->setAttribute(convertedName, convertedValue);
620     if (result.hasException()) {
621         auto description = WebCore::DOMException::description(result.releaseException().code());
622         g_set_error_literal(error, g_quark_from_string("WEBKIT_DOM"), description.legacyCode, description.name);
623     }
624 }
625
626 void webkit_dom_element_remove_attribute(WebKitDOMElement* self, const gchar* name)
627 {
628     WebCore::JSMainThreadNullState state;
629     g_return_if_fail(WEBKIT_DOM_IS_ELEMENT(self));
630     g_return_if_fail(name);
631     WebCore::Element* item = WebKit::core(self);
632     WTF::String convertedName = WTF::String::fromUTF8(name);
633     item->removeAttribute(convertedName);
634 }
635
636 WebKitDOMAttr* webkit_dom_element_get_attribute_node(WebKitDOMElement* self, const gchar* name)
637 {
638     WebCore::JSMainThreadNullState state;
639     g_return_val_if_fail(WEBKIT_DOM_IS_ELEMENT(self), 0);
640     g_return_val_if_fail(name, 0);
641     WebCore::Element* item = WebKit::core(self);
642     WTF::String convertedName = WTF::String::fromUTF8(name);
643     RefPtr<WebCore::Attr> gobjectResult = WTF::getPtr(item->getAttributeNode(convertedName));
644     return WebKit::kit(gobjectResult.get());
645 }
646
647 WebKitDOMAttr* webkit_dom_element_set_attribute_node(WebKitDOMElement* self, WebKitDOMAttr* newAttr, GError** error)
648 {
649     WebCore::JSMainThreadNullState state;
650     g_return_val_if_fail(WEBKIT_DOM_IS_ELEMENT(self), 0);
651     g_return_val_if_fail(WEBKIT_DOM_IS_ATTR(newAttr), 0);
652     g_return_val_if_fail(!error || !*error, 0);
653     WebCore::Element* item = WebKit::core(self);
654     WebCore::Attr* convertedNewAttr = WebKit::core(newAttr);
655     auto result = item->setAttributeNode(*convertedNewAttr);
656     if (result.hasException()) {
657         auto description = WebCore::DOMException::description(result.releaseException().code());
658         g_set_error_literal(error, g_quark_from_string("WEBKIT_DOM"), description.legacyCode, description.name);
659         return nullptr;
660     }
661     return WebKit::kit(result.releaseReturnValue().get());
662 }
663
664 WebKitDOMAttr* webkit_dom_element_remove_attribute_node(WebKitDOMElement* self, WebKitDOMAttr* oldAttr, GError** error)
665 {
666     WebCore::JSMainThreadNullState state;
667     g_return_val_if_fail(WEBKIT_DOM_IS_ELEMENT(self), 0);
668     g_return_val_if_fail(WEBKIT_DOM_IS_ATTR(oldAttr), 0);
669     g_return_val_if_fail(!error || !*error, 0);
670     WebCore::Element* item = WebKit::core(self);
671     WebCore::Attr* convertedOldAttr = WebKit::core(oldAttr);
672     auto result = item->removeAttributeNode(*convertedOldAttr);
673     if (result.hasException()) {
674         auto description = WebCore::DOMException::description(result.releaseException().code());
675         g_set_error_literal(error, g_quark_from_string("WEBKIT_DOM"), description.legacyCode, description.name);
676         return nullptr;
677     }
678     return WebKit::kit(result.releaseReturnValue().ptr());
679 }
680
681 WebKitDOMHTMLCollection* webkit_dom_element_get_elements_by_tag_name_as_html_collection(WebKitDOMElement* self, const gchar* name)
682 {
683     WebCore::JSMainThreadNullState state;
684     g_return_val_if_fail(WEBKIT_DOM_IS_ELEMENT(self), 0);
685     g_return_val_if_fail(name, 0);
686     WebCore::Element* item = WebKit::core(self);
687     WTF::String convertedName = WTF::String::fromUTF8(name);
688     RefPtr<WebCore::HTMLCollection> gobjectResult = WTF::getPtr(item->getElementsByTagName(convertedName));
689     return WebKit::kit(gobjectResult.get());
690 }
691
692 gboolean webkit_dom_element_has_attributes(WebKitDOMElement* self)
693 {
694     WebCore::JSMainThreadNullState state;
695     g_return_val_if_fail(WEBKIT_DOM_IS_ELEMENT(self), FALSE);
696     WebCore::Element* item = WebKit::core(self);
697     gboolean result = item->hasAttributes();
698     return result;
699 }
700
701 gchar* webkit_dom_element_get_attribute_ns(WebKitDOMElement* self, const gchar* namespaceURI, const gchar* localName)
702 {
703     WebCore::JSMainThreadNullState state;
704     g_return_val_if_fail(WEBKIT_DOM_IS_ELEMENT(self), 0);
705     g_return_val_if_fail(namespaceURI, 0);
706     g_return_val_if_fail(localName, 0);
707     WebCore::Element* item = WebKit::core(self);
708     WTF::String convertedNamespaceURI = WTF::String::fromUTF8(namespaceURI);
709     WTF::String convertedLocalName = WTF::String::fromUTF8(localName);
710     gchar* result = convertToUTF8String(item->getAttributeNS(convertedNamespaceURI, convertedLocalName));
711     return result;
712 }
713
714 void webkit_dom_element_set_attribute_ns(WebKitDOMElement* self, const gchar* namespaceURI, const gchar* qualifiedName, const gchar* value, GError** error)
715 {
716     WebCore::JSMainThreadNullState state;
717     g_return_if_fail(WEBKIT_DOM_IS_ELEMENT(self));
718     g_return_if_fail(qualifiedName);
719     g_return_if_fail(value);
720     g_return_if_fail(!error || !*error);
721     WebCore::Element* item = WebKit::core(self);
722     WTF::String convertedNamespaceURI = WTF::String::fromUTF8(namespaceURI);
723     WTF::String convertedQualifiedName = WTF::String::fromUTF8(qualifiedName);
724     WTF::String convertedValue = WTF::String::fromUTF8(value);
725     auto result = item->setAttributeNS(convertedNamespaceURI, convertedQualifiedName, convertedValue);
726     if (result.hasException()) {
727         auto description = WebCore::DOMException::description(result.releaseException().code());
728         g_set_error_literal(error, g_quark_from_string("WEBKIT_DOM"), description.legacyCode, description.name);
729     }
730 }
731
732 void webkit_dom_element_remove_attribute_ns(WebKitDOMElement* self, const gchar* namespaceURI, const gchar* localName)
733 {
734     WebCore::JSMainThreadNullState state;
735     g_return_if_fail(WEBKIT_DOM_IS_ELEMENT(self));
736     g_return_if_fail(namespaceURI);
737     g_return_if_fail(localName);
738     WebCore::Element* item = WebKit::core(self);
739     WTF::String convertedNamespaceURI = WTF::String::fromUTF8(namespaceURI);
740     WTF::String convertedLocalName = WTF::String::fromUTF8(localName);
741     item->removeAttributeNS(convertedNamespaceURI, convertedLocalName);
742 }
743
744 WebKitDOMHTMLCollection* webkit_dom_element_get_elements_by_tag_name_ns_as_html_collection(WebKitDOMElement* self, const gchar* namespaceURI, const gchar* localName)
745 {
746     WebCore::JSMainThreadNullState state;
747     g_return_val_if_fail(WEBKIT_DOM_IS_ELEMENT(self), 0);
748     g_return_val_if_fail(namespaceURI, 0);
749     g_return_val_if_fail(localName, 0);
750     WebCore::Element* item = WebKit::core(self);
751     WTF::String convertedNamespaceURI = WTF::String::fromUTF8(namespaceURI);
752     WTF::String convertedLocalName = WTF::String::fromUTF8(localName);
753     RefPtr<WebCore::HTMLCollection> gobjectResult = WTF::getPtr(item->getElementsByTagNameNS(convertedNamespaceURI, convertedLocalName));
754     return WebKit::kit(gobjectResult.get());
755 }
756
757 WebKitDOMAttr* webkit_dom_element_get_attribute_node_ns(WebKitDOMElement* self, const gchar* namespaceURI, const gchar* localName)
758 {
759     WebCore::JSMainThreadNullState state;
760     g_return_val_if_fail(WEBKIT_DOM_IS_ELEMENT(self), 0);
761     g_return_val_if_fail(namespaceURI, 0);
762     g_return_val_if_fail(localName, 0);
763     WebCore::Element* item = WebKit::core(self);
764     WTF::String convertedNamespaceURI = WTF::String::fromUTF8(namespaceURI);
765     WTF::String convertedLocalName = WTF::String::fromUTF8(localName);
766     RefPtr<WebCore::Attr> gobjectResult = WTF::getPtr(item->getAttributeNodeNS(convertedNamespaceURI, convertedLocalName));
767     return WebKit::kit(gobjectResult.get());
768 }
769
770 WebKitDOMAttr* webkit_dom_element_set_attribute_node_ns(WebKitDOMElement* self, WebKitDOMAttr* newAttr, GError** error)
771 {
772     WebCore::JSMainThreadNullState state;
773     g_return_val_if_fail(WEBKIT_DOM_IS_ELEMENT(self), 0);
774     g_return_val_if_fail(WEBKIT_DOM_IS_ATTR(newAttr), 0);
775     g_return_val_if_fail(!error || !*error, 0);
776     WebCore::Element* item = WebKit::core(self);
777     WebCore::Attr* convertedNewAttr = WebKit::core(newAttr);
778     auto result = item->setAttributeNodeNS(*convertedNewAttr);
779     if (result.hasException()) {
780         auto description = WebCore::DOMException::description(result.releaseException().code());
781         g_set_error_literal(error, g_quark_from_string("WEBKIT_DOM"), description.legacyCode, description.name);
782         return nullptr;
783     }
784     return WebKit::kit(result.releaseReturnValue().get());
785 }
786
787 gboolean webkit_dom_element_has_attribute(WebKitDOMElement* self, const gchar* name)
788 {
789     WebCore::JSMainThreadNullState state;
790     g_return_val_if_fail(WEBKIT_DOM_IS_ELEMENT(self), FALSE);
791     g_return_val_if_fail(name, FALSE);
792     WebCore::Element* item = WebKit::core(self);
793     WTF::String convertedName = WTF::String::fromUTF8(name);
794     gboolean result = item->hasAttribute(convertedName);
795     return result;
796 }
797
798 gboolean webkit_dom_element_has_attribute_ns(WebKitDOMElement* self, const gchar* namespaceURI, const gchar* localName)
799 {
800     WebCore::JSMainThreadNullState state;
801     g_return_val_if_fail(WEBKIT_DOM_IS_ELEMENT(self), FALSE);
802     g_return_val_if_fail(namespaceURI, FALSE);
803     g_return_val_if_fail(localName, FALSE);
804     WebCore::Element* item = WebKit::core(self);
805     WTF::String convertedNamespaceURI = WTF::String::fromUTF8(namespaceURI);
806     WTF::String convertedLocalName = WTF::String::fromUTF8(localName);
807     gboolean result = item->hasAttributeNS(convertedNamespaceURI, convertedLocalName);
808     return result;
809 }
810
811 void webkit_dom_element_focus(WebKitDOMElement* self)
812 {
813     WebCore::JSMainThreadNullState state;
814     g_return_if_fail(WEBKIT_DOM_IS_ELEMENT(self));
815     WebCore::Element* item = WebKit::core(self);
816     item->focus();
817 }
818
819 void webkit_dom_element_blur(WebKitDOMElement* self)
820 {
821     WebCore::JSMainThreadNullState state;
822     g_return_if_fail(WEBKIT_DOM_IS_ELEMENT(self));
823     WebCore::Element* item = WebKit::core(self);
824     item->blur();
825 }
826
827 void webkit_dom_element_scroll_into_view(WebKitDOMElement* self, gboolean alignWithTop)
828 {
829     WebCore::JSMainThreadNullState state;
830     g_return_if_fail(WEBKIT_DOM_IS_ELEMENT(self));
831     WebCore::Element* item = WebKit::core(self);
832     item->scrollIntoView(alignWithTop);
833 }
834
835 void webkit_dom_element_scroll_into_view_if_needed(WebKitDOMElement* self, gboolean centerIfNeeded)
836 {
837     WebCore::JSMainThreadNullState state;
838     g_return_if_fail(WEBKIT_DOM_IS_ELEMENT(self));
839     WebCore::Element* item = WebKit::core(self);
840     item->scrollIntoViewIfNeeded(centerIfNeeded);
841 }
842
843 void webkit_dom_element_scroll_by_lines(WebKitDOMElement* self, glong lines)
844 {
845     WebCore::JSMainThreadNullState state;
846     g_return_if_fail(WEBKIT_DOM_IS_ELEMENT(self));
847     WebCore::Element* item = WebKit::core(self);
848     item->scrollByLines(lines);
849 }
850
851 void webkit_dom_element_scroll_by_pages(WebKitDOMElement* self, glong pages)
852 {
853     WebCore::JSMainThreadNullState state;
854     g_return_if_fail(WEBKIT_DOM_IS_ELEMENT(self));
855     WebCore::Element* item = WebKit::core(self);
856     item->scrollByPages(pages);
857 }
858
859 WebKitDOMHTMLCollection* webkit_dom_element_get_elements_by_class_name_as_html_collection(WebKitDOMElement* self, const gchar* name)
860 {
861     WebCore::JSMainThreadNullState state;
862     g_return_val_if_fail(WEBKIT_DOM_IS_ELEMENT(self), 0);
863     g_return_val_if_fail(name, 0);
864     WebCore::Element* item = WebKit::core(self);
865     WTF::String convertedName = WTF::String::fromUTF8(name);
866     RefPtr<WebCore::HTMLCollection> gobjectResult = WTF::getPtr(item->getElementsByClassName(convertedName));
867     return WebKit::kit(gobjectResult.get());
868 }
869
870 gboolean webkit_dom_element_matches(WebKitDOMElement* self, const gchar* selectors, GError** error)
871 {
872     WebCore::JSMainThreadNullState state;
873     g_return_val_if_fail(WEBKIT_DOM_IS_ELEMENT(self), FALSE);
874     g_return_val_if_fail(selectors, FALSE);
875     g_return_val_if_fail(!error || !*error, FALSE);
876     WebCore::Element* item = WebKit::core(self);
877     WTF::String convertedSelectors = WTF::String::fromUTF8(selectors);
878     auto result = item->matches(convertedSelectors);
879     if (result.hasException()) {
880         auto description = WebCore::DOMException::description(result.releaseException().code());
881         g_set_error_literal(error, g_quark_from_string("WEBKIT_DOM"), description.legacyCode, description.name);
882         return false;
883     }
884     return result.releaseReturnValue();
885 }
886
887 WebKitDOMElement* webkit_dom_element_closest(WebKitDOMElement* self, const gchar* selectors, GError** error)
888 {
889     WebCore::JSMainThreadNullState state;
890     g_return_val_if_fail(WEBKIT_DOM_IS_ELEMENT(self), 0);
891     g_return_val_if_fail(selectors, 0);
892     g_return_val_if_fail(!error || !*error, 0);
893     WebCore::Element* item = WebKit::core(self);
894     WTF::String convertedSelectors = WTF::String::fromUTF8(selectors);
895     auto result = item->closest(convertedSelectors);
896     if (result.hasException()) {
897         auto description = WebCore::DOMException::description(result.releaseException().code());
898         g_set_error_literal(error, g_quark_from_string("WEBKIT_DOM"), description.legacyCode, description.name);
899         return nullptr;
900     }
901     return WebKit::kit(result.releaseReturnValue());
902 }
903
904 gboolean webkit_dom_element_webkit_matches_selector(WebKitDOMElement* self, const gchar* selectors, GError** error)
905 {
906     return webkit_dom_element_matches(self, selectors, error);
907 }
908
909 void webkit_dom_element_webkit_request_fullscreen(WebKitDOMElement* self)
910 {
911     WebCore::JSMainThreadNullState state;
912     g_return_if_fail(WEBKIT_DOM_IS_ELEMENT(self));
913     WebCore::Element* item = WebKit::core(self);
914     item->webkitRequestFullscreen();
915 }
916
917 WebKitDOMElement* webkit_dom_element_insert_adjacent_element(WebKitDOMElement* self, const gchar* where, WebKitDOMElement* element, GError** error)
918 {
919     WebCore::JSMainThreadNullState state;
920     g_return_val_if_fail(WEBKIT_DOM_IS_ELEMENT(self), 0);
921     g_return_val_if_fail(where, 0);
922     g_return_val_if_fail(WEBKIT_DOM_IS_ELEMENT(element), 0);
923     g_return_val_if_fail(!error || !*error, 0);
924     WebCore::Element* item = WebKit::core(self);
925     WTF::String convertedWhere = WTF::String::fromUTF8(where);
926     WebCore::Element* convertedElement = WebKit::core(element);
927     auto result = item->insertAdjacentElement(convertedWhere, *convertedElement);
928     if (result.hasException()) {
929         auto description = WebCore::DOMException::description(result.releaseException().code());
930         g_set_error_literal(error, g_quark_from_string("WEBKIT_DOM"), description.legacyCode, description.name);
931         return nullptr;
932     }
933     return WebKit::kit(result.releaseReturnValue());
934 }
935
936 void webkit_dom_element_insert_adjacent_html(WebKitDOMElement* self, const gchar* where, const gchar* html, GError** error)
937 {
938     WebCore::JSMainThreadNullState state;
939     g_return_if_fail(WEBKIT_DOM_IS_ELEMENT(self));
940     g_return_if_fail(where);
941     g_return_if_fail(html);
942     g_return_if_fail(!error || !*error);
943     WebCore::Element* item = WebKit::core(self);
944     WTF::String convertedWhere = WTF::String::fromUTF8(where);
945     WTF::String convertedHtml = WTF::String::fromUTF8(html);
946     auto result = item->insertAdjacentHTML(convertedWhere, convertedHtml);
947     if (result.hasException()) {
948         auto description = WebCore::DOMException::description(result.releaseException().code());
949         g_set_error_literal(error, g_quark_from_string("WEBKIT_DOM"), description.legacyCode, description.name);
950     }
951 }
952
953 void webkit_dom_element_insert_adjacent_text(WebKitDOMElement* self, const gchar* where, const gchar* text, GError** error)
954 {
955     WebCore::JSMainThreadNullState state;
956     g_return_if_fail(WEBKIT_DOM_IS_ELEMENT(self));
957     g_return_if_fail(where);
958     g_return_if_fail(text);
959     g_return_if_fail(!error || !*error);
960     WebCore::Element* item = WebKit::core(self);
961     WTF::String convertedWhere = WTF::String::fromUTF8(where);
962     WTF::String convertedText = WTF::String::fromUTF8(text);
963     auto result = item->insertAdjacentText(convertedWhere, convertedText);
964     if (result.hasException()) {
965         auto description = WebCore::DOMException::description(result.releaseException().code());
966         g_set_error_literal(error, g_quark_from_string("WEBKIT_DOM"), description.legacyCode, description.name);
967     }
968 }
969
970 void webkit_dom_element_request_pointer_lock(WebKitDOMElement* self)
971 {
972 #if ENABLE(POINTER_LOCK)
973     WebCore::JSMainThreadNullState state;
974     g_return_if_fail(WEBKIT_DOM_IS_ELEMENT(self));
975     WebCore::Element* item = WebKit::core(self);
976     item->requestPointerLock();
977 #else
978     UNUSED_PARAM(self);
979     WEBKIT_WARN_FEATURE_NOT_PRESENT("Pointer Lock")
980 #endif /* ENABLE(POINTER_LOCK) */
981 }
982
983 void webkit_dom_element_remove(WebKitDOMElement* self, GError** error)
984 {
985     WebCore::JSMainThreadNullState state;
986     g_return_if_fail(WEBKIT_DOM_IS_ELEMENT(self));
987     g_return_if_fail(!error || !*error);
988     WebCore::Element* item = WebKit::core(self);
989     auto result = item->remove();
990     if (result.hasException()) {
991         auto description = WebCore::DOMException::description(result.releaseException().code());
992         g_set_error_literal(error, g_quark_from_string("WEBKIT_DOM"), description.legacyCode, description.name);
993     }
994 }
995
996 WebKitDOMElement* webkit_dom_element_query_selector(WebKitDOMElement* self, const gchar* selectors, GError** error)
997 {
998     WebCore::JSMainThreadNullState state;
999     g_return_val_if_fail(WEBKIT_DOM_IS_ELEMENT(self), 0);
1000     g_return_val_if_fail(selectors, 0);
1001     g_return_val_if_fail(!error || !*error, 0);
1002     WebCore::Element* item = WebKit::core(self);
1003     WTF::String convertedSelectors = WTF::String::fromUTF8(selectors);
1004     auto result = item->querySelector(convertedSelectors);
1005     if (result.hasException()) {
1006         auto description = WebCore::DOMException::description(result.releaseException().code());
1007         g_set_error_literal(error, g_quark_from_string("WEBKIT_DOM"), description.legacyCode, description.name);
1008         return nullptr;
1009     }
1010     return WebKit::kit(result.releaseReturnValue());
1011 }
1012
1013 WebKitDOMNodeList* webkit_dom_element_query_selector_all(WebKitDOMElement* self, const gchar* selectors, GError** error)
1014 {
1015     WebCore::JSMainThreadNullState state;
1016     g_return_val_if_fail(WEBKIT_DOM_IS_ELEMENT(self), 0);
1017     g_return_val_if_fail(selectors, 0);
1018     g_return_val_if_fail(!error || !*error, 0);
1019     WebCore::Element* item = WebKit::core(self);
1020     WTF::String convertedSelectors = WTF::String::fromUTF8(selectors);
1021     auto result = item->querySelectorAll(convertedSelectors);
1022     if (result.hasException()) {
1023         auto description = WebCore::DOMException::description(result.releaseException().code());
1024         g_set_error_literal(error, g_quark_from_string("WEBKIT_DOM"), description.legacyCode, description.name);
1025         return nullptr;
1026     }
1027     return WebKit::kit(result.releaseReturnValue().ptr());
1028 }
1029
1030 gchar* webkit_dom_element_get_tag_name(WebKitDOMElement* self)
1031 {
1032     WebCore::JSMainThreadNullState state;
1033     g_return_val_if_fail(WEBKIT_DOM_IS_ELEMENT(self), 0);
1034     WebCore::Element* item = WebKit::core(self);
1035     gchar* result = convertToUTF8String(item->tagName());
1036     return result;
1037 }
1038
1039 WebKitDOMNamedNodeMap* webkit_dom_element_get_attributes(WebKitDOMElement* self)
1040 {
1041     WebCore::JSMainThreadNullState state;
1042     g_return_val_if_fail(WEBKIT_DOM_IS_ELEMENT(self), 0);
1043     WebCore::Element* item = WebKit::core(self);
1044     RefPtr<WebCore::NamedNodeMap> gobjectResult = WTF::getPtr(item->attributes());
1045     return WebKit::kit(gobjectResult.get());
1046 }
1047
1048 WebKitDOMCSSStyleDeclaration* webkit_dom_element_get_style(WebKitDOMElement* self)
1049 {
1050     WebCore::JSMainThreadNullState state;
1051     g_return_val_if_fail(WEBKIT_DOM_IS_ELEMENT(self), 0);
1052     auto& item = *WebKit::core(self);
1053     if (!is<WebCore::StyledElement>(item))
1054         return nullptr;
1055     return WebKit::kit(&downcast<WebCore::StyledElement>(item).cssomStyle());
1056 }
1057
1058 gchar* webkit_dom_element_get_id(WebKitDOMElement* self)
1059 {
1060     WebCore::JSMainThreadNullState state;
1061     g_return_val_if_fail(WEBKIT_DOM_IS_ELEMENT(self), 0);
1062     WebCore::Element* item = WebKit::core(self);
1063     gchar* result = convertToUTF8String(item->getIdAttribute());
1064     return result;
1065 }
1066
1067 void webkit_dom_element_set_id(WebKitDOMElement* self, const gchar* value)
1068 {
1069     WebCore::JSMainThreadNullState state;
1070     g_return_if_fail(WEBKIT_DOM_IS_ELEMENT(self));
1071     g_return_if_fail(value);
1072     WebCore::Element* item = WebKit::core(self);
1073     WTF::String convertedValue = WTF::String::fromUTF8(value);
1074     item->setAttributeWithoutSynchronization(WebCore::HTMLNames::idAttr, convertedValue);
1075 }
1076
1077 gchar* webkit_dom_element_get_namespace_uri(WebKitDOMElement* self)
1078 {
1079     WebCore::JSMainThreadNullState state;
1080     g_return_val_if_fail(WEBKIT_DOM_IS_ELEMENT(self), 0);
1081     WebCore::Element* item = WebKit::core(self);
1082     gchar* result = convertToUTF8String(item->namespaceURI());
1083     return result;
1084 }
1085
1086 gchar* webkit_dom_element_get_prefix(WebKitDOMElement* self)
1087 {
1088     WebCore::JSMainThreadNullState state;
1089     g_return_val_if_fail(WEBKIT_DOM_IS_ELEMENT(self), 0);
1090     WebCore::Element* item = WebKit::core(self);
1091     gchar* result = convertToUTF8String(item->prefix());
1092     return result;
1093 }
1094
1095 gchar* webkit_dom_element_get_local_name(WebKitDOMElement* self)
1096 {
1097     WebCore::JSMainThreadNullState state;
1098     g_return_val_if_fail(WEBKIT_DOM_IS_ELEMENT(self), 0);
1099     WebCore::Element* item = WebKit::core(self);
1100     gchar* result = convertToUTF8String(item->localName());
1101     return result;
1102 }
1103
1104 gdouble webkit_dom_element_get_offset_left(WebKitDOMElement* self)
1105 {
1106     WebCore::JSMainThreadNullState state;
1107     g_return_val_if_fail(WEBKIT_DOM_IS_ELEMENT(self), 0);
1108     WebCore::Element* item = WebKit::core(self);
1109     gdouble result = item->offsetLeft();
1110     return result;
1111 }
1112
1113 gdouble webkit_dom_element_get_offset_top(WebKitDOMElement* self)
1114 {
1115     WebCore::JSMainThreadNullState state;
1116     g_return_val_if_fail(WEBKIT_DOM_IS_ELEMENT(self), 0);
1117     WebCore::Element* item = WebKit::core(self);
1118     gdouble result = item->offsetTop();
1119     return result;
1120 }
1121
1122 gdouble webkit_dom_element_get_offset_width(WebKitDOMElement* self)
1123 {
1124     WebCore::JSMainThreadNullState state;
1125     g_return_val_if_fail(WEBKIT_DOM_IS_ELEMENT(self), 0);
1126     WebCore::Element* item = WebKit::core(self);
1127     gdouble result = item->offsetWidth();
1128     return result;
1129 }
1130
1131 gdouble webkit_dom_element_get_offset_height(WebKitDOMElement* self)
1132 {
1133     WebCore::JSMainThreadNullState state;
1134     g_return_val_if_fail(WEBKIT_DOM_IS_ELEMENT(self), 0);
1135     WebCore::Element* item = WebKit::core(self);
1136     gdouble result = item->offsetHeight();
1137     return result;
1138 }
1139
1140 gdouble webkit_dom_element_get_client_left(WebKitDOMElement* self)
1141 {
1142     WebCore::JSMainThreadNullState state;
1143     g_return_val_if_fail(WEBKIT_DOM_IS_ELEMENT(self), 0);
1144     WebCore::Element* item = WebKit::core(self);
1145     gdouble result = item->clientLeft();
1146     return result;
1147 }
1148
1149 gdouble webkit_dom_element_get_client_top(WebKitDOMElement* self)
1150 {
1151     WebCore::JSMainThreadNullState state;
1152     g_return_val_if_fail(WEBKIT_DOM_IS_ELEMENT(self), 0);
1153     WebCore::Element* item = WebKit::core(self);
1154     gdouble result = item->clientTop();
1155     return result;
1156 }
1157
1158 gdouble webkit_dom_element_get_client_width(WebKitDOMElement* self)
1159 {
1160     WebCore::JSMainThreadNullState state;
1161     g_return_val_if_fail(WEBKIT_DOM_IS_ELEMENT(self), 0);
1162     WebCore::Element* item = WebKit::core(self);
1163     gdouble result = item->clientWidth();
1164     return result;
1165 }
1166
1167 gdouble webkit_dom_element_get_client_height(WebKitDOMElement* self)
1168 {
1169     WebCore::JSMainThreadNullState state;
1170     g_return_val_if_fail(WEBKIT_DOM_IS_ELEMENT(self), 0);
1171     WebCore::Element* item = WebKit::core(self);
1172     gdouble result = item->clientHeight();
1173     return result;
1174 }
1175
1176 glong webkit_dom_element_get_scroll_left(WebKitDOMElement* self)
1177 {
1178     WebCore::JSMainThreadNullState state;
1179     g_return_val_if_fail(WEBKIT_DOM_IS_ELEMENT(self), 0);
1180     WebCore::Element* item = WebKit::core(self);
1181     glong result = item->scrollLeft();
1182     return result;
1183 }
1184
1185 void webkit_dom_element_set_scroll_left(WebKitDOMElement* self, glong value)
1186 {
1187     WebCore::JSMainThreadNullState state;
1188     g_return_if_fail(WEBKIT_DOM_IS_ELEMENT(self));
1189     WebCore::Element* item = WebKit::core(self);
1190     item->setScrollLeft(value);
1191 }
1192
1193 glong webkit_dom_element_get_scroll_top(WebKitDOMElement* self)
1194 {
1195     WebCore::JSMainThreadNullState state;
1196     g_return_val_if_fail(WEBKIT_DOM_IS_ELEMENT(self), 0);
1197     WebCore::Element* item = WebKit::core(self);
1198     glong result = item->scrollTop();
1199     return result;
1200 }
1201
1202 void webkit_dom_element_set_scroll_top(WebKitDOMElement* self, glong value)
1203 {
1204     WebCore::JSMainThreadNullState state;
1205     g_return_if_fail(WEBKIT_DOM_IS_ELEMENT(self));
1206     WebCore::Element* item = WebKit::core(self);
1207     item->setScrollTop(value);
1208 }
1209
1210 glong webkit_dom_element_get_scroll_width(WebKitDOMElement* self)
1211 {
1212     WebCore::JSMainThreadNullState state;
1213     g_return_val_if_fail(WEBKIT_DOM_IS_ELEMENT(self), 0);
1214     WebCore::Element* item = WebKit::core(self);
1215     glong result = item->scrollWidth();
1216     return result;
1217 }
1218
1219 glong webkit_dom_element_get_scroll_height(WebKitDOMElement* self)
1220 {
1221     WebCore::JSMainThreadNullState state;
1222     g_return_val_if_fail(WEBKIT_DOM_IS_ELEMENT(self), 0);
1223     WebCore::Element* item = WebKit::core(self);
1224     glong result = item->scrollHeight();
1225     return result;
1226 }
1227
1228 WebKitDOMClientRect* webkit_dom_element_get_bounding_client_rect(WebKitDOMElement* self)
1229 {
1230     WebCore::JSMainThreadNullState state;
1231     g_return_val_if_fail(WEBKIT_DOM_IS_ELEMENT(self), nullptr);
1232     WebCore::Element* item = WebKit::core(self);
1233     return WebKit::kit(item->getBoundingClientRect().ptr());
1234 }
1235
1236 WebKitDOMClientRectList* webkit_dom_element_get_client_rects(WebKitDOMElement* self)
1237 {
1238     WebCore::JSMainThreadNullState state;
1239     g_return_val_if_fail(WEBKIT_DOM_IS_ELEMENT(self), nullptr);
1240     WebCore::Element* item = WebKit::core(self);
1241     return WebKit::kit(item->getClientRects().ptr());
1242 }
1243
1244 WebKitDOMElement* webkit_dom_element_get_offset_parent(WebKitDOMElement* self)
1245 {
1246     WebCore::JSMainThreadNullState state;
1247     g_return_val_if_fail(WEBKIT_DOM_IS_ELEMENT(self), 0);
1248     WebCore::Element* item = WebKit::core(self);
1249     RefPtr<WebCore::Element> gobjectResult = WTF::getPtr(item->bindingsOffsetParent());
1250     return WebKit::kit(gobjectResult.get());
1251 }
1252
1253 gchar* webkit_dom_element_get_inner_html(WebKitDOMElement* self)
1254 {
1255     WebCore::JSMainThreadNullState state;
1256     g_return_val_if_fail(WEBKIT_DOM_IS_ELEMENT(self), 0);
1257     WebCore::Element* item = WebKit::core(self);
1258     gchar* result = convertToUTF8String(item->innerHTML());
1259     return result;
1260 }
1261
1262 void webkit_dom_element_set_inner_html(WebKitDOMElement* self, const gchar* value, GError** error)
1263 {
1264     WebCore::JSMainThreadNullState state;
1265     g_return_if_fail(WEBKIT_DOM_IS_ELEMENT(self));
1266     g_return_if_fail(value);
1267     g_return_if_fail(!error || !*error);
1268     WebCore::Element* item = WebKit::core(self);
1269     WTF::String convertedValue = WTF::String::fromUTF8(value);
1270     auto result = item->setInnerHTML(convertedValue);
1271     if (result.hasException()) {
1272         auto description = WebCore::DOMException::description(result.releaseException().code());
1273         g_set_error_literal(error, g_quark_from_string("WEBKIT_DOM"), description.legacyCode, description.name);
1274     }
1275 }
1276
1277 gchar* webkit_dom_element_get_outer_html(WebKitDOMElement* self)
1278 {
1279     WebCore::JSMainThreadNullState state;
1280     g_return_val_if_fail(WEBKIT_DOM_IS_ELEMENT(self), 0);
1281     WebCore::Element* item = WebKit::core(self);
1282     gchar* result = convertToUTF8String(item->outerHTML());
1283     return result;
1284 }
1285
1286 void webkit_dom_element_set_outer_html(WebKitDOMElement* self, const gchar* value, GError** error)
1287 {
1288     WebCore::JSMainThreadNullState state;
1289     g_return_if_fail(WEBKIT_DOM_IS_ELEMENT(self));
1290     g_return_if_fail(value);
1291     g_return_if_fail(!error || !*error);
1292     WebCore::Element* item = WebKit::core(self);
1293     WTF::String convertedValue = WTF::String::fromUTF8(value);
1294     auto result = item->setOuterHTML(convertedValue);
1295     if (result.hasException()) {
1296         auto description = WebCore::DOMException::description(result.releaseException().code());
1297         g_set_error_literal(error, g_quark_from_string("WEBKIT_DOM"), description.legacyCode, description.name);
1298     }
1299 }
1300
1301 gchar* webkit_dom_element_get_class_name(WebKitDOMElement* self)
1302 {
1303     WebCore::JSMainThreadNullState state;
1304     g_return_val_if_fail(WEBKIT_DOM_IS_ELEMENT(self), 0);
1305     WebCore::Element* item = WebKit::core(self);
1306     gchar* result = convertToUTF8String(item->attributeWithoutSynchronization(WebCore::HTMLNames::classAttr));
1307     return result;
1308 }
1309
1310 void webkit_dom_element_set_class_name(WebKitDOMElement* self, const gchar* value)
1311 {
1312     WebCore::JSMainThreadNullState state;
1313     g_return_if_fail(WEBKIT_DOM_IS_ELEMENT(self));
1314     g_return_if_fail(value);
1315     WebCore::Element* item = WebKit::core(self);
1316     WTF::String convertedValue = WTF::String::fromUTF8(value);
1317     item->setAttributeWithoutSynchronization(WebCore::HTMLNames::classAttr, convertedValue);
1318 }
1319
1320 WebKitDOMDOMTokenList* webkit_dom_element_get_class_list(WebKitDOMElement* self)
1321 {
1322     WebCore::JSMainThreadNullState state;
1323     g_return_val_if_fail(WEBKIT_DOM_IS_ELEMENT(self), 0);
1324     WebCore::Element* item = WebKit::core(self);
1325     RefPtr<WebCore::DOMTokenList> gobjectResult = WTF::getPtr(item->classList());
1326     return WebKit::kit(gobjectResult.get());
1327 }
1328
1329 gchar* webkit_dom_element_get_webkit_region_overset(WebKitDOMElement* self)
1330 {
1331 #if ENABLE(CSS_REGIONS)
1332     WebCore::JSMainThreadNullState state;
1333     g_return_val_if_fail(WEBKIT_DOM_IS_ELEMENT(self), 0);
1334     WebCore::Element* item = WebKit::core(self);
1335     gchar* result = convertToUTF8String(item->webkitRegionOverset());
1336     return result;
1337 #else
1338     UNUSED_PARAM(self);
1339     WEBKIT_WARN_FEATURE_NOT_PRESENT("Css Regions")
1340     return 0;
1341 #endif /* ENABLE(CSS_REGIONS) */
1342 }
1343
1344 WebKitDOMElement* webkit_dom_element_get_previous_element_sibling(WebKitDOMElement* self)
1345 {
1346     WebCore::JSMainThreadNullState state;
1347     g_return_val_if_fail(WEBKIT_DOM_IS_ELEMENT(self), 0);
1348     WebCore::Element* item = WebKit::core(self);
1349     RefPtr<WebCore::Element> gobjectResult = WTF::getPtr(item->previousElementSibling());
1350     return WebKit::kit(gobjectResult.get());
1351 }
1352
1353 WebKitDOMElement* webkit_dom_element_get_next_element_sibling(WebKitDOMElement* self)
1354 {
1355     WebCore::JSMainThreadNullState state;
1356     g_return_val_if_fail(WEBKIT_DOM_IS_ELEMENT(self), 0);
1357     WebCore::Element* item = WebKit::core(self);
1358     RefPtr<WebCore::Element> gobjectResult = WTF::getPtr(item->nextElementSibling());
1359     return WebKit::kit(gobjectResult.get());
1360 }
1361
1362 WebKitDOMHTMLCollection* webkit_dom_element_get_children(WebKitDOMElement* self)
1363 {
1364     WebCore::JSMainThreadNullState state;
1365     g_return_val_if_fail(WEBKIT_DOM_IS_ELEMENT(self), 0);
1366     WebCore::Element* item = WebKit::core(self);
1367     RefPtr<WebCore::HTMLCollection> gobjectResult = WTF::getPtr(item->children());
1368     return WebKit::kit(gobjectResult.get());
1369 }
1370
1371 WebKitDOMElement* webkit_dom_element_get_first_element_child(WebKitDOMElement* self)
1372 {
1373     WebCore::JSMainThreadNullState state;
1374     g_return_val_if_fail(WEBKIT_DOM_IS_ELEMENT(self), 0);
1375     WebCore::Element* item = WebKit::core(self);
1376     RefPtr<WebCore::Element> gobjectResult = WTF::getPtr(item->firstElementChild());
1377     return WebKit::kit(gobjectResult.get());
1378 }
1379
1380 WebKitDOMElement* webkit_dom_element_get_last_element_child(WebKitDOMElement* self)
1381 {
1382     WebCore::JSMainThreadNullState state;
1383     g_return_val_if_fail(WEBKIT_DOM_IS_ELEMENT(self), 0);
1384     WebCore::Element* item = WebKit::core(self);
1385     RefPtr<WebCore::Element> gobjectResult = WTF::getPtr(item->lastElementChild());
1386     return WebKit::kit(gobjectResult.get());
1387 }
1388
1389 gulong webkit_dom_element_get_child_element_count(WebKitDOMElement* self)
1390 {
1391     WebCore::JSMainThreadNullState state;
1392     g_return_val_if_fail(WEBKIT_DOM_IS_ELEMENT(self), 0);
1393     WebCore::Element* item = WebKit::core(self);
1394     gulong result = item->childElementCount();
1395     return result;
1396 }
1397