|
Line 0
WebKit/gtk/webkit/webkitevent.cpp_sec1
|
|
|
1 |
/* |
| 2 |
* Copyright (C) 2007 Holger Hans Peter Freyther |
| 3 |
* Copyright (C) 2008 Luke Kenneth Casson Leighton |
| 4 |
* |
| 5 |
* This library is free software; you can redistribute it and/or |
| 6 |
* modify it under the terms of the GNU Library General Public |
| 7 |
* License as published by the Free Software Foundation; either |
| 8 |
* version 2 of the License, or (at your option) any later version. |
| 9 |
* |
| 10 |
* This library is distributed in the hope that it will be useful, |
| 11 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 13 |
* Library General Public License for more details. |
| 14 |
* |
| 15 |
* You should have received a copy of the GNU Library General Public License |
| 16 |
* along with this library; see the file COPYING.LIB. If not, write to |
| 17 |
* the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, |
| 18 |
* Boston, MA 02110-1301, USA. |
| 19 |
*/ |
| 20 |
|
| 21 |
#include "config.h" |
| 22 |
|
| 23 |
#include "webkitevent.h" |
| 24 |
#include "WebCore/dom/Event.h" |
| 25 |
#include "WebCore/platform/text/CString.h" |
| 26 |
#include "WebCore/platform/text/StringImpl.h" |
| 27 |
|
| 28 |
|
| 29 |
#include "config.h" |
| 30 |
#include "HTMLDocument.h" |
| 31 |
|
| 32 |
|
| 33 |
#include "DocumentLoader.h" |
| 34 |
#include "Element.h" |
| 35 |
#include "EventListener.h" |
| 36 |
#include "EventNames.h" |
| 37 |
#include "FrameLoader.h" |
| 38 |
#include "FrameView.h" |
| 39 |
#include "HTMLNames.h" |
| 40 |
#include "Settings.h" |
| 41 |
#include "JavaScriptCore/API/JSValueRef.h" |
| 42 |
#include "JavaScriptCore/kjs/JSValue.h" |
| 43 |
#include "EventListenerHack.h" |
| 44 |
#include "DerivedSources/JSHTMLDocument.h" |
| 45 |
#include "JavaScriptCore/API/APICast.h" |
| 46 |
#include "WebCore/html/HTMLDocument.h" |
| 47 |
#include "WebCore/platform/text/CString.h" |
| 48 |
#include "WebCore/platform/text/StringImpl.h" |
| 49 |
|
| 50 |
#include <glib-object.h> |
| 51 |
|
| 52 |
|
| 53 |
using namespace WebCore; |
| 54 |
|
| 55 |
extern "C" { |
| 56 |
|
| 57 |
G_DEFINE_TYPE(WebKitEvent, webkit_event, G_TYPE_OBJECT); |
| 58 |
|
| 59 |
struct _WebKitEventPrivate { |
| 60 |
Event* event; |
| 61 |
}; |
| 62 |
|
| 63 |
#define WEBKIT_EVENT_GET_PRIVATE(obj) (G_TYPE_INSTANCE_GET_PRIVATE((obj), WEBKIT_TYPE_EVENT, WebKitEventPrivate)) |
| 64 |
|
| 65 |
static void webkit_event_finalize(GObject* object) |
| 66 |
{ |
| 67 |
//WebKitEvent* request = WEBKIT_EVENT(object); |
| 68 |
//WebKitEventPrivate* priv = request->priv; |
| 69 |
|
| 70 |
//g_free(priv->uri); |
| 71 |
|
| 72 |
G_OBJECT_CLASS(webkit_event_parent_class)->finalize(object); |
| 73 |
} |
| 74 |
|
| 75 |
static void webkit_event_class_init(WebKitEventClass* requestClass) |
| 76 |
{ |
| 77 |
G_OBJECT_CLASS(requestClass)->finalize = webkit_event_finalize; |
| 78 |
|
| 79 |
g_type_class_add_private(requestClass, sizeof(WebKitEventPrivate)); |
| 80 |
} |
| 81 |
|
| 82 |
static void webkit_event_init(WebKitEvent* request) |
| 83 |
{ |
| 84 |
WebKitEventPrivate* priv = WEBKIT_EVENT_GET_PRIVATE(request); |
| 85 |
request->priv = priv; |
| 86 |
} |
| 87 |
|
| 88 |
WebKitEvent* webkit_event_new(void) |
| 89 |
{ |
| 90 |
WebKitEvent* request = WEBKIT_EVENT(g_object_new(WEBKIT_TYPE_EVENT, NULL)); |
| 91 |
//priv->event = event; |
| 92 |
|
| 93 |
return request; |
| 94 |
} |
| 95 |
|
| 96 |
/* |
| 97 |
void webkit_event_set_uri(WebKitEvent* request, const gchar* uri) |
| 98 |
{ |
| 99 |
g_return_if_fail(WEBKIT_IS_EVENT(request)); |
| 100 |
g_return_if_fail(uri); |
| 101 |
|
| 102 |
WebKitEventPrivate* priv = request->priv; |
| 103 |
|
| 104 |
g_free(priv->uri); |
| 105 |
priv->uri = g_strdup(uri); |
| 106 |
} |
| 107 |
*/ |
| 108 |
G_CONST_RETURN gchar* webkit_event_get_event_type(WebKitEvent* request) |
| 109 |
{ |
| 110 |
g_return_val_if_fail(WEBKIT_IS_EVENT(request), NULL); |
| 111 |
|
| 112 |
WebKitEventPrivate* priv = request->priv; |
| 113 |
return g_strdup(priv->event->type().string().utf8().data()); |
| 114 |
} |
| 115 |
|
| 116 |
} |
| 117 |
|
| 118 |
class HackEventListener : public EventListener { |
| 119 |
public: |
| 120 |
static PassRefPtr<HackEventListener> create(WebKitWebFrame* wf) { return adoptRef(new HackEventListener(wf)); } |
| 121 |
virtual void handleEvent(Event*, bool isWindowEvent); |
| 122 |
|
| 123 |
private: |
| 124 |
HackEventListener(WebKitWebFrame* wf) : m_wf(wf) { } |
| 125 |
WebKitWebFrame* m_wf; |
| 126 |
}; |
| 127 |
|
| 128 |
void HackEventListener::handleEvent(Event* event, bool isWindowEvent) |
| 129 |
{ |
| 130 |
gboolean retval; |
| 131 |
printf("hack handleEvent %s\n", event->type().string().utf8().data()); |
| 132 |
WebKitEvent *wev = webkit_event_new(); |
| 133 |
WebKitEventPrivate* priv = wev->priv; |
| 134 |
priv->event = event; |
| 135 |
|
| 136 |
g_signal_emit_by_name(m_wf, "browser-event", |
| 137 |
wev, event->type().string().utf8().data(), isWindowEvent, &retval); |
| 138 |
/* TODO: stop event propagating if True returned */ |
| 139 |
} |
| 140 |
|
| 141 |
gboolean add_window_event_listener(WebKitWebFrame *wf, Frame *frame, |
| 142 |
const char *name) |
| 143 |
{ |
| 144 |
Document* doc = frame->document(); |
| 145 |
|
| 146 |
RefPtr<EventListener> listener = HackEventListener::create(wf); |
| 147 |
doc->addWindowEventListener(name, listener, true); |
| 148 |
|
| 149 |
return TRUE; |
| 150 |
|
| 151 |
} |
| 152 |
|