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