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

Alexandre Julliard julliard at winehq.org
Sun Jul 3 12:18:28 CDT 2016


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

Author: Jacek Caban <jacek at codeweavers.com>
Date:   Fri Jul  1 11:21:27 2016 +0200

mshtml: Added IHTMLElement6::getElementsByClassName implementation.

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

---

 dlls/mshtml/htmlelem.c    | 21 +++++++++++++++++++--
 dlls/mshtml/htmlelemcol.c |  3 ++-
 dlls/mshtml/tests/dom.c   | 38 ++++++++++++++++++++++++++++++++++++++
 3 files changed, 59 insertions(+), 3 deletions(-)

diff --git a/dlls/mshtml/htmlelem.c b/dlls/mshtml/htmlelem.c
index 7467822..df4377a 100644
--- a/dlls/mshtml/htmlelem.c
+++ b/dlls/mshtml/htmlelem.c
@@ -4103,8 +4103,25 @@ static HRESULT WINAPI HTMLElement6_get_nodeName(IHTMLElement6 *iface, BSTR *p)
 static HRESULT WINAPI HTMLElement6_getElementsByClassName(IHTMLElement6 *iface, BSTR v, IHTMLElementCollection **pel)
 {
     HTMLElement *This = impl_from_IHTMLElement6(iface);
-    FIXME("(%p)->(%s %p)\n", This, debugstr_w(v), pel);
-    return E_NOTIMPL;
+    nsIDOMHTMLCollection *nscol = NULL;
+    nsAString nsstr;
+    nsresult nsres;
+
+    TRACE("(%p)->(%s %p)\n", This, debugstr_w(v), pel);
+
+    if(This->nselem) {
+        nsAString_InitDepend(&nsstr, v);
+        nsres = nsIDOMHTMLElement_GetElementsByClassName(This->nselem, &nsstr, &nscol);
+        nsAString_Finish(&nsstr);
+        if(NS_FAILED(nsres)) {
+            ERR("GetElementsByClassName failed: %08x\n", nsres);
+            return E_FAIL;
+        }
+    }
+
+    *pel = create_collection_from_htmlcol(This->node.doc, nscol);
+    nsIDOMHTMLCollection_Release(nscol);
+    return S_OK;
 }
 
 static HRESULT WINAPI HTMLElement6_msMatchesSelector(IHTMLElement6 *iface, BSTR v, VARIANT_BOOL *pfMatches)
diff --git a/dlls/mshtml/htmlelemcol.c b/dlls/mshtml/htmlelemcol.c
index c6c65b1..6bf599d 100644
--- a/dlls/mshtml/htmlelemcol.c
+++ b/dlls/mshtml/htmlelemcol.c
@@ -723,7 +723,8 @@ IHTMLElementCollection *create_collection_from_htmlcol(HTMLDocumentNode *doc, ns
     HTMLDOMNode *node;
     HRESULT hres = S_OK;
 
-    nsIDOMHTMLCollection_GetLength(nscol, &length);
+    if(nscol)
+        nsIDOMHTMLCollection_GetLength(nscol, &length);
 
     buf.len = buf.size = length;
     if(buf.len) {
diff --git a/dlls/mshtml/tests/dom.c b/dlls/mshtml/tests/dom.c
index dce65d5..dec9cdd 100644
--- a/dlls/mshtml/tests/dom.c
+++ b/dlls/mshtml/tests/dom.c
@@ -8038,6 +8038,43 @@ static void test_selectors(IHTMLDocument2 *doc, IHTMLElement *div)
     IElementSelector_Release(elem_selector);
 }
 
+static void test_elemsbyclass(IHTMLElement *div)
+{
+    IHTMLElementCollection *collection;
+    IHTMLElement6 *elem;
+    BSTR str;
+    HRESULT hres;
+
+    static const elem_type_t types[] = {ET_DIV, ET_FORM};
+
+    test_elem_set_innerhtml((IUnknown*)div, "<div class=\"cl1\"><form class=\"cl1\"></form></div><div class=\"cl2\"></div>");
+
+    hres = IHTMLElement_QueryInterface(div, &IID_IHTMLElement6, (void**)&elem);
+    ok(hres == S_OK || broken(hres == E_NOINTERFACE), "Could not get IHTMLElement6 iface: %08x\n", hres);
+    if(FAILED(hres)) {
+        win_skip("IHTMLElement6 tests skipped.\n");
+        return;
+    }
+
+    collection = NULL;
+    str = a2bstr("nomatch");
+    hres = IHTMLElement6_getElementsByClassName(elem, str, &collection);
+    ok(hres == S_OK, "getElementsByClassName failed: %08x\n", hres);
+    ok(collection != NULL, "collection == NULL\n");
+    test_elem_collection((IUnknown*)collection, NULL, 0);
+    IHTMLElementCollection_Release(collection);
+
+    collection = NULL;
+    str = a2bstr("cl1");
+    hres = IHTMLElement6_getElementsByClassName(elem, str, &collection);
+    ok(hres == S_OK, "getElementsByClassName failed: %08x\n", hres);
+    ok(collection != NULL, "collection == NULL\n");
+    test_elem_collection((IUnknown*)collection, types, sizeof(types)/sizeof(*types));
+    IHTMLElementCollection_Release(collection);
+
+    IHTMLElement6_Release(elem);
+}
+
 static void test_elems(IHTMLDocument2 *doc)
 {
     IHTMLElementCollection *col;
@@ -9113,6 +9150,7 @@ static void test_elems2(IHTMLDocument2 *doc)
     }
 
     test_selectors(doc, div);
+    test_elemsbyclass(div);
 
     test_elem_set_innerhtml((IUnknown*)div, "<div id=\"elemid\">test</div>");
     elem = get_elem_by_id(doc, "elemid", TRUE);




More information about the wine-cvs mailing list