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 "WebKitDOMHTMLLabelElement.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 "WebKitDOMHTMLElementPrivate.h" |
33 | #include "WebKitDOMHTMLFormElementPrivate.h" |
34 | #include "WebKitDOMHTMLLabelElementPrivate.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 | WebKitDOMHTMLLabelElement* kit(WebCore::HTMLLabelElement* obj) |
46 | { |
47 | return WEBKIT_DOM_HTML_LABEL_ELEMENT(kit(static_cast<WebCore::Node*>(obj))); |
48 | } |
49 | |
50 | WebCore::HTMLLabelElement* core(WebKitDOMHTMLLabelElement* request) |
51 | { |
52 | return request ? static_cast<WebCore::HTMLLabelElement*>(WEBKIT_DOM_OBJECT(request)->coreObject) : 0; |
53 | } |
54 | |
55 | WebKitDOMHTMLLabelElement* wrapHTMLLabelElement(WebCore::HTMLLabelElement* coreObject) |
56 | { |
57 | ASSERT(coreObject); |
58 | return WEBKIT_DOM_HTML_LABEL_ELEMENT(g_object_new(WEBKIT_DOM_TYPE_HTML_LABEL_ELEMENT, "core-object" , coreObject, nullptr)); |
59 | } |
60 | |
61 | } // namespace WebKit |
62 | |
63 | static gboolean webkit_dom_html_label_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::HTMLLabelElement* coreTarget = static_cast<WebCore::HTMLLabelElement*>(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_label_element_add_event_listener(WebKitDOMEventTarget* target, const char* eventName, GClosure* handler, gboolean useCapture) |
80 | { |
81 | WebCore::HTMLLabelElement* coreTarget = static_cast<WebCore::HTMLLabelElement*>(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_label_element_remove_event_listener(WebKitDOMEventTarget* target, const char* eventName, GClosure* handler, gboolean useCapture) |
86 | { |
87 | WebCore::HTMLLabelElement* coreTarget = static_cast<WebCore::HTMLLabelElement*>(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_label_element_dom_event_target_init(WebKitDOMEventTargetIface* iface) |
92 | { |
93 | iface->dispatch_event = webkit_dom_html_label_element_dispatch_event; |
94 | iface->add_event_listener = webkit_dom_html_label_element_add_event_listener; |
95 | iface->remove_event_listener = webkit_dom_html_label_element_remove_event_listener; |
96 | } |
97 | |
98 | G_DEFINE_TYPE_WITH_CODE(WebKitDOMHTMLLabelElement, webkit_dom_html_label_element, WEBKIT_DOM_TYPE_HTML_ELEMENT, G_IMPLEMENT_INTERFACE(WEBKIT_DOM_TYPE_EVENT_TARGET, webkit_dom_html_label_element_dom_event_target_init)) |
99 | |
100 | enum { |
101 | DOM_HTML_LABEL_ELEMENT_PROP_0, |
102 | DOM_HTML_LABEL_ELEMENT_PROP_FORM, |
103 | DOM_HTML_LABEL_ELEMENT_PROP_HTML_FOR, |
104 | }; |
105 | |
106 | static void webkit_dom_html_label_element_set_property(GObject* object, guint propertyId, const GValue* value, GParamSpec* pspec) |
107 | { |
108 | WebKitDOMHTMLLabelElement* self = WEBKIT_DOM_HTML_LABEL_ELEMENT(object); |
109 | |
110 | switch (propertyId) { |
111 | case DOM_HTML_LABEL_ELEMENT_PROP_HTML_FOR: |
112 | webkit_dom_html_label_element_set_html_for(self, g_value_get_string(value)); |
113 | break; |
114 | default: |
115 | G_OBJECT_WARN_INVALID_PROPERTY_ID(object, propertyId, pspec); |
116 | break; |
117 | } |
118 | } |
119 | |
120 | static void webkit_dom_html_label_element_get_property(GObject* object, guint propertyId, GValue* value, GParamSpec* pspec) |
121 | { |
122 | WebKitDOMHTMLLabelElement* self = WEBKIT_DOM_HTML_LABEL_ELEMENT(object); |
123 | |
124 | switch (propertyId) { |
125 | case DOM_HTML_LABEL_ELEMENT_PROP_FORM: |
126 | g_value_set_object(value, webkit_dom_html_label_element_get_form(self)); |
127 | break; |
128 | case DOM_HTML_LABEL_ELEMENT_PROP_HTML_FOR: |
129 | g_value_take_string(value, webkit_dom_html_label_element_get_html_for(self)); |
130 | break; |
131 | default: |
132 | G_OBJECT_WARN_INVALID_PROPERTY_ID(object, propertyId, pspec); |
133 | break; |
134 | } |
135 | } |
136 | |
137 | static void webkit_dom_html_label_element_class_init(WebKitDOMHTMLLabelElementClass* requestClass) |
138 | { |
139 | GObjectClass* gobjectClass = G_OBJECT_CLASS(requestClass); |
140 | gobjectClass->set_property = webkit_dom_html_label_element_set_property; |
141 | gobjectClass->get_property = webkit_dom_html_label_element_get_property; |
142 | |
143 | g_object_class_install_property( |
144 | gobjectClass, |
145 | DOM_HTML_LABEL_ELEMENT_PROP_FORM, |
146 | g_param_spec_object( |
147 | "form" , |
148 | "HTMLLabelElement:form" , |
149 | "read-only WebKitDOMHTMLFormElement* HTMLLabelElement:form" , |
150 | WEBKIT_DOM_TYPE_HTML_FORM_ELEMENT, |
151 | WEBKIT_PARAM_READABLE)); |
152 | |
153 | g_object_class_install_property( |
154 | gobjectClass, |
155 | DOM_HTML_LABEL_ELEMENT_PROP_HTML_FOR, |
156 | g_param_spec_string( |
157 | "html-for" , |
158 | "HTMLLabelElement:html-for" , |
159 | "read-write gchar* HTMLLabelElement:html-for" , |
160 | "" , |
161 | WEBKIT_PARAM_READWRITE)); |
162 | } |
163 | |
164 | static void webkit_dom_html_label_element_init(WebKitDOMHTMLLabelElement* request) |
165 | { |
166 | UNUSED_PARAM(request); |
167 | } |
168 | |
169 | WebKitDOMHTMLFormElement* webkit_dom_html_label_element_get_form(WebKitDOMHTMLLabelElement* self) |
170 | { |
171 | WebCore::JSMainThreadNullState state; |
172 | g_return_val_if_fail(WEBKIT_DOM_IS_HTML_LABEL_ELEMENT(self), 0); |
173 | WebCore::HTMLLabelElement* item = WebKit::core(self); |
174 | RefPtr<WebCore::HTMLFormElement> gobjectResult = WTF::getPtr(item->form()); |
175 | return WebKit::kit(gobjectResult.get()); |
176 | } |
177 | |
178 | gchar* webkit_dom_html_label_element_get_html_for(WebKitDOMHTMLLabelElement* self) |
179 | { |
180 | WebCore::JSMainThreadNullState state; |
181 | g_return_val_if_fail(WEBKIT_DOM_IS_HTML_LABEL_ELEMENT(self), 0); |
182 | WebCore::HTMLLabelElement* item = WebKit::core(self); |
183 | gchar* result = convertToUTF8String(item->attributeWithoutSynchronization(WebCore::HTMLNames::forAttr)); |
184 | return result; |
185 | } |
186 | |
187 | void webkit_dom_html_label_element_set_html_for(WebKitDOMHTMLLabelElement* self, const gchar* value) |
188 | { |
189 | WebCore::JSMainThreadNullState state; |
190 | g_return_if_fail(WEBKIT_DOM_IS_HTML_LABEL_ELEMENT(self)); |
191 | g_return_if_fail(value); |
192 | WebCore::HTMLLabelElement* item = WebKit::core(self); |
193 | WTF::String convertedValue = WTF::String::fromUTF8(value); |
194 | item->setAttributeWithoutSynchronization(WebCore::HTMLNames::forAttr, convertedValue); |
195 | } |
196 | |
197 | G_GNUC_END_IGNORE_DEPRECATIONS; |
198 | |