From 664e861cdafbf3e6b34a1dab9428d2c234a9eb80 Mon Sep 17 00:00:00 2001 From: Jacek Caban Date: Thu, 23 Nov 2017 17:37:03 +0100 Subject: [PATCH] mshtml: Added IHTMLDOMNode3::compareDocumentPosition implementation. Signed-off-by: Jacek Caban Signed-off-by: Alexandre Julliard --- dlls/mshtml/htmlnode.c | 21 +++++++++++++++++++-- dlls/mshtml/tests/elements.js | 27 ++++++++++++++++++++++++++- 2 files changed, 45 insertions(+), 3 deletions(-) diff --git a/dlls/mshtml/htmlnode.c b/dlls/mshtml/htmlnode.c index 70b87583d25..0aad4912b0d 100644 --- a/dlls/mshtml/htmlnode.c +++ b/dlls/mshtml/htmlnode.c @@ -1341,8 +1341,25 @@ static HRESULT WINAPI HTMLDOMNode3_isSameNode(IHTMLDOMNode3 *iface, IHTMLDOMNode static HRESULT WINAPI HTMLDOMNode3_compareDocumentPosition(IHTMLDOMNode3 *iface, IHTMLDOMNode *otherNode, USHORT *flags) { HTMLDOMNode *This = impl_from_IHTMLDOMNode3(iface); - FIXME("(%p)->()\n", This); - return E_NOTIMPL; + HTMLDOMNode *other; + UINT16 position; + nsresult nsres; + + TRACE("(%p)->()\n", This); + + other = get_node_obj(otherNode); + if(!other) + return E_INVALIDARG; + + nsres = nsIDOMNode_CompareDocumentPosition(This->nsnode, other->nsnode, &position); + IHTMLDOMNode_Release(&other->IHTMLDOMNode_iface); + if(NS_FAILED(nsres)) { + ERR("failed: %08x\n", nsres); + return E_FAIL; + } + + *flags = position; + return S_OK; } static HRESULT WINAPI HTMLDOMNode3_isSupported(IHTMLDOMNode3 *iface, BSTR feature, VARIANT version, VARIANT_BOOL *pfisSupported) diff --git a/dlls/mshtml/tests/elements.js b/dlls/mshtml/tests/elements.js index 3912e9a8197..6e193ee5543 100644 --- a/dlls/mshtml/tests/elements.js +++ b/dlls/mshtml/tests/elements.js @@ -148,11 +148,36 @@ function test_query_selector() { next_test(); } +function test_compare_position() { + document.body.innerHTML = '
'; + + var parent = document.body.firstChild; + var child1 = parent.firstChild; + var child2 = child1.nextSibling; + var elem = document.createElement("div"); + + function compare_position(node1, node2, expected_result, ignore_mask) { + var cmp = node1.compareDocumentPosition(node2); + ok((cmp & ~ignore_mask) == expected_result, + "compareDocumentPosition returned " + cmp + " expected " + expected_result); + } + + compare_position(child1, child2, 4); + compare_position(child2, child1, 2); + compare_position(parent, child1, 0x14); + compare_position(parent, child2, 0x14); + compare_position(parent, elem, 0x21, 6); + compare_position(elem, parent, 0x21, 6); + + next_test(); +} + var tests = [ test_input_selection, test_textContent, test_ElementTraversal, test_getElementsByClassName, test_head, - test_query_selector + test_query_selector, + test_compare_position ]; -- 2.11.4.GIT