Commit 44031d70 authored by Paul Gofman's avatar Paul Gofman Committed by Alexandre Julliard

mshtml: Implement IWineDOMTokenList_add() method.

parent a08d13dd
......@@ -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[] = {
......
......@@ -111,6 +111,8 @@ interface IWineHTMLElementPrivate : IDispatch
]
interface IWineDOMTokenList : IDispatch
{
[id(1)]
HRESULT add([in] BSTR token);
}
} /* library MSHTML_private */
......@@ -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\")");
});
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment