This functions should also work with document fragments, in wine they only return NULL.
-- v6: mshtml: Implement HTMLDocument_get_body for document fragments. mshtml: Use This->node for HTMLDocument_get_all. mshtml/tests: Test for get_all and get_body in document fragments.
From: Santino Mazza smazza@codeweavers.com
--- dlls/mshtml/tests/dom.c | 72 ++++++++++++++++++++++++++++++++++++++--- 1 file changed, 68 insertions(+), 4 deletions(-)
diff --git a/dlls/mshtml/tests/dom.c b/dlls/mshtml/tests/dom.c index 6a960bfa21f..84d6b01d87f 100644 --- a/dlls/mshtml/tests/dom.c +++ b/dlls/mshtml/tests/dom.c @@ -10984,7 +10984,7 @@ static IHTMLDocument2 *create_docfrag(IHTMLDocument2 *doc) static void test_docfrag(IHTMLDocument2 *doc) { IHTMLDocument2 *frag, *owner_doc, *doc_node; - IHTMLElement *div, *body, *br; + IHTMLElement *div, *main_body, *frag_body, *br,*html; IHTMLElementCollection *col; IHTMLLocation *location; HRESULT hres; @@ -10998,20 +10998,38 @@ static void test_docfrag(IHTMLDocument2 *doc) ET_BR };
+ static const elem_type_t empty_types[] = {}; + + static const elem_type_t frag_types[] = { + ET_HTML, + ET_DIV, + ET_DIV, + ET_BODY + }; + frag = create_docfrag(doc);
test_disp((IUnknown*)frag, &DIID_DispHTMLDocument, &CLSID_HTMLDocument, L"[object]");
- body = (void*)0xdeadbeef; - hres = IHTMLDocument2_get_body(frag, &body); + frag_body = (void*)0xdeadbeef; + hres = IHTMLDocument2_get_body(frag, &frag_body); ok(hres == S_OK, "get_body failed: %08lx\n", hres); - ok(!body, "body != NULL\n"); + ok(!frag_body, "body != NULL\n");
location = (void*)0xdeadbeef; hres = IHTMLDocument2_get_location(frag, &location); ok(hres == E_UNEXPECTED, "get_location failed: %08lx\n", hres); ok(location == (void*)0xdeadbeef, "location changed\n");
+ col = NULL; + hres = IHTMLDocument2_get_all(frag, &col); + todo_wine ok(hres == S_OK, "get_all failed: %08lx\n", hres); + todo_wine ok(col != NULL, "got null elements collection\n"); + if (col) { + test_elem_collection((IUnknown *) col, empty_types, ARRAY_SIZE(empty_types)); + IHTMLElementCollection_Release(col); + } + br = test_create_elem(doc, L"BR"); test_elem_source_index(br, -1); test_node_append_child((IUnknown*)frag, (IUnknown*)br); @@ -11030,6 +11048,52 @@ static void test_docfrag(IHTMLDocument2 *doc) test_elem_collection((IUnknown*)col, all_types, ARRAY_SIZE(all_types)); IHTMLElementCollection_Release(col);
+ html = test_create_elem(doc, L"HTML"); + test_elem_source_index(html, -1); + test_node_append_child((IUnknown*)frag, (IUnknown*)html); + test_elem_source_index(html, 0); + + div = test_create_elem(doc, L"DIV"); + test_elem_source_index(div, -1); + test_node_append_child((IUnknown*)html, (IUnknown*)div); + test_elem_source_index(div, 1); + IHTMLElement_Release(div); + + div = test_create_elem(doc, L"DIV"); + test_elem_source_index(div, -1); + test_node_append_child((IUnknown*)html, (IUnknown*)div); + test_elem_source_index(div, 2); + + frag_body = test_create_elem(doc, L"BODY"); + test_elem_source_index(frag_body, -1); + test_node_append_child((IUnknown*)div, (IUnknown*)frag_body); + test_elem_source_index(frag_body, 3); + IHTMLElement_Release(frag_body); + IHTMLElement_Release(div); + IHTMLElement_Release(html); + + hres = IHTMLDocument2_get_body(doc, &main_body); + ok(hres == S_OK, "get_body failed: %08lx\n", hres); + ok(main_body != NULL, "body == NULL\n"); + + hres = IHTMLDocument2_get_body(frag, &frag_body); + ok(hres == S_OK, "get_body failed: %08lx\n", hres); + todo_wine ok(frag_body != NULL, "body == NULL\n"); + if (frag_body) { + todo_wine ok(!iface_cmp((IUnknown *) frag_body, (IUnknown *) main_body), "frag_body == main_body\n"); + IHTMLElement_Release(frag_body); + } + IHTMLElement_Release(main_body); + + col = NULL; + hres = IHTMLDocument2_get_all(frag, &col); + todo_wine ok(hres == S_OK, "get_all failed: %08lx\n", hres); + todo_wine ok(col != NULL, "got null elements collection\n"); + if (col) { + test_elem_collection((IUnknown *) col, frag_types, ARRAY_SIZE(frag_types)); + IHTMLElementCollection_Release(col); + } + div = test_create_elem(frag, L"div"); owner_doc = get_owner_doc((IUnknown*)div); doc_node = get_doc_node(doc);
From: Santino Mazza smazza@codeweavers.com
--- dlls/mshtml/htmldoc.c | 30 ++---------------------------- dlls/mshtml/tests/dom.c | 8 ++++---- 2 files changed, 6 insertions(+), 32 deletions(-)
diff --git a/dlls/mshtml/htmldoc.c b/dlls/mshtml/htmldoc.c index 90c4706abee..7b71ec1c1ae 100644 --- a/dlls/mshtml/htmldoc.c +++ b/dlls/mshtml/htmldoc.c @@ -487,37 +487,11 @@ static HRESULT WINAPI HTMLDocument_get_Script(IHTMLDocument2 *iface, IDispatch * static HRESULT WINAPI HTMLDocument_get_all(IHTMLDocument2 *iface, IHTMLElementCollection **p) { HTMLDocumentNode *This = impl_from_IHTMLDocument2(iface); - nsIDOMElement *nselem = NULL; - HTMLDOMNode *node; - nsresult nsres; - HRESULT hres;
TRACE("(%p)->(%p)\n", This, p); + *p = create_all_collection(&This->node, FALSE);
- if(!This->dom_document) { - WARN("NULL dom_document\n"); - return E_UNEXPECTED; - } - - nsres = nsIDOMDocument_GetDocumentElement(This->dom_document, &nselem); - if(NS_FAILED(nsres)) { - ERR("GetDocumentElement failed: %08lx\n", nsres); - return E_FAIL; - } - - if(!nselem) { - *p = NULL; - return S_OK; - } - - hres = get_node((nsIDOMNode*)nselem, TRUE, &node); - nsIDOMElement_Release(nselem); - if(FAILED(hres)) - return hres; - - *p = create_all_collection(node, TRUE); - node_release(node); - return hres; + return S_OK; }
static HRESULT WINAPI HTMLDocument_get_body(IHTMLDocument2 *iface, IHTMLElement **p) diff --git a/dlls/mshtml/tests/dom.c b/dlls/mshtml/tests/dom.c index 84d6b01d87f..d50148d40c2 100644 --- a/dlls/mshtml/tests/dom.c +++ b/dlls/mshtml/tests/dom.c @@ -11023,8 +11023,8 @@ static void test_docfrag(IHTMLDocument2 *doc)
col = NULL; hres = IHTMLDocument2_get_all(frag, &col); - todo_wine ok(hres == S_OK, "get_all failed: %08lx\n", hres); - todo_wine ok(col != NULL, "got null elements collection\n"); + ok(hres == S_OK, "get_all failed: %08lx\n", hres); + ok(col != NULL, "got null elements collection\n"); if (col) { test_elem_collection((IUnknown *) col, empty_types, ARRAY_SIZE(empty_types)); IHTMLElementCollection_Release(col); @@ -11087,8 +11087,8 @@ static void test_docfrag(IHTMLDocument2 *doc)
col = NULL; hres = IHTMLDocument2_get_all(frag, &col); - todo_wine ok(hres == S_OK, "get_all failed: %08lx\n", hres); - todo_wine ok(col != NULL, "got null elements collection\n"); + ok(hres == S_OK, "get_all failed: %08lx\n", hres); + ok(col != NULL, "got null elements collection\n"); if (col) { test_elem_collection((IUnknown *) col, frag_types, ARRAY_SIZE(frag_types)); IHTMLElementCollection_Release(col);
From: Santino Mazza smazza@codeweavers.com
--- dlls/mshtml/htmldoc.c | 22 ++++++++++++++++------ dlls/mshtml/tests/dom.c | 4 ++-- 2 files changed, 18 insertions(+), 8 deletions(-)
diff --git a/dlls/mshtml/htmldoc.c b/dlls/mshtml/htmldoc.c index 7b71ec1c1ae..414a39ae702 100644 --- a/dlls/mshtml/htmldoc.c +++ b/dlls/mshtml/htmldoc.c @@ -497,20 +497,30 @@ static HRESULT WINAPI HTMLDocument_get_all(IHTMLDocument2 *iface, IHTMLElementCo static HRESULT WINAPI HTMLDocument_get_body(IHTMLDocument2 *iface, IHTMLElement **p) { HTMLDocumentNode *This = impl_from_IHTMLDocument2(iface); - nsIDOMHTMLElement *nsbody = NULL; + nsIDOMElement *nsbody = NULL; HTMLElement *element; + nsresult nsres; HRESULT hres;
TRACE("(%p)->(%p)\n", This, p);
if(This->html_document) { - nsresult nsres; - - nsres = nsIDOMHTMLDocument_GetBody(This->html_document, &nsbody); + nsres = nsIDOMHTMLDocument_GetBody(This->html_document, (nsIDOMHTMLElement **)&nsbody); if(NS_FAILED(nsres)) { TRACE("Could not get body: %08lx\n", nsres); return E_UNEXPECTED; } + }else { + nsAString nsnode_name; + nsIDOMDocumentFragment *frag; + + nsres = nsIDOMNode_QueryInterface(This->node.nsnode, &IID_nsIDOMDocumentFragment, (void**)&frag); + if(!NS_FAILED(nsres)) { + nsAString_InitDepend(&nsnode_name, L"BODY"); + nsIDOMDocumentFragment_QuerySelector(frag, &nsnode_name, &nsbody); + nsAString_Finish(&nsnode_name); + nsIDOMDocumentFragment_Release(frag); + } }
if(!nsbody) { @@ -518,8 +528,8 @@ static HRESULT WINAPI HTMLDocument_get_body(IHTMLDocument2 *iface, IHTMLElement return S_OK; }
- hres = get_element((nsIDOMElement*)nsbody, &element); - nsIDOMHTMLElement_Release(nsbody); + hres = get_element(nsbody, &element); + nsIDOMElement_Release(nsbody); if(FAILED(hres)) return hres;
diff --git a/dlls/mshtml/tests/dom.c b/dlls/mshtml/tests/dom.c index d50148d40c2..af3038205b7 100644 --- a/dlls/mshtml/tests/dom.c +++ b/dlls/mshtml/tests/dom.c @@ -11078,9 +11078,9 @@ static void test_docfrag(IHTMLDocument2 *doc)
hres = IHTMLDocument2_get_body(frag, &frag_body); ok(hres == S_OK, "get_body failed: %08lx\n", hres); - todo_wine ok(frag_body != NULL, "body == NULL\n"); + ok(frag_body != NULL, "body == NULL\n"); if (frag_body) { - todo_wine ok(!iface_cmp((IUnknown *) frag_body, (IUnknown *) main_body), "frag_body == main_body\n"); + ok(!iface_cmp((IUnknown *) frag_body, (IUnknown *) main_body), "frag_body == main_body\n"); IHTMLElement_Release(frag_body); } IHTMLElement_Release(main_body);
On Tue Jan 10 16:55:00 2023 +0000, Santino Mazza wrote:
changed this line in [version 6 of the diff](/wine/wine/-/merge_requests/1918/diffs?diff_id=26972&start_sha=ac153b793cb39e97220fcce5877a4ac89a59d536#de52190fefc7d08534f3a8d527401e2e34decdeb_557_531)
woops fixed
This merge request was approved by Jacek Caban.