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 "WebKitDOMHTMLFieldSetElement.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/JSExecState.h> |
30 | #include "WebKitDOMEventPrivate.h" |
31 | #include "WebKitDOMEventTarget.h" |
32 | #include "WebKitDOMHTMLCollectionPrivate.h" |
33 | #include "WebKitDOMHTMLFieldSetElementPrivate.h" |
34 | #include "WebKitDOMHTMLFormElementPrivate.h" |
35 | #include "WebKitDOMNodePrivate.h" |
36 | #include "WebKitDOMPrivate.h" |
37 | #include "ConvertToUTF8String.h" |
38 | #include <wtf/GetPtr.h> |
39 | #include <wtf/RefPtr.h> |
40 | |
41 | G_GNUC_BEGIN_IGNORE_DEPRECATIONS; |
42 | |
43 | namespace WebKit { |
44 | |
45 | WebKitDOMHTMLFieldSetElement* kit(WebCore::HTMLFieldSetElement* obj) |
46 | { |
47 | return WEBKIT_DOM_HTML_FIELD_SET_ELEMENT(kit(static_cast<WebCore::Node*>(obj))); |
48 | } |
49 | |
50 | WebCore::HTMLFieldSetElement* core(WebKitDOMHTMLFieldSetElement* request) |
51 | { |
52 | return request ? static_cast<WebCore::HTMLFieldSetElement*>(WEBKIT_DOM_OBJECT(request)->coreObject) : 0; |
53 | } |
54 | |
55 | WebKitDOMHTMLFieldSetElement* wrapHTMLFieldSetElement(WebCore::HTMLFieldSetElement* coreObject) |
56 | { |
57 | ASSERT(coreObject); |
58 | return WEBKIT_DOM_HTML_FIELD_SET_ELEMENT(g_object_new(WEBKIT_DOM_TYPE_HTML_FIELD_SET_ELEMENT, "core-object" , coreObject, nullptr)); |
59 | } |
60 | |
61 | } // namespace WebKit |
62 | |
63 | static gboolean webkit_dom_html_field_set_element_dispatch_event(WebKitDOMEventTarget* target, WebKitDOMEvent* event, GError** error) |
64 | { |
65 | WebCore::Event* coreEvent = WebKit::core(event); |
66 | if (!coreEvent) |
67 | return false; |
68 | WebCore::HTMLFieldSetElement* coreTarget = static_cast<WebCore::HTMLFieldSetElement*>(WEBKIT_DOM_OBJECT(target)->coreObject); |
69 | |
70 | auto result = coreTarget->dispatchEventForBindings(*coreEvent); |
71 | if (result.hasException()) { |
72 | auto description = WebCore::DOMException::description(result.releaseException().code()); |
73 | g_set_error_literal(error, g_quark_from_string("WEBKIT_DOM" ), description.legacyCode, description.name); |
74 | return false; |
75 | } |
76 | return result.releaseReturnValue(); |
77 | } |
78 | |
79 | static gboolean webkit_dom_html_field_set_element_add_event_listener(WebKitDOMEventTarget* target, const char* eventName, GClosure* handler, gboolean useCapture) |
80 | { |
81 | WebCore::HTMLFieldSetElement* coreTarget = static_cast<WebCore::HTMLFieldSetElement*>(WEBKIT_DOM_OBJECT(target)->coreObject); |
82 | return WebKit::GObjectEventListener::addEventListener(G_OBJECT(target), coreTarget, eventName, handler, useCapture); |
83 | } |
84 | |
85 | static gboolean webkit_dom_html_field_set_element_remove_event_listener(WebKitDOMEventTarget* target, const char* eventName, GClosure* handler, gboolean useCapture) |
86 | { |
87 | WebCore::HTMLFieldSetElement* coreTarget = static_cast<WebCore::HTMLFieldSetElement*>(WEBKIT_DOM_OBJECT(target)->coreObject); |
88 | return WebKit::GObjectEventListener::removeEventListener(G_OBJECT(target), coreTarget, eventName, handler, useCapture); |
89 | } |
90 | |
91 | static void webkit_dom_html_field_set_element_dom_event_target_init(WebKitDOMEventTargetIface* iface) |
92 | { |
93 | iface->dispatch_event = webkit_dom_html_field_set_element_dispatch_event; |
94 | iface->add_event_listener = webkit_dom_html_field_set_element_add_event_listener; |
95 | iface->remove_event_listener = webkit_dom_html_field_set_element_remove_event_listener; |
96 | } |
97 | |
98 | G_DEFINE_TYPE_WITH_CODE(WebKitDOMHTMLFieldSetElement, webkit_dom_html_field_set_element, WEBKIT_DOM_TYPE_HTML_ELEMENT, G_IMPLEMENT_INTERFACE(WEBKIT_DOM_TYPE_EVENT_TARGET, webkit_dom_html_field_set_element_dom_event_target_init)) |
99 | |
100 | enum { |
101 | DOM_HTML_FIELD_SET_ELEMENT_PROP_0, |
102 | DOM_HTML_FIELD_SET_ELEMENT_PROP_FORM, |
103 | }; |
104 | |
105 | static void webkit_dom_html_field_set_element_get_property(GObject* object, guint propertyId, GValue* value, GParamSpec* pspec) |
106 | { |
107 | WebKitDOMHTMLFieldSetElement* self = WEBKIT_DOM_HTML_FIELD_SET_ELEMENT(object); |
108 | |
109 | switch (propertyId) { |
110 | case DOM_HTML_FIELD_SET_ELEMENT_PROP_FORM: |
111 | g_value_set_object(value, webkit_dom_html_field_set_element_get_form(self)); |
112 | break; |
113 | default: |
114 | G_OBJECT_WARN_INVALID_PROPERTY_ID(object, propertyId, pspec); |
115 | break; |
116 | } |
117 | } |
118 | |
119 | static void webkit_dom_html_field_set_element_class_init(WebKitDOMHTMLFieldSetElementClass* requestClass) |
120 | { |
121 | GObjectClass* gobjectClass = G_OBJECT_CLASS(requestClass); |
122 | gobjectClass->get_property = webkit_dom_html_field_set_element_get_property; |
123 | |
124 | g_object_class_install_property( |
125 | gobjectClass, |
126 | DOM_HTML_FIELD_SET_ELEMENT_PROP_FORM, |
127 | g_param_spec_object( |
128 | "form" , |
129 | "HTMLFieldSetElement:form" , |
130 | "read-only WebKitDOMHTMLFormElement* HTMLFieldSetElement:form" , |
131 | WEBKIT_DOM_TYPE_HTML_FORM_ELEMENT, |
132 | WEBKIT_PARAM_READABLE)); |
133 | } |
134 | |
135 | static void webkit_dom_html_field_set_element_init(WebKitDOMHTMLFieldSetElement* request) |
136 | { |
137 | UNUSED_PARAM(request); |
138 | } |
139 | |
140 | WebKitDOMHTMLFormElement* webkit_dom_html_field_set_element_get_form(WebKitDOMHTMLFieldSetElement* self) |
141 | { |
142 | WebCore::JSMainThreadNullState state; |
143 | g_return_val_if_fail(WEBKIT_DOM_IS_HTML_FIELD_SET_ELEMENT(self), 0); |
144 | WebCore::HTMLFieldSetElement* item = WebKit::core(self); |
145 | RefPtr<WebCore::HTMLFormElement> gobjectResult = WTF::getPtr(item->form()); |
146 | return WebKit::kit(gobjectResult.get()); |
147 | } |
148 | G_GNUC_END_IGNORE_DEPRECATIONS; |
149 | |