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 "WebKitDOMHTMLFrameSetElement.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 "WebKitDOMHTMLFrameSetElementPrivate.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
43WebKitDOMHTMLFrameSetElement* kit(WebCore::HTMLFrameSetElement* obj)
44{
45 return WEBKIT_DOM_HTML_FRAME_SET_ELEMENT(kit(static_cast<WebCore::Node*>(obj)));
46}
47
48WebCore::HTMLFrameSetElement* core(WebKitDOMHTMLFrameSetElement* request)
49{
50 return request ? static_cast<WebCore::HTMLFrameSetElement*>(WEBKIT_DOM_OBJECT(request)->coreObject) : 0;
51}
52
53WebKitDOMHTMLFrameSetElement* wrapHTMLFrameSetElement(WebCore::HTMLFrameSetElement* coreObject)
54{
55 ASSERT(coreObject);
56 return WEBKIT_DOM_HTML_FRAME_SET_ELEMENT(g_object_new(WEBKIT_DOM_TYPE_HTML_FRAME_SET_ELEMENT, "core-object", coreObject, nullptr));
57}
58
59} // namespace WebKit
60
61static gboolean webkit_dom_html_frame_set_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::HTMLFrameSetElement* coreTarget = static_cast<WebCore::HTMLFrameSetElement*>(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_frame_set_element_add_event_listener(WebKitDOMEventTarget* target, const char* eventName, GClosure* handler, gboolean useCapture)
78{
79 WebCore::HTMLFrameSetElement* coreTarget = static_cast<WebCore::HTMLFrameSetElement*>(WEBKIT_DOM_OBJECT(target)->coreObject);
80 return WebKit::GObjectEventListener::addEventListener(G_OBJECT(target), coreTarget, eventName, handler, useCapture);
81}
82
83static gboolean webkit_dom_html_frame_set_element_remove_event_listener(WebKitDOMEventTarget* target, const char* eventName, GClosure* handler, gboolean useCapture)
84{
85 WebCore::HTMLFrameSetElement* coreTarget = static_cast<WebCore::HTMLFrameSetElement*>(WEBKIT_DOM_OBJECT(target)->coreObject);
86 return WebKit::GObjectEventListener::removeEventListener(G_OBJECT(target), coreTarget, eventName, handler, useCapture);
87}
88
89static void webkit_dom_html_frame_set_element_dom_event_target_init(WebKitDOMEventTargetIface* iface)
90{
91 iface->dispatch_event = webkit_dom_html_frame_set_element_dispatch_event;
92 iface->add_event_listener = webkit_dom_html_frame_set_element_add_event_listener;
93 iface->remove_event_listener = webkit_dom_html_frame_set_element_remove_event_listener;
94}
95
96G_DEFINE_TYPE_WITH_CODE(WebKitDOMHTMLFrameSetElement, webkit_dom_html_frame_set_element, WEBKIT_DOM_TYPE_HTML_ELEMENT, G_IMPLEMENT_INTERFACE(WEBKIT_DOM_TYPE_EVENT_TARGET, webkit_dom_html_frame_set_element_dom_event_target_init))
97
98enum {
99 DOM_HTML_FRAME_SET_ELEMENT_PROP_0,
100 DOM_HTML_FRAME_SET_ELEMENT_PROP_COLS,
101 DOM_HTML_FRAME_SET_ELEMENT_PROP_ROWS,
102};
103
104static void webkit_dom_html_frame_set_element_set_property(GObject* object, guint propertyId, const GValue* value, GParamSpec* pspec)
105{
106 WebKitDOMHTMLFrameSetElement* self = WEBKIT_DOM_HTML_FRAME_SET_ELEMENT(object);
107
108 switch (propertyId) {
109 case DOM_HTML_FRAME_SET_ELEMENT_PROP_COLS:
110 webkit_dom_html_frame_set_element_set_cols(self, g_value_get_string(value));
111 break;
112 case DOM_HTML_FRAME_SET_ELEMENT_PROP_ROWS:
113 webkit_dom_html_frame_set_element_set_rows(self, g_value_get_string(value));
114 break;
115 default:
116 G_OBJECT_WARN_INVALID_PROPERTY_ID(object, propertyId, pspec);
117 break;
118 }
119}
120
121static void webkit_dom_html_frame_set_element_get_property(GObject* object, guint propertyId, GValue* value, GParamSpec* pspec)
122{
123 WebKitDOMHTMLFrameSetElement* self = WEBKIT_DOM_HTML_FRAME_SET_ELEMENT(object);
124
125 switch (propertyId) {
126 case DOM_HTML_FRAME_SET_ELEMENT_PROP_COLS:
127 g_value_take_string(value, webkit_dom_html_frame_set_element_get_cols(self));
128 break;
129 case DOM_HTML_FRAME_SET_ELEMENT_PROP_ROWS:
130 g_value_take_string(value, webkit_dom_html_frame_set_element_get_rows(self));
131 break;
132 default:
133 G_OBJECT_WARN_INVALID_PROPERTY_ID(object, propertyId, pspec);
134 break;
135 }
136}
137
138static void webkit_dom_html_frame_set_element_class_init(WebKitDOMHTMLFrameSetElementClass* requestClass)
139{
140 GObjectClass* gobjectClass = G_OBJECT_CLASS(requestClass);
141 gobjectClass->set_property = webkit_dom_html_frame_set_element_set_property;
142 gobjectClass->get_property = webkit_dom_html_frame_set_element_get_property;
143
144 g_object_class_install_property(
145 gobjectClass,
146 DOM_HTML_FRAME_SET_ELEMENT_PROP_COLS,
147 g_param_spec_string(
148 "cols",
149 "HTMLFrameSetElement:cols",
150 "read-write gchar* HTMLFrameSetElement:cols",
151 "",
152 WEBKIT_PARAM_READWRITE));
153
154 g_object_class_install_property(
155 gobjectClass,
156 DOM_HTML_FRAME_SET_ELEMENT_PROP_ROWS,
157 g_param_spec_string(
158 "rows",
159 "HTMLFrameSetElement:rows",
160 "read-write gchar* HTMLFrameSetElement:rows",
161 "",
162 WEBKIT_PARAM_READWRITE));
163
164}
165
166static void webkit_dom_html_frame_set_element_init(WebKitDOMHTMLFrameSetElement* request)
167{
168 UNUSED_PARAM(request);
169}
170
171gchar* webkit_dom_html_frame_set_element_get_cols(WebKitDOMHTMLFrameSetElement* self)
172{
173 WebCore::JSMainThreadNullState state;
174 g_return_val_if_fail(WEBKIT_DOM_IS_HTML_FRAME_SET_ELEMENT(self), 0);
175 WebCore::HTMLFrameSetElement* item = WebKit::core(self);
176 gchar* result = convertToUTF8String(item->attributeWithoutSynchronization(WebCore::HTMLNames::colsAttr));
177 return result;
178}
179
180void webkit_dom_html_frame_set_element_set_cols(WebKitDOMHTMLFrameSetElement* self, const gchar* value)
181{
182 WebCore::JSMainThreadNullState state;
183 g_return_if_fail(WEBKIT_DOM_IS_HTML_FRAME_SET_ELEMENT(self));
184 g_return_if_fail(value);
185 WebCore::HTMLFrameSetElement* item = WebKit::core(self);
186 WTF::String convertedValue = WTF::String::fromUTF8(value);
187 item->setAttributeWithoutSynchronization(WebCore::HTMLNames::colsAttr, convertedValue);
188}
189
190gchar* webkit_dom_html_frame_set_element_get_rows(WebKitDOMHTMLFrameSetElement* self)
191{
192 WebCore::JSMainThreadNullState state;
193 g_return_val_if_fail(WEBKIT_DOM_IS_HTML_FRAME_SET_ELEMENT(self), 0);
194 WebCore::HTMLFrameSetElement* item = WebKit::core(self);
195 gchar* result = convertToUTF8String(item->attributeWithoutSynchronization(WebCore::HTMLNames::rowsAttr));
196 return result;
197}
198
199void webkit_dom_html_frame_set_element_set_rows(WebKitDOMHTMLFrameSetElement* self, const gchar* value)
200{
201 WebCore::JSMainThreadNullState state;
202 g_return_if_fail(WEBKIT_DOM_IS_HTML_FRAME_SET_ELEMENT(self));
203 g_return_if_fail(value);
204 WebCore::HTMLFrameSetElement* item = WebKit::core(self);
205 WTF::String convertedValue = WTF::String::fromUTF8(value);
206 item->setAttributeWithoutSynchronization(WebCore::HTMLNames::rowsAttr, convertedValue);
207}
208
209G_GNUC_END_IGNORE_DEPRECATIONS;
210