W3C home > Mailing lists > Public > www-validator-cvs@w3.org > February 2012

2002/css-validator/org/w3c/css/properties/css2 CssBackground.java,1.1,1.2 CssBackgroundPosition.java,1.1,1.2 CssBackgroundRepeat.java,1.1,1.2 CssBackgroundImage.java,1.1,1.2

From: Yves Lafon via cvs-syncmail <cvsmail@w3.org>
Date: Mon, 13 Feb 2012 15:48:16 +0000
To: www-validator-cvs@w3.org
Message-Id: <E1Rwy8W-0002P3-8V@lionel-hutz.w3.org>
Update of /sources/public/2002/css-validator/org/w3c/css/properties/css2
In directory hutz:/tmp/cvs-serv9215

Modified Files:
	CssBackground.java CssBackgroundPosition.java 
	CssBackgroundRepeat.java CssBackgroundImage.java 
Log Message:
fixed background-position parsing when present in 'background' shorthand property, fixed also the array output

Index: CssBackgroundImage.java
===================================================================
RCS file: /sources/public/2002/css-validator/org/w3c/css/properties/css2/CssBackgroundImage.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -d -r1.1 -r1.2
--- CssBackgroundImage.java	9 Feb 2012 17:36:30 -0000	1.1
+++ CssBackgroundImage.java	13 Feb 2012 15:48:13 -0000	1.2
@@ -13,6 +13,7 @@
 import org.w3c.css.util.ApplContext;
 import org.w3c.css.util.InvalidParamException;
 import org.w3c.css.values.CssExpression;
+import org.w3c.css.values.CssIdent;
 import org.w3c.css.values.CssTypes;
 import org.w3c.css.values.CssValue;
 
@@ -41,6 +42,10 @@
 
     public CssValue url = null;
 
+    public static boolean checkMatchingIdent(CssIdent ident) {
+        return none.equals(ident);
+    }
+
     /**
      * Create a new CssBackgroundImage
      */

Index: CssBackgroundRepeat.java
===================================================================
RCS file: /sources/public/2002/css-validator/org/w3c/css/properties/css2/CssBackgroundRepeat.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -d -r1.1 -r1.2
--- CssBackgroundRepeat.java	9 Feb 2012 17:36:30 -0000	1.1
+++ CssBackgroundRepeat.java	13 Feb 2012 15:48:13 -0000	1.2
@@ -19,32 +19,7 @@
 import java.util.HashMap;
 
 /**
- * <H4>
- * <A NAME="background-repeat">5.3.4 &nbsp;&nbsp; 'background-repeat'</A>
- * </H4>
- * <p/>
- * <EM>Value:</EM> repeat | repeat-x | repeat-y | no-repeat<BR>
- * <EM>Initial:</EM> repeat<BR>
- * <EM>Applies to:</EM> all elements<BR>
- * <EM>Inherited:</EM> no<BR>
- * <EM>Percentage values:</EM> N/A<BR>
- * <p/>
- * If a background image is specified, the value of 'background-repeat' determines
- * how/if the image is repeated.
- * <p/>
- * A value of 'repeat' means that the image is repeated both horizontally and
- * vertically. The 'repeat-x' ('repeat-y') value makes the image repeat horizontally
- * (vertically), to create a single band of images from one side to the other.
- * With a value of 'no-repeat', the image is not repeated.
- * <PRE>
- * BODY {
- * background: red url(pendant.gif);
- * background-repeat: repeat-y;
- * }
- * </PRE>
- * <p/>
- * In the example above, the image will only be repeated vertically.
- *
+ * @spec http://www.w3.org/TR/2008/REC-CSS2-20080411/colors.html#propdef-background-repeat
  * @version $Revision$
  */
 public class CssBackgroundRepeat extends org.w3c.css.properties.css.CssBackgroundRepeat {

Index: CssBackgroundPosition.java
===================================================================
RCS file: /sources/public/2002/css-validator/org/w3c/css/properties/css2/CssBackgroundPosition.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -d -r1.1 -r1.2
--- CssBackgroundPosition.java	9 Feb 2012 17:36:30 -0000	1.1
+++ CssBackgroundPosition.java	13 Feb 2012 15:48:13 -0000	1.2
@@ -156,7 +156,6 @@
         }
 
         setByUser();
-        setByUser();
         CssValue val;
         CssBackgroundPositionValue b_val = null;
         char op;

Index: CssBackground.java
===================================================================
RCS file: /sources/public/2002/css-validator/org/w3c/css/properties/css2/CssBackground.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -d -r1.1 -r1.2
--- CssBackground.java	9 Feb 2012 17:36:29 -0000	1.1
+++ CssBackground.java	13 Feb 2012 15:48:11 -0000	1.2
@@ -13,7 +13,8 @@
 import org.w3c.css.util.ApplContext;
 import org.w3c.css.util.InvalidParamException;
 import org.w3c.css.values.CssExpression;
-import org.w3c.css.values.CssString;
+import org.w3c.css.values.CssIdent;
+import org.w3c.css.values.CssTypes;
 import org.w3c.css.values.CssValue;
 
 import static org.w3c.css.values.CssOperator.SPACE;
