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

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

Issue 1388903002: className should be allowed to be a whitespace-only string (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 2 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/LayoutTests/fast/dom/Element/classlist-empty-string-expected.txt ('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/Element.cpp
diff --git a/third_party/WebKit/Source/core/dom/Element.cpp b/third_party/WebKit/Source/core/dom/Element.cpp
index 9034a842ff08eed765667e4d3dfa4a467b18e33b..f753d301018a8616f9f0eb049734138c94529c0b 100644
--- a/third_party/WebKit/Source/core/dom/Element.cpp
+++ b/third_party/WebKit/Source/core/dom/Element.cpp
@@ -153,6 +153,8 @@ ScrollCustomizationCallbacks& scrollCustomizationCallbacks()
using namespace HTMLNames;
using namespace XMLNames;
+enum class ClassStringContent { Empty, WhiteSpaceOnly, HasClasses };
+
PassRefPtrWillBeRawPtr<Element> Element::create(const QualifiedName& tagName, Document* document)
{
return adoptRefWillBeNoop(new Element(tagName, document, CreateElement));
@@ -1229,7 +1231,7 @@ inline void Element::attributeChangedFromParserOrByCloning(const QualifiedName&
}
template <typename CharacterType>
-static inline bool classStringHasClassName(const CharacterType* characters, unsigned length)
+static inline ClassStringContent classStringHasClassName(const CharacterType* characters, unsigned length)
{
ASSERT(length > 0);
@@ -1240,15 +1242,20 @@ static inline bool classStringHasClassName(const CharacterType* characters, unsi
++i;
} while (i < length);
- return i < length;
+ if (i == length && length == 1)
+ return ClassStringContent::Empty;
+ if (i == length && length > 1)
+ return ClassStringContent::WhiteSpaceOnly;
+
+ return ClassStringContent::HasClasses;
}
-static inline bool classStringHasClassName(const AtomicString& newClassString)
+static inline ClassStringContent classStringHasClassName(const AtomicString& newClassString)
{
unsigned length = newClassString.length();
if (!length)
- return false;
+ return ClassStringContent::Empty;
if (newClassString.is8Bit())
return classStringHasClassName(newClassString.characters8(), length);
@@ -1261,8 +1268,9 @@ void Element::classAttributeChanged(const AtomicString& newClassString)
bool testShouldInvalidateStyle = inActiveDocument() && styleResolver && styleChangeType() < SubtreeStyleChange;
ASSERT(elementData());
- if (classStringHasClassName(newClassString)) {
- const bool shouldFoldCase = document().inQuirksMode();
+ ClassStringContent classStringContentType = classStringHasClassName(newClassString);
+ const bool shouldFoldCase = document().inQuirksMode();
+ if (classStringContentType == ClassStringContent::HasClasses) {
const SpaceSplitString oldClasses = elementData()->classNames();
elementData()->setClass(newClassString, shouldFoldCase);
const SpaceSplitString& newClasses = elementData()->classNames();
@@ -1272,7 +1280,10 @@ void Element::classAttributeChanged(const AtomicString& newClassString)
const SpaceSplitString& oldClasses = elementData()->classNames();
if (testShouldInvalidateStyle)
document().styleEngine().classChangedForElement(oldClasses, *this);
- elementData()->clearClass();
+ if (classStringContentType == ClassStringContent::WhiteSpaceOnly)
+ elementData()->setClass(newClassString, shouldFoldCase);
+ else
+ elementData()->clearClass();
}
if (hasRareData())
@@ -1297,7 +1308,7 @@ bool Element::shouldInvalidateDistributionWhenAttributeChanged(ElementShadow* el
if (name == HTMLNames::classAttr) {
const AtomicString& newClassString = newValue;
- if (classStringHasClassName(newClassString)) {
+ if (classStringHasClassName(newClassString) == ClassStringContent::HasClasses) {
const SpaceSplitString& oldClasses = elementData()->classNames();
const SpaceSplitString newClasses(newClassString, document().inQuirksMode() ? SpaceSplitString::ShouldFoldCase : SpaceSplitString::ShouldNotFoldCase);
if (featureSet.checkSelectorsForClassChange(oldClasses, newClasses))
« no previous file with comments | « third_party/WebKit/LayoutTests/fast/dom/Element/classlist-empty-string-expected.txt ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698