Commit fcaa9bbe authored by Gabriel Ivăncescu's avatar Gabriel Ivăncescu Committed by Alexandre Julliard

mshtml: Implement classList's toggle() method.

parent 59f7fbee
......@@ -7464,7 +7464,7 @@ static const WCHAR *find_token(const WCHAR *list, const WCHAR *token, unsigned i
return NULL;
}
static HRESULT token_list_add_remove(IWineDOMTokenList *iface, BSTR token, BOOL remove)
static HRESULT token_list_add_remove(IWineDOMTokenList *iface, BSTR token, BOOL remove, VARIANT_BOOL *toggle_ret)
{
struct token_list *token_list = impl_from_IWineDOMTokenList(iface);
unsigned int i, len, old_len, new_len;
......@@ -7472,7 +7472,7 @@ static HRESULT token_list_add_remove(IWineDOMTokenList *iface, BSTR token, BOOL
BSTR new, old;
HRESULT hr;
TRACE("iface %p, token %s, remove %#x.\n", iface, debugstr_w(token), remove);
TRACE("token_list %p, token %s, remove %#x, toggle_ret %p.\n", token_list, debugstr_w(token), remove, toggle_ret);
len = token ? lstrlenW(token) : 0;
if (!len)
......@@ -7493,8 +7493,13 @@ static HRESULT token_list_add_remove(IWineDOMTokenList *iface, BSTR token, BOOL
TRACE("old %s.\n", debugstr_w(old));
if (((old_pos = find_token(old, token, len)) && !remove)
|| (!old_pos && remove))
old_pos = find_token(old, token, len);
if (toggle_ret)
{
remove = !!old_pos;
*toggle_ret = !remove;
}
else if (!!old_pos != remove)
{
SysFreeString(old);
return S_OK;
......@@ -7553,21 +7558,17 @@ static HRESULT token_list_add_remove(IWineDOMTokenList *iface, BSTR token, BOOL
static HRESULT WINAPI token_list_add(IWineDOMTokenList *iface, BSTR token)
{
return token_list_add_remove(iface, token, FALSE);
return token_list_add_remove(iface, token, FALSE, NULL);
}
static HRESULT WINAPI token_list_remove(IWineDOMTokenList *iface, BSTR token)
{
return token_list_add_remove(iface, token, TRUE);
return token_list_add_remove(iface, token, TRUE, NULL);
}
static HRESULT WINAPI token_list_toggle(IWineDOMTokenList *iface, BSTR token, VARIANT_BOOL *p)
{
struct token_list *token_list = impl_from_IWineDOMTokenList(iface);
FIXME("(%p)->(%s %p)\n", token_list, debugstr_w(token), p);
return E_NOTIMPL;
return token_list_add_remove(iface, token, FALSE, p);
}
static HRESULT WINAPI token_list_contains(IWineDOMTokenList *iface, BSTR token, VARIANT_BOOL *p)
......
......@@ -623,7 +623,7 @@ sync_test("hasAttribute", function() {
sync_test("classList", function() {
var elem = document.createElement("div");
var classList = elem.classList, i;
var classList = elem.classList, i, r;
var props = [ "add", "contains", "item", "length", "remove", "toggle" ];
for(i = 0; i < props.length; i++)
......@@ -765,6 +765,60 @@ sync_test("classList", function() {
classList.remove("b");
ok(elem.className === "", "remove: expected className '', got " + elem.className);
exception = false;
try
{
classList.toggle();
}
catch(e)
{
exception = true;
}
ok(exception, "Expected exception for classList.toggle()");
exception = false;
try
{
classList.toggle("");
}
catch(e)
{
exception = true;
}
ok(exception, "Expected exception for classList.toggle(\"\")");
exception = false;
try
{
classList.toggle("a b");
}
catch(e)
{
exception = true;
}
ok(exception, "Expected exception for classList.toggle(\"a b\")");
// toggle's second arg is not implemented by IE, and ignored
r = classList.toggle("abc");
ok(r === true, "toggle('abc') returned " + r);
ok(elem.className === "abc", "toggle('abc'): got className " + elem.className);
r = classList.toggle("def", false);
ok(r === true, "toggle('def', false) returned " + r);
ok(elem.className === "abc def", "toggle('def', false): got className " + elem.className);
r = classList.toggle("123", 1234);
ok(r === true, "toggle('123', 1234) returned " + r);
ok(elem.className === "abc def 123", "toggle('123', 1234): got className " + elem.className);
r = classList.toggle("def", true);
ok(r === false, "toggle('def', true) returned " + r);
ok(elem.className === "abc 123", "toggle('def', true): got className " + elem.className);
r = classList.toggle("123", null);
ok(r === false, "toggle('123', null) returned " + r);
ok(elem.className === "abc", "toggle('123', null): got className " + elem.className);
elem.className = " testclass foobar ";
ok(("" + classList) === " testclass foobar ", "Expected classList value ' testclass foobar ', got " + classList);
ok(classList.toString() === " testclass foobar ", "Expected classList toString ' testclass foobar ', got " + classList.toString());
......
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