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 "WebKitDOMComment.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/JSExecState.h>
29#include "WebKitDOMCommentPrivate.h"
30#include "WebKitDOMEventPrivate.h"
31#include "WebKitDOMEventTarget.h"
32#include "WebKitDOMNodePrivate.h"
33#include "WebKitDOMPrivate.h"
34#include "ConvertToUTF8String.h"
35#include <wtf/GetPtr.h>
36#include <wtf/RefPtr.h>
37
38G_GNUC_BEGIN_IGNORE_DEPRECATIONS;
39
40namespace WebKit {
41
42WebKitDOMComment* kit(WebCore::Comment* obj)
43{
44 return WEBKIT_DOM_COMMENT(kit(static_cast<WebCore::Node*>(obj)));
45}
46
47WebCore::Comment* core(WebKitDOMComment* request)
48{
49 return request ? static_cast<WebCore::Comment*>(WEBKIT_DOM_OBJECT(request)->coreObject) : 0;
50}
51
52WebKitDOMComment* wrapComment(WebCore::Comment* coreObject)
53{
54 ASSERT(coreObject);
55 return WEBKIT_DOM_COMMENT(g_object_new(WEBKIT_DOM_TYPE_COMMENT, "core-object", coreObject, nullptr));
56}
57
58} // namespace WebKit
59
60static gboolean webkit_dom_comment_dispatch_event(WebKitDOMEventTarget* target, WebKitDOMEvent* event, GError** error)
61{
62 WebCore::Event* coreEvent = WebKit::core(event);
63 if (!coreEvent)
64 return false;
65 WebCore::Comment* coreTarget = static_cast<WebCore::Comment*>(WEBKIT_DOM_OBJECT(target)->coreObject);
66
67 auto result = coreTarget->dispatchEventForBindings(*coreEvent);
68 if (result.hasException()) {
69 auto description = WebCore::DOMException::description(result.releaseException().code());
70 g_set_error_literal(error, g_quark_from_string("WEBKIT_DOM"), description.legacyCode, description.name);
71 return false;
72 }
73 return result.releaseReturnValue();
74}
75
76static gboolean webkit_dom_comment_add_event_listener(WebKitDOMEventTarget* target, const char* eventName, GClosure* handler, gboolean useCapture)
77{
78 WebCore::Comment* coreTarget = static_cast<WebCore::Comment*>(WEBKIT_DOM_OBJECT(target)->coreObject);
79 return WebKit::GObjectEventListener::addEventListener(G_OBJECT(target), coreTarget, eventName, handler, useCapture);
80}
81
82static gboolean webkit_dom_comment_remove_event_listener(WebKitDOMEventTarget* target, const char* eventName, GClosure* handler, gboolean useCapture)
83{
84 WebCore::Comment* coreTarget = static_cast<WebCore::Comment*>(WEBKIT_DOM_OBJECT(target)->coreObject);
85 return WebKit::GObjectEventListener::removeEventListener(G_OBJECT(target), coreTarget, eventName, handler, useCapture);
86}
87
88static void webkit_dom_comment_dom_event_target_init(WebKitDOMEventTargetIface* iface)
89{
90 iface->dispatch_event = webkit_dom_comment_dispatch_event;
91 iface->add_event_listener = webkit_dom_comment_add_event_listener;
92 iface->remove_event_listener = webkit_dom_comment_remove_event_listener;
93}
94
95G_DEFINE_TYPE_WITH_CODE(WebKitDOMComment, webkit_dom_comment, WEBKIT_DOM_TYPE_CHARACTER_DATA, G_IMPLEMENT_INTERFACE(WEBKIT_DOM_TYPE_EVENT_TARGET, webkit_dom_comment_dom_event_target_init))
96
97static void webkit_dom_comment_class_init(WebKitDOMCommentClass* requestClass)
98{
99 UNUSED_PARAM(requestClass);
100}
101
102static void webkit_dom_comment_init(WebKitDOMComment* request)
103{
104 UNUSED_PARAM(request);
105}
106
107G_GNUC_END_IGNORE_DEPRECATIONS;
108