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

Unified Diff: Source/core/css/SelectorChecker.cpp

Issue 330043003: Add support for case-insensitive attribute value selectors (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Move zero-initialization of m_bits to RareData constructor (explicitly). Created 6 years, 5 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
Index: Source/core/css/SelectorChecker.cpp
diff --git a/Source/core/css/SelectorChecker.cpp b/Source/core/css/SelectorChecker.cpp
index c72ced2d974f11f2872da95fccd1f0ed376bf989..e84007f2ab91558190479e06bf20f10fffbfc796 100644
--- a/Source/core/css/SelectorChecker.cpp
+++ b/Source/core/css/SelectorChecker.cpp
@@ -470,7 +470,8 @@ static bool anyAttributeMatches(Element& element, CSSSelector::Match match, cons
if (!element.hasAttributesWithoutUpdate())
return false;
- const AtomicString& selectorValue = selector.value();
+ const AtomicString& selectorValue = selector.value();
+ bool caseInsensitive = selector.attributeMatchType() == CSSSelector::CaseInsensitive;
AttributeCollection attributes = element.attributes();
AttributeCollection::const_iterator end = attributes.end();
@@ -480,16 +481,20 @@ static bool anyAttributeMatches(Element& element, CSSSelector::Match match, cons
if (!attributeItem.matches(selectorAttr))
continue;
- if (attributeValueMatches(attributeItem, match, selectorValue, true))
+ if (attributeValueMatches(attributeItem, match, selectorValue, !caseInsensitive))
return true;
- // Case sensitivity for attribute matching is looser than hasAttribute or
- // Element::shouldIgnoreAttributeCase() for now. Unclear if that's correct.
- bool caseSensitive = !element.document().isHTMLDocument() || HTMLDocument::isCaseSensitiveAttribute(selectorAttr);
+ if (caseInsensitive)
+ continue;
+
+ // Legacy dictates that values of some attributes should be compared in
+ // a case-insensitive manner regardless of whether the case insensitive
+ // flag is set or not.
+ bool legacyCaseInsensitive = element.document().isHTMLDocument() && !HTMLDocument::isCaseSensitiveAttribute(selectorAttr);
// If case-insensitive, re-check, and count if result differs.
// See http://code.google.com/p/chromium/issues/detail?id=327060
- if (!caseSensitive && attributeValueMatches(attributeItem, match, selectorValue, false)) {
+ if (legacyCaseInsensitive && attributeValueMatches(attributeItem, match, selectorValue, false)) {
UseCounter::count(element.document(), UseCounter::CaseInsensitiveAttrSelectorMatch);
return true;
}

Powered by Google App Engine
This is Rietveld 408576698