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