[PATCH 4/7] mshtml: Implement HTMLAreaElement's href prop.

Gabriel Ivăncescu gabrielopcode at gmail.com
Fri Oct 1 08:12:45 CDT 2021


Signed-off-by: Gabriel Ivăncescu <gabrielopcode at gmail.com>
---
 dlls/mshtml/htmlarea.c  | 36 +++++++++++++++++++++---
 dlls/mshtml/tests/dom.c | 62 +++++++++++++++++++++++++++++++++++++++--
 2 files changed, 92 insertions(+), 6 deletions(-)

diff --git a/dlls/mshtml/htmlarea.c b/dlls/mshtml/htmlarea.c
index a0708c4..e785871 100644
--- a/dlls/mshtml/htmlarea.c
+++ b/dlls/mshtml/htmlarea.c
@@ -129,15 +129,43 @@ static HRESULT WINAPI HTMLAreaElement_get_coords(IHTMLAreaElement *iface, BSTR *
 static HRESULT WINAPI HTMLAreaElement_put_href(IHTMLAreaElement *iface, BSTR v)
 {
     HTMLAreaElement *This = impl_from_IHTMLAreaElement(iface);
-    FIXME("(%p)->(%s)\n", This, debugstr_w(v));
-    return E_NOTIMPL;
+    nsAString nsstr;
+    nsresult nsres;
+
+    TRACE("(%p)->(%s)\n", This, debugstr_w(v));
+
+    nsAString_InitDepend(&nsstr, v);
+    nsres = nsIDOMHTMLAreaElement_SetHref(This->nsarea, &nsstr);
+    nsAString_Finish(&nsstr);
+    if(NS_FAILED(nsres))
+        return E_FAIL;
+
+    return S_OK;
 }
 
 static HRESULT WINAPI HTMLAreaElement_get_href(IHTMLAreaElement *iface, BSTR *p)
 {
     HTMLAreaElement *This = impl_from_IHTMLAreaElement(iface);
-    FIXME("(%p)->(%p)\n", This, p);
-    return E_NOTIMPL;
+    nsAString href_str;
+    nsresult nsres;
+    HRESULT hres;
+
+    TRACE("(%p)->(%p)\n", This, p);
+
+    nsAString_Init(&href_str, NULL);
+    nsres = nsIDOMHTMLAreaElement_GetHref(This->nsarea, &href_str);
+    if(NS_SUCCEEDED(nsres)) {
+        const PRUnichar *href;
+
+        nsAString_GetData(&href_str, &href);
+        hres = nsuri_to_url(href, TRUE, p);
+    }else {
+        ERR("GetHref failed: %08x\n", nsres);
+        hres = E_FAIL;
+    }
+
+    nsAString_Finish(&href_str);
+    return hres;
 }
 
 static HRESULT WINAPI HTMLAreaElement_put_target(IHTMLAreaElement *iface, BSTR v)
diff --git a/dlls/mshtml/tests/dom.c b/dlls/mshtml/tests/dom.c
index 67d7978..3bae9e0 100644
--- a/dlls/mshtml/tests/dom.c
+++ b/dlls/mshtml/tests/dom.c
@@ -77,6 +77,7 @@ static const char elem_test_str[] =
     "<script id=\"sc\" type=\"text/javascript\"><!--\nfunction Testing() {}\n// -->\n</script>"
     "<test /><object id=\"objid\" name=\"objname\" vspace=100></object><embed />"
     "<img id=\"imgid\" name=\"WineImg\"/>"
+    "<area id=\"area\" href=\"http://test\">"
     "<iframe src=\"about:blank\" id=\"ifr\"></iframe>"
     "<form id=\"frm\"></form>"
     "<div id=\"attr\" attr1=\"attr1\" attr2 attr3=\"attr3\"></div>"
@@ -918,6 +919,17 @@ static IHTMLAnchorElement *_get_anchor_iface(unsigned line, IUnknown *unk)
     return anchor;
 }
 
