From 5cdb4a273eefaa3c77e41e2875d7a759e8892d10 Mon Sep 17 00:00:00 2001 From: Jacek Caban Date: Tue, 1 Oct 2013 15:43:52 +0200 Subject: [PATCH] mshtml: Added support for 'document' and 'window' script for attribute values. --- dlls/mshtml/htmlevent.c | 6 +++--- dlls/mshtml/htmlevent.h | 2 +- dlls/mshtml/script.c | 46 +++++++++++++++++++++++++++++-------------- dlls/mshtml/tests/events.html | 8 +++++++- 4 files changed, 42 insertions(+), 20 deletions(-) diff --git a/dlls/mshtml/htmlevent.c b/dlls/mshtml/htmlevent.c index a7b2969e98c..a564907d774 100644 --- a/dlls/mshtml/htmlevent.c +++ b/dlls/mshtml/htmlevent.c @@ -1510,11 +1510,11 @@ HRESULT detach_event(event_target_t *event_target, HTMLDocument *doc, BSTR name, return S_OK; } -void bind_elem_event(HTMLDocumentNode *doc, HTMLElement *elem, const WCHAR *event, IDispatch *disp) +void bind_node_event(HTMLDocumentNode *doc, event_target_t **event_target, HTMLDOMNode *node, const WCHAR *event, IDispatch *disp) { eventid_t eid; - TRACE("(%p %p %s %p)\n", doc, elem, debugstr_w(event), disp); + TRACE("(%p %p %p %s %p)\n", doc, event_target, node, debugstr_w(event), disp); eid = attr_to_eid(event); if(eid == EVENTID_LAST) { @@ -1522,7 +1522,7 @@ void bind_elem_event(HTMLDocumentNode *doc, HTMLElement *elem, const WCHAR *even return; } - set_event_handler_disp(&elem->node.event_target, elem->node.nsnode, doc, eid, disp); + set_event_handler_disp(event_target, node ? node->nsnode : NULL, doc, eid, disp); } void update_cp_events(HTMLInnerWindow *window, event_target_t **event_target_ptr, cp_static_data_t *cp, nsIDOMNode *nsnode) diff --git a/dlls/mshtml/htmlevent.h b/dlls/mshtml/htmlevent.h index ca39038c13c..abd19c26e57 100644 --- a/dlls/mshtml/htmlevent.h +++ b/dlls/mshtml/htmlevent.h @@ -62,7 +62,7 @@ void update_cp_events(HTMLInnerWindow*,event_target_t**,cp_static_data_t*,nsIDOM HRESULT doc_init_events(HTMLDocumentNode*) DECLSPEC_HIDDEN; void detach_events(HTMLDocumentNode *doc) DECLSPEC_HIDDEN; HRESULT create_event_obj(IHTMLEventObj**) DECLSPEC_HIDDEN; -void bind_elem_event(HTMLDocumentNode*,HTMLElement*,const WCHAR*,IDispatch*) DECLSPEC_HIDDEN; +void bind_node_event(HTMLDocumentNode*,event_target_t**,HTMLDOMNode*,const WCHAR*,IDispatch*) DECLSPEC_HIDDEN; void init_nsevents(HTMLDocumentNode*) DECLSPEC_HIDDEN; void release_nsevents(HTMLDocumentNode*) DECLSPEC_HIDDEN; diff --git a/dlls/mshtml/script.c b/dlls/mshtml/script.c index 3174bd289f0..8a745543bc5 100644 --- a/dlls/mshtml/script.c +++ b/dlls/mshtml/script.c @@ -1046,11 +1046,12 @@ IDispatch *get_script_disp(ScriptHost *script_host) return disp; } -static HTMLElement *find_event_target(HTMLDocumentNode *doc, HTMLScriptElement *script_elem) +static event_target_t **find_event_target(HTMLDocumentNode *doc, HTMLScriptElement *script_elem, HTMLDOMNode **ret_target_node) { + HTMLDOMNode *target_node = NULL; + event_target_t **target = NULL; const PRUnichar *target_id; nsAString target_id_str; - HTMLElement *elem; nsresult nsres; HRESULT hres; @@ -1063,17 +1064,27 @@ static HTMLElement *find_event_target(HTMLDocumentNode *doc, HTMLScriptElement * } nsAString_GetData(&target_id_str, &target_id); - if(!*target_id || !strcmpW(target_id, documentW) || !strcmpW(target_id, windowW)) { - FIXME("for %s not supported\n", debugstr_w(target_id)); - elem = NULL; + if(!*target_id) { + FIXME("Empty for attribute\n"); + }else if(!strcmpW(target_id, documentW)) { + target = &doc->node.event_target; + target_node = &doc->node; + IHTMLDOMNode_AddRef(&target_node->IHTMLDOMNode_iface); + }else if(!strcmpW(target_id, windowW)) { + target = &doc->body_event_target; }else { - hres = get_doc_elem_by_id(doc, target_id, &elem); - if(FAILED(hres)) - elem = NULL; + HTMLElement *target_elem; + + hres = get_doc_elem_by_id(doc, target_id, &target_elem); + if(SUCCEEDED(hres) && target_elem) { + target_node = &target_elem->node; + target = &target_elem->node.event_target; + } } nsAString_Finish(&target_id_str); - return elem; + *ret_target_node = target_node; + return target; } static BOOL parse_event_str(WCHAR *event, const WCHAR **args) @@ -1168,8 +1179,9 @@ void bind_event_scripts(HTMLDocumentNode *doc) HTMLPluginContainer *plugin_container; nsIDOMHTMLScriptElement *nsscript; HTMLScriptElement *script_elem; - HTMLElement *event_target; + event_target_t **event_target; nsIDOMNodeList *node_list; + HTMLDOMNode *target_node; nsIDOMNode *script_node; nsAString selector_str; IDispatch *event_disp; @@ -1216,17 +1228,21 @@ void bind_event_scripts(HTMLDocumentNode *doc) event_disp = parse_event_elem(doc, script_elem, &event); if(event_disp) { - event_target = find_event_target(doc, script_elem); + event_target = find_event_target(doc, script_elem, &target_node); if(event_target) { - hres = IHTMLElement_QueryInterface(&event_target->IHTMLElement_iface, &IID_HTMLPluginContainer, - (void**)&plugin_container); + if(target_node) + hres = IHTMLDOMNode_QueryInterface(&target_node->IHTMLDOMNode_iface, &IID_HTMLPluginContainer, + (void**)&plugin_container); + else + hres = E_NOINTERFACE; if(SUCCEEDED(hres)) bind_activex_event(doc, plugin_container, event, event_disp); else - bind_elem_event(doc, event_target, event, event_disp); + bind_node_event(doc, event_target, target_node, event, event_disp); - IHTMLElement_Release(&event_target->IHTMLElement_iface); + if(target_node) + IHTMLDOMNode_Release(&target_node->IHTMLDOMNode_iface); } heap_free(event); diff --git a/dlls/mshtml/tests/events.html b/dlls/mshtml/tests/events.html index 131ba19cfda..bf8a21f8bd8 100644 --- a/dlls/mshtml/tests/events.html +++ b/dlls/mshtml/tests/events.html @@ -1,7 +1,7 @@ + -- 2.11.4.GIT