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 "WebKitDOMHTMLHRElement.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 "WebKitDOMHTMLHRElementPrivate.h" |
33 | #include "WebKitDOMNodePrivate.h" |
34 | #include "WebKitDOMPrivate.h" |
35 | #include "ConvertToUTF8String.h" |
36 | #include <wtf/GetPtr.h> |
37 | #include <wtf/RefPtr.h> |
38 | |
39 | G_GNUC_BEGIN_IGNORE_DEPRECATIONS; |
40 | |
41 | namespace WebKit { |
42 | |
43 | WebKitDOMHTMLHRElement* kit(WebCore::HTMLHRElement* obj) |
44 | { |
45 | return WEBKIT_DOM_HTML_HR_ELEMENT(kit(static_cast<WebCore::Node*>(obj))); |
46 | } |
47 | |
48 | WebCore::HTMLHRElement* core(WebKitDOMHTMLHRElement* request) |
49 | { |
50 | return request ? static_cast<WebCore::HTMLHRElement*>(WEBKIT_DOM_OBJECT(request)->coreObject) : 0; |
51 | } |
52 | |
53 | WebKitDOMHTMLHRElement* wrapHTMLHRElement(WebCore::HTMLHRElement* coreObject) |
54 | { |
55 | ASSERT(coreObject); |
56 | return WEBKIT_DOM_HTML_HR_ELEMENT(g_object_new(WEBKIT_DOM_TYPE_HTML_HR_ELEMENT, "core-object" , coreObject, nullptr)); |
57 | } |
58 | |
59 | } // namespace WebKit |
60 | |
61 | static gboolean webkit_dom_html_hr_element_dispatch_event(WebKitDOMEventTarget* target, WebKitDOMEvent* event, GError** error) |
62 | { |
63 | WebCore::Event* coreEvent = WebKit::core(event); |
64 | if (!coreEvent) |
65 | return false; |
66 | WebCore::HTMLHRElement* coreTarget = static_cast<WebCore::HTMLHRElement*>(WEBKIT_DOM_OBJECT(target)->coreObject); |
67 | |
68 | auto result = coreTarget->dispatchEventForBindings(*coreEvent); |
69 | if (result.hasException()) { |
70 | auto description = WebCore::DOMException::description(result.releaseException().code()); |
71 | g_set_error_literal(error, g_quark_from_string("WEBKIT_DOM" ), description.legacyCode, description.name); |
72 | return false; |
73 | } |
74 | return result.releaseReturnValue(); |
75 | } |
76 | |
77 | static gboolean webkit_dom_html_hr_element_add_event_listener(WebKitDOMEventTarget* target, const char* eventName, GClosure* handler, gboolean useCapture) |
78 | { |
79 | WebCore::HTMLHRElement* coreTarget = static_cast<WebCore::HTMLHRElement*>(WEBKIT_DOM_OBJECT(target)->coreObject); |
80 | return WebKit::GObjectEventListener::addEventListener(G_OBJECT(target), coreTarget, eventName, handler, useCapture); |
81 | } |
82 | |
83 | static gboolean webkit_dom_html_hr_element_remove_event_listener(WebKitDOMEventTarget* target, const char* eventName, GClosure* handler, gboolean useCapture) |
84 | { |
85 | WebCore::HTMLHRElement* coreTarget = static_cast<WebCore::HTMLHRElement*>(WEBKIT_DOM_OBJECT(target)->coreObject); |
86 | return WebKit::GObjectEventListener::removeEventListener(G_OBJECT(target), coreTarget, eventName, handler, useCapture); |
87 | } |
88 | |
89 | static void webkit_dom_html_hr_element_dom_event_target_init(WebKitDOMEventTargetIface* iface) |
90 | { |
91 | iface->dispatch_event = webkit_dom_html_hr_element_dispatch_event; |
92 | iface->add_event_listener = webkit_dom_html_hr_element_add_event_listener; |
93 | iface->remove_event_listener = webkit_dom_html_hr_element_remove_event_listener; |
94 | } |
95 | |
96 | G_DEFINE_TYPE_WITH_CODE(WebKitDOMHTMLHRElement, webkit_dom_html_hr_element, WEBKIT_DOM_TYPE_HTML_ELEMENT, G_IMPLEMENT_INTERFACE(WEBKIT_DOM_TYPE_EVENT_TARGET, webkit_dom_html_hr_element_dom_event_target_init)) |
97 | |
98 | enum { |
99 | DOM_HTML_HR_ELEMENT_PROP_0, |
100 | DOM_HTML_HR_ELEMENT_PROP_ALIGN, |
101 | DOM_HTML_HR_ELEMENT_PROP_NO_SHADE, |
102 | DOM_HTML_HR_ELEMENT_PROP_SIZE, |
103 | DOM_HTML_HR_ELEMENT_PROP_WIDTH, |
104 | }; |
105 | |
106 | static void webkit_dom_html_hr_element_set_property(GObject* object, guint propertyId, const GValue* value, GParamSpec* pspec) |
107 | { |
108 | WebKitDOMHTMLHRElement* self = WEBKIT_DOM_HTML_HR_ELEMENT(object); |
109 | |
110 | switch (propertyId) { |
111 | case DOM_HTML_HR_ELEMENT_PROP_ALIGN: |
112 | webkit_dom_html_hr_element_set_align(self, g_value_get_string(value)); |
113 | break; |
114 | case DOM_HTML_HR_ELEMENT_PROP_NO_SHADE: |
115 | webkit_dom_html_hr_element_set_no_shade(self, g_value_get_boolean(value)); |
116 | break; |
117 | case DOM_HTML_HR_ELEMENT_PROP_SIZE: |
118 | webkit_dom_html_hr_element_set_size(self, g_value_get_string(value)); |
119 | break; |
120 | case DOM_HTML_HR_ELEMENT_PROP_WIDTH: |
121 | webkit_dom_html_hr_element_set_width(self, g_value_get_string(value)); |
122 | break; |
123 | default: |
124 | G_OBJECT_WARN_INVALID_PROPERTY_ID(object, propertyId, pspec); |
125 | break; |
126 | } |
127 | } |
128 | |
129 | static void webkit_dom_html_hr_element_get_property(GObject* object, guint propertyId, GValue* value, GParamSpec* pspec) |
130 | { |
131 | WebKitDOMHTMLHRElement* self = WEBKIT_DOM_HTML_HR_ELEMENT(object); |
132 | |
133 | switch (propertyId) { |
134 | case DOM_HTML_HR_ELEMENT_PROP_ALIGN: |
135 | g_value_take_string(value, webkit_dom_html_hr_element_get_align(self)); |
136 | break; |
137 | case DOM_HTML_HR_ELEMENT_PROP_NO_SHADE: |
138 | g_value_set_boolean(value, webkit_dom_html_hr_element_get_no_shade(self)); |
139 | break; |
140 | case DOM_HTML_HR_ELEMENT_PROP_SIZE: |
141 | g_value_take_string(value, webkit_dom_html_hr_element_get_size(self)); |
142 | break; |
143 | case DOM_HTML_HR_ELEMENT_PROP_WIDTH: |
144 | g_value_take_string(value, webkit_dom_html_hr_element_get_width(self)); |
145 | break; |
146 | default: |
147 | G_OBJECT_WARN_INVALID_PROPERTY_ID(object, propertyId, pspec); |
148 | break; |
149 | } |
150 | } |
151 | |
152 | static void webkit_dom_html_hr_element_class_init(WebKitDOMHTMLHRElementClass* requestClass) |
153 | { |
154 | GObjectClass* gobjectClass = G_OBJECT_CLASS(requestClass); |
155 | gobjectClass->set_property = webkit_dom_html_hr_element_set_property; |
156 | gobjectClass->get_property = webkit_dom_html_hr_element_get_property; |
157 | |
158 | g_object_class_install_property( |
159 | gobjectClass, |
160 | DOM_HTML_HR_ELEMENT_PROP_ALIGN, |
161 | g_param_spec_string( |
162 | "align" , |
163 | "HTMLHRElement:align" , |
164 | "read-write gchar* HTMLHRElement:align" , |
165 | "" , |
166 | WEBKIT_PARAM_READWRITE)); |
167 | |
168 | g_object_class_install_property( |
169 | gobjectClass, |
170 | DOM_HTML_HR_ELEMENT_PROP_NO_SHADE, |
171 | g_param_spec_boolean( |
172 | "no-shade" , |
173 | "HTMLHRElement:no-shade" , |
174 | "read-write gboolean HTMLHRElement:no-shade" , |
175 | FALSE, |
176 | WEBKIT_PARAM_READWRITE)); |
177 | |
178 | g_object_class_install_property( |
179 | gobjectClass, |
180 | DOM_HTML_HR_ELEMENT_PROP_SIZE, |
181 | g_param_spec_string( |
182 | "size" , |
183 | "HTMLHRElement:size" , |
184 | "read-write gchar* HTMLHRElement:size" , |
185 | "" , |
186 | WEBKIT_PARAM_READWRITE)); |
187 | |
188 | g_object_class_install_property( |
189 | gobjectClass, |
190 | DOM_HTML_HR_ELEMENT_PROP_WIDTH, |
191 | g_param_spec_string( |
192 | "width" , |
193 | "HTMLHRElement:width" , |
194 | "read-write gchar* HTMLHRElement:width" , |
195 | "" , |
196 | WEBKIT_PARAM_READWRITE)); |
197 | |
198 | } |
199 | |
200 | static void webkit_dom_html_hr_element_init(WebKitDOMHTMLHRElement* request) |
201 | { |
202 | UNUSED_PARAM(request); |
203 | } |
204 | |
205 | gchar* webkit_dom_html_hr_element_get_align(WebKitDOMHTMLHRElement* self) |
206 | { |
207 | WebCore::JSMainThreadNullState state; |
208 | g_return_val_if_fail(WEBKIT_DOM_IS_HTML_HR_ELEMENT(self), 0); |
209 | WebCore::HTMLHRElement* item = WebKit::core(self); |
210 | gchar* result = convertToUTF8String(item->attributeWithoutSynchronization(WebCore::HTMLNames::alignAttr)); |
211 | return result; |
212 | } |
213 | |
214 | void webkit_dom_html_hr_element_set_align(WebKitDOMHTMLHRElement* self, const gchar* value) |
215 | { |
216 | WebCore::JSMainThreadNullState state; |
217 | g_return_if_fail(WEBKIT_DOM_IS_HTML_HR_ELEMENT(self)); |
218 | g_return_if_fail(value); |
219 | WebCore::HTMLHRElement* item = WebKit::core(self); |
220 | WTF::String convertedValue = WTF::String::fromUTF8(value); |
221 | item->setAttributeWithoutSynchronization(WebCore::HTMLNames::alignAttr, convertedValue); |
222 | } |
223 | |
224 | gboolean webkit_dom_html_hr_element_get_no_shade(WebKitDOMHTMLHRElement* self) |
225 | { |
226 | WebCore::JSMainThreadNullState state; |
227 | g_return_val_if_fail(WEBKIT_DOM_IS_HTML_HR_ELEMENT(self), FALSE); |
228 | WebCore::HTMLHRElement* item = WebKit::core(self); |
229 | gboolean result = item->hasAttributeWithoutSynchronization(WebCore::HTMLNames::noshadeAttr); |
230 | return result; |
231 | } |
232 | |
233 | void webkit_dom_html_hr_element_set_no_shade(WebKitDOMHTMLHRElement* self, gboolean value) |
234 | { |
235 | WebCore::JSMainThreadNullState state; |
236 | g_return_if_fail(WEBKIT_DOM_IS_HTML_HR_ELEMENT(self)); |
237 | WebCore::HTMLHRElement* item = WebKit::core(self); |
238 | item->setBooleanAttribute(WebCore::HTMLNames::noshadeAttr, value); |
239 | } |
240 | |
241 | gchar* webkit_dom_html_hr_element_get_size(WebKitDOMHTMLHRElement* self) |
242 | { |
243 | WebCore::JSMainThreadNullState state; |
244 | g_return_val_if_fail(WEBKIT_DOM_IS_HTML_HR_ELEMENT(self), 0); |
245 | WebCore::HTMLHRElement* item = WebKit::core(self); |
246 | gchar* result = convertToUTF8String(item->attributeWithoutSynchronization(WebCore::HTMLNames::sizeAttr)); |
247 | return result; |
248 | } |
249 | |
250 | void webkit_dom_html_hr_element_set_size(WebKitDOMHTMLHRElement* self, const gchar* value) |
251 | { |
252 | WebCore::JSMainThreadNullState state; |
253 | g_return_if_fail(WEBKIT_DOM_IS_HTML_HR_ELEMENT(self)); |
254 | g_return_if_fail(value); |
255 | WebCore::HTMLHRElement* item = WebKit::core(self); |
256 | WTF::String convertedValue = WTF::String::fromUTF8(value); |
257 | item->setAttributeWithoutSynchronization(WebCore::HTMLNames::sizeAttr, convertedValue); |
258 | } |
259 | |
260 | gchar* webkit_dom_html_hr_element_get_width(WebKitDOMHTMLHRElement* self) |
261 | { |
262 | WebCore::JSMainThreadNullState state; |
263 | g_return_val_if_fail(WEBKIT_DOM_IS_HTML_HR_ELEMENT(self), 0); |
264 | WebCore::HTMLHRElement* item = WebKit::core(self); |
265 | gchar* result = convertToUTF8String(item->attributeWithoutSynchronization(WebCore::HTMLNames::widthAttr)); |
266 | return result; |
267 | } |
268 | |
269 | void webkit_dom_html_hr_element_set_width(WebKitDOMHTMLHRElement* self, const gchar* value) |
270 | { |
271 | WebCore::JSMainThreadNullState state; |
272 | g_return_if_fail(WEBKIT_DOM_IS_HTML_HR_ELEMENT(self)); |
273 | g_return_if_fail(value); |
274 | WebCore::HTMLHRElement* item = WebKit::core(self); |
275 | WTF::String convertedValue = WTF::String::fromUTF8(value); |
276 | item->setAttributeWithoutSynchronization(WebCore::HTMLNames::widthAttr, convertedValue); |
277 | } |
278 | |
279 | G_GNUC_END_IGNORE_DEPRECATIONS; |
280 | |