From c3d8d052f6f5e0163aa0853cedb19905db507a30 Mon Sep 17 00:00:00 2001 From: Jacek Caban Date: Mon, 23 Jun 2008 20:03:43 -0500 Subject: [PATCH] mshtml: Added IHTMLDOMNode::removeChild implementation. --- dlls/mshtml/htmlnode.c | 22 +++++++++++++++-- dlls/mshtml/tests/dom.c | 53 ++++++++++++++++++++++++++++------------- 2 files changed, 57 insertions(+), 18 deletions(-) diff --git a/dlls/mshtml/htmlnode.c b/dlls/mshtml/htmlnode.c index 056e38adc17..9b667a1fc8d 100644 --- a/dlls/mshtml/htmlnode.c +++ b/dlls/mshtml/htmlnode.c @@ -436,8 +436,26 @@ static HRESULT WINAPI HTMLDOMNode_removeChild(IHTMLDOMNode *iface, IHTMLDOMNode IHTMLDOMNode **node) { HTMLDOMNode *This = HTMLDOMNODE_THIS(iface); - FIXME("(%p)->(%p %p)\n", This, oldChild, node); - return E_NOTIMPL; + HTMLDOMNode *node_obj; + nsIDOMNode *nsnode; + nsresult nsres; + + TRACE("(%p)->(%p %p)\n", This, oldChild, node); + + node_obj = get_node_obj(This->doc, (IUnknown*)oldChild); + if(!node_obj) + return E_FAIL; + + nsres = nsIDOMNode_RemoveChild(This->nsnode, node_obj->nsnode, &nsnode); + if(NS_FAILED(nsres)) { + ERR("RemoveChild failed: %08x\n", nsres); + return E_FAIL; + } + + /* FIXME: Make sure that node != newChild */ + *node = HTMLDOMNODE(get_node(This->doc, nsnode, TRUE)); + IHTMLDOMNode_AddRef(*node); + return S_OK; } static HRESULT WINAPI HTMLDOMNode_replaceChild(IHTMLDOMNode *iface, IHTMLDOMNode *newChild, diff --git a/dlls/mshtml/tests/dom.c b/dlls/mshtml/tests/dom.c index 4da9110837b..9910ce6893e 100644 --- a/dlls/mshtml/tests/dom.c +++ b/dlls/mshtml/tests/dom.c @@ -769,15 +769,19 @@ static void _test_range_parent(unsigned line, IHTMLTxtRange *range, elem_type_t } #define test_elem_collection(c,t,l) _test_elem_collection(__LINE__,c,t,l) -static void _test_elem_collection(unsigned line, IHTMLElementCollection *col, +static void _test_elem_collection(unsigned line, IUnknown *unk, const elem_type_t *elem_types, long exlen) { + IHTMLElementCollection *col; long len; DWORD i; VARIANT name, index; IDispatch *disp; HRESULT hres; + hres = IUnknown_QueryInterface(unk, &IID_IHTMLElementCollection, (void**)&col); + ok(hres == S_OK, "Could not get IHTMLElementCollection: %08x\n", hres); + test_disp((IUnknown*)col, &DIID_DispHTMLElementCollection); hres = IHTMLElementCollection_get_length(col, &len); @@ -814,6 +818,8 @@ static void _test_elem_collection(unsigned line, IHTMLElementCollection *col, hres = IHTMLElementCollection_item(col, name, index, &disp); ok_(__FILE__,line) (hres == E_INVALIDARG, "item failed: %08x, expected E_INVALIDARG\n", hres); ok_(__FILE__,line) (disp == NULL, "disp != NULL\n"); + + IHTMLElementCollection_Release(col); } #define get_first_child(n) _get_first_child(__LINE__,n) @@ -1150,10 +1156,25 @@ static IHTMLDOMNode *_test_node_append_child(unsigned line, IUnknown *node_unk, return new_child; } +#define test_node_remove_child(n,c) _test_node_remove_child(__LINE__,n,c) +static void _test_node_remove_child(unsigned line, IUnknown *unk, IHTMLDOMNode *child) +{ + IHTMLDOMNode *node = _get_node_iface(line, unk); + IHTMLDOMNode *new_node = NULL; + HRESULT hres; + + hres = IHTMLDOMNode_removeChild(node, child, &new_node); + ok_(__FILE__,line) (hres == S_OK, "appendChild failed: %08x\n", hres); + ok_(__FILE__,line) (new_node != NULL, "new_node == NULL\n"); + /* TODO ok_(__FILE__,line) (new_node != child, "new_node == child\n"); */ + + IHTMLDOMNode_Release(node); + IHTMLDOMNode_Release(new_node); +} + static void test_elem_col_item(IHTMLElementCollection *col, LPCWSTR n, const elem_type_t *elem_types, long len) { - IHTMLElementCollection *elcol; IDispatch *disp; VARIANT name, index; DWORD i; @@ -1166,15 +1187,12 @@ static void test_elem_col_item(IHTMLElementCollection *col, LPCWSTR n, hres = IHTMLElementCollection_item(col, name, index, &disp); ok(hres == S_OK, "item failed: %08x\n", hres); - hres = IDispatch_QueryInterface(disp, &IID_IHTMLElementCollection, (void**)&elcol); + test_elem_collection((IUnknown*)disp, elem_types, len); IDispatch_Release(disp); ok(hres == S_OK, "Could not get IHTMLElementCollection interface: %08x\n", hres); if(hres != S_OK) goto cleanup; - test_elem_collection(elcol, elem_types, len); - IHTMLElementCollection_Release(elcol); - V_VT(&index) = VT_I4; for(i=0; i