Drop ExceptionCodeDescription class
[WebKit-https.git] / Source / WebKit / WebProcess / InjectedBundle / API / gtk / DOM / WebKitDOMHTMLFrameSetElement.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 "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/JSMainThreadExecState.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
39 namespace WebKit {
40
41 WebKitDOMHTMLFrameSetElement* kit(WebCore::HTMLFrameSetElement* obj)
42 {
43     return WEBKIT_DOM_HTML_FRAME_SET_ELEMENT(kit(static_cast<WebCore::Node*>(obj)));
44 }
45
46 WebCore::HTMLFrameSetElement* core(WebKitDOMHTMLFrameSetElement* request)
47 {
48     return request ? static_cast<WebCore::HTMLFrameSetElement*>(WEBKIT_DOM_OBJECT(request)->coreObject) : 0;
49 }
50
51 WebKitDOMHTMLFrameSetElement* wrapHTMLFrameSetElement(WebCore::HTMLFrameSetElement* coreObject)
52 {
53     ASSERT(coreObject);
54     return WEBKIT_DOM_HTML_FRAME_SET_ELEMENT(g_object_new(WEBKIT_DOM_TYPE_HTML_FRAME_SET_ELEMENT, "core-object", coreObject, nullptr));
55 }
56
57 } // namespace WebKit
58
59 static gboolean webkit_dom_html_frame_set_element_dispatch_event(WebKitDOMEventTarget* target, WebKitDOMEvent* event, GError** error)
60 {
61     WebCore::Event* coreEvent = WebKit::core(event);
62     if (!coreEvent)
63         return false;
64     WebCore::HTMLFrameSetElement* coreTarget = static_cast<WebCore::HTMLFrameSetElement*>(WEBKIT_DOM_OBJECT(target)->coreObject);
65
66     auto result = coreTarget->dispatchEventForBindings(*coreEvent);
67     if (result.hasException()) {
68         auto description = WebCore::DOMException::description(result.releaseException().code());
69         g_set_error_literal(error, g_quark_from_string("WEBKIT_DOM"), description.legacyCode, description.name);
70         return false;
71     }
72     return result.releaseReturnValue();
73 }
74
75 static gboolean webkit_dom_html_frame_set_element_add_event_listener(WebKitDOMEventTarget* target, const char* eventName, GClosure* handler, gboolean useCapture)
76 {
77     WebCore::HTMLFrameSetElement* coreTarget = static_cast<WebCore::HTMLFrameSetElement*>(WEBKIT_DOM_OBJECT(target)->coreObject);
78     return WebKit::GObjectEventListener::addEventListener(G_OBJECT(target), coreTarget, eventName, handler, useCapture);
79 }
80
81 static gboolean webkit_dom_html_frame_set_element_remove_event_listener(WebKitDOMEventTarget* target, const char* eventName, GClosure* handler, gboolean useCapture)
82 {
83     WebCore::HTMLFrameSetElement* coreTarget = static_cast<WebCore::HTMLFrameSetElement*>(WEBKIT_DOM_OBJECT(target)->coreObject);
84     return WebKit::GObjectEventListener::removeEventListener(G_OBJECT(target), coreTarget, eventName, handler, useCapture);
85 }
86
87 static void webkit_dom_event_target_init(WebKitDOMEventTargetIface* iface)
88 {
89     iface->dispatch_event = webkit_dom_html_frame_set_element_dispatch_event;
90     iface->add_event_listener = webkit_dom_html_frame_set_element_add_event_listener;
91     iface->remove_event_listener = webkit_dom_html_frame_set_element_remove_event_listener;
92 }
93
94 G_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_event_target_init))
95
96 enum {
97     PROP_0,
98     PROP_COLS,
99     PROP_ROWS,
100 };
101
102 static void webkit_dom_html_frame_set_element_set_property(GObject* object, guint propertyId, const GValue* value, GParamSpec* pspec)
103 {
104     WebKitDOMHTMLFrameSetElement* self = WEBKIT_DOM_HTML_FRAME_SET_ELEMENT(object);
105
106     switch (propertyId) {
107     case PROP_COLS:
108         webkit_dom_html_frame_set_element_set_cols(self, g_value_get_string(value));
109         break;
110     case PROP_ROWS:
111         webkit_dom_html_frame_set_element_set_rows(self, g_value_get_string(value));
112         break;
113     default:
114         G_OBJECT_WARN_INVALID_PROPERTY_ID(object, propertyId, pspec);
115         break;
116     }
117 }
118
119 static void webkit_dom_html_frame_set_element_get_property(GObject* object, guint propertyId, GValue* value, GParamSpec* pspec)
120 {
121     WebKitDOMHTMLFrameSetElement* self = WEBKIT_DOM_HTML_FRAME_SET_ELEMENT(object);
122
123     switch (propertyId) {
124     case PROP_COLS:
125         g_value_take_string(value, webkit_dom_html_frame_set_element_get_cols(self));
126         break;
127     case PROP_ROWS:
128         g_value_take_string(value, webkit_dom_html_frame_set_element_get_rows(self));
129         break;
130     default:
131         G_OBJECT_WARN_INVALID_PROPERTY_ID(object, propertyId, pspec);
132         break;
133     }
134 }
135
136 static void webkit_dom_html_frame_set_element_class_init(WebKitDOMHTMLFrameSetElementClass* requestClass)
137 {
138     GObjectClass* gobjectClass = G_OBJECT_CLASS(requestClass);
139     gobjectClass->set_property = webkit_dom_html_frame_set_element_set_property;
140     gobjectClass->get_property = webkit_dom_html_frame_set_element_get_property;
141
142     g_object_class_install_property(
143         gobjectClass,
144         PROP_COLS,
145         g_param_spec_string(
146             "cols",
147             "HTMLFrameSetElement:cols",
148             "read-write gchar* HTMLFrameSetElement:cols",
149             "",
150             WEBKIT_PARAM_READWRITE));
151
152     g_object_class_install_property(
153         gobjectClass,
154         PROP_ROWS,
155         g_param_spec_string(
156             "rows",
157             "HTMLFrameSetElement:rows",
158             "read-write gchar* HTMLFrameSetElement:rows",
159             "",
160             WEBKIT_PARAM_READWRITE));
161
162 }
163
164 static void webkit_dom_html_frame_set_element_init(WebKitDOMHTMLFrameSetElement* request)
165 {
166     UNUSED_PARAM(request);
167 }
168
169 gchar* webkit_dom_html_frame_set_element_get_cols(WebKitDOMHTMLFrameSetElement* self)
170 {
171     WebCore::JSMainThreadNullState state;
172     g_return_val_if_fail(WEBKIT_DOM_IS_HTML_FRAME_SET_ELEMENT(self), 0);
173     WebCore::HTMLFrameSetElement* item = WebKit::core(self);
174     gchar* result = convertToUTF8String(item->attributeWithoutSynchronization(WebCore::HTMLNames::colsAttr));
175     return result;
176 }
177
178 void webkit_dom_html_frame_set_element_set_cols(WebKitDOMHTMLFrameSetElement* self, const gchar* value)
179 {
180     WebCore::JSMainThreadNullState state;
181     g_return_if_fail(WEBKIT_DOM_IS_HTML_FRAME_SET_ELEMENT(self));
182     g_return_if_fail(value);
183     WebCore::HTMLFrameSetElement* item = WebKit::core(self);
184     WTF::String convertedValue = WTF::String::fromUTF8(value);
185     item->setAttributeWithoutSynchronization(WebCore::HTMLNames::colsAttr, convertedValue);
186 }
187
188 gchar* webkit_dom_html_frame_set_element_get_rows(WebKitDOMHTMLFrameSetElement* self)
189 {
190     WebCore::JSMainThreadNullState state;
191     g_return_val_if_fail(WEBKIT_DOM_IS_HTML_FRAME_SET_ELEMENT(self), 0);
192     WebCore::HTMLFrameSetElement* item = WebKit::core(self);
193     gchar* result = convertToUTF8String(item->attributeWithoutSynchronization(WebCore::HTMLNames::rowsAttr));
194     return result;
195 }
196
197 void webkit_dom_html_frame_set_element_set_rows(WebKitDOMHTMLFrameSetElement* self, const gchar* value)
198 {
199     WebCore::JSMainThreadNullState state;
200     g_return_if_fail(WEBKIT_DOM_IS_HTML_FRAME_SET_ELEMENT(self));
201     g_return_if_fail(value);
202     WebCore::HTMLFrameSetElement* item = WebKit::core(self);
203     WTF::String convertedValue = WTF::String::fromUTF8(value);
204     item->setAttributeWithoutSynchronization(WebCore::HTMLNames::rowsAttr, convertedValue);
205 }
206