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

2002/css-validator/org/w3c/css/properties/css1 Css1Style.java,1.32,1.33 CssTextDecoration.java,1.4,1.5

From: Yves Lafon via cvs-syncmail <cvsmail@w3.org>
Date: Tue, 04 Sep 2012 09:37:41 +0000
To: www-validator-cvs@w3.org
Message-Id: <E1T8pZl-0006Qe-JL@lionel-hutz.w3.org>
Update of /sources/public/2002/css-validator/org/w3c/css/properties/css1
In directory hutz:/tmp/cvs-serv24549/css1

Modified Files:
	Css1Style.java CssTextDecoration.java 
Log Message:
reimplemented text-decoration

Index: CssTextDecoration.java
===================================================================
RCS file: /sources/public/2002/css-validator/org/w3c/css/properties/css1/CssTextDecoration.java,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -d -r1.4 -r1.5
--- CssTextDecoration.java	5 Jan 2010 13:49:45 -0000	1.4
+++ CssTextDecoration.java	4 Sep 2012 09:37:39 -0000	1.5
@@ -1,239 +1,138 @@
-//
 // $Id$
-// From Philippe Le Hegaret (Philippe.Le_Hegaret@sophia.inria.fr)
+// Author: Yves Lafon <ylafon@w3.org>
 //
-// (c) COPYRIGHT MIT and INRIA, 1997.
+// (c) COPYRIGHT MIT, ERCIM and Keio University, 2012.
 // Please first read the full copyright statement in file COPYRIGHT.html
 package org.w3c.css.properties.css1;
 
-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.CssExpression;
 import org.w3c.css.values.CssIdent;
+import org.w3c.css.values.CssOperator;
+import org.w3c.css.values.CssTypes;
 import org.w3c.css.values.CssValue;
+import org.w3c.css.values.CssValueList;
+
+import java.util.ArrayList;
 
 /**
- *   <H4>
- *     &nbsp;&nbsp; 'text-decoration'
- *   </H4>
- *   <P>
- *   <EM>Value:</EM> none | [ underline || overline || line-through || blink ]<BR>
- *   <EM>Initial:</EM> none<BR>
- *   <EM>Applies to:</EM> all elements<BR>
- *   <EM>Inherited:</EM> no, but see clarification below<BR>
- *   <EM>Percentage values:</EM> N/A<BR>
- *   <P>
- *   This property describes decorations that are added to the text of an element.
- *   If the element has no text (e.g. the 'IMG' element in HTML) or is an empty
- *   element (e.g. '&lt;EM&gt;&lt;/EM&gt;'), this property has no effect. A value
- *   of 'blink' causes the text to blink.
- *   <P>
- *   The color(s) required for the text decoration should be derived from the
- *   'color' property value.
- *   <P>
- *   This property is not inherited, but elements should match their parent. E.g.,
- *   if an element is underlined, the line should span the child elements. The
- *   color of the underlining will remain the same even if descendant elements
- *   have different 'color' values.
- *   <PRE>
- *   A:link, A:visited, A:active { text-decoration: underline }
- * </PRE>
- *   <P>
- *   The example above would underline the text of all links (i.e., all 'A' elements
- *   with a 'HREF' attribute).
- *   <P>
- *   UAs must recognize the keyword 'blink', but are not required to support the
- *   blink effect.
- *
- * @version $Revision$
+ * @spec http://www.w3.org/TR/2008/REC-CSS1-20080411/#text-decoration
  */
