@@ -59,6 +59,12 @@ private SelectorSpecificity(final boolean fromStyle, final int idCount, final in
5959 typeCount_ = typeCount ;
6060 }
6161
62+ private void add (final SelectorSpecificity specificity ) {
63+ idCount_ += specificity .idCount_ ;
64+ classCount_ += specificity .classCount_ ;
65+ typeCount_ += specificity .typeCount_ ;
66+ }
67+
6268 private void readSelectorSpecificity (final Selector selector ) {
6369 switch (selector .getSelectorType ()) {
6470 case DESCENDANT_SELECTOR :
@@ -99,6 +105,10 @@ private void readSelectorSpecificity(final Selector selector) {
99105 readSelectorSpecificity (gas .getSelector ());
100106 readSelectorSpecificity (gas .getSimpleSelector ());
101107 return ;
108+ case RELATIVE_SELECTOR :
109+ final RelativeSelector rs = (RelativeSelector ) selector ;
110+ readSelectorSpecificity (rs .getSelector ());
111+ return ;
102112 default :
103113 throw new RuntimeException ("Unhandled CSS selector type for specificity computation: '"
104114 + selector .getSelectorType () + "'." );
@@ -141,16 +151,29 @@ private void readSelectorSpecificity(final Condition condition) {
141151 case IS_PSEUDO_CLASS_CONDITION :
142152 final IsPseudoClassCondition isPseudoCondition = (IsPseudoClassCondition ) condition ;
143153 final SelectorList isSelectorList = isPseudoCondition .getSelectors ();
154+ SelectorSpecificity maxIs = new SelectorSpecificity (false , 0 , 0 , 0 );
144155 for (final Selector selector : isSelectorList ) {
145- readSelectorSpecificity (selector );
156+ final SelectorSpecificity selSpec = new SelectorSpecificity (selector );
157+ if (selSpec .compareTo (maxIs ) > 0 ) {
158+ maxIs = selSpec ;
159+ }
146160 }
161+ add (maxIs );
162+ return ;
163+ case WHERE_PSEUDO_CLASS_CONDITION :
164+ // always 0
147165 return ;
148166 case HAS_PSEUDO_CLASS_CONDITION :
149167 final HasPseudoClassCondition hasPseudoCondition = (HasPseudoClassCondition ) condition ;
150168 final SelectorList hasSelectorList = hasPseudoCondition .getSelectors ();
169+ SelectorSpecificity maxHas = new SelectorSpecificity (false , 0 , 0 , 0 );
151170 for (final Selector selector : hasSelectorList ) {
152- readSelectorSpecificity (selector );
171+ final SelectorSpecificity selSpec = new SelectorSpecificity (selector );
172+ if (selSpec .compareTo (maxHas ) > 0 ) {
173+ maxHas = selSpec ;
174+ }
153175 }
176+ add (maxHas );
154177 return ;
155178 case PSEUDO_CLASS_CONDITION :
156179 classCount_ ++;
0 commit comments