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