Drop ExceptionCodeDescription class
[WebKit-https.git] / Source / WebKit / WebProcess / InjectedBundle / API / gtk / DOM / WebKitDOMHTMLParagraphElement.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 "WebKitDOMHTMLParagraphElement.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 "WebKitDOMHTMLParagraphElementPrivate.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 WebKitDOMHTMLParagraphElement* kit(WebCore::HTMLParagraphElement* obj)
42 {
43     return WEBKIT_DOM_HTML_PARAGRAPH_ELEMENT(kit(static_cast<WebCore::Node*>(obj)));
44 }
45
46 WebCore::HTMLParagraphElement* core(WebKitDOMHTMLParagraphElement* request)
47 {
48     return request ? static_cast<WebCore::HTMLParagraphElement*>(WEBKIT_DOM_OBJECT(request)->coreObject) : 0;
49 }
50
51 WebKitDOMHTMLParagraphElement* wrapHTMLParagraphElement(WebCore::HTMLParagraphElement* coreObject)
52 {
53     ASSERT(coreObject);
54     return WEBKIT_DOM_HTML_PARAGRAPH_ELEMENT(g_object_new(WEBKIT_DOM_TYPE_HTML_PARAGRAPH_ELEMENT, "core-object", coreObject, nullptr));
55 }
56
57 } // namespace WebKit
58
59 static gboolean webkit_dom_html_paragraph_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::HTMLParagraphElement* coreTarget = static_cast<WebCore::HTMLParagraphElement*>(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_paragraph_element_add_event_listener(WebKitDOMEventTarget* target, const char* eventName, GClosure* handler, gboolean useCapture)
76 {
77     WebCore::HTMLParagraphElement* coreTarget = static_cast<WebCore::HTMLParagraphElement*>(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_paragraph_element_remove_event_listener(WebKitDOMEventTarget* target, const char* eventName, GClosure* handler, gboolean useCapture)
82 {
83     WebCore::HTMLParagraphElement* coreTarget = static_cast<WebCore::HTMLParagraphElement*>(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_paragraph_element_dispatch_event;
90     iface->add_event_listener = webkit_dom_html_paragraph_element_add_event_listener;
91     iface->remove_event_listener = webkit_dom_html_paragraph_element_remove_event_listener;
92 }
93
94 G_DEFINE_TYPE_WITH_CODE(WebKitDOMHTMLParagraphElement, webkit_dom_html_paragraph_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_ALIGN,
99 };
100
101 static void webkit_dom_html_paragraph_element_set_property(GObject* object, guint propertyId, const GValue* value, GParamSpec* pspec)
102 {
103     WebKitDOMHTMLParagraphElement* self = WEBKIT_DOM_HTML_PARAGRAPH_ELEMENT(object);
104
105     switch (propertyId) {
106     case PROP_ALIGN:
107         webkit_dom_html_paragraph_element_set_align(self, g_value_get_string(value));
108         break;
109     default:
110         G_OBJECT_WARN_INVALID_PROPERTY_ID(object, propertyId, pspec);
111         break;
112     }
113 }
114
115 static void webkit_dom_html_paragraph_element_get_property(GObject* object, guint propertyId, GValue* value, GParamSpec* pspec)
116 {
117     WebKitDOMHTMLParagraphElement* self = WEBKIT_DOM_HTML_PARAGRAPH_ELEMENT(object);
118
119     switch (propertyId) {
120     case PROP_ALIGN:
121         g_value_take_string(value, webkit_dom_html_paragraph_element_get_align(self));
122         break;
123     default:
124         G_OBJECT_WARN_INVALID_PROPERTY_ID(object, propertyId, pspec);
125         break;
126     }
127 }
128
129 static void webkit_dom_html_paragraph_element_class_init(WebKitDOMHTMLParagraphElementClass* requestClass)
130 {
131     GObjectClass* gobjectClass = G_OBJECT_CLASS(requestClass);
132     gobjectClass->set_property = webkit_dom_html_paragraph_element_set_property;
133     gobjectClass->get_property = webkit_dom_html_paragraph_element_get_property;
134
135     g_object_class_install_property(
136         gobjectClass,
137         PROP_ALIGN,
138         g_param_spec_string(
139             "align",
140             "HTMLParagraphElement:align",
141             "read-write gchar* HTMLParagraphElement:align",
142             "",
143             WEBKIT_PARAM_READWRITE));
144
145 }
146
147 static void webkit_dom_html_paragraph_element_init(WebKitDOMHTMLParagraphElement* request)
148 {
149     UNUSED_PARAM(request);
150 }
151
152 gchar* webkit_dom_html_paragraph_element_get_align(WebKitDOMHTMLParagraphElement* self)
153 {
154     WebCore::JSMainThreadNullState state;
155     g_return_val_if_fail(WEBKIT_DOM_IS_HTML_PARAGRAPH_ELEMENT(self), 0);
156     WebCore::HTMLParagraphElement* item = WebKit::core(self);
157     gchar* result = convertToUTF8String(item->attributeWithoutSynchronization(WebCore::HTMLNames::alignAttr));
158     return result;
159 }
160
161 void webkit_dom_html_paragraph_element_set_align(WebKitDOMHTMLParagraphElement* self, const gchar* value)
162 {
163     WebCore::JSMainThreadNullState state;
164     g_return_if_fail(WEBKIT_DOM_IS_HTML_PARAGRAPH_ELEMENT(self));
165     g_return_if_fail(value);
166     WebCore::HTMLParagraphElement* item = WebKit::core(self);
167     WTF::String convertedValue = WTF::String::fromUTF8(value);
168     item->setAttributeWithoutSynchronization(WebCore::HTMLNames::alignAttr, convertedValue);
169 }
170