Paul Gofman : mshtml: Implement IWineDOMTokenList_add() method.

Alexandre Julliard julliard at winehq.org
Mon Jul 19 15:59:16 CDT 2021


Module: wine
Branch: master
Commit: 44031d7085a033f123db0f91fb7de8852d245375
URL:    https://source.winehq.org/git/wine.git/?a=commit;h=44031d7085a033f123db0f91fb7de8852d245375

Author: Paul Gofman <pgofman at codeweavers.com>
Date:   Mon Jul 19 15:53:17 2021 +0300

mshtml: Implement IWineDOMTokenList_add() method.

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

---

 dlls/mshtml/htmlelem.c               | 85 ++++++++++++++++++++++++++++++++++++
 dlls/mshtml/mshtml_private_iface.idl |  2 +
 dlls/mshtml/tests/dom.js             | 50 +++++++++++++++++++++
 3 files changed, 137 insertions(+)

diff --git a/dlls/mshtml/htmlelem.c b/dlls/mshtml/htmlelem.c
index 5bb3f1eaf15..fd9ef686381 100644
--- a/dlls/mshtml/htmlelem.c
+++ b/dlls/mshtml/htmlelem.c
@@ -6490,6 +6490,90 @@ static HRESULT WINAPI token_list_Invoke(IWineDOMTokenList *iface, DISPID dispIdM
             pDispParams, pVarResult, pExcepInfo, puArgErr);
 }
 
+static const WCHAR *find_token(const WCHAR *list, const WCHAR *token, unsigned int token_len)
+{
+    const WCHAR *ptr, *next;
+
+    if (!list || !token)
+        return NULL;
+
+    ptr = list;
+    while (*ptr)
+    {
+        while (iswspace(*ptr))
+            ++ptr;
+        if (!*ptr)
+            break;
+        next = ptr + 1;
+        while (*next && !iswspace(*next))
+            ++next;
+
+        if (next - ptr == token_len && !wcsncmp(ptr, token, token_len))
+            return ptr;
+        ptr = next;
+    }
+    return NULL;
+}
+
+static HRESULT WINAPI token_list_add(IWineDOMTokenList *iface, BSTR token)
+{
+    struct token_list *token_list = impl_from_IWineDOMTokenList(iface);
+    unsigned int i, len, old_len, new_len;
+    BSTR new, old;
+    HRESULT hr;
+
+    TRACE("iface %p, token %s.\n", iface, debugstr_w(token));
+
+    len = token ? lstrlenW(token) : 0;
+    if (!len)
+    {
+        WARN("Empty token.\n");
+        return E_INVALIDARG;
+    }
+
+    for (i = 0; i < len; ++i)
+        if (iswspace(token[i]))
+        {
+            WARN("Token has spaces.\n");
+            return E_INVALIDARG;
+        }
+
+    if (FAILED(hr = IHTMLElement_get_className(token_list->element, &old)))
+        return hr;
+
+    TRACE("old %s.\n", debugstr_w(old));
+
+    if (find_token(old, token, len))
+    {
+        SysFreeString(old);
+        return S_OK;
+    }
+
+    old_len = old ? lstrlenW(old) : 0;
+    new_len = old_len + len + !!old_len;
+
+    if (!(new = SysAllocStringLen(NULL, new_len)))
+    {
+        ERR("No memory.\n");
+        SysFreeString(old);
+        return E_OUTOFMEMORY;
+    }
+
+    memcpy(new, old, sizeof(*new) * old_len);
+    if (old_len)
+        new[old_len++]= L' ';
+    memcpy(new + old_len, token, sizeof(*new) * len);
+    new[old_len + len] = 0;
+
+    SysFreeString(old);
+
+    TRACE("new %s.\n", debugstr_w(new));
+
+    hr = IHTMLElement_put_className(token_list->element, new);
+    SysFreeString(new);
+    return hr;
+}
+
 static const IWineDOMTokenListVtbl WineDOMTokenListVtbl = {
     token_list_QueryInterface,
     token_list_AddRef,
@@ -6498,6 +6582,7 @@ static const IWineDOMTokenListVtbl WineDOMTokenListVtbl = {
     token_list_GetTypeInfo,
     token_list_GetIDsOfNames,
     token_list_Invoke,
+    token_list_add,
 };
 
 static const tid_t token_list_iface_tids[] = {
diff --git a/dlls/mshtml/mshtml_private_iface.idl b/dlls/mshtml/mshtml_private_iface.idl
index 1764b0a8c9d..8a2c9463dca 100644
--- a/dlls/mshtml/mshtml_private_iface.idl
+++ b/dlls/mshtml/mshtml_private_iface.idl
@@ -111,6 +111,8 @@ interface IWineHTMLElementPrivate : IDispatch
 ]
 interface IWineDOMTokenList : IDispatch
 {
+    [id(1)]
+    HRESULT add([in] BSTR token);
 }
 
 } /* library MSHTML_private */
diff --git a/dlls/mshtml/tests/dom.js b/dlls/mshtml/tests/dom.js
index f54cb0f7088..ccbb3d8b69d 100644
--- a/dlls/mshtml/tests/dom.js
+++ b/dlls/mshtml/tests/dom.js
@@ -512,4 +512,54 @@ sync_test("hasAttribute", function() {
 sync_test("classList", function() {
     var elem = document.createElement("div");
     var classList = elem.classList;
+
+    classList.add("a");
+    ok(elem.className === "a", "Expected className 'a', got " + elem.className);
+
+    classList.add("b");
+    ok(elem.className === "a b", "Expected className 'a b', got " + elem.className);
+
+    classList.add("c");
+    ok(elem.className === "a b c", "Expected className 'a b c', got " + elem.className);
+
+    classList.add(4);
+    ok(elem.className === "a b c 4", "Expected className 'a b c 4', got " + elem.className);
+
+    classList.add("c");
+    ok(elem.className === "a b c 4", "(2) Expected className 'a b c 4', got " + elem.className);
+
+    var exception = false
+
+    try
+    {
+        classList.add();
+    }
+    catch(e)
+    {
+        exception = true;
+    }
+    ok(exception && elem.className === "a b c 4", "Expected exception, className 'a b c 4', got exception "
+            + exception + ", className" + elem.className);
+
+    exception = false
+    try
+    {
+        classList.add("");
+    }
+    catch(e)
+    {
+        exception = true;
+    }
+    ok(exception, "Expected exception for classList.add(\"\")");
+
+    exception = false
+    try
+    {
+        classList.add("e f");
+    }
+    catch(e)
+    {
+        exception = true;
+    }
+    ok(exception, "Expected exception for classList.add(\"e f\")");
 });




More information about the wine-cvs mailing list