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

Side by Side 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 unified diff | 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 »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright (C) 1999 Lars Knoll (knoll@kde.org) 2 * Copyright (C) 1999 Lars Knoll (knoll@kde.org)
3 * (C) 1999 Antti Koivisto (koivisto@kde.org) 3 * (C) 1999 Antti Koivisto (koivisto@kde.org)
4 * (C) 2001 Peter Kelly (pmk@post.com) 4 * (C) 2001 Peter Kelly (pmk@post.com)
5 * (C) 2001 Dirk Mueller (mueller@kde.org) 5 * (C) 2001 Dirk Mueller (mueller@kde.org)
6 * (C) 2007 David Smith (catfish.man@gmail.com) 6 * (C) 2007 David Smith (catfish.man@gmail.com)
7 * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2012, 2013 Apple Inc. All rights reserved. 7 * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2012, 2013 Apple Inc. All rights reserved.
8 * (C) 2007 Eric Seidel (eric@webkit.org) 8 * (C) 2007 Eric Seidel (eric@webkit.org)
9 * 9 *
10 * This library is free software; you can redistribute it and/or 10 * This library is free software; you can redistribute it and/or
(...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after
146 DEFINE_STATIC_LOCAL(Persistent<ScrollCustomizationCallbacks>, 146 DEFINE_STATIC_LOCAL(Persistent<ScrollCustomizationCallbacks>,
147 scrollCustomizationCallbacks, (new ScrollCustomizationCallbacks())); 147 scrollCustomizationCallbacks, (new ScrollCustomizationCallbacks()));
148 return *scrollCustomizationCallbacks; 148 return *scrollCustomizationCallbacks;
149 } 149 }
150 150
151 } // namespace 151 } // namespace
152 152
153 using namespace HTMLNames; 153 using namespace HTMLNames;
154 using namespace XMLNames; 154 using namespace XMLNames;
155 155
156 enum class ClassStringContent { Empty, WhiteSpaceOnly, HasClasses };
157
156 PassRefPtrWillBeRawPtr<Element> Element::create(const QualifiedName& tagName, Do cument* document) 158 PassRefPtrWillBeRawPtr<Element> Element::create(const QualifiedName& tagName, Do cument* document)
157 { 159 {
158 return adoptRefWillBeNoop(new Element(tagName, document, CreateElement)); 160 return adoptRefWillBeNoop(new Element(tagName, document, CreateElement));
159 } 161 }
160 162
161 Element::Element(const QualifiedName& tagName, Document* document, ConstructionT ype type) 163 Element::Element(const QualifiedName& tagName, Document* document, ConstructionT ype type)
162 : ContainerNode(document, type) 164 : ContainerNode(document, type)
163 , m_tagName(tagName) 165 , m_tagName(tagName)
164 { 166 {
165 } 167 }
(...skipping 1056 matching lines...) Expand 10 before | Expand all | Expand 10 after
1222 } 1224 }
1223 1225
1224 inline void Element::attributeChangedFromParserOrByCloning(const QualifiedName& name, const AtomicString& newValue, AttributeModificationReason reason) 1226 inline void Element::attributeChangedFromParserOrByCloning(const QualifiedName& name, const AtomicString& newValue, AttributeModificationReason reason)
1225 { 1227 {
1226 if (name == isAttr) 1228 if (name == isAttr)
1227 CustomElementRegistrationContext::setTypeExtension(this, newValue); 1229 CustomElementRegistrationContext::setTypeExtension(this, newValue);
1228 attributeChanged(name, newValue, reason); 1230 attributeChanged(name, newValue, reason);
1229 } 1231 }
1230 1232
1231 template <typename CharacterType> 1233 template <typename CharacterType>
1232 static inline bool classStringHasClassName(const CharacterType* characters, unsi gned length) 1234 static inline ClassStringContent classStringHasClassName(const CharacterType* ch aracters, unsigned length)
1233 { 1235 {
1234 ASSERT(length > 0); 1236 ASSERT(length > 0);
1235 1237
1236 unsigned i = 0; 1238 unsigned i = 0;
1237 do { 1239 do {
1238 if (isNotHTMLSpace<CharacterType>(characters[i])) 1240 if (isNotHTMLSpace<CharacterType>(characters[i]))
1239 break; 1241 break;
1240 ++i; 1242 ++i;
1241 } while (i < length); 1243 } while (i < length);
1242 1244
1243 return i < length; 1245 if (i == length && length == 1)
1246 return ClassStringContent::Empty;
1247 if (i == length && length > 1)
1248 return ClassStringContent::WhiteSpaceOnly;
1249
1250 return ClassStringContent::HasClasses;
1244 } 1251 }
1245 1252
1246 static inline bool classStringHasClassName(const AtomicString& newClassString) 1253 static inline ClassStringContent classStringHasClassName(const AtomicString& new ClassString)
1247 { 1254 {
1248 unsigned length = newClassString.length(); 1255 unsigned length = newClassString.length();
1249 1256
1250 if (!length) 1257 if (!length)
1251 return false; 1258 return ClassStringContent::Empty;
1252 1259
1253 if (newClassString.is8Bit()) 1260 if (newClassString.is8Bit())
1254 return classStringHasClassName(newClassString.characters8(), length); 1261 return classStringHasClassName(newClassString.characters8(), length);
1255 return classStringHasClassName(newClassString.characters16(), length); 1262 return classStringHasClassName(newClassString.characters16(), length);
1256 } 1263 }
1257 1264
1258 void Element::classAttributeChanged(const AtomicString& newClassString) 1265 void Element::classAttributeChanged(const AtomicString& newClassString)
1259 { 1266 {
1260 StyleResolver* styleResolver = document().styleResolver(); 1267 StyleResolver* styleResolver = document().styleResolver();
1261 bool testShouldInvalidateStyle = inActiveDocument() && styleResolver && styl eChangeType() < SubtreeStyleChange; 1268 bool testShouldInvalidateStyle = inActiveDocument() && styleResolver && styl eChangeType() < SubtreeStyleChange;
1262 1269
1263 ASSERT(elementData()); 1270 ASSERT(elementData());
1264 if (classStringHasClassName(newClassString)) { 1271 ClassStringContent classStringContentType = classStringHasClassName(newClass String);
1265 const bool shouldFoldCase = document().inQuirksMode(); 1272 const bool shouldFoldCase = document().inQuirksMode();
1273 if (classStringContentType == ClassStringContent::HasClasses) {
1266 const SpaceSplitString oldClasses = elementData()->classNames(); 1274 const SpaceSplitString oldClasses = elementData()->classNames();
1267 elementData()->setClass(newClassString, shouldFoldCase); 1275 elementData()->setClass(newClassString, shouldFoldCase);
1268 const SpaceSplitString& newClasses = elementData()->classNames(); 1276 const SpaceSplitString& newClasses = elementData()->classNames();
1269 if (testShouldInvalidateStyle) 1277 if (testShouldInvalidateStyle)
1270 document().styleEngine().classChangedForElement(oldClasses, newClass es, *this); 1278 document().styleEngine().classChangedForElement(oldClasses, newClass es, *this);
1271 } else { 1279 } else {
1272 const SpaceSplitString& oldClasses = elementData()->classNames(); 1280 const SpaceSplitString& oldClasses = elementData()->classNames();
1273 if (testShouldInvalidateStyle) 1281 if (testShouldInvalidateStyle)
1274 document().styleEngine().classChangedForElement(oldClasses, *this); 1282 document().styleEngine().classChangedForElement(oldClasses, *this);
1275 elementData()->clearClass(); 1283 if (classStringContentType == ClassStringContent::WhiteSpaceOnly)
1284 elementData()->setClass(newClassString, shouldFoldCase);
1285 else
1286 elementData()->clearClass();
1276 } 1287 }
1277 1288
1278 if (hasRareData()) 1289 if (hasRareData())
1279 elementRareData()->clearClassListValueForQuirksMode(); 1290 elementRareData()->clearClassListValueForQuirksMode();
1280 } 1291 }
1281 1292
1282 bool Element::shouldInvalidateDistributionWhenAttributeChanged(ElementShadow* el ementShadow, const QualifiedName& name, const AtomicString& newValue) 1293 bool Element::shouldInvalidateDistributionWhenAttributeChanged(ElementShadow* el ementShadow, const QualifiedName& name, const AtomicString& newValue)
1283 { 1294 {
1284 ASSERT(elementShadow); 1295 ASSERT(elementShadow);
1285 const SelectRuleFeatureSet& featureSet = elementShadow->ensureSelectFeatureS et(); 1296 const SelectRuleFeatureSet& featureSet = elementShadow->ensureSelectFeatureS et();
1286 1297
1287 if (name == HTMLNames::idAttr) { 1298 if (name == HTMLNames::idAttr) {
1288 AtomicString oldId = elementData()->idForStyleResolution(); 1299 AtomicString oldId = elementData()->idForStyleResolution();
1289 AtomicString newId = makeIdForStyleResolution(newValue, document().inQui rksMode()); 1300 AtomicString newId = makeIdForStyleResolution(newValue, document().inQui rksMode());
1290 if (newId != oldId) { 1301 if (newId != oldId) {
1291 if (!oldId.isEmpty() && featureSet.hasSelectorForId(oldId)) 1302 if (!oldId.isEmpty() && featureSet.hasSelectorForId(oldId))
1292 return true; 1303 return true;
1293 if (!newId.isEmpty() && featureSet.hasSelectorForId(newId)) 1304 if (!newId.isEmpty() && featureSet.hasSelectorForId(newId))
1294 return true; 1305 return true;
1295 } 1306 }
1296 } 1307 }
1297 1308
1298 if (name == HTMLNames::classAttr) { 1309 if (name == HTMLNames::classAttr) {
1299 const AtomicString& newClassString = newValue; 1310 const AtomicString& newClassString = newValue;
1300 if (classStringHasClassName(newClassString)) { 1311 if (classStringHasClassName(newClassString) == ClassStringContent::HasCl asses) {
1301 const SpaceSplitString& oldClasses = elementData()->classNames(); 1312 const SpaceSplitString& oldClasses = elementData()->classNames();
1302 const SpaceSplitString newClasses(newClassString, document().inQuirk sMode() ? SpaceSplitString::ShouldFoldCase : SpaceSplitString::ShouldNotFoldCase ); 1313 const SpaceSplitString newClasses(newClassString, document().inQuirk sMode() ? SpaceSplitString::ShouldFoldCase : SpaceSplitString::ShouldNotFoldCase );
1303 if (featureSet.checkSelectorsForClassChange(oldClasses, newClasses)) 1314 if (featureSet.checkSelectorsForClassChange(oldClasses, newClasses))
1304 return true; 1315 return true;
1305 } else { 1316 } else {
1306 const SpaceSplitString& oldClasses = elementData()->classNames(); 1317 const SpaceSplitString& oldClasses = elementData()->classNames();
1307 if (featureSet.checkSelectorsForClassChange(oldClasses)) 1318 if (featureSet.checkSelectorsForClassChange(oldClasses))
1308 return true; 1319 return true;
1309 } 1320 }
1310 } 1321 }
(...skipping 2253 matching lines...) Expand 10 before | Expand all | Expand 10 after
3564 { 3575 {
3565 #if ENABLE(OILPAN) 3576 #if ENABLE(OILPAN)
3566 if (hasRareData()) 3577 if (hasRareData())
3567 visitor->trace(elementRareData()); 3578 visitor->trace(elementRareData());
3568 visitor->trace(m_elementData); 3579 visitor->trace(m_elementData);
3569 #endif 3580 #endif
3570 ContainerNode::trace(visitor); 3581 ContainerNode::trace(visitor);
3571 } 3582 }
3572 3583
3573 } // namespace blink 3584 } // namespace blink
OLDNEW
« 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