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 "WebKitDOMHTMLFontElement.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 "WebKitDOMHTMLFontElementPrivate.h"
33#include "WebKitDOMNodePrivate.h"
34#include "WebKitDOMPrivate.h"
35#include "ConvertToUTF8String.h"
36#include <wtf/GetPtr.h>
37#include <wtf/RefPtr.h>
38
39G_GNUC_BEGIN_IGNORE_DEPRECATIONS;
40
41namespace WebKit {
42
43WebKitDOMHTMLFontElement* kit(WebCore::HTMLFontElement* obj)
44{
45 return WEBKIT_DOM_HTML_FONT_ELEMENT(kit(static_cast<WebCore::Node*>(obj)));
46}
47
48WebCore::HTMLFontElement* core(WebKitDOMHTMLFontElement* request)
49{
50 return request ? static_cast<WebCore::HTMLFontElement*>(WEBKIT_DOM_OBJECT(request)->coreObject) : 0;
51}
52
53WebKitDOMHTMLFontElement* wrapHTMLFontElement(WebCore::HTMLFontElement* coreObject)
54{
55 ASSERT(coreObject);
56 return WEBKIT_DOM_HTML_FONT_ELEMENT(g_object_new(WEBKIT_DOM_TYPE_HTML_FONT_ELEMENT, "core-object", coreObject, nullptr));
57}
58
59} // namespace WebKit
60
61static gboolean webkit_dom_html_font_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::HTMLFontElement* coreTarget = static_cast<WebCore::HTMLFontElement*>(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
77static gboolean webkit_dom_html_font_element_add_event_listener(WebKitDOMEventTarget* target, const char* eventName, GClosure* handler, gboolean useCapture)
78{
79 WebCore::HTMLFontElement* coreTarget = static_cast<WebCore::HTMLFontElement*>(WEBKIT_DOM_OBJECT(target)->coreObject);
80 return WebKit::GObjectEventListener::addEventListener(G_OBJECT(target), coreTarget, eventName, handler, useCapture);
81}
82
83static gboolean webkit_dom_html_font_element_remove_event_listener(WebKitDOMEventTarget* target, const char* eventName, GClosure* handler, gboolean useCapture)
84{
85 WebCore::HTMLFontElement* coreTarget = static_cast<WebCore::HTMLFontElement*>(WEBKIT_DOM_OBJECT(target)->coreObject);
86 return WebKit::GObjectEventListener::removeEventListener(G_OBJECT(target), coreTarget, eventName, handler, useCapture);
87}
88
89static void webkit_dom_html_font_element_dom_event_target_init(WebKitDOMEventTargetIface* iface)
90{
91 iface->dispatch_event = webkit_dom_html_font_element_dispatch_event;
92 iface->add_event_listener = webkit_dom_html_font_element_add_event_listener;
93 iface->remove_event_listener = webkit_dom_html_font_element_remove_event_listener;
94}
95
96G_DEFINE_TYPE_WITH_CODE(WebKitDOMHTMLFontElement, webkit_dom_html_font_element, WEBKIT_DOM_TYPE_HTML_ELEMENT, G_IMPLEMENT_INTERFACE(WEBKIT_DOM_TYPE_EVENT_TARGET, webkit_dom_html_font_element_dom_event_target_init))
97
98enum {
99 DOM_HTML_FONT_ELEMENT_PROP_0,
100 DOM_HTML_FONT_ELEMENT_PROP_COLOR,
101 DOM_HTML_FONT_ELEMENT_PROP_FACE,
102 DOM_HTML_FONT_ELEMENT_PROP_SIZE,
103};
104
105static void webkit_dom_html_font_element_set_property(GObject* object, guint propertyId, const GValue* value, GParamSpec* pspec)
106{
107 WebKitDOMHTMLFontElement* self = WEBKIT_DOM_HTML_FONT_ELEMENT(object);
108
109 switch (propertyId) {
110 case DOM_HTML_FONT_ELEMENT_PROP_COLOR:
111 webkit_dom_html_font_element_set_color(self, g_value_get_string(value));
112 break;
113 case DOM_HTML_FONT_ELEMENT_PROP_FACE:
114 webkit_dom_html_font_element_set_face(self, g_value_get_string(value));
115 break;
116 case DOM_HTML_FONT_ELEMENT_PROP_SIZE:
117 webkit_dom_html_font_element_set_size(self, g_value_get_string(value));
118 break;
119 default:
120 G_OBJECT_WARN_INVALID_PROPERTY_ID(object, propertyId, pspec);
121 break;
122 }
123}
124
125static void webkit_dom_html_font_element_get_property(GObject* object, guint propertyId, GValue* value, GParamSpec* pspec)
126{
127 WebKitDOMHTMLFontElement* self = WEBKIT_DOM_HTML_FONT_ELEMENT(object);
128
129 switch (propertyId) {
130 case DOM_HTML_FONT_ELEMENT_PROP_COLOR:
131 g_value_take_string(value, webkit_dom_html_font_element_get_color(self));
132 break;
133 case DOM_HTML_FONT_ELEMENT_PROP_FACE:
134 g_value_take_string(value, webkit_dom_html_font_element_get_face(self));
135 break;
136 case DOM_HTML_FONT_ELEMENT_PROP_SIZE:
137 g_value_take_string(value, webkit_dom_html_font_element_get_size(self));
138 break;
139 default:
140 G_OBJECT_WARN_INVALID_PROPERTY_ID(object, propertyId, pspec);
141 break;
142 }
143}
144
145static void webkit_dom_html_font_element_class_init(WebKitDOMHTMLFontElementClass* requestClass)
146{
147 GObjectClass* gobjectClass = G_OBJECT_CLASS(requestClass);
148 gobjectClass->set_property = webkit_dom_html_font_element_set_property;
149 gobjectClass->get_property = webkit_dom_html_font_element_get_property;
150
151 g_object_class_install_property(
152 gobjectClass,
153 DOM_HTML_FONT_ELEMENT_PROP_COLOR,
154 g_param_spec_string(
155 "color",
156 "HTMLFontElement:color",
157 "read-write gchar* HTMLFontElement:color",
158 "",
159 WEBKIT_PARAM_READWRITE));
160
161 g_object_class_install_property(
162 gobjectClass,
163 DOM_HTML_FONT_ELEMENT_PROP_FACE,
164 g_param_spec_string(
165 "face",
166 "HTMLFontElement:face",
167 "read-write gchar* HTMLFontElement:face",
168 "",
169 WEBKIT_PARAM_READWRITE));
170
171 g_object_class_install_property(
172 gobjectClass,
173 DOM_HTML_FONT_ELEMENT_PROP_SIZE,
174 g_param_spec_string(
175 "size",
176 "HTMLFontElement:size",
177 "read-write gchar* HTMLFontElement:size",
178 "",
179 WEBKIT_PARAM_READWRITE));
180
181}
182
183static void webkit_dom_html_font_element_init(WebKitDOMHTMLFontElement* request)
184{
185 UNUSED_PARAM(request);
186}
187
188gchar* webkit_dom_html_font_element_get_color(WebKitDOMHTMLFontElement* self)
189{
190 WebCore::JSMainThreadNullState state;
191 g_return_val_if_fail(WEBKIT_DOM_IS_HTML_FONT_ELEMENT(self), 0);
192 WebCore::HTMLFontElement* item = WebKit::core(self);
193 gchar* result = convertToUTF8String(item->attributeWithoutSynchronization(WebCore::HTMLNames::colorAttr));
194 return result;
195}
196
197void webkit_dom_html_font_element_set_color(WebKitDOMHTMLFontElement* self, const gchar* value)
198{
199 WebCore::JSMainThreadNullState state;
200 g_return_if_fail(WEBKIT_DOM_IS_HTML_FONT_ELEMENT(self));
201 g_return_if_fail(value);
202 WebCore::HTMLFontElement* item = WebKit::core(self);
203 WTF::String convertedValue = WTF::String::fromUTF8(value);
204 item->setAttributeWithoutSynchronization(WebCore::HTMLNames::colorAttr, convertedValue);
205}
206
207gchar* webkit_dom_html_font_element_get_face(WebKitDOMHTMLFontElement* self)
208{
209 WebCore::JSMainThreadNullState state;
210 g_return_val_if_fail(WEBKIT_DOM_IS_HTML_FONT_ELEMENT(self), 0);
211 WebCore::HTMLFontElement* item = WebKit::core(self);
212 gchar* result = convertToUTF8String(item->attributeWithoutSynchronization(WebCore::HTMLNames::faceAttr));
213 return result;
214}
215
216void webkit_dom_html_font_element_set_face(WebKitDOMHTMLFontElement* self, const gchar* value)
217{
218 WebCore::JSMainThreadNullState state;
219 g_return_if_fail(WEBKIT_DOM_IS_HTML_FONT_ELEMENT(self));
220 g_return_if_fail(value);
221 WebCore::HTMLFontElement* item = WebKit::core(self);
222 WTF::String convertedValue = WTF::String::fromUTF8(value);
223 item->setAttributeWithoutSynchronization(WebCore::HTMLNames::faceAttr, convertedValue);
224}
225
226gchar* webkit_dom_html_font_element_get_size(WebKitDOMHTMLFontElement* self)
227{
228 WebCore::JSMainThreadNullState state;
229 g_return_val_if_fail(WEBKIT_DOM_IS_HTML_FONT_ELEMENT(self), 0);
230 WebCore::HTMLFontElement* item = WebKit::core(self);
231 gchar* result = convertToUTF8String(item->attributeWithoutSynchronization(WebCore::HTMLNames::sizeAttr));
232 return result;
233}
234
235void webkit_dom_html_font_element_set_size(WebKitDOMHTMLFontElement* self, const gchar* value)
236{
237 WebCore::JSMainThreadNullState state;
238 g_return_if_fail(WEBKIT_DOM_IS_HTML_FONT_ELEMENT(self));
239 g_return_if_fail(value);
240 WebCore::HTMLFontElement* item = WebKit::core(self);
241 WTF::String convertedValue = WTF::String::fromUTF8(value);
242 item->setAttributeWithoutSynchronization(WebCore::HTMLNames::sizeAttr, convertedValue);
243}
244
245G_GNUC_END_IGNORE_DEPRECATIONS;
246