Jacek Caban : mshtml: Added IHTMLDocument7:: getElementsByClassName implementation.

Alexandre Julliard julliard at winehq.org
Tue Sep 12 15:40:38 CDT 2017


Module: wine
Branch: master
Commit: 68b8b7b4bacf46a8c652a3084eba323d38c841e3
URL:    http://source.winehq.org/git/wine.git/?a=commit;h=68b8b7b4bacf46a8c652a3084eba323d38c841e3

Author: Jacek Caban <jacek at codeweavers.com>
Date:   Tue Sep 12 13:15:48 2017 +0200

mshtml: Added IHTMLDocument7::getElementsByClassName implementation.

Signed-off-by: Jacek Caban <jacek at codeweavers.com>
Signed-off-by: Alexandre Julliard <julliard at winehq.org>

---

 dlls/mshtml/htmldoc.c         | 29 +++++++++++++++++++++++++----
 dlls/mshtml/tests/elements.js | 26 ++++++++++++++++++++++++++
 2 files changed, 51 insertions(+), 4 deletions(-)

diff --git a/dlls/mshtml/htmldoc.c b/dlls/mshtml/htmldoc.c
index 413b0bd..0a2d243 100644
--- a/dlls/mshtml/htmldoc.c
+++ b/dlls/mshtml/htmldoc.c
@@ -3347,11 +3347,32 @@ static HRESULT WINAPI HTMLDocument7_createAttribute(IHTMLDocument7 *iface, BSTR
     return IHTMLDocument5_createAttribute(&This->IHTMLDocument5_iface, bstrAttrName, ppAttribute);
 }
 
-static HRESULT WINAPI HTMLDocument7_getElementByClassName(IHTMLDocument7 *iface, BSTR v, IHTMLElementCollection **pel)
+static HRESULT WINAPI HTMLDocument7_getElementsByClassName(IHTMLDocument7 *iface, BSTR v, IHTMLElementCollection **pel)
 {
     HTMLDocument *This = impl_from_IHTMLDocument7(iface);
-    FIXME("(%p)->(%s %p)\n", This, debugstr_w(v), pel);
-    return E_NOTIMPL;
+    nsIDOMNodeList *nslist;
+    nsAString nsstr;
+    nsresult nsres;
+
+    TRACE("(%p)->(%s %p)\n", This, debugstr_w(v), pel);
+
+    if(!This->doc_node->nsdoc) {
+        FIXME("NULL nsdoc not supported\n");
+        return E_NOTIMPL;
+    }
+
+    nsAString_InitDepend(&nsstr, v);
+    nsres = nsIDOMHTMLDocument_GetElementsByClassName(This->doc_node->nsdoc, &nsstr, &nslist);
+    nsAString_Finish(&nsstr);
+    if(FAILED(nsres)) {
+        ERR("GetElementByClassName failed: %08x\n", nsres);
+        return E_FAIL;
+    }
+
+
+    *pel = create_collection_from_nodelist(This->doc_node, nslist);
+    nsIDOMNodeList_Release(nslist);
+    return S_OK;
 }
 
 static HRESULT WINAPI HTMLDocument7_createProcessingInstruction(IHTMLDocument7 *iface, BSTR target,
@@ -4091,7 +4112,7 @@ static const IHTMLDocument7Vtbl HTMLDocument7Vtbl = {
     HTMLDocument7_get_characterSet,
     HTMLDocument7_createElement,
     HTMLDocument7_createAttribute,
-    HTMLDocument7_getElementByClassName,
+    HTMLDocument7_getElementsByClassName,
     HTMLDocument7_createProcessingInstruction,
     HTMLDocument7_adoptNode,
     HTMLDocument7_put_onmssitemodejumplistitemremoved,
diff --git a/dlls/mshtml/tests/elements.js b/dlls/mshtml/tests/elements.js
index 56c4e2f..f0498d5 100644
--- a/dlls/mshtml/tests/elements.js
+++ b/dlls/mshtml/tests/elements.js
@@ -104,9 +104,35 @@ function test_head() {
     next_test();
 }
 
+function test_getElementsByClassName() {
+    var elems;
+
+    document.body.innerHTML = '<div class="class1">'
+        + '<div class="class1"></div>'
+        + '<a id="class1" class="class2"></a>'
+        + '</div>'
+        + '<script class="class1"></script>';
+
+    elems = document.getElementsByClassName("class1");
+    ok(elems.length === 3, "elems.length = " + elems.length);
+    ok(elems[0].tagName === "DIV", "elems[0].tagName = " + elems[0].tagName);
+    ok(elems[1].tagName === "DIV", "elems[1].tagName = " + elems[1].tagName);
+    ok(elems[2].tagName === "SCRIPT", "elems[2].tagName = " + elems[2].tagName);
+
+    elems = document.getElementsByClassName("class2");
+    ok(elems.length === 1, "elems.length = " + elems.length);
+    ok(elems[0].tagName === "A", "elems[0].tagName = " + elems[0].tagName);
+
+    elems = document.getElementsByClassName("classnotfound");
+    ok(elems.length == 0, "elems.length = " + elems.length);
+
+    next_test();
+}
+
 var tests = [
     test_input_selection,
     test_textContent,
     test_ElementTraversal,
+    test_getElementsByClassName,
     test_head
 ];




More information about the wine-cvs mailing list