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

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

Issue 1149913008: Compute the linkMatchType inside the CSSSelectorParser. (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Created 5 years, 6 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 | Annotate | Revision Log
OLDNEW
1 /* 1 /*
2 * Copyright (C) 1999-2003 Lars Knoll (knoll@kde.org) 2 * Copyright (C) 1999-2003 Lars Knoll (knoll@kde.org)
3 * 1999 Waldo Bastian (bastian@kde.org) 3 * 1999 Waldo Bastian (bastian@kde.org)
4 * 2001 Andreas Schlapbach (schlpbch@iam.unibe.ch) 4 * 2001 Andreas Schlapbach (schlpbch@iam.unibe.ch)
5 * 2001-2003 Dirk Mueller (mueller@kde.org) 5 * 2001-2003 Dirk Mueller (mueller@kde.org)
6 * Copyright (C) 2002, 2006, 2007, 2008, 2009, 2010 Apple Inc. All rights reserv ed. 6 * Copyright (C) 2002, 2006, 2007, 2008, 2009, 2010 Apple Inc. All rights reserv ed.
7 * Copyright (C) 2008 David Smith (catfish.man@gmail.com) 7 * Copyright (C) 2008 David Smith (catfish.man@gmail.com)
8 * Copyright (C) 2010 Google Inc. All rights reserved. 8 * Copyright (C) 2010 Google Inc. All rights reserved.
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 835 matching lines...) Expand 10 before | Expand all | Expand 10 after
846 if (!validateSubSelector(subSelector)) 846 if (!validateSubSelector(subSelector))
847 return false; 847 return false;
848 848
849 prevSubSelector = subSelector; 849 prevSubSelector = subSelector;
850 subSelector = subSelector->tagHistory(); 850 subSelector = subSelector->tagHistory();
851 } 851 }
852 852
853 return true; 853 return true;
854 } 854 }
855 855
856 unsigned CSSSelector::computeLinkMatchType() const 856 void CSSSelector::updateLinkMatchType()
857 { 857 {
858 unsigned linkMatchType = MatchAll;
859
860 // Determine if this selector will match a link in visited, unvisited or any state, or never. 858 // Determine if this selector will match a link in visited, unvisited or any state, or never.
861 // :visited never matches other elements than the innermost link element. 859 // :visited never matches other elements than the innermost link element.
862 for (const CSSSelector* current = this; current; current = current->tagHisto ry()) { 860 for (const CSSSelector* current = this; current; current = current->tagHisto ry()) {
863 switch (current->pseudoType()) { 861 switch (current->pseudoType()) {
864 case PseudoNot: 862 case PseudoNot:
865 { 863 {
866 // :not(:visited) is equivalent to :link. Parser enforces that : not can't nest. 864 // :not(:visited) is equivalent to :link. Parser enforces that : not can't nest.
867 ASSERT(current->selectorList()); 865 ASSERT(current->selectorList());
868 for (const CSSSelector* subSelector = current->selectorList()->f irst(); subSelector; subSelector = subSelector->tagHistory()) { 866 for (const CSSSelector* subSelector = current->selectorList()->f irst(); subSelector; subSelector = subSelector->tagHistory()) {
869 PseudoType subType = subSelector->pseudoType(); 867 PseudoType subType = subSelector->pseudoType();
870 if (subType == PseudoVisited) 868 if (subType == PseudoVisited)
871 linkMatchType &= ~MatchVisited; 869 m_linkMatchType &= ~MatchVisited;
872 else if (subType == PseudoLink) 870 else if (subType == PseudoLink)
873 linkMatchType &= ~MatchLink; 871 m_linkMatchType &= ~MatchLink;
874 } 872 }
875 } 873 }
876 break; 874 break;
877 case PseudoLink: 875 case PseudoLink:
878 linkMatchType &= ~MatchVisited; 876 m_linkMatchType &= ~MatchVisited;
879 break; 877 break;
880 case PseudoVisited: 878 case PseudoVisited:
881 linkMatchType &= ~MatchLink; 879 m_linkMatchType &= ~MatchLink;
882 break; 880 break;
883 default: 881 default:
884 // We don't support :link and :visited inside :-webkit-any. 882 // We don't support :link and :visited inside :-webkit-any.
885 break; 883 break;
886 } 884 }
887 Relation relation = current->relation(); 885 Relation relation = current->relation();
888 if (relation == SubSelector) 886 if (relation == SubSelector)
889 continue; 887 continue;
890 if (relation != Descendant && relation != Child) 888 if (relation != Descendant && relation != Child)
891 return linkMatchType; 889 return;
892 if (linkMatchType != MatchAll) 890 if (m_linkMatchType != MatchAll)
893 return linkMatchType; 891 return;
894 } 892 }
895 return linkMatchType;
896 } 893 }
897 894
898 void CSSSelector::setNth(int a, int b) 895 void CSSSelector::setNth(int a, int b)
899 { 896 {
900 createRareData(); 897 createRareData();
901 m_data.m_rareData->m_bits.m_nth.m_a = a; 898 m_data.m_rareData->m_bits.m_nth.m_a = a;
902 m_data.m_rareData->m_bits.m_nth.m_b = b; 899 m_data.m_rareData->m_bits.m_nth.m_b = b;
903 } 900 }
904 901
905 bool CSSSelector::matchNth(int count) const 902 bool CSSSelector::matchNth(int count) const
(...skipping 23 matching lines...) Expand all
929 if (count < nthBValue()) 926 if (count < nthBValue())
930 return false; 927 return false;
931 return (count - nthBValue()) % nthAValue() == 0; 928 return (count - nthBValue()) % nthAValue() == 0;
932 } 929 }
933 if (count > nthBValue()) 930 if (count > nthBValue())
934 return false; 931 return false;
935 return (nthBValue() - count) % (-nthAValue()) == 0; 932 return (nthBValue() - count) % (-nthAValue()) == 0;
936 } 933 }
937 934
938 } // namespace blink 935 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698