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

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: legacyCaseSensitive->legacyCaseInsensitive; Extend tests. 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 4ab0cf1615c59d4c0a71cf53cb7624bec8292016..e0002e9c386087f040eb69a31d34c0530cce9743 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.attributeFlags() & 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