Drop ExceptionCodeDescription class
[WebKit-https.git] / Source / WebKit / WebProcess / InjectedBundle / API / gtk / DOM / WebKitDOMHTMLSelectElement.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 "WebKitDOMHTMLSelectElement.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/HTMLOptGroupElement.h>
30 #include <WebCore/JSMainThreadExecState.h>
31 #include "WebKitDOMEventPrivate.h"
32 #include "WebKitDOMEventTarget.h"
33 #include "WebKitDOMHTMLCollectionPrivate.h"
34 #include "WebKitDOMHTMLElementPrivate.h"
35 #include "WebKitDOMHTMLFormElementPrivate.h"
36 #include "WebKitDOMHTMLOptionsCollectionPrivate.h"
37 #include "WebKitDOMHTMLSelectElementPrivate.h"
38 #include "WebKitDOMNodeListPrivate.h"
39 #include "WebKitDOMNodePrivate.h"
40 #include "WebKitDOMPrivate.h"
41 #include "ConvertToUTF8String.h"
42 #include <wtf/GetPtr.h>
43 #include <wtf/RefPtr.h>
44
45 namespace WebKit {
46
47 WebKitDOMHTMLSelectElement* kit(WebCore::HTMLSelectElement* obj)
48 {
49     return WEBKIT_DOM_HTML_SELECT_ELEMENT(kit(static_cast<WebCore::Node*>(obj)));
50 }
51
52 WebCore::HTMLSelectElement* core(WebKitDOMHTMLSelectElement* request)
53 {
54     return request ? static_cast<WebCore::HTMLSelectElement*>(WEBKIT_DOM_OBJECT(request)->coreObject) : 0;
55 }
56
57 WebKitDOMHTMLSelectElement* wrapHTMLSelectElement(WebCore::HTMLSelectElement* coreObject)
58 {
59     ASSERT(coreObject);
60     return WEBKIT_DOM_HTML_SELECT_ELEMENT(g_object_new(WEBKIT_DOM_TYPE_HTML_SELECT_ELEMENT, "core-object", coreObject, nullptr));
61 }
62
63 } // namespace WebKit
64
65 static gboolean webkit_dom_html_select_element_dispatch_event(WebKitDOMEventTarget* target, WebKitDOMEvent* event, GError** error)
66 {
67     WebCore::Event* coreEvent = WebKit::core(event);
68     if (!coreEvent)
69         return false;
70     WebCore::HTMLSelectElement* coreTarget = static_cast<WebCore::HTMLSelectElement*>(WEBKIT_DOM_OBJECT(target)->coreObject);
71
72     auto result = coreTarget->dispatchEventForBindings(*coreEvent);
73     if (result.hasException()) {
74         auto description = WebCore::DOMException::description(result.releaseException().code());
75         g_set_error_literal(error, g_quark_from_string("WEBKIT_DOM"), description.legacyCode, description.name);
76         return false;
77     }
78     return result.releaseReturnValue();
79 }
80
81 static gboolean webkit_dom_html_select_element_add_event_listener(WebKitDOMEventTarget* target, const char* eventName, GClosure* handler, gboolean useCapture)
82 {
83     WebCore::HTMLSelectElement* coreTarget = static_cast<WebCore::HTMLSelectElement*>(WEBKIT_DOM_OBJECT(target)->coreObject);
84     return WebKit::GObjectEventListener::addEventListener(G_OBJECT(target), coreTarget, eventName, handler, useCapture);
85 }
86
87 static gboolean webkit_dom_html_select_element_remove_event_listener(WebKitDOMEventTarget* target, const char* eventName, GClosure* handler, gboolean useCapture)
88 {
89     WebCore::HTMLSelectElement* coreTarget = static_cast<WebCore::HTMLSelectElement*>(WEBKIT_DOM_OBJECT(target)->coreObject);
90     return WebKit::GObjectEventListener::removeEventListener(G_OBJECT(target), coreTarget, eventName, handler, useCapture);
91 }
92
93 static void webkit_dom_event_target_init(WebKitDOMEventTargetIface* iface)
94 {
95     iface->dispatch_event = webkit_dom_html_select_element_dispatch_event;
96     iface->add_event_listener = webkit_dom_html_select_element_add_event_listener;
97     iface->remove_event_listener = webkit_dom_html_select_element_remove_event_listener;
98 }
99
100 G_DEFINE_TYPE_WITH_CODE(WebKitDOMHTMLSelectElement, webkit_dom_html_select_element, WEBKIT_DOM_TYPE_HTML_ELEMENT, G_IMPLEMENT_INTERFACE(WEBKIT_DOM_TYPE_EVENT_TARGET, webkit_dom_event_target_init))
101
102 enum {
103     PROP_0,
104     PROP_AUTOFOCUS,
105     PROP_DISABLED,
106     PROP_FORM,
107     PROP_MULTIPLE,
108     PROP_NAME,
109     PROP_SIZE,
110     PROP_TYPE,
111     PROP_OPTIONS,
112     PROP_LENGTH,
113     PROP_SELECTED_INDEX,
114     PROP_VALUE,
115     PROP_WILL_VALIDATE,
116 };
117
118 static void webkit_dom_html_select_element_set_property(GObject* object, guint propertyId, const GValue* value, GParamSpec* pspec)
119 {
120     WebKitDOMHTMLSelectElement* self = WEBKIT_DOM_HTML_SELECT_ELEMENT(object);
121
122     switch (propertyId) {
123     case PROP_AUTOFOCUS:
124         webkit_dom_html_select_element_set_autofocus(self, g_value_get_boolean(value));
125         break;
126     case PROP_DISABLED:
127         webkit_dom_html_select_element_set_disabled(self, g_value_get_boolean(value));
128         break;
129     case PROP_MULTIPLE:
130         webkit_dom_html_select_element_set_multiple(self, g_value_get_boolean(value));
131         break;
132     case PROP_NAME:
133         webkit_dom_html_select_element_set_name(self, g_value_get_string(value));
134         break;
135     case PROP_SIZE:
136         webkit_dom_html_select_element_set_size(self, g_value_get_long(value));
137         break;
138     case PROP_LENGTH:
139         webkit_dom_html_select_element_set_length(self, g_value_get_ulong(value), nullptr);
140         break;
141     case PROP_SELECTED_INDEX:
142         webkit_dom_html_select_element_set_selected_index(self, g_value_get_long(value));
143         break;
144     case PROP_VALUE:
145         webkit_dom_html_select_element_set_value(self, g_value_get_string(value));
146         break;
147     default:
148         G_OBJECT_WARN_INVALID_PROPERTY_ID(object, propertyId, pspec);
149         break;
150     }
151 }
152
153 static void webkit_dom_html_select_element_get_property(GObject* object, guint propertyId, GValue* value, GParamSpec* pspec)
154 {
155     WebKitDOMHTMLSelectElement* self = WEBKIT_DOM_HTML_SELECT_ELEMENT(object);
156
157     switch (propertyId) {
158     case PROP_AUTOFOCUS:
159         g_value_set_boolean(value, webkit_dom_html_select_element_get_autofocus(self));
160         break;
161     case PROP_DISABLED:
162         g_value_set_boolean(value, webkit_dom_html_select_element_get_disabled(self));
163         break;
164     case PROP_FORM:
165         g_value_set_object(value, webkit_dom_html_select_element_get_form(self));
166         break;
167     case PROP_MULTIPLE:
168         g_value_set_boolean(value, webkit_dom_html_select_element_get_multiple(self));
169         break;
170     case PROP_NAME:
171         g_value_take_string(value, webkit_dom_html_select_element_get_name(self));
172         break;
173     case PROP_SIZE:
174         g_value_set_long(value, webkit_dom_html_select_element_get_size(self));
175         break;
176     case PROP_TYPE:
177         g_value_take_string(value, webkit_dom_html_select_element_get_select_type(self));
178         break;
179     case PROP_OPTIONS:
180         g_value_set_object(value, webkit_dom_html_select_element_get_options(self));
181         break;
182     case PROP_LENGTH:
183         g_value_set_ulong(value, webkit_dom_html_select_element_get_length(self));
184         break;
185     case PROP_SELECTED_INDEX:
186         g_value_set_long(value, webkit_dom_html_select_element_get_selected_index(self));
187         break;
188     case PROP_VALUE:
189         g_value_take_string(value, webkit_dom_html_select_element_get_value(self));
190         break;
191     case PROP_WILL_VALIDATE:
192         g_value_set_boolean(value, webkit_dom_html_select_element_get_will_validate(self));
193         break;
194     default:
195         G_OBJECT_WARN_INVALID_PROPERTY_ID(object, propertyId, pspec);
196         break;
197     }
198 }
199
200 static void webkit_dom_html_select_element_class_init(WebKitDOMHTMLSelectElementClass* requestClass)
201 {
202     GObjectClass* gobjectClass = G_OBJECT_CLASS(requestClass);
203     gobjectClass->set_property = webkit_dom_html_select_element_set_property;
204     gobjectClass->get_property = webkit_dom_html_select_element_get_property;
205
206     g_object_class_install_property(
207         gobjectClass,
208         PROP_AUTOFOCUS,
209         g_param_spec_boolean(
210             "autofocus",
211             "HTMLSelectElement:autofocus",
212             "read-write gboolean HTMLSelectElement:autofocus",
213             FALSE,
214             WEBKIT_PARAM_READWRITE));
215
216     g_object_class_install_property(
217         gobjectClass,
218         PROP_DISABLED,
219         g_param_spec_boolean(
220             "disabled",
221             "HTMLSelectElement:disabled",
222             "read-write gboolean HTMLSelectElement:disabled",
223             FALSE,
224             WEBKIT_PARAM_READWRITE));
225
226     g_object_class_install_property(
227         gobjectClass,
228         PROP_FORM,
229         g_param_spec_object(
230             "form",
231             "HTMLSelectElement:form",
232             "read-only WebKitDOMHTMLFormElement* HTMLSelectElement:form",
233             WEBKIT_DOM_TYPE_HTML_FORM_ELEMENT,
234             WEBKIT_PARAM_READABLE));
235
236     g_object_class_install_property(
237         gobjectClass,
238         PROP_MULTIPLE,
239         g_param_spec_boolean(
240             "multiple",
241             "HTMLSelectElement:multiple",
242             "read-write gboolean HTMLSelectElement:multiple",
243             FALSE,
244             WEBKIT_PARAM_READWRITE));
245
246     g_object_class_install_property(
247         gobjectClass,
248         PROP_NAME,
249         g_param_spec_string(
250             "name",
251             "HTMLSelectElement:name",
252             "read-write gchar* HTMLSelectElement:name",
253             "",
254             WEBKIT_PARAM_READWRITE));
255
256     g_object_class_install_property(
257         gobjectClass,
258         PROP_SIZE,
259         g_param_spec_long(
260             "size",
261             "HTMLSelectElement:size",
262             "read-write glong HTMLSelectElement:size",
263             G_MINLONG, G_MAXLONG, 0,
264             WEBKIT_PARAM_READWRITE));
265
266     g_object_class_install_property(
267         gobjectClass,
268         PROP_TYPE,
269         g_param_spec_string(
270             "type",
271             "HTMLSelectElement:type",
272             "read-only gchar* HTMLSelectElement:type",
273             "",
274             WEBKIT_PARAM_READABLE));
275
276     g_object_class_install_property(
277         gobjectClass,
278         PROP_OPTIONS,
279         g_param_spec_object(
280             "options",
281             "HTMLSelectElement:options",
282             "read-only WebKitDOMHTMLOptionsCollection* HTMLSelectElement:options",
283             WEBKIT_DOM_TYPE_HTML_OPTIONS_COLLECTION,
284             WEBKIT_PARAM_READABLE));
285
286     g_object_class_install_property(
287         gobjectClass,
288         PROP_LENGTH,
289         g_param_spec_ulong(
290             "length",
291             "HTMLSelectElement:length",
292             "read-write gulong HTMLSelectElement:length",
293             0, G_MAXULONG, 0,
294             WEBKIT_PARAM_READWRITE));
295
296     g_object_class_install_property(
297         gobjectClass,
298         PROP_SELECTED_INDEX,
299         g_param_spec_long(
300             "selected-index",
301             "HTMLSelectElement:selected-index",
302             "read-write glong HTMLSelectElement:selected-index",
303             G_MINLONG, G_MAXLONG, 0,
304             WEBKIT_PARAM_READWRITE));
305
306     g_object_class_install_property(
307         gobjectClass,
308         PROP_VALUE,
309         g_param_spec_string(
310             "value",
311             "HTMLSelectElement:value",
312             "read-write gchar* HTMLSelectElement:value",
313             "",
314             WEBKIT_PARAM_READWRITE));
315
316     g_object_class_install_property(
317         gobjectClass,
318         PROP_WILL_VALIDATE,
319         g_param_spec_boolean(
320             "will-validate",
321             "HTMLSelectElement:will-validate",
322             "read-only gboolean HTMLSelectElement:will-validate",
323             FALSE,
324             WEBKIT_PARAM_READABLE));
325 }
326
327 static void webkit_dom_html_select_element_init(WebKitDOMHTMLSelectElement* request)
328 {
329     UNUSED_PARAM(request);
330 }
331
332 WebKitDOMNode* webkit_dom_html_select_element_item(WebKitDOMHTMLSelectElement* self, gulong index)
333 {
334     WebCore::JSMainThreadNullState state;
335     g_return_val_if_fail(WEBKIT_DOM_IS_HTML_SELECT_ELEMENT(self), 0);
336     WebCore::HTMLSelectElement* item = WebKit::core(self);
337     RefPtr<WebCore::Node> gobjectResult = WTF::getPtr(item->item(index));
338     return WebKit::kit(gobjectResult.get());
339 }
340
341 WebKitDOMNode* webkit_dom_html_select_element_named_item(WebKitDOMHTMLSelectElement* self, const gchar* name)
342 {
343     WebCore::JSMainThreadNullState state;
344     g_return_val_if_fail(WEBKIT_DOM_IS_HTML_SELECT_ELEMENT(self), 0);
345     g_return_val_if_fail(name, 0);
346     WebCore::HTMLSelectElement* item = WebKit::core(self);
347     WTF::String convertedName = WTF::String::fromUTF8(name);
348     RefPtr<WebCore::Node> gobjectResult = WTF::getPtr(item->namedItem(convertedName));
349     return WebKit::kit(gobjectResult.get());
350 }
351
352 void webkit_dom_html_select_element_add(WebKitDOMHTMLSelectElement* self, WebKitDOMHTMLElement* element, WebKitDOMHTMLElement* before, GError** error)
353 {
354     WebCore::JSMainThreadNullState state;
355     g_return_if_fail(WEBKIT_DOM_IS_HTML_SELECT_ELEMENT(self));
356     g_return_if_fail(WEBKIT_DOM_IS_HTML_ELEMENT(element));
357     g_return_if_fail(WEBKIT_DOM_IS_HTML_ELEMENT(before));
358     g_return_if_fail(!error || !*error);
359     WebCore::HTMLSelectElement* item = WebKit::core(self);
360     WebCore::HTMLElement* convertedElement = WebKit::core(element);
361     WebCore::HTMLElement* convertedBefore = WebKit::core(before);
362     Variant<RefPtr<WebCore::HTMLOptionElement>, RefPtr<WebCore::HTMLOptGroupElement>> variantElement;
363     if (is<WebCore::HTMLOptionElement>(convertedElement))
364         variantElement = &downcast<WebCore::HTMLOptionElement>(*convertedElement);
365     else if (is<WebCore::HTMLOptGroupElement>(convertedElement))
366         variantElement = &downcast<WebCore::HTMLOptGroupElement>(*convertedElement);
367     else {
368         auto description = WebCore::DOMException::description(WebCore::TypeError);
369         g_set_error_literal(error, g_quark_from_string("WEBKIT_DOM"), description.legacyCode, description.name);
370         return;
371     }
372
373     auto exception = item->add(WTFMove(variantElement), WebCore::HTMLSelectElement::HTMLElementOrInt(convertedBefore));
374     if (exception.hasException()) {
375         auto description = WebCore::DOMException::description(exception.releaseException().code());
376         g_set_error_literal(error, g_quark_from_string("WEBKIT_DOM"), description.legacyCode, description.name);
377     }
378 }
379
380 void webkit_dom_html_select_element_remove(WebKitDOMHTMLSelectElement* self, glong index)
381 {
382     WebCore::JSMainThreadNullState state;
383     g_return_if_fail(WEBKIT_DOM_IS_HTML_SELECT_ELEMENT(self));
384     WebCore::HTMLSelectElement* item = WebKit::core(self);
385     item->remove(index);
386 }
387
388 gboolean webkit_dom_html_select_element_get_autofocus(WebKitDOMHTMLSelectElement* self)
389 {
390     WebCore::JSMainThreadNullState state;
391     g_return_val_if_fail(WEBKIT_DOM_IS_HTML_SELECT_ELEMENT(self), FALSE);
392     WebCore::HTMLSelectElement* item = WebKit::core(self);
393     gboolean result = item->hasAttributeWithoutSynchronization(WebCore::HTMLNames::autofocusAttr);
394     return result;
395 }
396
397 void webkit_dom_html_select_element_set_autofocus(WebKitDOMHTMLSelectElement* self, gboolean value)
398 {
399     WebCore::JSMainThreadNullState state;
400     g_return_if_fail(WEBKIT_DOM_IS_HTML_SELECT_ELEMENT(self));
401     WebCore::HTMLSelectElement* item = WebKit::core(self);
402     item->setBooleanAttribute(WebCore::HTMLNames::autofocusAttr, value);
403 }
404
405 gboolean webkit_dom_html_select_element_get_disabled(WebKitDOMHTMLSelectElement* self)
406 {
407     WebCore::JSMainThreadNullState state;
408     g_return_val_if_fail(WEBKIT_DOM_IS_HTML_SELECT_ELEMENT(self), FALSE);
409     WebCore::HTMLSelectElement* item = WebKit::core(self);
410     gboolean result = item->hasAttributeWithoutSynchronization(WebCore::HTMLNames::disabledAttr);
411     return result;
412 }
413
414 void webkit_dom_html_select_element_set_disabled(WebKitDOMHTMLSelectElement* self, gboolean value)
415 {
416     WebCore::JSMainThreadNullState state;
417     g_return_if_fail(WEBKIT_DOM_IS_HTML_SELECT_ELEMENT(self));
418     WebCore::HTMLSelectElement* item = WebKit::core(self);
419     item->setBooleanAttribute(WebCore::HTMLNames::disabledAttr, value);
420 }
421
422 WebKitDOMHTMLFormElement* webkit_dom_html_select_element_get_form(WebKitDOMHTMLSelectElement* self)
423 {
424     WebCore::JSMainThreadNullState state;
425     g_return_val_if_fail(WEBKIT_DOM_IS_HTML_SELECT_ELEMENT(self), 0);
426     WebCore::HTMLSelectElement* item = WebKit::core(self);
427     RefPtr<WebCore::HTMLFormElement> gobjectResult = WTF::getPtr(item->form());
428     return WebKit::kit(gobjectResult.get());
429 }
430
431 gboolean webkit_dom_html_select_element_get_multiple(WebKitDOMHTMLSelectElement* self)
432 {
433     WebCore::JSMainThreadNullState state;
434     g_return_val_if_fail(WEBKIT_DOM_IS_HTML_SELECT_ELEMENT(self), FALSE);
435     WebCore::HTMLSelectElement* item = WebKit::core(self);
436     gboolean result = item->multiple();
437     return result;
438 }
439
440 void webkit_dom_html_select_element_set_multiple(WebKitDOMHTMLSelectElement* self, gboolean value)
441 {
442     WebCore::JSMainThreadNullState state;
443     g_return_if_fail(WEBKIT_DOM_IS_HTML_SELECT_ELEMENT(self));
444     WebCore::HTMLSelectElement* item = WebKit::core(self);
445     item->setMultiple(value);
446 }
447
448 gchar* webkit_dom_html_select_element_get_name(WebKitDOMHTMLSelectElement* self)
449 {
450     WebCore::JSMainThreadNullState state;
451     g_return_val_if_fail(WEBKIT_DOM_IS_HTML_SELECT_ELEMENT(self), 0);
452     WebCore::HTMLSelectElement* item = WebKit::core(self);
453     gchar* result = convertToUTF8String(item->getNameAttribute());
454     return result;
455 }
456
457 void webkit_dom_html_select_element_set_name(WebKitDOMHTMLSelectElement* self, const gchar* value)
458 {
459     WebCore::JSMainThreadNullState state;
460     g_return_if_fail(WEBKIT_DOM_IS_HTML_SELECT_ELEMENT(self));
461     g_return_if_fail(value);
462     WebCore::HTMLSelectElement* item = WebKit::core(self);
463     WTF::String convertedValue = WTF::String::fromUTF8(value);
464     item->setAttributeWithoutSynchronization(WebCore::HTMLNames::nameAttr, convertedValue);
465 }
466
467 glong webkit_dom_html_select_element_get_size(WebKitDOMHTMLSelectElement* self)
468 {
469     WebCore::JSMainThreadNullState state;
470     g_return_val_if_fail(WEBKIT_DOM_IS_HTML_SELECT_ELEMENT(self), 0);
471     WebCore::HTMLSelectElement* item = WebKit::core(self);
472     glong result = item->size();
473     return result;
474 }
475
476 void webkit_dom_html_select_element_set_size(WebKitDOMHTMLSelectElement* self, glong value)
477 {
478     WebCore::JSMainThreadNullState state;
479     g_return_if_fail(WEBKIT_DOM_IS_HTML_SELECT_ELEMENT(self));
480     WebCore::HTMLSelectElement* item = WebKit::core(self);
481     item->setSize(value);
482 }
483
484 gchar* webkit_dom_html_select_element_get_select_type(WebKitDOMHTMLSelectElement* self)
485 {
486     WebCore::JSMainThreadNullState state;
487     g_return_val_if_fail(WEBKIT_DOM_IS_HTML_SELECT_ELEMENT(self), 0);
488     WebCore::HTMLSelectElement* item = WebKit::core(self);
489     gchar* result = convertToUTF8String(item->type());
490     return result;
491 }
492
493 WebKitDOMHTMLOptionsCollection* webkit_dom_html_select_element_get_options(WebKitDOMHTMLSelectElement* self)
494 {
495     WebCore::JSMainThreadNullState state;
496     g_return_val_if_fail(WEBKIT_DOM_IS_HTML_SELECT_ELEMENT(self), 0);
497     WebCore::HTMLSelectElement* item = WebKit::core(self);
498     RefPtr<WebCore::HTMLOptionsCollection> gobjectResult = WTF::getPtr(item->options());
499     return WebKit::kit(gobjectResult.get());
500 }
501
502 gulong webkit_dom_html_select_element_get_length(WebKitDOMHTMLSelectElement* self)
503 {
504     WebCore::JSMainThreadNullState state;
505     g_return_val_if_fail(WEBKIT_DOM_IS_HTML_SELECT_ELEMENT(self), 0);
506     WebCore::HTMLSelectElement* item = WebKit::core(self);
507     gulong result = item->length();
508     return result;
509 }
510
511 void webkit_dom_html_select_element_set_length(WebKitDOMHTMLSelectElement* self, gulong value, GError** error)
512 {
513     WebCore::JSMainThreadNullState state;
514     g_return_if_fail(WEBKIT_DOM_IS_HTML_SELECT_ELEMENT(self));
515     g_return_if_fail(!error || !*error);
516     WebCore::HTMLSelectElement* item = WebKit::core(self);
517     auto result = item->setLength(value);
518     if (result.hasException()) {
519         auto description = WebCore::DOMException::description(result.releaseException().code());
520         g_set_error_literal(error, g_quark_from_string("WEBKIT_DOM"), description.legacyCode, description.name);
521     }
522 }
523
524 glong webkit_dom_html_select_element_get_selected_index(WebKitDOMHTMLSelectElement* self)
525 {
526     WebCore::JSMainThreadNullState state;
527     g_return_val_if_fail(WEBKIT_DOM_IS_HTML_SELECT_ELEMENT(self), 0);
528     WebCore::HTMLSelectElement* item = WebKit::core(self);
529     glong result = item->selectedIndex();
530     return result;
531 }
532
533 void webkit_dom_html_select_element_set_selected_index(WebKitDOMHTMLSelectElement* self, glong value)
534 {
535     WebCore::JSMainThreadNullState state;
536     g_return_if_fail(WEBKIT_DOM_IS_HTML_SELECT_ELEMENT(self));
537     WebCore::HTMLSelectElement* item = WebKit::core(self);
538     item->setSelectedIndex(value);
539 }
540
541 gchar* webkit_dom_html_select_element_get_value(WebKitDOMHTMLSelectElement* self)
542 {
543     WebCore::JSMainThreadNullState state;
544     g_return_val_if_fail(WEBKIT_DOM_IS_HTML_SELECT_ELEMENT(self), 0);
545     WebCore::HTMLSelectElement* item = WebKit::core(self);
546     gchar* result = convertToUTF8String(item->value());
547     return result;
548 }
549
550 void webkit_dom_html_select_element_set_value(WebKitDOMHTMLSelectElement* self, const gchar* value)
551 {
552     WebCore::JSMainThreadNullState state;
553     g_return_if_fail(WEBKIT_DOM_IS_HTML_SELECT_ELEMENT(self));
554     g_return_if_fail(value);
555     WebCore::HTMLSelectElement* item = WebKit::core(self);
556     WTF::String convertedValue = WTF::String::fromUTF8(value);
557     item->setValue(convertedValue);
558 }
559
560 gboolean webkit_dom_html_select_element_get_will_validate(WebKitDOMHTMLSelectElement* self)
561 {
562     WebCore::JSMainThreadNullState state;
563     g_return_val_if_fail(WEBKIT_DOM_IS_HTML_SELECT_ELEMENT(self), FALSE);
564     WebCore::HTMLSelectElement* item = WebKit::core(self);
565     gboolean result = item->willValidate();
566     return result;
567 }