+#define get_area_iface(u) _get_area_iface(__LINE__,u)
+static IHTMLAreaElement *_get_area_iface(unsigned line, IUnknown *unk)
+{
+    IHTMLAreaElement *area;
+    HRESULT hres;
+
+    hres = IUnknown_QueryInterface(unk, &IID_IHTMLAreaElement, (void**)&area);
+    ok_(__FILE__,line) (hres == S_OK, "Could not get IHTMLAreaElement: %08x\n", hres);
+    return area;
+}
+
 #define get_textarea_iface(u) _get_textarea_iface(__LINE__,u)
 static IHTMLTextAreaElement *_get_textarea_iface(unsigned line, IUnknown *unk)
 {
@@ -1704,6 +1716,36 @@ static void _test_anchor_hash(unsigned line, IHTMLElement *elem, const WCHAR *ex
     SysFreeString(str);
 }
 
+#define test_area_href(a,h) _test_area_href(__LINE__,a,h)
+static void _test_area_href(unsigned line, IUnknown *unk, const WCHAR *exhref)
+{
+    IHTMLAreaElement *area = _get_area_iface(line, unk);
+    BSTR str;
+    HRESULT hres;
+
+    hres = IHTMLAreaElement_get_href(area, &str);
+    ok_(__FILE__,line)(hres == S_OK, "get_href failed: %08x\n", hres);
+    ok_(__FILE__,line)(!lstrcmpW(str, exhref), "href = %s, expected %s\n", wine_dbgstr_w(str), wine_dbgstr_w(exhref));
+    SysFreeString(str);
+
+    _test_disp_value(line, unk, exhref);
+}
+
+#define test_area_put_href(a,h) _test_area_put_href(__LINE__,a,h)
+static void _test_area_put_href(unsigned line, IUnknown *unk, const WCHAR *exhref)
+{
+    IHTMLAreaElement *area = _get_area_iface(line, unk);
+    BSTR str;
+    HRESULT hres;
+
+    str = SysAllocString(exhref);
+    hres = IHTMLAreaElement_put_href(area, str);
+    ok_(__FILE__,line)(hres == S_OK, "get_href failed: %08x\n", hres);
+    SysFreeString(str);
+
+    _test_disp_value(line, unk, exhref);
+}
+
 #define test_option_text(o,t) _test_option_text(__LINE__,o,t)
 static void _test_option_text(unsigned line, IHTMLOptionElement *option, const WCHAR *text)
 {
@@ -8763,6 +8805,7 @@ static void test_elems(IHTMLDocument2 *doc)
         ET_OBJECT,
         ET_EMBED,
         ET_IMG,
+        ET_AREA,
         ET_IFRAME,
         ET_FORM,
         ET_DIV
@@ -8803,8 +8846,8 @@ static void test_elems(IHTMLDocument2 *doc)
     ok(hres == S_OK, "get_links failed: %08x\n", hres);
     if(hres == S_OK)
     {
-        static const elem_type_t images_types[] = {ET_A};
-        test_elem_collection((IUnknown*)collection, images_types, 1);
+        static const elem_type_t link_types[] = {ET_A,ET_AREA};
+        test_elem_collection((IUnknown*)collection, link_types, 2);
 
         IHTMLElementCollection_Release(collection);
     }
@@ -9211,6 +9254,21 @@ static void test_elems(IHTMLDocument2 *doc)
         IHTMLElement_Release(elem);
     }
 
+    elem = get_elem_by_id(doc, L"area", TRUE);
+    if(elem) {
+        test_area_href((IUnknown*)elem, L"http://test/");
+
+        /* Change the href */
+        test_area_put_href((IUnknown*)elem, L"http://test1/");
+        test_area_href((IUnknown*)elem, L"http://test1/");
+
+        /* Restore the href */
+        test_area_put_href((IUnknown*)elem, L"http://test/");
+        test_area_href((IUnknown*)elem, L"http://test/");
+
+        IHTMLElement_Release(elem);
+    }
+
     elem = get_doc_elem_by_id(doc, L"metaid");
     if(elem) {
         test_meta_name((IUnknown*)elem, L"meta name");
-- 
2.31.1




More information about the wine-devel mailing list