From e4a936a2d2f81d027945c787861e786578300928 Mon Sep 17 00:00:00 2001 From: Jacek Caban Date: Mon, 4 Jan 2010 00:39:31 +0100 Subject: [PATCH] mshtml: Store body event target in HTMLDocumentNode. --- dlls/mshtml/htmlbody.c | 4 ++-- dlls/mshtml/htmldoc.c | 2 ++ dlls/mshtml/htmlevent.c | 2 +- dlls/mshtml/htmlevent.h | 10 ---------- dlls/mshtml/htmlwindow.c | 29 ++++++++++++++++++++++++++--- dlls/mshtml/mshtml_private.h | 2 +- 6 files changed, 32 insertions(+), 17 deletions(-) diff --git a/dlls/mshtml/htmlbody.c b/dlls/mshtml/htmlbody.c index 1aa73139723..7f22a4e06a6 100644 --- a/dlls/mshtml/htmlbody.c +++ b/dlls/mshtml/htmlbody.c @@ -783,8 +783,8 @@ static event_target_t **HTMLBodyElement_get_event_target(HTMLDOMNode *iface) { HTMLBodyElement *This = HTMLBODY_NODE_THIS(iface); - return This->textcont.element.node.doc && This->textcont.element.node.doc->basedoc.window - ? &This->textcont.element.node.doc->basedoc.window->event_target + return This->textcont.element.node.doc + ? &This->textcont.element.node.doc->body_event_target : &This->textcont.element.node.event_target; } diff --git a/dlls/mshtml/htmldoc.c b/dlls/mshtml/htmldoc.c index 54d3ca309e2..ac67a84cc60 100644 --- a/dlls/mshtml/htmldoc.c +++ b/dlls/mshtml/htmldoc.c @@ -1842,6 +1842,8 @@ static void HTMLDocumentNode_destructor(HTMLDOMNode *iface) { HTMLDocumentNode *This = HTMLDOCNODE_NODE_THIS(iface); + if(This->body_event_target) + release_event_target(This->body_event_target); if(This->nsevent_listener) release_nsevents(This); if(This->catmgr) diff --git a/dlls/mshtml/htmlevent.c b/dlls/mshtml/htmlevent.c index 2e2f1c95fba..d04b2e66370 100644 --- a/dlls/mshtml/htmlevent.c +++ b/dlls/mshtml/htmlevent.c @@ -934,7 +934,7 @@ void fire_event(HTMLDocumentNode *doc, eventid_t eid, nsIDOMNode *target, nsIDOM } } - call_event_handlers(doc, event_obj, doc->basedoc.doc_node->node.event_target, &doc->basedoc.cp_container, eid, + call_event_handlers(doc, event_obj, doc->node.event_target, &doc->basedoc.cp_container, eid, (IDispatch*)HTMLDOC(&doc->basedoc)); break; diff --git a/dlls/mshtml/htmlevent.h b/dlls/mshtml/htmlevent.h index a0fb198189c..1a8572f951e 100644 --- a/dlls/mshtml/htmlevent.h +++ b/dlls/mshtml/htmlevent.h @@ -74,13 +74,3 @@ static inline HRESULT get_doc_event(HTMLDocument *doc, eventid_t eid, VARIANT *v { return get_node_event(&doc->doc_node->node, eid, var); } - -static inline HRESULT set_window_event(HTMLWindow *window, eventid_t eid, VARIANT *var) -{ - return set_event_handler(&window->event_target, window->doc, eid, var); -} - -static inline HRESULT get_window_event(HTMLWindow *window, eventid_t eid, VARIANT *var) -{ - return get_event_handler(&window->event_target, eid, var); -} diff --git a/dlls/mshtml/htmlwindow.c b/dlls/mshtml/htmlwindow.c index 6db314883bd..4a2babee06d 100644 --- a/dlls/mshtml/htmlwindow.c +++ b/dlls/mshtml/htmlwindow.c @@ -117,6 +117,26 @@ static HRESULT get_location(HTMLWindow *This, HTMLLocation **ret) return S_OK; } +static inline HRESULT set_window_event(HTMLWindow *window, eventid_t eid, VARIANT *var) +{ + if(!window->doc) { + FIXME("No document\n"); + return E_FAIL; + } + + return set_event_handler(&window->doc->body_event_target, window->doc, eid, var); +} + +static inline HRESULT get_window_event(HTMLWindow *window, eventid_t eid, VARIANT *var) +{ + if(!window->doc) { + FIXME("No document\n"); + return E_FAIL; + } + + return get_event_handler(&window->doc->body_event_target, eid, var); +} + #define HTMLWINDOW2_THIS(iface) DEFINE_THIS(HTMLWindow, HTMLWindow2, iface) static HRESULT WINAPI HTMLWindow2_QueryInterface(IHTMLWindow2 *iface, REFIID riid, void **ppv) @@ -206,8 +226,6 @@ static ULONG WINAPI HTMLWindow2_Release(IHTMLWindow2 *iface) if(This->screen) IHTMLScreen_Release(This->screen); - if(This->event_target) - release_event_target(This->event_target); for(i=0; i < This->global_prop_cnt; i++) heap_free(This->global_props[i].name); @@ -1391,7 +1409,12 @@ static HRESULT WINAPI HTMLWindow3_attachEvent(IHTMLWindow3 *iface, BSTR event, I TRACE("(%p)->(%s %p %p)\n", This, debugstr_w(event), pDisp, pfResult); - return attach_event(&This->event_target, &This->doc_obj->basedoc, event, pDisp, pfResult); + if(!This->doc) { + FIXME("No document\n"); + return E_FAIL; + } + + return attach_event(&This->doc->body_event_target, &This->doc->basedoc, event, pDisp, pfResult); } static HRESULT WINAPI HTMLWindow3_detachEvent(IHTMLWindow3 *iface, BSTR event, IDispatch *pDisp) diff --git a/dlls/mshtml/mshtml_private.h b/dlls/mshtml/mshtml_private.h index 491bc2aa527..68b3393d868 100644 --- a/dlls/mshtml/mshtml_private.h +++ b/dlls/mshtml/mshtml_private.h @@ -242,7 +242,6 @@ struct HTMLWindow { IMoniker *mon; LPOLESTR url; - event_target_t *event_target; IHTMLEventObj *event; SCRIPTMODE scriptmode; @@ -531,6 +530,7 @@ struct HTMLDocumentNode { nsIDOMHTMLDocument *nsdoc; HTMLDOMNode *nodes; BOOL content_ready; + event_target_t *body_event_target; IInternetSecurityManager *secmgr; ICatInformation *catmgr;