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 "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"
|
2008-10-09 22:36:01 +02:00
|
|
|
#include "htmlevent.h"
|
2007-06-22 23:28:09 +02:00
|
|
|
|
|
|
|
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));
|
|
|
|
}
|
|
|
|
|
2007-06-22 23:33:00 +02:00
|
|
|
static BOOL is_doc_child_focus(NSContainer *This)
|
|
|
|
{
|
|
|
|
HWND hwnd;
|
|
|
|
|
|
|
|
if(!This->doc)
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
for(hwnd = GetFocus(); hwnd && hwnd != This->doc->hwnd; hwnd = GetParent(hwnd));
|
|
|
|
|
|
|
|
return hwnd == This->doc->hwnd;
|
|
|
|
}
|
|
|
|
|
|
|
|
static nsresult NSAPI handle_blur(nsIDOMEventListener *iface, nsIDOMEvent *event)
|
|
|
|
{
|
|
|
|
NSContainer *This = NSEVENTLIST_THIS(iface)->This;
|
|
|
|
|
|
|
|
TRACE("(%p)\n", This);
|
|
|
|
|
2007-11-12 01:23:47 +01:00
|
|
|
if(!This->reset_focus && This->doc && This->doc->focus && !is_doc_child_focus(This)) {
|
2007-06-22 23:33:00 +02:00
|
|
|
This->doc->focus = FALSE;
|
|
|
|
notif_focus(This->doc);
|
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
static nsresult NSAPI handle_focus(nsIDOMEventListener *iface, nsIDOMEvent *event)
|
|
|
|
{
|
|
|
|
NSContainer *This = NSEVENTLIST_THIS(iface)->This;
|
|
|
|
|
|
|
|
TRACE("(%p)\n", This);
|
|
|
|
|
2007-11-12 01:23:47 +01:00
|
|
|
if(!This->reset_focus && This->doc && !This->doc->focus) {
|
2007-06-22 23:33:00 +02:00
|
|
|
This->doc->focus = TRUE;
|
|
|
|
notif_focus(This->doc);
|
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2007-06-22 23:28:09 +02:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2007-06-22 23:28:54 +02:00
|
|
|
static nsresult NSAPI handle_load(nsIDOMEventListener *iface, nsIDOMEvent *event)
|
|
|
|
{
|
|
|
|
NSContainer *This = NSEVENTLIST_THIS(iface)->This;
|
2008-04-21 00:48:18 +02:00
|
|
|
nsIDOMHTMLElement *nsbody = NULL;
|
2007-06-22 23:28:54 +02:00
|
|
|
task_t *task;
|
|
|
|
|
|
|
|
TRACE("(%p)\n", This);
|
|
|
|
|
|
|
|
if(!This->doc)
|
|
|
|
return NS_OK;
|
|
|
|
|
2008-10-08 20:27:25 +02:00
|
|
|
update_nsdocument(This->doc);
|
2008-03-28 19:01:15 +01:00
|
|
|
connect_scripts(This->doc);
|
2007-08-15 12:40:19 +02:00
|
|
|
|
2007-06-22 23:28:54 +02:00
|
|
|
if(This->editor_controller) {
|
|
|
|
nsIController_Release(This->editor_controller);
|
|
|
|
This->editor_controller = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(This->doc->usermode == EDITMODE)
|
2007-07-25 00:06:56 +02:00
|
|
|
handle_edit_load(This->doc);
|
2007-06-22 23:28:54 +02:00
|
|
|
|
2007-12-05 21:52:31 +01:00
|
|
|
task = heap_alloc(sizeof(task_t));
|
2007-06-22 23:28:54 +02:00
|
|
|
|
|
|
|
task->doc = This->doc;
|
|
|
|
task->task_id = TASK_PARSECOMPLETE;
|
|
|
|
task->next = NULL;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* This should be done in the worker thread that parses HTML,
|
|
|
|
* but we don't have such thread (Gecko parses HTML for us).
|
|
|
|
*/
|
|
|
|
push_task(task);
|
|
|
|
|
2008-10-08 20:27:33 +02:00
|
|
|
if(!This->doc->nsdoc) {
|
|
|
|
ERR("NULL nsdoc\n");
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
2008-04-21 00:48:18 +02:00
|
|
|
|
2008-10-08 20:27:33 +02:00
|
|
|
nsIDOMHTMLDocument_GetBody(This->doc->nsdoc, &nsbody);
|
2008-04-21 00:48:18 +02:00
|
|
|
if(nsbody) {
|
|
|
|
fire_event(This->doc, EVENTID_LOAD, (nsIDOMNode*)nsbody);
|
|
|
|
nsIDOMHTMLElement_Release(nsbody);
|
|
|
|
}
|
|
|
|
|
2007-06-22 23:28:54 +02:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2008-10-15 22:22:29 +02:00
|
|
|
#define IE_MAJOR_VERSION 7
|
|
|
|
#define IE_MINOR_VERSION 0
|
|
|
|
|
|
|
|
static BOOL handle_insert_comment(HTMLDocument *doc, const PRUnichar *comment)
|
|
|
|
{
|
|
|
|
DWORD len;
|
|
|
|
int majorv = 0, minorv = 0;
|
|
|
|
const PRUnichar *ptr, *end;
|
|
|
|
nsAString nsstr;
|
|
|
|
PRUnichar *buf;
|
|
|
|
nsresult nsres;
|
|
|
|
|
|
|
|
enum {
|
|
|
|
CMP_EQ,
|
|
|
|
CMP_LT,
|
|
|
|
CMP_LTE,
|
|
|
|
CMP_GT,
|
|
|
|
CMP_GTE
|
|
|
|
} cmpt = CMP_EQ;
|
|
|
|
|
|
|
|
static const PRUnichar endifW[] = {'<','!','[','e','n','d','i','f',']'};
|
|
|
|
|
|
|
|
if(comment[0] != '[' || comment[1] != 'i' || comment[2] != 'f')
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
ptr = comment+3;
|
|
|
|
while(isspaceW(*ptr))
|
|
|
|
ptr++;
|
|
|
|
|
|
|
|
if(ptr[0] == 'l' && ptr[1] == 't') {
|
|
|
|
ptr += 2;
|
|
|
|
if(*ptr == 'e') {
|
|
|
|
cmpt = CMP_LTE;
|
|
|
|
ptr++;
|
|
|
|
}else {
|
|
|
|
cmpt = CMP_LT;
|
|
|
|
}
|
|
|
|
}else if(ptr[0] == 'g' && ptr[1] == 't') {
|
|
|
|
ptr += 2;
|
|
|
|
if(*ptr == 'e') {
|
|
|
|
cmpt = CMP_GTE;
|
|
|
|
ptr++;
|
|
|
|
}else {
|
|
|
|
cmpt = CMP_GT;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if(!isspaceW(*ptr++))
|
|
|
|
return FALSE;
|
|
|
|
while(isspaceW(*ptr))
|
|
|
|
ptr++;
|
|
|
|
|
|
|
|
if(ptr[0] != 'I' || ptr[1] != 'E')
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
ptr +=2;
|
|
|
|
if(!isspaceW(*ptr++))
|
|
|
|
return FALSE;
|
|
|
|
while(isspaceW(*ptr))
|
|
|
|
ptr++;
|
|
|
|
|
|
|
|
if(!isdigitW(*ptr))
|
|
|
|
return FALSE;
|
|
|
|
while(isdigitW(*ptr))
|
|
|
|
majorv = majorv*10 + (*ptr++ - '0');
|
|
|
|
|
|
|
|
if(*ptr == '.') {
|
|
|
|
if(!isdigitW(*ptr))
|
|
|
|
return FALSE;
|
|
|
|
while(isdigitW(*ptr))
|
|
|
|
minorv = minorv*10 + (*ptr++ - '0');
|
|
|
|
}
|
|
|
|
|
|
|
|
while(isspaceW(*ptr))
|
|
|
|
ptr++;
|
|
|
|
if(ptr[0] != ']' || ptr[1] != '>')
|
|
|
|
return FALSE;
|
|
|
|
ptr += 2;
|
|
|
|
|
|
|
|
len = strlenW(ptr);
|
|
|
|
if(len < sizeof(endifW)/sizeof(WCHAR))
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
end = ptr + len-sizeof(endifW)/sizeof(WCHAR);
|
|
|
|
if(memcmp(end, endifW, sizeof(endifW)))
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
switch(cmpt) {
|
|
|
|
case CMP_EQ:
|
|
|
|
if(majorv == IE_MAJOR_VERSION && minorv == IE_MINOR_VERSION)
|
|
|
|
break;
|
|
|
|
return FALSE;
|
|
|
|
case CMP_LT:
|
|
|
|
if(majorv > IE_MAJOR_VERSION)
|
|
|
|
break;
|
|
|
|
if(majorv == IE_MAJOR_VERSION && minorv > IE_MINOR_VERSION)
|
|
|
|
break;
|
|
|
|
return FALSE;
|
|
|
|
case CMP_LTE:
|
|
|
|
if(majorv > IE_MAJOR_VERSION)
|
|
|
|
break;
|
|
|
|
if(majorv == IE_MAJOR_VERSION && minorv >= IE_MINOR_VERSION)
|
|
|
|
break;
|
|
|
|
return FALSE;
|
|
|
|
case CMP_GT:
|
|
|
|
if(majorv < IE_MAJOR_VERSION)
|
|
|
|
break;
|
|
|
|
if(majorv == IE_MAJOR_VERSION && minorv < IE_MINOR_VERSION)
|
|
|
|
break;
|
|
|
|
return FALSE;
|
|
|
|
case CMP_GTE:
|
|
|
|
if(majorv < IE_MAJOR_VERSION)
|
|
|
|
break;
|
|
|
|
if(majorv == IE_MAJOR_VERSION && minorv <= IE_MINOR_VERSION)
|
|
|
|
break;
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
buf = heap_alloc((end-ptr+1)*sizeof(WCHAR));
|
|
|
|
if(!buf)
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
memcpy(buf, ptr, (end-ptr)*sizeof(WCHAR));
|
|
|
|
buf[end-ptr] = 0;
|
|
|
|
nsAString_Init(&nsstr, buf);
|
|
|
|
heap_free(buf);
|
|
|
|
|
|
|
|
/* FIXME: Find better way to insert HTML to document. */
|
|
|
|
nsres = nsIDOMHTMLDocument_Write(doc->nsdoc, &nsstr);
|
|
|
|
nsAString_Finish(&nsstr);
|
|
|
|
if(NS_FAILED(nsres)) {
|
|
|
|
ERR("Write failed: %08x\n", nsres);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2008-03-25 02:10:47 +01:00
|
|
|
static nsresult NSAPI handle_node_insert(nsIDOMEventListener *iface, nsIDOMEvent *event)
|
|
|
|
{
|
|
|
|
NSContainer *This = NSEVENTLIST_THIS(iface)->This;
|
|
|
|
nsIDOMEventTarget *target;
|
2008-10-15 22:22:29 +02:00
|
|
|
nsIDOMComment *nscomment;
|
2008-04-18 20:16:35 +02:00
|
|
|
nsIDOMElement *elem;
|
2008-03-25 02:10:47 +01:00
|
|
|
nsresult nsres;
|
|
|
|
|
|
|
|
TRACE("(%p %p)\n", This, event);
|
|
|
|
|
|
|
|
nsres = nsIDOMEvent_GetTarget(event, &target);
|
|
|
|
if(NS_FAILED(nsres)) {
|
|
|
|
ERR("GetTarget failed: %08x\n", nsres);
|
2008-04-18 20:16:35 +02:00
|
|
|
return NS_OK;
|
2008-03-25 02:10:47 +01:00
|
|
|
}
|
|
|
|
|
2008-04-18 20:16:35 +02:00
|
|
|
nsres = nsIDOMEventTarget_QueryInterface(target, &IID_nsIDOMElement, (void**)&elem);
|
2008-10-15 22:22:29 +02:00
|
|
|
if(NS_SUCCEEDED(nsres)) {
|
|
|
|
nsIDOMHTMLScriptElement *script;
|
|
|
|
|
|
|
|
nsres = nsIDOMElement_QueryInterface(elem, &IID_nsIDOMHTMLScriptElement, (void**)&script);
|
|
|
|
if(NS_SUCCEEDED(nsres)) {
|
|
|
|
doc_insert_script(This->doc, script);
|
|
|
|
nsIDOMHTMLScriptElement_Release(script);
|
|
|
|
}
|
2008-04-18 20:16:35 +02:00
|
|
|
|
2008-10-15 22:22:29 +02:00
|
|
|
check_event_attr(This->doc, elem);
|
|
|
|
|
|
|
|
nsIDOMEventTarget_Release(target);
|
|
|
|
nsIDOMNode_Release(elem);
|
|
|
|
return NS_OK;
|
2008-03-25 02:10:47 +01:00
|
|
|
}
|
|
|
|
|
2008-10-15 22:22:29 +02:00
|
|
|
nsres = nsIDOMEventTarget_QueryInterface(target, &IID_nsIDOMComment, (void**)&nscomment);
|
|
|
|
if(NS_SUCCEEDED(nsres)) {
|
|
|
|
nsAString comment_str;
|
|
|
|
BOOL remove_comment = FALSE;
|
|
|
|
|
|
|
|
nsAString_Init(&comment_str, NULL);
|
|
|
|
nsres = nsIDOMComment_GetData(nscomment, &comment_str);
|
|
|
|
if(NS_SUCCEEDED(nsres)) {
|
|
|
|
const PRUnichar *comment;
|
|
|
|
|
|
|
|
nsAString_GetData(&comment_str, &comment);
|
|
|
|
remove_comment = handle_insert_comment(This->doc, comment);
|
|
|
|
}
|
|
|
|
|
|
|
|
nsAString_Finish(&comment_str);
|
|
|
|
|
|
|
|
if(remove_comment) {
|
|
|
|
nsIDOMNode *nsparent, *tmp;
|
|
|
|
|
|
|
|
nsIDOMComment_GetParentNode(nscomment, &nsparent);
|
|
|
|
nsIDOMNode_RemoveChild(nsparent, (nsIDOMNode*)nscomment, &tmp);
|
|
|
|
nsIDOMNode_Release(nsparent);
|
|
|
|
nsIDOMNode_Release(tmp);
|
|
|
|
}
|
|
|
|
|
|
|
|
nsIDOMComment_Release(nscomment);
|
|
|
|
}
|
2008-04-18 20:16:35 +02:00
|
|
|
|
2008-03-25 02:10:47 +01:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2008-06-23 16:54:33 +02:00
|
|
|
static nsresult NSAPI handle_htmlevent(nsIDOMEventListener *iface, nsIDOMEvent *event)
|
|
|
|
{
|
|
|
|
NSContainer *This = NSEVENTLIST_THIS(iface)->This;
|
|
|
|
const PRUnichar *type;
|
|
|
|
nsIDOMEventTarget *event_target;
|
|
|
|
nsIDOMNode *nsnode;
|
|
|
|
nsAString type_str;
|
|
|
|
eventid_t eid;
|
|
|
|
nsresult nsres;
|
|
|
|
|
|
|
|
nsAString_Init(&type_str, NULL);
|
|
|
|
nsIDOMEvent_GetType(event, &type_str);
|
|
|
|
nsAString_GetData(&type_str, &type);
|
|
|
|
eid = str_to_eid(type);
|
|
|
|
nsAString_Finish(&type_str);
|
|
|
|
|
|
|
|
nsres = nsIDOMEvent_GetTarget(event, &event_target);
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
fire_event(This->doc, eid, nsnode);
|
|
|
|
|
|
|
|
nsIDOMNode_Release(nsnode);
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2007-06-22 23:28:09 +02:00
|
|
|
#undef NSEVENTLIST_THIS
|
|
|
|
|
|
|
|
#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-03-25 02:10:47 +01:00
|
|
|
static const nsIDOMEventListenerVtbl node_insert_vtbl = EVENTLISTENER_VTBL(handle_node_insert);
|
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;
|
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2008-06-23 16:54:33 +02:00
|
|
|
void add_nsevent_listener(NSContainer *container, LPCWSTR type)
|
|
|
|
{
|
|
|
|
nsIDOMWindow *dom_window;
|
|
|
|
nsIDOMEventTarget *target;
|
|
|
|
nsresult nsres;
|
|
|
|
|
|
|
|
nsres = nsIWebBrowser_GetContentDOMWindow(container->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, type, NSEVENTLIST(&container->htmlevent_listener), TRUE);
|
|
|
|
nsIDOMEventTarget_Release(target);
|
|
|
|
}
|
|
|
|
|
2007-06-22 23:28:09 +02:00
|
|
|
void init_nsevents(NSContainer *This)
|
|
|
|
{
|
|
|
|
nsIDOMWindow *dom_window;
|
|
|
|
nsIDOMEventTarget *target;
|
|
|
|
nsresult nsres;
|
|
|
|
|
2007-06-22 23:33:00 +02:00
|
|
|
static const PRUnichar wsz_blur[] = {'b','l','u','r',0};
|
|
|
|
static const PRUnichar wsz_focus[] = {'f','o','c','u','s',0};
|
2007-06-22 23:28:09 +02:00
|
|
|
static const PRUnichar wsz_keypress[] = {'k','e','y','p','r','e','s','s',0};
|
2007-06-22 23:28:54 +02:00
|
|
|
static const PRUnichar wsz_load[] = {'l','o','a','d',0};
|
2008-03-25 02:10:47 +01:00
|
|
|
static const PRUnichar DOMNodeInsertedW[] =
|
|
|
|
{'D','O','M','N','o','d','e','I','n','s','e','r','t','e','d',0};
|
2007-06-22 23:28:09 +02:00
|
|
|
|
2007-06-22 23:33:00 +02:00
|
|
|
init_listener(&This->blur_listener, This, &blur_vtbl);
|
|
|
|
init_listener(&This->focus_listener, This, &focus_vtbl);
|
2007-06-22 23:28:09 +02:00
|
|
|
init_listener(&This->keypress_listener, This, &keypress_vtbl);
|
2007-06-22 23:28:54 +02:00
|
|
|
init_listener(&This->load_listener, This, &load_vtbl);
|
2008-03-25 02:10:47 +01:00
|
|
|
init_listener(&This->node_insert_listener, This, &node_insert_vtbl);
|
2008-06-23 16:54:33 +02:00
|
|
|
init_listener(&This->htmlevent_listener, This, &htmlevent_vtbl);
|
2007-06-22 23:28:09 +02:00
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2007-06-22 23:33:00 +02:00
|
|
|
init_event(target, wsz_blur, NSEVENTLIST(&This->blur_listener), TRUE);
|
|
|
|
init_event(target, wsz_focus, NSEVENTLIST(&This->focus_listener), TRUE);
|
2007-06-22 23:28:09 +02:00
|
|
|
init_event(target, wsz_keypress, NSEVENTLIST(&This->keypress_listener), FALSE);
|
2007-06-22 23:28:54 +02:00
|
|
|
init_event(target, wsz_load, NSEVENTLIST(&This->load_listener), TRUE);
|
2008-03-25 02:10:47 +01:00
|
|
|
init_event(target, DOMNodeInsertedW,NSEVENTLIST(&This->node_insert_listener),TRUE);
|
2007-06-22 23:28:09 +02:00
|
|
|
|
|
|
|
nsIDOMEventTarget_Release(target);
|
|
|
|
}
|