2007-06-22 23:28:09 +02:00
|
|
|
/*
|
2008-10-15 22:22:29 +02:00
|
|
|
* Copyright 2007-2008 Jacek Caban for CodeWeavers
|
2007-06-22 23:28:09 +02:00
|
|
|
*
|
|
|
|
* 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 <stdarg.h>
|
2019-03-13 17:54:11 +01:00
|
|
|
#include <assert.h>
|
2007-06-22 23:28:09 +02:00
|
|
|
|
|
|
|
#define COBJMACROS
|
|
|
|
|
|
|
|
#include "windef.h"
|
|
|
|
#include "winbase.h"
|
|
|
|
#include "winuser.h"
|
|
|
|
#include "ole2.h"
|
2009-11-08 15:40:11 +01:00
|
|
|
#include "mshtmcid.h"
|
|
|
|
#include "shlguid.h"
|
2007-06-22 23:28:09 +02:00
|
|
|
|
|
|
|
#include "wine/debug.h"
|
|
|
|
|
|
|
|
#include "mshtml_private.h"
|
2012-10-16 17:07:29 +02:00
|
|
|
#include "htmlscript.h"
|
2008-10-09 22:36:01 +02:00
|
|
|
#include "htmlevent.h"
|
2012-11-12 12:58:41 +01:00
|
|
|
#include "binding.h"
|
2010-07-30 21:56:05 +02:00
|
|
|
#include "resource.h"
|
2007-06-22 23:28:09 +02:00
|
|
|
|
|
|
|
WINE_DEFAULT_DEBUG_CHANNEL(mshtml);
|
|
|
|
|
2009-10-27 21:09:25 +01:00
|
|
|
typedef struct {
|
2011-01-03 12:19:35 +01:00
|
|
|
nsIDOMEventListener nsIDOMEventListener_iface;
|
2009-10-27 21:09:25 +01:00
|
|
|
nsDocumentEventListener *This;
|
|
|
|
} nsEventListener;
|
|
|
|
|
|
|
|
struct nsDocumentEventListener {
|
|
|
|
nsEventListener blur_listener;
|
|
|
|
nsEventListener focus_listener;
|
|
|
|
nsEventListener keypress_listener;
|
|
|
|
nsEventListener load_listener;
|
|
|
|
nsEventListener htmlevent_listener;
|
|
|
|
|
|
|
|
LONG ref;
|
|
|
|
|
|
|
|
HTMLDocumentNode *doc;
|
|
|
|
};
|
|
|
|
|
|
|
|
static LONG release_listener(nsDocumentEventListener *This)
|
|
|
|
{
|
|
|
|
LONG ref = InterlockedDecrement(&This->ref);
|
|
|
|
|
|
|
|
TRACE("(%p) ref=%d\n", This, ref);
|
|
|
|
|
|
|
|
if(!ref)
|
|
|
|
heap_free(This);
|
|
|
|
|
|
|
|
return ref;
|
|
|
|
}
|
|
|
|
|
2011-01-03 12:19:35 +01:00
|
|
|
static inline nsEventListener *impl_from_nsIDOMEventListener(nsIDOMEventListener *iface)
|
|
|
|
{
|
|
|
|
return CONTAINING_RECORD(iface, nsEventListener, nsIDOMEventListener_iface);
|
|
|
|
}
|
2007-06-22 23:28:09 +02:00
|
|
|
|
|
|
|
static nsresult NSAPI nsDOMEventListener_QueryInterface(nsIDOMEventListener *iface,
|
2010-08-02 11:08:26 +02:00
|
|
|
nsIIDRef riid, void **result)
|
2007-06-22 23:28:09 +02:00
|
|
|
{
|
2011-01-03 12:19:35 +01:00
|
|
|
nsEventListener *This = impl_from_nsIDOMEventListener(iface);
|
2007-06-22 23:28:09 +02:00
|
|
|
|
|
|
|
*result = NULL;
|
|
|
|
|
|
|
|
if(IsEqualGUID(&IID_nsISupports, riid)) {
|
|
|
|
TRACE("(%p)->(IID_nsISupports, %p)\n", This, result);
|
2011-01-03 12:19:35 +01:00
|
|
|
*result = &This->nsIDOMEventListener_iface;
|
2007-06-22 23:28:09 +02:00
|
|
|
}else if(IsEqualGUID(&IID_nsIDOMEventListener, riid)) {
|
|
|
|
TRACE("(%p)->(IID_nsIDOMEventListener %p)\n", This, result);
|
2011-01-03 12:19:35 +01:00
|
|
|
*result = &This->nsIDOMEventListener_iface;
|
2007-06-22 23:28:09 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if(*result) {
|
2012-07-26 11:37:48 +02:00
|
|
|
nsIDOMEventListener_AddRef(&This->nsIDOMEventListener_iface);
|
2007-06-22 23:28:09 +02:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
TRACE("(%p)->(%s %p)\n", This, debugstr_guid(riid), result);
|
|
|
|
return NS_NOINTERFACE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static nsrefcnt NSAPI nsDOMEventListener_AddRef(nsIDOMEventListener *iface)
|
|
|
|
{
|
2011-01-03 12:19:35 +01:00
|
|
|
nsEventListener *This = impl_from_nsIDOMEventListener(iface);
|
|
|
|
LONG ref = InterlockedIncrement(&This->This->ref);
|
2009-10-27 21:09:25 +01:00
|
|
|
|
2011-01-03 12:19:35 +01:00
|
|
|
TRACE("(%p) ref=%d\n", This->This, ref);
|
2009-10-27 21:09:25 +01:00
|
|
|
|
|
|
|
return ref;
|
2007-06-22 23:28:09 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static nsrefcnt NSAPI nsDOMEventListener_Release(nsIDOMEventListener *iface)
|
|
|
|
{
|
2011-01-03 12:19:35 +01:00
|
|
|
nsEventListener *This = impl_from_nsIDOMEventListener(iface);
|
2009-10-27 21:09:25 +01:00
|
|
|
|
2011-01-03 12:19:35 +01:00
|
|
|
return release_listener(This->This);
|
2007-06-22 23:28:09 +02:00
|
|
|
}
|
|
|
|
|
2019-03-11 14:22:24 +01:00
|
|
|
static BOOL is_doc_child_focus(GeckoBrowser *nscontainer)
|
2007-06-22 23:33:00 +02:00
|
|
|
{
|
|
|
|
HWND hwnd;
|
|
|
|
|
2010-04-13 20:01:59 +02:00
|
|
|
for(hwnd = GetFocus(); hwnd && hwnd != nscontainer->hwnd; hwnd = GetParent(hwnd));
|
2007-06-22 23:33:00 +02:00
|
|
|
|
2009-09-16 22:09:17 +02:00
|
|
|
return hwnd != NULL;
|
2007-06-22 23:33:00 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static nsresult NSAPI handle_blur(nsIDOMEventListener *iface, nsIDOMEvent *event)
|
|
|
|
{
|
2011-01-03 12:19:35 +01:00
|
|
|
nsEventListener *This = impl_from_nsIDOMEventListener(iface);
|
|
|
|
HTMLDocumentNode *doc = This->This->doc;
|
2009-10-27 21:09:25 +01:00
|
|
|
HTMLDocumentObj *doc_obj;
|
2007-06-22 23:33:00 +02:00
|
|
|
|
2009-10-27 21:09:25 +01:00
|
|
|
TRACE("(%p)\n", doc);
|
|
|
|
|
2009-11-01 19:25:13 +01:00
|
|
|
if(!doc || !doc->basedoc.doc_obj)
|
2009-10-27 21:09:25 +01:00
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
doc_obj = doc->basedoc.doc_obj;
|
2007-06-22 23:33:00 +02:00
|
|
|
|
2010-04-13 20:01:59 +02:00
|
|
|
if(doc_obj->focus && !is_doc_child_focus(doc_obj->nscontainer)) {
|
2009-10-27 21:09:25 +01:00
|
|
|
doc_obj->focus = FALSE;
|
|
|
|
notif_focus(doc_obj);
|
2007-06-22 23:33:00 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
static nsresult NSAPI handle_focus(nsIDOMEventListener *iface, nsIDOMEvent *event)
|
|
|
|
{
|
2011-01-03 12:19:35 +01:00
|
|
|
nsEventListener *This = impl_from_nsIDOMEventListener(iface);
|
|
|
|
HTMLDocumentNode *doc = This->This->doc;
|
2009-10-27 21:09:25 +01:00
|
|
|
HTMLDocumentObj *doc_obj;
|
2007-06-22 23:33:00 +02:00
|
|
|
|
2009-10-27 21:09:25 +01:00
|
|
|
TRACE("(%p)\n", doc);
|
2007-06-22 23:33:00 +02:00
|
|
|
|
2009-10-27 21:09:25 +01:00
|
|
|
if(!doc)
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
doc_obj = doc->basedoc.doc_obj;
|
|
|
|
|
2010-04-13 20:01:21 +02:00
|
|
|
if(!doc_obj->focus) {
|
2009-10-27 21:09:25 +01:00
|
|
|
doc_obj->focus = TRUE;
|
|
|
|
notif_focus(doc_obj);
|
2007-06-22 23:33:00 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2007-06-22 23:28:09 +02:00
|
|
|
static nsresult NSAPI handle_keypress(nsIDOMEventListener *iface,
|
|
|
|
nsIDOMEvent *event)
|
|
|
|
{
|
2011-01-03 12:19:35 +01:00
|
|
|
nsEventListener *This = impl_from_nsIDOMEventListener(iface);
|
|
|
|
HTMLDocumentNode *doc = This->This->doc;
|
2009-10-27 21:09:25 +01:00
|
|
|
|
2019-03-12 16:10:24 +01:00
|
|
|
if(!doc || !doc->browser)
|
2009-10-27 21:09:25 +01:00
|
|
|
return NS_ERROR_FAILURE;
|
2007-06-22 23:28:09 +02:00
|
|
|
|
2009-10-27 21:09:25 +01:00
|
|
|
TRACE("(%p)->(%p)\n", doc, event);
|
2007-06-22 23:28:09 +02:00
|
|
|
|
2019-03-12 16:10:39 +01:00
|
|
|
update_doc(doc->browser->doc, UPDATE_UI);
|
2019-03-12 16:10:24 +01:00
|
|
|
if(doc->browser->usermode == EDITMODE)
|
2019-03-12 16:10:39 +01:00
|
|
|
handle_edit_event(doc, event);
|
2007-06-22 23:28:09 +02:00
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2009-11-08 15:40:11 +01:00
|
|
|
static void handle_docobj_load(HTMLDocumentObj *doc)
|
|
|
|
{
|
2011-07-23 12:50:49 +02:00
|
|
|
IOleCommandTarget *olecmd = NULL;
|
2009-11-08 15:40:11 +01:00
|
|
|
HRESULT hres;
|
|
|
|
|
2010-10-06 21:35:39 +02:00
|
|
|
if(doc->nscontainer->editor_controller) {
|
|
|
|
nsIController_Release(doc->nscontainer->editor_controller);
|
|
|
|
doc->nscontainer->editor_controller = NULL;
|
|
|
|
}
|
2009-11-08 15:40:11 +01:00
|
|
|
|
2019-03-12 16:10:24 +01:00
|
|
|
if(doc->nscontainer->usermode == EDITMODE)
|
2019-03-12 16:11:41 +01:00
|
|
|
setup_editor_controller(doc->nscontainer);
|
2009-11-08 15:40:11 +01:00
|
|
|
|
2010-10-06 21:35:39 +02:00
|
|
|
if(doc->client) {
|
|
|
|
hres = IOleClientSite_QueryInterface(doc->client, &IID_IOleCommandTarget, (void**)&olecmd);
|
2011-07-23 12:50:49 +02:00
|
|
|
if(FAILED(hres))
|
|
|
|
olecmd = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(doc->download_state) {
|
|
|
|
if(olecmd) {
|
|
|
|
VARIANT progress;
|
|
|
|
|
|
|
|
V_VT(&progress) = VT_I4;
|
|
|
|
V_I4(&progress) = 0;
|
|
|
|
IOleCommandTarget_Exec(olecmd, NULL, OLECMDID_SETPROGRESSPOS,
|
|
|
|
OLECMDEXECOPT_DONTPROMPTUSER, &progress, NULL);
|
2010-10-06 21:35:39 +02:00
|
|
|
}
|
2011-07-23 12:50:49 +02:00
|
|
|
|
|
|
|
set_download_state(doc, 0);
|
2009-11-08 15:40:11 +01:00
|
|
|
}
|
2010-10-06 21:35:39 +02:00
|
|
|
|
2011-07-23 12:50:49 +02:00
|
|
|
if(olecmd) {
|
|
|
|
IOleCommandTarget_Exec(olecmd, &CGID_ShellDocView, 103, 0, NULL, NULL);
|
|
|
|
IOleCommandTarget_Exec(olecmd, &CGID_MSHTML, IDM_PARSECOMPLETE, 0, NULL, NULL);
|
|
|
|
IOleCommandTarget_Exec(olecmd, NULL, OLECMDID_HTTPEQUIV_DONE, 0, NULL, NULL);
|
|
|
|
|
|
|
|
IOleCommandTarget_Release(olecmd);
|
|
|
|
}
|
2009-11-08 15:40:11 +01:00
|
|
|
}
|
|
|
|
|
2007-06-22 23:28:54 +02:00
|
|
|
static nsresult NSAPI handle_load(nsIDOMEventListener *iface, nsIDOMEvent *event)
|
|
|
|
{
|
2011-01-03 12:19:35 +01:00
|
|
|
nsEventListener *This = impl_from_nsIDOMEventListener(iface);
|
|
|
|
HTMLDocumentNode *doc = This->This->doc;
|
2010-10-06 21:35:39 +02:00
|
|
|
HTMLDocumentObj *doc_obj = NULL;
|
2018-01-02 15:07:07 +01:00
|
|
|
DOMEvent *load_event;
|
|
|
|
HRESULT hres;
|
2007-06-22 23:28:54 +02:00
|
|
|
|
2009-10-27 21:09:25 +01:00
|
|
|
TRACE("(%p)\n", doc);
|
2007-06-22 23:28:54 +02:00
|
|
|
|
2010-03-13 16:45:15 +01:00
|
|
|
if(!doc || !doc->basedoc.window)
|
2009-10-27 21:09:25 +01:00
|
|
|
return NS_ERROR_FAILURE;
|
2010-10-06 21:35:39 +02:00
|
|
|
if(doc->basedoc.doc_obj && doc->basedoc.doc_obj->basedoc.doc_node == doc)
|
|
|
|
doc_obj = doc->basedoc.doc_obj;
|
2007-06-22 23:28:54 +02:00
|
|
|
|
2012-07-30 15:56:45 +02:00
|
|
|
connect_scripts(doc->window);
|
2007-08-15 12:40:19 +02:00
|
|
|
|
2013-05-15 12:52:52 +02:00
|
|
|
htmldoc_addref(&doc->basedoc);
|
|
|
|
|
2010-10-06 21:35:39 +02:00
|
|
|
if(doc_obj)
|
2009-11-08 15:40:11 +01:00
|
|
|
handle_docobj_load(doc_obj);
|
|
|
|
|
|
|
|
set_ready_state(doc->basedoc.window, READYSTATE_COMPLETE);
|
|
|
|
|
2010-10-06 21:35:39 +02:00
|
|
|
if(doc_obj) {
|
2010-02-15 16:03:25 +01:00
|
|
|
if(doc_obj->view_sink)
|
|
|
|
IAdviseSink_OnViewChange(doc_obj->view_sink, DVASPECT_CONTENT, -1);
|
|
|
|
|
2010-07-30 21:56:05 +02:00
|
|
|
set_statustext(doc_obj, IDS_STATUS_DONE, NULL);
|
2009-11-08 15:40:11 +01:00
|
|
|
|
|
|
|
update_title(doc_obj);
|
|
|
|
}
|
2009-11-01 19:25:13 +01:00
|
|
|
|
2019-03-12 16:10:24 +01:00
|
|
|
if(doc_obj && doc_obj->nscontainer->usermode != EDITMODE && doc_obj->doc_object_service
|
2012-11-12 12:58:41 +01:00
|
|
|
&& !(doc->basedoc.window->load_flags & BINDING_REFRESH))
|
2011-03-11 11:14:18 +01:00
|
|
|
IDocObjectService_FireDocumentComplete(doc_obj->doc_object_service,
|
2012-06-25 14:04:59 +02:00
|
|
|
&doc->basedoc.window->base.IHTMLWindow2_iface, 0);
|
2011-03-11 11:14:18 +01:00
|
|
|
|
2013-05-15 12:52:52 +02:00
|
|
|
if(doc->nsdoc) {
|
2017-10-20 15:10:17 +02:00
|
|
|
hres = create_document_event(doc, EVENTID_LOAD, &load_event);
|
|
|
|
if(SUCCEEDED(hres)) {
|
2017-10-20 15:10:46 +02:00
|
|
|
dispatch_event(&doc->node.event_target, load_event);
|
2017-10-20 15:10:17 +02:00
|
|
|
IDOMEvent_Release(&load_event->IDOMEvent_iface);
|
|
|
|
}
|
2018-01-02 15:07:07 +01:00
|
|
|
}else {
|
|
|
|
WARN("no nsdoc\n");
|
|
|
|
}
|
2017-10-20 15:09:36 +02:00
|
|
|
|
2018-01-02 15:07:07 +01:00
|
|
|
if(doc->window) {
|
2021-03-11 20:40:19 +01:00
|
|
|
hres = create_event_from_nsevent(event, dispex_compat_mode(&doc->node.event_target.dispex), &load_event);
|
2017-10-20 15:09:36 +02:00
|
|
|
if(SUCCEEDED(hres)) {
|
2017-10-20 15:10:46 +02:00
|
|
|
dispatch_event(&doc->window->event_target, load_event);
|
2017-10-20 15:09:36 +02:00
|
|
|
IDOMEvent_Release(&load_event->IDOMEvent_iface);
|
|
|
|
}
|
2013-05-15 12:52:52 +02:00
|
|
|
}else {
|
2018-01-02 15:07:07 +01:00
|
|
|
WARN("no window\n");
|
2008-10-08 20:27:33 +02:00
|
|
|
}
|
2008-04-21 00:48:18 +02:00
|
|
|
|
2013-05-15 12:52:52 +02:00
|
|
|
htmldoc_release(&doc->basedoc);
|
2018-01-02 15:07:07 +01:00
|
|
|
return NS_OK;
|
2007-06-22 23:28:54 +02:00
|
|
|
}
|
|
|
|
|
2017-10-20 15:09:55 +02:00
|
|
|
static nsresult NSAPI handle_htmlevent(nsIDOMEventListener *iface, nsIDOMEvent *nsevent)
|
2008-06-23 16:54:33 +02:00
|
|
|
{
|
2011-01-03 12:19:35 +01:00
|
|
|
nsEventListener *This = impl_from_nsIDOMEventListener(iface);
|
|
|
|
HTMLDocumentNode *doc = This->This->doc;
|
2008-06-23 16:54:33 +02:00
|
|
|
nsIDOMEventTarget *event_target;
|
|
|
|
nsIDOMNode *nsnode;
|
2016-04-04 13:21:58 +02:00
|
|
|
HTMLDOMNode *node;
|
2017-10-20 15:09:55 +02:00
|
|
|
DOMEvent *event;
|
2008-06-23 16:54:33 +02:00
|
|
|
nsresult nsres;
|
2016-04-04 13:21:58 +02:00
|
|
|
HRESULT hres;
|
2008-06-23 16:54:33 +02:00
|
|
|
|
2011-11-24 12:48:31 +01:00
|
|
|
TRACE("%p\n", This->This);
|
2010-03-18 01:05:38 +01:00
|
|
|
|
2012-09-20 15:05:07 +02:00
|
|
|
if(!doc) {
|
|
|
|
WARN("NULL doc\n");
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2017-10-20 15:09:55 +02:00
|
|
|
nsres = nsIDOMEvent_GetTarget(nsevent, &event_target);
|
2008-06-23 16:54:33 +02:00
|
|
|
if(NS_FAILED(nsres) || !event_target) {
|
|
|
|
ERR("GetEventTarget failed: %08x\n", nsres);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsres = nsIDOMEventTarget_QueryInterface(event_target, &IID_nsIDOMNode, (void**)&nsnode);
|
|
|
|
nsIDOMEventTarget_Release(event_target);
|
|
|
|
if(NS_FAILED(nsres)) {
|
|
|
|
ERR("Could not get nsIDOMNode: %08x\n", nsres);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2018-02-19 14:49:07 +01:00
|
|
|
hres = get_node(nsnode, TRUE, &node);
|
2008-06-23 16:54:33 +02:00
|
|
|
nsIDOMNode_Release(nsnode);
|
2016-04-04 13:21:58 +02:00
|
|
|
if(FAILED(hres))
|
|
|
|
return NS_OK;
|
|
|
|
|
2021-03-11 20:40:19 +01:00
|
|
|
hres = create_event_from_nsevent(nsevent, dispex_compat_mode(&doc->node.event_target.dispex), &event);
|
2017-10-20 15:09:55 +02:00
|
|
|
if(FAILED(hres)) {
|
|
|
|
node_release(node);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2016-04-04 13:22:09 +02:00
|
|
|
/* If we fine need for more special cases here, we may consider handling it in a more generic way. */
|
2017-10-20 15:10:11 +02:00
|
|
|
if(event->event_id == EVENTID_FOCUS || event->event_id == EVENTID_BLUR) {
|
|
|
|
DOMEvent *focus_event;
|
|
|
|
|
|
|
|
hres = create_document_event(doc, event->event_id == EVENTID_FOCUS ? EVENTID_FOCUSIN : EVENTID_FOCUSOUT, &focus_event);
|
|
|
|
if(SUCCEEDED(hres)) {
|
2017-10-20 15:10:46 +02:00
|
|
|
dispatch_event(&node->event_target, focus_event);
|
2017-10-20 15:10:11 +02:00
|
|
|
IDOMEvent_Release(&focus_event->IDOMEvent_iface);
|
|
|
|
}
|
2016-04-04 13:22:09 +02:00
|
|
|
}
|
|
|
|
|
2017-10-20 15:10:46 +02:00
|
|
|
dispatch_event(&node->event_target, event);
|
2008-06-23 16:54:33 +02:00
|
|
|
|
2017-10-20 15:09:55 +02:00
|
|
|
IDOMEvent_Release(&event->IDOMEvent_iface);
|
2016-04-04 13:21:58 +02:00
|
|
|
node_release(node);
|
2008-06-23 16:54:33 +02:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2007-06-22 23:28:09 +02:00
|
|
|
#define EVENTLISTENER_VTBL(handler) \
|
|
|
|
{ \
|
|
|
|
nsDOMEventListener_QueryInterface, \
|
|
|
|
nsDOMEventListener_AddRef, \
|
|
|
|
nsDOMEventListener_Release, \
|
|
|
|
handler, \
|
2008-03-31 21:42:14 +02:00
|
|
|
}
|
2007-06-22 23:28:09 +02:00
|
|
|
|
2007-06-22 23:33:00 +02:00
|
|
|
static const nsIDOMEventListenerVtbl blur_vtbl = EVENTLISTENER_VTBL(handle_blur);
|
|
|
|
static const nsIDOMEventListenerVtbl focus_vtbl = EVENTLISTENER_VTBL(handle_focus);
|
2007-06-22 23:28:09 +02:00
|
|
|
static const nsIDOMEventListenerVtbl keypress_vtbl = EVENTLISTENER_VTBL(handle_keypress);
|
2007-06-22 23:28:54 +02:00
|
|
|
static const nsIDOMEventListenerVtbl load_vtbl = EVENTLISTENER_VTBL(handle_load);
|
2008-06-23 16:54:33 +02:00
|
|
|
static const nsIDOMEventListenerVtbl htmlevent_vtbl = EVENTLISTENER_VTBL(handle_htmlevent);
|
2007-06-22 23:28:09 +02:00
|
|
|
|
|
|
|
static void init_event(nsIDOMEventTarget *target, const PRUnichar *type,
|
|
|
|
nsIDOMEventListener *listener, BOOL capture)
|
|
|
|
{
|
|
|
|
nsAString type_str;
|
|
|
|
nsresult nsres;
|
|
|
|
|
2010-01-28 23:56:31 +01:00
|
|
|
nsAString_InitDepend(&type_str, type);
|
2011-11-09 18:11:42 +01:00
|
|
|
nsres = nsIDOMEventTarget_AddEventListener(target, &type_str, listener, capture, FALSE, 1);
|
2007-06-22 23:28:09 +02:00
|
|
|
nsAString_Finish(&type_str);
|
|
|
|
if(NS_FAILED(nsres))
|
|
|
|
ERR("AddEventTarget failed: %08x\n", nsres);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2009-10-27 21:09:25 +01:00
|
|
|
static void init_listener(nsEventListener *This, nsDocumentEventListener *listener,
|
2007-06-22 23:28:09 +02:00
|
|
|
const nsIDOMEventListenerVtbl *vtbl)
|
|
|
|
{
|
2011-01-03 12:19:35 +01:00
|
|
|
This->nsIDOMEventListener_iface.lpVtbl = vtbl;
|
2009-10-27 21:09:25 +01:00
|
|
|
This->This = listener;
|
2007-06-22 23:28:09 +02:00
|
|
|
}
|
|
|
|
|
2019-03-13 17:54:11 +01:00
|
|
|
static nsIDOMEventTarget *get_default_document_target(HTMLDocumentNode *doc)
|
|
|
|
{
|
|
|
|
nsIDOMEventTarget *target;
|
|
|
|
nsISupports *target_iface;
|
|
|
|
nsresult nsres;
|
|
|
|
|
|
|
|
target_iface = doc->window ? (nsISupports*)doc->basedoc.window->nswindow : (nsISupports*)doc->nsdoc;
|
|
|
|
nsres = nsISupports_QueryInterface(target_iface, &IID_nsIDOMEventTarget, (void**)&target);
|
|
|
|
return NS_SUCCEEDED(nsres) ? target : NULL;
|
|
|
|
}
|
|
|
|
|
2010-03-18 01:05:38 +01:00
|
|
|
void add_nsevent_listener(HTMLDocumentNode *doc, nsIDOMNode *nsnode, LPCWSTR type)
|
2008-06-23 16:54:33 +02:00
|
|
|
{
|
|
|
|
nsIDOMEventTarget *target;
|
|
|
|
nsresult nsres;
|
|
|
|
|
2019-03-13 17:54:11 +01:00
|
|
|
if(nsnode) {
|
2010-03-18 01:05:38 +01:00
|
|
|
nsres = nsIDOMNode_QueryInterface(nsnode, &IID_nsIDOMEventTarget, (void**)&target);
|
2019-03-13 17:54:11 +01:00
|
|
|
assert(nsres == NS_OK);
|
|
|
|
}else {
|
|
|
|
target = get_default_document_target(doc);
|
|
|
|
if(!target)
|
|
|
|
return;
|
2008-06-23 16:54:33 +02:00
|
|
|
}
|
|
|
|
|
2011-01-03 12:19:35 +01:00
|
|
|
init_event(target, type, &doc->nsevent_listener->htmlevent_listener.nsIDOMEventListener_iface,
|
|
|
|
TRUE);
|
2008-06-23 16:54:33 +02:00
|
|
|
nsIDOMEventTarget_Release(target);
|
|
|
|
}
|
|
|
|
|
2012-04-05 13:57:53 +02:00
|
|
|
static void detach_nslistener(HTMLDocumentNode *doc, const WCHAR *type, nsEventListener *listener, cpp_bool is_capture)
|
2011-11-24 12:48:31 +01:00
|
|
|
{
|
|
|
|
nsIDOMEventTarget *target;
|
|
|
|
nsAString type_str;
|
|
|
|
nsresult nsres;
|
|
|
|
|
2019-03-13 17:54:11 +01:00
|
|
|
target = get_default_document_target(doc);
|
|
|
|
if(!target)
|
2011-11-24 12:48:31 +01:00
|
|
|
return;
|
|
|
|
|
|
|
|
nsAString_InitDepend(&type_str, type);
|
|
|
|
nsres = nsIDOMEventTarget_RemoveEventListener(target, &type_str,
|
2012-04-05 13:57:53 +02:00
|
|
|
&listener->nsIDOMEventListener_iface, is_capture);
|
2011-11-24 12:48:31 +01:00
|
|
|
nsAString_Finish(&type_str);
|
|
|
|
nsIDOMEventTarget_Release(target);
|
|
|
|
if(NS_FAILED(nsres))
|
|
|
|
ERR("RemoveEventTarget failed: %08x\n", nsres);
|
|
|
|
}
|
|
|
|
|
2012-04-05 13:57:53 +02:00
|
|
|
void detach_nsevent(HTMLDocumentNode *doc, const WCHAR *type)
|
|
|
|
{
|
|
|
|
detach_nslistener(doc, type, &doc->nsevent_listener->htmlevent_listener, TRUE);
|
|
|
|
}
|
|
|
|
|
2009-10-27 21:09:25 +01:00
|
|
|
void release_nsevents(HTMLDocumentNode *doc)
|
|
|
|
{
|
2012-04-05 13:57:53 +02:00
|
|
|
nsDocumentEventListener *listener = doc->nsevent_listener;
|
|
|
|
|
2011-11-24 12:48:31 +01:00
|
|
|
TRACE("%p %p\n", doc, doc->nsevent_listener);
|
|
|
|
|
2012-04-05 13:57:53 +02:00
|
|
|
if(!listener)
|
|
|
|
return;
|
|
|
|
|
2020-11-24 00:49:06 +01:00
|
|
|
detach_nslistener(doc, L"blur", &listener->blur_listener, TRUE);
|
|
|
|
detach_nslistener(doc, L"focus", &listener->focus_listener, TRUE);
|
|
|
|
detach_nslistener(doc, L"keypress", &listener->keypress_listener, FALSE);
|
|
|
|
detach_nslistener(doc, L"load", &listener->load_listener, TRUE);
|
2012-04-05 13:57:53 +02:00
|
|
|
|
|
|
|
listener->doc = NULL;
|
|
|
|
release_listener(listener);
|
|
|
|
doc->nsevent_listener = NULL;
|
2009-10-27 21:09:25 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void init_nsevents(HTMLDocumentNode *doc)
|
2007-06-22 23:28:09 +02:00
|
|
|
{
|
2009-10-27 21:09:25 +01:00
|
|
|
nsDocumentEventListener *listener;
|
2007-06-22 23:28:09 +02:00
|
|
|
nsIDOMEventTarget *target;
|
|
|
|
|
2009-10-27 21:09:25 +01:00
|
|
|
listener = heap_alloc(sizeof(nsDocumentEventListener));
|
|
|
|
if(!listener)
|
2007-06-22 23:28:09 +02:00
|
|
|
return;
|
|
|
|
|
2011-11-24 12:48:31 +01:00
|
|
|
TRACE("%p %p\n", doc, listener);
|
|
|
|
|
2009-10-27 21:09:25 +01:00
|
|
|
listener->ref = 1;
|
|
|
|
listener->doc = doc;
|
|
|
|
|
|
|
|
init_listener(&listener->blur_listener, listener, &blur_vtbl);
|
|
|
|
init_listener(&listener->focus_listener, listener, &focus_vtbl);
|
|
|
|
init_listener(&listener->keypress_listener, listener, &keypress_vtbl);
|
|
|
|
init_listener(&listener->load_listener, listener, &load_vtbl);
|
|
|
|
init_listener(&listener->htmlevent_listener, listener, &htmlevent_vtbl);
|
|
|
|
|
|
|
|
doc->nsevent_listener = listener;
|
|
|
|
|
2019-03-13 17:54:11 +01:00
|
|
|
target = get_default_document_target(doc);
|
|
|
|
if(!target)
|
2007-06-22 23:28:09 +02:00
|
|
|
return;
|
|
|
|
|
2020-11-24 00:49:06 +01:00
|
|
|
init_event(target, L"blur", &listener->blur_listener.nsIDOMEventListener_iface, TRUE);
|
|
|
|
init_event(target, L"focus", &listener->focus_listener.nsIDOMEventListener_iface, TRUE);
|
|
|
|
init_event(target, L"keypress", &listener->keypress_listener.nsIDOMEventListener_iface, FALSE);
|
|
|
|
init_event(target, L"load", &listener->load_listener.nsIDOMEventListener_iface, TRUE);
|
2007-06-22 23:28:09 +02:00
|
|
|
|
|
|
|
nsIDOMEventTarget_Release(target);
|
|
|
|
}
|