- Revision
- 131408
- Author
- commit-qu...@webkit.org
- Date
- 2012-10-15 20:57:02 -0700 (Mon, 15 Oct 2012)
Log Message
Add force parameter to DOMTokenList.toggle
https://bugs.webkit.org/show_bug.cgi?id=99375
Patch by Pablo Flouret <pab...@motorola.com> on 2012-10-15
Reviewed by Darin Adler.
Source/WebCore:
See http://dom.spec.whatwg.org/#dom-domtokenlist-toggle and
https://www.w3.org/Bugs/Public/show_bug.cgi?id=18463
Essentially, the optional boolean force parameter, if present, makes
toggle always add or remove a class.
No new tests, modified fast/dom/HTMLElement/script-tests/class-list.js
* html/DOMTokenList.cpp:
(WebCore::DOMTokenList::toggle):
(WebCore):
* html/DOMTokenList.h:
(DOMTokenList):
* html/DOMTokenList.idl:
New toggle() overload that takes a force parameter and calls
addInternal() or removeInternal() based on it.
LayoutTests:
* fast/dom/HTMLElement/class-list-expected.txt:
* fast/dom/HTMLElement/class-list-quirks-expected.txt:
* fast/dom/HTMLElement/script-tests/class-list.js:
(shouldThrowDOMException):
Modified Paths
Diff
Modified: trunk/LayoutTests/ChangeLog (131407 => 131408)
--- trunk/LayoutTests/ChangeLog 2012-10-16 03:51:00 UTC (rev 131407)
+++ trunk/LayoutTests/ChangeLog 2012-10-16 03:57:02 UTC (rev 131408)
@@ -1,3 +1,15 @@
+2012-10-15 Pablo Flouret <pab...@motorola.com>
+
+ Add force parameter to DOMTokenList.toggle
+ https://bugs.webkit.org/show_bug.cgi?id=99375
+
+ Reviewed by Darin Adler.
+
+ * fast/dom/HTMLElement/class-list-expected.txt:
+ * fast/dom/HTMLElement/class-list-quirks-expected.txt:
+ * fast/dom/HTMLElement/script-tests/class-list.js:
+ (shouldThrowDOMException):
+
2012-10-15 Shinya Kawanaka <shin...@chromium.org>
[Chromium] Unreviewed gardening, TestExpectations updated.
Modified: trunk/LayoutTests/fast/dom/HTMLElement/class-list-expected.txt (131407 => 131408)
--- trunk/LayoutTests/fast/dom/HTMLElement/class-list-expected.txt 2012-10-16 03:51:00 UTC (rev 131407)
+++ trunk/LayoutTests/fast/dom/HTMLElement/class-list-expected.txt 2012-10-16 03:57:02 UTC (rev 131408)
@@ -18,10 +18,23 @@
PASS element.className is " y y "
PASS element.className is "y"
Ensure that we can handle empty class name correctly
+PASS element.classList.toggle('x') is true
PASS element.className is "x"
+PASS element.classList.toggle('x') is false
PASS element.className is ""
PASS element.classList.contains('x') is false
PASS element.classList[1] is undefined.
+Test toggle with force argument
+PASS element.classList.toggle('x', true) is true
+PASS element.className is "x"
+PASS element.classList.toggle('x', true) is true
+PASS element.className is "x"
+PASS element.classList.toggle('x', false) is false
+PASS element.className is ""
+PASS element.classList.toggle('x', false) is false
+PASS element.className is ""
+PASS element.classList.toggle('', true) threw expected DOMException with code 12
+PASS element.classList.toggle('x y', false) threw expected DOMException with code 5
Testing add in presence of trailing white spaces.
PASS element.className is "x y"
PASS element.className is "x\ty"
Modified: trunk/LayoutTests/fast/dom/HTMLElement/class-list-quirks-expected.txt (131407 => 131408)
--- trunk/LayoutTests/fast/dom/HTMLElement/class-list-quirks-expected.txt 2012-10-16 03:51:00 UTC (rev 131407)
+++ trunk/LayoutTests/fast/dom/HTMLElement/class-list-quirks-expected.txt 2012-10-16 03:57:02 UTC (rev 131408)
@@ -18,10 +18,23 @@
PASS element.className is " y y "
PASS element.className is "y"
Ensure that we can handle empty class name correctly
+PASS element.classList.toggle('x') is true
PASS element.className is "x"
+PASS element.classList.toggle('x') is false
PASS element.className is ""
PASS element.classList.contains('x') is false
PASS element.classList[1] is undefined.
+Test toggle with force argument
+PASS element.classList.toggle('x', true) is true
+PASS element.className is "x"
+PASS element.classList.toggle('x', true) is true
+PASS element.className is "x"
+PASS element.classList.toggle('x', false) is false
+PASS element.className is ""
+PASS element.classList.toggle('x', false) is false
+PASS element.className is ""
+PASS element.classList.toggle('', true) threw expected DOMException with code 12
+PASS element.classList.toggle('x y', false) threw expected DOMException with code 5
Testing add in presence of trailing white spaces.
PASS element.className is "x y"
PASS element.className is "x\ty"
Modified: trunk/LayoutTests/fast/dom/HTMLElement/script-tests/class-list.js (131407 => 131408)
--- trunk/LayoutTests/fast/dom/HTMLElement/script-tests/class-list.js 2012-10-16 03:51:00 UTC (rev 131407)
+++ trunk/LayoutTests/fast/dom/HTMLElement/script-tests/class-list.js 2012-10-16 03:57:02 UTC (rev 131408)
@@ -80,9 +80,9 @@
debug('Ensure that we can handle empty class name correctly');
element = document.createElement('span');
-element.classList.toggle('x');
+shouldBeTrue("element.classList.toggle('x')");
shouldBeEqualToString('element.className', 'x');
-element.classList.toggle('x');
+shouldBeFalse("element.classList.toggle('x')");
shouldBeEqualToString('element.className', '');
element = document.createElement('span');
@@ -92,6 +92,27 @@
element.classList.add('x')
+debug('Test toggle with force argument')
+
+createElement('');
+shouldBeTrue("element.classList.toggle('x', true)");
+shouldBeEqualToString('element.className', 'x');
+shouldBeTrue("element.classList.toggle('x', true)");
+shouldBeEqualToString('element.className', 'x');
+shouldBeFalse("element.classList.toggle('x', false)");
+shouldBeEqualToString('element.className', '');
+shouldBeFalse("element.classList.toggle('x', false)");
+shouldBeEqualToString('element.className', '');
+
+shouldThrowDOMException(function() {
+ element.classList.toggle('', true);
+}, DOMException.SYNTAX_ERR);
+
+shouldThrowDOMException(function() {
+ element.classList.toggle('x y', false);
+}, DOMException.INVALID_CHARACTER_ERR);
+
+
debug('Testing add in presence of trailing white spaces.');
createElement('x ');
Modified: trunk/Source/WebCore/ChangeLog (131407 => 131408)
--- trunk/Source/WebCore/ChangeLog 2012-10-16 03:51:00 UTC (rev 131407)
+++ trunk/Source/WebCore/ChangeLog 2012-10-16 03:57:02 UTC (rev 131408)
@@ -1,3 +1,27 @@
+2012-10-15 Pablo Flouret <pab...@motorola.com>
+
+ Add force parameter to DOMTokenList.toggle
+ https://bugs.webkit.org/show_bug.cgi?id=99375
+
+ Reviewed by Darin Adler.
+
+ See http://dom.spec.whatwg.org/#dom-domtokenlist-toggle and
+ https://www.w3.org/Bugs/Public/show_bug.cgi?id=18463
+
+ Essentially, the optional boolean force parameter, if present, makes
+ toggle always add or remove a class.
+
+ No new tests, modified fast/dom/HTMLElement/script-tests/class-list.js
+
+ * html/DOMTokenList.cpp:
+ (WebCore::DOMTokenList::toggle):
+ (WebCore):
+ * html/DOMTokenList.h:
+ (DOMTokenList):
+ * html/DOMTokenList.idl:
+ New toggle() overload that takes a force parameter and calls
+ addInternal() or removeInternal() based on it.
+
2012-10-15 Dan Bernstein <m...@apple.com>
Layout Test fast/text/justify-ideograph-leading-expansion.html is failing an assertion chromium mac
Modified: trunk/Source/WebCore/html/DOMTokenList.cpp (131407 => 131408)
--- trunk/Source/WebCore/html/DOMTokenList.cpp 2012-10-16 03:51:00 UTC (rev 131407)
+++ trunk/Source/WebCore/html/DOMTokenList.cpp 2012-10-16 03:57:02 UTC (rev 131408)
@@ -128,6 +128,19 @@
return true;
}
+bool DOMTokenList::toggle(const AtomicString& token, bool force, ExceptionCode& ec)
+{
+ if (!validateToken(token, ec))
+ return false;
+
+ if (force)
+ addInternal(token);
+ else
+ removeInternal(token);
+
+ return force;
+}
+
void DOMTokenList::addInternal(const AtomicString& token)
{
if (!containsInternal(token))
Modified: trunk/Source/WebCore/html/DOMTokenList.h (131407 => 131408)
--- trunk/Source/WebCore/html/DOMTokenList.h 2012-10-16 03:51:00 UTC (rev 131407)
+++ trunk/Source/WebCore/html/DOMTokenList.h 2012-10-16 03:57:02 UTC (rev 131408)
@@ -52,6 +52,7 @@
virtual void remove(const Vector<String>&, ExceptionCode&);
void remove(const AtomicString&, ExceptionCode&);
bool toggle(const AtomicString&, ExceptionCode&);
+ bool toggle(const AtomicString&, bool force, ExceptionCode&);
AtomicString toString() const { return value(); }
Modified: trunk/Source/WebCore/html/DOMTokenList.idl (131407 => 131408)
--- trunk/Source/WebCore/html/DOMTokenList.idl 2012-10-16 03:51:00 UTC (rev 131407)
+++ trunk/Source/WebCore/html/DOMTokenList.idl 2012-10-16 03:57:02 UTC (rev 131408)
@@ -31,7 +31,7 @@
boolean contains(in DOMString token) raises(DOMException);
void add(in DOMString... tokens) raises(DOMException);
void remove(in DOMString... tokens) raises(DOMException);
- boolean toggle(in DOMString token) raises(DOMException);
+ boolean toggle(in DOMString token, in [Optional] boolean force) raises(DOMException);
#if defined(LANGUAGE_JAVASCRIPT) && LANGUAGE_JAVASCRIPT
[NotEnumerable] DOMString toString();