From a1e6835d0e7466b0ade7432e7aeb4f2e6094dc76 Mon Sep 17 00:00:00 2001 From: Jacek Caban Date: Tue, 4 Sep 2012 13:59:22 +0200 Subject: [PATCH] mshtml: Added IHTMLElement::contains implementation. --- dlls/mshtml/htmlelem.c | 22 ++++++++++++++++++++-- dlls/mshtml/tests/dom.c | 26 ++++++++++++++++++++++++-- 2 files changed, 44 insertions(+), 4 deletions(-) diff --git a/dlls/mshtml/htmlelem.c b/dlls/mshtml/htmlelem.c index 7d6620aad76..e44f97d46fe 100644 --- a/dlls/mshtml/htmlelem.c +++ b/dlls/mshtml/htmlelem.c @@ -773,8 +773,26 @@ static HRESULT WINAPI HTMLElement_contains(IHTMLElement *iface, IHTMLElement *pC VARIANT_BOOL *pfResult) { HTMLElement *This = impl_from_IHTMLElement(iface); - FIXME("(%p)->(%p %p)\n", This, pChild, pfResult); - return E_NOTIMPL; + HTMLElement *child; + cpp_bool result; + nsresult nsres; + + TRACE("(%p)->(%p %p)\n", This, pChild, pfResult); + + child = unsafe_impl_from_IHTMLElement(pChild); + if(!child) { + ERR("not our element\n"); + return E_FAIL; + } + + nsres = nsIDOMNode_Contains(This->node.nsnode, child->node.nsnode, &result); + if(NS_FAILED(nsres)) { + ERR("failed\n"); + return E_FAIL; + } + + *pfResult = result ? VARIANT_TRUE : VARIANT_FALSE; + return S_OK; } static HRESULT WINAPI HTMLElement_get_sourceIndex(IHTMLElement *iface, LONG *p) diff --git a/dlls/mshtml/tests/dom.c b/dlls/mshtml/tests/dom.c index 1b7de7540c5..149aa5eb9ad 100644 --- a/dlls/mshtml/tests/dom.c +++ b/dlls/mshtml/tests/dom.c @@ -2117,6 +2117,18 @@ static void _test_elem_outerhtml(unsigned line, IUnknown *unk, const char *outer SysFreeString(html); } +#define test_elem_contains(a,b,c) _test_elem_contains(__LINE__,a,b,c) +static void _test_elem_contains(unsigned line, IHTMLElement *elem, IHTMLElement *elem2, VARIANT_BOOL exval) +{ + VARIANT_BOOL b; + HRESULT hres; + + b = 100; + hres = IHTMLElement_contains(elem, elem2, &b); + ok_(__FILE__,line)(hres == S_OK, "contains failed: %08x\n", hres); + ok_(__FILE__,line)(b == exval, "contains returned %x, expected %x\n", b, exval); +} + #define get_first_child(n) _get_first_child(__LINE__,n) static IHTMLDOMNode *_get_first_child(unsigned line, IUnknown *unk) { @@ -5301,13 +5313,23 @@ static void test_elems(IHTMLDocument2 *doc) elem2 = test_elem_get_parent((IUnknown*)elem); ok(elem2 != NULL, "elem2 == NULL\n"); test_node_name((IUnknown*)elem2, "BODY"); + elem3 = test_elem_get_parent((IUnknown*)elem2); - IHTMLElement_Release(elem2); ok(elem3 != NULL, "elem3 == NULL\n"); test_node_name((IUnknown*)elem3, "HTML"); + + test_elem_contains(elem3, elem2, VARIANT_TRUE); + test_elem_contains(elem3, elem, VARIANT_TRUE); + test_elem_contains(elem2, elem, VARIANT_TRUE); + test_elem_contains(elem2, elem3, VARIANT_FALSE); + test_elem_contains(elem, elem3, VARIANT_FALSE); + test_elem_contains(elem, elem2, VARIANT_FALSE); + test_elem_contains(elem, elem, VARIANT_TRUE); + IHTMLElement_Release(elem2); + elem2 = test_elem_get_parent((IUnknown*)elem3); - IHTMLElement_Release(elem3); ok(elem2 == NULL, "elem2 != NULL\n"); + IHTMLElement_Release(elem3); test_elem_getelembytag((IUnknown*)elem, ET_OPTION, 2); test_elem_getelembytag((IUnknown*)elem, ET_SELECT, 0);