1010import org .w3c .css .atrules .css .AtRuleFontFace ;
1111import org .w3c .css .atrules .css .AtRulePage ;
1212import org .w3c .css .properties .css .CssProperty ;
13- import org .w3c .css .selectors .AdjacentSiblingSelector ;
1413import org .w3c .css .selectors .AttributeSelector ;
15- import org .w3c .css .selectors .ChildSelector ;
16- import org .w3c .css .selectors .DescendantSelector ;
17- import org .w3c .css .selectors .GeneralSiblingSelector ;
1814import org .w3c .css .selectors .PseudoClassSelector ;
1915import org .w3c .css .selectors .PseudoElementSelector ;
2016import org .w3c .css .selectors .PseudoFactory ;
@@ -57,12 +53,12 @@ public final class CssSelectors extends SelectorsList
5753 */
5854 String element ;
5955
60- char connector = DESCENDANT ;
56+ String connector = DESCENDANT_COMBINATOR ;
6157
6258 /**
6359 * The next context.
6460 */
65- protected CssSelectors next ;
61+ protected CssSelectors next = null ;
6662
6763 // true if the element is a block-level element
6864 private boolean isBlock ;
@@ -75,7 +71,7 @@ public final class CssSelectors extends SelectorsList
7571 //private int hashGeneral;
7672
7773 // The CssStyle to use
78- private static Class style ;
74+ private static Class <?> style ;
7975
8076 // see isEmpty and addProperty
8177 private boolean Init ;
@@ -97,7 +93,7 @@ public CssSelectors(ApplContext ac) {
9793 this .ac = ac ;
9894 }
9995
100- private CssSelectors (Class style ) {
96+ private CssSelectors (Class <?> style ) {
10197 super ();
10298 CssSelectors .style = style ;
10399 try {
@@ -134,7 +130,7 @@ public CssSelectors(ApplContext ac, CssSelectors next) {
134130 *
135131 * @param style0 the style
136132 */
137- public void setStyle (Class style0 ) {
133+ public void setStyle (Class <?> style0 ) {
138134 Util .verbose ("Style is : " + style0 );
139135 style = style0 ;
140136 }
@@ -243,7 +239,7 @@ public void addPseudoElement(String pseudo) throws InvalidParamException {
243239 throw new InvalidParamException ("pseudo" , "::" + pseudo , ac );
244240 }
245241
246- public void setPseudoFun (String pseudo , String param )
242+ public void setPseudoFun (ApplContext ac , String pseudo , String param )
247243 throws InvalidParamException {
248244
249245 CssVersion version = ac .getCssVersion ();
@@ -259,33 +255,57 @@ public void setPseudoFun(String pseudo, String param)
259255 }
260256 }
261257
258+ public void setPseudoFun (ApplContext ac , String pseudo , ArrayList <CssSelectors > selector_list )
259+ throws InvalidParamException {
260+
261+ CssVersion version = ac .getCssVersion ();
262+ String [] ps = PseudoFactory .getPseudoFunction (version );
263+ if (ps != null ) {
264+ for (String s : ps ) {
265+ if (pseudo .equals (s )) {
266+ addPseudoFunction (PseudoFactory .newPseudoFunction (pseudo , selector_list , ac ));
267+ return ;
268+ }
269+ }
270+ throw new InvalidParamException ("pseudo" , ":" + pseudo , ac );
271+ }
272+ }
273+
274+
262275 public void addType (TypeSelector type ) throws InvalidParamException {
263276 super .addType (type );
264277 element = type .getName ();
265278 hashElement = element .hashCode ();
266279 }
267280
268- public void addDescendant ( DescendantSelector descendant )
281+ public void addDescendantCombinator ( )
269282 throws InvalidParamException {
270- super .addDescendant ( descendant );
271- connector = DESCENDANT ;
283+ super .addDescendantCombinator ( );
284+ connector = DESCENDANT_COMBINATOR ;
272285 }
273286
274- public void addChild (ChildSelector child ) throws InvalidParamException {
275- super .addChild (child );
276- connector = CHILD ;
287+ public void addChildCombinator ()
288+ throws InvalidParamException {
289+ super .addChildCombinator ();
290+ connector = CHILD_COMBINATOR ;
277291 }
278292
279- public void addAdjacentSibling ( AdjacentSiblingSelector adjacent )
293+ public void addNextSiblingCombinator ( )
280294 throws InvalidParamException {
281- super .addAdjacentSibling ( adjacent );
282- connector = ADJACENT_SIBLING ;
295+ super .addNextSiblingCombinator ( );
296+ connector = NEXT_SIBLING_COMBINATOR ;
283297 }
284298
285- public void addGeneralSibling ( GeneralSiblingSelector sibling )
299+ public void addSubsequentSiblingCombinator ( )
286300 throws InvalidParamException {
287- super .addGeneralSibling (sibling );
288- connector = GENERAL_SIBLING ;
301+ super .addSubsequentSiblingCombinator ();
302+ connector = SUBSEQUENT_SIBLING_COMBINATOR ;
303+ }
304+
305+ public void addColumnCombinator ()
306+ throws InvalidParamException {
307+ super .addColumnCombinator ();
308+ connector = COLUMN_COMBINATOR ;
289309 }
290310
291311
@@ -381,8 +401,8 @@ marking as final (ie: no more modifications) triggers more
381401 */
382402
383403 /*
384- * Mark as final, ie: no more modification to the structure.
385- */
404+ * Mark as final, ie: no more modification to the structure.
405+ */
386406 public void markAsFinal () {
387407 // if something has been changed, reset to force recomputing
388408 if (!isFinal ) {
@@ -585,7 +605,7 @@ private boolean canMatch(CssSelectors selector) {
585605 Util .verbose ("canMatch for attributes :" + result );
586606
587607 if ((hashElement != selector .hashElement ) && hashElement != 0 ) {
588- if ((connector == DESCENDANT ) && (selector .next != null )) {
608+ if ((connector . equals ( DESCENDANT_COMBINATOR ) ) && (selector .next != null )) {
589609 // here we are in this case :
590610 // H1 and HTML BODY H1 EM
591611 // H1 can't match EM but EM have next
@@ -618,4 +638,21 @@ public void findConflicts(ApplContext ac, Warnings warnings,
618638 CssStyle style = getStyle ();
619639 style .findConflicts (ac , warnings , this , allSelectors );
620640 }
641+
642+ public static String toArrayString (ArrayList <CssSelectors > selectors ) {
643+ if (selectors == null ) {
644+ return "" ;
645+ }
646+ StringBuilder sb = new StringBuilder ();
647+ boolean first = true ;
648+ for (CssSelectors s : selectors ) {
649+ if (!first ) {
650+ sb .append (", " );
651+ } else {
652+ first = false ;
653+ }
654+ sb .append (s );
655+ }
656+ return sb .toString ();
657+ }
621658}
0 commit comments