Jacek Caban : mshtml: Move keypress event listener to separated
object.
Alexandre Julliard
julliard at wine.codeweavers.com
Mon Jun 25 07:28:16 CDT 2007
Module: wine
Branch: master
Commit: 8b3086a512a9e0db26bbd23151ce69ff2e9fce3b
URL: http://source.winehq.org/git/wine.git/?a=commit;h=8b3086a512a9e0db26bbd23151ce69ff2e9fce3b
Author: Jacek Caban <jacek at codeweavers.com>
Date: Fri Jun 22 23:28:09 2007 +0200
mshtml: Move keypress event listener to separated object.
---
dlls/mshtml/Makefile.in | 1 +
dlls/mshtml/mshtml_private.h | 8 ++
dlls/mshtml/nsembed.c | 11 +--
dlls/mshtml/nsevents.c | 148 ++++++++++++++++++++++++++++++++++++++++++
4 files changed, 160 insertions(+), 8 deletions(-)
diff --git a/dlls/mshtml/Makefile.in b/dlls/mshtml/Makefile.in
index 6cbeaf7..eeb6e0d 100644
--- a/dlls/mshtml/Makefile.in
+++ b/dlls/mshtml/Makefile.in
@@ -30,6 +30,7 @@ C_SRCS = \
main.c \
navigate.c \
nsembed.c \
+ nsevents.c \
nsio.c \
nsservice.c \
olecmd.c \
diff --git a/dlls/mshtml/mshtml_private.h b/dlls/mshtml/mshtml_private.h
index b20354c..644f6b0 100644
--- a/dlls/mshtml/mshtml_private.h
+++ b/dlls/mshtml/mshtml_private.h
@@ -126,6 +126,11 @@ struct HTMLDocument {
HTMLDOMNode *nodes;
};
+typedef struct {
+ const nsIDOMEventListenerVtbl *lpDOMEventListenerVtbl;
+ NSContainer *This;
+} nsEventListener;
+
struct NSContainer {
const nsIWebBrowserChromeVtbl *lpWebBrowserChromeVtbl;
const nsIContextMenuListenerVtbl *lpContextMenuListenerVtbl;
@@ -137,6 +142,8 @@ struct NSContainer {
const nsISupportsWeakReferenceVtbl *lpSupportsWeakReferenceVtbl;
const nsIDOMEventListenerVtbl *lpDOMEventListenerVtbl;
+ nsEventListener keypress_listener;
+
nsIWebBrowser *webbrowser;
nsIWebNavigation *navigation;
nsIBaseWindow *window;
@@ -350,6 +357,7 @@ void nsAString_Finish(nsAString*);
nsIInputStream *create_nsstream(const char*,PRInt32);
nsICommandParams *create_nscommand_params(void);
void nsnode_to_nsstring(nsIDOMNode*,nsAString*);
+void init_nsevents(NSContainer*);
BSCallback *create_bscallback(IMoniker*);
HRESULT start_binding(BSCallback*);
diff --git a/dlls/mshtml/nsembed.c b/dlls/mshtml/nsembed.c
index 40225d5..862e084 100644
--- a/dlls/mshtml/nsembed.c
+++ b/dlls/mshtml/nsembed.c
@@ -1627,16 +1627,9 @@ NSContainer *NSContainer_Create(HTMLDocument *doc, NSContainer *parent)
nsres = nsIDOMWindow_QueryInterface(dom_window, &IID_nsIDOMEventTarget, (void**)&target);
nsIDOMWindow_Release(dom_window);
if(NS_SUCCEEDED(nsres)) {
- nsAString keypress_str, load_str;
- static const PRUnichar wsz_keypress[] = {'k','e','y','p','r','e','s','s',0};
+ nsAString load_str;
static const PRUnichar wsz_load[] = {'l','o','a','d',0};
- nsAString_Init(&keypress_str, wsz_keypress);
- nsres = nsIDOMEventTarget_AddEventListener(target, &keypress_str, NSEVENTLIST(ret), FALSE);
- nsAString_Finish(&keypress_str);
- if(NS_FAILED(nsres))
- ERR("AddEventTarget failed: %08x\n", nsres);
-
nsAString_Init(&load_str, wsz_load);
nsres = nsIDOMEventTarget_AddEventListener(target, &load_str, NSEVENTLIST(ret), TRUE);
nsAString_Finish(&load_str);
@@ -1651,6 +1644,8 @@ NSContainer *NSContainer_Create(HTMLDocument *doc, NSContainer *parent)
ERR("GetContentDOMWindow failed: %08x\n", nsres);
}
+ init_nsevents(ret);
+
nsres = nsIWebBrowser_QueryInterface(ret->webbrowser, &IID_nsIScrollable, (void**)&scrollable);
if(NS_SUCCEEDED(nsres)) {
nsres = nsIScrollable_SetDefaultScrollbarPreferences(scrollable,
diff --git a/dlls/mshtml/nsevents.c b/dlls/mshtml/nsevents.c
new file mode 100644
index 0000000..887a169
--- /dev/null
+++ b/dlls/mshtml/nsevents.c
@@ -0,0 +1,148 @@
+/*
+ * Copyright 2007 Jacek Caban for CodeWeavers
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
+ */
+
+#include "config.h"
+
+#include <stdarg.h>
+
+#define COBJMACROS
+
+#include "windef.h"
+#include "winbase.h"
+#include "winuser.h"
+#include "ole2.h"
+
+#include "wine/debug.h"
+#include "wine/unicode.h"
+
+#include "mshtml_private.h"
+
+WINE_DEFAULT_DEBUG_CHANNEL(mshtml);
+
+#define NSEVENTLIST_THIS(iface) DEFINE_THIS(nsEventListener, DOMEventListener, iface)
+
+static nsresult NSAPI nsDOMEventListener_QueryInterface(nsIDOMEventListener *iface,
+ nsIIDRef riid, nsQIResult result)
+{
+ nsEventListener *This = NSEVENTLIST_THIS(iface);
+
+ *result = NULL;
+
+ if(IsEqualGUID(&IID_nsISupports, riid)) {
+ TRACE("(%p)->(IID_nsISupports, %p)\n", This, result);
+ *result = NSEVENTLIST(This);
+ }else if(IsEqualGUID(&IID_nsIDOMEventListener, riid)) {
+ TRACE("(%p)->(IID_nsIDOMEventListener %p)\n", This, result);
+ *result = NSEVENTLIST(This);
+ }
+
+ if(*result) {
+ nsIWebBrowserChrome_AddRef(NSEVENTLIST(This));
+ return NS_OK;
+ }
+
+ TRACE("(%p)->(%s %p)\n", This, debugstr_guid(riid), result);
+ return NS_NOINTERFACE;
+}
+
+static nsrefcnt NSAPI nsDOMEventListener_AddRef(nsIDOMEventListener *iface)
+{
+ NSContainer *This = NSEVENTLIST_THIS(iface)->This;
+ return nsIWebBrowserChrome_AddRef(NSWBCHROME(This));
+}
+
+static nsrefcnt NSAPI nsDOMEventListener_Release(nsIDOMEventListener *iface)
+{
+ NSContainer *This = NSEVENTLIST_THIS(iface)->This;
+ return nsIWebBrowserChrome_Release(NSWBCHROME(This));
+}
+
+static nsresult NSAPI handle_keypress(nsIDOMEventListener *iface,
+ nsIDOMEvent *event)
+{
+ NSContainer *This = NSEVENTLIST_THIS(iface)->This;
+
+ TRACE("(%p)->(%p)\n", This, event);
+
+ update_doc(This->doc, UPDATE_UI);
+ if(This->doc->usermode == EDITMODE)
+ handle_edit_event(This->doc, event);
+
+ return NS_OK;
+}
+
+#undef NSEVENTLIST_THIS
+
+#define EVENTLISTENER_VTBL(handler) \
+ { \
+ nsDOMEventListener_QueryInterface, \
+ nsDOMEventListener_AddRef, \
+ nsDOMEventListener_Release, \
+ handler, \
+ };
+
+static const nsIDOMEventListenerVtbl keypress_vtbl = EVENTLISTENER_VTBL(handle_keypress);
+
+static void init_event(nsIDOMEventTarget *target, const PRUnichar *type,
+ nsIDOMEventListener *listener, BOOL capture)
+{
+ nsAString type_str;
+ nsresult nsres;
+
+ nsAString_Init(&type_str, type);
+ nsres = nsIDOMEventTarget_AddEventListener(target, &type_str, listener, capture);
+ nsAString_Finish(&type_str);
+ if(NS_FAILED(nsres))
+ ERR("AddEventTarget failed: %08x\n", nsres);
+
+}
+
+static void init_listener(nsEventListener *This, NSContainer *container,
+ const nsIDOMEventListenerVtbl *vtbl)
+{
+ This->lpDOMEventListenerVtbl = vtbl;
+ This->This = container;
+}
+
+void init_nsevents(NSContainer *This)
+{
+ nsIDOMWindow *dom_window;
+ nsIDOMEventTarget *target;
+ nsresult nsres;
+
+ static const PRUnichar wsz_keypress[] = {'k','e','y','p','r','e','s','s',0};
+
+ init_listener(&This->keypress_listener, This, &keypress_vtbl);
+
+ nsres = nsIWebBrowser_GetContentDOMWindow(This->webbrowser, &dom_window);
+ if(NS_FAILED(nsres)) {
+ ERR("GetContentDOMWindow failed: %08x\n", nsres);
+ return;
+ }
+
+ nsres = nsIDOMWindow_QueryInterface(dom_window, &IID_nsIDOMEventTarget, (void**)&target);
+ nsIDOMWindow_Release(dom_window);
+ if(NS_FAILED(nsres)) {
+ ERR("Could not get nsIDOMEventTarget interface: %08x\n", nsres);
+ return;
+ }
+
+ init_event(target, wsz_keypress, NSEVENTLIST(&This->keypress_listener), FALSE);
+
+ nsIDOMEventTarget_Release(target);
+}
More information about the wine-cvs
mailing list