From a68e77d6133bbe60e1d4e6c3e683af549b989bd3 Mon Sep 17 00:00:00 2001 From: Jacek Caban Date: Tue, 24 Jul 2012 15:55:41 +0200 Subject: [PATCH] mshtml: Use proper document node for createElement called on document fragment. --- dlls/mshtml/htmldoc.c | 10 ++++++++-- dlls/mshtml/tests/dom.c | 10 +++++++++- 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/dlls/mshtml/htmldoc.c b/dlls/mshtml/htmldoc.c index f9e11ce9b5b..57d0b315113 100644 --- a/dlls/mshtml/htmldoc.c +++ b/dlls/mshtml/htmldoc.c @@ -1022,17 +1022,23 @@ static HRESULT WINAPI HTMLDocument_createElement(IHTMLDocument2 *iface, BSTR eTa IHTMLElement **newElem) { HTMLDocument *This = impl_from_IHTMLDocument2(iface); + HTMLDocumentNode *doc_node; nsIDOMHTMLElement *nselem; HTMLElement *elem; HRESULT hres; TRACE("(%p)->(%s %p)\n", This, debugstr_w(eTag), newElem); - hres = create_nselem(This->doc_node, eTag, &nselem); + /* Use owner doc if called on document fragment */ + doc_node = This->doc_node; + if(!doc_node->nsdoc) + doc_node = doc_node->node.doc; + + hres = create_nselem(doc_node, eTag, &nselem); if(FAILED(hres)) return hres; - hres = HTMLElement_Create(This->doc_node, (nsIDOMNode*)nselem, TRUE, &elem); + hres = HTMLElement_Create(doc_node, (nsIDOMNode*)nselem, TRUE, &elem); nsIDOMHTMLElement_Release(nselem); if(FAILED(hres)) return hres; diff --git a/dlls/mshtml/tests/dom.c b/dlls/mshtml/tests/dom.c index 8907a988599..1a1732f549e 100644 --- a/dlls/mshtml/tests/dom.c +++ b/dlls/mshtml/tests/dom.c @@ -6246,10 +6246,10 @@ static IHTMLDocument2 *create_docfrag(IHTMLDocument2 *doc) static void test_docfrag(IHTMLDocument2 *doc) { + IHTMLDocument2 *frag, *owner_doc, *doc_node; IHTMLElement *div, *body, *br; IHTMLElementCollection *col; IHTMLLocation *location; - IHTMLDocument2 *frag; HRESULT hres; static const elem_type_t all_types[] = { @@ -6288,6 +6288,14 @@ static void test_docfrag(IHTMLDocument2 *doc) test_elem_collection((IUnknown*)col, all_types, sizeof(all_types)/sizeof(all_types[0])); IHTMLElementCollection_Release(col); + div = test_create_elem(frag, "div"); + owner_doc = get_owner_doc((IUnknown*)div); + doc_node = get_doc_node(doc); + ok(iface_cmp((IUnknown*)owner_doc, (IUnknown*)doc_node), "owner_doc != doc_node\n"); + IHTMLDocument2_Release(doc_node); + IHTMLDocument2_Release(owner_doc); + IHTMLElement_Release(div); + IHTMLDocument2_Release(frag); }