mshtml: Pass node as an object to fire_event.

Signed-off-by: Jacek Caban <jacek@codeweavers.com>
Signed-off-by: Alexandre Julliard <julliard@winehq.org>
This commit is contained in:
Jacek Caban 2016-04-04 13:21:58 +02:00 committed by Alexandre Julliard
parent b692aad3b6
commit 1dc502c5b4
7 changed files with 39 additions and 34 deletions

View File

@ -4112,7 +4112,7 @@ HRESULT HTMLElement_handle_event(HTMLDOMNode *iface, DWORD eid, nsIDOMEvent *eve
switch(code) { switch(code) {
case VK_F1: /* DOM_VK_F1 */ case VK_F1: /* DOM_VK_F1 */
TRACE("F1 pressed\n"); TRACE("F1 pressed\n");
fire_event(This->node.doc, EVENTID_HELP, TRUE, This->node.nsnode, NULL, NULL); fire_event(This->node.doc, EVENTID_HELP, TRUE, &This->node, NULL, NULL);
*prevent_default = TRUE; *prevent_default = TRUE;
} }

View File

@ -1085,7 +1085,7 @@ void call_event_handlers(HTMLDocumentNode *doc, HTMLEventObj *event_obj, EventTa
} }
static void fire_event_obj(HTMLDocumentNode *doc, eventid_t eid, HTMLEventObj *event_obj, static void fire_event_obj(HTMLDocumentNode *doc, eventid_t eid, HTMLEventObj *event_obj,
nsIDOMNode *target, IDispatch *script_this) HTMLDOMNode *target, IDispatch *script_this)
{ {
IHTMLEventObj *prev_event; IHTMLEventObj *prev_event;
nsIDOMNode *parent, *nsnode; nsIDOMNode *parent, *nsnode;
@ -1109,8 +1109,8 @@ static void fire_event_obj(HTMLDocumentNode *doc, eventid_t eid, HTMLEventObj *e
prev_event = window->event; prev_event = window->event;
window->event = event_obj ? &event_obj->IHTMLEventObj_iface : NULL; window->event = event_obj ? &event_obj->IHTMLEventObj_iface : NULL;
nsIDOMNode_GetNodeType(target, &node_type); nsIDOMNode_GetNodeType(target->nsnode, &node_type);
nsnode = target; nsnode = target->nsnode;
nsIDOMNode_AddRef(nsnode); nsIDOMNode_AddRef(nsnode);
switch(node_type) { switch(node_type) {
@ -1173,8 +1173,8 @@ static void fire_event_obj(HTMLDocumentNode *doc, eventid_t eid, HTMLEventObj *e
window->event = prev_event; window->event = prev_event;
if(!prevent_default && (event_info[eid].flags & EVENT_HASDEFAULTHANDLERS)) { if(!prevent_default && (event_info[eid].flags & EVENT_HASDEFAULTHANDLERS)) {
nsIDOMNode_AddRef(target); nsnode = target->nsnode;
nsnode = target; nsIDOMNode_AddRef(nsnode);
do { do {
hres = get_node(doc, nsnode, TRUE, &node); hres = get_node(doc, nsnode, TRUE, &node);
@ -1209,24 +1209,18 @@ static void fire_event_obj(HTMLDocumentNode *doc, eventid_t eid, HTMLEventObj *e
htmldoc_release(&doc->basedoc); htmldoc_release(&doc->basedoc);
} }
void fire_event(HTMLDocumentNode *doc, eventid_t eid, BOOL set_event, nsIDOMNode *target, nsIDOMEvent *nsevent, void fire_event(HTMLDocumentNode *doc, eventid_t eid, BOOL set_event, HTMLDOMNode *target, nsIDOMEvent *nsevent,
IDispatch *script_this) IDispatch *script_this)
{ {
HTMLEventObj *event_obj = NULL; HTMLEventObj *event_obj = NULL;
HTMLDOMNode *node;
HRESULT hres; HRESULT hres;
if(set_event) { if(set_event) {
hres = get_node(doc, target, TRUE, &node);
if(FAILED(hres))
return;
event_obj = create_event(); event_obj = create_event();
node_release(node);
if(!event_obj) if(!event_obj)
return; return;
hres = set_event_info(event_obj, node, eid, nsevent); hres = set_event_info(event_obj, target, eid, nsevent);
if(FAILED(hres)) { if(FAILED(hres)) {
IHTMLEventObj_Release(&event_obj->IHTMLEventObj_iface); IHTMLEventObj_Release(&event_obj->IHTMLEventObj_iface);
return; return;
@ -1278,13 +1272,13 @@ HRESULT dispatch_event(HTMLDOMNode *node, const WCHAR *event_name, VARIANT *even
if(event_obj) { if(event_obj) {
hres = set_event_info(event_obj, node, eid, NULL); hres = set_event_info(event_obj, node, eid, NULL);
if(SUCCEEDED(hres)) if(SUCCEEDED(hres))
fire_event_obj(node->doc, eid, event_obj, node->nsnode, NULL); fire_event_obj(node->doc, eid, event_obj, node, NULL);
IHTMLEventObj_Release(&event_obj->IHTMLEventObj_iface); IHTMLEventObj_Release(&event_obj->IHTMLEventObj_iface);
if(FAILED(hres)) if(FAILED(hres))
return hres; return hres;
}else { }else {
fire_event(node->doc, eid, TRUE, node->nsnode, NULL, NULL); fire_event(node->doc, eid, TRUE, node, NULL, NULL);
} }
*cancelled = VARIANT_TRUE; /* FIXME */ *cancelled = VARIANT_TRUE; /* FIXME */
@ -1303,7 +1297,7 @@ HRESULT call_fire_event(HTMLDOMNode *node, eventid_t eid)
return hres; return hres;
} }
fire_event(node->doc, eid, TRUE, node->nsnode, NULL, NULL); fire_event(node->doc, eid, TRUE, node, NULL, NULL);
return S_OK; return S_OK;
} }

View File

@ -53,7 +53,7 @@ typedef enum {
eventid_t str_to_eid(LPCWSTR) DECLSPEC_HIDDEN; eventid_t str_to_eid(LPCWSTR) DECLSPEC_HIDDEN;
void check_event_attr(HTMLDocumentNode*,nsIDOMHTMLElement*) DECLSPEC_HIDDEN; void check_event_attr(HTMLDocumentNode*,nsIDOMHTMLElement*) DECLSPEC_HIDDEN;
void release_event_target(event_target_t*) DECLSPEC_HIDDEN; void release_event_target(event_target_t*) DECLSPEC_HIDDEN;
void fire_event(HTMLDocumentNode*,eventid_t,BOOL,nsIDOMNode*,nsIDOMEvent*,IDispatch*) DECLSPEC_HIDDEN; void fire_event(HTMLDocumentNode*,eventid_t,BOOL,HTMLDOMNode*,nsIDOMEvent*,IDispatch*) DECLSPEC_HIDDEN;
HRESULT set_event_handler(EventTarget*,eventid_t,VARIANT*) DECLSPEC_HIDDEN; HRESULT set_event_handler(EventTarget*,eventid_t,VARIANT*) DECLSPEC_HIDDEN;
HRESULT get_event_handler(EventTarget*,eventid_t,VARIANT*) DECLSPEC_HIDDEN; HRESULT get_event_handler(EventTarget*,eventid_t,VARIANT*) DECLSPEC_HIDDEN;
HRESULT attach_event(EventTarget*,BSTR,IDispatch*,VARIANT_BOOL*) DECLSPEC_HIDDEN; HRESULT attach_event(EventTarget*,BSTR,IDispatch*,VARIANT_BOOL*) DECLSPEC_HIDDEN;

View File

@ -1462,13 +1462,14 @@ static nsresult NSAPI nsContextMenuListener_OnShowContextMenu(nsIContextMenuList
TRACE("(%p)->(%08x %p %p)\n", This, aContextFlags, aEvent, aNode); TRACE("(%p)->(%08x %p %p)\n", This, aContextFlags, aEvent, aNode);
fire_event(This->doc->basedoc.doc_node /* FIXME */, EVENTID_CONTEXTMENU, TRUE, aNode, aEvent, NULL); hres = get_node(This->doc->basedoc.doc_node, aNode, TRUE, &node);
if(FAILED(hres))
return NS_ERROR_FAILURE;
fire_event(This->doc->basedoc.doc_node /* FIXME */, EVENTID_CONTEXTMENU, TRUE, node, aEvent, NULL);
nsres = nsIDOMEvent_QueryInterface(aEvent, &IID_nsIDOMMouseEvent, (void**)&event); nsres = nsIDOMEvent_QueryInterface(aEvent, &IID_nsIDOMMouseEvent, (void**)&event);
if(NS_FAILED(nsres)) { assert(NS_SUCCEEDED(nsres));
ERR("Could not get nsIDOMMouseEvent interface: %08x\n", nsres);
return nsres;
}
nsIDOMMouseEvent_GetScreenX(event, &pt.x); nsIDOMMouseEvent_GetScreenX(event, &pt.x);
nsIDOMMouseEvent_GetScreenY(event, &pt.y); nsIDOMMouseEvent_GetScreenY(event, &pt.y);
@ -1506,10 +1507,6 @@ static nsresult NSAPI nsContextMenuListener_OnShowContextMenu(nsIContextMenuList
FIXME("aContextFlags=%08x\n", aContextFlags); FIXME("aContextFlags=%08x\n", aContextFlags);
}; };
hres = get_node(This->doc->basedoc.doc_node, aNode, TRUE, &node);
if(FAILED(hres))
return NS_ERROR_FAILURE;
show_context_menu(This->doc, dwID, &pt, (IDispatch*)&node->IHTMLDOMNode_iface); show_context_menu(This->doc, dwID, &pt, (IDispatch*)&node->IHTMLDOMNode_iface);
node_release(node); node_release(node);
return NS_OK; return NS_OK;

View File

@ -273,8 +273,16 @@ static nsresult NSAPI handle_load(nsIDOMEventListener *iface, nsIDOMEvent *event
nsres = nsIDOMHTMLDocument_GetBody(doc->nsdoc, &nsbody); nsres = nsIDOMHTMLDocument_GetBody(doc->nsdoc, &nsbody);
if(NS_SUCCEEDED(nsres) && nsbody) { if(NS_SUCCEEDED(nsres) && nsbody) {
fire_event(doc, EVENTID_LOAD, TRUE, (nsIDOMNode*)nsbody, event, (IDispatch*)&doc->window->base.IDispatchEx_iface); HTMLDOMNode *node;
HRESULT hres;
hres = get_node(doc, (nsIDOMNode*)nsbody, TRUE, &node);
nsIDOMHTMLElement_Release(nsbody); nsIDOMHTMLElement_Release(nsbody);
if(SUCCEEDED(hres)) {
fire_event(doc, EVENTID_LOAD, TRUE, node, event,
(IDispatch*)&doc->window->base.IDispatchEx_iface);
node_release(node);
}
} }
}else { }else {
ERR("NULL nsdoc\n"); ERR("NULL nsdoc\n");
@ -293,8 +301,10 @@ static nsresult NSAPI handle_htmlevent(nsIDOMEventListener *iface, nsIDOMEvent *
nsIDOMEventTarget *event_target; nsIDOMEventTarget *event_target;
nsIDOMNode *nsnode; nsIDOMNode *nsnode;
nsAString type_str; nsAString type_str;
HTMLDOMNode *node;
eventid_t eid; eventid_t eid;
nsresult nsres; nsresult nsres;
HRESULT hres;
TRACE("%p\n", This->This); TRACE("%p\n", This->This);
@ -322,10 +332,14 @@ static nsresult NSAPI handle_htmlevent(nsIDOMEventListener *iface, nsIDOMEvent *
return NS_OK; return NS_OK;
} }
fire_event(doc, eid, TRUE, nsnode, event, NULL); hres = get_node(doc, nsnode, TRUE, &node);
nsIDOMNode_Release(nsnode); nsIDOMNode_Release(nsnode);
if(FAILED(hres))
return NS_OK;
fire_event(doc, eid, TRUE, node, event, NULL);
node_release(node);
return NS_OK; return NS_OK;
} }

View File

@ -448,11 +448,11 @@ static void notif_readystate(HTMLOuterWindow *window)
call_property_onchanged(&window->doc_obj->basedoc.cp_container, DISPID_READYSTATE); call_property_onchanged(&window->doc_obj->basedoc.cp_container, DISPID_READYSTATE);
fire_event(window->base.inner_window->doc, EVENTID_READYSTATECHANGE, FALSE, fire_event(window->base.inner_window->doc, EVENTID_READYSTATECHANGE, FALSE,
window->base.inner_window->doc->node.nsnode, NULL, NULL); &window->base.inner_window->doc->node, NULL, NULL);
if(window->frame_element) if(window->frame_element)
fire_event(window->frame_element->element.node.doc, EVENTID_READYSTATECHANGE, fire_event(window->frame_element->element.node.doc, EVENTID_READYSTATECHANGE,
TRUE, window->frame_element->element.node.nsnode, NULL, NULL); TRUE, &window->frame_element->element.node, NULL, NULL);
} }
typedef struct { typedef struct {

View File

@ -735,7 +735,7 @@ static void fire_readystatechange_proc(task_t *_task)
return; return;
task->elem->pending_readystatechange_event = FALSE; task->elem->pending_readystatechange_event = FALSE;
fire_event(task->elem->element.node.doc, EVENTID_READYSTATECHANGE, FALSE, task->elem->element.node.nsnode, NULL, NULL); fire_event(task->elem->element.node.doc, EVENTID_READYSTATECHANGE, FALSE, &task->elem->element.node, NULL, NULL);
} }
static void fire_readystatechange_task_destr(task_t *_task) static void fire_readystatechange_task_destr(task_t *_task)
@ -771,7 +771,7 @@ static void set_script_elem_readystate(HTMLScriptElement *script_elem, READYSTAT
}else { }else {
script_elem->pending_readystatechange_event = FALSE; script_elem->pending_readystatechange_event = FALSE;
fire_event(script_elem->element.node.doc, EVENTID_READYSTATECHANGE, FALSE, fire_event(script_elem->element.node.doc, EVENTID_READYSTATECHANGE, FALSE,
script_elem->element.node.nsnode, NULL, NULL); &script_elem->element.node, NULL, NULL);
} }
} }
} }