Module: wine Branch: master Commit: 3d505b12e352fd837246890656905b11d3b36699 URL: http://source.winehq.org/git/wine.git/?a=commit;h=3d505b12e352fd837246890656...
Author: Jacek Caban jacek@codeweavers.com Date: Thu Nov 2 16:48:07 2017 +0100
mshtml: Added IDocumentSelector::querySelector implementation.
Signed-off-by: Jacek Caban jacek@codeweavers.com Signed-off-by: Alexandre Julliard julliard@winehq.org
---
dlls/mshtml/htmldoc.c | 28 ++++++++++++++++++++++++++-- dlls/mshtml/tests/elements.js | 22 +++++++++++++++++++++- 2 files changed, 47 insertions(+), 3 deletions(-)
diff --git a/dlls/mshtml/htmldoc.c b/dlls/mshtml/htmldoc.c index fbb70c1..55d55f7 100644 --- a/dlls/mshtml/htmldoc.c +++ b/dlls/mshtml/htmldoc.c @@ -4262,8 +4262,32 @@ static HRESULT WINAPI DocumentSelector_Invoke(IDocumentSelector *iface, DISPID d static HRESULT WINAPI DocumentSelector_querySelector(IDocumentSelector *iface, BSTR v, IHTMLElement **pel) { HTMLDocument *This = impl_from_IDocumentSelector(iface); - FIXME("(%p)->(%s %p)\n", This, debugstr_w(v), pel); - return E_NOTIMPL; + nsIDOMElement *nselem; + HTMLElement *elem; + nsAString nsstr; + nsresult nsres; + HRESULT hres; + + TRACE("(%p)->(%s %p)\n", This, debugstr_w(v), pel); + + nsAString_InitDepend(&nsstr, v); + nsres = nsIDOMHTMLDocument_QuerySelector(This->doc_node->nsdoc, &nsstr, &nselem); + nsAString_Finish(&nsstr); + if(NS_FAILED(nsres)) { + ERR("QuerySelector failed: %08x\n", nsres); + return E_FAIL; + } + + if(!nselem) { + *pel = NULL; + return S_OK; + } + + hres = get_elem(This->doc_node, nselem, &elem); + nsIDOMElement_Release(nselem); + if(SUCCEEDED(hres)) + *pel = &elem->IHTMLElement_iface; + return S_OK; }
static HRESULT WINAPI DocumentSelector_querySelectorAll(IDocumentSelector *iface, BSTR v, IHTMLDOMChildrenCollection **pel) diff --git a/dlls/mshtml/tests/elements.js b/dlls/mshtml/tests/elements.js index f0498d5..3912e9a 100644 --- a/dlls/mshtml/tests/elements.js +++ b/dlls/mshtml/tests/elements.js @@ -129,10 +129,30 @@ function test_getElementsByClassName() { next_test(); }
+function test_query_selector() { + document.body.innerHTML = '<div class="class1">' + + '<div class="class1"></div>' + + '<a id="class1" class="class2"></a>' + + '</div>' + + '<script class="class1"></script>'; + + var e = document.querySelector("nomatch"); + ok(e === null, "e = " + e); + + e = document.querySelector(".class1"); + ok(e.tagName === "DIV", "e.tagName = " + e.tagName); + + e = document.querySelector("a"); + ok(e.tagName === "A", "e.tagName = " + e.tagName); + + next_test(); +} + var tests = [ test_input_selection, test_textContent, test_ElementTraversal, test_getElementsByClassName, - test_head + test_head, + test_query_selector ];