@@ -108,8 +109,9 @@
                          boolean check) throws InvalidParamException {
 
         CssValue val;
-        char op;
+        char op = SPACE;
         boolean find = true;
+        CssExpression background_position_expression = null;
 
         // too many values
         if (check && expression.getCount() > 6) {
@@ -121,79 +123,120 @@
         boolean manyValues = (expression.getCount() > 1);
 
         while (find) {
-            find = false;
             val = expression.getValue();
-            op = expression.getOperator();
-
             if (val == null) {
                 break;
             }
+            op = expression.getOperator();
 
-            if (inherit.equals(val)) {
-                if (manyValues) {
             // if there are many values, we can't have inherit as one of them
-                    throw new InvalidParamException("unrecognize", null, null, ac);
-                }
-                same = true;
-                expression.next();
-                // we exit as find is false
-                continue;
+            if (manyValues && val.equals(inherit)) {
+                throw new InvalidParamException("unrecognize", null, null, ac);
             }
 
+            switch (val.getType()) {
+                case CssTypes.CSS_STRING:
+                    if (check) {
+                        throw new InvalidParamException("unrecognize", ac);
+                    }
+                    find = false;
+                    break;
+                case CssTypes.CSS_URL:
+                    if (getImage() == null) {
+                        setImage(new CssBackgroundImage(ac, expression));
+                        continue;
+                    }
+                    find = false;
+                    break;
+                case CssTypes.CSS_COLOR:
+                    if (getColor2() == null) {
+                        setColor(new CssBackgroundColor(ac, expression));
+                        continue;
+                    }
+                    find = false;
+                    break;
+                case CssTypes.CSS_NUMBER:
+                case CssTypes.CSS_PERCENTAGE:
+                case CssTypes.CSS_LENGTH:
+                    if (background_position_expression == null) {
+                        background_position_expression = new CssExpression();
+                    }
+                    background_position_expression.addValue(val);
+                    expression.next();
+                    find = true;
+                    break;
+                case CssTypes.CSS_IDENT:
+                    // the hard part, as ident can be from different subproperties
+                    find = false;
+                    CssIdent identval = (CssIdent) val;
+                    if (inherit.equals(identval) && !manyValues) {
+                        find = true;
+                        same = true;
+                        expression.next();
+                        break;
+                    }
+                    // check background-image ident
+                    if (CssBackgroundImage.checkMatchingIdent(identval)) {
+                        if (getImage() == null) {
+                            setImage(new CssBackgroundImage(ac, expression));
+                            find = true;
+                        }
+                        break;
+                    }
+                    // check background-repeat ident
+                    if (CssBackgroundRepeat.checkMatchingIdent(identval)) {
+                        if (getRepeat() == null) {
+                            setRepeat(new CssBackgroundRepeat(ac, expression));
+                            find = true;
+                        }
+                        break;
+                    }
+                    // check background-attachment ident
+                    if (CssBackgroundAttachment.checkMatchingIdent(identval)) {
+                        if (getAttachment() == null) {
+                            setAttachment(new CssBackgroundAttachment(ac, expression));
+                            find = true;
+                        }
+                        break;
+                    }
+                    // check background-position ident
+                    if (CssBackgroundPosition.checkMatchingIdent(identval)) {
+                        if (background_position_expression == null) {
+                            background_position_expression = new CssExpression();
+                        }
+                        background_position_expression.addValue(val);
+                        expression.next();
+                        find = true;
+                        break;
+                    }
 
-            // quoted strings are not allowed (CssString)
-            if (check && (val instanceof CssString)) {
-                throw new InvalidParamException("unrecognize", ac);
-            }
+                    if (getColor2() == null) {
+                        try {
+                            setColor(new CssBackgroundColor(ac, expression));
+                            find = true;
+                            break;
+                        } catch (InvalidParamException e) {
+                            // nothing to do, image will test this value
+                        }
+                    }
 
-            if (color == null) {
-                try {
-                    color = new CssBackgroundColor(ac, expression);
-                    find = true;
-                } catch (InvalidParamException e) {
-                    // nothing to do, image will test this value
-                }
-            }
-            if (!find && image == null) {
-                try {
-                    image = new CssBackgroundImage(ac, expression);
-                    find = true;
-                } catch (InvalidParamException e) {
-                    // nothing to do, repeat will test this value
-                }
-            }
-            if (!find && repeat == null) {
-                try {
-                    repeat = new CssBackgroundRepeat(ac, expression);
-                    find = true;
-                } catch (InvalidParamException e) {
-                    // nothing to do, attachment will test this value
-                }
-            }
-            if (!find && attachment == null) {
-                try {
-                    attachment = new CssBackgroundAttachment(ac, expression);
-                    find = true;
-                } catch (InvalidParamException e) {
-                    // nothing to do, position will test this value
-                }
+                default:
+                    if (check) {
+                        throw new InvalidParamException("unrecognize", ac);
+                    }
+                    find = false;
             }
-            if (!find && position == null) {
-                try {
-                    position = new CssBackgroundPosition(ac, expression);
-                    find = true;
-                } catch (InvalidParamException e) {
-                    // nothing to do
-                }
+            if (check && !find) {
+                throw new InvalidParamException("unrecognize", ac);
             }
             if (op != SPACE) {
                 throw new InvalidParamException("operator",
-                        ((new Character(op)).toString()),
+                        Character.toString(op),
                         ac);
             }
-            if (!find && val != null) {
-                throw new InvalidParamException("unrecognize", ac);
-            }
+        }
+        if (background_position_expression != null) {
+            setPosition(new CssBackgroundPosition(ac, background_position_expression, check));
         }
     }
 
Received on Monday, 13 February 2012 15:48:25 GMT

This archive was generated by hypermail 2.2.0+W3C-0.50 : Thursday, 26 April 2012 12:55:32 GMT