2002/css-validator/org/w3c/css/properties/css3 Css3Style.java,1.16,1.17 CssBoxShadow.java,1.3,1.4

Update of /sources/public/2002/css-validator/org/w3c/css/properties/css3
In directory hutz:/tmp/cvs-serv18171/css/properties/css3

Modified Files:
	Css3Style.java CssBoxShadow.java 
Log Message:
box-shadow support

Index: Css3Style.java
===================================================================
RCS file: /sources/public/2002/css-validator/org/w3c/css/properties/css3/Css3Style.java,v
retrieving revision 1.16
retrieving revision 1.17
diff -u -d -r1.16 -r1.17
--- Css3Style.java	9 Feb 2012 17:36:32 -0000	1.16
+++ Css3Style.java	4 Apr 2012 13:58:57 -0000	1.17
@@ -27,6 +27,7 @@
 import org.w3c.css.properties.css.CssColumnWidth;
 import org.w3c.css.properties.css.CssColumns;
 import org.w3c.css.properties.css.CssOpacity;
+import org.w3c.css.properties.css.CssBoxShadow;
 import org.w3c.css.util.ApplContext;
 import org.w3c.css.util.Util;
 import org.w3c.css.util.Warning;
@@ -34,7 +35,6 @@
 
 public class Css3Style extends ATSCStyle {
 
-    public CssOpacity cssOpacity;
     CssColorProfile cssColorProfile;
     CssRenderIntent cssRenderIntent;
     CssFontEffect cssFontEffect;
@@ -110,9 +110,8 @@
     CssClearCSS3 cssClearCSS3;
     CssLineHeightPolicy cssLineHeightPolicy;
     CssLineBoxContain cssLineBoxContain;
-    public CssBackgroundClip cssBackgroundClip;
-    public CssBackgroundSize cssBackgroundSize;
-    public CssBackgroundOrigin cssBackgroundOrigin;
+
+
     CssTextDecorationCSS3 cssTextDecoration;
     CssAllSpaceTreatment cssAllSpaceTreatment;
     CssHangingPunctuation cssHangingPunctuation;
@@ -127,6 +126,10 @@
     CssWhiteSpaceTreatment cssWhiteSpaceTreatment;
     CssWrapOption cssWrapOption;
 
+    public CssOpacity cssOpacity;
+    public CssBackgroundClip cssBackgroundClip;
+    public CssBackgroundSize cssBackgroundSize;
+    public CssBackgroundOrigin cssBackgroundOrigin;
     public CssColumns cssColumns;
     public CssColumnCount cssColumnCount;
     public CssColumnFill cssColumnFill;
@@ -140,6 +143,7 @@
     public CssBreakAfter cssBreakAfter;
     public CssBreakBefore cssBreakBefore;
     public CssBreakInside cssBreakInside;
+    public CssBoxShadow cssBoxShadow;
 
     CssDropInitialAfterAdjust cssDropInitialAfterAdjust;
     CssDropInitialAfterAlign cssDropInitialAfterAlign;
@@ -224,7 +228,6 @@
     CssBorderCornerFit cssBorderCornerFit;
     CssBorderImageTransform cssBorderImageTransform;
     CssBorderBreak cssBorderBreak;
-    CssBoxShadow cssBoxShadow;
     CssTextIndentCSS3 cssTextIndentCSS3;
     CssBlockProgression cssBlockProgression;
 

Index: CssBoxShadow.java
===================================================================
RCS file: /sources/public/2002/css-validator/org/w3c/css/properties/css3/CssBoxShadow.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -d -r1.3 -r1.4
--- CssBoxShadow.java	5 Jan 2010 13:49:50 -0000	1.3
+++ CssBoxShadow.java	4 Apr 2012 13:58:57 -0000	1.4
@@ -1,182 +1,251 @@
-//
 // $Id$
 // From Sijtsche de Jong (sy.de.jong@let.rug.nl)
+// Rewritten 2012 by Yves Lafon <ylafon@w3.org>
 //
-// (c) COPYRIGHT 1995-2000  World Wide Web Consortium (MIT, INRIA, Keio University)
+// (c) COPYRIGHT 1995-2012  World Wide Web Consortium (MIT, ERCIM, Keio University)
 // Please first read the full copyright statement at
 // http://www.w3.org/Consortium/Legal/copyright-software-19980720
 
 package org.w3c.css.properties.css3;
 
-import org.w3c.css.parser.CssStyle;
 import org.w3c.css.properties.css.CssProperty;
 import org.w3c.css.util.ApplContext;
 import org.w3c.css.util.InvalidParamException;
-import org.w3c.css.values.CssColor;
 import org.w3c.css.values.CssExpression;
 import org.w3c.css.values.CssIdent;
 import org.w3c.css.values.CssLength;
-import org.w3c.css.values.CssOperator;
+import org.w3c.css.values.CssNumber;
+import org.w3c.css.values.CssTypes;
 import org.w3c.css.values.CssValue;
+import org.w3c.css.values.CssValueList;
 
+import java.util.ArrayList;
 
+import static org.w3c.css.values.CssOperator.COMMA;
+import static org.w3c.css.values.CssOperator.SPACE;
 
-public class CssBoxShadow extends CssProperty implements CssOperator {
 
-    String value = "";
-    ApplContext ac;
-    CssIdent none = new CssIdent("none");
+public class CssBoxShadow extends org.w3c.css.properties.css.CssBoxShadow {
+
+    public static CssIdent inset;
+    Object value;
+
+    static {
+        inset = CssIdent.getIdent("inset");
+    }
 
     /**
      * Create new CssBoxShadow
      */
     public CssBoxShadow() {
-	value = "none";
+        value = none;
     }
 
     /**
      * Create new CssBoxShadow
      *
      * @param expression The expression for this property
-     * @exception InvalidParamException Values are incorrect
+     * @throws InvalidParamException Values are incorrect
      */
     public CssBoxShadow(ApplContext ac, CssExpression expression,
-	    boolean check) throws InvalidParamException {
-	setByUser();
-	CssValue val = expression.getValue();
-	char op = COMMA;
-
-	if (val instanceof CssIdent) {
-	    if (val.equals(none)) {
-		value = "none";
-		expression.next();
-	    } else if (val.equals(inherit)) {
-		value = "inherit";
-		expression.next();
-	    }
-	} else {
-
-	    // <length> <length> <length>? || <color> [, <length> <length> <length>? || <color>]+
-
-	    int lengthcounter = 0;
-	    int runs = 1;
+                        boolean check) throws InvalidParamException {
+        CssExpression single_layer = null;
+        ArrayList<CssBoxShadowValue> values;
+        CssBoxShadowValue boxShadowValue;
 
-	    for (int i = 0; i < expression.getCount(); i++) {
+        setByUser();
+        CssValue val = expression.getValue();
+        char op = expression.getOperator();
 
-		if (op != COMMA) {
-		    throw new InvalidParamException("operator",
-			    ((new Character(op)).toString()), ac);
-		} else if (runs != 1) {
-		    value += ", ";
-		}
+        if (expression.getCount() == 1) {
+            // it can be only 'none' or 'inherit'
+            if (val.getType() == CssTypes.CSS_IDENT) {
+                CssIdent ident = (CssIdent) val;
+                if (inherit.equals(ident)) {
+                    value = inherit;
+                    expression.next();
+                    return;
+                } else if (none.equals(ident)) {
+                    value = none;
+                    expression.next();
+                    return;
+                }
+            }
+            // if it is another ident, or not an ident, fail.
+            throw new InvalidParamException("value", expression.getValue(),
+                    getPropertyName(), ac);
+        }
+        // ok, so we have one or multiple layers here...
+        values = new ArrayList<CssBoxShadowValue>();
 
-		val = expression.getValue();
+        while (!expression.end()) {
+            val = expression.getValue();
+            op = expression.getOperator();
 
-		if (val != null) {
+            if (single_layer == null) {
+                single_layer = new CssExpression();
+            }
+            single_layer.addValue(val);
+            single_layer.setOperator(op);
+            expression.next();
 
-		    while (val instanceof CssLength && lengthcounter < 3) {
-			value += val.toString() + " ";
-			expression.next();
-			i++;
-			val = expression.getValue();
-			lengthcounter++;
-		    }
+            if (!expression.end()) {
+                // incomplete value followed by a comma... it's complete!
+                if (op == COMMA) {
+                    single_layer.setOperator(SPACE);
+                    boxShadowValue = check(ac, single_layer, check);
+                    values.add(boxShadowValue);
+                    single_layer = null;
+                } else if ((op != SPACE)) {
+                    throw new InvalidParamException("operator",
+                            ((new Character(op)).toString()), ac);
+                }
+            }
+        }
+        // if we reach the end in a value that can come in pair
+        if (single_layer != null) {
+            boxShadowValue = check(ac, single_layer, check);
+            values.add(boxShadowValue);
+        }
+        if (values.size() == 1) {
+            value = values.get(0);
+        } else {
+            value = values;
+        }
 
-		    if (lengthcounter == 2 || lengthcounter == 3) {
-			if (val instanceof CssColor) {
-			    value += val.toString() + " ";
-			} else {
-			    value += (new org.w3c.css.values.CssColor(ac, (String) val.get())).toString() + " ";
-			}
-		    } else {
-			throw new InvalidParamException("value", expression.getValue(),
-				getPropertyName(), ac);
-		    }
-		} else {
+    }
 
-		    if (runs < 2) {
-			throw new InvalidParamException("value", expression.getValue(),
-				getPropertyName(), ac);
-		    }
+    public CssBoxShadowValue check(ApplContext ac, CssExpression expression,
+                                   boolean check)
+            throws InvalidParamException {
+        if (check && expression.getCount() > 6) {
+            throw new InvalidParamException("unrecognize", ac);
+        }
+        CssValue val;
+        char op;
+        CssBoxShadowValue value = new CssBoxShadowValue();
+        boolean length_ok = true;
+        int got_length = 0;
 
-		    value = value.trim();
-		    return;
-		}
+        while (!expression.end()) {
+            val = expression.getValue();
+            op = expression.getOperator();
+            switch (val.getType()) {
+                case CssTypes.CSS_NUMBER:
+                    val = ((CssNumber) val).getLength();
+                case CssTypes.CSS_LENGTH:
+                    if (!length_ok) {
+                        throw new InvalidParamException("value", val,
+                                getPropertyName(), ac);
+                    }
+                    got_length++;
+                    switch (got_length) {
+                        case 1:
+                            value.horizontal_offset = val;
+                            break;
+                        case 2:
+                            value.vertical_offset = val;
+                            break;
+                        case 3:
+                            CssLength length = (CssLength) val;
+                            if (!length.isPositive()) {
+                                throw new InvalidParamException("negative-value",
+                                        expression.getValue(),
+                                        getPropertyName(), ac);
 
-		op = expression.getOperator();
-		lengthcounter = 0;
-		expression.next();
-		runs++;
-	    }
-	}
+                            }
+                            value.blur_radius = length;
+                            break;
+                        case 4:
+                            value.spread_distance = val;
+                            break;
+                        default:
+                            throw new InvalidParamException("value", val,
+                                    getPropertyName(), ac);
+                    }
+                    break;
+                case CssTypes.CSS_IDENT:
+                    // if we got 2 or 4 length tokens we must not have others
+                    if (got_length != 0) {
+                        length_ok = false;
+                    }
+                    CssIdent ident = (CssIdent) val;
+                    // checked before, not allowed here
+                    if (inherit.equals(ident)) {
+                        throw new InvalidParamException("value", val,
+                                getPropertyName(), ac);
+                    }
+                    if (inset.equals(ident)) {
+                        value.shadow_mod = inset;
+                        break;
+                    }
+                    // if not a known ident, it must be a color
+                    // and let's use the CSS3 color.
+                    CssExpression exp = new CssExpression();
+                    exp.addValue(val);
+                    CssColor color = new CssColor(ac, exp, check);
+                    value.color = (CssValue) color.get();
+                    break;
+                case CssTypes.CSS_COLOR:
+                case CssTypes.CSS_FUNCTION:
+                    // this one is a pain... need to remove function for colors.
+                    CssExpression fexp = new CssExpression();
+                    fexp.addValue(val);
+                    CssColor fcolor = new CssColor(ac, fexp, check);
+                    value.color = (CssValue) fcolor.get();
+                    break;
+                default:
+                    throw new InvalidParamException("value", val,
+                            getPropertyName(), ac);
+            }
+            if (op != SPACE) {
+                throw new InvalidParamException("operator", val,
+                        getPropertyName(), ac);
+            }
+            expression.next();
+        }
+        // we need 2 or 4 lengthed
+        if (got_length != 2 && got_length != 4) {
+            throw new InvalidParamException("unrecognize", ac);
+        }
+        return value;
     }
 
     public CssBoxShadow(ApplContext ac, CssExpression expression)
-	    throws InvalidParamException {
-	this(ac, expression, false);
-    }
-
-    /**
-     * Add this property to the CssStyle.
-     *
-     * @param style The CssStyle
-     */
-    public void addToStyle(ApplContext ac, CssStyle style) {
-	if (((Css3Style) style).cssBoxShadow != null)
-	    style.addRedefinitionWarning(ac, this);
-	((Css3Style) style).cssBoxShadow = this;
-    }
-
-    /**
-     * Get this property in the style.
-     *
-     * @param style The style where the property is
-     * @param resolve if true, resolve the style to find this property
-     */
-    public CssProperty getPropertyInStyle(CssStyle style, boolean resolve) {
-	if (resolve) {
-	    return ((Css3Style) style).getBoxShadow();
-	} else {
-	    return ((Css3Style) style).cssBoxShadow;
-	}
+            throws InvalidParamException {
+        this(ac, expression, false);
     }
 
     /**
      * Compares two properties for equality.
      *
-     * @param value The other property.
+     * @param property The other property.
      */
     public boolean equals(CssProperty property) {
-	return (property instanceof CssBoxShadow &&
-		value.equals( ((CssBoxShadow) property).value));
-    }
-
-    /**
-     * Returns the name of this property
-     */
-    public String getPropertyName() {
-	return "box-shadow";
+        return (property instanceof CssBoxShadow &&
+                value.equals(((CssBoxShadow) property).value));
     }
 
     /**
      * Returns the value of this property
      */
     public Object get() {
-	return value;
+        return value;
     }
 
     /**
      * Returns true if this property is "softly" inherited
      */
     public boolean isSoftlyInherited() {
-	return value.equals(inherit);
+        return (inherit == value);
     }
 
     /**
      * Returns a string representation of the object
      */
     public String toString() {
-	return value;
+        // FIXME TODO
+        return value.toString();
     }
 
     /**
@@ -184,7 +253,39 @@
      * It is used by all macro for the function <code>print</code>
      */
     public boolean isDefault() {
-	return value.equals(none);
+        return none == value;
+    }
+
+// placeholder for the different values
+
+    public class CssBoxShadowValue extends CssValueList {
+
+        CssValue horizontal_offset;
+        CssValue vertical_offset;
+        CssValue blur_radius;
+        CssValue spread_distance;
+        CssValue color;
+        CssValue shadow_mod;
+
+        public boolean equals(CssBoxShadowValue v) {
+            // at last!
+            return true;
+        }
+
+        public String toString() {
+            StringBuilder sb = new StringBuilder();
+            sb.append(horizontal_offset).append(' ').append(vertical_offset);
+            if (blur_radius != null) {
+                sb.append(' ').append(blur_radius).append(' ').append(spread_distance);
+            }
+            if (color != null) {
+                sb.append(' ').append(color);
+            }
+            if (shadow_mod != null) {
+                sb.append(' ').append(shadow_mod);
+            }
+            return sb.toString();
+        }
     }
 
 }

Received on Wednesday, 4 April 2012 13:59:22 UTC