mshtml: Move event handlers invocation to separated function.

This commit is contained in:
Jacek Caban 2009-09-06 18:54:30 +02:00 committed by Alexandre Julliard
parent 872a89436d
commit 50ab5620e8
3 changed files with 35 additions and 20 deletions

View File

@ -318,11 +318,8 @@ static dispex_data_t *get_dispex_data(DispatchEx *This)
return This->data->data;
}
void call_disp_func(HTMLDocument *doc, IDispatch *disp, IDispatch *this_obj)
HRESULT call_disp_func(IDispatch *disp, DISPPARAMS *dp)
{
DISPID named_arg = DISPID_THIS;
VARIANTARG arg;
DISPPARAMS params = {&arg, &named_arg, 1, 1};
EXCEPINFO ei;
IDispatchEx *dispex;
VARIANT res;
@ -331,20 +328,17 @@ void call_disp_func(HTMLDocument *doc, IDispatch *disp, IDispatch *this_obj)
hres = IDispatch_QueryInterface(disp, &IID_IDispatchEx, (void**)&dispex);
if(FAILED(hres)) {
FIXME("Could not get IDispatchEx interface: %08x\n", hres);
return;
return hres;
}
V_VT(&arg) = VT_DISPATCH;
V_DISPATCH(&arg) = this_obj;
VariantInit(&res);
memset(&ei, 0, sizeof(ei));
hres = IDispatchEx_InvokeEx(dispex, 0, GetUserDefaultLCID(), DISPATCH_METHOD, &params, &res, &ei, NULL);
hres = IDispatchEx_InvokeEx(dispex, 0, GetUserDefaultLCID(), DISPATCH_METHOD, dp, &res, &ei, NULL);
IDispatchEx_Release(dispex);
TRACE("%p returned %08x\n", disp, hres);
VariantClear(&res);
return hres;
}
static inline BOOL is_custom_dispid(DISPID id)

View File

@ -460,6 +460,31 @@ static IHTMLEventObj *create_event(HTMLDOMNode *target)
return HTMLEVENTOBJ(ret);
}
static void call_event_handlers(HTMLDocument *doc, event_target_t *event_target,
eventid_t eid, IDispatch *this_obj)
{
HRESULT hres;
if(!event_target || !event_target->event_table[eid])
return;
if(event_target->event_table[eid]) {
DISPID named_arg = DISPID_THIS;
VARIANTARG arg;
DISPPARAMS dp = {&arg, &named_arg, 1, 1};
V_VT(&arg) = VT_DISPATCH;
V_DISPATCH(&arg) = this_obj;
TRACE("%s >>>\n", debugstr_w(event_info[eid].name));
hres = call_disp_func(event_target->event_table[eid], &dp);
if(hres == S_OK)
TRACE("%s <<<\n", debugstr_w(event_info[eid].name));
else
WARN("%s <<< %08x\n", debugstr_w(event_info[eid].name), hres);
}
}
void fire_event(HTMLDocument *doc, eventid_t eid, nsIDOMNode *target)
{
IHTMLEventObj *prev_event, *event_obj = NULL;
@ -480,13 +505,11 @@ void fire_event(HTMLDocument *doc, eventid_t eid, nsIDOMNode *target)
while(1) {
node = get_node(doc, nsnode, FALSE);
if(node && node->event_target && node->event_target->event_table[eid]) {
if(node) {
if(!event_obj)
event_obj = doc->window->event = create_event(get_node(doc, target, TRUE));
TRACE("%s >>>\n", debugstr_w(event_info[eid].name));
call_disp_func(doc, node->event_target->event_table[eid], (IDispatch*)HTMLDOMNODE(node));
TRACE("%s <<<\n", debugstr_w(event_info[eid].name));
call_event_handlers(doc, node->event_target, eid, (IDispatch*)HTMLDOMNODE(node));
}
if(!(event_info[eid].flags & EVENT_BUBBLE))
@ -506,13 +529,11 @@ void fire_event(HTMLDocument *doc, eventid_t eid, nsIDOMNode *target)
if(nsnode)
nsIDOMNode_Release(nsnode);
if((event_info[eid].flags & EVENT_BUBBLE) && doc->event_target && doc->event_target->event_table[eid]) {
if(event_info[eid].flags & EVENT_BUBBLE) {
if(!event_obj)
event_obj = doc->window->event = create_event(get_node(doc, target, TRUE));
TRACE("doc %s >>>\n", debugstr_w(event_info[eid].name));
call_disp_func(doc, doc->event_target->event_table[eid], (IDispatch*)HTMLDOC(doc));
TRACE("doc %s <<<\n", debugstr_w(event_info[eid].name));
call_event_handlers(doc, doc->event_target, eid, (IDispatch*)HTMLDOC(doc));
}
if(event_obj) {

View File

@ -692,7 +692,7 @@ DWORD set_task_timer(HTMLDocument*,DWORD,BOOL,IDispatch*);
HRESULT clear_task_timer(HTMLDocument*,BOOL,DWORD);
void release_typelib(void);
void call_disp_func(HTMLDocument*,IDispatch*,IDispatch*);
HRESULT call_disp_func(IDispatch*,DISPPARAMS*);
const char *debugstr_variant(const VARIANT*);