-public class CssTextDecoration extends CssProperty
-        implements CssTextPropertiesConstants {
-
-    CssValue value;
-
-    private boolean[] values = new boolean[TEXTDECORATION.length];
-
-    private static int[] hash_values;
-
-    private static CssIdent none = new CssIdent("none");
-
-    private static final int INVALID = -1;
-
-    /**
-     * Create a new CssTextDecoration
-     */
-    public CssTextDecoration() {
-    }
-
-    /**
-     * Create a new CssTextDecoration
-     *
-     * @param expression The expression for this property
-     * @exception InvalidParamException Values are incorrect
-     */
-    public CssTextDecoration(ApplContext ac, CssExpression expression, boolean check)
-	    throws InvalidParamException {
-
-	CssValue val = expression.getValue();
-	boolean find = true;
-	//int computed = 0;
-	int index = INVALID;
+public class CssTextDecoration extends org.w3c.css.properties.css.CssTextDecoration {
 
-	setByUser();
+	public static final CssIdent underline, overline, line_through, blink;
 
-	if (val.equals(none)) {
-	    if(expression.getCount() > 1) {
-		throw new InvalidParamException("unrecognize", ac);
-	    }
-	    value = none;
-	    expression.next();
-	    return;
-	} else if (val.equals(inherit)) {
-	    if(expression.getCount() > 1) {
-		 throw new InvalidParamException("unrecognize", ac);
-	    }
-	    value = inherit;
-	    expression.next();
-	    return;
+	static {
+		underline = CssIdent.getIdent("underline");
+		overline = CssIdent.getIdent("overline");
+		line_through = CssIdent.getIdent("line-through");
+		blink = CssIdent.getIdent("blink");
 	}
-	val = null;
 
-	if(check && expression.getCount() > 4) {
-	    throw new InvalidParamException("unrecognize", ac);
+	/**
+	 * Create a new CssTextDecoration
+	 */
+	public CssTextDecoration() {
 	}
 
-	while (find) {
-	    find = false;
-	    val = expression.getValue();
-
-	    if(val != null && val.equals(inherit)) {
-		throw new InvalidParamException("unrecognize", ac);
-	    }
-
-	    if (val instanceof CssIdent) {
-		index = getIndex((CssIdent) val, ac);
-		if (values[index] == true) {
-		    throw new InvalidParamException("same-value",
-						    TEXTDECORATION[index], ac);
-		} else {
-		    values[index] = true;
-		    find = true;
-		    expression.next();
+	/**
+	 * Creates a new CssTextDecoration
+	 *
+	 * @param expression The expression for this property
+	 * @throws org.w3c.css.util.InvalidParamException
+	 *          Expressions are incorrect
+	 */
+	public CssTextDecoration(ApplContext ac, CssExpression expression, boolean check)
+			throws InvalidParamException {
+		if (check && expression.getCount() > 4) {
+			throw new InvalidParamException("unrecognize", ac);
 		}
-	    } else if (val != null) {
-		throw new InvalidParamException("value", val.toString(),
-						getPropertyName(), ac);
-	    }
-	}
-    }
+		setByUser();
 
-    public CssTextDecoration(ApplContext ac, CssExpression expression)
-	throws InvalidParamException {
-	this(ac, expression, false);
-    }
+		CssValue val;
+		char op;
 
-    /**
-     * Returns the value of this property
-     */
-    public Object get() {
-	if (value != null) {
-	    return value;
-	}
-	for (int i = 0; i < TEXTDECORATION.length; i++) {
-	    if (values[i] == true) {
-		return TEXTDECORATION[i];
-	    }
-	}
-	return null;
-    }
+		CssIdent undValue = null;
+		CssIdent oveValue = null;
+		CssIdent linValue = null;
+		CssIdent bliValue = null;
 
-    /**
-     * Returns the name of this property
-     */
-    public String getPropertyName() {
-	return "text-decoration";
-    }
+		val = expression.getValue();
+		op = expression.getOperator();
 
-    private int getIndex(CssIdent val, ApplContext ac) throws InvalidParamException {
-	int hash = val.hashCode();
-	for (int i = 0; i < TEXTDECORATION.length; i++) {
-	    if (hash_values[i] == hash) {
-		return i;
-	    }
-	}
-	throw new InvalidParamException("value", val.toString(),
+		if (val.getType() != CssTypes.CSS_IDENT) {
+			throw new InvalidParamException("value",
+					val.toString(),
 					getPropertyName(), ac);
-    }
-
-    /**
-     * Returns true if this property is "softly" inherited
-     * e.g. his value equals inherit
-     */
-    public boolean isSoftlyInherited() {
-	return value == inherit;
-    }
-
-    /**
-     * Returns a string representation of the object.
-     */
-    public String toString() {
-	if (value != null) {
-	    return value.toString();
-	} else {
-	    String ret = "";
-	    for (int i = 0; i < TEXTDECORATION.length; i++) {
-		if (values[i] == true) {
-		    ret += " " + TEXTDECORATION[i];
 		}
-	    }
-	    return ret.substring(1);
-	}
-    }
 
-    /**
-     * Add this property to the CssStyle.
-     *
-     * @param style The CssStyle
-     */
-    public void addToStyle(ApplContext ac, CssStyle style) {
-	Css1Style style0 = (Css1Style) style;
-	if (style0.cssTextDecoration != null) {
-	    style0.addRedefinitionWarning(ac, this);
-	}
-	style0.cssTextDecoration = 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 ((Css1Style) style).getTextDecoration();
-	} else {
-	    return ((Css1Style) style).cssTextDecoration;
+		CssIdent ident = (CssIdent) val;
+		if (none.equals(ident)) {
+			value = none;
+			if (check && expression.getCount() != 1) {
+				throw new InvalidParamException("value",
+						val.toString(),
+						getPropertyName(), ac);
+			}
+		} else {
+			int nbgot = 0;
+			do {
+				if (undValue == null && underline.equals(ident)) {
+					undValue = underline;
+				} else if (oveValue == null && overline.equals(ident)) {
+					oveValue = overline;
+				} else if (linValue == null && line_through.equals(ident)) {
+					linValue = line_through;
+				} else if (bliValue == null && blink.equals(ident)) {
+					bliValue = blink;
+				} else {
+					throw new InvalidParamException("value",
+							val.toString(),
+							getPropertyName(), ac);
+				}
+				nbgot++;
+				if (expression.getRemainingCount() == 1 || (!check && nbgot == 4)) {
+					// if we have both, exit
+					// (needed only if check == false...
+					break;
+				}
+				if (op != CssOperator.SPACE) {
+					throw new InvalidParamException("operator",
+							((new Character(op)).toString()), ac);
+				}
+				expression.next();
+				val = expression.getValue();
+				op = expression.getOperator();
+				if (val.getType() != CssTypes.CSS_IDENT) {
+					throw new InvalidParamException("value",
+							val.toString(),
+							getPropertyName(), ac);
+				}
+				ident = (CssIdent) val;
+			} while (!expression.end());
+			// now construct the value
+			ArrayList<CssValue> v = new ArrayList<CssValue>(nbgot);
+			if (undValue != null) {
+				v.add(undValue);
+			}
+			if (oveValue != null) {
+				v.add(oveValue);
+			}
+			if (linValue != null) {
+				v.add(linValue);
+			}
+			if (bliValue != null) {
+				v.add(bliValue);
+			}
+			value = (nbgot > 1) ? new CssValueList(v) : v.get(0);
+		}
+		expression.next();
 	}
-    }
 
-    /**
-     * Compares two properties for equality.
-     *
-     * @param value The other property.
-     */
-    public boolean equals(CssProperty property) {
-	// @@ FIXME
-	return false;
-    }
-
-    static {
-	hash_values = new int[TEXTDECORATION.length];
-	for (int i=0; i<TEXTDECORATION.length; i++) {
-	    hash_values[i] = TEXTDECORATION[i].hashCode();
+	public CssTextDecoration(ApplContext ac, CssExpression expression)
+			throws InvalidParamException {
+		this(ac, expression, false);
 	}
-    }
 }
+

Index: Css1Style.java
===================================================================
RCS file: /sources/public/2002/css-validator/org/w3c/css/properties/css1/Css1Style.java,v
retrieving revision 1.32
retrieving revision 1.33
diff -u -d -r1.32 -r1.33
--- Css1Style.java	3 Sep 2012 20:34:43 -0000	1.32
+++ Css1Style.java	4 Sep 2012 09:37:39 -0000	1.33
@@ -15,6 +15,7 @@
 import org.w3c.css.properties.css.CssZIndex;
 import org.w3c.css.properties.css.CssTextTransform;
 import org.w3c.css.properties.css.CssTextAlign;
+import org.w3c.css.properties.css.CssTextDecoration;
 import org.w3c.css.properties.css.CssTextIndent;
 
 import org.w3c.css.util.ApplContext;
Received on Tuesday, 4 September 2012 09:37:48 UTC

This archive was generated by hypermail 2.3.1 : Wednesday, 7 January 2015 15:17:51 UTC