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

Side by Side Diff: Source/core/css/SelectorChecker.cpp

Issue 140323003: Add UseCounter for case-insensitive attribute value selector matching (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Created 6 years, 11 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 | « no previous file | Source/core/frame/UseCounter.h » ('j') | Source/core/frame/UseCounter.h » ('J')
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) 2004-2005 Allan Sandfeld Jensen (kde@carewolf.com) 3 * (C) 2004-2005 Allan Sandfeld Jensen (kde@carewolf.com)
4 * Copyright (C) 2006, 2007 Nicholas Shanks (webkit@nickshanks.com) 4 * Copyright (C) 2006, 2007 Nicholas Shanks (webkit@nickshanks.com)
5 * Copyright (C) 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012, 2013 Apple Inc. All rights reserved. 5 * Copyright (C) 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012, 2013 Apple Inc. All rights reserved.
6 * Copyright (C) 2007 Alexey Proskuryakov <ap@webkit.org> 6 * Copyright (C) 2007 Alexey Proskuryakov <ap@webkit.org>
7 * Copyright (C) 2007, 2008 Eric Seidel <eric@webkit.org> 7 * Copyright (C) 2007, 2008 Eric Seidel <eric@webkit.org>
8 * Copyright (C) 2008, 2009 Torch Mobile Inc. All rights reserved. (http://www.t orchmobile.com/) 8 * Copyright (C) 2008, 2009 Torch Mobile Inc. All rights reserved. (http://www.t orchmobile.com/)
9 * Copyright (c) 2011, Code Aurora Forum. All rights reserved. 9 * Copyright (c) 2011, Code Aurora Forum. All rights reserved.
10 * Copyright (C) Research In Motion Limited 2011. All rights reserved. 10 * Copyright (C) Research In Motion Limited 2011. All rights reserved.
(...skipping 419 matching lines...) Expand 10 before | Expand all | Expand 10 after
430 ASSERT(selectorAttr.localName() != starAtom); // Should not be possible from the CSS grammar. 430 ASSERT(selectorAttr.localName() != starAtom); // Should not be possible from the CSS grammar.
431 431
432 // Synchronize the attribute in case it is lazy-computed. 432 // Synchronize the attribute in case it is lazy-computed.
433 // Currently all lazy properties have a null namespace, so only pass localNa me(). 433 // Currently all lazy properties have a null namespace, so only pass localNa me().
434 element.synchronizeAttribute(selectorAttr.localName()); 434 element.synchronizeAttribute(selectorAttr.localName());
435 435
436 if (!element.hasAttributesWithoutUpdate()) 436 if (!element.hasAttributesWithoutUpdate())
437 return false; 437 return false;
438 438
439 const AtomicString& selectorValue = selector.value(); 439 const AtomicString& selectorValue = selector.value();
440 // Case sensitivity for attribute matching is looser than hasAttribute or
441 // Element::shouldIgnoreAttributeCase() for now. Unclear if that's correct.
442 bool caseSensitive = !element.document().isHTMLDocument() || HTMLDocument::i sCaseSensitiveAttribute(selectorAttr);
443 440
444 for (size_t i = 0; i < element.attributeCount(); ++i) { 441 for (size_t i = 0; i < element.attributeCount(); ++i) {
445 const Attribute* attributeItem = element.attributeItem(i); 442 const Attribute* attributeItem = element.attributeItem(i);
446 443
447 if (!attributeItem->matches(selectorAttr)) 444 if (!attributeItem->matches(selectorAttr))
448 continue; 445 continue;
449 446
450 if (attributeValueMatches(attributeItem, match, selectorValue, caseSensi tive)) 447 if (attributeValueMatches(attributeItem, match, selectorValue, true))
451 return true; 448 return true;
449
450 // Case sensitivity for attribute matching is looser than hasAttribute o r
451 // Element::shouldIgnoreAttributeCase() for now. Unclear if that's corre ct.
452 bool caseSensitive = !element.document().isHTMLDocument() || HTMLDocumen t::isCaseSensitiveAttribute(selectorAttr);
Mike West 2014/01/23 09:21:14 Why did you move this inside the `for` loop? It ap
Jens Widell 2014/01/23 09:38:49 Moving it is essentially a tiny optimization. It
Mike West 2014/01/23 10:08:24 Hrm. Ok, sounds reasonable. Thanks for the explana
Jens Widell 2014/01/23 10:27:21 Sorry about the unexplained micro-optimizations I
453
454 // If case-insensitive, re-check, and count if result differs.
455 // See http://code.google.com/p/chromium/issues/detail?id=327060
456 if (!caseSensitive && attributeValueMatches(attributeItem, match, select orValue, false)) {
457 UseCounter::count(element.document(), UseCounter::CaseInsensitiveAtt rSelectorMatch);
458 return true;
459 }
452 } 460 }
453 461
454 return false; 462 return false;
455 } 463 }
456 464
457 template<typename SiblingTraversalStrategy> 465 template<typename SiblingTraversalStrategy>
458 bool SelectorChecker::checkOne(const SelectorCheckingContext& context, const Sib lingTraversalStrategy& siblingTraversalStrategy, unsigned* specificity) const 466 bool SelectorChecker::checkOne(const SelectorCheckingContext& context, const Sib lingTraversalStrategy& siblingTraversalStrategy, unsigned* specificity) const
459 { 467 {
460 ASSERT(context.element); 468 ASSERT(context.element);
461 Element& element = *context.element; 469 Element& element = *context.element;
(...skipping 606 matching lines...) Expand 10 before | Expand all | Expand 10 after
1068 return element.focused() && isFrameFocused(element); 1076 return element.focused() && isFrameFocused(element);
1069 } 1077 }
1070 1078
1071 template 1079 template
1072 SelectorChecker::Match SelectorChecker::match(const SelectorCheckingContext&, co nst DOMSiblingTraversalStrategy&, MatchResult*) const; 1080 SelectorChecker::Match SelectorChecker::match(const SelectorCheckingContext&, co nst DOMSiblingTraversalStrategy&, MatchResult*) const;
1073 1081
1074 template 1082 template
1075 SelectorChecker::Match SelectorChecker::match(const SelectorCheckingContext&, co nst ShadowDOMSiblingTraversalStrategy&, MatchResult*) const; 1083 SelectorChecker::Match SelectorChecker::match(const SelectorCheckingContext&, co nst ShadowDOMSiblingTraversalStrategy&, MatchResult*) const;
1076 1084
1077 } 1085 }
OLDNEW
« no previous file with comments | « no previous file | Source/core/frame/UseCounter.h » ('j') | Source/core/frame/UseCounter.h » ('J')

Powered by Google App Engine
This is Rietveld 408576698