Drop ExceptionCodeDescription class
[WebKit-https.git] / Source / WebKit / WebProcess / InjectedBundle / API / gtk / DOM / WebKitDOMHTMLOptionsCollection.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 "WebKitDOMHTMLOptionsCollection.h"
22
23 #include <WebCore/CSSImportRule.h>
24 #include "DOMObjectCache.h"
25 #include <WebCore/Document.h>
26 #include <WebCore/ExceptionCode.h>
27 #include <WebCore/JSMainThreadExecState.h>
28 #include "WebKitDOMHTMLCollectionPrivate.h"
29 #include "WebKitDOMHTMLOptionElementPrivate.h"
30 #include "WebKitDOMHTMLOptionsCollectionPrivate.h"
31 #include "WebKitDOMNodePrivate.h"
32 #include "WebKitDOMPrivate.h"
33 #include "ConvertToUTF8String.h"
34 #include <wtf/GetPtr.h>
35 #include <wtf/RefPtr.h>
36
37 namespace WebKit {
38
39 WebKitDOMHTMLOptionsCollection* kit(WebCore::HTMLOptionsCollection* obj)
40 {
41     return WEBKIT_DOM_HTML_OPTIONS_COLLECTION(kit(static_cast<WebCore::HTMLCollection*>(obj)));
42 }
43
44 WebCore::HTMLOptionsCollection* core(WebKitDOMHTMLOptionsCollection* request)
45 {
46     return request ? static_cast<WebCore::HTMLOptionsCollection*>(WEBKIT_DOM_OBJECT(request)->coreObject) : 0;
47 }
48
49 WebKitDOMHTMLOptionsCollection* wrapHTMLOptionsCollection(WebCore::HTMLOptionsCollection* coreObject)
50 {
51     ASSERT(coreObject);
52     return WEBKIT_DOM_HTML_OPTIONS_COLLECTION(g_object_new(WEBKIT_DOM_TYPE_HTML_OPTIONS_COLLECTION, "core-object", coreObject, nullptr));
53 }
54
55 } // namespace WebKit
56
57 G_DEFINE_TYPE(WebKitDOMHTMLOptionsCollection, webkit_dom_html_options_collection, WEBKIT_DOM_TYPE_HTML_COLLECTION)
58
59 enum {
60     PROP_0,
61     PROP_SELECTED_INDEX,
62     PROP_LENGTH,
63 };
64
65 static void webkit_dom_html_options_collection_set_property(GObject* object, guint propertyId, const GValue* value, GParamSpec* pspec)
66 {
67     WebKitDOMHTMLOptionsCollection* self = WEBKIT_DOM_HTML_OPTIONS_COLLECTION(object);
68
69     switch (propertyId) {
70     case PROP_SELECTED_INDEX:
71         webkit_dom_html_options_collection_set_selected_index(self, g_value_get_long(value));
72         break;
73     default:
74         G_OBJECT_WARN_INVALID_PROPERTY_ID(object, propertyId, pspec);
75         break;
76     }
77 }
78
79 static void webkit_dom_html_options_collection_get_property(GObject* object, guint propertyId, GValue* value, GParamSpec* pspec)
80 {
81     WebKitDOMHTMLOptionsCollection* self = WEBKIT_DOM_HTML_OPTIONS_COLLECTION(object);
82
83     switch (propertyId) {
84     case PROP_SELECTED_INDEX:
85         g_value_set_long(value, webkit_dom_html_options_collection_get_selected_index(self));
86         break;
87     case PROP_LENGTH:
88         g_value_set_ulong(value, webkit_dom_html_options_collection_get_length(self));
89         break;
90     default:
91         G_OBJECT_WARN_INVALID_PROPERTY_ID(object, propertyId, pspec);
92         break;
93     }
94 }
95
96 static void webkit_dom_html_options_collection_class_init(WebKitDOMHTMLOptionsCollectionClass* requestClass)
97 {
98     GObjectClass* gobjectClass = G_OBJECT_CLASS(requestClass);
99     gobjectClass->set_property = webkit_dom_html_options_collection_set_property;
100     gobjectClass->get_property = webkit_dom_html_options_collection_get_property;
101
102     g_object_class_install_property(
103         gobjectClass,
104         PROP_SELECTED_INDEX,
105         g_param_spec_long(
106             "selected-index",
107             "HTMLOptionsCollection:selected-index",
108             "read-write glong HTMLOptionsCollection:selected-index",
109             G_MINLONG, G_MAXLONG, 0,
110             WEBKIT_PARAM_READWRITE));
111
112     g_object_class_install_property(
113         gobjectClass,
114         PROP_LENGTH,
115         g_param_spec_ulong(
116             "length",
117             "HTMLOptionsCollection:length",
118             "read-only gulong HTMLOptionsCollection:length",
119             0, G_MAXULONG, 0,
120             WEBKIT_PARAM_READABLE));
121
122 }
123
124 static void webkit_dom_html_options_collection_init(WebKitDOMHTMLOptionsCollection* request)
125 {
126     UNUSED_PARAM(request);
127 }
128
129 WebKitDOMNode* webkit_dom_html_options_collection_named_item(WebKitDOMHTMLOptionsCollection* self, const gchar* name)
130 {
131     WebCore::JSMainThreadNullState state;
132     g_return_val_if_fail(WEBKIT_DOM_IS_HTML_OPTIONS_COLLECTION(self), 0);
133     g_return_val_if_fail(name, 0);
134     WebCore::HTMLOptionsCollection* item = WebKit::core(self);
135     WTF::String convertedName = WTF::String::fromUTF8(name);
136     RefPtr<WebCore::Node> gobjectResult = WTF::getPtr(item->namedItem(convertedName));
137     return WebKit::kit(gobjectResult.get());
138 }
139
140 glong webkit_dom_html_options_collection_get_selected_index(WebKitDOMHTMLOptionsCollection* self)
141 {
142     WebCore::JSMainThreadNullState state;
143     g_return_val_if_fail(WEBKIT_DOM_IS_HTML_OPTIONS_COLLECTION(self), 0);
144     WebCore::HTMLOptionsCollection* item = WebKit::core(self);
145     glong result = item->selectedIndex();
146     return result;
147 }
148
149 void webkit_dom_html_options_collection_set_selected_index(WebKitDOMHTMLOptionsCollection* self, glong value)
150 {
151     WebCore::JSMainThreadNullState state;
152     g_return_if_fail(WEBKIT_DOM_IS_HTML_OPTIONS_COLLECTION(self));
153     WebCore::HTMLOptionsCollection* item = WebKit::core(self);
154     item->setSelectedIndex(value);
155 }
156
157 gulong webkit_dom_html_options_collection_get_length(WebKitDOMHTMLOptionsCollection* self)
158 {
159     WebCore::JSMainThreadNullState state;
160     g_return_val_if_fail(WEBKIT_DOM_IS_HTML_OPTIONS_COLLECTION(self), 0);
161     WebCore::HTMLOptionsCollection* item = WebKit::core(self);
162     gulong result = item->length();
163     return result;
164 }
165