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

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 1211 matching lines...) Expand 10 before | Expand all | Expand 10 after
1222 } 1222 }
1223 1223
1224 inline void Element::attributeChangedFromParserOrByCloning(const QualifiedName& name, const AtomicString& newValue, AttributeModificationReason reason) 1224 inline void Element::attributeChangedFromParserOrByCloning(const QualifiedName& name, const AtomicString& newValue, AttributeModificationReason reason)
1225 { 1225 {
1226 if (name == isAttr) 1226 if (name == isAttr)
1227 CustomElementRegistrationContext::setTypeExtension(this, newValue); 1227 CustomElementRegistrationContext::setTypeExtension(this, newValue);
1228 attributeChanged(name, newValue, reason); 1228 attributeChanged(name, newValue, reason);
1229 } 1229 }
1230 1230
1231 template <typename CharacterType> 1231 template <typename CharacterType>
1232 static inline bool classStringHasClassName(const CharacterType* characters, unsi gned length) 1232 static inline bool classStringHasClassName(const CharacterType* characters, unsi gned length, bool& isWhiteSpaceOnly)
tkent 2015/10/08 23:20:12 We should introduce an enum, and this function sho
1233 { 1233 {
1234 ASSERT(length > 0); 1234 ASSERT(length > 0);
1235 1235
1236 isWhiteSpaceOnly = false;
1236 unsigned i = 0; 1237 unsigned i = 0;
1237 do { 1238 do {
1238 if (isNotHTMLSpace<CharacterType>(characters[i])) 1239 if (isNotHTMLSpace<CharacterType>(characters[i]))
1239 break; 1240 break;
1240 ++i; 1241 ++i;
1241 } while (i < length); 1242 } while (i < length);
1242 1243
1244 if (i == length)
1245 isWhiteSpaceOnly = true;
1246
1243 return i < length; 1247 return i < length;
1244 } 1248 }
1245 1249
1246 static inline bool classStringHasClassName(const AtomicString& newClassString) 1250 static inline bool classStringHasClassName(const AtomicString& newClassString, b ool& isWhiteSpaceOnly)
1247 { 1251 {
1248 unsigned length = newClassString.length(); 1252 unsigned length = newClassString.length();
1249 1253
1250 if (!length) 1254 if (!length)
1251 return false; 1255 return false;
1252 1256
1253 if (newClassString.is8Bit()) 1257 if (newClassString.is8Bit())
1254 return classStringHasClassName(newClassString.characters8(), length); 1258 return classStringHasClassName(newClassString.characters8(), length, isW hiteSpaceOnly);
1255 return classStringHasClassName(newClassString.characters16(), length); 1259 return classStringHasClassName(newClassString.characters16(), length, isWhit eSpaceOnly);
1256 } 1260 }
1257 1261
1258 void Element::classAttributeChanged(const AtomicString& newClassString) 1262 void Element::classAttributeChanged(const AtomicString& newClassString)
1259 { 1263 {
1260 StyleResolver* styleResolver = document().styleResolver(); 1264 StyleResolver* styleResolver = document().styleResolver();
1261 bool testShouldInvalidateStyle = inActiveDocument() && styleResolver && styl eChangeType() < SubtreeStyleChange; 1265 bool testShouldInvalidateStyle = inActiveDocument() && styleResolver && styl eChangeType() < SubtreeStyleChange;
1262 1266
1263 ASSERT(elementData()); 1267 ASSERT(elementData());
1264 if (classStringHasClassName(newClassString)) { 1268
1265 const bool shouldFoldCase = document().inQuirksMode(); 1269 bool isWhiteSpaceOnlyClassname;
tkent 2015/10/08 23:20:12 This variable needs to be initialized, or classStr
1270 const bool shouldFoldCase = document().inQuirksMode();
1271 if (classStringHasClassName(newClassString, isWhiteSpaceOnlyClassname)) {
1266 const SpaceSplitString oldClasses = elementData()->classNames(); 1272 const SpaceSplitString oldClasses = elementData()->classNames();
1267 elementData()->setClass(newClassString, shouldFoldCase); 1273 elementData()->setClass(newClassString, shouldFoldCase);
1268 const SpaceSplitString& newClasses = elementData()->classNames(); 1274 const SpaceSplitString& newClasses = elementData()->classNames();
1269 if (testShouldInvalidateStyle) 1275 if (testShouldInvalidateStyle)
1270 document().styleEngine().classChangedForElement(oldClasses, newClass es, *this); 1276 document().styleEngine().classChangedForElement(oldClasses, newClass es, *this);
1271 } else { 1277 } else {
1272 const SpaceSplitString& oldClasses = elementData()->classNames(); 1278 const SpaceSplitString& oldClasses = elementData()->classNames();
1273 if (testShouldInvalidateStyle) 1279 if (testShouldInvalidateStyle)
1274 document().styleEngine().classChangedForElement(oldClasses, *this); 1280 document().styleEngine().classChangedForElement(oldClasses, *this);
1275 elementData()->clearClass(); 1281 if (isWhiteSpaceOnlyClassname)
1282 elementData()->setClass(newClassString, shouldFoldCase);
1283 else
1284 elementData()->clearClass();
1276 } 1285 }
1277 1286
1278 if (hasRareData()) 1287 if (hasRareData())
1279 elementRareData()->clearClassListValueForQuirksMode(); 1288 elementRareData()->clearClassListValueForQuirksMode();
1280 } 1289 }
1281 1290
1282 bool Element::shouldInvalidateDistributionWhenAttributeChanged(ElementShadow* el ementShadow, const QualifiedName& name, const AtomicString& newValue) 1291 bool Element::shouldInvalidateDistributionWhenAttributeChanged(ElementShadow* el ementShadow, const QualifiedName& name, const AtomicString& newValue)
1283 { 1292 {
1284 ASSERT(elementShadow); 1293 ASSERT(elementShadow);
1285 const SelectRuleFeatureSet& featureSet = elementShadow->ensureSelectFeatureS et(); 1294 const SelectRuleFeatureSet& featureSet = elementShadow->ensureSelectFeatureS et();
1286 1295
1287 if (name == HTMLNames::idAttr) { 1296 if (name == HTMLNames::idAttr) {
1288 AtomicString oldId = elementData()->idForStyleResolution(); 1297 AtomicString oldId = elementData()->idForStyleResolution();
1289 AtomicString newId = makeIdForStyleResolution(newValue, document().inQui rksMode()); 1298 AtomicString newId = makeIdForStyleResolution(newValue, document().inQui rksMode());
1290 if (newId != oldId) { 1299 if (newId != oldId) {
1291 if (!oldId.isEmpty() && featureSet.hasSelectorForId(oldId)) 1300 if (!oldId.isEmpty() && featureSet.hasSelectorForId(oldId))
1292 return true; 1301 return true;
1293 if (!newId.isEmpty() && featureSet.hasSelectorForId(newId)) 1302 if (!newId.isEmpty() && featureSet.hasSelectorForId(newId))
1294 return true; 1303 return true;
1295 } 1304 }
1296 } 1305 }
1297 1306
1298 if (name == HTMLNames::classAttr) { 1307 if (name == HTMLNames::classAttr) {
1299 const AtomicString& newClassString = newValue; 1308 const AtomicString& newClassString = newValue;
1300 if (classStringHasClassName(newClassString)) { 1309 bool isWhiteSpaceOnlyClassname;
1310 if (classStringHasClassName(newClassString, isWhiteSpaceOnlyClassname)) {
1301 const SpaceSplitString& oldClasses = elementData()->classNames(); 1311 const SpaceSplitString& oldClasses = elementData()->classNames();
1302 const SpaceSplitString newClasses(newClassString, document().inQuirk sMode() ? SpaceSplitString::ShouldFoldCase : SpaceSplitString::ShouldNotFoldCase ); 1312 const SpaceSplitString newClasses(newClassString, document().inQuirk sMode() ? SpaceSplitString::ShouldFoldCase : SpaceSplitString::ShouldNotFoldCase );
1303 if (featureSet.checkSelectorsForClassChange(oldClasses, newClasses)) 1313 if (featureSet.checkSelectorsForClassChange(oldClasses, newClasses))
1304 return true; 1314 return true;
1305 } else { 1315 } else {
1306 const SpaceSplitString& oldClasses = elementData()->classNames(); 1316 const SpaceSplitString& oldClasses = elementData()->classNames();
1307 if (featureSet.checkSelectorsForClassChange(oldClasses)) 1317 if (featureSet.checkSelectorsForClassChange(oldClasses))
1308 return true; 1318 return true;
1309 } 1319 }
1310 } 1320 }
(...skipping 2253 matching lines...) Expand 10 before | Expand all | Expand 10 after
3564 { 3574 {
3565 #if ENABLE(OILPAN) 3575 #if ENABLE(OILPAN)
3566 if (hasRareData()) 3576 if (hasRareData())
3567 visitor->trace(elementRareData()); 3577 visitor->trace(elementRareData());
3568 visitor->trace(m_elementData); 3578 visitor->trace(m_elementData);
3569 #endif 3579 #endif
3570 ContainerNode::trace(visitor); 3580 ContainerNode::trace(visitor);
3571 } 3581 }
3572 3582
3573 } // namespace blink 3583 } // 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