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 "WebKitDOMHTMLBRElement.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 "WebKitDOMHTMLBRElementPrivate.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 | WebKitDOMHTMLBRElement* kit(WebCore::HTMLBRElement* obj) |
44 | { |
45 | return WEBKIT_DOM_HTML_BR_ELEMENT(kit(static_cast<WebCore::Node*>(obj))); |
46 | } |
47 | |
48 | WebCore::HTMLBRElement* core(WebKitDOMHTMLBRElement* request) |
49 | { |
50 | return request ? static_cast<WebCore::HTMLBRElement*>(WEBKIT_DOM_OBJECT(request)->coreObject) : 0; |
51 | } |
52 | |
53 | WebKitDOMHTMLBRElement* wrapHTMLBRElement(WebCore::HTMLBRElement* coreObject) |
54 | { |
55 | ASSERT(coreObject); |
56 | return WEBKIT_DOM_HTML_BR_ELEMENT(g_object_new(WEBKIT_DOM_TYPE_HTML_BR_ELEMENT, "core-object" , coreObject, nullptr)); |
57 | } |
58 | |
59 | } // namespace WebKit |
60 | |
61 | static gboolean webkit_dom_html_br_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::HTMLBRElement* coreTarget = static_cast<WebCore::HTMLBRElement*>(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_br_element_add_event_listener(WebKitDOMEventTarget* target, const char* eventName, GClosure* handler, gboolean useCapture) |
78 | { |
79 | WebCore::HTMLBRElement* coreTarget = static_cast<WebCore::HTMLBRElement*>(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_br_element_remove_event_listener(WebKitDOMEventTarget* target, const char* eventName, GClosure* handler, gboolean useCapture) |
84 | { |
85 | WebCore::HTMLBRElement* coreTarget = static_cast<WebCore::HTMLBRElement*>(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_br_element_dom_event_target_init(WebKitDOMEventTargetIface* iface) |
90 | { |
91 | iface->dispatch_event = webkit_dom_html_br_element_dispatch_event; |
92 | iface->add_event_listener = webkit_dom_html_br_element_add_event_listener; |
93 | iface->remove_event_listener = webkit_dom_html_br_element_remove_event_listener; |
94 | } |
95 | |
96 | G_DEFINE_TYPE_WITH_CODE(WebKitDOMHTMLBRElement, webkit_dom_html_br_element, WEBKIT_DOM_TYPE_HTML_ELEMENT, G_IMPLEMENT_INTERFACE(WEBKIT_DOM_TYPE_EVENT_TARGET, webkit_dom_html_br_element_dom_event_target_init)) |
97 | enum { |
98 | DOM_HTML_BR_ELEMENT_PROP_0, |
99 | DOM_HTML_BR_ELEMENT_PROP_CLEAR, |
100 | }; |
101 | |
102 | static void webkit_dom_html_br_element_set_property(GObject* object, guint propertyId, const GValue* value, GParamSpec* pspec) |
103 | { |
104 | WebKitDOMHTMLBRElement* self = WEBKIT_DOM_HTML_BR_ELEMENT(object); |
105 | |
106 | switch (propertyId) { |
107 | case DOM_HTML_BR_ELEMENT_PROP_CLEAR: |
108 | webkit_dom_html_br_element_set_clear(self, g_value_get_string(value)); |
109 | break; |
110 | default: |
111 | G_OBJECT_WARN_INVALID_PROPERTY_ID(object, propertyId, pspec); |
112 | break; |
113 | } |
114 | } |
115 | |
116 | static void webkit_dom_html_br_element_get_property(GObject* object, guint propertyId, GValue* value, GParamSpec* pspec) |
117 | { |
118 | WebKitDOMHTMLBRElement* self = WEBKIT_DOM_HTML_BR_ELEMENT(object); |
119 | |
120 | switch (propertyId) { |
121 | case DOM_HTML_BR_ELEMENT_PROP_CLEAR: |
122 | g_value_take_string(value, webkit_dom_html_br_element_get_clear(self)); |
123 | break; |
124 | default: |
125 | G_OBJECT_WARN_INVALID_PROPERTY_ID(object, propertyId, pspec); |
126 | break; |
127 | } |
128 | } |
129 | |
130 | static void webkit_dom_html_br_element_class_init(WebKitDOMHTMLBRElementClass* requestClass) |
131 | { |
132 | GObjectClass* gobjectClass = G_OBJECT_CLASS(requestClass); |
133 | gobjectClass->set_property = webkit_dom_html_br_element_set_property; |
134 | gobjectClass->get_property = webkit_dom_html_br_element_get_property; |
135 | |
136 | g_object_class_install_property( |
137 | gobjectClass, |
138 | DOM_HTML_BR_ELEMENT_PROP_CLEAR, |
139 | g_param_spec_string( |
140 | "clear" , |
141 | "HTMLBRElement:clear" , |
142 | "read-write gchar* HTMLBRElement:clear" , |
143 | "" , |
144 | WEBKIT_PARAM_READWRITE)); |
145 | |
146 | } |
147 | |
148 | static void webkit_dom_html_br_element_init(WebKitDOMHTMLBRElement* request) |
149 | { |
150 | UNUSED_PARAM(request); |
151 | } |
152 | |
153 | gchar* webkit_dom_html_br_element_get_clear(WebKitDOMHTMLBRElement* self) |
154 | { |
155 | WebCore::JSMainThreadNullState state; |
156 | g_return_val_if_fail(WEBKIT_DOM_IS_HTML_BR_ELEMENT(self), 0); |
157 | WebCore::HTMLBRElement* item = WebKit::core(self); |
158 | gchar* result = convertToUTF8String(item->attributeWithoutSynchronization(WebCore::HTMLNames::clearAttr)); |
159 | return result; |
160 | } |
161 | |
162 | void webkit_dom_html_br_element_set_clear(WebKitDOMHTMLBRElement* self, const gchar* value) |
163 | { |
164 | WebCore::JSMainThreadNullState state; |
165 | g_return_if_fail(WEBKIT_DOM_IS_HTML_BR_ELEMENT(self)); |
166 | g_return_if_fail(value); |
167 | WebCore::HTMLBRElement* item = WebKit::core(self); |
168 | WTF::String convertedValue = WTF::String::fromUTF8(value); |
169 | item->setAttributeWithoutSynchronization(WebCore::HTMLNames::clearAttr, convertedValue); |
170 | } |
171 | |
172 | G_GNUC_END_IGNORE_DEPRECATIONS; |
173 | |