[PATCH 4/4] mshtml: Added IDocumentSelector::querySelector implementation.

Jacek Caban <[email protected]>
Newsgroups gmane.comp.emulators.wine.patches
Message-ID <[email protected]>
Signed-off-by: Jacek Caban <[email protected]>
---
 dlls/mshtml/htmldoc.c         | 28 ++++++++++++++++++++++++++--
 dlls/mshtml/tests/elements.js | 22 +++++++++++++++++++++-
 2 files changed, 47 insertions(+), 3 deletions(-)
0004-mshtml-Added-IDocumentSelector-querySelector-implemen.diff (text/x-patch, 2.3 KB)
diff --git a/dlls/mshtml/htmldoc.c b/dlls/mshtml/htmldoc.c
index fbb70c101c..55d55f7d59 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 f0498d5abc..3912e9a819 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
 ];
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.