From f84d1f0aac98fce5746fb550b9397fbd16fa202d Mon Sep 17 00:00:00 2001 From: Jacek Caban Date: Thu, 24 Aug 2017 12:29:09 +0200 Subject: [PATCH] mshtml: Added IHTMLDocument6::getElementById implementation. Signed-off-by: Jacek Caban Signed-off-by: Alexandre Julliard --- dlls/mshtml/htmldoc.c | 40 ++++++++++++++++++++++++++++++++++++++-- dlls/mshtml/tests/dom.c | 24 ++++++++++++++++++++++++ 2 files changed, 62 insertions(+), 2 deletions(-) diff --git a/dlls/mshtml/htmldoc.c b/dlls/mshtml/htmldoc.c index a8d104e4f4d..8d48e1896b8 100644 --- a/dlls/mshtml/htmldoc.c +++ b/dlls/mshtml/htmldoc.c @@ -3142,8 +3142,44 @@ static HRESULT WINAPI HTMLDocument6_getElementById(IHTMLDocument6 *iface, BSTR bstrId, IHTMLElement2 **p) { HTMLDocument *This = impl_from_IHTMLDocument6(iface); - FIXME("(%p)->(%s %p)\n", This, debugstr_w(bstrId), p); - return E_NOTIMPL; + nsIDOMElement *nselem; + HTMLElement *elem; + nsAString nsstr; + nsresult nsres; + HRESULT hres; + + TRACE("(%p)->(%s %p)\n", This, debugstr_w(bstrId), p); + + /* + * Unlike IHTMLDocument3 implementation, this is standard compliant and does + * not search for name attributes, so we may simply let Gecko do the right thing. + */ + + if(!This->doc_node->nsdoc) { + FIXME("Not a document\n"); + return E_FAIL; + } + + nsAString_InitDepend(&nsstr, bstrId); + nsres = nsIDOMHTMLDocument_GetElementById(This->doc_node->nsdoc, &nsstr, &nselem); + nsAString_Finish(&nsstr); + if(NS_FAILED(nsres)) { + ERR("GetElementById failed: %08x\n", nsres); + return E_FAIL; + } + + if(!nselem) { + *p = NULL; + return S_OK; + } + + hres = get_elem(This->doc_node, nselem, &elem); + nsIDOMElement_Release(nselem); + if(FAILED(hres)) + return hres; + + *p = &elem->IHTMLElement2_iface; + return S_OK; } static HRESULT WINAPI HTMLDocument6_updateSettings(IHTMLDocument6 *iface) diff --git a/dlls/mshtml/tests/dom.c b/dlls/mshtml/tests/dom.c index c6053a6f898..a3a3bfe189e 100644 --- a/dlls/mshtml/tests/dom.c +++ b/dlls/mshtml/tests/dom.c @@ -9857,6 +9857,7 @@ static void test_frameset(IHTMLDocument2 *doc) { IHTMLWindow2 *window; IHTMLFramesCollection2 *frames; + IHTMLDocument6 *doc6; IHTMLElement *elem; HRESULT hres; @@ -9887,6 +9888,29 @@ static void test_frameset(IHTMLDocument2 *doc) elem = get_doc_elem_by_id(doc, "nm1"); test_elem_id((IUnknown*)elem, "fr1"); + hres = IHTMLDocument2_QueryInterface(doc, &IID_IHTMLDocument6, (void**)&doc6); + if(SUCCEEDED(hres)) { + IHTMLElement2 *elem2; + BSTR str; + + str = a2bstr("nm1"); + hres = IHTMLDocument6_getElementById(doc6, str, &elem2); + ok(hres == S_OK, "getElementById failed: %08x\n", hres); + ok(!elem2, "elem = %p\n", elem2); + SysFreeString(str); + + str = a2bstr("fr1"); + hres = IHTMLDocument6_getElementById(doc6, str, &elem2); + ok(hres == S_OK, "getElementById failed: %08x\n", hres); + ok(elem2 != NULL, "elem2 is NULL\n"); + test_elem_id((IUnknown*)elem2, "fr1"); + SysFreeString(str); + + IHTMLDocument6_Release(doc6); + }else { + win_skip("IHTMLDocument6 not supported\n"); + } + test_framebase((IUnknown*)elem); test_framebase_name(elem, "nm1"); test_framebase_put_name(elem, "frame name"); -- 2.11.4.GIT