From: Santino Mazza smazza@codeweavers.com
--- dlls/mshtml/htmldoc.c | 47 +++++++++++++++++++++++++++++++++++++++++ dlls/mshtml/tests/dom.c | 2 +- 2 files changed, 48 insertions(+), 1 deletion(-)
diff --git a/dlls/mshtml/htmldoc.c b/dlls/mshtml/htmldoc.c index ac471e9e1a8..cc6c6ff4338 100644 --- a/dlls/mshtml/htmldoc.c +++ b/dlls/mshtml/htmldoc.c @@ -520,6 +520,51 @@ static HRESULT WINAPI HTMLDocument_get_all(IHTMLDocument2 *iface, IHTMLElementCo return hres; }
+static void get_next_node(nsIDOMNode **node) +{ + HRESULT hres; + nsIDOMNode *parent_node, *tmp_node = NULL; + + hres = nsIDOMNode_GetFirstChild(*node, &tmp_node); + if(hres != S_OK) return; + + while(!tmp_node && (nsIDOMNode_GetNextSibling(*node, &tmp_node) == S_OK) && !tmp_node) { + if((nsIDOMNode_GetParentNode(*node, &parent_node) != S_OK) || !parent_node) + break; + + nsIDOMNode_Release(*node); + *node = parent_node; + } + + nsIDOMNode_Release(*node); + *node = tmp_node; +} + +static HRESULT search_body_element_in_node(nsIDOMNode *node, nsIDOMHTMLElement **body) +{ + nsAString nsnode_name; + const PRUnichar *node_name; + + *body = NULL; + nsIDOMNode_AddRef(node); + + for(nsIDOMNode *current_node = node; current_node; get_next_node(¤t_node)) { + nsAString_Init(&nsnode_name, NULL); + nsIDOMNode_GetNodeName(current_node, &nsnode_name); + nsAString_GetData(&nsnode_name, &node_name); + nsAString_Finish(&nsnode_name); + + if(!wcscmp(node_name, L"BODY")) { + nsIDOMNode_QueryInterface(current_node, &IID_nsIDOMHTMLElement, (void **)body); + nsIDOMNode_Release(current_node); + } + + free((void*)node_name); + if(*body) break; + } + return S_OK; +} + static HRESULT WINAPI HTMLDocument_get_body(IHTMLDocument2 *iface, IHTMLElement **p) { HTMLDocumentNode *This = impl_from_IHTMLDocument2(iface); @@ -538,6 +583,8 @@ static HRESULT WINAPI HTMLDocument_get_body(IHTMLDocument2 *iface, IHTMLElement return E_UNEXPECTED; } } + else if(This->node.nsnode) + search_body_element_in_node(This->node.nsnode, &nsbody);
if(!nsbody) { *p = NULL; diff --git a/dlls/mshtml/tests/dom.c b/dlls/mshtml/tests/dom.c index a726801a43e..eea3dbe7126 100644 --- a/dlls/mshtml/tests/dom.c +++ b/dlls/mshtml/tests/dom.c @@ -11063,7 +11063,7 @@ static void test_docfrag(IHTMLDocument2 *doc)
hres = IHTMLDocument2_get_body(frag, &body); ok(hres == S_OK, "get_body failed: %08lx\n", hres); - todo_wine ok(body != NULL, "body == NULL\n"); + ok(body != NULL, "body == NULL\n"); if (body) IHTMLElement_Release(body);