Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(234)

Unified Diff: third_party/WebKit/Source/core/dom/DOMTokenList.cpp

Issue 2909203003: DOMTokenList: Fold AddInternal() and RemoveInternal() into toggle(). (Closed)
Patch Set: Created 3 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « third_party/WebKit/Source/core/dom/DOMTokenList.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: third_party/WebKit/Source/core/dom/DOMTokenList.cpp
diff --git a/third_party/WebKit/Source/core/dom/DOMTokenList.cpp b/third_party/WebKit/Source/core/dom/DOMTokenList.cpp
index 11dbfc79c3da346fa9a9da1d7a923e6631701e4c..60e9c7f6f6c185af61343ecb7129fad18d16bafe 100644
--- a/third_party/WebKit/Source/core/dom/DOMTokenList.cpp
+++ b/third_party/WebKit/Source/core/dom/DOMTokenList.cpp
@@ -126,29 +126,44 @@ void DOMTokenList::remove(const Vector<String>& tokens,
RemoveTokens(tokens);
}
+// https://dom.spec.whatwg.org/#dom-domtokenlist-toggle
bool DOMTokenList::toggle(const AtomicString& token,
ExceptionState& exception_state) {
if (!ValidateToken(token, exception_state))
return false;
+ // 4. If context object’s token set[token] exists, then:
if (contains(token)) {
- RemoveInternal(token);
+ // 1. If force is either not given or is false, then remove token from
+ // context object’s token set.
+ RemoveTokens(Vector<String>({token}));
return false;
}
- AddInternal(token);
+ // 5. Otherwise, if force not given or is true, append token to context
+ // object’s token set and set result to true.
+ AddTokens(Vector<String>({token}));
return true;
}
+// https://dom.spec.whatwg.org/#dom-domtokenlist-toggle
bool DOMTokenList::toggle(const AtomicString& token,
bool force,
ExceptionState& exception_state) {
if (!ValidateToken(token, exception_state))
return false;
- if (force)
- AddInternal(token);
- else
- RemoveInternal(token);
+ // 4. If context object’s token set[token] exists, then:
+ if (contains(token)) {
+ // 1. If force is either not given or is false, then remove token from
+ // context object’s token set.
+ if (!force)
+ RemoveTokens(Vector<String>({token}));
+ } else {
+ // 5. Otherwise, if force not given or is true, append token to context
+ // object’s token set and set result to true.
+ if (force)
+ AddTokens(Vector<String>({token}));
+ }
return force;
}
@@ -158,23 +173,6 @@ bool DOMTokenList::supports(const AtomicString& token,
return ValidateTokenValue(token, exception_state);
}
-void DOMTokenList::AddInternal(const AtomicString& token) {
- if (contains(token))
- return;
- Vector<String> tokens;
- tokens.push_back(token.GetString());
- AddTokens(tokens);
-}
-
-void DOMTokenList::RemoveInternal(const AtomicString& token) {
- // Check using contains first to skip unnecessary reserialization.
- if (!contains(token))
- return;
- Vector<String> tokens;
- tokens.push_back(token.GetString());
- RemoveTokens(tokens);
-}
-
// https://dom.spec.whatwg.org/#dom-domtokenlist-add
void DOMTokenList::AddTokens(const Vector<String>& tokens) {
// 2. For each token in tokens, append token to context object’s token set.
« no previous file with comments | « third_party/WebKit/Source/core/dom/DOMTokenList.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698